PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Proj4/geod_set.c

http://github.com/route-me/route-me
C | 79 lines | 71 code | 3 blank | 5 comment | 23 complexity | c575464901c6918f962bba20d37f8286 MD5 | raw file
 1#ifndef lint
 2static const char SCCSID[]="@(#)geod_set.c	4.8	95/09/23	GIE	REL";
 3#endif
 4
 5#define _IN_GEOD_SET
 6
 7#include <string.h>
 8#include "projects.h"
 9#include "geodesic.h"
10#include "emess.h"
11	void
12geod_set(int argc, char **argv) {
13	paralist *start = 0, *curr = 0;
14	double es;
15	char *name;
16	int i;
17
18    /* put arguments into internal linked list */
19	if (argc <= 0)
20		emess(1, "no arguments in initialization list");
21	for (i = 0; i < argc; ++i)
22		if (i)
23			curr = curr->next = pj_mkparam(argv[i]);
24		else
25			start = curr = pj_mkparam(argv[i]);
26	/* set elliptical parameters */
27	if (pj_ell_set(start, &geod_a, &es)) emess(1,"ellipse setup failure");
28	/* set units */
29	name = pj_param(start, "sunits").s;
30	if (name) {
31		char *s;
32                struct PJ_UNITS *unit_list = pj_get_units_ref();
33		for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ;
34		if (!s)
35			emess(1,"%s unknown unit conversion id", name);
36		fr_meter = 1. / (to_meter = atof(unit_list[i].to_meter));
37	} else
38		to_meter = fr_meter = 1.;
39	ellipse = es != 0.;
40	if (ellipse) {
41		onef = sqrt(1. - es);
42		geod_f = 1 - onef;
43		f2 = geod_f/2;
44		f4 = geod_f/4;
45		f64 = geod_f*geod_f/64;
46	} else {
47		onef = 1.;
48		geod_f = f2 = f4 = f64 = 0.;
49	}
50	/* check if line or arc mode */
51	if (pj_param(start, "tlat_1").i) {
52		double del_S;
53#undef f
54		phi1 = pj_param(start, "rlat_1").f;
55		lam1 = pj_param(start, "rlon_1").f;
56		if (pj_param(start, "tlat_2").i) {
57			phi2 = pj_param(start, "rlat_2").f;
58			lam2 = pj_param(start, "rlon_2").f;
59			geod_inv();
60			geod_pre();
61		} else if ((geod_S = pj_param(start, "dS").f)) {
62			al12 = pj_param(start, "rA").f;
63			geod_pre();
64			geod_for();
65		} else emess(1,"incomplete geodesic/arc info");
66		if ((n_alpha = pj_param(start, "in_A").i) > 0) {
67			if (!(del_alpha = pj_param(start, "rdel_A").f))
68				emess(1,"del azimuth == 0");
69		} else if ((del_S = fabs(pj_param(start, "ddel_S").f))) {
70			n_S = geod_S / del_S + .5;
71		} else if ((n_S = pj_param(start, "in_S").i) <= 0)
72			emess(1,"no interval divisor selected");
73	}
74	/* free up linked list */
75	for ( ; start; start = curr) {
76		curr = start->next;
77		pj_dalloc(start);
78	}
79}