GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71817
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wind_scan.c
Go to the documentation of this file.
1 /*!
2  \file lib/gis/wind_scan.c
3 
4  \brief GIS Library - Coordinate scanning functions.
5 
6  (C) 2001-2009, 2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Original author CERL
12 */
13 
14 #include <stdio.h>
15 #include <grass/gis.h>
16 
17 static int scan_double(const char *, double *);
18 
19 /*!
20  \brief ASCII northing to double.
21 
22  Converts the ASCII "northing" coordinate string in <i>buf</i> to its
23  double representation (into <i>northing</i>).
24 
25  Supported projection codes (see gis.h):
26  - PROJECTION_XY
27  - PROJECTION_UTM
28  - PROJECTION_LL
29  - PROJECTION_OTHER
30 
31  \param buf buffer hold string northing
32  \param[out] northing northing
33  \param projection projection code
34 
35  \return 0 on error
36  \return 1 on success
37 */
38 int G_scan_northing(const char *buf, double *northing, int projection)
39 {
40  if (projection == PROJECTION_LL) {
41  if (!scan_double(buf, northing))
42  return G_lat_scan(buf, northing);
43 
44  return 1;
45  }
46 
47  return scan_double(buf, northing);
48 }
49 
50 /*!
51  \brief ASCII easting to double.
52 
53  Converts the ASCII "easting" coordinate string in <i>buf</i> to its
54  double representation (into <i>easting</i>).
55 
56  Supported projection codes (see gis.h):
57  - PROJECTION_XY
58  - PROJECTION_UTM
59  - PROJECTION_LL
60  - PROJECTION_OTHER
61 
62  \param buf buffer containing string easting
63  \param[out] easting easting
64  \param projection projection code
65 
66  \return 0 on error
67  \return 1 on success
68 */
69 int G_scan_easting(const char *buf, double *easting, int projection)
70 {
71  if (projection == PROJECTION_LL) {
72  if (!scan_double(buf, easting))
73  return G_lon_scan(buf, easting);
74 
75  return 1;
76  }
77 
78  return scan_double(buf, easting);
79 }
80 
81 /*!
82  \brief ASCII resolution to double.
83 
84  Converts the ASCII "resolution" string in <i>buf</i> to its double
85  representation (into resolution).
86 
87  Supported projection codes (see gis.h):
88  - PROJECTION_XY
89  - PROJECTION_UTM
90  - PROJECTION_LL
91  - PROJECTION_OTHER
92 
93  \param buf buffer containing string resolution
94  \param[out] resolution resolution value
95  \param projection projection code
96 
97  \return 0 on error
98  \return 1 on success
99 */
100 int G_scan_resolution(const char *buf, double *res, int projection)
101 {
102  if (projection == PROJECTION_LL) {
103  if (G_llres_scan(buf, res))
104  return (*res > 0.0);
105  }
106 
107  return (scan_double(buf, res) && *res > 0.0);
108 }
109 
110 static int scan_double(const char *buf, double *value)
111 {
112  char junk[2];
113 
114  /* use sscanf to convert buf to double
115  * make sure value doesn't have other characters after it */
116 
117  *junk = 0;
118  *value = 0.0;
119 
120  if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) {
121  while (*buf)
122  buf++;
123  buf--;
124 
125  if (*buf >= 'A' && *buf <= 'Z')
126  return 0;
127  if (*buf >= 'a' && *buf <= 'z')
128  return 0;
129 
130  return 1; /* success */
131  }
132 
133  return 0; /* failure */
134 }
int G_scan_resolution(const char *buf, double *res, int projection)
ASCII resolution to double.
Definition: wind_scan.c:100
int G_lat_scan(const char *buf, double *lat)
Definition: ll_scan.c:46
#define PROJECTION_LL
Projection code - Latitude-Longitude.
Definition: gis.h:99
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:56
int G_scan_easting(const char *buf, double *easting, int projection)
ASCII easting to double.
Definition: wind_scan.c:69
int G_lon_scan(const char *buf, double *lon)
Definition: ll_scan.c:51