| 418 | #define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);} |
| 419 | |
| 420 | EXTERN_MSC int GMT_grdgradient (void *V_API, int mode, void *args) { |
| 421 | bool bad, new_grid = false, separate = false; |
| 422 | int p[4], mx, error = 0; |
| 423 | openmp_int row, col; |
| 424 | unsigned int n, orig_pad[4]; |
| 425 | uint64_t ij, ij0, n_used = 0; |
| 426 | |
| 427 | char format[GMT_BUFSIZ] = {""}, buffer[GMT_GRID_REMARK_LEN160] = {""}; |
| 428 | |
| 429 | double dx_grid, dy_grid, x_factor = 0.0, x_factor_set, y_factor, y_factor_set, dzdx, dzdy, ave_gradient, wesn[4]; |
| 430 | double azim, denom, max_gradient = 0.0, min_gradient = 0.0, rpi, lat, output, one; |
| 431 | double x_factor2 = 0.0, x_factor2_set = 0.0, y_factor2 = 0.0, dzdx2 = 0.0, dzdy2 = 0.0, dzds1, dzds2; |
| 432 | double p0 = 0.0, q0 = 0.0, p0q0_cte = 1.0, norm_z, mag, s[3], lim_x, lim_y, lim_z; |
| 433 | double k_ads = 0.0, diffuse, spec, r_min = DBL_MAX, r_max = -DBL_MAX, scale, sin_Az[2] = {0.0, 0.0}; |
| 434 | double def_offset = 0.0, def_sigma = 0.0; |
| 435 | |
| 436 | struct GMT_GRID *In = NULL, *Slope = NULL, *Grid = NULL, *A = NULL; |
| 437 | struct GRDGRADIENT_CTRL *Ctrl = NULL; |
| 438 | struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL; |
| 439 | struct GMT_OPTION *options = NULL; |
| 440 | struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */ |
| 441 | |
| 442 | /*----------------------- Standard module initialization and parsing ----------------------*/ |
| 443 | |
| 444 | if (API == NULL) return (GMT_NOT_A_SESSION); |
| 445 | if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */ |
| 446 | options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */ |
| 447 | |
| 448 | if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */ |
| 449 | |
| 450 | /* Parse the command-line arguments */ |
| 451 | |
| 452 | if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */ |
| 453 | if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error); |
| 454 | Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */ |
| 455 | if ((error = parse (GMT, Ctrl, options)) != 0) Return (error); |
| 456 | |
| 457 | /*---------------------------- This is the grdgradient main code ----------------------------*/ |
| 458 | |
| 459 | gmt_grd_set_datapadding (GMT, true); /* Turn on gridpadding when reading a subset */ |
| 460 | |
| 461 | if (Ctrl->Q.mode & 1) { /* Read in previous statistics */ |
| 462 | char sfile[PATH_MAX] = {""}; |
| 463 | FILE *fp = NULL; |
| 464 | if (Ctrl->Q.file) |
| 465 | sprintf (sfile, "%s", Ctrl->Q.file); |
| 466 | else if (GMT->session.TMPDIR) |
| 467 | sprintf (sfile, "%s/grdgradient.stat", GMT->session.TMPDIR); |
| 468 | else if (API->tmp_dir) |
| 469 | sprintf (sfile, "%s/grdgradient.stat", API->tmp_dir); |
| 470 | else |
| 471 | sprintf (sfile, "grdgradient.stat"); |
| 472 | GMT_Report (API, GMT_MSG_DEBUG, "Read statistics file [%s] with offset and sigma\n", sfile); |
| 473 | if (access (sfile, F_OK)) { |
| 474 | GMT_Report (API, GMT_MSG_ERROR, "Unable to find statistics file from last run [%s]!\n", sfile); |
| 475 | Return (GMT_FILE_NOT_FOUND); |
| 476 | } |
| 477 | if ((fp = fopen (sfile, "r")) == NULL) { |
nothing calls this directly
no test coverage detected