Skip to content

Commit

Permalink
preliminary implementation of projCtx API
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@1854 4e78687f-474d-0410-85f9-8d5e500ac6b2
  • Loading branch information
warmerdam committed Jun 11, 2010
1 parent a729083 commit ec678c0
Show file tree
Hide file tree
Showing 25 changed files with 640 additions and 240 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Expand Up @@ -54,7 +54,7 @@ libproj_la_SOURCES = \
pj_factors.c pj_fwd.c pj_init.c pj_inv.c \ pj_factors.c pj_fwd.c pj_init.c pj_inv.c \
pj_list.c pj_malloc.c pj_mlfn.c pj_msfn.c proj_mdist.c \ pj_list.c pj_malloc.c pj_mlfn.c pj_msfn.c proj_mdist.c \
pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \ pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \
pj_qsfn.c pj_strerrno.c pj_tsfn.c pj_units.c \ pj_qsfn.c pj_strerrno.c pj_tsfn.c pj_units.c pj_ctx.c pj_log.c \
pj_zpoly1.c rtodms.c vector1.c pj_release.c pj_gauss.c \ pj_zpoly1.c rtodms.c vector1.c pj_release.c pj_gauss.c \
\ \
nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \ nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
Expand Down
10 changes: 6 additions & 4 deletions src/Makefile.in
Expand Up @@ -99,9 +99,9 @@ am_libproj_la_OBJECTS = PJ_aeqd.lo PJ_gnom.lo PJ_laea.lo \
pj_init.lo pj_inv.lo pj_list.lo pj_malloc.lo pj_mlfn.lo \ pj_init.lo pj_inv.lo pj_list.lo pj_malloc.lo pj_mlfn.lo \
pj_msfn.lo proj_mdist.lo pj_open_lib.lo pj_param.lo pj_phi2.lo \ pj_msfn.lo proj_mdist.lo pj_open_lib.lo pj_param.lo pj_phi2.lo \
pj_pr_list.lo pj_qsfn.lo pj_strerrno.lo pj_tsfn.lo pj_units.lo \ pj_pr_list.lo pj_qsfn.lo pj_strerrno.lo pj_tsfn.lo pj_units.lo \
pj_zpoly1.lo rtodms.lo vector1.lo pj_release.lo pj_gauss.lo \ pj_ctx.lo pj_log.lo pj_zpoly1.lo rtodms.lo vector1.lo \
nad_cvt.lo nad_init.lo nad_intr.lo emess.lo \ pj_release.lo pj_gauss.lo nad_cvt.lo nad_init.lo nad_intr.lo \
pj_apply_gridshift.lo pj_datums.lo pj_datum_set.lo \ emess.lo pj_apply_gridshift.lo pj_datums.lo pj_datum_set.lo \
pj_transform.lo geocent.lo pj_utils.lo pj_gridinfo.lo \ pj_transform.lo geocent.lo pj_utils.lo pj_gridinfo.lo \
pj_gridlist.lo jniproj.lo pj_mutex.lo pj_initcache.lo \ pj_gridlist.lo jniproj.lo pj_mutex.lo pj_initcache.lo \
pj_apply_vgridshift.lo pj_apply_vgridshift.lo
Expand Down Expand Up @@ -310,7 +310,7 @@ libproj_la_SOURCES = \
pj_factors.c pj_fwd.c pj_init.c pj_inv.c \ pj_factors.c pj_fwd.c pj_init.c pj_inv.c \
pj_list.c pj_malloc.c pj_mlfn.c pj_msfn.c proj_mdist.c \ pj_list.c pj_malloc.c pj_mlfn.c pj_msfn.c proj_mdist.c \
pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \ pj_open_lib.c pj_param.c pj_phi2.c pj_pr_list.c \
pj_qsfn.c pj_strerrno.c pj_tsfn.c pj_units.c \ pj_qsfn.c pj_strerrno.c pj_tsfn.c pj_units.c pj_ctx.c pj_log.c \
pj_zpoly1.c rtodms.c vector1.c pj_release.c pj_gauss.c \ pj_zpoly1.c rtodms.c vector1.c pj_release.c pj_gauss.c \
\ \
nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \ nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
Expand Down Expand Up @@ -582,6 +582,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_apply_gridshift.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_apply_gridshift.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_apply_vgridshift.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_apply_vgridshift.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_auth.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_auth.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_ctx.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_datum_set.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_datum_set.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_datums.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_datums.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_deriv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_deriv.Plo@am__quote@
Expand All @@ -599,6 +600,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_inv.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_inv.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_latlong.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_latlong.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_list.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_list.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_log.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_malloc.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_malloc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_mlfn.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_mlfn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_msfn.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_msfn.Plo@am__quote@
Expand Down
4 changes: 2 additions & 2 deletions src/PJ_tmerc.c
Expand Up @@ -32,7 +32,7 @@ FORWARD(e_forward); /* ellipse */
{ {
xy.x = HUGE_VAL; xy.x = HUGE_VAL;
xy.y = HUGE_VAL; xy.y = HUGE_VAL;
pj_errno = -14; pj_ctx_set_errno( P->ctx, -14 );
return xy; return xy;
} }


Expand Down Expand Up @@ -70,7 +70,7 @@ FORWARD(s_forward); /* sphere */
{ {
xy.x = HUGE_VAL; xy.x = HUGE_VAL;
xy.y = HUGE_VAL; xy.y = HUGE_VAL;
pj_errno = -14; pj_ctx_set_errno( P->ctx, -14 );
return xy; return xy;
} }


Expand Down
4 changes: 4 additions & 0 deletions src/cs2cs.c
Expand Up @@ -284,6 +284,10 @@ int main(int argc, char **argv)
case 's': /* reverse output */ case 's': /* reverse output */
reverseout = 1; reverseout = 1;
continue; continue;
case 'd': /* set debug level */
if (--argc <= 0) goto noargument;
pj_ctx_set_debug( pj_get_default_ctx(), atoi(*++argv));
continue;
default: default:
emess(1, "invalid option: -%c",*arg); emess(1, "invalid option: -%c",*arg);
break; break;
Expand Down
2 changes: 1 addition & 1 deletion src/geod_set.c
Expand Up @@ -21,7 +21,7 @@ geod_set(int argc, char **argv) {
else else
start = curr = pj_mkparam(argv[i]); start = curr = pj_mkparam(argv[i]);
/* set elliptical parameters */ /* set elliptical parameters */
if (pj_ell_set(start, &geod_a, &es)) emess(1,"ellipse setup failure"); if (pj_ell_set(pj_get_default_ctx(),start, &geod_a, &es)) emess(1,"ellipse setup failure");
/* set units */ /* set units */
if (name = pj_param(start, "sunits").s) { if (name = pj_param(start, "sunits").s) {
char *s; char *s;
Expand Down
111 changes: 99 additions & 12 deletions src/multistresstest.c
Expand Up @@ -32,9 +32,15 @@
#include <unistd.h> #include <unistd.h>
#include "proj_api.h" #include "proj_api.h"


#define num_threads 10
#define num_iterations 100000
#define reinit_every_iteration 0

typedef struct { typedef struct {
const char *src_def; const char *src_def;
const char *dst_def; const char *dst_def;

int skip;


double src_x, src_y, src_z; double src_x, src_y, src_z;
double dst_x, dst_y, dst_z; double dst_x, dst_y, dst_z;
Expand All @@ -58,23 +64,56 @@ TestItem test_list[] = {
"+proj=merc +datum=potsdam", "+proj=merc +datum=potsdam",
150000.0, 3000000.0, 0.0, 150000.0, 3000000.0, 0.0,
}, },

/*
** This test currentsly sets pj_errno and messes up the others. It
** should be re-enabled when the pj_errno conflict is resolved.
*/
#ifdef notdef
{ {
"+proj=latlong +nadgrids=nzgd2kgrid0005.gsb", "+proj=latlong +nadgrids=nzgd2kgrid0005.gsb",
"+proj=latlong +datum=WGS84", "+proj=latlong +datum=WGS84",
150000.0, 3000000.0, 0.0, 150000.0, 3000000.0, 0.0,
}, },
#endif
{ {
"+proj=latlong +nadgrids=nzgd2kgrid0005.gsb", "+proj=latlong +nadgrids=nzgd2kgrid0005.gsb",
"+proj=latlong +datum=WGS84", "+proj=latlong +datum=WGS84",
170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0, 170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0,
}, },
{
"+proj=latlong +ellps=GRS80 +towgs84=2,3,5",
"+proj=latlong +ellps=intl +towgs84=10,12,15",
170 * DEG_TO_RAD, -40 * DEG_TO_RAD, 0.0,
},
{
"+proj=eqc +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
"+proj=stere +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=cea +lat_ts=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=merc +lon_0=12 +k=0.999 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=bonne +lat_1=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=cass +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=nzmg +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=gnom +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=ortho +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=laea +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=aeqd +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=eqdc +lat_1=20 +lat_2=5 +lat_0=11 +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{
"+proj=mill +lat_0=11 +lon_0=12 +y_0=200000 +datum=WGS84 ",
"+proj=moll +lon_0=12 +x_0=100000 +y_0=200000 +datum=WGS84 ",
150000.0, 250000.0, 0.0,
},
{ {
"+init=epsg:3309", "+init=epsg:3309",
"+init=epsg:4326", "+init=epsg:4326",
Expand All @@ -97,22 +136,26 @@ static void *TestThread( void *pData )
/* Initialize coordinate system definitions. */ /* Initialize coordinate system definitions. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
projPJ *src_pj_list, *dst_pj_list; projPJ *src_pj_list, *dst_pj_list;
projCtx ctx = pj_ctx_alloc();
// projCtx ctx = pj_get_default_ctx();


src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); src_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));
dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ)); dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));


#if reinit_every_iteration == 0
for( i = 0; i < test_count; i++ ) for( i = 0; i < test_count; i++ )
{ {
TestItem *test = test_list + i; TestItem *test = test_list + i;


src_pj_list[i] = pj_init_plus( test->src_def ); src_pj_list[i] = pj_init_plus_ctx( ctx, test->src_def );
dst_pj_list[i] = pj_init_plus( test->dst_def ); dst_pj_list[i] = pj_init_plus_ctx( ctx, test->dst_def );
} }
#endif


/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Perform tests - over and over. */ /* Perform tests - over and over. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
int repeat_count = 100000, i_iter; int repeat_count = num_iterations, i_iter;


for( i_iter = 0; i_iter < repeat_count; i_iter++ ) for( i_iter = 0; i_iter < repeat_count; i_iter++ )
{ {
Expand All @@ -121,11 +164,19 @@ static void *TestThread( void *pData )
TestItem *test = test_list + i; TestItem *test = test_list + i;
double x, y, z; double x, y, z;
int error; int error;

if( test->skip )
continue;


x = test->src_x; x = test->src_x;
y = test->src_y; y = test->src_y;
z = test->src_z; z = test->src_z;


#if reinit_every_iteration == 1
src_pj_list[i] = pj_init_plus_ctx( ctx, test->src_def );
dst_pj_list[i] = pj_init_plus_ctx( ctx, test->dst_def );
#endif

error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0, error = pj_transform( src_pj_list[i], dst_pj_list[i], 1, 0,
&x, &y, &z ); &x, &y, &z );


Expand All @@ -144,9 +195,31 @@ static void *TestThread( void *pData )
x, y, z, x, y, z,
test->dst_x, test->dst_y, test->dst_z ); test->dst_x, test->dst_y, test->dst_z );
} }

#if reinit_every_iteration == 1
pj_free( src_pj_list[i] );
pj_free( dst_pj_list[i] );
#endif
} }
} }


/* -------------------------------------------------------------------- */
/* Cleanup */
/* -------------------------------------------------------------------- */
#if reinit_every_iteration == 0
for( i = 0; i < test_count; i++ )
{
TestItem *test = test_list + i;
pj_free( src_pj_list[i] );
pj_free( dst_pj_list[i] );
}
#endif

free( src_pj_list );
free( dst_pj_list );

pj_ctx_free( ctx );

printf( "%d iterations of the %d tests complete in thread X\n", printf( "%d iterations of the %d tests complete in thread X\n",
repeat_count, test_count ); repeat_count, test_count );


Expand All @@ -173,6 +246,20 @@ int main( int argc, char **argv )


src_pj = pj_init_plus( test->src_def ); src_pj = pj_init_plus( test->src_def );
dst_pj = pj_init_plus( test->dst_def ); dst_pj = pj_init_plus( test->dst_def );

if( src_pj == NULL )
{
printf( "Unable to translate:\n%s\n", test->src_def );
test->skip = 1;
continue;
}

if( dst_pj == NULL )
{
printf( "Unable to translate:\n%s\n", test->dst_def );
test->skip = 1;
continue;
}


test->dst_x = test->src_x; test->dst_x = test->src_x;
test->dst_y = test->src_y; test->dst_y = test->src_y;
Expand All @@ -185,15 +272,15 @@ int main( int argc, char **argv )


pj_free( src_pj ); pj_free( src_pj );
pj_free( dst_pj ); pj_free( dst_pj );

test->skip = 0;
} }


printf( "%d tests initialized.\n", test_count ); printf( "%d tests initialized.\n", test_count );


/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Now launch a bunch of threads to repeat the tests. */ /* Now launch a bunch of threads to repeat the tests. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
#define num_threads 2

pthread_t ahThread[num_threads]; pthread_t ahThread[num_threads];
pthread_attr_t hThreadAttr; pthread_attr_t hThreadAttr;


Expand Down
4 changes: 2 additions & 2 deletions src/nad2nad.c
Expand Up @@ -63,7 +63,7 @@ set_zone(int in, struct IO_CON *io) {


if (io->hp) { if (io->hp) {
io->t83 = 1; io->t83 = 1;
if (!(htab = nad_init(io->hp))) if (!(htab = nad_init(pj_get_default_ctx(), io->hp)))
emess(1,"hp datum file: %s, failed: %s", io->hp, emess(1,"hp datum file: %s, failed: %s", io->hp,
pj_strerrno(pj_errno)); pj_strerrno(pj_errno));
} }
Expand Down Expand Up @@ -98,7 +98,7 @@ setup() {
if (czone) { if (czone) {
if (!input.hp && !output.hp && input.t83 == output.t83) if (!input.hp && !output.hp && input.t83 == output.t83)
emess(1,"identical datums"); emess(1,"identical datums");
if (!(ctab = nad_init(czone))) if (!(ctab = nad_init(pj_get_default_ctx(), czone)))
emess(1,"datum file: %s, failed: %s", czone, pj_strerrno(pj_errno)); emess(1,"datum file: %s, failed: %s", czone, pj_strerrno(pj_errno));
} else if (input.t83 != output.t83) } else if (input.t83 != output.t83)
emess(1,"conversion region (-r) not specified"); emess(1,"conversion region (-r) not specified");
Expand Down
21 changes: 10 additions & 11 deletions src/nad_init.c
Expand Up @@ -50,7 +50,7 @@
/* Load the data portion of a ctable formatted grid. */ /* Load the data portion of a ctable formatted grid. */
/************************************************************************/ /************************************************************************/


int nad_ctable_load( struct CTABLE *ct, FILE *fid ) int nad_ctable_load( projCtx ctx, struct CTABLE *ct, FILE *fid )


{ {
int a_size; int a_size;
Expand All @@ -72,7 +72,7 @@ int nad_ctable_load( struct CTABLE *ct, FILE *fid )
"ctable loading failed on fread() - binary incompatible?\n" ); "ctable loading failed on fread() - binary incompatible?\n" );
} }


pj_errno = -38; pj_ctx_set_errno( ctx, -38 );
return 0; return 0;
} }


Expand All @@ -85,7 +85,7 @@ int nad_ctable_load( struct CTABLE *ct, FILE *fid )
/* Read the header portion of a "ctable" format grid. */ /* Read the header portion of a "ctable" format grid. */
/************************************************************************/ /************************************************************************/


struct CTABLE *nad_ctable_init( FILE * fid ) struct CTABLE *nad_ctable_init( projCtx ctx, FILE * fid )
{ {
struct CTABLE *ct; struct CTABLE *ct;
int id_end; int id_end;
Expand All @@ -95,15 +95,15 @@ struct CTABLE *nad_ctable_init( FILE * fid )
if( ct == NULL if( ct == NULL
|| fread( ct, sizeof(struct CTABLE), 1, fid ) != 1 ) || fread( ct, sizeof(struct CTABLE), 1, fid ) != 1 )
{ {
pj_errno = -38; pj_ctx_set_errno( ctx, -38 );
return NULL; return NULL;
} }


/* do some minimal validation to ensure the structure isn't corrupt */ /* do some minimal validation to ensure the structure isn't corrupt */
if( ct->lim.lam < 1 || ct->lim.lam > 100000 if( ct->lim.lam < 1 || ct->lim.lam > 100000
|| ct->lim.phi < 1 || ct->lim.phi > 100000 ) || ct->lim.phi < 1 || ct->lim.phi > 100000 )
{ {
pj_errno = -38; pj_ctx_set_errno( ctx, -38 );
return NULL; return NULL;
} }


Expand All @@ -127,27 +127,26 @@ struct CTABLE *nad_ctable_init( FILE * fid )
/* Read a datum shift file in any of the supported binary formats. */ /* Read a datum shift file in any of the supported binary formats. */
/************************************************************************/ /************************************************************************/


struct CTABLE *nad_init(char *name) struct CTABLE *nad_init(projCtx ctx, char *name)
{ {
char fname[MAX_PATH_FILENAME+1]; char fname[MAX_PATH_FILENAME+1];
struct CTABLE *ct; struct CTABLE *ct;
FILE *fid; FILE *fid;


errno = pj_errno = 0; ctx->last_errno = 0;


/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
/* Open the file using the usual search rules. */ /* Open the file using the usual search rules. */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
strcpy(fname, name); strcpy(fname, name);
if (!(fid = pj_open_lib(fname, "rb"))) { if (!(fid = pj_open_lib(ctx, fname, "rb"))) {
pj_errno = errno;
return 0; return 0;
} }


ct = nad_ctable_init( fid ); ct = nad_ctable_init( ctx, fid );
if( ct != NULL ) if( ct != NULL )
{ {
if( !nad_ctable_load( ct, fid ) ) if( !nad_ctable_load( ctx, ct, fid ) )
{ {
nad_free( ct ); nad_free( ct );
ct = NULL; ct = NULL;
Expand Down

0 comments on commit ec678c0

Please sign in to comment.