MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / grdfft_parse_f_string

Function grdfft_parse_f_string

src/grdfft.c:479–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

477}
478
479GMT_LOCAL bool grdfft_parse_f_string (struct GMT_CTRL *GMT, struct F_INFO *f_info, char *c) {
480 unsigned int i, j, n_tokens, pos;
481 bool descending;
482 double fourvals[4];
483 char line[GMT_LEN256] = {""}, p[GMT_LEN256] = {""};
484
485 /* Syntax is either -F[r|x|y]lc/hc/lp/hp (Cosine taper), -F[r|x|y]lo/hi (Gaussian), or -F[r|x|y]lo/hi/order (Butterworth) */
486
487 strncpy (line, c, GMT_LEN256-1);
488 i = 0;
489 f_info->k_type = GMT_FFT_K_IS_KR; /* j is Filter type: r=2, x=0, y=1 [r] */
490
491 if (line[i] == 'r') {
492 i++; f_info->k_type = GMT_FFT_K_IS_KR;
493 }
494 else if (line[i] == 'x') {
495 i++; f_info->k_type = GMT_FFT_K_IS_KX;
496 }
497 else if (line[i] == 'y') {
498 i++; f_info->k_type = GMT_FFT_K_IS_KY;
499 }
500 fourvals[0] = fourvals[1] = fourvals[2] = fourvals[3] = GMT_NOTSET;
501
502 n_tokens = pos = 0;
503 while ((gmt_strtok (&line[i], "/", &pos, p))) {
504 if (n_tokens > 3) {
505 GMT_Report (GMT->parent, GMT_MSG_ERROR, "Too many slashes in -F.\n");
506 return (true);
507 }
508 if(p[0] == '-')
509 fourvals[n_tokens] = GMT_NOTSET;
510 else {
511 if ((sscanf(p, "%lf", &fourvals[n_tokens])) != 1) {
512 GMT_Report (GMT->parent, GMT_MSG_ERROR, " Cannot read token %d.\n", n_tokens);
513 return (true);
514 }
515 }
516 n_tokens++;
517 }
518
519 if (!(n_tokens == 2 || n_tokens == 3 || n_tokens == 4)) {
520 GMT_Report (GMT->parent, GMT_MSG_ERROR, "-F Cannot find 2-4 tokens separated by slashes.\n");
521 return (true);
522 }
523 descending = true;
524 if (f_info->kind == GRDFFT_FILTER_BW && n_tokens == 3) n_tokens = 2; /* So we don't check the order as a wavelength */
525
526 for (i = 1; i < n_tokens; i++) {
527 if (fourvals[i] == GMT_NOTSET || fourvals[i-1] == GMT_NOTSET) continue;
528 if (fourvals[i] > fourvals[i-1]) descending = false;
529 }
530 if (!(descending)) {
531 GMT_Report (GMT->parent, GMT_MSG_ERROR, "-F Wavelengths are not in descending order.\n");
532 return (true);
533 }
534 j = f_info->k_type;
535 if (f_info->kind == GRDFFT_FILTER_COS) { /* Cosine band-pass specification */
536 if ((fourvals[0] * fourvals[1]) < 0.0 || (fourvals[2] * fourvals[3]) < 0.0) {

Callers 1

parseFunction · 0.85

Calls 2

gmt_strtokFunction · 0.85
GMT_ReportFunction · 0.85

Tested by

no test coverage detected