From d96ad04833f4c857d4dda2560387b8e8053d821b Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Mon, 18 Apr 2016 14:02:19 +0200 Subject: Expanded tabs and removed trailing whitespace in an attempt at getting cleaner diffs for upcomming commits. --- src/PJ_goode.c | 70 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/PJ_goode.c') diff --git a/src/PJ_goode.c b/src/PJ_goode.c index 387557e6..b03e15d1 100644 --- a/src/PJ_goode.c +++ b/src/PJ_goode.c @@ -1,49 +1,49 @@ #define PROJ_PARMS__ \ - struct PJconsts *sinu; \ - struct PJconsts *moll; + struct PJconsts *sinu; \ + struct PJconsts *moll; #define PJ_LIB__ -#include +#include PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph."; - C_NAMESPACE PJ + C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *); -#define Y_COR 0.05280 -#define PHI_LIM .71093078197902358062 +#define Y_COR 0.05280 +#define PHI_LIM .71093078197902358062 FORWARD(s_forward); /* spheroid */ - if (fabs(lp.phi) <= PHI_LIM) - xy = P->sinu->fwd(lp, P->sinu); - else { - xy = P->moll->fwd(lp, P->moll); - xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR; - } - return (xy); + if (fabs(lp.phi) <= PHI_LIM) + xy = P->sinu->fwd(lp, P->sinu); + else { + xy = P->moll->fwd(lp, P->moll); + xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR; + } + return (xy); } INVERSE(s_inverse); /* spheroid */ - if (fabs(xy.y) <= PHI_LIM) - lp = P->sinu->inv(xy, P->sinu); - else { - xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR; - lp = P->moll->inv(xy, P->moll); - } - return (lp); + if (fabs(xy.y) <= PHI_LIM) + lp = P->sinu->inv(xy, P->sinu); + else { + xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR; + lp = P->moll->inv(xy, P->moll); + } + return (lp); } FREEUP; - if (P) { - if (P->sinu) - (*(P->sinu->pfree))(P->sinu); - if (P->moll) - (*(P->moll->pfree))(P->moll); - pj_dalloc(P); - } + if (P) { + if (P->sinu) + (*(P->sinu->pfree))(P->sinu); + if (P->moll) + (*(P->moll->pfree))(P->moll); + pj_dalloc(P); + } } ENTRY2(goode, sinu, moll) - P->es = 0.; - if (!(P->sinu = pj_sinu(0)) || !(P->moll = pj_moll(0))) - E_ERROR_0; - P->sinu->es = 0.; + P->es = 0.; + if (!(P->sinu = pj_sinu(0)) || !(P->moll = pj_moll(0))) + E_ERROR_0; + P->sinu->es = 0.; P->sinu->ctx = P->ctx; P->moll->ctx = P->ctx; - if (!(P->sinu = pj_sinu(P->sinu)) || !(P->moll = pj_moll(P->moll))) - E_ERROR_0; - P->fwd = s_forward; - P->inv = s_inverse; + if (!(P->sinu = pj_sinu(P->sinu)) || !(P->moll = pj_moll(P->moll))) + E_ERROR_0; + P->fwd = s_forward; + P->inv = s_inverse; ENDENTRY(P) -- cgit v1.2.3 From eca42acae89ad5892cb14a29ae7be46891e5c059 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Tue, 19 Apr 2016 09:37:35 +0200 Subject: Converted goode --- src/PJ_goode.c | 177 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 128 insertions(+), 49 deletions(-) (limited to 'src/PJ_goode.c') diff --git a/src/PJ_goode.c b/src/PJ_goode.c index b03e15d1..d577f901 100644 --- a/src/PJ_goode.c +++ b/src/PJ_goode.c @@ -1,49 +1,128 @@ -#define PROJ_PARMS__ \ - struct PJconsts *sinu; \ - struct PJconsts *moll; -#define PJ_LIB__ -#include -PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph."; - C_NAMESPACE PJ -*pj_sinu(PJ *), *pj_moll(PJ *); -#define Y_COR 0.05280 -#define PHI_LIM .71093078197902358062 -FORWARD(s_forward); /* spheroid */ - if (fabs(lp.phi) <= PHI_LIM) - xy = P->sinu->fwd(lp, P->sinu); - else { - xy = P->moll->fwd(lp, P->moll); - xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR; - } - return (xy); -} -INVERSE(s_inverse); /* spheroid */ - if (fabs(xy.y) <= PHI_LIM) - lp = P->sinu->inv(xy, P->sinu); - else { - xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR; - lp = P->moll->inv(xy, P->moll); - } - return (lp); -} -FREEUP; - if (P) { - if (P->sinu) - (*(P->sinu->pfree))(P->sinu); - if (P->moll) - (*(P->moll->pfree))(P->moll); - pj_dalloc(P); - } -} -ENTRY2(goode, sinu, moll) - P->es = 0.; - if (!(P->sinu = pj_sinu(0)) || !(P->moll = pj_moll(0))) - E_ERROR_0; - P->sinu->es = 0.; - P->sinu->ctx = P->ctx; - P->moll->ctx = P->ctx; - if (!(P->sinu = pj_sinu(P->sinu)) || !(P->moll = pj_moll(P->moll))) - E_ERROR_0; - P->fwd = s_forward; - P->inv = s_inverse; -ENDENTRY(P) +#define PJ_LIB__ +#include + +PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph."; + +#define Y_COR 0.05280 +#define PHI_LIM 0.71093078197902358062 + +struct pj_opaque { + struct PJconsts *sinu; \ + struct PJconsts *moll; +}; + + +static XY s_forward (LP lp, PJ *P) { /* Spheroidal, forward */ + XY xy = {0.0,0.0}; + struct pj_opaque *Q = P->opaque; + + if (fabs(lp.phi) <= PHI_LIM) + xy = Q->sinu->fwd(lp, Q->sinu); + else { + xy = Q->moll->fwd(lp, Q->moll); + xy.y -= lp.phi >= 0.0 ? Y_COR : -Y_COR; + } + return xy; +} + + +static LP s_inverse (XY xy, PJ *P) { /* Spheroidal, inverse */ + LP lp = {0.0,0.0}; + struct pj_opaque *Q = P->opaque; + + if (fabs(xy.y) <= PHI_LIM) + lp = Q->sinu->inv(xy, Q->sinu); + else { + xy.y += xy.y >= 0.0 ? Y_COR : -Y_COR; + lp = Q->moll->inv(xy, Q->moll); + } + return lp; +} + + +static void *freeup_new (PJ *P) { /* Destructor */ + if (0==P) + return 0; + if (0==P->opaque) + return pj_dealloc(P); + if (P->opaque->sinu) + pj_dealloc(P->opaque->sinu); + if (P->opaque->moll) + pj_dealloc(P->opaque->moll); + pj_dealloc (P->opaque); + return pj_dealloc(P); + +} + + +static void freeup (PJ *P) { + freeup_new (P); + return; +} + + +PJ *PROJECTION(goode) { + struct pj_opaque *Q = pj_calloc (1, sizeof (struct pj_opaque)); + if (0==Q) + return freeup_new (P); + P->opaque = Q; + + P->es = 0.; + if (!(Q->sinu = pj_sinu(0)) || !(Q->moll = pj_moll(0))) + E_ERROR_0; + Q->sinu->es = 0.; + Q->sinu->ctx = P->ctx; + Q->moll->ctx = P->ctx; + if (!(Q->sinu = pj_sinu(Q->sinu)) || !(Q->moll = pj_moll(Q->moll))) + E_ERROR_0; + + P->fwd = s_forward; + P->inv = s_inverse; + + return P; +} + + +#ifdef PJ_OMIT_SELFTEST +int pj_goode_selftest (void) {return 0;} +#else + +int pj_goode_selftest (void) { + double tolerance_lp = 1e-10; + double tolerance_xy = 1e-7; + + char s_args[] = {"+proj=goode +a=6400000 +lat_1=0.5 +lat_2=2"}; + + LP fwd_in[] = { + { 2, 1}, + { 2,-1}, + {-2, 1}, + {-2,-1} + }; + + XY s_fwd_expect[] = { + { 223368.11902663155, 111701.07212763709 }, + { 223368.11902663155, -111701.07212763709 }, + {-223368.11902663155, 111701.07212763709 }, + {-223368.11902663155, -111701.07212763709 }, + }; + + XY inv_in[] = { + { 200, 100}, + { 200,-100}, + {-200, 100}, + {-200,-100} + }; + + LP s_inv_expect[] = { + { 0.0017904931100023887, 0.00089524655489191132 }, + { 0.0017904931100023887, -0.00089524655489191132 }, + {-0.0017904931100023887, 0.00089524655489191132 }, + {-0.0017904931100023887, -0.00089524655489191132 }, + }; + + return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 4, fwd_in, 0, s_fwd_expect, inv_in, 0, s_inv_expect); +} + + +#endif -- cgit v1.2.3 From 9687e69b177933c2894adc842f6aa507fc70ca16 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Wed, 20 Apr 2016 18:10:00 +0200 Subject: Portability cleanups for the code in PR #5 Eliminated load time non-constant initializers, mixed code/declarations and C++ style comments. A lot of non-constant initializers remain in PJ_healpix. Should probably be handled before next release. --- src/PJ_goode.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'src/PJ_goode.c') diff --git a/src/PJ_goode.c b/src/PJ_goode.c index d577f901..48fc9ad5 100644 --- a/src/PJ_goode.c +++ b/src/PJ_goode.c @@ -6,9 +6,11 @@ PROJ_HEAD(goode, "Goode Homolosine") "\n\tPCyl, Sph."; #define Y_COR 0.05280 #define PHI_LIM 0.71093078197902358062 +C_NAMESPACE PJ *pj_sinu(PJ *), *pj_moll(PJ *); + struct pj_opaque { - struct PJconsts *sinu; \ - struct PJconsts *moll; + PJ *sinu; + PJ *moll; }; @@ -101,11 +103,7 @@ int pj_goode_selftest (void) { }; XY s_fwd_expect[] = { - { 223368.11902663155, 111701.07212763709 }, - { 223368.11902663155, -111701.07212763709 }, - {-223368.11902663155, 111701.07212763709 }, - {-223368.11902663155, -111701.07212763709 }, - }; + { 223368.11902663155, 111701.07212763709}, { 223368.11902663155, -111701.07212763709}, {-223368.11902663155, 111701.07212763709}, {-223368.11902663155, -111701.07212763709}, }; XY inv_in[] = { { 200, 100}, @@ -115,11 +113,7 @@ int pj_goode_selftest (void) { }; LP s_inv_expect[] = { - { 0.0017904931100023887, 0.00089524655489191132 }, - { 0.0017904931100023887, -0.00089524655489191132 }, - {-0.0017904931100023887, 0.00089524655489191132 }, - {-0.0017904931100023887, -0.00089524655489191132 }, - }; + { 0.0017904931100023887, 0.00089524655489191132}, { 0.0017904931100023887, -0.00089524655489191132}, {-0.0017904931100023887, 0.00089524655489191132}, {-0.0017904931100023887, -0.00089524655489191132}, }; return pj_generic_selftest (0, s_args, tolerance_xy, tolerance_lp, 4, 4, fwd_in, 0, s_fwd_expect, inv_in, 0, s_inv_expect); } -- cgit v1.2.3