7
7
#define RV4 .06944444444444444444 /* 5/72 */
8
8
#define RV6 .04243827160493827160 /* 55/1296 */
9
9
int /* initialize geographic shape parameters */
10
pj_ell_set(paralist *pl, double *a, double *es) {
10
pj_ell_set(projCtx ctx, paralist *pl, double *a, double *es) {
14
14
paralist *start = 0, *curr;
16
/* check for varying forms of ellipsoid input */
16
/* clear any previous error */
17
pj_ctx_set_errno(ctx,0);
19
/* check for varying forms of ellipsoid input */
18
21
/* R takes precedence */
19
if (pj_param(pl, "tR").i)
20
*a = pj_param(pl, "dR").f;
22
if (pj_param(NULL, pl, "tR").i)
23
*a = pj_param(NULL,pl, "dR").f;
21
24
else { /* probable elliptical figure */
23
26
/* check if ellps present and temporarily append its values to pl */
24
if (name = pj_param(pl, "sellps").s) {
27
if ((name = pj_param(NULL,pl, "sellps").s) != NULL) {
27
30
for (start = pl; start && start->next ; start = start->next) ;
29
32
for (i = 0; (s = pj_ellps[i].id) && strcmp(name, s) ; ++i) ;
30
if (!s) { pj_errno = -9; return 1; }
33
if (!s) { pj_ctx_set_errno( ctx, -9); return 1; }
31
34
curr = curr->next = pj_mkparam(pj_ellps[i].major);
32
35
curr = curr->next = pj_mkparam(pj_ellps[i].ell);
34
*a = pj_param(pl, "da").f;
35
if (pj_param(pl, "tes").i) /* eccentricity squared */
36
*es = pj_param(pl, "des").f;
37
else if (pj_param(pl, "te").i) { /* eccentricity */
38
e = pj_param(pl, "de").f;
37
*a = pj_param(NULL,pl, "da").f;
38
if (pj_param(NULL,pl, "tes").i) /* eccentricity squared */
39
*es = pj_param(NULL,pl, "des").f;
40
else if (pj_param(NULL,pl, "te").i) { /* eccentricity */
41
e = pj_param(NULL,pl, "de").f;
40
} else if (pj_param(pl, "trf").i) { /* recip flattening */
41
*es = pj_param(pl, "drf").f;
43
} else if (pj_param(NULL,pl, "trf").i) { /* recip flattening */
44
*es = pj_param(NULL,pl, "drf").f;
46
pj_ctx_set_errno( ctx, -10);
47
50
*es = *es * (2. - *es);
48
} else if (pj_param(pl, "tf").i) { /* flattening */
49
*es = pj_param(pl, "df").f;
51
} else if (pj_param(NULL,pl, "tf").i) { /* flattening */
52
*es = pj_param(NULL,pl, "df").f;
50
53
*es = *es * (2. - *es);
51
} else if (pj_param(pl, "tb").i) { /* minor axis */
52
b = pj_param(pl, "db").f;
54
} else if (pj_param(NULL,pl, "tb").i) { /* minor axis */
55
b = pj_param(NULL,pl, "db").f;
53
56
*es = 1. - (b * b) / (*a * *a);
54
57
} /* else *es == 0. and sphere of radius *a */
56
59
b = *a * sqrt(1. - *es);
57
60
/* following options turn ellipsoid into equivalent sphere */
58
if (pj_param(pl, "bR_A").i) { /* sphere--area of ellipsoid */
61
if (pj_param(NULL,pl, "bR_A").i) { /* sphere--area of ellipsoid */
59
62
*a *= 1. - *es * (SIXTH + *es * (RA4 + *es * RA6));
61
} else if (pj_param(pl, "bR_V").i) { /* sphere--vol. of ellipsoid */
64
} else if (pj_param(NULL,pl, "bR_V").i) { /* sphere--vol. of ellipsoid */
62
65
*a *= 1. - *es * (SIXTH + *es * (RV4 + *es * RV6));
64
} else if (pj_param(pl, "bR_a").i) { /* sphere--arithmetic mean */
67
} else if (pj_param(NULL,pl, "bR_a").i) { /* sphere--arithmetic mean */
65
68
*a = .5 * (*a + b);
67
} else if (pj_param(pl, "bR_g").i) { /* sphere--geometric mean */
70
} else if (pj_param(NULL,pl, "bR_g").i) { /* sphere--geometric mean */
70
} else if (pj_param(pl, "bR_h").i) { /* sphere--harmonic mean */
73
} else if (pj_param(NULL,pl, "bR_h").i) { /* sphere--harmonic mean */
71
74
*a = 2. * *a * b / (*a + b);
73
} else if ((i = pj_param(pl, "tR_lat_a").i) || /* sphere--arith. */
74
pj_param(pl, "tR_lat_g").i) { /* or geom. mean at latitude */
76
} else if ((i = pj_param(NULL,pl, "tR_lat_a").i) || /* sphere--arith. */
77
pj_param(NULL,pl, "tR_lat_g").i) { /* or geom. mean at latitude */
77
tmp = sin(pj_param(pl, i ? "rR_lat_a" : "rR_lat_g").f);
80
tmp = sin(pj_param(NULL,pl, i ? "rR_lat_a" : "rR_lat_g").f);
78
81
if (fabs(tmp) > HALFPI) {
82
pj_ctx_set_errno(ctx,-11);
82
85
tmp = 1. - *es * tmp * tmp;