GRASS Programmer's Manual 6.4.1(2011)
|
00001 00017 #include <stdio.h> 00018 #include <grass/gis.h> 00019 00020 00021 static int scan_double(const char *, double *); 00022 00023 00037 int G_scan_northing(const char *buf, double *northing, int projection) 00038 { 00039 if (projection == PROJECTION_LL) { 00040 if (G_lat_scan(buf, northing)) 00041 return 1; 00042 if (!scan_double(buf, northing)) 00043 return 0; 00044 00045 return (*northing <= 90.0 && *northing >= -90.0); 00046 } 00047 00048 return scan_double(buf, northing); 00049 } 00050 00051 00065 int G_scan_easting(const char *buf, double *easting, int projection) 00066 { 00067 if (projection == PROJECTION_LL) { 00068 if (G_lon_scan(buf, easting)) 00069 return 1; 00070 if (!scan_double(buf, easting)) 00071 return 0; 00072 while (*easting > 180.0) 00073 *easting -= 360.0; 00074 while (*easting < -180.0) 00075 *easting += 360.0; 00076 00077 return 1; 00078 } 00079 00080 return scan_double(buf, easting); 00081 } 00082 00083 00097 int G_scan_resolution(const char *buf, double *res, int projection) 00098 { 00099 if (projection == PROJECTION_LL) { 00100 if (G_llres_scan(buf, res)) 00101 return 1; 00102 } 00103 00104 return (scan_double(buf, res) && *res > 0.0); 00105 } 00106 00107 00108 static int scan_double(const char *buf, double *value) 00109 { 00110 char junk[2]; 00111 00112 /* use sscanf to convert buf to double 00113 * make sure value doesn't have other characters after it */ 00114 00115 *junk = 0; 00116 *value = 0.0; 00117 00118 if (sscanf(buf, "%lf%1s", value, junk) == 1 && *junk == 0) { 00119 while (*buf) 00120 buf++; 00121 buf--; 00122 00123 if (*buf >= 'A' && *buf <= 'Z') 00124 return 0; 00125 if (*buf >= 'a' && *buf <= 'z') 00126 return 0; 00127 00128 return 1; /* success */ 00129 } 00130 00131 return 0; /* failure */ 00132 }