From 6b07474e9427d53134e77f0bdf3ced7812d080c4 Mon Sep 17 00:00:00 2001 From: Kristian Evers Date: Wed, 13 Sep 2017 13:27:14 +0200 Subject: Introduce PJ_DEFAULT_CTX constant that improves code readability --- src/PJ_vgridshift.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index e790cd4d..0f031d4f 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -112,18 +112,18 @@ int pj_vgridshift_selftest (void) { PJ_OBS expect, a, b; double dist; - /* fail on purpose: +grids parameter it mandatory*/ - P = proj_create(0, "+proj=vgridshift"); + /* fail on purpose: +grids parameter is mandatory*/ + P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift"); if (0!=P) return 99; /* fail on purpose: open non-existing grid */ - P = proj_create(0, "+proj=vgridshift +grids=nonexistinggrid.gtx"); + P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=nonexistinggrid.gtx"); if (0!=P) return 999; /* Failure most likely means the grid is missing */ - P = proj_create (0, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80"); + P = proj_create(PJ_DEFAULT_CTX, "+proj=vgridshift +grids=egm96_15.gtx +ellps=GRS80"); if (0==P) return 10; -- cgit v1.2.3 From 664577ced6a8e4074b1f53af82b5ae5d1d189eac Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Wed, 27 Sep 2017 13:56:34 +0200 Subject: Enable default destructor for all PJ objects. In most cases memory deallocation is completely removed from the code since it can be handled by the default destructor. In a few special cases a local destructor overrides the default destructor and makes sure that locally allocated memored is cleaned up correctly. Move all deallocation from pj_free to pj_default_destructor Rename pj_latlong.c to fit with the conventional format PJ_latlong.c - freeup was missed here due to wrong naming Clean up pj_init to avoid double deallocation; Also resolve #576 by adding z_0 and t_0 options in pj_init, while cleaning Add a prototype for dealloc_params Added missing errno.h include in pj_ctx.c Temporarily removing ob_tran from testvarious, to be sure that is where the trouble is Make PJ_ob_tran.c use proper initialization for the chained projection proj=ob_tran: make it clear, that we disallow ellipsoidal projections, and, for improved backwards compatibility, turns off default settings, which could inject unwanted ellipsoid definitions ... then also remove the ellipsoid definition from the testvarious test case - which is probably buggy anyway Work around cs2cs spherical init bug in testvarious; Forbid defs for ob_tran in pj_init --- src/PJ_vgridshift.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'src/PJ_vgridshift.c') 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 +#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; } -- cgit v1.2.3 From efa741bafb0f40d4d7b7f9138292f15965ed5d75 Mon Sep 17 00:00:00 2001 From: Thomas Knudsen Date: Fri, 6 Oct 2017 22:21:55 +0200 Subject: Switch proj_roundtrip to accept PJ_COORD, rather than PJ_OBS, and make it do proper geodesic distances for forward roundtrips --- src/PJ_vgridshift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/PJ_vgridshift.c') diff --git a/src/PJ_vgridshift.c b/src/PJ_vgridshift.c index d58972f4..ededd544 100644 --- a/src/PJ_vgridshift.c +++ b/src/PJ_vgridshift.c @@ -118,7 +118,7 @@ int pj_vgridshift_selftest (void) { a.coo.lpz.lam = PJ_TORAD(12.5); a.coo.lpz.phi = PJ_TORAD(55.5); - dist = proj_roundtrip (P, PJ_FWD, 1, a); + dist = proj_roundtrip (P, PJ_FWD, 1, a.coo); if (dist > 0.00000001) return 1; -- cgit v1.2.3