aboutsummaryrefslogtreecommitdiff
path: root/src/PJ_hgridshift.c
diff options
context:
space:
mode:
authorThomas Knudsen <thokn@sdfe.dk>2017-09-27 13:56:34 +0200
committerThomas Knudsen <thokn@sdfe.dk>2017-10-06 11:39:27 +0200
commit664577ced6a8e4074b1f53af82b5ae5d1d189eac (patch)
treea29d4a6c0842bb87df63fc913502c3b6c5b097a5 /src/PJ_hgridshift.c
parent0495fdca92fc620d44572ce1e4e871f57f968198 (diff)
downloadPROJ-664577ced6a8e4074b1f53af82b5ae5d1d189eac.tar.gz
PROJ-664577ced6a8e4074b1f53af82b5ae5d1d189eac.zip
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
Diffstat (limited to 'src/PJ_hgridshift.c')
-rw-r--r--src/PJ_hgridshift.c87
1 files changed, 47 insertions, 40 deletions
diff --git a/src/PJ_hgridshift.c b/src/PJ_hgridshift.c
index 4ee3fd42..1b65b1bd 100644
--- a/src/PJ_hgridshift.c
+++ b/src/PJ_hgridshift.c
@@ -1,25 +1,9 @@
#define PJ_LIB__
#include "proj_internal.h"
-#include <projects.h>
+#include "projects.h"
PROJ_HEAD(hgridshift, "Horizontal 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;
@@ -67,25 +51,30 @@ static PJ_OBS reverse_obs(PJ_OBS obs, PJ *P) {
}
-PJ *PROJECTION(hgridshift) {
- if (!pj_param(P->ctx, P->params, "tgrids").i) {
- proj_log_error(P, "hgridshift: +grids parameter missing.");
- return freeup_msg(P, -1);
- }
+#if 0
+static XY forward_xy(LP lp, PJ *P) {
+ PJ_TRIPLET point;
+ point.lp = lp;
+ point.lpz.z = 0;
+ point.xyz = forward_3d (point.lpz, P);
+ return point.xy;
+}
- /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */
- P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s,
- &(P->gridlist_count) );
- /* Was gridlist compiled properly? */
- if ( pj_ctx_get_errno(P->ctx) ) {
- proj_log_error(P, "hgridshift: could not find required grid(s).");
- pj_dalloc(P->gridlist);
- P->gridlist = NULL;
- return freeup_msg(P, -38);
- }
+static LP reverse_lp(XY xy, PJ *P) {
+ PJ_TRIPLET point;
+ point.xy = xy;
+ point.xyz.z = 0;
+ point.lpz = reverse_3d (point.xyz, P);
+ return point.lp;
+}
+#endif
+
+
+PJ *PROJECTION(hgridshift) {
+
P->fwdobs = forward_obs;
P->invobs = reverse_obs;
P->fwd3d = forward_3d;
@@ -96,6 +85,21 @@ PJ *PROJECTION(hgridshift) {
P->left = PJ_IO_UNITS_RADIANS;
P->right = PJ_IO_UNITS_RADIANS;
+ if (0==pj_param(P->ctx, P->params, "tgrids").i) {
+ proj_log_error(P, "hgridshift: +grids parameter missing.");
+ return pj_default_destructor (P, PJD_ERR_NO_ARGS);
+ }
+
+ /* Build gridlist. P->gridlist can be empty if +grids only ask for optional grids. */
+ P->gridlist = pj_gridlist_from_nadgrids( P->ctx, pj_param(P->ctx, P->params, "sgrids").s,
+ &(P->gridlist_count) );
+
+ /* Was gridlist compiled properly? */
+ if ( pj_ctx_get_errno(pj_get_ctx(P)) ) {
+ proj_log_error(P, "hgridshift: could not find required grid(s).");
+ return pj_default_destructor (P, PJD_ERR_FAILED_TO_LOAD_GRID);
+ }
+
return P;
}
@@ -111,24 +115,27 @@ int pj_hgridshift_selftest (void) {
/* fail on purpose: +grids parameter is mandatory*/
P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift");
- 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=hgridshift +grids=nonexistinggrid.gsb");
- if (0!=P)
+ P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=@nonexistinggrid.gsb,anothernonexistinggrid.gsb");
+ if (0!=P) {
+ proj_destroy (P);
return 999;
-
-
+ }
+
/* Failure most likely means the grid is missing */
P = proj_create(PJ_DEFAULT_CTX, "+proj=hgridshift +grids=nzgd2kgrid0005.gsb +ellps=GRS80");
if (0==P)
return 10;
-
+
a = proj_obs_null;
a.coo.lpz.lam = PJ_TORAD(173);
a.coo.lpz.phi = PJ_TORAD(-45);
-
+
dist = proj_roundtrip (P, PJ_FWD, 1, a);
if (dist > 0.00000001)
return 1;