19 #define LL_TOLERANCE 10
23 static double llepsilon = 0.01;
24 static double fpepsilon = 1.0e-9;
26 static int ll_wrap(
struct Cell_head *cellhd);
27 static int ll_check_ns(
struct Cell_head *cellhd);
28 static int ll_check_ew(
struct Cell_head *cellhd);
61 if (cellhd->
rows <= 0)
63 " (resolution is %g)"),
72 if (cellhd->
cols <= 0)
74 " (resolution is %g)"),
82 " but %g (north) <= %g (south"),
86 " but %g (north) <= %g (south"),
94 " but %g (east) <= %g (west)"),
111 if (cellhd->
cols < 0) {
112 G_fatal_error(
_(
"Invalid coordinates: negative number of columns"));
114 if (cellhd->
rows < 0) {
121 if (old_res > 0 && fabs(old_res - cellhd->
ns_res) / old_res > 0.01)
126 if (old_res > 0 && fabs(old_res - cellhd->
ew_res) / old_res > 0.01)
177 if (cellhd->
rows <= 0)
179 " (resolution is %g)"),
181 if (cellhd->
rows3 <= 0)
183 " (resolution is %g)"),
195 if (cellhd->
cols <= 0)
197 " (resolution is %g)"),
199 if (cellhd->
cols3 <= 0)
201 " (resolution is %g)"),
218 " but %g (north) <= %g (south"),
222 " but %g (north) <= %g (south"),
230 " but %g (east) <= %g (west)"),
235 " but %g (top) <= %g (bottom)"),
270 if (cellhd->
cols < 0 || cellhd->
cols3 < 0) {
271 G_fatal_error(
_(
"Invalid coordinates: negative number of columns"));
273 if (cellhd->
rows < 0 || cellhd->
rows3 < 0) {
277 G_fatal_error(
_(
"Invalid coordinates: negative number of depths"));
283 if (old_res > 0 && fabs(old_res - cellhd->
ns_res) / old_res > 0.01)
288 if (old_res > 0 && fabs(old_res - cellhd->
ew_res) / old_res > 0.01)
302 static int ll_wrap(
struct Cell_head *cellhd)
311 G_warning(
_(
"East (%.15g) is not larger than West (%.15g)"),
314 while (cellhd->
east <= cellhd->
west)
315 cellhd->
east += 360.0;
324 while (cellhd->
west + shift >= 180) {
327 while (cellhd->
east + shift <= -180) {
332 while (cellhd->
east + shift > 360) {
335 while (cellhd->
west + shift <= -360) {
340 cellhd->
west += shift;
341 cellhd->
east += shift;
365 static int ll_check_ns(
struct Cell_head *cellhd)
377 G_debug(3,
"ll_check_ns: epsilon: %g", llepsilon);
382 ncells = (
int)(diff + 0.5);
384 if ((diff < 0 && diff < -fpepsilon) || (diff > 0 && diff > fpepsilon)) {
386 _(
"NS extent does not match NS resolution: %g cells difference"),
394 if (cellhd->
north < 90.0 && diff < 1.0) {
396 if (diff < llepsilon && diff > fpepsilon) {
398 _(
"Subtle input data rounding error of north boundary (%g)"),
399 cellhd->
north - 90.0);
406 if (cellhd->
north > 90.0) {
407 if (diff <= 0.5 + llepsilon) {
411 if (diff < llepsilon && diff > fpepsilon) {
414 cellhd->
north - 90.0);
415 G_debug(1,
"North of north in seconds: %g",
416 (cellhd->
north - 90.0) * 3600);
426 if (diff < llepsilon && diff > fpepsilon) {
430 G_debug(1,
"North of north + 0.5 cells in seconds: %g",
431 (cellhd->
north - 90.0 - cellhd->
ns_res / 2.0) * 3600);
446 if (cellhd->
south > -90.0 && diff < 1.0) {
448 if (diff < llepsilon && diff > fpepsilon) {
450 _(
"Subtle input data rounding error of south boundary (%g)"),
451 cellhd->
south + 90.0);
458 if (cellhd->
south < -90.0) {
459 if (diff <= 0.5 + llepsilon) {
463 if (diff < llepsilon && diff > fpepsilon) {
467 G_debug(1,
"South of south in seconds: %g",
468 (-cellhd->
south - 90) * 3600);
478 if (diff < llepsilon && diff > fpepsilon) {
482 G_debug(1,
"South of south + 0.5 cells in seconds: %g",
483 (-cellhd->
south - 90 - cellhd->
ns_res / 2.0) * 3600);
500 static int ll_check_ew(
struct Cell_head *cellhd)
512 G_debug(3,
"ll_check_ew: epsilon: %g", llepsilon);
516 ncells = (
int)(diff + 0.5);
518 if ((diff < 0 && diff < -fpepsilon) || (diff > 0 && diff > fpepsilon)) {
520 _(
"EW extent does not match EW resolution: %g cells difference"),
523 if (cellhd->
east - cellhd->
west > 360.0) {
525 if (diff > fpepsilon)
527 " (East: %g, West: %g)"),
530 else if (cellhd->
east - cellhd->
west < 360.0) {
532 if (diff < 1.0 && diff > fpepsilon)
534 _(
"%g cells missing to cover 360 degree EW extent"), diff);
554 int ll_adjust, res_adj;
556 char buf[100], buf2[100];
599 old = cellhds.
ns_res * 3600;
600 sprintf(buf,
"%f", old);
601 sscanf(buf,
"%lf", &
new);
604 old = cellhds.
ew_res * 3600;
605 sprintf(buf,
"%f", old);
606 sscanf(buf,
"%lf", &
new);
609 old = cellhds.
north * 3600;
610 sprintf(buf,
"%f", old);
611 sscanf(buf,
"%lf", &
new);
614 old = cellhds.
south * 3600;
615 sprintf(buf,
"%f", old);
616 sscanf(buf,
"%lf", &
new);
619 old = cellhds.
west * 3600;
620 sprintf(buf,
"%f", old);
621 sscanf(buf,
"%lf", &
new);
624 old = cellhds.
east * 3600;
625 sprintf(buf,
"%f", old);
626 sscanf(buf,
"%lf", &
new);
639 dsec2 = floor(dsec + 0.5);
641 diff = fabs(dsec2 - dsec) / dsec;
642 if (diff > 0 && diff < llepsilon) {
645 if (strcmp(buf, buf2))
659 dsec2 = floor(dsec + 0.5);
660 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
665 dsec2 = floor(dsec + 0.5);
666 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
669 if (n_off < llepsilon || n_off <= s_off) {
672 dsec2 = floor(dsec + 0.5);
675 if (diff > 0 && diff < llepsilon) {
678 if (strcmp(buf, buf2))
686 diff = fabs(
new - old) / cellhds.
ns_res;
690 if (strcmp(buf, buf2))
699 dsec2 = floor(dsec + 0.5);
702 if (diff > 0 && diff < llepsilon) {
705 if (strcmp(buf, buf2))
713 diff = fabs(
new - old) / cellhds.
ns_res;
717 if (strcmp(buf, buf2))
727 dsec2 = floor(dsec + 0.5);
729 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
730 if (diff > 0 && diff < llepsilon) {
733 if (strcmp(buf, buf2))
741 dsec2 = floor(dsec + 0.5);
743 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
744 if (diff > 0 && diff < llepsilon) {
747 if (strcmp(buf, buf2))
763 dsec2 = floor(dsec + 0.5);
765 diff = fabs(dsec2 - dsec) / dsec;
766 if (diff > 0 && diff < llepsilon) {
769 if (strcmp(buf, buf2))
783 dsec2 = floor(dsec + 0.5);
784 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
789 dsec2 = floor(dsec + 0.5);
790 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
793 if (w_off < llepsilon || w_off <= e_off) {
796 dsec2 = floor(dsec + 0.5);
799 if (diff > 0 && diff < llepsilon) {
802 if (strcmp(buf, buf2))
810 diff = fabs(
new - old) / cellhds.
ew_res;
814 if (strcmp(buf, buf2))
823 dsec2 = floor(dsec + 0.5);
826 if (diff > 0 && diff < llepsilon) {
829 if (strcmp(buf, buf2))
837 diff = fabs(
new - cellhds.
west) / cellhds.
ew_res;
841 if (strcmp(buf, buf2))
851 dsec2 = floor(dsec + 0.5);
853 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
854 if (diff > 0 && diff < llepsilon) {
857 if (strcmp(buf, buf2))
865 dsec2 = floor(dsec + 0.5);
867 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
868 if (diff > 0 && diff < llepsilon) {
871 if (strcmp(buf, buf2))
void G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag, int col_flag, int depth_flag)
Adjust cell header for 3D values.
void G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
Adjust cell header.
int G_adjust_window_ll(struct Cell_head *cellhd)
Adjust window for lat/lon.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_lat_format(double, char *)
void G_lon_format(double, char *)
int G_lon_scan(const char *, double *)
void void G_verbose_message(const char *,...) __attribute__((format(printf
void G_llres_format(double, char *)
void void void G_important_message(const char *,...) __attribute__((format(printf
int G_lat_scan(const char *, double *)
int G_llres_scan(const char *, double *)
int G_debug(int, const char *,...) __attribute__((format(printf
#define PROJECTION_LL
Projection code - Latitude-Longitude.
2D/3D raster map header (used also for region)
int cols3
Number of columns for 3D data.
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
double bottom
Extent coordinates (bottom) - 3D data.
int depths
number of depths for 3D data
double east
Extent coordinates (east)
double ew_res3
Resolution - east to west cell size for 3D data.
double ns_res
Resolution - north to south cell size for 2D data.
double ns_res3
Resolution - north to south cell size for 3D data.
double top
Extent coordinates (top) - 3D data.
int rows3
Number of rows for 3D data.
int rows
Number of rows for 2D data.
int cols
Number of columns for 2D data.
double south
Extent coordinates (south)
double tb_res
Resolution - top to bottom cell size for 3D data.
double west
Extent coordinates (west)