Skip to content

Commit

Permalink
More readable code courtesy of Thomas
Browse files Browse the repository at this point in the history
  • Loading branch information
kbevers committed May 24, 2018
1 parent 3029de1 commit 1e03829
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
29 changes: 21 additions & 8 deletions src/PJ_hgridshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,35 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_hgridshift *Q = (struct pj_opaque_hgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);
} else {

/* If transformation is not time restricted, we always call it */
if (Q->t_final==0 || Q->t_epoch==0) {
point.xyz = forward_3d (obs.lpz, P);
return point;
}

/* Time restricted - only apply transform if within time bracket */
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);


return point;
}

static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_hgridshift *Q = (struct pj_opaque_hgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);
} else {

/* If transformation is not time restricted, we always call it */
if (Q->t_final==0 || Q->t_epoch==0) {
point.lpz = reverse_3d (obs.xyz, P);
return point;
}

/* Time restricted - only apply transform if within time bracket */
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);

return point;
}

Expand All @@ -88,6 +99,8 @@ PJ *TRANSFORMATION(hgridshift,0) {
return pj_default_destructor (P, PJD_ERR_NO_ARGS);
}

/* TODO: Refactor into shared function that can be used */
/* by both vgridshift and hgridshift */
if (pj_param(P->ctx, P->params, "tt_final").i) {
Q->t_final = pj_param (P->ctx, P->params, "dt_final").f;
if (Q->t_final == 0) {
Expand Down
29 changes: 21 additions & 8 deletions src/PJ_vgridshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,35 @@ static LPZ reverse_3d(XYZ xyz, PJ *P) {
static PJ_COORD forward_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_vgridshift *Q = (struct pj_opaque_vgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);
} else {

/* If transformation is not time restricted, we always call it */
if (Q->t_final==0 || Q->t_epoch==0) {
point.xyz = forward_3d (obs.lpz, P);
return point;
}

/* Time restricted - only apply transform if within time bracket */
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.xyz = forward_3d (obs.lpz, P);


return point;
}

static PJ_COORD reverse_4d(PJ_COORD obs, PJ *P) {
struct pj_opaque_vgridshift *Q = (struct pj_opaque_vgridshift *) P->opaque;
PJ_COORD point = obs;
if (Q->t_final != 0.0 && Q->t_epoch != 0.0) {
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);
} else {

/* If transformation is not time restricted, we always call it */
if (Q->t_final==0 || Q->t_epoch==0) {
point.lpz = reverse_3d (obs.xyz, P);
return point;
}

/* Time restricted - only apply transform if within time bracket */
if (obs.lpzt.t < Q->t_epoch && Q->t_final > Q->t_epoch)
point.lpz = reverse_3d (obs.xyz, P);

return point;
}

Expand All @@ -79,6 +90,8 @@ PJ *TRANSFORMATION(vgridshift,0) {
return pj_default_destructor(P, PJD_ERR_NO_ARGS);
}

/* TODO: Refactor into shared function that can be used */
/* by both vgridshift and hgridshift */
if (pj_param(P->ctx, P->params, "tt_final").i) {
Q->t_final = pj_param (P->ctx, P->params, "dt_final").f;
if (Q->t_final == 0) {
Expand Down

0 comments on commit 1e03829

Please sign in to comment.