~ubuntu-branches/ubuntu/wily/proj/wily

« back to all changes in this revision

Viewing changes to src/pj_ell_set.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine, Jerome Villeneuve Larouche, Francesco Paolo Lovergine
  • Date: 2013-11-25 15:11:25 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20131125151125-mvcw144wvgep1hev
Tags: 4.8.0-1
[ Jerome Villeneuve Larouche ]
* New upstream release
* Modified libproj-dev.install to remove nad_list.h and projects.h
* Modified proj-bin.install to remove nad2nad
* Modified proj-bin.manpages to remove nad2nad man
* Added symbols for libproj0

[ Francesco Paolo Lovergine ]
* Properly merged with current git master and sid version 4.7.0-2.
* Removed proj transitional package and obsolete conflicts/replaces against
  series 4.6 and older.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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) {
11
11
        int i;
12
12
        double b=0.0, e;
13
13
        char *name;
14
14
        paralist *start = 0, *curr;
15
15
 
16
 
                /* check for varying forms of ellipsoid input */
 
16
        /* clear any previous error */
 
17
        pj_ctx_set_errno(ctx,0);
 
18
 
 
19
        /* check for varying forms of ellipsoid input */
17
20
        *a = *es = 0.;
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 */
22
25
 
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) {
25
28
                        char *s;
26
29
 
27
30
                        for (start = pl; start && start->next ; start = start->next) ;
28
31
                        curr = start;
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);
33
36
                }
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;
39
42
                        *es = e * e;
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;
42
45
                        if (!*es) {
43
 
                                pj_errno = -10;
 
46
                                pj_ctx_set_errno( ctx, -10);
44
47
                                goto bomb;
45
48
                        }
46
49
                        *es = 1./ *es;
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 */
55
58
                if (!b)
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));
60
63
                        *es = 0.;
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));
63
66
                        *es = 0.;
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);
66
69
                        *es = 0.;
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 */
68
71
                        *a = sqrt(*a * b);
69
72
                        *es = 0.;
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);
72
75
                        *es = 0.;
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 */
75
78
                        double tmp;
76
79
 
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) {
79
 
                                pj_errno = -11;
 
82
                                pj_ctx_set_errno(ctx,-11);
80
83
                                goto bomb;
81
84
                        }
82
85
                        tmp = 1. - *es * tmp * tmp;
90
93
                        pj_dalloc(start->next);
91
94
                        start->next = 0;
92
95
                }
93
 
                if (pj_errno)
 
96
                if (ctx->last_errno)
94
97
                        return 1;
95
98
        }
96
99
        /* some remaining checks */
97
100
        if (*es < 0.)
98
 
                { pj_errno = -12; return 1; }
 
101
                { pj_ctx_set_errno( ctx, -12); return 1; }
99
102
        if (*a <= 0.)
100
 
                { pj_errno = -13; return 1; }
 
103
                { pj_ctx_set_errno( ctx, -13); return 1; }
101
104
        return 0;
102
105
}