Skip to content
Permalink
Browse files

preliminary implementation of projCtx API

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 ec678c07c2acb83da8a2187c541b8a2e452dec4b
@@ -54,7 +54,7 @@ libproj_la_SOURCES = \
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_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 \
\
nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
@@ -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_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_zpoly1.lo rtodms.lo vector1.lo pj_release.lo pj_gauss.lo \
nad_cvt.lo nad_init.lo nad_intr.lo emess.lo \
pj_apply_gridshift.lo pj_datums.lo pj_datum_set.lo \
pj_ctx.lo pj_log.lo pj_zpoly1.lo rtodms.lo vector1.lo \
pj_release.lo pj_gauss.lo nad_cvt.lo nad_init.lo nad_intr.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_gridlist.lo jniproj.lo pj_mutex.lo pj_initcache.lo \
pj_apply_vgridshift.lo
@@ -310,7 +310,7 @@ libproj_la_SOURCES = \
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_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 \
\
nad_cvt.c nad_init.c nad_intr.c emess.c emess.h \
@@ -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_vgridshift.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_datums.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_deriv.Plo@am__quote@
@@ -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_latlong.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_mlfn.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pj_msfn.Plo@am__quote@
@@ -32,7 +32,7 @@ FORWARD(e_forward); /* ellipse */
{
xy.x = HUGE_VAL;
xy.y = HUGE_VAL;
pj_errno = -14;
pj_ctx_set_errno( P->ctx, -14 );
return xy;
}

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

@@ -284,6 +284,10 @@ int main(int argc, char **argv)
case 's': /* reverse output */
reverseout = 1;
continue;
case 'd': /* set debug level */
if (--argc <= 0) goto noargument;
pj_ctx_set_debug( pj_get_default_ctx(), atoi(*++argv));
continue;
default:
emess(1, "invalid option: -%c",*arg);
break;
@@ -21,7 +21,7 @@ geod_set(int argc, char **argv) {
else
start = curr = pj_mkparam(argv[i]);
/* 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 */
if (name = pj_param(start, "sunits").s) {
char *s;
@@ -32,9 +32,15 @@
#include <unistd.h>
#include "proj_api.h"

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

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

int skip;

double src_x, src_y, src_z;
double dst_x, dst_y, dst_z;
@@ -58,23 +64,56 @@ TestItem test_list[] = {
"+proj=merc +datum=potsdam",
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 +datum=WGS84",
150000.0, 3000000.0, 0.0,
},
#endif
{
"+proj=latlong +nadgrids=nzgd2kgrid0005.gsb",
"+proj=latlong +datum=WGS84",
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:4326",
@@ -97,22 +136,26 @@ static void *TestThread( void *pData )
/* Initialize coordinate system definitions. */
/* -------------------------------------------------------------------- */
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));
dst_pj_list = (projPJ *) calloc(test_count,sizeof(projPJ));

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

src_pj_list[i] = pj_init_plus( test->src_def );
dst_pj_list[i] = pj_init_plus( test->dst_def );
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

/* -------------------------------------------------------------------- */
/* 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++ )
{
@@ -121,11 +164,19 @@ static void *TestThread( void *pData )
TestItem *test = test_list + i;
double x, y, z;
int error;

if( test->skip )
continue;

x = test->src_x;
y = test->src_y;
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,
&x, &y, &z );

@@ -144,9 +195,31 @@ static void *TestThread( void *pData )
x, y, 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",
repeat_count, test_count );

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

src_pj = pj_init_plus( test->src_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_y = test->src_y;
@@ -185,15 +272,15 @@ int main( int argc, char **argv )

pj_free( src_pj );
pj_free( dst_pj );

test->skip = 0;
}

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

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

pthread_t ahThread[num_threads];
pthread_attr_t hThreadAttr;

@@ -63,7 +63,7 @@ set_zone(int in, struct IO_CON *io) {

if (io->hp) {
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,
pj_strerrno(pj_errno));
}
@@ -98,7 +98,7 @@ setup() {
if (czone) {
if (!input.hp && !output.hp && input.t83 == output.t83)
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));
} else if (input.t83 != output.t83)
emess(1,"conversion region (-r) not specified");
@@ -50,7 +50,7 @@
/* 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;
@@ -72,7 +72,7 @@ int nad_ctable_load( struct CTABLE *ct, FILE *fid )
"ctable loading failed on fread() - binary incompatible?\n" );
}

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

@@ -85,7 +85,7 @@ int nad_ctable_load( struct CTABLE *ct, FILE *fid )
/* 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;
int id_end;
@@ -95,15 +95,15 @@ struct CTABLE *nad_ctable_init( FILE * fid )
if( ct == NULL
|| fread( ct, sizeof(struct CTABLE), 1, fid ) != 1 )
{
pj_errno = -38;
pj_ctx_set_errno( ctx, -38 );
return NULL;
}

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

@@ -127,27 +127,26 @@ struct CTABLE *nad_ctable_init( FILE * fid )
/* 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];
struct CTABLE *ct;
FILE *fid;

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

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

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

0 comments on commit ec678c0

Please sign in to comment.
You can’t perform that action at this time.