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)"),
102 if (cellhd->
rows == 0)
109 if (cellhd->
cols == 0)
113 if (cellhd->
cols < 0) {
114 G_fatal_error(
_(
"Invalid coordinates: negative number of columns"));
116 if (cellhd->
rows < 0) {
123 if (old_res > 0 && fabs(old_res - cellhd->
ns_res) / old_res > 0.01)
128 if (old_res > 0 && fabs(old_res - cellhd->
ew_res) / old_res > 0.01)
166 int col_flag,
int depth_flag)
179 if (cellhd->
rows <= 0)
181 " (resolution is %g)"),
183 if (cellhd->
rows3 <= 0)
185 " (resolution is %g)"),
197 if (cellhd->
cols <= 0)
199 " (resolution is %g)"),
201 if (cellhd->
cols3 <= 0)
203 " (resolution is %g)"),
220 " but %g (north) <= %g (south"),
224 " but %g (north) <= %g (south"),
232 " but %g (east) <= %g (west)"),
237 " but %g (top) <= %g (bottom)"),
245 if (cellhd->
rows == 0)
251 if (cellhd->
rows3 == 0)
258 if (cellhd->
cols == 0)
264 if (cellhd->
cols3 == 0)
276 if (cellhd->
cols < 0 || cellhd->
cols3 < 0) {
277 G_fatal_error(
_(
"Invalid coordinates: negative number of columns"));
279 if (cellhd->
rows < 0 || cellhd->
rows3 < 0) {
283 G_fatal_error(
_(
"Invalid coordinates: negative number of depths"));
289 if (old_res > 0 && fabs(old_res - cellhd->
ns_res) / old_res > 0.01)
294 if (old_res > 0 && fabs(old_res - cellhd->
ew_res) / old_res > 0.01)
308 static int ll_wrap(
struct Cell_head *cellhd)
317 G_warning(
_(
"East (%.15g) is not larger than West (%.15g)"),
320 while (cellhd->
east <= cellhd->
west)
321 cellhd->
east += 360.0;
330 while (cellhd->
west + shift >= 180) {
333 while (cellhd->
east + shift <= -180) {
338 while (cellhd->
east + shift > 360) {
341 while (cellhd->
west + shift <= -360) {
346 cellhd->
west += shift;
347 cellhd->
east += shift;
371 static int ll_check_ns(
struct Cell_head *cellhd)
383 G_debug(3,
"ll_check_ns: epsilon: %g", llepsilon);
388 ncells = (
int) (diff + 0.5);
390 if ((diff < 0 && diff < -fpepsilon) ||
391 (diff > 0 && diff > fpepsilon)) {
400 if (cellhd->
north < 90.0 && diff < 1.0 ) {
403 if (diff < llepsilon && diff > fpepsilon) {
405 cellhd->
north - 90.0);
412 if (cellhd->
north > 90.0) {
413 if (diff <= 0.5 + llepsilon) {
417 if (diff < llepsilon && diff > fpepsilon) {
419 cellhd->
north - 90.0);
420 G_debug(1,
"North of north in seconds: %g",
421 (cellhd->
north - 90.0) * 3600);
431 if (diff < llepsilon && diff > fpepsilon) {
434 G_debug(1,
"North of north + 0.5 cells in seconds: %g",
435 (cellhd->
north - 90.0 - cellhd->
ns_res / 2.0) * 3600);
450 if (cellhd->
south > -90.0 && diff < 1.0 ) {
453 if (diff < llepsilon && diff > fpepsilon) {
455 cellhd->
south + 90.0);
462 if (cellhd->
south < -90.0) {
463 if (diff <= 0.5 + llepsilon) {
467 if (diff < llepsilon && diff > fpepsilon) {
470 G_debug(1,
"South of south in seconds: %g",
471 (-cellhd->
south - 90) * 3600);
481 if (diff < llepsilon && diff > fpepsilon) {
484 G_debug(1,
"South of south + 0.5 cells in seconds: %g",
485 (-cellhd->
south - 90 - cellhd->
ns_res / 2.0) * 3600);
502 static int ll_check_ew(
struct Cell_head *cellhd)
514 G_debug(3,
"ll_check_ew: epsilon: %g", llepsilon);
518 ncells = (
int) (diff + 0.5);
520 if ((diff < 0 && diff < -fpepsilon) ||
521 (diff > 0 && diff > fpepsilon)) {
525 if (cellhd->
east - cellhd->
west > 360.0) {
527 if (diff > fpepsilon)
531 else if (cellhd->
east - cellhd->
west < 360.0) {
533 if (diff < 1.0 && diff > fpepsilon)
555 int ll_adjust, res_adj;
557 char buf[100], buf2[100];
600 old = cellhds.
ns_res * 3600;
601 sprintf(buf,
"%f", old);
602 sscanf(buf,
"%lf", &
new);
605 old = cellhds.
ew_res * 3600;
606 sprintf(buf,
"%f", old);
607 sscanf(buf,
"%lf", &
new);
610 old = cellhds.
north * 3600;
611 sprintf(buf,
"%f", old);
612 sscanf(buf,
"%lf", &
new);
615 old = cellhds.
south * 3600;
616 sprintf(buf,
"%f", old);
617 sscanf(buf,
"%lf", &
new);
620 old = cellhds.
west * 3600;
621 sprintf(buf,
"%f", old);
622 sscanf(buf,
"%lf", &
new);
625 old = cellhds.
east * 3600;
626 sprintf(buf,
"%f", old);
627 sscanf(buf,
"%lf", &
new);
640 dsec2 = floor(dsec + 0.5);
642 diff = fabs(dsec2 - dsec) / dsec;
643 if (diff > 0 && diff < llepsilon) {
646 if (strcmp(buf, buf2))
660 dsec2 = floor(dsec + 0.5);
661 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
666 dsec2 = floor(dsec + 0.5);
667 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
670 if (n_off < llepsilon || n_off <= s_off) {
673 dsec2 = floor(dsec + 0.5);
676 if (diff > 0 && diff < llepsilon) {
679 if (strcmp(buf, buf2))
687 diff = fabs(
new - old) / cellhds.
ns_res;
691 if (strcmp(buf, buf2))
700 dsec2 = floor(dsec + 0.5);
703 if (diff > 0 && diff < llepsilon) {
706 if (strcmp(buf, buf2))
714 diff = fabs(
new - old) / cellhds.
ns_res;
718 if (strcmp(buf, buf2))
728 dsec2 = floor(dsec + 0.5);
730 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
731 if (diff > 0 && diff < llepsilon) {
734 if (strcmp(buf, buf2))
743 dsec2 = floor(dsec + 0.5);
745 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
746 if (diff > 0 && diff < llepsilon) {
749 if (strcmp(buf, buf2))
766 dsec2 = floor(dsec + 0.5);
768 diff = fabs(dsec2 - dsec) / dsec;
769 if (diff > 0 && diff < llepsilon) {
772 if (strcmp(buf, buf2))
786 dsec2 = floor(dsec + 0.5);
787 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
792 dsec2 = floor(dsec + 0.5);
793 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
796 if (w_off < llepsilon || w_off <= e_off) {
799 dsec2 = floor(dsec + 0.5);
802 if (diff > 0 && diff < llepsilon) {
805 if (strcmp(buf, buf2))
813 diff = fabs(
new - old) / cellhds.
ew_res;
817 if (strcmp(buf, buf2))
826 dsec2 = floor(dsec + 0.5);
829 if (diff > 0 && diff < llepsilon) {
832 if (strcmp(buf, buf2))
840 diff = fabs(
new - cellhds.
west) / cellhds.
ew_res;
844 if (strcmp(buf, buf2))
854 dsec2 = floor(dsec + 0.5);
856 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
857 if (diff > 0 && diff < llepsilon) {
860 if (strcmp(buf, buf2))
869 dsec2 = floor(dsec + 0.5);
871 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
872 if (diff > 0 && diff < llepsilon) {
875 if (strcmp(buf, buf2))
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void void void G_important_message(const char *,...) __attribute__((format(printf
int G_llres_scan(const char *, double *)
void G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag, int col_flag, int depth_flag)
Adjust cell header for 3D values.
2D/3D raster map header (used also for region)
double west
Extent coordinates (west)
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.
int cols3
Number of columns for 3D data.
double top
Extent coordinates (top) - 3D data.
void G_llres_format(double, char *)
double north
Extent coordinates (north)
double ns_res3
Resolution - north to south cell size for 3D data.
int rows3
Number of rows for 3D data.
double south
Extent coordinates (south)
double bottom
Extent coordinates (bottom) - 3D data.
#define PROJECTION_LL
Projection code - Latitude-Longitude.
int depths
number of depths for 3D data
int G_lat_scan(const char *, double *)
int cols
Number of columns for 2D data.
double ns_res
Resolution - north to south cell size for 2D data.
void G_warning(const char *,...) __attribute__((format(printf
void G_lat_format(double, char *)
double east
Extent coordinates (east)
double ew_res
Resolution - east to west cell size for 2D data.
double tb_res
Resolution - top to bottom cell size for 3D data.
void G_lon_format(double, char *)
void void G_verbose_message(const char *,...) __attribute__((format(printf
int rows
Number of rows for 2D data.
int G_debug(int, const char *,...) __attribute__((format(printf
double ew_res3
Resolution - east to west cell size for 3D data.
int G_lon_scan(const char *, double *)