32 static const char PERMANENT[] =
"PERMANENT";
49 static int get_a_e2_f(
const char *,
const char *,
double *,
double *,
double *);
50 static int compare_ellipse_names(
const void *,
const void *);
51 static int get_ellipsoid_parameters(
struct Key_Value *,
double *,
double *);
77 if (access(ipath, 0) != 0) {
85 stat = get_ellipsoid_parameters(proj_keys, a, e2);
111 for (i = 0; i < table.count; i++) {
113 *a = table.ellipses[i].a;
114 *e2 = table.ellipses[i].e2;
136 return n >= 0 && n < table.count ? table.ellipses[n].name :
NULL;
160 for (i = 0; i < table.count; i++) {
162 *a = table.ellipses[i].a;
163 *e2 = table.ellipses[i].e2;
164 *f = table.ellipses[i].f;
187 return n >= 0 && n < table.count ? table.ellipses[n].descr :
NULL;
190 static int get_a_e2_f(
const char *s1,
const char *s2,
double *a,
double *e2,
double *f)
194 if (sscanf(s1,
"a=%lf", a) != 1)
200 if (sscanf(s2,
"e=%lf", e2) == 1) {
201 *f = (double)1.0 / -sqrt(((
double)1.0 - *e2)) + (
double)1.0;
205 if (sscanf(s2,
"f=1/%lf", f) == 1) {
208 recipf = (double)1.0 / (*f);
209 *e2 = recipf + recipf - recipf * recipf;
213 if (sscanf(s2,
"b=%lf", &b) == 1) {
221 recipf = ((*a) -
b) / (*a);
222 *f = (double)1.0 / recipf;
223 *e2 = recipf + recipf - recipf * recipf;
230 static int compare_ellipse_names(
const void *pa,
const void *pb)
232 const struct ellipse *a = pa;
233 const struct ellipse *
b = pb;
259 sprintf(file,
"%s/etc/proj/ellipse.table",
G_gisbase());
260 fd = fopen(file,
"r");
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) != 4) {
280 sprintf(buf,
" %d", line);
282 strcat(badlines,
",");
283 strcat(badlines, buf);
287 if (table.count >= table.size) {
289 table.ellipses =
G_realloc(table.ellipses, table.size *
sizeof(
struct ellipse));
292 e = &table.ellipses[table.count];
297 if (get_a_e2_f(buf1, buf2, &e->a, &e->e2, &e->f) ||
298 get_a_e2_f(buf2, buf1, &e->a, &e->e2, &e->f))
302 sprintf(buf,
" %d", line);
304 strcat(badlines,
",");
305 strcat(badlines, buf);
314 qsort(table.ellipses, table.count,
sizeof(
struct ellipse), compare_ellipse_names);
321 (
"Line%s of ellipsoid table file <%s> is invalid"),
322 (
"Lines%s of ellipsoid table file <%s> are invalid"),
331 static int get_ellipsoid_parameters(
struct Key_Value *proj_keys,
double *a,
double *e2)
333 const char *str, *str1;
340 if (strncmp(str,
"sphere", 6) == 0) {
343 if (sscanf(str,
"%lf", a) != 1)
365 if ((str !=
NULL) && (str1 !=
NULL)) {
366 if (sscanf(str,
"%lf", a) != 1)
369 if (sscanf(str1,
"%lf", e2) != 1)
377 if ((str ==
NULL) || (strcmp(str,
"ll") == 0)) {
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
struct Key_Value * G_read_key_value_file(const char *)
Read key/values pairs from file.
#define n_(strs, strp, num)
int G_get_ellipsoid_parameters(double *a, double *e2)
get ellipsoid parameters
void G_strip(char *)
Removes all leading and trailing white space from string.
const char * G_ellipsoid_name(int n)
Get ellipsoid name.
void G_initialize_done(int *)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
const char * G_ellipsoid_description(int n)
Get description for nth ellipsoid.
int G_get_ellipsoid_by_name(const char *name, double *a, double *e2)
Get ellipsoid parameters by name.
int G_get_spheroid_by_name(const char *name, double *a, double *e2, double *f)
Get spheroid parameters by name.
int G_is_initialized(int *)
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_warning(const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
int G_read_ellipsoid_table(int fatal)
Read ellipsoid table.
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)