28 #include <grass/gis.h>
29 #include <grass/glocale.h>
40 static int count = -1;
44 static int get_a_e2_f(
const char *,
const char *,
double *,
double *,
47 static int compare_table_names(
const void *,
const void *);
48 static int read_ellipsoid_table(
int);
49 static int get_ellipsoid_parameters(
struct Key_Value *,
double *,
double *);
69 char ipath[GPATH_MAX];
70 struct Key_Value *proj_keys;
76 if (access(ipath, 0) != 0) {
89 stat = get_ellipsoid_parameters(proj_keys, a, e2);
114 (void)read_ellipsoid_table(0);
116 for (i = 0; i <
count; i++) {
140 (void)read_ellipsoid_table(0);
141 return n >= 0 && n <
count ? table[
n].name :
NULL;
175 (void)read_ellipsoid_table(0);
177 for (i = 0; i <
count; i++) {
204 (void)read_ellipsoid_table(0);
205 return n >= 0 && n <
count ? table[
n].descr :
NULL;
209 get_a_e2_f(
const char *s1,
const char *s2,
double *a,
double *e2,
double *f)
213 if (sscanf(s1,
"a=%lf", a) != 1)
219 if (sscanf(s2,
"e=%lf", e2) == 1) {
220 *f = (double)1.0 / -sqrt(((
double)1.0 - *e2)) + (
double)1.0;
224 if (sscanf(s2,
"f=1/%lf", f) == 1) {
227 recipf = (double)1.0 / (*f);
228 *e2 = recipf + recipf - recipf * recipf;
232 if (sscanf(s2,
"b=%lf", &b) == 1) {
240 recipf = ((*a) -
b) / (*a);
241 *f = (double)1.0 / recipf;
242 *e2 = recipf + recipf - recipf * recipf;
255 static int compare_table_names(
const void *pa,
const void *pb)
257 const struct table *a = pa, *b = pb;
263 static int read_ellipsoid_table(
int fatal)
266 char file[GPATH_MAX];
268 char name[100], descr[100], buf1[100],
buf2[100];
279 fd = fopen(file,
"r");
283 sprintf(buf, _(
"Unable to open ellipsoid table file <%s>"), file);
290 for (line = 1;
G_getl2(buf,
sizeof buf, fd); line++) {
292 if (*buf == 0 || *buf ==
'#')
295 if (sscanf(buf,
"%s \"%99[^\"]\" %s %s", name, descr, buf1, buf2) !=
306 (
struct table *)G_realloc((
char *)table,
307 (
count + 1) *
sizeof(*table));
313 || get_a_e2_f(buf2, buf1, &table[
count].a, &table[
count].e2,
330 qsort(table,
count,
sizeof(*table), compare_table_names);
336 _(
"Lines%s of ellipsoid table file <%s> are invalid")
338 _(
"Line%s of ellipsoid table file <%s> is invalid"),
344 static int get_ellipsoid_parameters(
struct Key_Value *proj_keys,
double *a,
354 if (strncmp(str,
"sphere", 6) == 0) {
357 if (sscanf(str,
"%lf", a) != 1) {
371 G_fatal_error(_(
"Invalid ellipsoid '%s' in file %s in <%s>"),
382 if ((str !=
NULL) && (str1 !=
NULL)) {
383 if (sscanf(str,
"%lf", a) != 1) {
387 if (sscanf(str1,
"%lf", e2) != 1) {
388 G_fatal_error(_(
"Invalid es: field '%s' in file %s in <%s>"),
396 if ((str ==
NULL) || (strcmp(str,
"ll") == 0)) {
402 G_fatal_error(_(
"No ellipsoid info given in file %s in <%s>"),
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)
char * G_store(const char *s)
Copy string to allocated memory.
void ellipsoid_table_file(char *)
char * G_strcat(char *T, const char *F)
This copies characters from the string F into the string T.
int G_free_key_value(struct Key_Value *kv)
Free allocated Key_Value structure.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
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.
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
struct Key_Value * G_read_key_value_file(const char *file, int *stat)
Read key/values pairs from file.
int G_strip(char *buf)
Removes all leading and trailing white space from string.
char * G_ellipsoid_description(int n)
get description for nth ellipsoid
char * G_ellipsoid_name(int n)
get ellipsoid name
int G_get_ellipsoid_by_name(const char *name, double *a, double *e2)
get ellipsoid parameters by name
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_get_spheroid_by_name(const char *name, double *a, double *e2, double *f)
get spheroid parameters by name
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * G_gisbase(void)
top level module directory
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.