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)"),
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)"),
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)
529 " (East: %g, West: %g)"),
532 else if (cellhd->
east - cellhd->
west < 360.0) {
534 if (diff < 1.0 && diff > fpepsilon)
556 int ll_adjust, res_adj;
558 char buf[100], buf2[100];
601 old = cellhds.
ns_res * 3600;
602 sprintf(buf,
"%f", old);
603 sscanf(buf,
"%lf", &
new);
606 old = cellhds.
ew_res * 3600;
607 sprintf(buf,
"%f", old);
608 sscanf(buf,
"%lf", &
new);
611 old = cellhds.
north * 3600;
612 sprintf(buf,
"%f", old);
613 sscanf(buf,
"%lf", &
new);
616 old = cellhds.
south * 3600;
617 sprintf(buf,
"%f", old);
618 sscanf(buf,
"%lf", &
new);
621 old = cellhds.
west * 3600;
622 sprintf(buf,
"%f", old);
623 sscanf(buf,
"%lf", &
new);
626 old = cellhds.
east * 3600;
627 sprintf(buf,
"%f", old);
628 sscanf(buf,
"%lf", &
new);
641 dsec2 = floor(dsec + 0.5);
643 diff = fabs(dsec2 - dsec) / dsec;
644 if (diff > 0 && diff < llepsilon) {
647 if (strcmp(buf, buf2))
661 dsec2 = floor(dsec + 0.5);
662 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
667 dsec2 = floor(dsec + 0.5);
668 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
671 if (n_off < llepsilon || n_off <= s_off) {
674 dsec2 = floor(dsec + 0.5);
677 if (diff > 0 && diff < llepsilon) {
680 if (strcmp(buf, buf2))
688 diff = fabs(
new - old) / cellhds.
ns_res;
692 if (strcmp(buf, buf2))
701 dsec2 = floor(dsec + 0.5);
704 if (diff > 0 && diff < llepsilon) {
707 if (strcmp(buf, buf2))
715 diff = fabs(
new - old) / cellhds.
ns_res;
719 if (strcmp(buf, buf2))
729 dsec2 = floor(dsec + 0.5);
731 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
732 if (diff > 0 && diff < llepsilon) {
735 if (strcmp(buf, buf2))
744 dsec2 = floor(dsec + 0.5);
746 diff = fabs(dsec2 - dsec) / (cellhds.
ns_res * 10);
747 if (diff > 0 && diff < llepsilon) {
750 if (strcmp(buf, buf2))
767 dsec2 = floor(dsec + 0.5);
769 diff = fabs(dsec2 - dsec) / dsec;
770 if (diff > 0 && diff < llepsilon) {
773 if (strcmp(buf, buf2))
787 dsec2 = floor(dsec + 0.5);
788 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
793 dsec2 = floor(dsec + 0.5);
794 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
797 if (w_off < llepsilon || w_off <= e_off) {
800 dsec2 = floor(dsec + 0.5);
803 if (diff > 0 && diff < llepsilon) {
806 if (strcmp(buf, buf2))
814 diff = fabs(
new - old) / cellhds.
ew_res;
818 if (strcmp(buf, buf2))
827 dsec2 = floor(dsec + 0.5);
830 if (diff > 0 && diff < llepsilon) {
833 if (strcmp(buf, buf2))
841 diff = fabs(
new - cellhds.
west) / cellhds.
ew_res;
845 if (strcmp(buf, buf2))
855 dsec2 = floor(dsec + 0.5);
857 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
858 if (diff > 0 && diff < llepsilon) {
861 if (strcmp(buf, buf2))
870 dsec2 = floor(dsec + 0.5);
872 diff = fabs(dsec2 - dsec) / (cellhds.
ew_res * 10);
873 if (diff > 0 && diff < llepsilon) {
876 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)