21 #include <grass/gis.h>
22 #include <grass/glocale.h>
23 #include <grass/gprojects.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 char *str, *str1, *str3;
99 "(rf, es or b) in file"));
101 if (get_a_e2_rf(str, str1, a, e2, rf) == 0)
103 "(a, rf, es or b) in file"));
108 if ((str ==
NULL) || (strcmp(str,
"ll") == 0)) {
137 while (list !=
NULL) {
141 estruct->a = list->
a;
142 estruct->es = list->
es;
143 estruct->rf = list->
rf;
154 get_a_e2_rf(
const char *s1,
const char *s2,
double *
a,
double *e2,
159 if (sscanf(s1,
"a=%lf", a) != 1)
165 if (sscanf(s2,
"e=%lf", e2) == 1) {
166 f = 1.0 - sqrt(1.0 - *e2);
171 if (sscanf(s2,
"f=1/%lf", recipf) == 1) {
179 if (sscanf(s2,
"b=%lf", &b) == 1) {
199 char file[GPATH_MAX];
201 char name[100], descr[1024], buf1[1024],
buf2[1024];
211 fd = fopen(file,
"r");
215 _(
"Unable to open ellipsoid table file <%s>"),
file);
221 for (line = 1;
G_getl2(buf,
sizeof buf, fd); line++) {
223 if (*buf == 0 || *buf ==
'#')
226 if (sscanf(buf,
"%s \"%1023[^\"]\" %s %s", name, descr, buf1, buf2)
237 if (get_a_e2_rf(buf1, buf2, &a, &e2, &rf)
238 || get_a_e2_rf(buf2, buf1, &a, &e2, &rf)) {
240 current = outputlist = G_malloc(
sizeof(
struct ellps_list));
268 ? _(
"Line%s of ellipsoid table file <%s> is invalid")
269 : _(
"Lines%s of ellipsoid table file <%s> are invalid"),
278 G_free(estruct->longname);
286 while (elist !=
NULL) {
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
void GPJ_free_datum(struct gpj_datum *dstruct)
Free the memory used for the strings in a gpj_datum struct.
char * G_store(const char *s)
Copy string to allocated memory.
char * G_strcat(char *T, const char *F)
This copies characters from the string F into the string T.
struct ellps_list * read_ellipsoid_table(int fatal)
int G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
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...
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
def fatal
Display an error message using g.message -e, then abort.
int GPJ__get_ellipsoid_params(struct Key_Value *proj_keys, double *a, double *e2, double *rf)
void GPJ_free_ellps(struct gpj_ellps *estruct)
int G_strip(char *buf)
Removes all leading and trailing white space from string.
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * G_gisbase(void)
top level module directory
int GPJ_get_ellipsoid_params(double *a, double *e2, double *rf)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
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 ...
struct Key_Value * G_create_key_value(void)
Allocate and initialize Key_Value structure.
void free_ellps_list(struct ellps_list *elist)