32 static const char PERMANENT[] =
"PERMANENT";
48 static int get_a_e2_f(
const char *,
const char *,
double *,
double *,
double *);
49 static int compare_ellipse_names(
const void *,
const void *);
50 static int get_ellipsoid_parameters(
struct Key_Value *,
double *,
double *);
76 if (access(ipath, 0) != 0) {
84 stat = get_ellipsoid_parameters(proj_keys, a, e2);
110 for (i = 0; i < table.count; i++) {
112 *a = table.ellipses[i].a;
113 *e2 = table.ellipses[i].e2;
135 return n >= 0 && n < table.count ? table.ellipses[n].name :
NULL;
159 for (i = 0; i < table.count; i++) {
161 *a = table.ellipses[i].a;
162 *e2 = table.ellipses[i].e2;
163 *f = table.ellipses[i].f;
185 return n >= 0 && n < table.count ? table.ellipses[n].descr :
NULL;
188 static int get_a_e2_f(
const char *s1,
const char *s2,
double *a,
double *e2,
193 if (sscanf(s1,
"a=%lf", a) != 1)
199 if (sscanf(s2,
"e=%lf", e2) == 1) {
200 *f = (double)1.0 / -sqrt(((
double)1.0 - *e2)) + (
double)1.0;
204 if (sscanf(s2,
"f=1/%lf", f) == 1) {
207 recipf = (double)1.0 / (*f);
208 *e2 = recipf + recipf - recipf * recipf;
212 if (sscanf(s2,
"b=%lf", &
b) == 1) {
220 recipf = ((*a) -
b) / (*a);
221 *f = (double)1.0 / recipf;
222 *e2 = recipf + recipf - recipf * recipf;
229 static int compare_ellipse_names(
const void *pa,
const void *pb)
231 const struct ellipse *a = pa;
232 const struct ellipse *
b = pb;
259 fd = fopen(
file,
"r");
263 _(
"Unable to open ellipsoid table file <%s>"),
file);
270 for (line = 1;
G_getl2(buf,
sizeof buf, fd); line++) {
271 char name[100], descr[100], buf1[100], buf2[100];
275 if (*buf == 0 || *buf ==
'#')
278 if (sscanf(buf,
"%s \"%99[^\"]\" %s %s",
name, descr, buf1, buf2) !=
281 sprintf(buf,
" %d", line);
283 strcat(badlines,
",");
284 strcat(badlines, buf);
288 if (table.count >= table.size) {
291 G_realloc(table.ellipses, table.size *
sizeof(
struct ellipse));
294 e = &table.ellipses[table.count];
299 if (get_a_e2_f(buf1, buf2, &e->a, &e->e2, &e->f) ||
300 get_a_e2_f(buf2, buf1, &e->a, &e->e2, &e->f))
304 sprintf(buf,
" %d", line);
306 strcat(badlines,
",");
307 strcat(badlines, buf);
316 qsort(table.ellipses, table.count,
sizeof(
struct ellipse),
317 compare_ellipse_names);
323 n_((
"Line%s of ellipsoid table file <%s> is invalid"),
324 (
"Lines%s of ellipsoid table file <%s> are invalid"),
err),
332 static int get_ellipsoid_parameters(
struct Key_Value *proj_keys,
double *a,
335 const char *str, *str1;
342 if (strncmp(str,
"sphere", 6) == 0) {
345 if (sscanf(str,
"%lf", a) != 1)
367 if ((str !=
NULL) && (str1 !=
NULL)) {
368 if (sscanf(str,
"%lf", a) != 1)
371 if (sscanf(str1,
"%lf", e2) != 1)
379 if ((str ==
NULL) || (strcmp(str,
"ll") == 0)) {
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
void G_strip(char *)
Removes all leading and trailing white space from string.
struct Key_Value * G_read_key_value_file(const char *)
Read key/values pairs from file.
int G_is_initialized(int *)
void G_initialize_done(int *)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
const char * G_gisbase(void)
Get full path name of the top level module directory.
char * G_store(const char *)
Copy string to allocated memory.
int G_read_ellipsoid_table(int fatal)
Read ellipsoid table.
int G_get_spheroid_by_name(const char *name, double *a, double *e2, double *f)
Get spheroid parameters by name.
const char * G_ellipsoid_name(int n)
Get ellipsoid name.
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
int G_get_ellipsoid_by_name(const char *name, double *a, double *e2)
Get ellipsoid parameters by name.
const char * G_ellipsoid_description(int n)
Get description for nth ellipsoid.
#define n_(strs, strp, num)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)