Пример #1
0
int EXP_LVL9 CSwgs72Q (struct cs_GeodeticTransform_ *gxDef,unsigned short xfrmCode,int err_list [],int list_sz)
{
	int err_cnt;

	/* We will return (err_cnt + 1) below. */
	err_cnt = -1;
	if (err_list == NULL) list_sz = 0;

	/* Check the definition stuff specific to cswgs72_
	   Unlike other methods, this is a method explicitly
	   for WGS72 to WGS84.  Thus, we verify that the target
	   datum is indeed WGS84.  It is perhaps a bit klutzy
	   to do this strictly by name; but WGS72 is rearely used. */
	if (CS_stricmp (gxDef->srcDatum,"WGS72"))
	{
		if (++err_cnt < list_sz) err_list [err_cnt] = cs_DTQ_WGS72SRC;
	}
	if (CS_stricmp (gxDef->trgDatum,"WGS84"))
	{
		if (++err_cnt < list_sz) err_list [err_cnt] = cs_DTQ_WGS72TRG;
	}
	return (err_cnt + 1);
}
Пример #2
0
int EXP_LVL7 CS_dtcmp (Const struct cs_Dtdef_ *pp,Const struct cs_Dtdef_ *qq)
{
    cs_Register unsigned char key;
    cs_Register unsigned char *cp;

    int st;

    unsigned char *cpe;

    char pp_key [24];
    char qq_key [24];

    /* If the entries are encoded, we must decode before the
       comparision is made.  Note, this whole encryption
       scheme is designed to decode from the front, therefore
       we need only deal with the first 24 characters. */

    (void)memcpy (pp_key,pp->key_nm,sizeof (pp_key));
    key = (unsigned char)pp->fill [0];
    if (key != '\0')
    {
        cp = (unsigned char *)pp_key;
        cpe = cp + sizeof (pp_key);
        while (cp < cpe)
        {
            key ^= *cp;
            *cp++ = key;
        }
    }
    (void)memcpy (qq_key,qq->key_nm,sizeof (qq_key));
    key = (unsigned char)qq->fill [0];
    if (key != '\0')
    {
        cp = (unsigned char *)qq_key;
        cpe = cp + sizeof (qq_key);
        while (cp < cpe)
        {
            key ^= *cp;
            *cp++ = key;
        }
    }

    /* OK, now we can compare the two structures.  For sorting
       and binary search purposes, we only look at the key name. */

    st = CS_stricmp (pp_key,qq_key);

    return (st);
}
Пример #3
0
/**********************************************************************
**	cmp_val = CS_elcmp (pp,qq);
**
**	struct cs_Eldef_ *pp;
**	struct cs_Eldef_ *qq;		The two ellipsoid definition structures which are
**								to be compared.
**	int cmp_val;				return is negative if pp follows qq in the
**								collating sequence, positive if pp preceeds
**								qq, and zero if they are equivalent.
**********************************************************************/
int EXP_LVL7 CS_elcmp (Const struct cs_Eldef_ *pp,Const struct cs_Eldef_ *qq)
{
	cs_Register unsigned char key;
	cs_Register unsigned char *cp;

	int st;

	unsigned char *cpe;

	char pp_key [24];
	char qq_key [24];

	/* If the entries are encoded, we must decode before the
	   comparision is made. */

	(void)memcpy (pp_key,pp->key_nm,sizeof (pp_key));
	key = (unsigned char)pp->fill [0];
	if (key != '\0')
	{
		cp = (unsigned char *)pp_key;
		cpe = cp + sizeof (pp_key);
		while (cp < cpe)
		{
			key ^= *cp;
			*cp++ = key;
		}
	}
	(void)memcpy (qq_key,qq->key_nm,sizeof (qq_key));
	key = (unsigned char)qq->fill [0];
	if (key != '\0')
	{
		cp = (unsigned char *)qq_key;
		cpe = cp + sizeof (qq_key);
		while (cp < cpe)
		{
			key ^= *cp;
			*cp++ = key;
		}
	}

	/* OK, now we can compare the two structures.  For sorting
	   and binary search purposes, we only lookl at the key name. */

	st = CS_stricmp (pp_key,qq_key);

	return (st);
}
Пример #4
0
int CSdtdefwr (	csFILE *outStrm,
				struct cs_Dtdef_ *dtdef,
				int crypt,
				int warn,
				csFILE *elStrm,
				int (*err_func)(char *mesg)
			  )
{
	extern double cs_Zero;			/* 0.0 */

	int err_cnt;
	int cancel;
	int flag;
	int tr_cnt;
	int rt_cnt;
	int sc_cnt;

	char err_msg [128];
 
 	__ALIGNMENT__2		/* For some versions of Sun compiler. */
	struct cs_Eldef_ eldef;

	err_cnt = 0;
	cancel = 0;
	
	if (dtdef->to84_via == cs_DTCTYP_NONE)
	{
		sprintf (err_msg,"Conversion specification missing in definition of %s.",dtdef->key_nm);
		cancel = (*err_func)(err_msg);
		err_cnt += 1;
	}

	/* Make some last minute checks which can't be done by
	   the line processor. */
	tr_cnt = 3;
	if (dtdef->delta_X == no_value) tr_cnt -= 1;
	if (dtdef->delta_Y == no_value) tr_cnt -= 1;
	if (dtdef->delta_Z == no_value) tr_cnt -= 1;
	rt_cnt = 3;
	if (dtdef->rot_X == no_value) rt_cnt -= 1;
	if (dtdef->rot_Y == no_value) rt_cnt -= 1;
	if (dtdef->rot_Z == no_value) rt_cnt -= 1;
	sc_cnt = 1;
	if (dtdef->bwscale == no_value) sc_cnt -= 1;

	switch (dtdef->to84_via) {

	case cs_DTCTYP_MOLO:
	case cs_DTCTYP_3PARM:
		if (tr_cnt != 3)
		{
			sprintf (err_msg,"Delta[XYZ] value(s) missing for datum named %s.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
		if ((rt_cnt != 0 || sc_cnt != 0) && warn)
		{
			sprintf (err_msg,"Warning: unused Bursa/Wolfe parameters present for %s.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
		}
		break;

	case cs_DTCTYP_BURS:
	case cs_DTCTYP_7PARM:
		if (tr_cnt != 3 || rt_cnt != 3 || sc_cnt != 1)
		{
			sprintf (err_msg,"Missing parameters for %s.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
		break;

	case cs_DTCTYP_6PARM:
		if (tr_cnt != 3 || rt_cnt != 3)
		{
			sprintf (err_msg,"Missing parameters for %s.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
		if (sc_cnt != 0 && warn)
		{
			sprintf (err_msg,"Warning: datum %s has unused scale parameter specified.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
		}
		break;

	case cs_DTCTYP_4PARM:
		if (tr_cnt != 3 || sc_cnt != 1)
		{
			sprintf (err_msg,"Missing parameters for %s.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
		if (rt_cnt != 0 && warn)
		{
			sprintf (err_msg,"Warning: datum %s has unused rotation parameters specified.",dtdef->key_nm);
			cancel = (*err_func)(err_msg);
		}
		break;

	case cs_DTCTYP_MREG:
	case cs_DTCTYP_NAD27:
	case cs_DTCTYP_NAD83:
	case cs_DTCTYP_WGS84:
	case cs_DTCTYP_WGS72:
	case cs_DTCTYP_HPGN:
	case cs_DTCTYP_AGD66:
	case cs_DTCTYP_AGD84:
	case cs_DTCTYP_NZGD49:
	case cs_DTCTYP_ATS77:
	case cs_DTCTYP_GDA94:
	case cs_DTCTYP_NZGD2K:
	case cs_DTCTYP_CSRS:
	case cs_DTCTYP_TOKYO:
	case cs_DTCTYP_RGF93:
	case cs_DTCTYP_ED50:
	case cs_DTCTYP_DHDN:
	case cs_DTCTYP_ETRF89:
		break;

	default:
		sprintf (err_msg,"Internal software error, CSdtcomp:%d.",__LINE__);
		cancel = (*err_func)(err_msg);
		err_cnt += 1;
		break;
	}

	/* For those values not specified, we reset them to hard zero. */
	if (dtdef->delta_X == no_value) dtdef->delta_X = cs_Zero;
	if (dtdef->delta_Y == no_value) dtdef->delta_Y = cs_Zero;
	if (dtdef->delta_Z == no_value) dtdef->delta_Z = cs_Zero;
	if (dtdef->rot_X == no_value) dtdef->rot_X = cs_Zero;
	if (dtdef->rot_Y == no_value) dtdef->rot_Y = cs_Zero;
	if (dtdef->rot_Z == no_value) dtdef->rot_Z = cs_Zero;
	if (dtdef->bwscale == no_value) dtdef->bwscale = cs_Zero;

	if (dtdef->ell_knm [0] == '\0')
	{
		sprintf (err_msg,"No ellipsoid specified for datum named %s.",dtdef->key_nm);
		cancel = (*err_func)(err_msg);
		err_cnt += 1;
	}
	else if (elStrm != 0)
	{
		CS_stncp (eldef.key_nm,dtdef->ell_knm,sizeof (eldef.key_nm));
		CS_nampp (eldef.key_nm);							/*lint !e534 */
		eldef.fill [0] = '\0';
		eldef.fill [1] = '\0';
		flag = CS_bins (elStrm,(long)sizeof (cs_magic_t),-1L,
						sizeof (eldef),
						&eldef,
						(CMPFUNC_CAST)CS_elcmp);
		if (flag == 0)
		{
			sprintf (err_msg,"Invalid ellipsoid name, %s, on line %d.",dtdef->ell_knm,line_nbr);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
	}

	if (err_cnt == 0)
	{
		dtdef->protect = TRUE;
		/* The following sets the "creation date" to Jan 1, 2002 (approx) for
		   all test coordinate systems.  This enables the protection system to
		   be tested.  Normally, distribution definitions are protected from
		   any kind of change. */
		if (!CS_stricmp (dtdef->group,"TEST")) dtdef->protect = 4383;
		dtdef->fill [0] = '\0';
		dtdef->fill [1] = '\0';
		CS_dtwr (outStrm,dtdef,crypt);					/*lint !e534 */
	}
	if (warn && dtdef->name [0] == '\0')
	{
		sprintf (err_msg,"No description provided for datum %s.",dtdef->key_nm);
		cancel = (*err_func)(err_msg);
	}
	if (warn && dtdef->source [0] == '\0')
	{
		sprintf (err_msg,"No source provided for datum %s.",dtdef->key_nm);
		cancel = (*err_func)(err_msg);
	}
	if (cancel && err_cnt == 0) err_cnt = 1;
	return (cancel ? -err_cnt : err_cnt);
}
Пример #5
0
csFILE *CS_fopen(const char *filename, const char *mode)
{
	extern char cs_DirsepC;
	struct stat statbuf;
	csFILE *result = NULL;
	char *fixed_filename = (char*) filename;

	/* If we are attempting to read from the file, and the file passed
	 * in does not exist, look for a different file in the same directory
	 * that has the same filename with a different case.
	 */

	if ( (*mode == *_STRM_TXTRD) && stat(filename,&statbuf) )
	{
		/* Make a copy of the filename passed in, and separate it into
		 * directory and path components.
		 */

		char *last_path_sep;

		fixed_filename = (char*) malloc(strlen(filename)+1);
		strcpy(fixed_filename,filename);
		last_path_sep = strrchr(fixed_filename,cs_DirsepC);
		if ( last_path_sep )
		{
			/* Unless the directory is the current directory, we'd
			 * better make sure that at least the directory exists!
			 */
			char *filename_part = last_path_sep + 1;
			*last_path_sep = '\0';
			if ( ! stat(fixed_filename,&statbuf) )
			{
				/* Search the contents of the directory for a file which
				 * matches the one passed in, allowing for different
				 * case.
				 */
#if 1
				DIR *directory = opendir(fixed_filename);
				if ( directory )
				{
					struct dirent *entry;
					while ( (entry = readdir(directory)) != 0 )
					{
						if ( ! CS_stricmp(entry->d_name,filename_part) )
						{
							 /* We have a match!  It should be safe to assume that
							  * their lengths are the same, so we'll just copy it
							  * in-place.
							  */
							strcpy(filename_part,entry->d_name);
							break;
						}
					}
					closedir(directory);
				}
#else
				struct dirent *name_list = NULL;
				int num_matches = scandir( fixed_filename, name_list, NULL, NULL);
				if (num_matches > 0)
				{
					int ii;
					for (ii=0;ii < num_matches;ii++ )
					{
						if (!CS_stricmp (name_list[ii].d_name,filename_part))
						{
							 /* We have a match!  It should be safe to assume that
							  * their lengths are the same, so we'll just copy it
							  * in-place.
							  */
							strcpy (filename_part,name_list[ii].d_name);
							break;
						}
					}
					free (name_list);
				}
#endif
				/* Replace the directory/path separator */
				*last_path_sep = cs_DirsepC;
			}
		}
	}
	result = (csFILE*) fopen(fixed_filename,mode);
	if ( filename != fixed_filename )
	{
		free(fixed_filename);
	}
	return result;
}
Пример #6
0
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);
}
Пример #7
0
struct cs_Csprm_ * EXP_LVL9 CSbcclu (Const char *cs_name)
{
	extern csThread struct csCscach_ *csCscachP;
	extern csThread int csCscachI;

	cs_Register struct csCscach_ *ch_ptr;

	int ii;

	struct csCscach_ *tmp_ptr;
	struct csCscach_ *last_chp;
	struct cs_Csprm_ *cs_ptr;

	char kyTemp [cs_KEYNM_DEF + 2];

	CS_stncp (kyTemp,cs_name,sizeof (kyTemp));
	if (CS_nampp (kyTemp) != 0) return ((struct cs_Csprm_ *)0);

	if (csCscachP == NULL)
	{
		/* Here to allocate the cache. */

		if (csCscachI <= 1) csCscachI = 2;
		last_chp = NULL;
		for (ii = 0;ii < csCscachI;ii++)
		{
			ch_ptr = (struct csCscach_ *)CS_malc (sizeof (struct csCscach_));
			if (ch_ptr == NULL)
			{
				CS_erpt (cs_NO_MEM);
				ch_ptr = csCscachP;
				while (ch_ptr != NULL)
				{
					tmp_ptr = ch_ptr->next;
					CS_free (ch_ptr);
					ch_ptr = tmp_ptr;
				}
				csCscachP = NULL;
				goto error;
			}
			if (ii == 0)
			{
				csCscachP = ch_ptr;
			}
			else
			{
				last_chp->next = ch_ptr;		/*lint !e613 */
			}
			ch_ptr->prev = last_chp;
			ch_ptr->next = NULL;
			ch_ptr->cs_ptr = NULL;
			ch_ptr->cs_nam [0] = '\0';
			last_chp = ch_ptr;
		}
	}

	/* At this point, we have a cache.  It may be empty, but
	   it exists and has more than one entry. */

	cs_ptr = NULL;
	ch_ptr = csCscachP;
	last_chp = NULL;
	while (ch_ptr != NULL)
	{
		if (ch_ptr->cs_ptr == NULL) break;
		if (!CS_stricmp (ch_ptr->cs_nam,kyTemp))
		{
			cs_ptr = ch_ptr->cs_ptr;
			break;
		}

		last_chp = ch_ptr;
		ch_ptr = ch_ptr->next;
	}

	/* If cs_ptr is NULL, we havn't found the one we are looking
	   for.  We must add it to the cache. */

	if (cs_ptr == NULL)
	{
		/* If ch_ptr is not NULL, it must point to the
		   first element in the linked list which is
		   unused.  We simply use this entry. */

		if (ch_ptr != NULL)
		{
			ch_ptr->cs_ptr = CS_csloc (kyTemp);
			if (ch_ptr->cs_ptr == NULL)
			{
				goto error;
			}
			(void)CS_stncp (ch_ptr->cs_nam,kyTemp,sizeof (ch_ptr->cs_nam));
			cs_ptr = ch_ptr->cs_ptr;
		}
		else
		{
			/* We need to reuse an existing entry.  We always
			   reuse that the last entry in the linked list
			   as it should be the least recently accessed
			   entry in the list. */

			ch_ptr = last_chp;
			CS_free (ch_ptr->cs_ptr);
			ch_ptr->cs_nam [0] = '\0';
			ch_ptr->cs_ptr = CS_csloc (kyTemp);
			(void)CS_stncp (ch_ptr->cs_nam,kyTemp,sizeof (ch_ptr->cs_nam));
			cs_ptr = ch_ptr->cs_ptr;
		}
	}

	/* OK, we should now have a coordinate system pointer.  All we
	   need to do is make this one first on the list as an indication
	   that it was the most recently accessed.  Of course, if it
	   is already the first on the list, we do not need to do
	   anything.  The following code assumes that the entry being
	   processed is not the first on the list (i.e. ch_ptr->prev
	   is not NULL). */

	if (ch_ptr != csCscachP)
	{
		/* Remove the current entry from 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 */
		}

		/* Now we insert it at the top of the list. */

		ch_ptr->prev = NULL;							/*lint !e613 */
		ch_ptr->next = csCscachP;						/*lint !e613 */
		csCscachP->prev = ch_ptr;
		csCscachP = ch_ptr;
	}

	/* Return a pointer to the located coordinate system. */

	return (cs_ptr);

error:
	return ((struct cs_Csprm_ *)0);
}
Пример #8
0
int EXP_LVL3 CS_dtDefCmp (Const struct cs_Dtdef_ *original,Const struct cs_Dtdef_ *revised,char* message,size_t messageSize)
{
    static const double deltaEpsilon = 6.0E-04;
    static const double rotEpsilon = 5.0E-04;
    static double scaleEpsilon = 5.0E-06;

    int orgIsNull;
    int revIsNull;
    int ellipsoidUse = 0;

    short paramUseCount = -1;
    short orgDeltaZeroCount;
    short revDeltaZeroCount;

    int errCnt = 0;

    char errMsg [512];

    errMsg [0] = '\0';
    if (message != NULL && messageSize > 0) *message = '\0';

    /* The revised will often get converted to a type cs_DTCTYP_GEOCTR with zero
       deltas if it was one of those types that is generally considered to be
       equivalent with WGS84. */
    orgDeltaZeroCount  = (original->delta_X == 0.0);
    orgDeltaZeroCount += (original->delta_Y == 0.0);
    orgDeltaZeroCount += (original->delta_Z == 0.0);
    orgIsNull = (original->to84_via == cs_DTCTYP_WGS84  ||
                 original->to84_via == cs_DTCTYP_NAD83  ||
                 original->to84_via == cs_DTCTYP_WGS84  ||
                 original->to84_via == cs_DTCTYP_GDA94  ||
                 original->to84_via == cs_DTCTYP_NZGD2K ||
                 original->to84_via == cs_DTCTYP_ETRF89 ||
                 original->to84_via == cs_DTCTYP_RGF93  ||
                 (orgDeltaZeroCount == 3 &&
                  (original->to84_via == cs_DTCTYP_GEOCTR || original->to84_via == cs_DTCTYP_3PARM)
                 )
                );

    revDeltaZeroCount  = (revised->delta_X == 0.0);
    revDeltaZeroCount += (revised->delta_Y == 0.0);
    revDeltaZeroCount += (revised->delta_Z == 0.0);
    revIsNull = (revised->to84_via == cs_DTCTYP_WGS84  ||
                 revised->to84_via == cs_DTCTYP_NAD83  ||
                 revised->to84_via == cs_DTCTYP_WGS84  ||
                 revised->to84_via == cs_DTCTYP_GDA94  ||
                 revised->to84_via == cs_DTCTYP_NZGD2K ||
                 revised->to84_via == cs_DTCTYP_ETRF89 ||
                 revised->to84_via == cs_DTCTYP_RGF93  ||
                 (revDeltaZeroCount == 3 &&
                  (revised->to84_via == cs_DTCTYP_GEOCTR || revised->to84_via == cs_DTCTYP_3PARM)
                 )
                );

    /* We can now compare the type giving proper consideration to the fact that
       there are numerous ways of defining the null transformation.  That is, if
       both original and revised are the null transformation, we  */
    if (orgIsNull && revIsNull)
    {
        /* Both are the null transformation, so they are essentially
           equivalent. */
        return errCnt;
    }

    /* Compare the transformation technique. */
    if (original->to84_via != revised->to84_via)
    {
        if (errCnt == 0)
        {
            sprintf (errMsg,"Datum transformation method on datum named %s does not match.  Method was %d, is now %d",
                     original->key_nm,
                     original->to84_via,
                     revised->to84_via);
        }

        /* We bump the error count by 8 to make this error appear to be more
           than other types of errors. */
        errCnt += 8;
    }
    else
    {
        /* If the transformation technique is the same, it makes sense to compare
           the parameters; if the transformation is of the type that uses
           parameters, of course. */
        switch (original->to84_via) {
        case cs_DTCTYP_MOLO:
            paramUseCount = 3;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_MREG:
            paramUseCount = 7;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_BURS:
            paramUseCount = 7;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_NAD27:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_NAD83:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_WGS84:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_WGS72:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_HPGN:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_7PARM:
            paramUseCount = 7;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_AGD66:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_3PARM:
            paramUseCount = 3;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_6PARM:
            paramUseCount = 6;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_4PARM:
            paramUseCount = 4;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_AGD84:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_NZGD49:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_ATS77:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_GDA94:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_NZGD2K:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_CSRS:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_TOKYO:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_RGF93:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_ED50:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_DHDN:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_ETRF89:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_GEOCTR:
            paramUseCount = 3;
            ellipsoidUse =  TRUE;
            break;
        case cs_DTCTYP_CHENYX:
            paramUseCount = 0;
            ellipsoidUse = FALSE;
            break;
        case cs_DTCTYP_NONE:
        default:
            paramUseCount = -1;
            ellipsoidUse = FALSE;
            break;
        }
    }

    /* Check the parameters as is appropriate. */

    if (paramUseCount > 0)
    {
        if (fabs (original->delta_X - revised->delta_X) > deltaEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Delta X was %12.3f, is now %12.3f",original->key_nm,original->delta_X,revised->delta_X);
            }
            errCnt += 1;
        }
        if (fabs (original->delta_Y - revised->delta_Y) > deltaEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Delta Y was %12.3f, is now %12.3f",original->key_nm,original->delta_Y,revised->delta_Y);
            }
            errCnt += 1;
        }
        if (fabs (original->delta_Z - revised->delta_Z) > deltaEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Delta Z was %12.3f, is now %12.3f",original->key_nm,original->delta_Z,revised->delta_Z);
            }
            errCnt += 1;
        }
    }
    if (paramUseCount > 4)
    {
        if (fabs (original->rot_X - revised->rot_X)> rotEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: X Rotation was %12.3f, is now %12.3f",original->key_nm,original->rot_X,revised->rot_X);
            }
            errCnt += 1;
        }
        if (fabs (original->rot_Y - revised->rot_Y) > rotEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Y Rotation was %12.3f, is now %12.3f",original->key_nm,original->rot_Y,revised->rot_Y);
            }
            errCnt += 1;
        }
        if (fabs (original->rot_Z - revised->rot_Z) > rotEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Z Rotation was %12.3f, is now %12.3f",original->key_nm,original->rot_Z,revised->rot_Z);
            }
            errCnt += 1;
        }
    }
    if (paramUseCount > 3 && paramUseCount != 6)
    {
        if (fabs (original->bwscale - revised->bwscale) > scaleEpsilon)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Scale was %12.8f, is now %12.8f",original->key_nm,original->bwscale,revised->bwscale);
            }
            errCnt += 1;
        }
    }

    /* Check the ellipsoid if it matters for the trsansformation technique. */

    if (ellipsoidUse)
    {
        if (!CS_stricmp (original->ell_knm,revised->ell_knm))
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"%s: Ellipsoid was %s, is now %s",original->key_nm,original->ell_knm,revised->ell_knm);
            }
            errCnt += 1;
        }
    }

    /* OK, we're done.  Return results of comparison to the calling module. */
    if (errCnt != 0)
    {
        if (message != 0 && messageSize > 1)
        {
            CS_stncp (message,errMsg,(int)messageSize);
        }
    }
    return errCnt;
}
Пример #9
0
int CStest2 (bool verbose,bool crypt)
{
	short protectSave;
	char uniqueSave;

	int st;
	int cnt;
	int my_crypt;

	csFILE *dtStrm;
	struct tst_lst_ *tp;

	char last_name [48];

	__ALIGNMENT__1			/* Required by some Sun compilers. */
	struct cs_Dtdef_ dt_def;

	protectSave = cs_Protect;
	uniqueSave = cs_Unique;
	printf ("Testing Datum Dictionary functions.\n");

	/* We do the same thing now with datum definitions. */

	tp = dt_tst;
	while (tp->name [0] != '\0')
	{
		cs_Protect = protectSave;
		cs_Unique = uniqueSave;
		if (verbose)
		{
			printf ("Fetching %s datum definition.",tp->name);
		}
		tp->dt_ptr = CS_dtdef (tp->name);
		if (tp->dt_ptr == NULL)
		{
			(void)printf ("\nCS_dtdef failed on %s. [%d:%d]\n",
							tp->name,
							cs_Error,
							cs_Errno);
			return (1);
		}
		if (verbose) printf (" OK.\n");

		if (CS_stricmp (tp->dt_ptr->group,"tESt"))
		{
			if (verbose)
			{
				printf ("Updating %s datum definition, protection off.",tp->name);
			}
			cs_Protect = -1;
			st = CS_dtupd (tp->dt_ptr,crypt);
			if (st != 1)
			{
				(void)printf ("\nCS_dtupd failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
			if (verbose)
			{
				printf ("Deleting %s datum definition.",tp->name);
			}
			st = CS_dtdel (tp->dt_ptr);
			if (st != 0)
			{
				(void)printf ("CS_dtdel failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
		}
		else
		{
			if (verbose)
			{
				printf ("Updating %s datum definition, protection on.",tp->name);
			}
			cs_Protect = 10000;
			st = CS_dtupd (tp->dt_ptr,crypt);
			if (st != 1)
			{
				(void)printf ("\nCS_dtupd failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
			if (verbose)
			{
				printf ("Deleting %s datum definition.",tp->name);
			}
			st = CS_dtdel (tp->dt_ptr);
			if (st != 0)
			{
				(void)printf ("CS_dtdel failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
		}
		tp++;
	}
	tp = dt_tst;
	while (tp->name [0] != '\0')
	{
		cs_Protect = protectSave;
		cs_Unique = uniqueSave;
		if (verbose)
		{
			printf ("Putting %s datum definition back in.",tp->name);
		}
		cs_Unique = '\0';
		st = CS_dtupd (tp->dt_ptr,crypt);
		if (st != 0)
		{
			(void)printf ("\nCS_dtupd (2) failed on %s. [%d:%d]\n",
							tp->name,
							cs_Error,
							cs_Errno);
			return (1);
		}
		if (verbose) printf (" OK.\n");
		CS_free (tp->dt_ptr);
		tp++;
	}
	if (verbose)
	{
		printf ("Checking the order of the Datum Dictionary.\n");
	}
	cnt = 0;
	dtStrm = CS_dtopn (_STRM_BINRD);
	st = CS_dtrd (dtStrm,&dt_def,&my_crypt);
	CS_stncp (last_name,dt_def.key_nm,sizeof (last_name));
	while (CS_dtrd (dtStrm,&dt_def,&my_crypt))
	{
		cnt += 1;
		if (verbose && (cnt % 4) == 0) putchar ('.');
		st = CS_stricmp (last_name,dt_def.key_nm);
		if (st > 0)
		{
			printf ("\nDatum Dictionary no longer sorted!!!\n");
			CS_fclose (dtStrm);
			return (1);
		}
		else if (st == 0)
		{
			printf ("\nDuplicate entries in Datum Dictionary!!!\n");
			CS_fclose (dtStrm);
			return (1);
		}
	}
	if (verbose) printf (" OK.\n");
	CS_dtDictCls (dtStrm);
	return (0);
}
Пример #10
0
bool ListDuplicateCS (std::wostream& listStrm)
{
	bool ok (false);
	int st;
	unsigned dupCount;
	unsigned long epsgCodeII;
	unsigned long epsgCodeJJ;
	const cs_Csdef_ *csPtrII;
	const cs_Csdef_ *csPtrJJ;
	double qValue;
	char message [1024];

	std::vector<TcsKeyName> duplicateNameVector;
	std::vector<TcsKeyNameList> duplicateListVector;
	std::vector<TcsKeyNameList>::iterator itrDuplicateListVctr;

	TcsCoordsysFile csFile;
	if (csFile.IsOk ())
	{
		size_t ii, jj, csCount;
		csCount = csFile.GetRecordCount ();
		duplicateNameVector.clear ();
		duplicateNameVector.reserve (1024);

		for (ii = 0;ii < (csCount - 1);ii +=1 )
		{
			csPtrII = csFile.FetchCoordinateSystem (ii);
			if (csPtrII == 0) break;
			if (!CS_stricmp (csPtrII->group,"LEGACY")) continue;
			if (!CS_stricmp (csPtrII->prj_knm,"LM-WCCS")) continue;
			if (!CS_stricmp (csPtrII->prj_knm,"LM-MNDOT")) continue;
			if (!CS_stricmp (csPtrII->prj_knm,"TM-WCCS")) continue;
			if (!CS_stricmp (csPtrII->prj_knm,"TM-MNDOT")) continue;
			epsgCodeII = csMapNameToIdC (csMapProjGeoCSys,csMapFlvrEpsg,csMapFlvrAutodesk,csPtrII->key_nm);

			TcsKeyName primaryName (csKyNmTypeCRS,csPtrII->key_nm,epsgCodeII);
			primaryName.SetQuality (csPtrII);
			TcsKeyNameList duplicateList (primaryName);
			dupCount = 0;

			// If this coordinate system name already appears in our duplicate
			// name vector, we ignore it.  It's already a secondary name and we
			// don't want it to appear as also as a primary name.
			if (binary_search (duplicateNameVector.begin (),duplicateNameVector.end (),primaryName))
			{
				continue;
			}

			for (jj = (ii + 1);jj < csCount;jj += 1)
			{
				csPtrJJ = csFile.FetchCoordinateSystem (jj);
				if (csPtrJJ == 0) break;
				if (!CS_stricmp (csPtrJJ->group,"LEGACY")) continue;
				if (!CS_stricmp (csPtrJJ->prj_knm,"LM-WCCS")) continue;
				if (!CS_stricmp (csPtrJJ->prj_knm,"LM-MNDOT")) continue;
				if (!CS_stricmp (csPtrJJ->prj_knm,"TM-WCCS")) continue;
				if (!CS_stricmp (csPtrII->prj_knm,"TM-MNDOT")) continue;
				if (CS_stricmp (csPtrII->dat_knm,csPtrJJ->dat_knm)) continue;
				message [0] = '\0';
				st = CS_csDefCmpEx (&qValue,csPtrII,csPtrJJ,message,sizeof (message));
				if ((st == 0) && (qValue < 3.0))
				{
					dupCount += 1;
					epsgCodeJJ = csMapNameToIdC (csMapProjGeoCSys,csMapFlvrEpsg,csMapFlvrAutodesk,csPtrJJ->key_nm);
					if (epsgCodeJJ == KcsNmInvNumber) epsgCodeJJ = 0UL;
					TcsKeyName duplicateName (csKyNmTypeCRS,csPtrJJ->key_nm,epsgCodeJJ);
					duplicateName.SetQuality (csPtrJJ);
					duplicateNameVector.push_back (duplicateName);
					duplicateList += duplicateName;
				}
			}

			if (dupCount > 0)
			{
				duplicateListVector.push_back (duplicateList);
				std::stable_sort (duplicateNameVector.begin (),duplicateNameVector.end ());
			}
		}

		// OK, we have a vector of TcsKeyNameList objects which represent the definitions
		// which are candidates for drepecation as duplicates.  We do some arranging
		// and print the results out in a form ammenable to inserting as a data object
		// initialization in a C++ source code module.
		for (itrDuplicateListVctr  = duplicateListVector.begin ();
			 itrDuplicateListVctr != duplicateListVector.end ();
			 itrDuplicateListVctr++)
		{
			// Here once for each instance of duplicate deifnitions.  First we
			// "Arrange" the names so the most preferred name is the "Primary" name.
			// Then we write them out in a ofrm suitable for the C++ compiler.
			TcsKeyNameList& keyNameList = *itrDuplicateListVctr;
			keyNameList.Arrange ();
			keyNameList.WriteToStream (listStrm);
		}
		ok = true;
	}
	return ok;
}
Пример #11
0
int main (int argc,char *argv [])
{
	extern char cs_Dir [];
	extern char* cs_DirP;
	extern char cs_Csname [];
	extern char cs_Dtname [];
	extern char cs_Elname [];

	int cmpVal, iTmp;
	int csDiffCnt, dtDiffCnt, elDiffCnt;
	int dummy;
	int nlFlag;

	csFILE *wasStrm, *isStrm;

	char wasDir [MAXPATH];
	char isDir [MAXPATH];
	char errorText [260];

	struct cs_Csdef_ wasCsDef, isCsDef;
	struct cs_Dtdef_ wasDtDef, isDtDef;
	struct cs_Eldef_ wasElDef, isElDef;

	csDiffCnt = 0;
	dtDiffCnt = 0;
	elDiffCnt = 0;

	if (argc != 3) Usage ();

	strncpy (wasDir,argv [1],sizeof (wasDir));
	wasDir [sizeof (wasDir) - 1] = '\0';

	strncpy (isDir,argv [2],sizeof (isDir));
	isDir [sizeof (isDir) - 1] = '\0';

	if (CS_altdr (wasDir) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Csname,wasDir);
		Usage ();
	}
	CS_stcpy (cs_DirP,cs_Dtname);
	if (CS_access (cs_Dir,4) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Dtname,wasDir);
		Usage ();
	}
	CS_stcpy (cs_DirP,cs_Elname);
	if (CS_access (cs_Dir,4) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Elname,wasDir);
		Usage ();
	}

	if (CS_altdr (isDir) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Csname,isDir);
		Usage ();
	}
	CS_stcpy (cs_DirP,cs_Dtname);
	if (CS_access (cs_Dir,4) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Dtname,isDir);
		Usage ();
	}
	CS_stcpy (cs_DirP,cs_Elname);
	if (CS_access (cs_Dir,4) != 0)
	{
		printf ("%s file not found in %s directory.\n",cs_Elname,isDir);
		Usage ();
	}

	/* Ok, we're ready to do our thing.  Do coordinate systems first. */
	CS_altdr (wasDir);											/*lint !e534 */
	wasStrm = CS_csopn (_STRM_BINRD);
	if (wasStrm == NULL)
	{
		printf ("Open of %s in the 'WAS' directory failed.\n",cs_Csname);
		Usage ();
	}

	CS_altdr (isDir);											/*lint !e534 */
	isStrm = CS_csopn (_STRM_BINRD);
	if (isStrm == NULL)
	{
		printf ("Open of %s in the 'IS' directory failed.\n",cs_Csname);
		Usage ();
	}

	/* Now, we loop through the dictionaries.  In this module, we simply
	   compare key names, looking for new definitions, or deleted
	   definitions.  When we have definitions with the same name, we call
	   CS_csDiff to report any differences.

	   First, we prime the pump. */
	iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'WAS' coordinate system dictionary is empty.\n");
		Usage ();
	}

	iTmp = CS_csrd (isStrm,&isCsDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'IS' coordinate system dictionary is empty.\n");
		Usage ();
	}

	nlFlag = FALSE;
	while (TRUE)
	{
		cmpVal = CS_stricmp (wasCsDef.key_nm,isCsDef.key_nm);
		if (cmpVal < 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from coordinate system dictionary!!!\n",wasCsDef.key_nm);
			csDiffCnt += 1;
		}
		else if (cmpVal > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to coordinate system dictionary!!!\n",isCsDef.key_nm);
			csDiffCnt += 1;
		}
		else
		{
			/* Normal case, we have two definitions with the same name, */
			iTmp = CS_csDiff (stdout,&wasCsDef,&isCsDef);
			if (iTmp != 0)
			{
				csDiffCnt += 1;
				nlFlag = TRUE;
			}
		}
		if (cmpVal >= 0)
		{
			iTmp = CS_csrd (isStrm,&isCsDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (isStrm);
				isStrm = NULL;
				break;
			}
		}
		if (cmpVal <= 0)
		{
			iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (wasStrm);
				wasStrm = NULL;
				break;
			}
		}
	}

	/* Finish up properly. */
	nlFlag = TRUE;
	while (wasStrm != NULL)
	{
		iTmp = CS_csrd (wasStrm,&wasCsDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from coordinate system dictionary!!!\n",wasCsDef.key_nm);
			csDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (wasStrm);
			wasStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	while (isStrm != NULL)
	{
		iTmp = CS_csrd (isStrm,&wasCsDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to coordinate system dictionary!!!\n",isCsDef.key_nm);
			csDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (isStrm);
			isStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	if (csDiffCnt == 0)
	{
		printf ("\nCoordinate system dictionaries are the same.\n\n");
	}
	else
	{
		printf ("\n%d coordinate systems are different.\n\n",csDiffCnt);
	}

	/* Done with the coordinate system dictionary. Same as above, but with the
	   Datum Dictionary this time. */
	CS_altdr (wasDir);											/*lint !e534 */
	wasStrm = CS_dtopn (_STRM_BINRD);
	if (wasStrm == NULL)
	{
		printf ("Open of %s in the 'WAS' directory failed.\n",cs_Dtname);
		Usage ();
	}

	CS_altdr (isDir);											/*lint !e534 */
	isStrm = CS_dtopn (_STRM_BINRD);
	if (isStrm == NULL)
	{
		printf ("Open of %s in the 'IS' directory failed.\n",cs_Dtname);
		Usage ();
	}

	iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'WAS' datum dictionary is empty.\n");
		Usage ();
	}

	iTmp = CS_dtrd (isStrm,&isDtDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'IS' datum dictionary is empty.\n");
		Usage ();
	}

	nlFlag = FALSE;
	while (TRUE)
	{
		cmpVal = CS_stricmp (wasDtDef.key_nm,isDtDef.key_nm);
		if (cmpVal < 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from datum dictionary!!!\n",wasDtDef.key_nm);
			dtDiffCnt += 1;
		}
		else if (cmpVal > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to datum dictionary!!!\n",isDtDef.key_nm);
			dtDiffCnt += 1;
		}
		else
		{
			/* Normal case, we have two definitions with the same name, */
			iTmp = CS_dtDiff (stdout,&wasDtDef,&isDtDef);
			if (iTmp != 0)
			{
				dtDiffCnt += 1;
				nlFlag = TRUE;
			}
		}
		if (cmpVal >= 0)
		{
			iTmp = CS_dtrd (isStrm,&isDtDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (isStrm);
				isStrm = NULL;
				break;
			}
		}
		if (cmpVal <= 0)
		{
			iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (wasStrm);
				wasStrm = NULL;
				break;
			}
		}
	}

	nlFlag = TRUE;
	while (wasStrm != NULL)
	{
		iTmp = CS_dtrd (wasStrm,&wasDtDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from datum dictionary!!!\n",wasDtDef.key_nm);
			dtDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (wasStrm);
			wasStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	while (isStrm != NULL)
	{
		iTmp = CS_dtrd (isStrm,&wasDtDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to datum dictionary!!!\n",isDtDef.key_nm);
			dtDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (isStrm);
			isStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	if (dtDiffCnt == 0)
	{
		printf ("\nDatum dictionaries are the same.\n\n");
	}
	else
	{
		printf ("\n%d datum definitions are different.\n\n",dtDiffCnt);
	}

	/* Ellipsoid Dictionary */
	CS_altdr (wasDir);											/*lint !e534 */
	wasStrm = CS_elopn (_STRM_BINRD);
	if (wasStrm == NULL)
	{
		printf ("Open of %s in the 'WAS' directory failed.\n",cs_Elname);
		Usage ();
	}

	CS_altdr (isDir);											/*lint !e534 */
	isStrm = CS_elopn (_STRM_BINRD);
	if (isStrm == NULL)
	{
		printf ("Open of %s in the 'IS' directory failed.\n",cs_Elname);
		Usage ();
	}

	iTmp = CS_elrd (wasStrm,&wasElDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'WAS' ellipsoid dictionary is empty.\n");
		Usage ();
	}

	iTmp = CS_elrd (isStrm,&isElDef,&dummy);
	if (iTmp < 0)
	{
		CS_errmsg (errorText,sizeof (errorText));
		printf ("%s\n",errorText);
		Usage ();
	}
	if (iTmp == 0)
	{
		printf ("'IS' ellipsoid dictionary is empty.\n");
		Usage ();
	}

	nlFlag = FALSE;
	while (TRUE)
	{
		cmpVal = CS_stricmp (wasElDef.key_nm,isElDef.key_nm);
		if (cmpVal < 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from ellipsoid dictionary!!!\n",wasElDef.key_nm);
			elDiffCnt += 1;
		}
		else if (cmpVal > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to ellipsoid dictionary!!!\n",isElDef.key_nm);
			elDiffCnt += 1;
		}
		else
		{
			/* Normal case, we have two definitions with the same name, */
			iTmp = CS_elDiff (stdout,&wasElDef,&isElDef);
			if (iTmp != 0)
			{
				elDiffCnt += 1;
				nlFlag = TRUE;
			}
		}
		if (cmpVal >= 0)
		{
			iTmp = CS_elrd (isStrm,&isElDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (isStrm);
				isStrm = NULL;
				break;
			}
		}
		if (cmpVal <= 0)
		{
			iTmp = CS_elrd (wasStrm,&wasElDef,&dummy);
			if (iTmp < 0)
			{
				CS_errmsg (errorText,sizeof (errorText));
				printf ("%s\n",errorText);
				Usage ();
			}
			if (iTmp == 0)
			{
				CS_fclose (wasStrm);
				wasStrm = NULL;
				break;
			}
		}
	}

	nlFlag = TRUE;
	while (wasStrm != NULL)
	{
		iTmp = CS_elrd (wasStrm,&wasElDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s deleted from ellipsoid dictionary!!!\n",wasElDef.key_nm);
			elDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (wasStrm);
			wasStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	while (isStrm != NULL)
	{
		iTmp = CS_elrd (isStrm,&wasElDef,&dummy);
		if (iTmp > 0)
		{
			if (nlFlag)
			{
				printf ("\n");
				nlFlag = FALSE;
			}
			printf ("%s added to ellipsoid dictionary!!!\n",isElDef.key_nm);
			dtDiffCnt += 1;
		}
		else if (iTmp == 0)
		{
			CS_fclose (isStrm);
			isStrm = NULL;
		}
		else
		{
			CS_errmsg (errorText,sizeof (errorText));
			printf ("%s\n",errorText);
			Usage ();
		}
	}
	if (elDiffCnt == 0)
	{
		printf ("\nEllipsoid dictionaries are the same.\n\n");
	}
	else
	{
		printf ("\n%d ellipsoid definitions are different.\n\n",elDiffCnt);
	}

	return 0;
}
Пример #12
0
csFILE * EXP_LVL3 CS_dtopn (Const char *mode)
{
    extern char cs_Dir [];
    extern char *cs_DirP;
    extern char cs_Dtname [];
    extern char csErrnam [];

    size_t rdCnt;

    csFILE *strm = NULL;

    cs_magic_t magic;

    if (cs_DtStream != 0)
    {
        if (!CS_stricmp (mode,_STRM_BINRD))
        {
            strm = cs_DtStream;
            CS_fseek (strm,(long)sizeof (magic),SEEK_SET);
        }
        else
        {
            CS_fclose (cs_DtStream);
            cs_DtStream = NULL;
        }
    }
    if (strm == NULL)
    {
        strcpy (cs_DirP,cs_Dtname);
        strm = CS_fopen (cs_Dir,mode);
        if (strm != NULL)
        {
            rdCnt = CS_fread ((char *)&magic,1,sizeof (magic),strm);
            if (rdCnt != sizeof (magic))
            {
                if (CS_ferror (strm)) CS_erpt (cs_IOERR);
                else				  CS_erpt (cs_INV_FILE);
                CS_fclose (strm);
                strm = NULL;
                strcpy (csErrnam,cs_Dir);
            }
            else
            {
                CS_bswap (&magic,"l");
                if (magic != cs_DTDEF_MAGIC)
                {
                    CS_fclose (strm);
                    strm = NULL;
                    strcpy (csErrnam,cs_Dir);
                    CS_erpt (cs_DT_BAD_MAGIC);
                }
                else if (!strcmp (mode,_STRM_BINRD))
                {
                    cs_DtStream = strm;
                }
            }
        }
        else
        {
            strcpy (csErrnam,cs_Dir);
            CS_erpt (cs_DTDICT);
        }
    }
    return (strm);
}
Пример #13
0
/******************************************************************************
	Constructor: for the "Entry" sub-object.  A linked list of these "Entry"
	objects is the basic structure of the main object.
*/
struct csGeoidHeightEntry_* CSnewGeoidHeightEntry (struct csDatumCatalogEntry_* catPtr)
{
	extern char cs_DirsepC;
	extern char cs_ExtsepC;
	extern char csErrnam [];

	char *cp;
	struct csGeoidHeightEntry_* __This;

	/* Prepare for an error. */
	__This = NULL;

	/* Allocate some storage. */
	__This = (struct csGeoidHeightEntry_*) CS_malc (sizeof (struct csGeoidHeightEntry_));
	if (__This == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}
	__This->next = NULL;
	__This->type = csGeoidHgtTypeNone;
	__This->pointers.geoid96Ptr = NULL;

	/* Isolate the file name from the path, and the extension from the file name. */
	cp = strrchr (catPtr->pathName,cs_DirsepC);
	if (cp == NULL)
	{
		/* Is not supposed to happen, but we can't allow a bomb. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_DTC_PATH);
		goto error;
	}

	/* Isolate the extension on the file. */
	cp = strrchr (catPtr->pathName,cs_ExtsepC);
	if (cp == NULL)
	{
		/* Is not supposed to happen. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_NAD_EXT);
		goto error;
	}
	cp += 1;

	/* Do what's appropriate for this extension. */
	if (!CS_stricmp (cp,"GEO"))
	{
		/* Must not set the type until allocated for correct error handling. */
		__This->pointers.geoid96Ptr = CSnewGeoid96GridFile (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->pointers.geoid96Ptr == NULL)
		{
			goto error;
		}
		__This->type = csGeoidHgtTypeGeoid96;
	}
	else if (!CS_stricmp (cp,"bin"))
	{
		/* These are supposed to be Geoid99 type files. */
		/* Must not set the type until allocated for correct error handling. */
		__This->pointers.geoid99Ptr = CSnewGeoid99GridFile (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->pointers.geoid99Ptr == NULL)
		{
			goto error;
		}
		__This->type = csGeoidHgtTypeGeoid99;
	}
	else if (!CS_stricmp (cp,"txt"))
	{
		/* These are supposed to be OSGM91 type files. */
		/* Must not set the type until allocated for correct error handling. */
		__This->pointers.osgm91Ptr = CSnewOsgm91 (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->pointers.osgm91Ptr == NULL)
		{
			goto error;
		}
		__This->type = csGeoidHgtTypeOsgm91;
	}	/* When we know how to do the others, we add that stuff here. */
	else if (!CS_stricmp (cp,"byn"))
	{
		/* Must not set the type until allocated for correct error handling. */
		__This->pointers.bynGridFilePtr = CSnewBynGridFile (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->pointers.bynGridFilePtr == NULL)
		{
			goto error;
		}
		__This->type = csGeoidHgtTypeBynGridFile;
	}
   else if (!CS_stricmp (cp,"grd"))
   {
      /* Must not set the type until allocated for correct error handling. */
      __This->pointers.egm96Ptr = CSnewEgm96 (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
      if (__This->pointers.egm96Ptr == NULL)
      {
         goto error;
      }
      __This->type = csGeoidHgtTypeEgm96;
   }
	else
	{
		CS_erpt (cs_GHGT_EXT);
		goto error;
	}
	return __This;
error:
	CSdeleteGeoidHeightEntry (__This);
	return NULL;
}
Пример #14
0
/******************************************************************************
	Constructor  (for an 'Entry' sub object)
*/
struct csVertconUSEntry_* CSnewVertconUSEntry (struct csDatumCatalogEntry_* catPtr)
{
	extern char cs_DirsepC;
	extern char cs_ExtsepC;
	extern char csErrnam [];

	char *cp;
	struct csVertconUSEntry_* __This;

	/* Prepare for an error. */
	__This = NULL;

	/* Allocate some storage. */
	__This = (struct csVertconUSEntry_*) CS_malc (sizeof (struct csVertconUSEntry_));
	if (__This == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}
	__This->next = NULL;
	__This->usGridPtr = NULL;

	/* Isolate the file name from the path, and the extension from the file name. */
	cp = strrchr (catPtr->pathName,cs_DirsepC);
	if (cp == NULL)
	{
		/* Is not supposed to happen, but we can't allow a bomb. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_DTC_PATH);
		goto error;
	}

	/* Isolate the extension on the file. */
	cp = strrchr (catPtr->pathName,cs_ExtsepC);
	if (cp == NULL)
	{
		/* Is not supposed to happen. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_NAD_EXT);
		goto error;
	}
	cp += 1;

	/* Report special errors concerning the extensions.  Again, specific
	   error messages will reduce frustration. */
	if (CS_stricmp (cp,"94"))
	{
		CS_erpt (cs_VCON_94);
		goto error;
	}
	/* Do what's appropriate for this extension. */
	if (!CS_stricmp (cp,"94"))
	{
		__This->usGridPtr = CSnewGridFileUS (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->usGridPtr == NULL)
		{
			goto error;
		}
	}
	/* When we know how to do the others, we add that stuff here. */
	else
	{
		CS_erpt (cs_VCON_EXT);
		goto error;
	}
	return __This;
error:
	CSdeleteVertconUSEntry (__This);
	return NULL;
}
Пример #15
0
int CSinitNTv2 (struct cs_NTv2_* thisPtr,Const char *filePath,long32_t bufferSize,
															  ulong32_t flags,
															  double density)
{
	extern double cs_Sec2Deg;
	extern char cs_DirsepC;
	extern char csErrnam [];

	short idx;
	short parIdx;

	int overlap;
	int seekStat;

	size_t readCnt;
	size_t readCntRq;
	size_t malcCnt;
	long32_t skipAmount;

	char *cp;
	struct csNTv2SubGrid_* subPtr;
	struct csNTv2SubGrid_* kidPtr;
	struct csNTv2SubGrid_* parPtr;

	union csNtv2Hdrs_ fileHdr;
	struct csNTv2SubHdr_ fileSubHdr;

	char ctemp [MAXPATH];

	csFILE* stream = NULL;

	/* Try to prevent a likely crash. */
	if (thisPtr == NULL)
	{
		CS_stncp (csErrnam,"CS_ntv2::1",MAXPATH);
		CS_erpt (cs_ISER);
		return -1;
	}

	/* In the event of an error; this eliminates duplicating this many many
	   times. */
	CS_stncp (csErrnam,filePath,MAXPATH);

	/* Initialize the structure to harmless values. */
	thisPtr->SubGridDir = NULL;
	thisPtr->fileImage = NULL;
	thisPtr->fileImageSize = 0;
	thisPtr->HdrRecCnt = 0;
	thisPtr->SubCount = 0;
	thisPtr->RecSize = 16;
	thisPtr->CellIsValid = FALSE;
	thisPtr->SubOverlap = (short)((flags & 0x01) != 0);
	thisPtr->IntType = csNTv2TypeNone;
	thisPtr->BufferSize = bufferSize;
	thisPtr->sourceId [0] = '\0';
	if (thisPtr->BufferSize <= 0) thisPtr->BufferSize = csNTv2BufrSz;
	if (thisPtr->BufferSize <= 4096) thisPtr->BufferSize = 4096;
	CSinitNTv2GridCell (&thisPtr->longitudeCell);
	CSinitNTv2GridCell (&thisPtr->latitudeCell);

	/* Deal with the file path. */
	CS_stncp (thisPtr->FilePath,filePath,sizeof (thisPtr->FilePath));

	/* Extract and save last 15 characters of the data file name. */
	cp = strrchr (thisPtr->FilePath,cs_DirsepC);
	if (cp == NULL) cp = thisPtr->FilePath;
	CS_stncp (ctemp,cp,sizeof (ctemp));
	cp = strrchr (ctemp,'.');
	if (cp != NULL) *cp = '\0';
	cp = ctemp;
	if (strlen (ctemp) > 15)
	{
		cp = ctemp + strlen (ctemp) - 15;
	}
	CS_stncp (thisPtr->FileName,cp,sizeof (thisPtr->FileName));

	/* Open the file. */
	stream = CS_fopen (thisPtr->FilePath,_STRM_BINRD);
	if (stream == NULL)
	{
		CS_erpt (cs_DTC_FILE);
		goto error;
	}
	setvbuf (stream,NULL,_IOFBF,(size_t)thisPtr->BufferSize);

	/* We've got a file.  Read the header. */
	readCnt = CS_fread (&fileHdr,1,sizeof (fileHdr),stream);
	if (CS_ferror (stream))
	{
		CS_erpt (cs_IOERR);
		goto error;
	}
	if (readCnt != sizeof (fileHdr))
	{
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Verify that this is the kind of file we know how to deal with. */
	if (strncmp (fileHdr.Canadian.titl01,"NUM_OREC",8))
	{
		/* Opps!!! Not a CaNTv2 file. */
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Determine the type/source of the file. */
	if (fileHdr.Canadian.titl02 [0] == 'N' &&
	    fileHdr.Canadian.titl02 [1] == 'U')
	{
		/* It appears that the file is Canadian. */
		thisPtr->IntType = csNTv2TypeCanada;
		skipAmount = sizeof (struct csNTv2HdrCa_);
		CS_bswap (&fileHdr.Canadian,cs_BSWP_NTv2HdrCa);
	}
	else if (fileHdr.Australian.titl02 [0] == 'N' &&
			 fileHdr.Australian.titl02 [1] == 'U')
	{
		/* It appears to be an Australian file. */
		thisPtr->IntType = csNTv2TypeAustralia;
		skipAmount = sizeof (struct csNTv2HdrAu_);
		CS_bswap (&fileHdr.Australian,cs_BSWP_NTv2HdrAu);
	}
	else
	{
		/* Opps!!! Don't know what kind of file it is. */
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Reposition the input file as is appropriate due to the
	   type of file.  A little hoeky, but it should be portable. */
	seekStat = CS_fseek (stream,skipAmount,SEEK_SET);
	if (seekStat != 0)
	{
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Extract the valuable stuff. */
	if (thisPtr->IntType == csNTv2TypeCanada)
	{
		thisPtr->HdrRecCnt = fileHdr.Canadian.num_orec;
		thisPtr->SubCount = fileHdr.Canadian.num_file;
		thisPtr->SubHdrRecCnt = fileHdr.Canadian.num_srec;
	}
	else
	{
		thisPtr->HdrRecCnt = fileHdr.Australian.num_orec;
		thisPtr->SubCount = fileHdr.Australian.num_file;
		thisPtr->SubHdrRecCnt = fileHdr.Australian.num_srec;
	}
	/* The rest of the header is pretty much useless. */

	/* Now, we deal with the sub-directories.  THese are very
	   important. */
	malcCnt = sizeof (struct csNTv2SubHdr_) * (ulong32_t)thisPtr->SubCount;
	thisPtr->SubGridDir = (struct csNTv2SubGrid_ *)CS_malc (malcCnt);
	if (thisPtr->SubGridDir == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}

	/* Initialize (i.e. construct) each of the sub-grid items we just
	   allocated. */
	for (idx = 0;idx < thisPtr->SubCount;idx += 1)
	{
		subPtr = &thisPtr->SubGridDir [idx];

		/* Initialize to a boundary which will not match anything. */
		subPtr->SouthWest [LNG] = 180.0;
		subPtr->SouthWest [LAT] = 90.0;
		subPtr->NorthEast [LNG] = -180.0;
		subPtr->NorthEast [LAT] = -90.0;

		/* Remember, these values as extracted from the file itself are
		   WEST positive. */
		subPtr->SeReference [LNG] =  180.0;
		subPtr->SeReference [LAT] =   90.0;
		subPtr->NwReference [LNG] = -180.0;
		subPtr->NwReference [LAT] =  -90.0;

		subPtr->DeltaLng  = 0.0;
		subPtr->DeltaLat  = 0.0;
		subPtr->Density   = 0.0;
		subPtr->FirstRecord = -1;
		subPtr->GridRecCnt = 0;
		subPtr->ParentIndex = -1;
		subPtr->ChildIndex = -1;
		subPtr->RowCount = 0;
		subPtr->ElementCount = 0;
		subPtr->RowSize = 0;
		subPtr->Cacheable = FALSE;
		subPtr->Name [0] = '\0';
		subPtr->Parent [0] = '\0';
	}

	/* Once for each sub-grid in the file; read in the header.  At this point,
	   we just read them in.  Later on, we peruse the array and figure out
	   who the mamas and the papas are. */
	for (idx = 0;idx < thisPtr->SubCount;idx += 1)
	{
		/* Kludge to handle the variation in format.  Doing this right
		   would require duplication of a whole bunch of code. So . . . */
		readCntRq = sizeof (fileSubHdr);
		if (thisPtr->IntType == csNTv2TypeAustralia) readCntRq -= 4;

		readCnt = CS_fread (&fileSubHdr,1,readCntRq,stream);
		if (CS_ferror (stream))
		{
			CS_erpt (cs_IOERR);
			goto error;
		}
		if (readCnt != readCntRq)
		{
			CS_erpt (cs_INV_FILE);
			goto error;
		}
		if (strncmp (fileSubHdr.titl01,"SUB_NAME",8))
		{
			CS_erpt (cs_INV_FILE);
			goto error;
		}
		if (thisPtr->IntType == csNTv2TypeCanada)
		{
			CS_bswap (&fileSubHdr,cs_BSWP_NTv2SubHdrCA);
		}
		else
		{
			CS_bswap (&fileSubHdr,cs_BSWP_NTv2SubHdrAU);
		}

		/* Collect the useful stuff. */		
		subPtr = &thisPtr->SubGridDir [idx];

		/* Data for each sub-grid immediately follows the sub-grid header. */
		subPtr->FirstRecord = CS_ftell (stream);

		/* These boundaries are rational east positive boundaries. */
		subPtr->SouthWest [LNG] = -fileSubHdr.w_long * cs_Sec2Deg;
		subPtr->SouthWest [LAT] =  fileSubHdr.s_lat  * cs_Sec2Deg;
		subPtr->NorthEast [LNG] = -fileSubHdr.e_long * cs_Sec2Deg;
		subPtr->NorthEast [LAT] =  fileSubHdr.n_lat  * cs_Sec2Deg;

		/* These boundaries are the screwy west positive ones used in the
		   NTv2 format. */
		subPtr->SeReference [LNG] = fileSubHdr.e_long * cs_Sec2Deg;
		subPtr->SeReference [LAT] = fileSubHdr.s_lat  * cs_Sec2Deg;
		subPtr->NwReference [LNG] = fileSubHdr.w_long * cs_Sec2Deg;
		subPtr->NwReference [LAT] = fileSubHdr.n_lat  * cs_Sec2Deg;

		/* The remainder of this is pretty rational. */
		subPtr->DeltaLng  = fileSubHdr.long_inc * cs_Sec2Deg;
		subPtr->DeltaLat  = fileSubHdr.lat_inc  * cs_Sec2Deg;

		/* We do not use Density in the calculations.  It is only used to
		   select one sub-grid over another in the case of overlap.  Yes,
		   I know.  The sub-grids at the same level are not suppoded to
		   overlap; but they do.  Call it job security for you an me. */
		subPtr->Density = (subPtr->DeltaLat < subPtr->DeltaLng) ? subPtr->DeltaLat : subPtr->DeltaLng;

		/* If the user has specified a default density value, we use it. */
		if (density != 0.0)
		{
			subPtr->Density = density;
		}

		/* Save the name for reporting purposes. */
		CS_stncp (subPtr->Name,fileSubHdr.sub_name,9);
		CS_stncp (subPtr->Parent,fileSubHdr.parent,9);

		subPtr->GridRecCnt = fileSubHdr.gs_count;
		/* WEST Positive, dummy.  The extra .01 is to eliminate possible fuzz
		   in the double portion of the calculations. */
		subPtr->RowCount = (unsigned short)(((subPtr->NwReference [LAT] - subPtr->SeReference [LAT]) / subPtr->DeltaLat) + 1.01);
		subPtr->ElementCount = (unsigned short)(((subPtr->NwReference [LNG] - subPtr->SeReference [LNG]) / subPtr->DeltaLng) + 1.01);
		subPtr->RowSize = (unsigned short)(subPtr->ElementCount * thisPtr->RecSize);

		/* Certain sub grids are not cacheable.  In the Canadian file, the region
		   which is not cacheable is rather small.  We use the csCaNTv2KludgeTable
		   to handle it.  The one Austrailian sub-grid we've seen is screwed up,
		   so we disable cacheing (at least for now), for all Australian files.
		   Australian, in this context, means file in the old Australian format,
		   not necessarily data files covering Australian geography.
		   
		   In the case of the Spanish variation, parent grids overlap, and
		   therefore none of the sub-grids are cacheable. */
//???? 	subPtr->Cacheable = (short)((thisPtr->IntType == csNTv2TypeCanada) && (thisPtr->SubOverlap == 0));
		subPtr->Cacheable = FALSE;

		/* Skip over the data records in the file. */
		skipAmount = subPtr->GridRecCnt * thisPtr->RecSize;
		seekStat = CS_fseek (stream,skipAmount,SEEK_CUR);
		if (seekStat != 0)
		{
			CS_erpt (cs_INV_FILE);
			goto error;
		}
	}

	/* Now we figure out who the mammas and the pappas are.  Note, all we have
	   to work with are parent names.  Therefore, we have to work bassackwards.

	   End result of all of this, is that each child needs to have the index
	   of its parent; and each sub-grid that has a child needs to be so marked. */
	for (idx =  0;idx < thisPtr->SubCount;idx += 1)
	{
		kidPtr = &thisPtr->SubGridDir [idx];
		if (CS_stricmp (kidPtr->Parent,"NONE    "))
		{
			/* Its a child, find the parent. */
			for (parIdx = 0;parIdx < thisPtr->SubCount;parIdx += 1)
			{
				parPtr = &thisPtr->SubGridDir [parIdx];
				if (!CS_stricmp (kidPtr->Parent,parPtr->Name))
				{
					/* Save the index of the parent. */
					kidPtr->ParentIndex = parIdx;

					/* Mark the parent as having a child, if not already so marked. */
					if (parPtr->ChildIndex == -1 || parPtr->ChildIndex > idx)
					{
						parPtr->ChildIndex = idx;
					}
				}
			}
		} 
	}

	/* To accomodate the Spanish (and perhaps others in the future, we check the
	   parent grids in the list of sub-grids for overlap.  If overlap exists,
	   we turn on the SubOverlap flag.  Of course, if this flag is already on,
	   we have nothing to do.  If we did indeed turn on the SubOverlap flag,
	   we need to cruise through all the sub-grids and set the Cacheable flag
	   to false to assure that no data from this file makes it to the grid cell
	   cache. */
	if (thisPtr->SubOverlap == 0)
	{
		for (parIdx = 0;parIdx < thisPtr->SubCount && thisPtr->SubOverlap == 0;parIdx += 1)
		{
			parPtr = &thisPtr->SubGridDir [parIdx];
			/* Top level grids only, we know the children overlap. */
			if (parPtr->ParentIndex >= 0) continue;

			overlap = FALSE;
			for (idx = 0;idx < thisPtr->SubCount;idx += 1)
			{
				if (idx == parIdx) continue;
				subPtr = &thisPtr->SubGridDir [idx];
				if (subPtr->ParentIndex >= 0) continue;
				
				/* See if subPtr overlaps with parPtr. */
				overlap  = subPtr->SeReference [LNG] > parPtr->SeReference [LNG] &&
						   subPtr->SeReference [LAT] > parPtr->SeReference [LAT] &&
						   subPtr->SeReference [LNG] < parPtr->NwReference [LNG] &&
						   subPtr->SeReference [LAT] < parPtr->NwReference [LAT];
				overlap |= subPtr->NwReference [LNG] > parPtr->SeReference [LNG] &&
						   subPtr->NwReference [LAT] > parPtr->SeReference [LAT] &&
						   subPtr->NwReference [LNG] < parPtr->NwReference [LNG] &&
						   subPtr->NwReference [LAT] < parPtr->NwReference [LAT];
				if (overlap)
				{
					thisPtr->SubOverlap = TRUE;		/* for testing ease */
				}
			}
		}
	
		if (thisPtr->SubOverlap != 0)
		{
			for (idx = 0;idx < thisPtr->SubCount;idx += 1)
			{
				subPtr = &thisPtr->SubGridDir [idx];
				subPtr->Cacheable = FALSE;
			}
		}
	}

	/* OK, we should be ready to rock and roll.  We close the Stream until
	   we actually need it.  Often, we get constructed just so there is a
	   record of the coverage afforded by the file. */
	if (stream != NULL)
	{
		CS_fclose (stream);
		stream = NULL;
	}
	csErrnam [0] = '\0';
	return 0;

error:
	if (stream != NULL)
	{
		CS_fclose (stream);
		stream = NULL;
	}
	if (thisPtr->SubGridDir != NULL)
	{
		CS_free (thisPtr->SubGridDir);
		thisPtr->SubGridDir = NULL;
	}
	thisPtr->HdrRecCnt = 0;
	thisPtr->SubCount = 0;
	thisPtr->RecSize = 16;
	thisPtr->CellIsValid = FALSE;
	thisPtr->SubOverlap = (short)((flags & 0x01) != 0);
	thisPtr->IntType = csNTv2TypeNone;
	thisPtr->BufferSize = bufferSize;
	thisPtr->sourceId [0] = '\0';
	if (thisPtr->BufferSize <= 0) thisPtr->BufferSize = csNTv2BufrSz;
	if (thisPtr->BufferSize <= 4096) thisPtr->BufferSize = 4096;
	CSinitNTv2GridCell (&thisPtr->longitudeCell);
	CSinitNTv2GridCell (&thisPtr->latitudeCell);
	return -1;
}
Пример #16
0
int CStest6 (int verbose,int crypt)
{
	int st;
	int cnt;
	int flag;
	int my_crypt;

	csFILE *csStrm;
	struct tst_lst_ *tp;

	char last_name [48];

	__ALIGNMENT__1			/* Required by some Sun compilers. */
	struct cs_Csdef_ cs_def;

	printf ("Testing sort and binary search functions.\n");

	/* This test sorts the Coordinate System Dictionary, the
	   largest of the three dictionaries, into reverse order.
	   Then does some CS_bins calls.  Then resorts back into
	   normal order.  This is a resaonable good exercise of
	   the sort function which normally sorts files with a
	   single entry out of order. */

	if (verbose)
	{
		printf ("Sorting Coordinate System Dictionary into reverse order.\n");
	}
	csStrm = CS_csopn (_STRM_BINUP);
	if (csStrm == NULL)
	{
		printf ("Coordinate System Dictionary open failed.  Is it write protected?.\n");
		return 1;
	}

	/* NOTE: CS_csopn leaves the file positioned after
	   the magic number.  CS_ips always starts sorting
	   at the current file position. */

	CS_ips (csStrm,sizeof (struct cs_Csdef_),-1L,(CMPFUNC_CAST)CStest6cmp);

	/* The dictionary should now be in reverse order.  We
	   check the order now.  CS_ips is supposed to return
	   with the file position where it was when we started. */

	if (verbose)
	{
		printf ("Checking reverse order of Coordinate System Dictionary.\n");
	}
	cnt = 0;
	st = CS_csrd (csStrm,&cs_def,&my_crypt);
	if (st == 0)
	{
		printf ("CS_ips hosed the Coordinate System Dictionary.\n");
		CS_fclose (csStrm);
		return (1);
	}
	CS_stncp (last_name,cs_def.key_nm,sizeof (last_name));
	while (CS_csrd (csStrm,&cs_def,&my_crypt))
	{
		cnt += 1;
		if (verbose && (cnt % 10) == 0) putchar ('.');
		st = CS_stricmp (last_name,cs_def.key_nm);
		if (st < 0)
		{
			printf ("\nSort did not sort entire file correctly!!!\n");
			CS_fclose (csStrm);
			return (1);
		}
		else if (st == 0)
		{
			printf ("\nSort left duplicate entries when sorting entire file!!!\n");
			CS_fclose (csStrm);
			return (1);
		}
	}
	if (verbose) printf (" OK.\n");

	/* If we are still here, the sort worked correctly.
	   Use the sort_tst list as a list of names to binary
	   search on.  It includes the normal first and last;
	   which should now be the last and the first. */

	tp = sort_tst;
	while (tp->name [0] != '\0')
	{
		if (verbose)
		{
			printf ("Searching for %s in reversed CS Dictionary.",tp->name);
		}
		CS_stncp (cs_def.key_nm,tp->name,sizeof (cs_def.key_nm));
		flag = CS_bins (csStrm,(long32_t)sizeof (cs_magic_t),(long32_t)0,sizeof (cs_def),
				(char *)&cs_def,(CMPFUNC_CAST)CStest6cmp);
		if (flag <= 0)
		{
			printf ("CS_bins failed on file in reverse order!!!\n");
			CS_fclose (csStrm);
			return (1);
		}
		if (verbose) printf (" OK.\n");
		tp += 1;
	}

	/* OK, return the file back to normal sorted order. */

	if (verbose)
	{
		printf ("Sorting Coordinate System Dictionary back to normal order.\n");
	}
	CS_fseek (csStrm,(long)sizeof (cs_magic_t),SEEK_SET);
	CS_ips (csStrm,sizeof (struct cs_Csdef_),-1L,(CMPFUNC_CAST)CS_cscmp);

	/* One more time, check that the order is correct. */

	if (verbose)
	{
		printf ("Checking Coordinate System Dictionary normal sorted order.\n");
	}
	cnt = 0;
	st = CS_csrd (csStrm,&cs_def,&my_crypt);
	if (st == 0)
	{
		printf ("CS_ips hosed the Coordinate System Dictionary.\n");
		CS_fclose (csStrm);
		return (1);
	}
	CS_stncp (last_name,cs_def.key_nm,sizeof (last_name));
	while (CS_csrd (csStrm,&cs_def,&my_crypt))
	{
		cnt += 1;
		if (verbose && (cnt % 10) == 0) putchar ('.');
		st = CS_stricmp (last_name,cs_def.key_nm);
		if (st > 0)
		{
			printf ("Sort did not sort entire file correctly!!!\n");
			CS_fclose (csStrm);
			return (1);
		}
		else if (st == 0)
		{
			printf ("Sort left duplicate entries when sorting entire file!!!\n");
			CS_fclose (csStrm);
			return (1);
		}
	}
	if (verbose) printf (" OK.\n");

	/* OK, if we are still here, we passed the test. */

	CS_csDictCls (csStrm);
	return (0);
}
Пример #17
0
/*****************************************************************************
	Constructor
*/
struct csGeoid96GridFile_* CSnewGeoid96GridFile (Const char *path,long32_t bufferSize,ulong32_t flags,double density)
{
	extern char cs_DirsepC;
	extern char cs_ExtsepC;
	extern char csErrnam [];

	size_t readCount;
	long lngTmp;
	char *cp1, *cp2;
	csFILE *fstr;
	struct csGeoid96GridFile_* __This;
	char cTemp [MAXPATH];
	struct csNadconFileHdr_ nadconHdr;

	/* Prepare for an error. */
	__This = NULL;
	fstr = NULL;

	/* Malloc and initialize */
	__This = CS_malc (sizeof (struct csGeoid96GridFile_));
	if (__This == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}
	CSinitGeoid96 (__This);

	/* Set default values for all members. */
	__This->bufferSize = bufferSize;
	if (__This->bufferSize < 0) __This->bufferSize = 0;

	/* Save file path/name. */
	CS_stncp (__This->filePath,path,sizeof (__This->filePath));
	CS_stncp (cTemp,path,sizeof (cTemp));

	/* Set up the type of file.  Get cp1 to point at the file
	   name, and cp2 to point at the extension.  We consider it
	   an error if we are not given a full path name.  Note,
	   we care not about the format of the drive specification.
	   But there must be at least one directory and there must
	   be an extension. */
	cp1 = strrchr (cTemp,cs_DirsepC);
	if (cp1 == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	cp1 += 1;
	cp2 = strchr (cp1,cs_ExtsepC);
	if (cp2 == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	*cp2++ = '\0';
	CS_stncp (__This->fileName,cp1,sizeof (__This->fileName));

	/* The thing should have a .geo extension to be processed by us. */
	if (CS_stricmp (cp2,"geo"))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Get the file information header. */
	fstr = CS_fopen (__This->filePath,_STRM_BINRD);
	if (fstr == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_DTC_FILE);
		goto error;
	}
	readCount = CS_fread (&nadconHdr,1,sizeof (nadconHdr),fstr);
	if (readCount != sizeof (nadconHdr))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	if (CS_ferror (fstr))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}

	/* Determine the size of the file. */
	if (CS_fseek (fstr,0L,SEEK_END))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}
	__This->fileSize = CS_ftell (fstr);
	if (__This->fileSize < 0L)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}

	/* This constructor doesn't need the file any more. */
	CS_fclose (fstr);
	fstr = NULL;

	/* Swap the bytes if necessary. */
	CS_bswap (&nadconHdr,cs_BSWP_NadconFileHdr);

	/* The extra stuff here is required as conversions of floats to doubles
	   does not always provide precise results.  To get the precise results we
	   require, we assume that the value (which is in degrees) is an intergal
	   number of seconds. */
	lngTmp = (long)(((double)nadconHdr.del_lng * 3600.0) + 0.4);
	__This->deltaLng = ((double)lngTmp / 3600.0);
	lngTmp = (long)(((double)nadconHdr.del_lat * 3600.0) + 0.4);
	__This->deltaLat = ((double)lngTmp / 3600.0);

	/* Now we can do the rest of this stuff. */
	__This->coverage.southWest [LNG] = nadconHdr.min_lng;
	__This->coverage.southWest [LAT] = nadconHdr.min_lat;
	__This->coverage.northEast [LNG] = nadconHdr.min_lng + (__This->deltaLng * (nadconHdr.ele_cnt - 1));
	__This->coverage.northEast [LAT] = nadconHdr.min_lat + (__This->deltaLat * (nadconHdr.rec_cnt - 1));
	__This->coverage.density = (__This->deltaLng < __This->deltaLat) ? __This->deltaLng : __This->deltaLat;
	if (density != 0.0) __This->coverage.density = density;
	__This->elementCount = nadconHdr.ele_cnt;
	__This->recordCount = nadconHdr.rec_cnt;
	__This->recordSize = nadconHdr.ele_cnt * (int)sizeof (float) + (int)sizeof (long);

	/* Verify the integrity of the file. */
	lngTmp = (__This->recordCount + 1) * __This->recordSize;
	if (lngTmp != __This->fileSize)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Now that we know recordSize, we can adjust the bufferSize for maximum
	   efficiency. */
	if (__This->bufferSize > __This->fileSize)
	{
		__This->bufferSize = __This->fileSize;
	}
	else
	{
		if (__This->bufferSize > (3 * __This->recordSize))
		{
			/* Maximum efficiency is obtained with a buffer size whch is
			   a multiple of the record size. */
			__This->bufferSize = (__This->bufferSize / __This->recordSize) * __This->recordSize;
		}
		else
		{
			/* We require a minimum buffer size of 3 records. */
			__This->bufferSize = 3 * __This->recordSize;
		}
	}

	return (__This);
error:
	CSdeleteGeoid96GridFile (__This);
	return NULL;
}
Пример #18
0
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);
}
Пример #19
0
/*****************************************************************************
	Constructor
*/
struct csGeoid99GridFile_* CSnewGeoid99GridFile (Const char *path,long32_t bufferSize,ulong32_t flags,double density)
{
	extern double cs_K360;
	extern char cs_DirsepC;
	extern char cs_ExtsepC;
	extern char csErrnam [];

	size_t readCount;
	long lngTmp;
	double lngMin, lngMax;
	char *cp1, *cp2;
	csFILE *fstr;
	struct csGeoid99GridFile_* __This;
	char cTemp [MAXPATH];
	struct csGeoid99Hdr_ geoid99Hdr;

	/* Prepare for an error. */
	__This = NULL;
	fstr = NULL;

	/* Malloc and initialize */
	__This = CS_malc (sizeof (struct csGeoid99GridFile_));
	if (__This == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}
	CSinitGeoid99 (__This);

	/* Set default values for all members. */
	__This->bufferSize = bufferSize;
	if (__This->bufferSize < 0) __This->bufferSize = 0;

	/* Save file path/name. */
	CS_stncp (__This->filePath,path,sizeof (__This->filePath));
	CS_stncp (cTemp,path,sizeof (cTemp));

	/* Set up the type of file.  Get cp1 to point at the file
	   name, and cp2 to point at the extension.  We consider it
	   an error if we are not given a full path name.  Note,
	   we care not about the format of the drive specification.
	   But there must be at least one directory and there must
	   be an extension. */
	cp1 = strrchr (cTemp,cs_DirsepC);
	if (cp1 == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	cp1 += 1;
	cp2 = strchr (cp1,cs_ExtsepC);
	if (cp2 == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	*cp2++ = '\0';
	CS_stncp (__This->fileName,cp1,sizeof (__This->fileName));

	/* The thing should have a .bin extension to be processed by us. */
	if (CS_stricmp (cp2,"bin"))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Get the file information header. */
	fstr = CS_fopen (__This->filePath,_STRM_BINRD);
	if (fstr == NULL)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_DTC_FILE);
		goto error;
	}
	readCount = CS_fread (&geoid99Hdr,1,sizeof (geoid99Hdr),fstr);
	if (readCount != sizeof (geoid99Hdr))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}
	if (CS_ferror (fstr))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}

	/* Determine the size of the file. */
	if (CS_fseek (fstr,0L,SEEK_END))
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}
	__This->fileSize = CS_ftell (fstr);
	if (__This->fileSize < 0L)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_IOERR);
		goto error;
	}

	/* This constructor doesn't need the file any more. */
	CS_fclose (fstr);
	fstr = NULL;

	/* Swap the bytes if necessary.  In all the data files I've seen, iKind is 32
	   bit 1.  If it is a one in the structure, than the file is in the same byte
	   order as the machine we are running on, and swapping is unnecessary.  If
	   iKind is not a one, we assume that is because of byte order, and we do a
	   swap.  Note, however, that we preserve iKind as it was before swapping so
	   that we know whether to swap or not in the other functions in this code
	   module. */

	__This->iKind = geoid99Hdr.iKind;
	if (geoid99Hdr.iKind != 1L)
	{
		/* CSbswap is a variation on CS_bswap.  CSbswap always swaps. */
		CSbswap (&geoid99Hdr,cs_BSWP_Geoid99Hdr);
	}

	/* At this point, geoid99Hdr.iKind should be a one, or either the file
	   is corrupted, or we don't understand the file format properly. */

	if (geoid99Hdr.iKind != 1L)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Extract the important stuff from the header.  Note that the longitude in the header
	   is a zero thru 360 value, proceeding east from Greenwich.  This makes a lot of sense
	   since Alaska crosses the 190 degree crack.  However, it is inconsistent with
	   all the other stuff.  So, we do the following kludge, which is consistent with the
	   NADCON data files. */
	lngMin = geoid99Hdr.lngMin;
	lngMax = lngMin + (geoid99Hdr.lngDelta * (geoid99Hdr.lngCount - 1));
	if (lngMin >= 180.0 || lngMax > 180.0)
	{
		__This->coverage.southWest [LNG] = geoid99Hdr.lngMin - cs_K360;
	}
	else
	{
		__This->coverage.southWest [LNG] = geoid99Hdr.lngMin;
	}
	__This->coverage.southWest [LAT] = geoid99Hdr.latMin;
	__This->deltaLng = geoid99Hdr.lngDelta;
	__This->deltaLat = geoid99Hdr.latDelta;
	__This->coverage.northEast [LNG] = __This->coverage.southWest [LNG] + (geoid99Hdr.lngDelta * (geoid99Hdr.lngCount - 1));
	__This->coverage.northEast [LAT] = __This->coverage.southWest [LAT] + (geoid99Hdr.latDelta * (geoid99Hdr.latCount - 1));
	__This->coverage.density = (__This->deltaLng < __This->deltaLat) ? __This->deltaLng : __This->deltaLat;
	if (density != 0.0) __This->coverage.density = density;
	__This->elementCount = geoid99Hdr.lngCount;
	__This->recordCount = geoid99Hdr.latCount;
	__This->recordSize = geoid99Hdr.lngCount * (int)sizeof (float);

	/* Verify the integrity of the file. */
	lngTmp = __This->recordCount * __This->recordSize + sizeof (geoid99Hdr);
	if (lngTmp != __This->fileSize)
	{
		CS_stncp (csErrnam,__This->filePath,MAXPATH);
		CS_erpt (cs_INV_FILE);
		goto error;
	}

	/* Now that we know recordSize, we can adjust the bufferSize for maximum
	   efficiency. */
	if (__This->bufferSize > __This->fileSize)
	{
		__This->bufferSize = __This->fileSize;
	}
	else
	{
		if (__This->bufferSize > (3 * __This->recordSize))
		{
			/* Maximum efficiency is obtained with a buffer size whch is
			   a multiple of the record size. */
			__This->bufferSize = (__This->bufferSize / __This->recordSize) * __This->recordSize;
		}
		else
		{
			/* We require a minimum buffer size of 3 records. */
			__This->bufferSize = 3 * __This->recordSize;
		}
	}

	return (__This);
error:
	CSdeleteGeoid99GridFile (__This);
	return NULL;
}
Пример #20
0
/* The following function compares only those portions of a Coordinate System
   definition which affect numeric results.  The number of differences found
   is returned.  Zero return indcates a match.  If the message argument is
   not NULL, and the messageSize argument is greater than one, a description
   of the first difference located is returned. */
int EXP_LVL3 CS_csDefCmp (Const struct cs_Csdef_ *original,Const struct cs_Csdef_ *revised,char* message,size_t messageSize)
{
    extern struct cs_Prjtab_ cs_Prjtab [];		/* Projection Table */
    extern double cs_Six;
    extern double cs_Zero;

    int errCnt = 0;
    int errCntCnc = 0;

    struct cs_Prjtab_ *pp;

    double unitsFactor;

    char errMsg [512];

    const struct cs_Csdef_ *lclOrgPtr;
    const struct cs_Csdef_ *lclRevPtr;
    struct cs_Csdef_ lclOriginal;
    struct cs_Csdef_ lclRevised;

    /* Before we get onto this to heavy; we check the projection code of the
       original and the revised.  If the original is UTM, and the revised is
       TM, we convert the original from UTM form to TM form.  This eliminates
       a big headache. */
    lclOrgPtr = original;
    if (!CS_stricmp (original->prj_knm,"UTM") && !CS_stricmp (revised->prj_knm,"TM"))
    {
        /* Convert original to the TM form. */
        memcpy (&lclOriginal,original,sizeof (lclOriginal));
        strcpy (lclOriginal.prj_knm,"TM");
        lclOriginal.prj_prm1 = cs_Six * lclOriginal.prj_prm1 - 183.0;
        lclOriginal.org_lat = cs_Zero;
        unitsFactor = CS_unitlu (cs_UTYP_LEN,lclOriginal.unit);
        lclOriginal.x_off = 500000.0 / unitsFactor;
        lclOriginal.y_off = (lclOrgPtr->prj_prm2 >= 0.0) ? cs_Zero : 10000000.0 / unitsFactor;
        lclOriginal.scl_red = 0.9996;
        lclOriginal.quad = 1;
        lclOrgPtr = &lclOriginal;
    }
    lclRevPtr = revised;
    if (!CS_stricmp (revised->prj_knm,"UTM") && !CS_stricmp (original->prj_knm,"TM"))
    {
        /* Convert revised to the TM form. */
        memcpy (&lclRevised,revised,sizeof (lclRevised));
        strcpy (lclRevised.prj_knm,"TM");
        lclRevised.prj_prm1 = cs_Six * lclRevised.prj_prm1 - 183.0;
        lclRevised.org_lat = cs_Zero;
        unitsFactor = CS_unitlu (cs_UTYP_LEN,lclRevised.unit);
        lclRevised.x_off = 500000.0 / unitsFactor;
        lclRevised.y_off = (lclRevPtr->prj_prm2 >= 0.0) ? cs_Zero : 10000000.0 / unitsFactor;
        lclRevised.scl_red = 0.9996;
        lclRevised.quad = 1;
        lclRevPtr = &lclRevised;
    }

    if (CS_stricmp (lclOrgPtr->prj_knm,lclRevPtr->prj_knm))
    {
        if (errCnt == 0)
        {
            sprintf (errMsg,"Projection key name was %s, is now %s",lclOrgPtr->prj_knm,lclRevPtr->prj_knm);
        }
        errCnt += 1;
    }
    if (CS_stricmp (lclOrgPtr->unit,lclRevPtr->unit))
    {
        if (errCnt == 0)
        {
            sprintf (errMsg,"Unit name was %s, is now %s",lclOrgPtr->unit,lclRevPtr->unit);
        }
        errCnt += 1;
    }

    /* If the projection codes don't match, we're in deep do-do.  So, we bag it now
       if we haven't got a match so far. */
    if (errCnt != 0)
    {
        if (message != 0 && messageSize > 1)
        {
            CS_stncp (message,errMsg,(int)messageSize);
        }
        return errCnt;
    }

    /* Look this projection up in the projection table, we need to pass the
       projection code to the parameter check function. */
    for (pp = cs_Prjtab; pp->key_nm [0] != '\0'; pp += 1)
    {
        if (!CS_stricmp (lclOrgPtr->prj_knm,pp->key_nm))
        {
            break;
        }
    }
    if (pp->check == NULL)
    {
        if (errCnt == 0)
        {
            sprintf (errMsg,"Projection key name is now %s which is invalid.",lclRevPtr->prj_knm);
        }
        errCnt += 1;
    }
    else
    {
        if (message != NULL && messageSize > 1)
        {
            if (errCnt == 0) *message = '\0';
        }
        else
        {
            CS_stncp (message,errMsg,(int)messageSize);
        }

        /* Check all of the parameters. */
        if (errCnt == 0) errMsg[0] = '\0';

        /* We skip checking the first two parameters for the Unity projection as WKT
           does not support the longitude range feature. */
        if (pp->code != cs_PRJCOD_UNITY)
        {
            /* For conic projections which require two standard parallels, the order of the parallels
               does not make any difference to the mathemagics of the projection.  In this case,
               if (prm1 != prm1 && prm2 != prm2) we do an additional check of
               if (prm1 == prm2 and prm2 == prm1).  It is traditional to supply the northern
               parallel first, but the are variations of WKT out there to do not follw this
               tradition (and it is only a tradition). */
            if (pp->code == cs_PRJCOD_LM2SP   ||
                    pp->code == cs_PRJCOD_LMBLG   ||
                    pp->code == cs_PRJCOD_WCCSL   ||
                    pp->code == cs_PRJCOD_MNDOTL  ||
                    pp->code == cs_PRJCOD_ALBER   ||
                    pp->code == cs_PRJCOD_LMBRTAF)
            {
                errCntCnc = 0;
                errCntCnc += CS_defCmpPrjPrm (pp, 1,lclOrgPtr->prj_prm1 ,lclRevPtr->prj_prm1,errMsg,sizeof (errMsg));
                errCntCnc += CS_defCmpPrjPrm (pp, 2,lclOrgPtr->prj_prm2 ,lclRevPtr->prj_prm2,errMsg,sizeof (errMsg));
                if (errCntCnc == 2)
                {
                    errCnt += CS_defCmpPrjPrm (pp, 1,lclOrgPtr->prj_prm1 ,lclRevPtr->prj_prm2,errMsg,sizeof (errMsg));
                    errCnt += CS_defCmpPrjPrm (pp, 2,lclOrgPtr->prj_prm2 ,lclRevPtr->prj_prm1,errMsg,sizeof (errMsg));
                }
            }
            else
            {
                /* Not a conic nor geographic, so we just compare the two
                   parameter values. */
                errCnt += CS_defCmpPrjPrm (pp, 1,lclOrgPtr->prj_prm1 ,lclRevPtr->prj_prm1,errMsg,sizeof (errMsg));
                errCnt += CS_defCmpPrjPrm (pp, 2,lclOrgPtr->prj_prm2 ,lclRevPtr->prj_prm2,errMsg,sizeof (errMsg));
            }
        }
        errCnt += CS_defCmpPrjPrm (pp, 3,lclOrgPtr->prj_prm3 ,lclRevPtr->prj_prm3,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 4,lclOrgPtr->prj_prm4 ,lclRevPtr->prj_prm4,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 5,lclOrgPtr->prj_prm5 ,lclRevPtr->prj_prm5,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 6,lclOrgPtr->prj_prm6 ,lclRevPtr->prj_prm6,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 7,lclOrgPtr->prj_prm7 ,lclRevPtr->prj_prm7,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 8,lclOrgPtr->prj_prm8 ,lclRevPtr->prj_prm8,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp, 9,lclOrgPtr->prj_prm9 ,lclRevPtr->prj_prm9,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,10,lclOrgPtr->prj_prm10,lclRevPtr->prj_prm10,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,11,lclOrgPtr->prj_prm11,lclRevPtr->prj_prm11,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,12,lclOrgPtr->prj_prm12,lclRevPtr->prj_prm12,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,13,lclOrgPtr->prj_prm13,lclRevPtr->prj_prm13,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,14,lclOrgPtr->prj_prm14,lclRevPtr->prj_prm14,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,15,lclOrgPtr->prj_prm15,lclRevPtr->prj_prm15,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,16,lclOrgPtr->prj_prm16,lclRevPtr->prj_prm16,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,17,lclOrgPtr->prj_prm17,lclRevPtr->prj_prm17,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,18,lclOrgPtr->prj_prm18,lclRevPtr->prj_prm18,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,19,lclOrgPtr->prj_prm19,lclRevPtr->prj_prm19,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,20,lclOrgPtr->prj_prm20,lclRevPtr->prj_prm20,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,21,lclOrgPtr->prj_prm21,lclRevPtr->prj_prm21,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,22,lclOrgPtr->prj_prm22,lclRevPtr->prj_prm22,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,23,lclOrgPtr->prj_prm23,lclRevPtr->prj_prm23,errMsg,sizeof (errMsg));
        errCnt += CS_defCmpPrjPrm (pp,24,lclOrgPtr->prj_prm24,lclRevPtr->prj_prm24,errMsg,sizeof (errMsg));
    }

    if ((pp->flags & cs_PRJFLG_ORGLAT) == 0)
    {
        if (CS_cmpDbls (lclOrgPtr->org_lat,lclRevPtr->org_lat) == 0)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"Origin Latitude was %14.8f, is now %14.8f",lclOrgPtr->org_lat,lclRevPtr->org_lat);
            }
            errCnt += 1;
        }
    }
    if ((pp->flags & cs_PRJFLG_ORGLNG) == 0)
    {
        if (CS_cmpDbls (lclOrgPtr->org_lng,lclRevPtr->org_lng) == 0)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"Origin Longitude was %14.8f, is now %14.8f",lclOrgPtr->org_lng,lclRevPtr->org_lng);
            }
            errCnt += 1;
        }
    }
    if ((pp->flags & cs_PRJFLG_ORGFLS) == 0)
    {
        if (fabs (lclOrgPtr->x_off - lclRevPtr->x_off) > 0.001)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"False easting was %14.3f, is now %14.3f",lclOrgPtr->x_off,lclRevPtr->x_off);
            }
            errCnt += 1;
        }
        if (fabs (lclOrgPtr->y_off - lclRevPtr->y_off) > 0.001)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"False northing was %14.3f, is now %14.3f",lclOrgPtr->y_off,lclRevPtr->y_off);
            }
            errCnt += 1;
        }
    }
    if ((pp->flags & cs_PRJFLG_SCLRED) != 0)
    {
        if (CS_cmpDbls (lclOrgPtr->scl_red,lclRevPtr->scl_red) == 0)
        {
            if (errCnt == 0)
            {
                sprintf (errMsg,"Scale reduction was %12.10f, is now %12.10f",lclOrgPtr->scl_red,lclRevPtr->scl_red);
            }
            errCnt += 1;
        }
    }
    if (lclOrgPtr->quad != lclRevPtr->quad)
    {
        if (errCnt == 0)
        {
            sprintf (errMsg,"Quad was %d, is now %d",lclOrgPtr->quad,lclRevPtr->quad);
        }
        errCnt += 1;
    }

    if (errCnt != 0)
    {
        if (message != 0 && messageSize > 1)
        {
            CS_stncp (message,errMsg,(int)messageSize);
        }
    }

    return errCnt;
}
Пример #21
0
int CS_csDiff (FILE *rptStrm,struct cs_Csdef_ *was,struct cs_Csdef_ *is)
{
	extern struct cs_Prjtab_ cs_Prjtab [];		/* Projection Table */

	int flag = TRUE;
	int errCnt = 0;
	double okValue;

	struct cs_Prjtab_ *pp;

	char key_name [64];

	if (strcmp (was->dat_knm,is->dat_knm))
	{
		fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Datum Key Name (dat_knm):\n       was: %s\n    is now: %s\n",was->dat_knm,is->dat_knm);
	}
	if (strcmp (was->elp_knm,is->elp_knm))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Ellipsoid Key Name (elp_knm):\n       was: %s\n    is now: %s\n",was->elp_knm,is->elp_knm);
	}
	if (strcmp (was->prj_knm,is->prj_knm))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Projection Key Name (prj_knm):\n       was: %s\n    is now: %s\n",was->prj_knm,is->prj_knm);
	}
	if (strcmp (was->group,is->group))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Group (group):\n       was: %s\n    is now: %s\n",was->group,is->group);
	}
	if (strcmp (was->locatn,is->locatn))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Group (group):\n       was: %s\n    is now: %s\n",was->locatn,is->locatn);
	}
	if (strcmp (was->cntry_st,is->cntry_st))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Political Location (cntry_st):\n       was: %s\n    is now: %s\n",was->cntry_st,is->cntry_st);
	}
	if (strcmp (was->unit,is->unit))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Unit (unit):\n       was: %s\n    is now: %s\n",was->unit,is->unit);
	}

	/* Look this projection up in the projection table, we need to pass the
	   projection code to the parameter check function. */

	for (pp = cs_Prjtab;pp->key_nm [0] != '\0';pp += 1)
	{
		if (!CS_stricmp (was->prj_knm,pp->key_nm))
		{
			break;
		}
	}

	if (pp->check == NULL)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;

		fprintf (rptStrm,"  %s has an invalid projection code name.",was->prj_knm);
	}
	else
	{
		/* Check all of the parameters. */

		if (flag) CS_stcpy (key_name,was->key_nm);
		else      key_name [0] = '\0';

		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 1,was->prj_prm1 ,is->prj_prm1);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 2,was->prj_prm2 ,is->prj_prm2);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 3,was->prj_prm3 ,is->prj_prm3);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 4,was->prj_prm4 ,is->prj_prm4);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 5,was->prj_prm5 ,is->prj_prm5);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 6,was->prj_prm6 ,is->prj_prm6);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 7,was->prj_prm7 ,is->prj_prm7);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 8,was->prj_prm8 ,is->prj_prm8);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp, 9,was->prj_prm9 ,is->prj_prm9);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,10,was->prj_prm10,is->prj_prm10);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,11,was->prj_prm11,is->prj_prm11);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,12,was->prj_prm12,is->prj_prm12);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,13,was->prj_prm13,is->prj_prm13);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,14,was->prj_prm14,is->prj_prm14);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,15,was->prj_prm15,is->prj_prm15);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,16,was->prj_prm16,is->prj_prm16);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,17,was->prj_prm17,is->prj_prm17);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,18,was->prj_prm18,is->prj_prm18);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,19,was->prj_prm19,is->prj_prm19);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,20,was->prj_prm20,is->prj_prm20);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,21,was->prj_prm21,is->prj_prm21);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,22,was->prj_prm22,is->prj_prm22);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,23,was->prj_prm23,is->prj_prm23);
		errCnt += CScmpPrjParm (rptStrm,key_name,pp,24,was->prj_prm24,is->prj_prm24);
	}

	okValue = 1.0E-09;
	if (fabs (was->org_lng - is->org_lng) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Origin Longitude (org_lng):\n       was: %18.12f\n    is now: %18.12f\n",was->org_lng,is->org_lng);
	}
	if (fabs (was->org_lat - is->org_lat) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Origin Latitude (org_lat):\n       was: %18.12f\n    is now: %18.12f\n",was->org_lat,is->org_lat);
	}

	okValue = 1.0E-03;
	if (fabs (was->x_off - is->x_off) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  FALSE Easting (x_off):\n       was: %16.6f\n    is now: %16.6f\n",was->x_off,is->x_off);
	}
	if (fabs (was->y_off - is->y_off) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  FALSE Northing (y_off):\n       was: %16.6f\n    is now: %16.6f\n",was->y_off,is->y_off);
	}

	okValue = 1.0E-09;
	if (fabs (was->scl_red - is->scl_red) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Scale Reduction (scl_red):\n       was: %18.12f\n    is now: %18.12f\n",was->scl_red,is->scl_red);
	}

	if (!CS_stricmp (was->prj_knm,"LL"))
	{
		okValue = 1.0E-09;
		if (fabs (was->zero [0] - is->zero [0]) > okValue || fabs (was->zero [1] - is->zero [1]) > okValue)
		{
			if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
			flag = FALSE;
			errCnt += 1;
			fprintf (rptStrm,"  Miinimum Non Zero (zero):\n       was: %14.12f:%14.12f\n    is now: %14.12f:%14.12f\n",was->zero [0],was->zero[1],is->zero [0],is->zero [1]);
		}
	}
	else
	{
		okValue = 1.0E-03;
		if (fabs (was->zero [0] - is->zero [0]) > okValue || fabs (was->zero [1] - is->zero [1]) > okValue)
		{
			if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
			flag = FALSE;
			errCnt += 1;
			fprintf (rptStrm,"  Miinimum Non Zero (zero):\n       was: %8.6f:%8.6f\n    is now: %8.6f:%8.6f\n",was->zero [0],was->zero[1],is->zero [0],is->zero [1]);
		}
	}

	okValue = 1.0E-09;
	if (fabs (was->hgt_lng - is->hgt_lng) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Height Longitude (hgt_lng):\n       was: %18.12f\n    is now: %18.12f\n",was->hgt_lng,is->hgt_lng);
	}
	if (fabs (was->hgt_lat - is->hgt_lat) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Height Latitude (hgt_lat):\n       was: %18.12f\n    is now: %18.12f\n",was->hgt_lat,is->hgt_lat);
	}
	if (fabs (was->hgt_zz - is->hgt_zz) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Height Elevation (hgt_zz):\n       was: %12.6f\n    is now: %12.6f\n",was->hgt_zz,is->hgt_zz);
	}
	if (fabs (was->geoid_sep - is->geoid_sep) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Geoid Separation (geoid_sep):\n       was: %12.6f\n    is now: %12.6f\n",was->geoid_sep,is->geoid_sep);
	}

	okValue = 1.0E-08;
	if (fabs (was->ll_min [0] - is->ll_min [0]) > okValue || fabs (was->ll_min [1] - is->ll_min [1]) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Min Lat/Lng (ll_min):\n       was: %14.8f:%14.8f\n    is now: %14.8f:%14.8f\n",was->ll_min [0],was->ll_min[1],is->ll_min [0],is->ll_min [1]);
	}
	if (fabs (was->ll_max [0] - is->ll_max [0]) > okValue || fabs (was->ll_max [1] - is->ll_max [1]) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Max Lat/Lng (ll_max):\n       was: %14.8f:%14.8f\n    is now: %14.8f:%14.8f\n",was->ll_max [0],was->ll_max[1],is->ll_max [0],is->ll_max [1]);
	}

	okValue = 1.0E-03;
	if (fabs (was->xy_min [0] - is->xy_min [0]) > okValue || fabs (was->xy_min [1] - is->xy_min [1]) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Min X/Y (xy_min):\n       was: %14.4f:%14.4f\n    is now: %14.4f:%14.4f\n",was->xy_min [0],was->xy_min[1],is->xy_min [0],is->xy_min [1]);
	}
	if (fabs (was->xy_max [0] - is->xy_max [0]) > okValue || fabs (was->xy_max [1] - is->xy_max [1]) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Max X/Y (xy_max):\n       was: %14.4f:%14.4f\n    is now: %14.4f:%14.4f\n",was->xy_max [0],was->xy_max[1],is->xy_max [0],is->xy_max [1]);
	}

	if (strcmp (was->desc_nm,is->desc_nm))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Descriptive Name (desc_nm):\n       was: %s\n    is now: %s\n",was->desc_nm,is->desc_nm);
	}
	if (strcmp (was->source,is->source))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Source description (source):\n       was: %s\n    is now: %s\n",was->source,is->source);
	}

	if (was->quad != is->quad)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Quadrant (quad):\n       was: %d\n    is now: %d\n",was->quad,is->quad);
	}
	if (was->order != is->order)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Polynomial Order (order):\n       was: %d\n    is now: %d\n",was->order,is->order);
	}
	if (was->zones != is->zones)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Zone Count (zones):\n       was: %d\n    is now: %d\n",was->zones,is->zones);
	}
	if (was->protect != is->protect)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Protection Flag (protect):\n       was: %d\n    is now: %d\n",was->protect,is->protect);
	}
	if (was->epsg_qd != is->epsg_qd)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Automatic Geoid Flag (epsg_qd):\n       was: %d\n    is now: %d\n",was->epsg_qd,is->epsg_qd);
	}
	if (was->srid != is->srid)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Elevation Technique (srid):\n       was: %d\n    is now: %d\n",was->srid,is->srid);
	}
	if (was->epsgNbr != is->epsgNbr)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  EPSG (epsgNbr):\n       was: %d\n    is now: %d\n",was->epsgNbr,is->epsgNbr);
	}
	if (was->wktFlvr != is->wktFlvr)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  WKT Flavor (wktFlvr):\n       was: %d\n    is now: %d\n",was->wktFlvr,is->wktFlvr);
	}
	return errCnt;
}
Пример #22
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);
}
Пример #23
0
int CS_dtDiff (FILE *rptStrm,struct cs_Dtdef_ *was,struct cs_Dtdef_ *is)
{
	int flag = TRUE;
	int errCnt = 0;
	double okValue;

	if (CS_stricmp (was->ell_knm,is->ell_knm))
	{
		fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Ellipsoid Key Name (ell_knm):\n       was: %s\n    is now: %s\n",was->ell_knm,is->ell_knm);
	}
	if (CS_stricmp (was->group,is->group))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Group (group):\n       was: %s\n    is now: %s\n",was->group,is->group);
	}
	if (CS_stricmp (was->locatn,is->locatn))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Location (locatn):\n       was: %s\n    is now: %s\n",was->locatn,is->locatn);
	}
	if (CS_stricmp (was->cntry_st,is->cntry_st))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Political Location (cntry_st):\n       was: %s\n    is now: %s\n",was->cntry_st,is->cntry_st);
	}

	okValue = 1.0E-03;
	if (fabs (was->delta_X - is->delta_X) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Delta X (delta_X):\n       was: %9.3f\n    is now: %9.3f\n",was->delta_X,is->delta_X);
	}
	if (fabs (was->delta_Y - is->delta_Y) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Delta Y (delta_Y):\n       was: %9.3f\n    is now: %9.3f\n",was->delta_Y,is->delta_Y);
	}
	if (fabs (was->delta_Z - is->delta_Z) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Delta Z (delta_Z):\n       was: %9.3f\n    is now: %9.3f\n",was->delta_Z,is->delta_Z);
	}

	okValue = 1.0E-03;
	if (fabs (was->rot_X - is->rot_X) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  X Rotation (rot_X):\n       was: %9.3f\n    is now: %9.3f\n",was->rot_X,is->rot_X);
	}
	if (fabs (was->rot_Y - is->rot_Y) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Y Rotation (rot_Y):\n       was: %9.3f\n    is now: %9.3f\n",was->rot_Y,is->rot_Y);
	}
	if (fabs (was->rot_Z - is->rot_Z) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Z Rotation (rot_Z):\n       was: %9.3f\n    is now: %9.3f\n",was->rot_Z,is->rot_Z);
	}

	okValue = 1.0E-06;
	if (fabs (was->bwscale - is->bwscale) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Scale (bwscale):\n       was: %10.6f\n    is now: %10.6f\n",was->bwscale,is->bwscale);
	}

	if (CS_stricmp (was->name,is->name))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Descriptive Name (name):\n       was: %s\n    is now: %s\n",was->name,is->name);
	}
	if (CS_stricmp (was->source,is->source))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Information Source (source):\n       was: %s\n    is now: %s\n",was->source,is->source);
	}

	if (was->protect != is->protect)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Protection (protect):\n       was: %d\n    is now: %d\n",was->protect,is->protect);
	}
	if (was->to84_via != is->to84_via)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Calculation Technique (to84_via):\n       was: %d\n    is now: %d\n",was->to84_via,is->to84_via);
	}
	if (was->epsgNbr != is->epsgNbr)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Epsg Number (epsgNbr):\n       was: %d\n    is now: %d\n",was->epsgNbr,is->epsgNbr);
	}
	return errCnt;
}
Пример #24
0
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);
}
Пример #25
0
int CS_elDiff (FILE *rptStrm,struct cs_Eldef_ *was,struct cs_Eldef_ *is)
{
	int flag = TRUE;
	int errCnt = 0;
	double okValue;

	if (CS_stricmp (was->group,is->group))
	{
		fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Group (group):\n       was: %s\n    is now: %s\n",was->group,is->group);
	}

	okValue = 1.0E-04;
	if (fabs (was->e_rad - is->e_rad) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Equatorial Radius (e_rad):\n       was: %12.3f\n    is now: %12.3f\n",was->e_rad,is->e_rad);
	}
	if (fabs (was->p_rad - is->p_rad) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Polar radius (p_rad):\n       was: %12.3f\n    is now: %12.3f\n",was->p_rad,is->p_rad);
	}

	okValue = 1.0E-12;
	if (fabs (was->flat - is->flat) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Flattening (flat):\n       was: %14.11f\n    is now: %14.11f\n",was->flat,is->flat);
	}
	if (fabs (was->ecent - is->ecent) > okValue)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Eccentricity (ecent):\n       was: %14.11f\n    is now: %14.11f\n",was->ecent,is->ecent);
	}

	if (CS_stricmp (was->name,is->name))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Descriptive Name (name):\n       was: %s\n    is now: %s\n",was->name,is->name);
	}

	if (CS_stricmp (was->source,is->source))
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Information Source (source):\n       was: %s\n    is now: %s\n",was->source,is->source);
	}

	if (was->protect != is->protect)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Protection (protect):\n       was: %d\n    is now: %d\n",was->protect,is->protect);
	}

	if (was->epsgNbr != is->epsgNbr)
	{
		if (flag) fprintf (rptStrm,"\n%s has changed:\n",is->key_nm);
		flag = FALSE;
		errCnt += 1;
		fprintf (rptStrm,"  Epsg Number (epsgNbr):\n       was: %d\n    is now: %d\n",was->epsgNbr,is->epsgNbr);
	}

	return errCnt;
}
Пример #26
0
int EXP_LVL9 CSdtcomp (	Const char *inpt,
						Const char *outp,
						int flags,
						Const char *elipsoid,
						int (*err_func)(char *mesg)
					  )
{
	int st;
	int test;
	int demo;
	int warn;
	int dummy;
	int cancel;
	int err_cnt;
	int crypt;

	size_t rdCnt;
	size_t wrCnt;

	char *cp;
	csFILE *inStrm;
	csFILE *elStrm;
	csFILE *outStrm;
	struct cs_DtcmpT_ *tp;
	struct cs_DtTypeT_ *typPtr;

	cs_magic_t magic;

	char err_seg [18];
	char buff [128];
	char err_msg [128];
	char last_name [48];

	__ALIGNMENT__2		/* For some versions of Sun compiler. */
	struct cs_Dtdef_ dtdef;

	crypt = ((flags & cs_CMPLR_CRYPT) != 0);
	demo  = ((flags & cs_CMPLR_DEMO) != 0);
	test  = ((flags & cs_CMPLR_TEST) != 0);
	warn  = ((flags & cs_CMPLR_WARN) != 0);

	/* Open the source file. */
	inStrm = CS_fopen (inpt,_STRM_TXTRD);
	if (inStrm == NULL)
	{
		sprintf (err_msg,"Couldn't open %s for input.",inpt);
		cancel = (*err_func)(err_msg);
		return (1);
	}

	/* Open the output file and write the magic number.  BINRW mode
	   creates a new file with read and write access. */
	outStrm = CS_fopen (outp,_STRM_BINRW);
	if (outStrm == NULL)
	{
		sprintf (err_msg,"Couldn't open %s for output.",outp);
		cancel = (*err_func)(err_msg);
		CS_fclose (inStrm);
		return (1);
	}
	if (demo) magic = cs_DTDEF_MAGIC;
	else      magic = cs_DTDEF_MAGIC;
	CS_bswap (&magic,"l");
	wrCnt = CS_fwrite ((char *)&magic,1,sizeof (magic),outStrm);
	if (wrCnt != sizeof (magic))
	{
		sprintf (err_msg,"Failure detected during write to %s.",outp);
		cancel = (*err_func)(err_msg);  
		CS_fclose (outStrm);
		CS_remove (outp);										/*lint !e534 */
		CS_fclose (inStrm);
		return (1);
	}

	/* If we have been given an ellipsoid file name, we open it now. */
	if (elipsoid != NULL && *elipsoid != '\0')
	{
		elStrm = CS_fopen (elipsoid,_STRM_BINRD);
		if (elStrm == NULL)
		{
			sprintf (err_msg,"Couldn't open %s as an Ellipsoid Dictionary.",elipsoid);
			cancel = (*err_func)(err_msg);
			CS_fclose (inStrm);
			return (1);
		}
		rdCnt = CS_fread (&magic,1,sizeof (magic),elStrm);
		CS_bswap (&magic,"l");
		if (rdCnt != sizeof (magic) ||
			(demo && magic != cs_ELDEF_MAGIC) ||
			(!demo && magic != cs_ELDEF_MAGIC))
		{
			sprintf (err_msg,"%s is not an Elipsoid Dictionary file.",elipsoid);
			cancel = (*err_func)(err_msg);
			CS_fclose (inStrm);
			CS_fclose (elStrm);
			return (1);
		}
	}
	else
	{
		elStrm = NULL;
	}

	/* Process each line in the source file. */
	line_nbr = 0;
	err_cnt = 0;
	cancel = FALSE;
	memset (&dtdef,'\0',sizeof (dtdef));
	dtdef.delta_X = no_value;
	dtdef.delta_Y = no_value;
	dtdef.delta_Z = no_value;
	dtdef.rot_X = no_value;
	dtdef.rot_Y = no_value;
	dtdef.rot_Z = no_value;
	dtdef.bwscale = no_value;
	dtdef.to84_via = cs_DTCTYP_NONE;
	while (CS_fgets (buff,sizeof (buff),inStrm) != NULL)
	{
		if (cancel)
		{
			CS_fclose (inStrm);
			CS_fclose (outStrm);
			if (elStrm != NULL) CS_fclose (elStrm);
			CS_remove (outp);										/*lint !e534 */
			return (err_cnt);
		}
		line_nbr += 1;

		/* Ignore comments and blank lines. */
		CS_trim (buff);
		if (buff [0] == '#' || buff [0] == '\0')
		{
			continue;
		}
		cp = buff;
		while ((cp = strchr (cp,'#')) != NULL)
		{
			if (*(cp + 1) != '#' &&
			    *(cp - 1) != '\\')
			{
				*cp = '\0';
				break;
			}
		}

		/* Run the line through the table parser.  We
		   see what type of line we have. */
		cp = buff;
		tp = (struct cs_DtcmpT_ *)CS_tpars (&cp,cs_DtcmpT,sizeof (struct cs_DtcmpT_));

		if (tp == NULL)
		{
			CS_stncp (err_seg,buff,sizeof (err_seg));
			sprintf (err_msg,"Invalid keyword (%s) on line %d.",err_seg,line_nbr);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
			dtdef.key_nm [0] = '\0';
			continue;
		}

		/* Here when we have a valid line. Cp points to the first
		   character after the colon. */
		CS_trim (cp);
		switch (tp->type) {
		case DT_NAME:

			/* Here each time we encounter a new datum
			   name.  We see if there is an existing
			   datum which must be written. */
			if (dtdef.key_nm [0] != '\0' &&		/* Skip 1st one. */
				(test || CS_stricmp (dtdef.group,"TEST")))
			{
				st = CSdtdefwr (outStrm,&dtdef,crypt,warn,elStrm,err_func);
				if (st >= 0) err_cnt += st;
				else
				{
					cancel = TRUE;
					err_cnt += -st;
				}
				
			}

			/* Prepare for the next coordinate system. */
			memset (&dtdef,'\0',sizeof (dtdef));
			dtdef.delta_X = no_value;
			dtdef.delta_Y = no_value;
			dtdef.delta_Z = no_value;
			dtdef.rot_X = no_value;
			dtdef.rot_Y = no_value;
			dtdef.rot_Z = no_value;
			dtdef.bwscale = no_value;
			dtdef.protect = FALSE;
			dtdef.to84_via = cs_DTCTYP_NONE;

			CS_stncp (dtdef.key_nm,cp,sizeof (dtdef.key_nm));
			st = CS_nampp (dtdef.key_nm);
			if (st != 0)
			{
				sprintf (err_msg,"%s is not a valid datum key name; line %d.",cp,line_nbr);
				cancel = (*err_func)(err_msg);
				err_cnt += 1;
			}
			break;

		case DESC_NM:
			if (strlen (cp) >= sizeof (dtdef.name) && warn)
			{
				sprintf (err_msg,"Warning: Description for %s on line %d is too long.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			CS_stncp (dtdef.name,cp,sizeof (dtdef.name));
			break;

		case ELLP_NM:
			CS_stncp (dtdef.ell_knm,cp,sizeof (dtdef.ell_knm));
			break;

		case LOCATION:
			if (strlen (cp) >= sizeof (dtdef.locatn) && warn)
			{
				sprintf (err_msg,"Warning: Country list for %s on line %d is too long.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			CS_stncp (dtdef.locatn,cp,sizeof (dtdef.locatn));
			break;

		case COUNTRY:
			if (strlen (cp) >= sizeof (dtdef.cntry_st) && warn)
			{
				sprintf (err_msg,"Warning: Country list for %s on line %d is too long.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			CS_stncp (dtdef.cntry_st,cp,sizeof (dtdef.cntry_st));
			break;

		case SOURCE:
			if (strlen (cp) >= sizeof (dtdef.source) && warn)
			{
				sprintf (err_msg,"Warning: Source for %s on line %d is too long.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			CS_stncp (dtdef.source,cp,sizeof (dtdef.source));
			break;

		case DELTA_X:
			dtdef.delta_X = atof (cp);
			if (warn && (fabs (dtdef.delta_X) > 2000.0))
			{
				sprintf (err_msg,"Warning: Delta X value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			break;

		case DELTA_Y:
			dtdef.delta_Y = atof (cp);
			if (warn && (fabs (dtdef.delta_Y) > 2000.0))
			{
				sprintf (err_msg,"Warning: Delta Y value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			break;

		case DELTA_Z:
			dtdef.delta_Z = atof (cp);
			if (warn && (fabs (dtdef.delta_Z) > 2000.0))
			{
				sprintf (err_msg,"Warning: Delta Z value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			break;

		case ROT_X:
			dtdef.rot_X = atof (cp);
			if (warn && (fabs (dtdef.rot_X) >= 60.0))
			{
				sprintf (err_msg,"Warning: X Rotation value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}		
			break;

		case ROT_Y:
			dtdef.rot_Y = atof (cp);
			if (warn && (fabs (dtdef.rot_Y) >= 60.0))
			{
				sprintf (err_msg,"Warning: Y Rotation value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}		
			break;

		case ROT_Z:
			dtdef.rot_Z = atof (cp);
			if (warn	 && (fabs (dtdef.rot_Z) >= 60.0))
			{
				sprintf (err_msg,"Warning: Y Rotation value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}		
			break;

		case BWSCALE:
			dtdef.bwscale = atof (cp);
			if (warn && (fabs (dtdef.bwscale) >= 25.0))
			{
				sprintf (err_msg,"Warning: Bursa Wolfe scale value for %s on line %d is suspicious.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}		
			break;

		case USE:
			dtdef.to84_via = cs_DTCTYP_NONE;
			for (typPtr = cs_DtTypeT;typPtr->type != cs_DTCTYP_NONE;typPtr += 1)
			{
				if (!CS_stricmp (cp,typPtr->label))
				{
					dtdef.to84_via = typPtr->type;
					break;
				}
			}
			if (dtdef.to84_via == cs_DTCTYP_NONE)
			{
				sprintf (err_msg,"Invalid 'USE' specification detected on line %d.",line_nbr);
				cancel = (*err_func)(err_msg);
				err_cnt += 1;
			}
			break;

		case GROUP:
			if (strlen (cp) >= sizeof (dtdef.group) && warn)
			{
				sprintf (err_msg,"Warning: Group for %s on line %d is too long.",dtdef.key_nm,line_nbr);
				cancel = (*err_func)(err_msg);
			}
			CS_stncp (dtdef.group,cp,sizeof (dtdef.group));
			break;

		case EPSG_NBR:
			dtdef.epsgNbr = atoi (cp);
			break;

		default:
			sprintf (err_msg,"Software problem detected at line %d in module %s.",__LINE__,__FILE__);
			(void)(*err_func)(err_msg);
			cancel = TRUE;
			break;
		}

		/* On to the next input line. */
	}
	CS_fclose (inStrm);

	/* Write out the last coordinate system if not in error. */
	if (dtdef.key_nm [0] != '\0' && (test || CS_stricmp (dtdef.group,"TEST")))
	{
		st = CSdtdefwr (outStrm,&dtdef,crypt,warn,elStrm,err_func);
		if (st >= 0) err_cnt += st;
		else
		{
			cancel = TRUE;
			err_cnt += -st;
		}
	}
	if (elStrm != NULL) CS_fclose (elStrm);
	if (cancel)
	{
		CS_fclose (outStrm);
		CS_remove (outp);										/*lint !e534 */
		return (err_cnt);
	}

	/* Sort the output file. */
	CS_fseek (outStrm,(long)sizeof (magic),SEEK_SET);
	CS_ips (outStrm,sizeof (dtdef),0L,(CMPFUNC_CAST)CS_dtcmp);		/*lint !e534 */

	/* Verify that there are no duplicates. */
	CS_fseek (outStrm,(long)sizeof (magic),0);
	CS_dtrd (outStrm,&dtdef,&dummy);								/*lint !e534 */
	CS_stncp (last_name,dtdef.key_nm,sizeof (last_name));
	while (!cancel && CS_dtrd (outStrm,&dtdef,&dummy) != 0)
	{
		if (!CS_stricmp (dtdef.key_nm,last_name))
		{
			sprintf (err_msg,"Datum key name %s appears more than once.",last_name);
			cancel = (*err_func)(err_msg);
			err_cnt += 1;
		}
		CS_stncp (last_name,dtdef.key_nm,sizeof (last_name));
	}
	CS_fclose (outStrm);

	/* Remove the output file if there were errors. */
	if (err_cnt != 0)
	{
		CS_remove (outp);										/*lint !e534 */
	}
	return (err_cnt);
}
Пример #27
0
int EXP_LVL3 CScs2WktEx (char *csWktBufr,size_t bufrSize,enum ErcWktFlavor flavor,const struct cs_Csdef_ *cs_def,const struct cs_Dtdef_ *dt_def,const struct cs_Eldef_ *el_def,unsigned short flags)
{
	extern double cs_One;
	extern double cs_K90;
	extern double cs_Degree;
	extern char csErrnam [];
	extern struct cs_Prjtab_ cs_Prjtab [];

	int status;
	short prjCode;

	double tmpDbl;
	double primeMer;
	double unitFactor;

	const char *kCp;
	const char *prjNmPtr;

	const char *prmNmFalseEasting;
	const char *prmNmFalseNorthing;
	const char *prmNmScaleFactor;
	const char *prmNmCentralMeridian;
	const char *prmNmLatitudeOfOrigin;
	const char *prmNmStandardParallel1;
	const char *prmNmStandardParallel2;
	const char *prmNmYAxisAzimuth;
	const char *prmNmAzimuth;
	const char *prmNmLongitudeOfCenter;
	const char *prmNmLatitudeOfCenter;
	const char *prmNmLongitudeOf1stPoint;
	const char *prmNmLatitudeOf1stPoint;
	const char *prmNmLongitudeOf2ndPoint;
	const char *prmNmLatitudeOf2ndPoint;
	const char *prmNmLatitudeOfStdParall;

	struct cs_Dtdef_ *dtDefPtr;
	struct cs_Prjtab_ *prjPtr;

	char refDtmName [24];
	char baseName [24];
	char cTemp [64];

	char datmWkt [512];
	char pmerWkt [512];
	char geogWkt [512];
	char parmWkt [512];
	char unitWkt [128];
	char projWkt [1024];
	char geoAxis [1024];
	char prjAxis [1024];
	char geoTranWkt [1024];
	char projection [64];
	char gcsName [128];
	char dtmName [128];
	char csysWktName [96];
	
	status = 0;
	refDtmName [0] = '\0';
	dtDefPtr = 0;

	if (cs_def == 0)
	{
		CS_stncp (csErrnam,"CS_cs2Wkt:1",MAXPATH);
		CS_erpt (cs_ISER);
		goto error;
	}

	/* Make sure we have a datum pointer. */
	if (dt_def == NULL)
	{
		/* The calling application did not provide a specific datum definition.
		   We use the datum name in the Coordinate System definition to obtain
		   a definition fomr the dictionary. */
		if (cs_def->dat_knm [0] == '\0')
		{
			/* Oops!!! No datum definition in the coordinate system definition.
			   If we were to output something special for a cartographic definition,
			   i.e. a coordinate system referenced directly to an ellipsoid, we
			   would do that here. */
			CS_erpt (cs_NO_REFERNCE);
			goto error;
		}
		
		/* We need to free this definition, we stash it in a new pointer variable. */
		dtDefPtr = CS_dtdef (cs_def->dat_knm);
		if (dtDefPtr == NULL)
		{
			/* If the coordinate system definition came from the dictionary,
			   this shouldn't happen.  If the application got the cs_Csdef_
			   data from somewhere else, it is possible. */
			CS_erpt (cs_NO_REFERNCE);
			goto error;
		}
		dt_def = dtDefPtr;
	}
	
	if (el_def != 0)
	{
		if (CS_stricmp (dt_def->ell_knm,el_def->key_nm))
		{
			CS_erpt (cs_WKT_INCNSIST);
			goto error;
		}
	}

	/* Locate the projection in the projection table.  We need this for access
	   to the flag word for this projection. */
	for (prjPtr = cs_Prjtab;prjPtr->code != cs_PRJCOD_END;prjPtr += 1)
	{
		if (!strcmp (cs_def->prj_knm,prjPtr->key_nm)) break;
	}
	if (prjPtr->code == cs_PRJCOD_END)
	{
		CS_erpt (cs_UNKWN_PROJ);
		goto error;
	}
	prjCode = prjPtr->code;

	prjNmPtr = 0;
	if (prjCode == cs_PRJCOD_SWISS && (flavor == wktFlvrEsri || flavor == wktFlvrOracle))
	{
		prjNmPtr = CSwktPrjCode2Name (cs_PRJCOD_RSKEW,flavor);
	}
	else if (prjCode == cs_PRJCOD_LMTAN)
	{
		prjNmPtr = CSwktPrjCode2Name (cs_PRJCOD_LM1SP,flavor);
	}
	else if (prjPtr->code == cs_PRJCOD_UNITY)
	{
		prjNmPtr = "LL";
	}
	else
	{
		prjNmPtr = CSwktPrjCode2Name (prjCode,flavor);
	}
	if (prjNmPtr == 0 || *prjNmPtr == '\0')
	{
		/* This projection is not supported by this flavor of WKT. */
		CS_stncp (csErrnam,prjPtr->descr,MAXPATH);
		CS_erpt (cs_WKT_PRJSUPRT);
		goto error;
	}

	/* Locate the datum definition, if there is one.  We can't do anything
	   that isn't referenced to a datum. */
	if (dt_def == NULL)										/*lint !e774 */
	{
		/* The calling application did not provide a specific deatum definition.
		   We use the datum name in the Coordinate System definition to obtain
		   a definition fomr the dictionary. */
		if (cs_def->dat_knm [0] == '\0')
		{
			/* Oops!!! No datum definition in the coordinate system definition.
			   If we were to output something special for a cartographic definition,
			   i.e. a coordinate system referenced directly to an ellipsoid, we
			   would do that here. */
			CS_erpt (cs_NO_REFERNCE);	
			goto error;
		}
		dtDefPtr = CS_dtdef (cs_def->dat_knm);
		if (dtDefPtr == NULL)
		{
			/* If the coordinate system definition came from the dictionary,
			   this shouldn't happen.  If the application got the cs_Csdef_
			   data from somewhere else, it is possible. */
			CS_erpt (cs_NO_REFERNCE);
			goto error;
		}
		/* Capture the name of referenced datum which we will be using. */
		CS_stncp (refDtmName,cs_def->dat_knm,sizeof (refDtmName));
		
		/* I don't have to locate the ellipsoid, CSdt2WktEx will do that. */
		status = CSdt2WktEx (datmWkt,sizeof (datmWkt),geoTranWkt,sizeof (geoTranWkt),flavor,dtDefPtr,0,flags);
		CS_free (dtDefPtr);
		dtDefPtr = 0;
	}
	else
	{
		CS_stncp (refDtmName,dt_def->key_nm,sizeof (refDtmName));
		status = CSdt2WktEx (datmWkt,sizeof (datmWkt),geoTranWkt,sizeof (geoTranWkt),flavor,dt_def,el_def,flags);
	}
	if (status != 0)
	{
		/* CSdt2WktEx will have reported the nature of the error. */
		goto error;
	}

	/* Deal with the quad/axis situation. */
	geoAxis [0] = '\0';
	prjAxis [0] = '\0';
	if (cs_def->quad != 0 && cs_def->quad != 1)
	{
		if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0)
		{
			switch (cs_def->quad) {
			default:
			case 0:
			case 1:
				CS_stncp (geoAxis,",AXIS[\"Lon\",EAST],AXIS[\"Lat\",NORTH]",sizeof (prjAxis));
				break;
			case 2:
				CS_stncp (geoAxis,",AXIS[\"Lon\",WEST],AXIS[\"Lat\",NORTH]",sizeof (prjAxis));
				break;
			case 3:
				CS_stncp (geoAxis,",AXIS[\"Lon\",WEST],AXIS[\"Lat\",SOUTH]",sizeof (prjAxis));
				break;
			case 4:
				CS_stncp (geoAxis,",AXIS[\"Lon\",EAST],AXIS[\"Lat\",SOUTH]",sizeof (prjAxis));
				break;
			case -1:
				CS_stncp (geoAxis,",AXIS[\"Lat\",NORTH],AXIS[\"Lon\",EAST]",sizeof (prjAxis));
				break;
			case -2:
				CS_stncp (geoAxis,",AXIS[\"Lat\",NORTH],AXIS[\"Lon\",WEST]",sizeof (prjAxis));
				break;
			case -3:
				CS_stncp (geoAxis,",AXIS[\"Lat\",SOUTH],AXIS[\"Lon\",WEST]",sizeof (prjAxis));
				break;
			case -4:
				CS_stncp (geoAxis,",AXIS[\"Lat\",SOUTH],AXIS[\"Lon\",EAST]",sizeof (prjAxis));
				break;
			}
		}
		else
		{
			switch (cs_def->quad) {
			default:
			case 0:
			case 1:
				CS_stncp (prjAxis,",AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]",sizeof (prjAxis));
				break;
			case 2:
				CS_stncp (prjAxis,",AXIS[\"X\",WEST],AXIS[\"Y\",NORTH]",sizeof (prjAxis));
				break;
			case 3:
				CS_stncp (prjAxis,",AXIS[\"X\",WEST],AXIS[\"Y\",SOUTH]",sizeof (prjAxis));
				break;
			case 4:
				CS_stncp (prjAxis,",AXIS[\"X\",EAST],AXIS[\"Y\",SOUTH]",sizeof (prjAxis));
				break;
			case -1:
				CS_stncp (prjAxis,",AXIS[\"Y\",NORTH],AXIS[\"X\",EAST]",sizeof (prjAxis));
				break;
			case -2:
				CS_stncp (prjAxis,",AXIS[\"Y\",NORTH],AXIS[\"X\",WEST]",sizeof (prjAxis));
				break;
			case -3:
				CS_stncp (prjAxis,",AXIS[\"Y\",SOUTH],AXIS[\"X\",WEST]",sizeof (prjAxis));
				break;
			case -4:
				CS_stncp (prjAxis,",AXIS[\"Y\",SOUTH],AXIS[\"X\",EAST]",sizeof (prjAxis));
				break;
			}
		}
	}

	/* Locate the base.  The base is what this coordinate system is referenced
	   to.  For example, the definition of UTM27-13 defines how to get from
	   LL27 to UTM27-13.  Therefore, LL27 is the base for that coordinate
	   system. */
	if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0)
	{
		/* This is a geographic coordinate system, so the base name is whatever
		   the coordinate system name is. */
		CS_stncp (baseName,cs_def->key_nm,sizeof (baseName));
	}
	else
	{
		/* Otherwise, basename is the name of a geographic coordinate system
		   referenced to the same datum as the projected coordinate system.
		   We have a function which will find this for us.  If we don't
		   have one, we are in trouble. */
		CSllCsFromDt (baseName,sizeof baseName,refDtmName);
		if (!CS_csIsValid (baseName))
		{
			CS_stncp (csErrnam,cs_def->key_nm,MAXPATH);
			CS_erpt (cs_WKT_NOLLBASE);
			return -1;
		}
	}

	/* Manufacture the prime meridian. */
	CS_stncp (pmerWkt,"PRIMEM[\"Greenwich\",0]",sizeof (pmerWkt));
	if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0 && cs_def->org_lng != 0.0)
	{
		int orgLng = (int)cs_def->org_lng;
		switch (orgLng) {
		case 0:
			primeMer = 0.0;
			CS_stncp (pmerWkt,"PRIMEM[\"Greenwich\",0]",sizeof (pmerWkt));
			break;
		case 2:
			primeMer = 2.337229166666667;
			CS_stncp (pmerWkt,"PRIMEM[\"Paris\",2.337229166666667]",sizeof (pmerWkt));
			break;
		case 9:
			primeMer = 9.13190611111111;
			CS_stncp (pmerWkt,"PRIMEM[\"Lisbon\",9.13190611111111]",sizeof (pmerWkt));
			break;
		case -17:
			primeMer = -17.4;
			CS_stncp (pmerWkt,"PRIMEM[\"Ferro\",-17.4]",sizeof (pmerWkt));
			break;
		case -74:
			primeMer = -74.08175;
			CS_stncp (pmerWkt,"PRIMEM[\"Bogota\",-74.08175]",sizeof (pmerWkt));
			break;
		default:
			break;
		}
	}

	/* We will always need the GEOGCS object.  If this is a geographic
	   coordinate system definition, than that's all we'll need.  If this is
	   a Projective coordinate system, the unit is the default for internal
	   coordinates within CS-MAP, namely the degree.  Only if this is a 
	   Geographic Coordinate system, is the actual unit of the definition
	   of importance to us here. */

   	kCp = CSmsiUnitName2WktName ("DEGREE",flavor);
   	if (kCp == 0 || *kCp == '\0')
   	{
		kCp = "Degree";
	}
	sprintf (unitWkt,"UNIT[\"%s\",0.017453292519943295]",kCp);
	if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0)
	{
		/* This is a geographic coordinate system, extract the unit information
		   from the definition. */
	   	kCp = CSmsiUnitName2WktName (cs_def->unit,flavor);
	   	if (kCp == 0)
	   	{
	   		/* Just in case the flavor does not define angular units... */
	   		kCp = "Degree";
			unitFactor = cs_Degree;
	   	}
	   	else
	   	{
			unitFactor = CS_unitlu (cs_UTYP_ANG,cs_def->unit) * cs_Degree;
		}
		sprintf (unitWkt,"UNIT[\"%s\",%.14f]",kCp,unitFactor);
	}
	
	/* If we are mapping names, the GCS name and the Datum name need to be
	   mapped, and then configured for the active flavor.
	   
	   First, we do the default in case anything goes wrong in the mapping
	   process. */
	sprintf (geogWkt,"GEOGCS[\"%s\",%s,%s,%s%s]",baseName,datmWkt,pmerWkt,unitWkt,geoAxis);
	if ((flags & cs_WKTFLG_MAPNAMES) != 0)
	{
		CS_stncp (dtmName,baseName,sizeof (dtmName));
		CS_stncp (gcsName,baseName,sizeof (gcsName));
		if (flavor == wktFlvrEsri)
		{
			kCp = CS_msiDtmName2Esri (dt_def->key_nm,0);
			if (kCp != 0)
			{
				if (*kCp != 'D' || *(kCp + 1) != '_')
				{
					CS_stcpy (dtmName,"D_");
					CS_stncp (&dtmName [2],kCp,sizeof (dtmName) - 2);

					CS_stcpy (gcsName,"GCS_");
					CS_stncp (&gcsName [4],kCp,sizeof (gcsName) - 4);
				}
				else
				{
					CS_stncp (dtmName,kCp,sizeof (dtmName));
					CS_stcpy (gcsName,"GCS_");
					CS_stncp (&gcsName [4],kCp+2,sizeof (gcsName) - 4);
				}
			}
		}
		else if (flavor == wktFlvrOracle)
		{
			kCp = CS_msiDtmName2Oracle (dt_def->key_nm,0);
			if (kCp != 0)
			{
				CS_stncp (dtmName,kCp,sizeof (dtmName));
				if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0)
				{
					sprintf (gcsName,"Longitude / Latitude (%s)",kCp);
				}
				else
				{
					CS_stncp (gcsName,kCp,sizeof (gcsName));
				}
			}
		}
		sprintf (geogWkt,"GEOGCS[\"%s\",%s,%s,%s%s]",gcsName,datmWkt,pmerWkt,unitWkt,geoAxis);
	}

	if ((prjPtr->flags & cs_PRJFLG_GEOGR) != 0)
	{
		/* If this is a geographic coordinate system, we're done. */
		CS_stncp (csWktBufr,geogWkt,(int)bufrSize);
	}
	else
	{
		/* We get here only if the coordinate system is of the projected type. */

		/* Do the linear unit for the projWkt. */
		unitFactor = CS_unitlu (cs_UTYP_LEN,cs_def->unit);
		kCp = CSmsiUnitName2WktName (cs_def->unit,flavor);
		if (kCp == 0 || *kCp == '\0')
		{
			CS_stncp (csErrnam,cs_def->unit,MAXPATH);
			CS_erpt (cs_WKT_UNITMAP);
			return -1;
		}
		sprintf (unitWkt,"UNIT[\"%s\",%.14f]",kCp,unitFactor);

		prmNmFalseEasting        = CSwktPrmEnum2Name (csWktPrmFalseEasting,flavor);
		prmNmFalseNorthing       = CSwktPrmEnum2Name (csWktPrmFalseNorthing,flavor);
		prmNmScaleFactor         = CSwktPrmEnum2Name (csWktPrmScaleAtCenter,flavor);
		prmNmCentralMeridian     = CSwktPrmEnum2Name (csWktPrmLongitudeOfOrg,flavor);
		prmNmLatitudeOfOrigin    = CSwktPrmEnum2Name (csWktPrmLatitudeOfOrg,flavor);
		prmNmStandardParallel1   = CSwktPrmEnum2Name (csWktPrmStdParallel1,flavor);
		prmNmStandardParallel2   = CSwktPrmEnum2Name (csWktPrmStdParallel2,flavor);
		prmNmYAxisAzimuth        = CSwktPrmEnum2Name (csWktPrmYaxisAzimuth,flavor);
		prmNmAzimuth             = CSwktPrmEnum2Name (csWktPrmAzimuth,flavor);
		prmNmLongitudeOfCenter   = CSwktPrmEnum2Name (csWktPrmLongitudeOfCtr,flavor);
		prmNmLatitudeOfCenter    = CSwktPrmEnum2Name (csWktPrmLatitudeOfCtr,flavor);
		prmNmLongitudeOf1stPoint = CSwktPrmEnum2Name (csWktPrmLngFirstPoint,flavor);
		prmNmLatitudeOf1stPoint  = CSwktPrmEnum2Name (csWktPrmLatFirstPoint,flavor);
		prmNmLongitudeOf2ndPoint = CSwktPrmEnum2Name (csWktPrmLngSecondPoint,flavor);
		prmNmLatitudeOf2ndPoint  = CSwktPrmEnum2Name (csWktPrmLatSecondPoint,flavor);
		prmNmLatitudeOfStdParall = CSwktPrmEnum2Name (csWktPrmLatOfStdParall,flavor);

		/* Build the projection and parameter portions of this thing. */ 
		parmWkt [0] = '\0';
		CS_stcpy (projection,prjNmPtr);
		switch (prjCode) {
		case  cs_PRJCOD_TRMER:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_ALBER:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel2,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_MRCAT:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_AZMED:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmYAxisAzimuth,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_PLYCN:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_AZMEA:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmYAxisAzimuth,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_EDCNC:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel2,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_MILLR:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_NZLND:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_SINUS:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_EDCYL:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_VDGRN:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_CSINI:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_ROBIN:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_BONNE:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_EKRT4:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_EKRT6:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_MOLWD:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_PSTRO:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_PSTROSL:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			
			/* Kludge time again.  If the flavor is ESRI, we change the rpojection name based
			   on the origin latitude.  Sorry about that, but this WKT stuff is maddening. */
			if (flavor == wktFlvrEsri)
			{
				if (cs_def->org_lat < -89.0)
				{
					CS_stncp (projection,"Stereographic_South_Pole",sizeof (projection));
				}
				else if (cs_def->org_lat < -89.0)
				{
					CS_stncp (projection,"Stereographic_North_Pole",sizeof (projection));
				}
			}
			break;
		case  cs_PRJCOD_OSTRO:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_LM1SP:
		case  cs_PRJCOD_LMTAN:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_LM2SP:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel1,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmStandardParallel2,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_UTM:
			tmpDbl = 500000.00 / unitFactor;
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,tmpDbl);
			strcat (parmWkt,cTemp);
			tmpDbl = (cs_def->prj_prm2 >= 0.0) ? 0.0 : 10000000.0;
			tmpDbl /= unitFactor;
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,tmpDbl);
			strcat (parmWkt,cTemp);
			tmpDbl = (double)(-183 + (6 * (int)cs_def->prj_prm1)); 				/*lint !e790 */
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,tmpDbl);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",0.9996]",prmNmScaleFactor);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",0.000]",prmNmLatitudeOfOrigin);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_TRMRS:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_HOM1XY:
		case  cs_PRJCOD_RSKEW:
		case  cs_PRJCOD_RSKEWC:
		case  cs_PRJCOD_RSKEWO:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmAzimuth,cs_def->prj_prm3);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLongitudeOfCenter,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfCenter,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_HOM2XY:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLongitudeOf1stPoint,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOf1stPoint,cs_def->prj_prm2);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLongitudeOf2ndPoint,cs_def->prj_prm3);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOf2ndPoint,cs_def->prj_prm4);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfCenter,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_GAUSSK:
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_def->scl_red);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmCentralMeridian,cs_def->prj_prm1);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfOrigin,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		case  cs_PRJCOD_SWISS:
			CS_stncp (projection,prjNmPtr,sizeof (projection));
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseEasting,cs_def->x_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.3f]",prmNmFalseNorthing,cs_def->y_off);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.12f]",prmNmScaleFactor,cs_One);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmAzimuth,cs_K90);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLongitudeOfCenter,cs_def->org_lng);
			strcat (parmWkt,cTemp);
			sprintf (cTemp,",PARAMETER[\"%s\",%.14f]",prmNmLatitudeOfCenter,cs_def->org_lat);
			strcat (parmWkt,cTemp);
			break;
		}												/*lint !e744 */

		/* Need to determine the name we will assign to this definition.  We
		generate a default value which is used if anything else fails. */
		CS_stncp (csysWktName,cs_def->key_nm,sizeof (csysWktName));
		if ((flags & cs_WKTFLG_MAPNAMES) != 0)
		{
			if (flavor == wktFlvrEsri)
			{
				kCp = CS_msiName2Esri (cs_def->key_nm);
				if (kCp != 0)
				{
					CS_stncp (csysWktName,kCp,sizeof (csysWktName));
				}
			}
			else if (flavor == wktFlvrOracle)
			{
				kCp = CS_msiName2Oracle (cs_def->key_nm);
				if (kCp != 0)
				{
					CS_stncp (csysWktName,kCp,sizeof (csysWktName));
				}
			}
		}

		/* Construct the final string. */
		sprintf (projWkt,"PROJCS[\"%s\",%s,PROJECTION[\"%s\"]%s,%s%s]",csysWktName,geogWkt,projection,parmWkt,unitWkt,prjAxis);
		CS_stncp (csWktBufr,projWkt,(int)bufrSize);
	}
	if (dtDefPtr != 0)
	{
		CS_free (dtDefPtr);
	}
	return 0;
error:
	if (dtDefPtr != 0)
	{
		CS_free (dtDefPtr);
	}
	return -1;
}
Пример #28
0
/******************************************************************************
	Constructor: This is a constructor for the "Entry" object.  A linked list
	of these "Entry" objects is underlying structure of the main object.

	NOTE: the specific of handling different file types is handled here.
*/
struct csRgf93ToNtfEntry_* CSnewRgf93ToNtfEntry (struct csDatumCatalogEntry_* catPtr)
{
	extern char cs_DirsepC;
	extern char cs_ExtsepC;
	extern char csErrnam [];

	char *cp;
	struct csRgf93ToNtfEntry_* __This;

	/* Prepare for an error. */
	__This = NULL;

	/* Allocate some storage. */
	__This = (struct csRgf93ToNtfEntry_*) CS_malc (sizeof (struct csRgf93ToNtfEntry_));
	if (__This == NULL)
	{
		CS_erpt (cs_NO_MEM);
		goto error;
	}
	__This->next = NULL;
	__This->type = dtRgf93ToNtfNone;
	__This->pointers.txtDatumPtr = NULL;
	__This->pointers.c2DatumPtr = NULL;         /* Yes, redundant! */

	/* Issue an error if information in the catalog file is
	   inconsistent.  That is, if the extension is not one of the
	   two supported. */
	cp = strrchr (catPtr->pathName,cs_DirsepC);
	if (cp == NULL)
	{
		/* Can't find a path specification in the path name. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_DTC_PATH);
		goto error;
	}
	cp = strchr (cp,cs_ExtsepC);
	if (cp == NULL || strlen (cp) != 4)
	{
		/* Can't find an extension in the file name. */
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_DTC_PATH);
		goto error;
	}
	

	/* Process the entry according to the extension on the file name. */
	cp += 1;                                /* bump past the separator*/
	if (!CS_stricmp (cp,"TXT"))
	{
		/* Construct a text file object.  In the past 10 years, there has only
		   one.  But with htis new implementation (Nov 2008) we supported
		   multiple .txt files as well as multiple .gsb files. */
		__This->pointers.txtDatumPtr = CSnewRgf93ToNtfTxt (catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		__This->type = dtRgf93ToNtfTxt;
	}
	else if (!CS_stricmp (cp,"GSB"))
	{
		/* Construct a Canadian National Transformation Version 2 object. */
		__This->pointers.c2DatumPtr = CSnewDatumShiftCa2 (dtcTypeCanadian2,catPtr->pathName,catPtr->bufferSize,catPtr->flags,catPtr->density);
		if (__This->pointers.c2DatumPtr == NULL)
		{
			goto error;
		}
		__This->type = dtRgf93ToNtfC2;
	}
	else
	{
		CS_stncp (csErrnam,catPtr->pathName,MAXPATH);
		CS_erpt (cs_NAD_EXT);
		goto error;
	}

	/* Return a pointer to t2he 'constructed' entry object. */
	return __This;
error:
	CSdeleteRgf93ToNtfEntry (__This);
	return NULL;
}
Пример #29
0
int CStest1 (bool verbose,bool crypt)
{
	short protectSave;
	char uniqueSave;

	int st;
	int cnt;
	int my_crypt;

	csFILE *elStrm;
	struct tst_lst_ *tp;

	char last_name [48];

	__ALIGNMENT__1			/* Required by some Sun compilers. */
	struct cs_Eldef_ el_def;

	protectSave = cs_Protect;
	uniqueSave = cs_Unique;
	printf ("Testing Ellipsoid Dictionary functions.\n");

	/* Test the Ellipsoid Dictionary manipulation functions
	   by fetching, updating, deleteing, and updating again
	   all the ellipsoids in the test list structure for
	   ellipsoids.  Most of these were all chosen as ellipsoids
	   used in the coordinate calculation test.  Thus, the
	   validity of the results can be tested by using test 4
	   after the completion of this test. */
	tp = el_tst;
	while (tp->name [0] != '\0')
	{
		cs_Protect = protectSave;
		cs_Unique = uniqueSave;

		/* First we fetch the ellipsoid definition. */
		if (verbose)
		{
			printf ("Fetching %s ellipsoid definition.",tp->name);
		}
		tp->el_ptr = CS_eldef (tp->name);
		if (tp->el_ptr == NULL)
		{
			(void)printf ("CS_eldef failed on %s. [%d:%d]\n",tp->name,cs_Error,cs_Errno);
			return (1);
		}
		if (verbose) printf (" OK.\n");

		/* There are two tests.  One with protection on, one with it  off.
		   If this is not a TEST ellipsoid,  then we can only do an update
		   with protection off.  If it is a TEST ellipsoid, we can test
		   with protection on. */
		if (CS_stricmp (tp->el_ptr->group,"teSt"))
		{
			/* Now we put it back in, with protection off. */
			if (verbose)
			{
				printf ("Updating %s ellipsoid definition, protection off.",tp->name);
			}
			cs_Protect = -1;
			st = CS_elupd (tp->el_ptr,crypt);
			if (st != 1)
			{
				(void)printf ("\nCS_elupd failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");

			/* Now we delete it. */
			if (verbose)
			{
				printf ("Deleting %s ellipsoid definition, protection off.",tp->name);
			}
			st = CS_eldel (tp->el_ptr);
			if (st != 0)
			{
				(void)printf ("\nCS_eldel failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
		}
		else
		{
			/* Now we put it back in, with protection on. */
			if (verbose)
			{
				printf ("Updating %s ellipsoid definition, protection on.",tp->name);
			}
			cs_Protect = 10000;						/* Sets protect date 27 years into the future. */
			st = CS_elupd (tp->el_ptr,crypt);
			if (st != 1)
			{
				(void)printf ("\nCS_elupd failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");

			/* Now we delete it. */
			if (verbose)
			{
				printf ("Deleting %s ellipsoid definition, protection on.",tp->name);
			}
			st = CS_eldel (tp->el_ptr);
			if (st != 0)
			{
				(void)printf ("\nCS_eldel failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
				return (1);
			}
			if (verbose) printf (" OK.\n");
		}
		tp++;
	}

	/* Now we put all the deleted ellipsoid definitions back in.
	   This is a test of the add case since they shouldn't be
	   there any more. */
	tp = el_tst;
	while (tp->name [0] != '\0')
	{
		cs_Protect = protectSave;
		cs_Unique = uniqueSave;
		if (verbose)
		{
			printf ("Putting %s ellipsoid definition back in.",tp->name);
		}

		/* I can't really do a prtected test without changeing the name of the
		   definition.  So, we're stuck with testing with protection off. */
		cs_Unique = '\0';
		st = CS_elupd (tp->el_ptr,crypt);
		if (st != 0)
		{
			(void)printf ("\nCS_elupd failed on %s at line %d. [%d:%d]\n",tp->name,(__LINE__-3),cs_Error,cs_Errno);
			return (st);
		}
		if (verbose) printf (" OK.\n");
		CS_free (tp->el_ptr);
		tp++;
	}

	/* Finally, we cruise through the ellipsoid file and verify
	   that all are in sorted order and that there are no
	   duplicates.  */
	if (verbose)
	{
		printf ("Checking order of Ellipsoid Dictionary.\n");
	}
	cnt = 0;
	elStrm = CS_elopn (_STRM_BINRD);
	st = CS_elrd (elStrm,&el_def,&my_crypt);
	CS_stncp (last_name,el_def.key_nm,sizeof (last_name));
	while (CS_elrd (elStrm,&el_def,&my_crypt))
	{
		cnt += 1;
		if (verbose && (cnt % 3) == 0) putchar ('.');
		st = CS_stricmp (last_name,el_def.key_nm);
		if (st > 0)
		{
			printf ("\nEllipsoid Dictionary no longer sorted!!!\n");
			CS_fclose (elStrm);
			return (1);
		}
		else if (st == 0)
		{
			printf ("\nDuplicate entries in Ellipsoid Dictionary!!!\n");
			CS_fclose (elStrm);
			return (1);
		}
	}
	CS_elDictCls (elStrm);
	if (verbose) printf (" OK.\n");
	return (0);
}