Cartography-Projection-GCTP
view release on metacpan or search on metacpan
gctpc/cproj.c view on Meta::CPAN
double eccent; /* Spheroid eccentricity */
double ts; /* Constant value t */
long *flag; /* Error flag number */
{
double eccnth;
double phi;
double con;
double dphi;
double sinpi;
long i;
*flag = 0;
eccnth = .5 * eccent;
phi = HALF_PI - 2 * atan(ts);
for (i = 0; i <= 15; i++)
{
sinpi = sin(phi);
con = eccent * sinpi;
dphi = HALF_PI - 2 * atan(ts *(pow(((1.0 - con)/(1.0 + con)),eccnth))) -
phi;
phi += dphi;
if (fabs(dphi) <= .0000000001)
return(phi);
}
p_error ("Convergence error","phi2z-conv");
*flag = 002;
return(002);
}
/* Function to compute latitude, phi3, for the inverse of the Equidistant
Conic projection.
-----------------------------------------------------------------*/
double phi3z(ml,e0,e1,e2,e3,flag)
double ml; /* Constant */
double e0; /* Constant */
double e1; /* Constant */
double e2; /* Constant */
double e3; /* Constant */
long *flag; /* Error flag number */
{
double phi;
double dphi;
long i;
phi = ml;
for (i = 0; i < 15; i++)
{
dphi = (ml + e1 * sin(2.0 * phi) - e2 * sin(4.0 * phi) + e3 * sin(6.0 * phi))
/ e0 - phi;
phi += dphi;
if (fabs(dphi) <= .0000000001)
{
*flag = 0;
return(phi);
}
}
p_error("Latitude failed to converge after 15 iterations","PHI3Z-CONV");
*flag = 3;
return(3);
}
/* Function to compute, phi4, the latitude for the inverse of the
Polyconic projection.
------------------------------------------------------------*/
double phi4z (eccent,e0,e1,e2,e3,a,b,c,phi)
double eccent; /* Spheroid eccentricity squared */
double e0;
double e1;
double e2;
double e3;
double a;
double b;
double *c;
double *phi;
{
double sinphi;
double sin2ph;
double tanphi;
double ml;
double mlp;
double con1;
double con2;
double con3;
double dphi;
long i;
*phi = a;
for (i = 1; i <= 15; i++)
{
sinphi = sin(*phi);
tanphi = tan(*phi);
*c = tanphi * sqrt (1.0 - eccent * sinphi * sinphi);
sin2ph = sin (2.0 * *phi);
/*
ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 * *phi);
mlp = e0 - 2.0 * e1 * cos (2.0 * *phi) + 4.0 * e2 *
cos (4.0 * *phi);
*/
ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 * *phi) - e3 *
sin (6.0 * *phi);
mlp = e0 - 2.0 * e1 * cos (2.0 * *phi) + 4.0 * e2 *
cos (4.0 * *phi) - 6.0 * e3 * cos (6.0 * *phi);
con1 = 2.0 * ml + *c * (ml * ml + b) - 2.0 * a * (*c * ml + 1.0);
con2 = eccent * sin2ph * (ml * ml + b - 2.0 * a * ml) / (2.0 * *c);
con3 = 2.0 * (a - ml) * (*c * mlp - 2.0 / sin2ph) - 2.0 * mlp;
dphi = con1 / (con2 + con3);
*phi += dphi;
if (fabs(dphi) <= .0000000001 )
return(OK);
}
p_error("Latitude failed to converge","phi4z-conv");
return(004);
}
/* Function to convert 2 digit alternate packed DMS format (+/-)DDDMMSS.SSS
to 3 digit standard packed DMS format (+/-)DDDMMMSSS.SSS.
( run in 1.166 second using v1.01-cache-2.11-cpan-71847e10f99 )