Skip to content

Commit

Permalink
Merge 526fe49 into 117a3f4
Browse files Browse the repository at this point in the history
  • Loading branch information
kbevers committed Oct 16, 2018
2 parents 117a3f4 + 526fe49 commit 912c6b0
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 127 deletions.
46 changes: 23 additions & 23 deletions docs/source/development/reference/datatypes.rst
Expand Up @@ -472,12 +472,12 @@ List structures
.. code-block:: C
struct PJ_OPERATIONS {
char *id; /* operation keyword */
PJ *(*proj)(PJ *); /* operation entry point */
char * const *descr; /* description text */
const char *id; /* operation keyword */
PJ *(*proj)(PJ *); /* operation entry point */
char * const *descr; /* description text */
};
.. c:member:: char *id
.. c:member:: const char *id
Operation keyword.

Expand All @@ -497,25 +497,25 @@ List structures
.. code-block:: C
struct PJ_ELLPS {
char *id;
char *major;
char *ell;
char *name;
const char *id;
const char *major;
const char *ell;
const char *name;
};
.. c:member:: char *id
.. c:member:: const char *id
Keyword name of the ellipsoid.

.. c:member:: char *major
.. c:member:: const char *major
Semi-major axis of the ellipsoid, or radius in case of a sphere.

.. c:member:: char *ell
.. c:member:: const char *ell
Elliptical parameter, e.g. `rf=298.257` or `b=6356772.2`.

.. c:member:: char *name
.. c:member:: const char *name
Name of the ellipsoid

Expand All @@ -526,21 +526,21 @@ List structures
.. code-block:: C
struct PJ_UNITS {
char *id; /* units keyword */
char *to_meter; /* multiply by value to get meters */
char *name; /* comments */
double factor; /* to_meter factor in actual numbers */
const char *id; /* units keyword */
const char *to_meter; /* multiply by value to get meters */
const char *name; /* comments */
double factor; /* to_meter factor in actual numbers */
};
.. c:member:: char *id
.. c:member:: const char *id
Keyword for the unit.

.. c:member:: char *to_meter
.. c:member:: const char *to_meter
Text representation of the factor that converts a given unit to meters

.. c:member:: char *name
.. c:member:: const char *name
Name of the unit.

Expand All @@ -555,15 +555,15 @@ List structures
.. code-block:: C
struct PJ_PRIME_MERIDIANS {
char *id;
char *defn;
const char *id;
const char *defn;
};
.. c:member:: char *id
.. c:member:: const char *id
Keyword for the prime meridian

.. c:member:: char *def
.. c:member:: const char *def
Offset from Greenwich in DMS format.

Expand Down
9 changes: 6 additions & 3 deletions src/PJ_unitconvert.c
Expand Up @@ -401,17 +401,20 @@ static double get_unit_conversion_factor(const char* name,
/***********************************************************************/
int i;
const char* s;
const PJ_UNITS *units;

units = proj_list_units();

/* Try first with linear units */
for (i = 0; (s = pj_units[i].id) ; ++i) {
for (i = 0; (s = units[i].id) ; ++i) {
if ( strcmp(s, name) == 0 ) {
if( p_normalized_name ) {
*p_normalized_name = pj_units[i].name;
*p_normalized_name = units[i].name;
}
if( p_is_linear ) {
*p_is_linear = 1;
}
return pj_units[i].factor;
return units[i].factor;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cs2cs.c
Expand Up @@ -211,7 +211,7 @@ int main(int argc, char **argv)
/* list projections */
const struct PJ_LIST *lp;
int do_long = arg[1] == 'P', c;
char *str;
const char *str;

for (lp = proj_list_operations() ; lp->id ; ++lp) {
(void)printf("%s : ", lp->id);
Expand Down
2 changes: 1 addition & 1 deletion src/geod_set.c
Expand Up @@ -32,7 +32,7 @@ geod_set(int argc, char **argv) {
if (pj_ell_set(pj_get_default_ctx(),start, &geod_a, &es)) emess(1,"ellipse setup failure");
/* set units */
if ((name = pj_param(NULL,start, "sunits").s) != NULL) {
char *s;
const char *s;
const struct PJ_UNITS *unit_list = proj_list_units();
for (i = 0; (s = unit_list[i].id) && strcmp(name, s) ; ++i) ;
if (!s)
Expand Down
5 changes: 0 additions & 5 deletions src/pj_datums.c
Expand Up @@ -93,11 +93,6 @@ C_NAMESPACE_VAR const struct PJ_PRIME_MERIDIANS pj_prime_meridians[] = {
{NULL, NULL}
};

struct PJ_PRIME_MERIDIANS *pj_get_prime_meridians_ref()
{
return (struct PJ_PRIME_MERIDIANS *)pj_prime_meridians;
}

const PJ_PRIME_MERIDIANS *proj_list_prime_meridians(void)
{
return pj_prime_meridians;
Expand Down
10 changes: 7 additions & 3 deletions src/pj_ell_set.c
Expand Up @@ -424,15 +424,19 @@ static char *pj_param_value (paralist *list) {

static const PJ_ELLPS *pj_find_ellps (char *name) {
int i;
char *s;
const char *s;
const PJ_ELLPS *ellps;

if (0==name)
return 0;

ellps = proj_list_ellps();

/* Search through internal ellipsoid list for name */
for (i = 0; (s = pj_ellps[i].id) && strcmp(name, s) ; ++i);
for (i = 0; (s = ellps[i].id) && strcmp(name, s) ; ++i);
if (0==s)
return 0;
return pj_ellps + i;
return ellps + i;
}


Expand Down
7 changes: 0 additions & 7 deletions src/pj_ellps.c
Expand Up @@ -3,8 +3,6 @@
#include <stddef.h>

#include "proj.h"

#define PJ_ELLPS__
#include "projects.h"

C_NAMESPACE_VAR const struct PJ_ELLPS
Expand Down Expand Up @@ -58,11 +56,6 @@ pj_ellps[] = {
{NULL, NULL, NULL, NULL}
};

struct PJ_ELLPS *pj_get_ellps_ref()
{
return (struct PJ_ELLPS *)pj_ellps;
}

const PJ_ELLPS *proj_list_ellps(void)
{
return pj_ellps;
Expand Down
33 changes: 20 additions & 13 deletions src/pj_init.c
Expand Up @@ -484,24 +484,29 @@ pj_init(int argc, char **argv) {

static PJ_CONSTRUCTOR locate_constructor (const char *name) {
int i;
char *s;
for (i = 0; (s = pj_list[i].id) && strcmp(name, s) ; ++i) ;
const char *s;
const PJ_OPERATIONS *operations;
operations = proj_list_operations();
for (i = 0; (s = operations[i].id) && strcmp(name, s) ; ++i) ;
if (0==s)
return 0;
return (PJ_CONSTRUCTOR) pj_list[i].proj;
return (PJ_CONSTRUCTOR) operations[i].proj;
}


PJ *
pj_init_ctx(projCtx ctx, int argc, char **argv) {
char *s, *name;
const char *s;
char *name;
PJ_CONSTRUCTOR proj;
paralist *curr, *init, *start;
int i;
int err;
PJ *PIN = 0;
int n_pipelines = 0;
int n_inits = 0;
const PJ_UNITS *units;
const PJ_PRIME_MERIDIANS *prime_meridians;

if (0==ctx)
ctx = pj_get_default_ctx ();
Expand Down Expand Up @@ -701,12 +706,13 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
return pj_default_destructor (PIN, PJD_ERR_K_LESS_THAN_ZERO);

/* Set units */
units = proj_list_units();
s = 0;
if ((name = pj_param(ctx, start, "sunits").s) != NULL) {
for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ;
for (i = 0; (s = units[i].id) && strcmp(name, s) ; ++i) ;
if (!s)
return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
s = pj_units[i].to_meter;
s = units[i].to_meter;
}
if (s || (s = pj_param(ctx, start, "sto_meter").s)) {
double factor;
Expand All @@ -718,7 +724,7 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
s += 2;
}

factor = pj_strtod(s, &s);
factor = pj_strtod(s, 0);
if ((factor <= 0.0) || (1/factor==0))
return pj_default_destructor (PIN, PJD_ERR_UNIT_FACTOR_LESS_THAN_0);

Expand All @@ -731,13 +737,13 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
/* Set vertical units */
s = 0;
if ((name = pj_param(ctx, start, "svunits").s) != NULL) {
for (i = 0; (s = pj_units[i].id) && strcmp(name, s) ; ++i) ;
for (i = 0; (s = units[i].id) && strcmp(name, s) ; ++i) ;
if (!s)
return pj_default_destructor (PIN, PJD_ERR_UNKNOWN_UNIT_ID);
s = pj_units[i].to_meter;
s = units[i].to_meter;
}
if (s || (s = pj_param(ctx, start, "svto_meter").s)) {
PIN->vto_meter = pj_strtod(s, &s);
PIN->vto_meter = pj_strtod(s, 0);
if (*s == '/') /* ratio number */
PIN->vto_meter /= pj_strtod(++s, 0);
if (PIN->vto_meter <= 0.0)
Expand All @@ -749,16 +755,17 @@ pj_init_ctx(projCtx ctx, int argc, char **argv) {
}

/* Prime meridian */
prime_meridians = proj_list_prime_meridians();
s = 0;
if ((name = pj_param(ctx, start, "spm").s) != NULL) {
const char *value = NULL;
char *next_str = NULL;

for (i = 0; pj_prime_meridians[i].id != NULL; ++i )
for (i = 0; prime_meridians[i].id != NULL; ++i )
{
if( strcmp(name,pj_prime_meridians[i].id) == 0 )
if( strcmp(name,prime_meridians[i].id) == 0 )
{
value = pj_prime_meridians[i].defn;
value = prime_meridians[i].defn;
break;
}
}
Expand Down
11 changes: 3 additions & 8 deletions src/pj_list.c
Expand Up @@ -14,24 +14,19 @@
#undef PROJ_HEAD

/* Generate extern declarations for description strings */
#define PROJ_HEAD(id, name) extern char * const pj_s_##id;
#define PROJ_HEAD(id, name) extern const char * const pj_s_##id;
#include "pj_list.h"
#undef PROJ_HEAD

/* Generate the null-terminated list of projection functions with associated mnemonics and descriptions */
#define PROJ_HEAD(id, name) {#id, pj_##id, &pj_s_##id},
const struct PJ_LIST pj_list[] = {
#include "pj_list.h"
{0, 0, 0},
};
{0, 0, 0},
};
#undef PROJ_HEAD


struct PJ_LIST *pj_get_list_ref()
{
return (struct PJ_LIST *)pj_list;
}

const PJ_OPERATIONS *proj_list_operations(void) {
return pj_list;
}
4 changes: 2 additions & 2 deletions src/pj_param.c
Expand Up @@ -9,7 +9,7 @@
#include "projects.h"

/* create parameter list entry */
paralist *pj_mkparam(char *str) {
paralist *pj_mkparam(const char *str) {
paralist *newitem;

if((newitem = (paralist *)pj_malloc(sizeof(paralist) + strlen(str))) != NULL) {
Expand All @@ -24,7 +24,7 @@ paralist *pj_mkparam(char *str) {


/* As pj_mkparam, but payload ends at first whitespace, rather than at end of <str> */
paralist *pj_mkparam_ws (char *str) {
paralist *pj_mkparam_ws (const char *str) {
paralist *newitem;
size_t len = 0;

Expand Down
5 changes: 0 additions & 5 deletions src/pj_units.c
Expand Up @@ -36,11 +36,6 @@ pj_units[] = {
{NULL, NULL, NULL, 0.0}
};

struct PJ_UNITS *pj_get_units_ref()
{
return (struct PJ_UNITS *)pj_units;
}

const PJ_UNITS *proj_list_units()
{
return pj_units;
Expand Down
2 changes: 1 addition & 1 deletion src/proj.c
Expand Up @@ -369,7 +369,7 @@ int main(int argc, char **argv) {
/* list projections */
const struct PJ_LIST *lp;
int do_long = arg[1] == 'P', c;
char *str;
const char *str;

for (lp = proj_list_operations() ; lp->id ; ++lp) {
if( strcmp(lp->id,"latlong") == 0
Expand Down
4 changes: 0 additions & 4 deletions src/proj.def
Expand Up @@ -26,11 +26,7 @@ EXPORTS
pj_datum_transform @24
pj_set_searchpath @25
dmstor @26
pj_get_ellps_ref @27
pj_get_datums_ref @28
pj_get_units_ref @29
pj_get_list_ref @30
pj_get_prime_meridians_ref @31
rtodms @32
set_rtodms @33
pj_factors @34
Expand Down

0 comments on commit 912c6b0

Please sign in to comment.