GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wind_scan.c
Go to the documentation of this file.
1 
17 #include <stdio.h>
18 #include <grass/gis.h>
19 
20 
21 static int scan_double(const char *, double *);
22 
23 
37 int G_scan_northing(const char *buf, double *northing, int projection)
38 {
39  if (projection == PROJECTION_LL) {
40  if (G_lat_scan(buf, northing))
41  return 1;
42  if (!scan_double(buf, northing))
43  return 0;
44 
45  return (*northing <= 90.0 && *northing >= -90.0);
46  }
47 
48  return scan_double(buf, northing);
49 }
50 
51 
65 int G_scan_easting(const char *buf, double *easting, int projection)
66 {
67  if (projection == PROJECTION_LL) {
68  if (G_lon_scan(buf, easting))
69  return 1;
70  if (!scan_double(buf, easting))
71  return 0;
72  while (*easting > 180.0)
73  *easting -= 360.0;
74  while (*easting < -180.0)
75  *easting += 360.0;
76 
77  return 1;
78  }
79 
80  return scan_double(buf, easting);
81 }
82 
83 
97 int G_scan_resolution(const char *buf, double *res, int projection)
98 {
99  if (projection == PROJECTION_LL) {
100  if (G_llres_scan(buf, res))
101  return 1;
102  }
103 
104  return (scan_double(buf, res) && *res > 0.0);
105 }
106 
107 
108 static int scan_double(const char *buf, double *value)
109 {
110  char junk[2];
111 
112  /* use sscanf to convert buf to double
113  * make sure value doesn't have other characters after it */
114 
115  *junk = 0;
116  *value = 0.0;
117 
118  if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) {
119  while (*buf)
120  buf++;
121  buf--;
122 
123  if (*buf >= 'A' && *buf <= 'Z')
124  return 0;
125  if (*buf >= 'a' && *buf <= 'z')
126  return 0;
127 
128  return 1; /* success */
129  }
130 
131  return 0; /* failure */
132 }
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
Definition: wind_scan.c:97
int G_lat_scan(const char *buf, double *lat)
Definition: ll_scan.c:44
char * value
Definition: env.c:30
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int G_scan_northing(const char *buf, double *northing, int projection)
ASCII northing to double.
Definition: wind_scan.c:37
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:65
int G_lon_scan(const char *buf, double *lon)
Definition: ll_scan.c:49