GRASS GIS 7 Programmer's Manual  7.0.2(2015)-r00000
wind_scan.c
Go to the documentation of this file.
1 
14 #include <stdio.h>
15 #include <grass/gis.h>
16 
17 static int scan_double(const char *, double *);
18 
38 int G_scan_northing(const char *buf, double *northing, int projection)
39 {
40  if (projection == PROJECTION_LL) {
41  if (G_lat_scan(buf, northing))
42  return 1;
43  if (!scan_double(buf, northing))
44  return 0;
45 
46  return (*northing <= 90.0 && *northing >= -90.0);
47  }
48 
49  return scan_double(buf, northing);
50 }
51 
71 int G_scan_easting(const char *buf, double *easting, int projection)
72 {
73  if (projection == PROJECTION_LL) {
74  if (G_lon_scan(buf, easting))
75  return 1;
76  if (!scan_double(buf, easting))
77  return 0;
78  while (*easting > 180.0)
79  *easting -= 360.0;
80  while (*easting < -180.0)
81  *easting += 360.0;
82 
83  return 1;
84  }
85 
86  return scan_double(buf, easting);
87 }
88 
108 int G_scan_resolution(const char *buf, double *res, int projection)
109 {
110  if (projection == PROJECTION_LL) {
111  if (G_llres_scan(buf, res))
112  return 1;
113  }
114 
115  return (scan_double(buf, res) && *res > 0.0);
116 }
117 
118 static int scan_double(const char *buf, double *value)
119 {
120  char junk[2];
121 
122  /* use sscanf to convert buf to double
123  * make sure value doesn't have other characters after it */
124 
125  *junk = 0;
126  *value = 0.0;
127 
128  if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) {
129  while (*buf)
130  buf++;
131  buf--;
132 
133  if (*buf >= 'A' && *buf <= 'Z')
134  return 0;
135  if (*buf >= 'a' && *buf <= 'z')
136  return 0;
137 
138  return 1; /* success */
139  }
140 
141  return 0; /* failure */
142 }
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
Definition: wind_scan.c:108
int G_lat_scan(const char *buf, double *lat)
Definition: ll_scan.c:44
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Definition: wind_scan.c:38
int G_llres_scan(const char *buf, double *res)
Definition: ll_scan.c:54
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
Definition: wind_scan.c:71
int G_lon_scan(const char *buf, double *lon)
Definition: ll_scan.c:49