@@ -379,14 +379,14 @@ GMT_LOCAL void gmtnc_set_optimal_chunksize (struct GMT_CTRL *GMT, struct GMT_GRI
379
379
}
380
380
381
381
GMT_LOCAL bool gmtnc_not_obviously_global (double * we ) {
382
- /* If range is not 360 and boundaries are not 0, 180, 360 then we pass */
382
+ /* If range is not 360 and boundaries are not 0, 180, 360 then we pass true */
383
383
if (!gmt_M_360_range (we [0 ], we [1 ])) return true;
384
384
if (!(doubleAlmostEqualZero (we [0 ], 0.0 ) || doubleAlmostEqual (we [0 ], -180.0 ))) return true;
385
385
return false;
386
386
}
387
387
388
388
GMT_LOCAL bool gmtnc_not_obviously_polar (double * se ) {
389
- /* If range is not 180 and boundaries are not -90/90 then we pass */
389
+ /* If range is not 180 and boundaries are not -90/90 then we pass true */
390
390
if (!gmt_M_180_range (se [0 ], se [1 ])) return true;
391
391
if (!(doubleAlmostEqual (se [0 ], -90.0 ) && doubleAlmostEqual (se [1 ], 90.0 ))) return true;
392
392
return false;
@@ -395,7 +395,7 @@ GMT_LOCAL bool gmtnc_not_obviously_polar (double *se) {
395
395
GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL * GMT , struct GMT_GRID_HEADER * header , char job ) {
396
396
int j , err , has_vector , has_range , registration , var_spacing = 0 ;
397
397
int old_fill_mode , status ;
398
- double dummy [2 ], * xy = NULL ;
398
+ double dummy [2 ], min , max , * xy = NULL ;
399
399
char dimname [GMT_GRID_UNIT_LEN80 ], coord [GMT_LEN8 ];
400
400
nc_type z_type ;
401
401
bool save_xy_array = !strncmp (GMT -> init .module_name , "grd2xyz" , 7U );
@@ -572,7 +572,7 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head
572
572
573
573
if (job == 'r' ) {
574
574
bool set_reg = true;
575
- double dx = 0 , dy = 0 ;
575
+ double dx = 0 , dy = 0 , threshold = 0.0 ;
576
576
/* Get global information */
577
577
if (gmtlib_nc_get_att_text (GMT , ncid , NC_GLOBAL , "title" , header -> title , GMT_GRID_TITLE_LEN80 ))
578
578
gmtlib_nc_get_att_text (GMT , ncid , z_id , "long_name" , header -> title , GMT_GRID_TITLE_LEN80 );
@@ -636,14 +636,18 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head
636
636
nc_get_att_double (ncid , ids [HH -> xy_dim [0 ]], "valid_max" , & dummy [1 ])));
637
637
638
638
if (has_vector && has_range ) { /* Has both so we can do a basic sanity check */
639
- if (fabs (dummy [0 ] - xy [0 ]) > ((0.5 + GMT_CONV5_LIMIT ) * dx ) || fabs (dummy [1 ] - xy [header -> n_columns - 1 ]) > ((0.5 + GMT_CONV5_LIMIT ) * dx )) {
639
+ threshold = (0.5 + GMT_CONV5_LIMIT ) * dx ;
640
+ min = xy [0 ]; max = xy [header -> n_columns - 1 ];
641
+ if (min > max ) gmt_M_double_swap (min , max ); /* Got it backwards in the array */
642
+ if (fabs (dummy [0 ] - min ) > threshold || fabs (dummy [1 ] - max ) > threshold ) {
640
643
if (gmtnc_not_obviously_global (dummy )) {
641
644
GMT_Report (GMT -> parent , GMT_MSG_WARNING , "The x-coordinates and range attribute are in conflict; must rely on coordinates only\n" );
642
645
dummy [0 ] = xy [0 ], dummy [1 ] = xy [header -> n_columns - 1 ];
643
646
has_range = false; /* Since useless information */
644
647
/* For registration, we have to assume that the actual range is an integer multiple of increment.
645
648
* If so, then if the coordinates are off by 0.5*dx then we assume we have pixel registration */
646
- if (set_reg && fabs (fmod (dummy [0 ], dx )) > ((0.5 - GMT_CONV5_LIMIT ) * dx )) { /* Pixel registration */
649
+ threshold = (0.5 - GMT_CONV5_LIMIT ) * dx ;
650
+ if (set_reg && fabs (fmod (dummy [0 ], dx )) > threshold ) { /* Pixel registration */
647
651
registration = header -> registration = GMT_GRID_PIXEL_REG ;
648
652
dummy [0 ] -= 0.5 * dx ; dummy [1 ] += 0.5 * dx ;
649
653
if (gmt_M_360_range (dummy [0 ], dummy [1 ]))
@@ -666,7 +670,8 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head
666
670
}
667
671
else if (has_vector ) { /* No attribute for range, use coordinates */
668
672
dummy [0 ] = xy [0 ], dummy [1 ] = xy [header -> n_columns - 1 ];
669
- if (set_reg && fabs (fmod (dummy [0 ], dx )) > ((0.5 - GMT_CONV5_LIMIT ) * dx )) { /* Most likely pixel registration since off by dx/2 */
673
+ threshold = (0.5 - GMT_CONV5_LIMIT ) * dx ;
674
+ if (set_reg && fabs (fmod (dummy [0 ], dx )) > threshold ) { /* Most likely pixel registration since off by dx/2 */
670
675
registration = header -> registration = GMT_GRID_PIXEL_REG ;
671
676
dummy [0 ] -= 0.5 * dx ; dummy [1 ] += 0.5 * dx ;
672
677
if (gmt_M_360_range (dummy [0 ], dummy [1 ]))
@@ -725,14 +730,18 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head
725
730
nc_get_att_double (ncid , ids [HH -> xy_dim [1 ]], "valid_max" , & dummy [1 ])));
726
731
727
732
if (has_vector && has_range ) { /* Has both so we can do a basic sanity check */
728
- if (fabs (dummy [0 ] - xy [0 ]) > ((0.5 + GMT_CONV5_LIMIT ) * dy ) || fabs (dummy [1 ] - xy [header -> n_rows - 1 ]) > ((0.5 + GMT_CONV5_LIMIT ) * dy )) {
733
+ threshold = (0.5 + GMT_CONV5_LIMIT ) * dy ;
734
+ min = xy [0 ]; max = xy [header -> n_rows - 1 ];
735
+ if (min > max ) gmt_M_double_swap (min , max ); /* Got it backwards in the array */
736
+ if (fabs (dummy [0 ] - min ) > threshold || fabs (dummy [1 ] - max ) > threshold ) {
729
737
if (gmtnc_not_obviously_polar (dummy )) {
730
738
GMT_Report (GMT -> parent , GMT_MSG_WARNING , "The y-coordinates and range attribute are in conflict; must rely on coordinates only\n" );
731
739
dummy [0 ] = xy [0 ], dummy [1 ] = xy [header -> n_rows - 1 ];
732
740
has_range = false; /* Since useless information */
733
741
/* Registration was set using x values, so here we just check that we get the same result.
734
742
* If the coordinates are off by 0.5*dy then we assume we have pixel registration */
735
- if (fabs (fmod (dummy [0 ], dy )) > ((0.5 - GMT_CONV5_LIMIT ) * dy )) { /* Pixel registration? */
743
+ threshold = (0.5 - GMT_CONV5_LIMIT ) * dy ;
744
+ if (fabs (fmod (dummy [0 ], dy )) > threshold ) { /* Pixel registration? */
736
745
if (header -> registration == GMT_GRID_NODE_REG ) /* No, somehow messed up now */
737
746
GMT_Report (GMT -> parent , GMT_MSG_WARNING , "Guessing of registration in conflict between x and y, using %s\n" , regtype [header -> registration ]);
738
747
else { /* Pixel registration confirmed */
@@ -758,8 +767,9 @@ GMT_LOCAL int gmtnc_grd_info (struct GMT_CTRL *GMT, struct GMT_GRID_HEADER *head
758
767
}
759
768
}
760
769
else if (has_vector ) { /* No attribute for range, use coordinates */
770
+ threshold = (0.5 - GMT_CONV5_LIMIT ) * dy ;
761
771
dummy [0 ] = xy [0 ], dummy [1 ] = xy [header -> n_rows - 1 ];
762
- if (( fabs (fmod (dummy [0 ], dy )) > (( 0.5 - GMT_CONV5_LIMIT ) * dy )) ) { /* Most likely pixel registration since off by dy/2 */
772
+ if (fabs (fmod (dummy [0 ], dy )) > threshold ) { /* Most likely pixel registration since off by dy/2 */
763
773
if (header -> registration == GMT_GRID_NODE_REG ) /* No, somehow messed up now */
764
774
GMT_Report (GMT -> parent , GMT_MSG_WARNING , "Guessing of registration in conflict between x and y, using %s\n" , regtype [header -> registration ]);
765
775
else { /* Pixel registration confirmed */
0 commit comments