Esempio n. 1
0
struct cs_Dtcprm_ * EXP_LVL9 CSbdclu (	Const struct cs_Csprm_ *src_cs,
										Const struct cs_Csprm_ *dst_cs,
										int dat_err,
										int blk_err)
{
	extern csThread struct csDtcach_ *csDtcachP;
	extern csThread int csDtcachI;

	unsigned short srcPrjCode;
	unsigned short dstPrjCode;
	int ii;
	

	struct cs_Dtcprm_ *dtc_ptr;
	struct csDtcach_ *ch_ptr;
	struct csDtcach_ *tmp_ptr;
	struct csDtcach_ *last_chp;

	/* Make sure we're not converting between non-georeferenced and georeferenced. */
	srcPrjCode = src_cs->prj_code;
	dstPrjCode = dst_cs->prj_code;

	if (srcPrjCode == cs_PRJCOD_NRTHSRT) srcPrjCode = cs_PRJCOD_NERTH;
	if (dstPrjCode == cs_PRJCOD_NRTHSRT) dstPrjCode = cs_PRJCOD_NERTH;
	
	if ((srcPrjCode == cs_PRJCOD_NERTH) ^ (dstPrjCode == cs_PRJCOD_NERTH))	/*lint !e514 */
	{
		CS_erpt (cs_NOT_NERTH);
		goto error;
	}

	/* If we have not done so already, allocate the cache now. */
	if (csDtcachP == NULL)
	{
		if (csDtcachI <= 1) csDtcachI = 2;
		last_chp = NULL;
		for (ii = 0;ii < csDtcachI;ii++)
		{
			ch_ptr = (struct csDtcach_ *)CS_malc (sizeof (struct csDtcach_));
			if (ch_ptr == NULL)
			{
				CS_erpt (cs_NO_MEM);
				ch_ptr = csDtcachP;
				while (ch_ptr != NULL)
				{
					tmp_ptr = ch_ptr->next;
					CS_free (ch_ptr);
					ch_ptr = tmp_ptr;
				}
				csDtcachP = NULL;
				goto error;
			}
			if (ii == 0)
			{
				csDtcachP = ch_ptr;
			}
			else
			{
				last_chp->next = ch_ptr;				/*lint !e613 */
			}
			ch_ptr->prev = last_chp;
			ch_ptr->next = NULL;
			ch_ptr->dtc_ptr = NULL;
			last_chp = ch_ptr;
		}
	}

	/* Search the existing cache entries for the desired
	   datum combination.  While doing so, we maintain
	   last_chp as a pointer to the last cache entry
	   examined.  We will use this to add a new entry to
	   the cache if we don't find the one we are looking for. */

	dtc_ptr = NULL;
	ch_ptr = csDtcachP;
	last_chp = NULL;
	while (ch_ptr != NULL)
	{
		if (ch_ptr->dtc_ptr == NULL) break;
		if (!CS_stricmp (ch_ptr->dtc_ptr->srcKeyName,src_cs->csdef.dat_knm) &&
		    !CS_stricmp (ch_ptr->dtc_ptr->trgKeyName,dst_cs->csdef.dat_knm))
		{
			dtc_ptr = ch_ptr->dtc_ptr;
			break;
		}
		last_chp = ch_ptr;
		ch_ptr = ch_ptr->next;
	}

	if (dtc_ptr == NULL)
	{
		/* Didn't find one. */
		if (ch_ptr != NULL)
		{
			/* ch_ptr is pointing to an unused entry. */
			dtc_ptr = CS_dtcsu (src_cs,dst_cs,dat_err,blk_err);
			if (dtc_ptr == NULL) goto error;
			ch_ptr->dtc_ptr = dtc_ptr;
		}
		else
		{
			/* All entries in the cache are used. Last_chp
			   points to the last entry in the cache, which is
			   also the least recently used entry. */
			ch_ptr = last_chp;
			CS_dtcls (ch_ptr->dtc_ptr);
			dtc_ptr = ch_ptr->dtc_ptr = CS_dtcsu (src_cs,dst_cs,dat_err,blk_err);
			if (dtc_ptr == NULL) goto error;
		}
	}
	else
	{
		dtc_ptr->block_err = (short)blk_err;
	}

	if (ch_ptr != csDtcachP)
	{
		/* Push this cache entry to the top of the list. */
		ch_ptr->prev->next = ch_ptr->next;			/*lint !e613 */
		if (ch_ptr->next != NULL)					/*lint !e613 */
		{
			ch_ptr->next->prev = ch_ptr->prev;		/*lint !e613 */
		}
		ch_ptr->prev = NULL;						/*lint !e613 */
		ch_ptr->next = csDtcachP;					/*lint !e613 */
		csDtcachP->prev = ch_ptr;
		csDtcachP = ch_ptr;
	}
	return (dtc_ptr);

error:
	return (NULL);
}
Esempio n. 2
0
int CStestT (bool verbose,long32_t duration)
{
	int err_cnt = 0;

#ifdef __SKIP__

	double xyz [3];

	xyz [0] = 0.0;
	xyz [1] = 20000000.000;
	xyz [2] = 0.0;

	int st = CS_cnvrt ("WGS84.PseudoMercator","LL",xyz);
	if (st != 0)
	{
		err_cnt += 1;
	}
#endif

#ifndef __SKIP__

	char wktOne   [1024] = "GEOGCS [ \"NAD83\", DATUM [\"NAD 83\", SPHEROID [\"GRS 80\", 6378137.000000, 298.257222]], PRIMEM [ \"Greenwich\", 0.000000 ], UNIT [\"Degrees\", 0.01745329251994330]]";
//	char wktOne   [1024] = "PROJCS[\"DHDN / Gauss-Kruger zone 5\",GEOGCS[\"DHDN\",DATUM[\"Deutsches_Hauptdreiecksnetz\",SPHEROID[\"Bessel 1841\",6377397.155,299.1528128,AUTHORITY[\"EPSG\",\"7004\"]],AUTHORITY[\"EPSG\",\"6314\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4314\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",15],PARAMETER[\"scale_factor\",1],PARAMETER[\"false_easting\",5500000],PARAMETER[\"false_northing\",0],AUTHORITY[\"EPSG\",\"31469\"]]";
	char wktTwo   [1024] = "GEOGCS[\"LL84\",DATUM[\"WGS84\",SPHEROID[\"WGS84\",6378137.000,298.25722293]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.01745329251994]]";
	char wktThree [1024] = "PROJCS[\"NAD83 / California zone 3 (ftUS)\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],UNIT[\"US survey foot\",0.3048006096012192,AUTHORITY[\"EPSG\",\"9003\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",38.43333333333333],PARAMETER[\"standard_parallel_2\",37.06666666666667],PARAMETER[\"latitude_of_origin\",36.5],PARAMETER[\"central_meridian\",-120.5],PARAMETER[\"false_easting\",6561666.667],PARAMETER[\"false_northing\",1640416.667],AUTHORITY[\"EPSG\",\"2227\"],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
	char wktFour  [1024] = "PROJCS[\"DHDN.Berlin/Cassini\",GEOGCS[\"DHDN.LL\",DATUM[\"DHDN\",SPHEROID[\"BESSEL\",6377397.155,299.15281535],TOWGS84[582.0000,105.0000,414.0000,-1.040000,-0.350000,3.080000,8.30000000]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Cassini-Soldner\"],PARAMETER[\"false_easting\",40000.000],PARAMETER[\"false_northing\",10000.000],PARAMETER[\"central_meridian\",13.62720366666667],PARAMETER[\"latitude_of_origin\",52.41864827777778],UNIT[\"Meter\",1.00000000000000]]";
	char wktFive  [1024] = "PROJCS[\"NAD83 / UTM zone 19N\",GEOGCS[\"NAD83\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS 1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6269\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4269\"]],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-69],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],AUTHORITY[\"EPSG\",\"26919\"],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]";
	char wktSix   [1024] = "PROJCS[\"NAD_1983_HARN_StatePlane_Hawaii_3_FIPS_5103_Feet\",GEOGCS[\"GCS_North_American_1983_HARN\",DATUM[\"D_North_American_1983_HARN\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",1640416.666666667],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-158.0],PARAMETER[\"Scale_Factor\",0.99999],PARAMETER[\"Latitude_Of_Origin\",21.16666666666667],UNIT[\"Foot_US\",0.3048006096012192]]";
	char wktSeven [1024] = "PROJCS[\"NAD_1983_UTM_Zone_12N\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-111.0],PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";
	char wktEight [1024] = "PROJCS[\"Italian National System (Gauss-Boaga), Zone 1 (West) Peninsular\",GEOGCS [\"Rome 1940\",DATUM [\"Rome 1940\",SPHEROID [\"International 1924\", 6378388, 297], -104.1, -49.1, -9.9, 0.971, -2.917, 0.714, -11.68],PRIMEM [ \"Greenwich\", 0.000000 ],UNIT [\"Decimal Degree\", 0.01745329251994330]],PROJECTION [\"Transverse Mercator\"],PARAMETER [\"Scale_Factor\", 0.999600],PARAMETER [\"Central_Meridian\", 9.000000],PARAMETER [\"False_Easting\", 150000000],UNIT [\"Centimeter\", 0.01]]";
	char wktNine  [1024] = "PROJCS[\"ENEL GB\",GEOGCS[\"ROME1940-IT-7P\",DATUM[\"ROME1940-IT-7P\",SPHEROID[\"International 1924 (EPSG ID 7022)\",6378388.000,297.00000000],TOWGS84[-104.1000,-49.1000,-9.9000,0.971000,-2.917000,0.714000,-11.68000000]],PRIMEM[\"Greenwich\",0],UNIT[\"Decimal Degree\",0.017453292519943295]],PROJECTION[\"Transverse Mercator\"],PARAMETER[\"False_Easting\",1500000.000],PARAMETER[\"False_Northing\",0.000],PARAMETER[\"Scale_Factor\",1.000000000000],PARAMETER[\"Central_Meridian\",9.00000000000000],PARAMETER[\"Latitude_Of_Origin\",0.00000000000000],UNIT[\"Centimeter\",0.01000000000000]]";

	int stOne;
	struct cs_Csdef_ csDefOne;
	struct cs_Dtdef_ dtDefOne;
	struct cs_Eldef_ elDefOne;

	int stTwo;
	struct cs_Csdef_ csDefTwo;
	struct cs_Dtdef_ dtDefTwo;
	struct cs_Eldef_ elDefTwo;

	int stThree;
	struct cs_Csdef_ csDefThree;
	struct cs_Dtdef_ dtDefThree;
	struct cs_Eldef_ elDefThree;

	int stFour;
	struct cs_Csdef_ csDefFour;
	struct cs_Dtdef_ dtDefFour;
	struct cs_Eldef_ elDefFour;

	int stFive;
	struct cs_Csdef_ csDefFive;
	struct cs_Dtdef_ dtDefFive;
	struct cs_Eldef_ elDefFive;

	int stSix;
	struct cs_Csdef_ csDefSix;
	struct cs_Dtdef_ dtDefSix;
	struct cs_Eldef_ elDefSix;

	int stSeven;
	struct cs_Csdef_ csDefSeven;
	struct cs_Dtdef_ dtDefSeven;
	struct cs_Eldef_ elDefSeven;

	int stEight;
	struct cs_Csdef_ csDefEight;
	struct cs_Dtdef_ dtDefEight;
	struct cs_Eldef_ elDefEight;

	int stNine;
	struct cs_Csdef_ csDefNine;
	struct cs_Dtdef_ dtDefNine;
	struct cs_Eldef_ elDefNine;

	csErrmsg [0] = '\0';
	stOne = CS_wktToCsEx (&csDefOne,&dtDefOne,&elDefOne,wktFlvrOgc,wktOne,TRUE);
	if (verbose && stOne < 0)
	{
		printf ("WKT1 processing failed! Status = %d; Reason: %s\n",stOne,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stTwo = CS_wktToCsEx (&csDefTwo,&dtDefTwo,&elDefTwo,wktFlvrNone,wktTwo,FALSE);
	if (verbose && stTwo < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stTwo,csErrmsg);
	}


	csErrmsg [0] = '\0';
	stThree = CS_wktToCsEx (&csDefThree,&dtDefThree,&elDefThree,wktFlvrOgc,wktThree,TRUE);
	if (verbose && stThree < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stThree,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stFour = CS_wktToCsEx (&csDefFour,&dtDefFour,&elDefFour,wktFlvrOgc,wktFour,TRUE);
	if (verbose && stFour < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stFour,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stFive = CS_wktToCsEx (&csDefFive,&dtDefFive,&elDefFive,wktFlvrOgc,wktFive,TRUE);
	if (verbose && stFive < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stFive,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stSix = CS_wktToCsEx (&csDefSix,&dtDefSix,&elDefSix,wktFlvrEsri,wktSix,TRUE);
	if (verbose && stSix < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stSix,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stSeven = CS_wktToCsEx (&csDefSeven,&dtDefSeven,&elDefSeven,wktFlvrEsri,wktSeven,TRUE);
	if (verbose && stSeven < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stSeven,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stEight = CS_wktToCsEx (&csDefEight,&dtDefEight,&elDefEight,wktFlvrEsri,wktEight,TRUE);
	if (verbose && stEight < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stEight,csErrmsg);
	}

	csErrmsg [0] = '\0';
	stNine = CS_wktToCsEx (&csDefNine,&dtDefNine,&elDefNine,wktFlvrEsri,wktNine,TRUE);
	if (verbose && stNine < 0)
	{
		printf ("WKT2 processing failed! Status = %d; Reason: %s\n",stNine,csErrmsg);
	}

	err_cnt += (stOne   != 0);
	err_cnt += (stTwo   != 0);
	err_cnt += (stThree != 0);
	err_cnt += (stFour  != 0);
	err_cnt += (stFive  != 0);
	err_cnt += (stSix   != 0);
	err_cnt += (stSeven != 0);
	err_cnt += (stEight != 0);
	err_cnt += (stNine != 0);

#endif
#ifdef __SKIP__
	int st;

	unsigned idx;
	unsigned gxIdxCnt;

	Const struct cs_GxIndex_* gxIdxPtr;
	struct cs_GeodeticTransform_ *gxDefPtr;

	int err_list [8];

	gxIdxCnt = CS_getGxIndexCount ();
	for (idx = 0;idx < gxIdxCnt;idx++)
	{
		gxIdxPtr = CS_getGxIndexEntry (idx);
		if (gxIdxPtr == NULL)
		{
			err_cnt += 1;
		}
		else
		{
			gxDefPtr = CS_gxdef (gxIdxPtr->xfrmName);
			if (gxDefPtr == NULL)
			{
				err_cnt += 1;
			}
			else
			{
				st = CS_gxchk (gxDefPtr,cs_GXCHK_DATUM | cs_GXCHK_REPORT,err_list,sizeof (err_list) / sizeof (int));
				if (st != 0)
				{
					printf ("CS_gxchk failed on geodetic transformation named %s.\n",gxDefPtr->xfrmName);
					err_cnt += 1;
				}
				CS_free (gxDefPtr);
			}
		}
	}
#endif
#ifdef __SKIP__
	int st;
	printf ("Running temporary test code module.\n");


	struct cs_GeodeticTransform_* gx_def1;
	struct cs_GeodeticTransform_* gx_def2;


	gx_def1 = CS_gxdef ("NAD27_to_NAD83");
	gx_def2 = CS_gxdef ("ABIDJAN-87_to_WGS84");
	
	st = CS_gxupd (gx_def1);
	st = CS_gxupd (gx_def2);

	gx_def1 = CS_gxdef ("NAD27_to_NAD83");
	gx_def2 = CS_gxdef ("ABIDJAN-87_to_WGS84");
#endif
#ifdef __SKIP__
	int st;

	const char* csOneName = "LL27";
	const char* csTwoName = "Tokyo";

	struct cs_Csprm_ *csOne;
	struct cs_Csprm_ *csTwo;
	struct cs_Dtcprm_ *dtcPrm;

	double llTmp [3];

	printf ("Running temporary test code module.\n");

	csOne = CS_csloc (csOneName);
	csTwo = CS_csloc (csTwoName);
	if (csOne == NULL || csTwo == NULL)
	{
		return 1;
	}

	dtcPrm = CS_dtcsu (csOne,csTwo,cs_DTCFLG_DAT_F,cs_DTCFLG_BLK_W);
	if (dtcPrm == NULL)
	{
		return 1;
	}

	llTmp [0] = -122.1509375;
	llTmp [1] = 36.10875;
	llTmp [2] = 0.0;

	st = CS_dtcvt3D (dtcPrm,llTmp,llTmp);

	if (st != 0)
	{
		err_cnt += 1;
	}

	CS_dtcls (dtcPrm);
#endif
#ifdef __SKIP__
	int st;
	int counter;
	FILE* tstStrm;
	struct cs_Csprm_ *csOne;
	struct cs_Csprm_ *csTwo;
	struct cs_Dtcprm_ *dtcPrm;

	double lngMin = -5.5000;
	double lngMax = 10.0000;
	double latMin = 41.0000;
	double latMax = 52.0000;

	double llOne [3];
	double llTmp [3];
	double llTwo [3];

	const char* csOneName = "LL-RGF93";
	const char* csTwoName = "NTF.LL";

	tstStrm = fopen ("C:\\Tmp\\TestPoints.txt","wt");
	if (tstStrm == NULL)
	{
		return 1;
	}

	csOne = CS_csloc (csOneName);
	csTwo = CS_csloc (csTwoName);
	if (csOne == NULL || csTwo == NULL)
	{
		return 1;
	}
	dtcPrm = CS_dtcsu (csOne,csTwo,cs_DTCFLG_DAT_F,cs_DTCFLG_BLK_W);
	if (dtcPrm == NULL)
	{
		return 1;
	}

	for (counter = 0;counter < duration;counter += 1)
	{
		st = 0;
		llOne [0] = CStestRN (lngMin,lngMax);
		llOne [1] = CStestRN (latMin,latMax);
		llOne [2] = 0.0;
		st  = CS_cs3ll (csOne,llTmp,llOne);
		st |= CS_dtcvt (dtcPrm,llTmp,llTmp);
		st |= CS_ll3cs (csTwo,llTwo,llTmp);
	    
		fprintf (tstStrm,"%s,%.9f,%.9f,%s,%.9f,%.9f,1.0E-08,1.0E-08\n",csOneName,llOne [0],
																				 llOne [1],
																				 csTwoName,
																				 llTwo [0],
																				 llTwo [1]);
		fprintf (tstStrm,"%s,%.9f,%.9f,%s,%.9f,%.9f,1.0E-08,1.0E-08\n",csTwoName,llTwo [0],
																				 llTwo [1],
																				 csOneName,
																				 llOne [0],
																				 llOne [1]);
		if (st != 0)
		{
			err_cnt += 1;
		}
	}
	fclose (tstStrm);
#endif
#ifdef __SKIP__
	int st;

	const char* dtOneName = "AFGOOYE";
	const char* dtTwoName = "WGS84";

	struct cs_Datum_ *dtOne;
	struct cs_Datum_ *dtTwo;
	struct cs_Dtcprm_ *dtcPrm;

	double llTmp [3];

	printf ("Running temporary test code module.\n");

	dtOne = CS_dtloc (dtOneName);
	dtTwo = CS_dtloc (dtTwoName);
	if (dtOne == NULL || dtTwo == NULL)
	{
		return 1;
	}

	dtcPrm = CSdtcsu (dtOne,dtTwo,cs_DTCFLG_DAT_F,cs_DTCFLG_BLK_W);
	if (dtcPrm == NULL)
	{
		return 1;
	}

	CS_dtcls (dtcPrm);
#endif

	return err_cnt;
}