21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include <grass/gprojects.h>
24 #include "local_proto.h"
26 static int get_a_e2_rf(
const char *,
const char *,
double *,
double *,
42 if (proj_keys ==
NULL)
53 double *a,
double *e2,
double *rf)
55 struct gpj_ellps estruct;
56 struct gpj_datum dstruct;
57 const char *str, *str3;
74 if (ellps !=
NULL && *ellps) {
104 "(rf, es or b) in file"));
106 if (get_a_e2_rf(str4, str1, a, e2, rf) == 0)
108 "(a, rf, es or b) in file"));
113 if ((str ==
NULL) || (strcmp(str,
"ll") == 0)) {
138 struct ellps_list *
list, *listhead;
142 while (list !=
NULL) {
144 estruct->name =
G_store(list->name);
145 estruct->longname =
G_store(list->longname);
146 estruct->a = list->a;
147 estruct->es = list->es;
148 estruct->rf = list->rf;
159 get_a_e2_rf(
const char *s1,
const char *s2,
double *a,
double *e2,
164 if (sscanf(s1,
"a=%lf", a) != 1)
170 if (sscanf(s2,
"e=%lf", e2) == 1) {
171 f = 1.0 - sqrt(1.0 - *e2);
176 if (sscanf(s2,
"f=1/%lf", recipf) == 1) {
184 if (sscanf(s2,
"b=%lf", &b) == 1) {
204 char file[GPATH_MAX];
206 char name[100], descr[1024], buf1[1024], buf2[1024];
210 struct ellps_list *current =
NULL, *outputlist =
NULL;
215 sprintf(file,
"%s%s",
G_gisbase(), ELLIPSOIDTABLE);
216 fd = fopen(file,
"r");
220 _(
"Unable to open ellipsoid table file <%s>"),
file);
226 for (line = 1;
G_getl2(buf,
sizeof buf, fd); line++) {
228 if (*buf == 0 || *buf ==
'#')
231 if (sscanf(buf,
"%s \"%1023[^\"]\" %s %s", name, descr, buf1, buf2)
234 sprintf(buf,
" %d", line);
236 strcat(badlines,
",");
237 strcat(badlines, buf);
242 if (get_a_e2_rf(buf1, buf2, &a, &e2, &rf)
243 || get_a_e2_rf(buf2, buf1, &a, &e2, &rf)) {
245 current = outputlist = G_malloc(
sizeof(
struct ellps_list));
247 current = current->next = G_malloc(
sizeof(
struct ellps_list));
249 current->longname =
G_store(descr);
253 current->next =
NULL;
258 sprintf(buf,
" %d", line);
260 strcat(badlines,
",");
261 strcat(badlines, buf);
273 (
"Line%s of ellipsoid table file <%s> is invalid"),
274 (
"Lines%s of ellipsoid table file <%s> are invalid"),
284 G_free(estruct->longname);
290 struct ellps_list *old;
292 while (elist !=
NULL) {
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
const char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key (case sensitive)
void GPJ_free_datum(struct gpj_datum *dstruct)
Free the memory used for the strings in a gpj_datum struct.
void G_strip(char *buf)
Removes all leading and trailing white space from string.
struct ellps_list * read_ellipsoid_table(int fatal)
char * G_store(const char *s)
Copy string to allocated memory.
int G_asprintf(char **out, const char *fmt,...)
int GPJ_get_datum_by_name(const char *name, struct gpj_datum *dstruct)
Look up a string in datum.table file to see if it is a valid datum name and if so place its informati...
void G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
int GPJ__get_ellipsoid_params(const struct Key_Value *proj_keys, double *a, double *e2, double *rf)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
int G_getl2(char *buf, int n, FILE *fd)
Gets a line of text from a file of any pedigree.
void GPJ_free_ellps(struct gpj_ellps *estruct)
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
int GPJ_get_ellipsoid_params(double *a, double *e2, double *rf)
int GPJ_get_ellipsoid_by_name(const char *name, struct gpj_ellps *estruct)
looks up ellipsoid in ellipsoid table and returns the a, e2 parameters for the ellipsoid ...
void G_free(void *buf)
Free allocated memory.
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_warning(const char *msg,...)
Print a warning message to stderr.
struct Key_Value * G_create_key_value(void)
Allocate and initialize Key_Value structure.
void free_ellps_list(struct ellps_list *elist)