コード例 #1
0
ファイル: CStest8.c プロジェクト: asir6/Colt
int CStest8 (int verbose,int crypt)
{
    extern char cs_MeKynm [128];
    extern char cs_MeFunc [128];
    extern double cs_Coords [3];

	extern struct cs_Grptbl_ cs_CsGrptbl [];
	extern int cs_Error;

	int err_cnt;

	struct cs_Grptbl_ *tp;
	struct cs_Csgrplst_ *gp;
	struct cs_Csgrplst_ *grp_list;
	struct cs_Csprm_ *csprm;

	double xy [3];
	double ll [3];

	printf ("Exercising each coordinate system definition at least once.\n");

	/* Loop through the group table and fetch a linked list
	   for each group.  Count the number in the group and
	   add to the total in the group. */

	err_cnt = 0;
	for (tp = cs_CsGrptbl;tp->group [0] != 0;tp += 1)
	{
		if (!CS_stricmp (tp->group,"LEGACY"))
		{
			continue;
		}
		CS_csgrp (tp->group,&grp_list);
		for (gp = grp_list;gp != NULL;gp = gp->next)
		{
			/* Activate this coordinate system.  This
			   ensures that every coordinate system
			   is "set up" at least once in all of this. */

			if (verbose)
			{
				printf ("Exercising coordinate system named %s.\n",
							gp->key_nm);
			}
			csprm = CS_csloc (gp->key_nm);
			if (csprm == NULL)
			{
				printf ("Couldn't setup coordinate system named %s.\n",gp->key_nm);
				err_cnt += 1;
			}
			else
			{
			    /* Set information in case there is a floating point exception. */
			    CS_stncp (cs_MeKynm,gp->key_nm,sizeof (cs_MeKynm));
			    cs_Coords [0] = csprm->csdef.x_off;
			    cs_Coords [1] = csprm->csdef.y_off;
			    cs_Coords [2] = 0.0;
   
				/* Convert a coordinate, the false origin should
				   be a safe one. */

				xy [0] = csprm->csdef.x_off;
				xy [1] = csprm->csdef.y_off;
				xy [2] = 0.0;
				cs_Error = 0;
				CS_stncp (cs_MeFunc,"CS_cs2ll",sizeof (cs_MeFunc));
				CS_cs2ll (csprm,ll,xy);
				CS_stncp (cs_MeFunc,"CS_ll2cs",sizeof (cs_MeFunc));
				CS_ll2cs (csprm,xy,ll);
				CS_stncp (cs_MeFunc,"CS_csscl",sizeof (cs_MeFunc));
				CS_csscl (csprm,ll);
				CS_stncp (cs_MeFunc,"CS_cscnv",sizeof (cs_MeFunc));
				CS_cscnv (csprm,ll);
				if (cs_Error != 0)
				{
					printf ("Exercise of coordinate system %s failed.\n",
								csprm->csdef.key_nm);
					err_cnt += 1;
				}
				CS_free (csprm);
			}
		}
		CS_csgrpf (grp_list);
	}
    cs_MeKynm [0] = '\0';
    cs_MeFunc [0] = '\0';
    cs_Coords [0] = 0.0;
    cs_Coords [1] = 0.0;
    cs_Coords [2] = 0.0;
	return (err_cnt);
}
コード例 #2
0
ファイル: CS_hlApi.c プロジェクト: auranet/csmap
void EXP_LVL1 CS_recvr (void)
{
	extern csThread struct cs_Ostn97_ *cs_Ostn97Ptr;
	extern csThread struct cs_Ostn02_ *cs_Ostn02Ptr;

	extern csThread struct csCscach_ *csCscachP;
	extern csThread struct csDtcach_ *csDtcachP;

	extern csThread char *cs_CsKeyNames;
	extern csThread char *cs_DtKeyNames;
	extern csThread char *cs_ElKeyNames;
	extern csThread char *cs_CsLlEnum;
	extern csThread struct cs_Csgrplst_ *cs_CsGrpList;
	extern csThread struct cs_Mgrs_ *cs_MgrsPtr;

	struct csDtcach_ *dtch_ptr;
	struct csDtcach_ *dtch_tmp;

	struct csCscach_ *csch_ptr;
	struct csCscach_ *csch_tmp;

	/* Kludge time.  Delete any cs_Ostn97_ object which may currently exist. */
	if (cs_Ostn97Ptr != NULL)
	{
		CSdeleteOstn97 (cs_Ostn97Ptr);
		cs_Ostn97Ptr = NULL;
	}
	if (cs_Ostn02Ptr != NULL)
	{
		CSdeleteOstn02 (cs_Ostn02Ptr);
		cs_Ostn02Ptr = NULL;
	}

	/* Loop through the datum conversion cache. */

	dtch_ptr = csDtcachP;
	while (dtch_ptr != NULL)
	{
		/* If this entry has a datum conversion, close it. */

		if (dtch_ptr->dtc_ptr != NULL)
		{
			CS_dtcls (dtch_ptr->dtc_ptr);
			dtch_ptr->dtc_ptr = NULL;
		}

		/* Unlink this entry from the list.  We try to keep the list
		   intact in case of an error. */

		dtch_tmp = dtch_ptr;
		dtch_ptr = dtch_ptr->next;
		csDtcachP = dtch_ptr;
		if (dtch_ptr != NULL)
		{
			dtch_ptr->prev = NULL;
		}

		/* Free the cache entry. */

		CS_free (dtch_tmp);
	}

	/* Same with the coordinate systems. */

	csch_ptr = csCscachP;
	while (csch_ptr != NULL)
	{
		if (csch_ptr->cs_ptr != NULL)
		{
			CS_free (csch_ptr->cs_ptr);
			csch_ptr->cs_ptr = NULL;
		}
		csch_tmp = csch_ptr;
		csch_ptr = csch_ptr->next;
		csCscachP = csch_ptr;
		if (csch_ptr != NULL)
		{
			csch_ptr->prev = NULL;
		}
		CS_free (csch_tmp);
	}

	/* Free up any name lists which may be present. */

	if (cs_CsKeyNames != NULL)
	{
		CS_free (cs_CsKeyNames);
		cs_CsKeyNames = NULL;
	}
	if (cs_DtKeyNames != NULL)
	{
		CS_free (cs_DtKeyNames);
		cs_DtKeyNames = NULL;
	}
	if (cs_ElKeyNames != NULL)
	{
		CS_free (cs_ElKeyNames);
		cs_ElKeyNames = NULL;
	}
	if (cs_CsLlEnum != NULL)
	{
		CS_free (cs_CsLlEnum);
		cs_CsLlEnum = NULL;
	}
	if (cs_CsGrpList != NULL)
	{
		CS_csgrpf (cs_CsGrpList);
		cs_CsGrpList = NULL;
	};

	/* Do the high level MGRS stuff. */
	if (cs_MgrsPtr != NULL)
	{
		CS_free (cs_MgrsPtr);
		cs_MgrsPtr = NULL;
	}

	return;
}
コード例 #3
0
ファイル: CStestC.cpp プロジェクト: asir6/Colt
int CStestC (bool verbose,long32_t duration)
{
	int err_cnt;

	unsigned sequencer;

	struct cs_Grptbl_ *tp;
	struct cs_Csgrplst_ *gp;
	struct cs_Csgrplst_ *grp_list;
	struct cs_Csprm_ *csprm;

	double ll [3];
	double xy [3];
	double falseOrg [2];
	double llAry [1][3];
	double xyAry [1][3];

	duration *= 10L;

	printf ("Trying very hard to produce a floating point exception.\n");

	/* Loop through the group table and fetch a linked list
	   for each group.  Count the number in the group and
	   add to the total in the group. */

	err_cnt = 0;
	csprm = NULL;
	for (tp = cs_CsGrptbl;tp->group [0] != 0;tp += 1)
	{
		if (csprm != NULL)
		{
			CS_free (csprm);
			csprm = NULL;
		}
		if (!CS_stricmp (tp->group,"LEGACY"))
		{
			continue;
		}
		CS_csgrp (tp->group,&grp_list);
		for (gp = grp_list;gp != NULL;gp = gp->next)
		{
			if (csprm != NULL)
			{
				CS_free (csprm);
				csprm = NULL;
			}
			if (verbose)
			{
				printf ("Trying to cause a floating exception using %s.\n",
							gp->key_nm);
			}
			else
			{
				printf ("%s               \r",gp->key_nm);
			}

			csprm = CS_csloc (gp->key_nm);
			if (csprm == NULL)
			{
				printf ("Couldn't setup coordinate system named %s.\n",gp->key_nm);
				err_cnt += 1;
				strcpy (cs_MeKynm,"???");
				continue;
			}
			cs_MeFlag = 0;
			strcpy (cs_MeKynm,csprm->csdef.key_nm);
			
			sequencer = 0;
			while (CStestLLH (ll,csprm->cent_mer,&sequencer) == 0)
			{
				cs_Coords [LNG] = ll [0];
				cs_Coords [LAT] = ll [1];
				cs_Coords [HGT] = ll [2];

				strcpy (cs_MeFunc,"CS_cssck");
				CS_cssck (csprm,ll);
				if (cs_MeFlag) break;
				strcpy (cs_MeFunc,"CS_cssch");
				CS_cssch (csprm,ll);
				if (cs_MeFlag) break;
				strcpy (cs_MeFunc,"CS_cscnv");
				CS_cscnv (csprm,ll);
				if (cs_MeFlag) break;
				strcpy (cs_MeFunc,"CS_ll2cs");
				CS_ll2cs (csprm,xy,ll);
				if (cs_MeFlag) break;

				llAry [0][0] = ll [0];		/* keep gcc compiler happy */
				llAry [0][1] = ll [1];
				llAry [0][2] = ll [2];
				strcpy (cs_MeFunc,"CS_llchk");
				CS_llchk (csprm,1,llAry);
				if (cs_MeFlag) break;
			}
			if (cs_MeFlag)
			{
				if (verbose)
				{
					printf ("\tLNG = %g, LAT = %g, HGT = %g     \n",ll [0],ll [1],ll [2]);
				}
				err_cnt += 1;
				continue;
			}

			sequencer = 0;
			falseOrg [0] = csprm->csdef.x_off;
			falseOrg [1] = csprm->csdef.y_off;
			while (CStestXYZ (xy,falseOrg,&sequencer) == 0)
			{
				cs_Coords [XX] = xy [XX];
				cs_Coords [YY] = xy [YY];
				cs_Coords [ZZ] = xy [ZZ];
				strcpy (cs_MeFunc,"CS_cs2ll");
				CS_cs2ll (csprm,ll,xy);
				if (cs_MeFlag) break;
				strcpy (cs_MeFunc,"CS_llchk");
				xyAry [0][0] = xy [0];		/* keep gcc compiler happy */
				xyAry [0][1] = xy [1];
				xyAry [0][2] = xy [2];
				CS_xychk (csprm,1,xyAry);
				if (cs_MeFlag) break;
			}
			if (cs_MeFlag)
			{
				if (verbose)
				{
					printf ("\tXX = %g, YY = %g, ZZ = %g          \n",xy [XX],xy [YY],xy [ZZ]);
				}
				err_cnt += 1;
				continue;
			}

			if (verbose)
			{
				printf ("                                                \r");
			}
			CS_free (csprm);
			csprm = NULL;
		}
		CS_csgrpf (grp_list);
	}
	printf ("                                 \r");
	return (err_cnt);
}
コード例 #4
0
ファイル: CStestE.cpp プロジェクト: kanbang/Colt
int CStestE (bool verbose,long32_t duration)
{
    bool special;

    int index;
    int status;
    int err_cnt;
    int isPseudo;

    long32_t il;

    struct cs_Grptbl_ *tp;
    struct cs_Csgrplst_ *gp;
    struct cs_Csgrplst_ *grp_list;
    struct cs_Csprm_ *csprm;

    double ll  [3];
    double xy  [3];
    double ll1 [3];

    double lat_del;
    double low_lng;
    double low_lat;
    double hi_lng;
    double hi_lat;
    double ll_tol;
    double del_lng;
    double del_lat;

    duration *= 100L;

    printf ("Checking reversibility of all projections, smaller region/tolerance.\n");

    /* Loop through the group table and fetch a linked list
       for each group.  Count the number in the group and
       add to the total in the group. */

    err_cnt = 0;
    csprm = NULL;
    for (tp = cs_CsGrptbl; tp->group [0] != 0; tp += 1)
    {
        if (csprm != NULL)
        {
            CS_free (csprm);
            csprm = NULL;
        }
        if (!CS_stricmp (tp->group,"LEGACY"))
        {
            continue;
        }
        CS_csgrp (tp->group,&grp_list);
        for (gp = grp_list; gp != NULL; gp = gp->next)
        {
            if (csprm != NULL)
            {
                CS_free (csprm);
                csprm = NULL;
            }
            if (verbose)
            {
                printf ("Testing %s for reversibility.\n",
                        gp->key_nm);
            }
            else
            {
                printf ("%s               \r",gp->key_nm);
            }

            csprm = CS_csloc (gp->key_nm);
            if (csprm == NULL)
            {
                printf ("Couldn't setup coordinate system named %s.\n",gp->key_nm);
                err_cnt += 1;
                continue;
            }
            strcpy (cs_MeKynm,csprm->csdef.key_nm);

            /* Is this one on the "special" list? */
            special = false;
            for (index = 0; KcsTestEspecialList [index][0] != '\0'; index += 1)
            {
                if (!CS_stricmp (csprm->csdef.key_nm,KcsTestEspecialList [index]))
                {
                    special = true;
                    break;
                }
            }

            isPseudo = FALSE;
            if (csprm->prj_code == cs_PRJCOD_MRCATPV)
            {
                isPseudo = TRUE;
            }

            /* Get the useful range of the coordinate system and reduce it
               by about one half. */
            if (special)
            {
                /* here to reduce by two thirds. */
                low_lng = csprm->cent_mer + csprm->min_ll [LNG] + fabs (csprm->min_ll [LNG] * 0.6666);
                hi_lng =  csprm->cent_mer + csprm->max_ll [LNG] - fabs (csprm->min_ll [LNG] * 0.6666);
                lat_del = csprm->max_ll [LAT] - csprm->min_ll [LAT];
                low_lat = csprm->min_ll [LAT] + lat_del * 0.333333;
                hi_lat  = csprm->max_ll [LAT] - lat_del * 0.333333;
            }
            else
            {
                /* Code that has been used for testE for many years before the "special fix", unedited. */
                low_lng = csprm->cent_mer + csprm->min_ll [LNG] + fabs (csprm->min_ll [LNG] * 0.5);
                hi_lng =  csprm->cent_mer + csprm->max_ll [LNG] - fabs (csprm->min_ll [LNG] * 0.5);
                lat_del = csprm->max_ll [LAT] - csprm->min_ll [LAT];
                low_lat = csprm->min_ll [LAT] + lat_del * 0.5;
                hi_lat  = csprm->max_ll [LAT] - lat_del * 0.5;
            }

            /* insure that there is a range of some sort. */
            if ((hi_lng - low_lng) < cs_One)
            {
                low_lng = csprm->cent_mer - cs_Half;
                hi_lng = csprm->cent_mer + cs_Half;
            }
            if ((hi_lat - low_lat) < cs_One)
            {
                low_lat = ((csprm->max_ll [LAT] + csprm->min_ll [LAT]) * cs_Half) - cs_Half;
                hi_lat = low_lat + cs_One;
            }

            for (il = 0; il < duration; il += 1)
            {
                ll [LNG] = CStestRN (low_lng,hi_lng);
                ll [LNG] = CS_adj180 (ll [LNG]);
                ll [LAT] = CStestRN (low_lat,hi_lat);

                /* The pseudo Mercator cannot convert any point with
                   latitude higher than 84. */
                if (isPseudo && fabs (ll [LAT]) > 83.0)
                {
                    continue;
                }

                /* For the two projections which account for 95% of
                   the mapping in the world, we use a very small
                   tolerance which approximates 5 millimeters on the
                   earth.  For the less important projections, we
                   use a tolerance which approximates 50 millimeters.

                   That is, for several projections, specifically the
                   whole world type, the mathemagics simply doesn't
                   produce the same level of accuracy as the two
                   biggies do.

                   As the Van der Grinten approaches the central
                   meridian, however, we need to relax the tolerance
                   to account for the mathematical discontinuity
                   encountered there. */

                if (csprm->prj_code == cs_PRJCOD_TRMER ||
                        csprm->prj_code == cs_PRJCOD_LM2SP)
                {
                    ll_tol = 4.5E-08;
                }
                else if (csprm->prj_code == cs_PRJCOD_CSINI)
                {
                    /* Cassini doesn't reverse very well.  This is well known
                       in the coordinate conversion community.  Someone needs
                       to figure out the math involved and improve the
                       projection formulas. */
                    ll_tol = 2.5E-06;
                }
                else
                {
                    ll_tol = 4.5E-07;
                }
                if (csprm->prj_code == cs_PRJCOD_VDGRN)
                {
                    if (fabs (ll [0] - csprm->cent_mer) < 0.1) ll_tol = 1.0E-05;
                }

                /* Due to the polynomials, the Danish stuff does not invert well
                   when you're not within the real domain of the polynomial; i.e.
                   actually in the region being converted.  Thus, randomly generated
                   numbers like this do not invert well.

                   The polynomial code uses the inverse to determine if a coordinate
                   pair is within the useful range of the polynomial.  The tolerance
                   check is set to 4 centimeters.  Adjusting for the latitude of
                   Denmark, we use the following tolerance. */
                if (csprm->prj_code == cs_PRJCOD_SYS34    ||
                        csprm->prj_code == cs_PRJCOD_SYS34_99 ||
                        csprm->prj_code == cs_PRJCOD_SYS34_01)
                {
                    ll_tol = 7.0E-06;
                }

                /* Convert to X and Y, then back again. */

                strcpy (cs_MeFunc,"CS_ll2cs");
                status = CS_ll2cs (csprm,xy,ll);
                if (status != cs_CNVRT_NRML) continue;
                strcpy (cs_MeFunc,"CS_cs2ll");
                status = CS_cs2ll (csprm,ll1,xy);
                if (status != cs_CNVRT_NRML) continue;

                /* Conversions were OK, see if we
                   ended up with what we started
                   with. */

                del_lng = CS_adj180 (ll [0] - ll1 [0]);
                del_lat = ll [1] - ll1 [1];
                if (fabs (del_lng) > ll_tol ||
                        fabs (del_lat) > ll_tol)
                {
                    printf ("%s:: Couldn't reverse %f:%f.\n",csprm->csdef.key_nm,ll[0],ll[1]);
                    printf ("\t\tdel_lng = %g,del_lat = %g.\n",del_lng,del_lat);
                    err_cnt += 1;

                    /* Uncomment the following for
                       easier debugging. */

                    status = CS_ll2cs (csprm,xy,ll);
                    status = CS_cs2ll (csprm,ll1,xy);
                }
            }

            CS_free (csprm);
            csprm = NULL;
        }
        CS_csgrpf (grp_list);
    }
    return (err_cnt);
}