Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/gmt_grdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,19 +1293,22 @@ int gmtlib_get_grdtype (struct GMT_CTRL *GMT, unsigned int direction, struct GMT

GMT_LOCAL void gmtgrdio_doctor_geo_increments (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *header) {
/* Check for sloppy arc min/sec increments due to divisions by 60 or 3600 */
double round_inc, scale, inc, slop;
unsigned int side;
double round_inc[2], scale[2], inc, slop;
unsigned int side, n_fix = 0;
static char *type[2] = {"longitude", "latitude"};

GMT_Report (GMT->parent, GMT_MSG_DEBUG, "Call gmtgrdio_doctor_geo_increments on a geographic grid\n");
for (side = GMT_X; side <= GMT_Y; side++) { /* Check both increments */
scale = (header->inc[side] < GMT_MIN2DEG) ? 3600.0 : 60.0; /* Check for clean multiples of minutes or seconds */
inc = header->inc[side] * scale;
round_inc = rint (inc);
slop = fabs (inc - round_inc);
if (slop > 0 && slop < GMT_CONV4_LIMIT) {
scale[side] = (header->inc[side] < GMT_MIN2DEG) ? 3600.0 : 60.0; /* Check for clean multiples of minutes or seconds */
inc = header->inc[side] * scale[side];
round_inc[side] = rint (inc);
slop = fabs (inc - round_inc[side]);
if (slop > 0 && slop < GMT_CONV4_LIMIT) n_fix++;
}
if (n_fix == 2) {
for (side = GMT_X; side <= GMT_Y; side++) { /* Check both increments */
inc = header->inc[side];
header->inc[side] = round_inc / scale;
header->inc[side] = round_inc[side] / scale[side];
GMT_Report (GMT->parent, GMT_MSG_INFORMATION, "Round-off patrol changed geographic grid increment for %s from %.18g to %.18g\n",
type[side], inc, header->inc[side]);
}
Expand Down Expand Up @@ -1381,7 +1384,8 @@ int gmtlib_read_grd_info (struct GMT_CTRL *GMT, char *file, struct GMT_GRID_HEAD
header->nan_value = invalid;

gmtlib_grd_get_units (GMT, header);
gmtgrdio_round_off_patrol (GMT, header); /* Ensure limit/inc consistency */
if (strncmp (GMT->init.module_name, "grdedit", 7U))
gmtgrdio_round_off_patrol (GMT, header); /* Ensure limit/inc consistency */
//gmtlib_clean_global_headers (GMT, header);

if (header->ProjRefPROJ4 && strstr (header->ProjRefPROJ4, "longlat")) /* A geographic image perhaps */
Expand Down