diff options
Diffstat (limited to 'src/PJ_vgridshift.c')
| -rw-r--r-- | src/PJ_vgridshift.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index 0f031d4f..d58972f4 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -1,25 +1,9 @@ #define PJ_LIB__ #include "proj_internal.h" -#include <projects.h> +#include "projects.h" PROJ_HEAD(vgridshift, "Vertical grid shift"); -static void *freeup_msg (PJ *P, int errlev) { - if (0==P) - return 0; - - if (0!=P->ctx) - pj_ctx_set_errno (P->ctx, errlev); - - return pj_dealloc(P); -} - - -static void freeup (PJ *P) { - freeup_msg (P, 0); - return; -} - static XYZ forward_3d(LPZ lpz, PJ *P) { PJ_TRIPLET point; @@ -74,7 +58,7 @@ PJ *PROJECTION(vgridshift) { if (!pj_param(P->ctx, P->params, "tgrids").i) { proj_log_error(P, "vgridshift: +grids parameter missing."); - return freeup_msg(P, -1); + return pj_default_destructor(P, PJD_ERR_NO_ARGS); } /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */ @@ -84,9 +68,7 @@ PJ *PROJECTION(vgridshift) { /* Was gridlist compiled properly? */ if ( pj_ctx_get_errno(P->ctx) ) { proj_log_error(P, "vgridshift: could not find required grid(s)."); - pj_dalloc(P->gridlist); - P->gridlist = NULL; - return freeup_msg(P, -38); + return pj_default_destructor(P, -38); } P->fwdobs = forward_obs; @@ -111,16 +93,21 @@ int pj_vgridshift_selftest (void) { PJ *P; PJ_OBS expect, a, b; double dist; + int failures = 0; /* fail on purpose: +grids parameter is mandatory*/ P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift"); - if (0!=P) + if (0!=P) { + proj_destroy (P); return 99; + } /* fail on purpose: open non-existing grid */ P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=nonexistinggrid.gtx"); - if (0!=P) + if (0!=P) { + proj_destroy (P); return 999; + } /* Failure most likely means the grid is missing */ P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80"); @@ -136,13 +123,21 @@ int pj_vgridshift_selftest (void) { return 1; expect = a; - expect.coo.lpz.z = -36.021305084228515625; + /* Appears there is a difference between the egm96_15.gtx distributed by OSGeo4W, */ + /* and the one from http://download.osgeo.org/proj/vdatum/egm96_15/egm96_15.gtx */ + /* Was: expect.coo.lpz.z = -36.021305084228515625; (download.osgeo.org) */ + /* Was: expect.coo.lpz.z = -35.880001068115234000; (OSGeo4W) */ + /* This is annoying, but must be handled elsewhere. So for now, we check for both. */ + expect.coo.lpz.z = -36.021305084228516; + failures = 0; b = proj_trans_obs(P, PJ_FWD, a); - if (proj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-10) + if (proj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-4) failures++; + expect.coo.lpz.z = -35.880001068115234000; + if (proj_xyz_dist(expect.coo.xyz, b.coo.xyz) > 1e-4) failures++; + if (failures > 1) return 2; - - - pj_free(P); + + proj_destroy (P); return 0; } |
