コード例 #1
0
ファイル: CSdtcomp.c プロジェクト: auranet/csmap
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);
}
コード例 #2
0
ファイル: CStest6.c プロジェクト: asir6/Colt
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);
}
コード例 #3
0
ファイル: CS_dtio.c プロジェクト: auranet/csmap
struct cs_Dtdef_ * EXP_LVL3 CS_dtdef (Const char *dat_nam)
{
    extern char csErrnam [];

    extern double cs_DelMax;		/* 5,000.0 */
    extern double cs_RotMax;		/* 15.0    */
    extern double cs_SclMax;		/* 200.0   */

    int st;
    int flag;
    int crypt;

    csFILE *strm;
    struct cs_Dtdef_ *dtptr;

    __ALIGNMENT__1				/* For some versions of Sun compiler. */

    struct cs_Dtdef_ dtdef;

    /* Prepare for an error condition. */
    dtptr = NULL;
    strm = NULL;

    /* Give the application first shot at satisfying this request. */
    if (CS_usrDtDefPtr != NULL)
    {
        st = (*CS_usrDtDefPtr)(&dtdef,dat_nam);
        if (st < 0) return NULL;
        if (st == 0)
        {
            dtptr = (struct cs_Dtdef_ *)CS_malc (sizeof (struct cs_Dtdef_));
            if (dtptr == NULL)
            {
                CS_erpt (cs_NO_MEM);
                goto error;
            }
            memmove (dtptr,&dtdef,sizeof (*dtptr));
            return dtptr;
        }
    }

    /* Verify the name is OK. */
    CS_stncp (dtdef.key_nm,dat_nam,sizeof (dtdef.key_nm));
    st = CS_nampp (dtdef.key_nm);
    if (st != 0) goto error;

    /* Mark this name as unencrypted so that the comaprison function
       will work. */
    dtdef.fill [0] = '\0';

    /* Open the Datum Dictionary and test its magic number. */
    strm = CS_dtopn (_STRM_BINRD);
    if (strm == NULL) goto error;

    /* Search for the requested datum. */
    flag = CS_bins (strm,(long)sizeof (cs_magic_t),0L,sizeof (dtdef),&dtdef,(CMPFUNC_CAST)CS_dtcmp);
    if (flag < 0) goto error;

    /* Tell the user if we didn't find the requested datum. */
    if (!flag)
    {
        CS_stncp (csErrnam,dat_nam,MAXPATH);
        CS_erpt (cs_DT_NOT_FND);
        goto error;
    }
    else
    {
        /* The datum exists, malloc some memory for it. */
        dtptr = (struct cs_Dtdef_ *)CS_malc (sizeof (*dtptr));
        if (dtptr == NULL)
        {
            CS_erpt (cs_NO_MEM);
            goto error;
        }

        /* Read it in. */
        if (!CS_dtrd (strm,dtptr,&crypt))
        {
            goto error;
        }
    }

    /* We don't need the datum dictionary anymore. */
    if (!cs_DtStrmFlg)
    {
        CS_dtDictCls (strm);
    }
    strm = NULL;

    /* Verify that the values are not completely bogus. */
    if (fabs (dtptr->delta_X) > cs_DelMax ||
            fabs (dtptr->delta_Y) > cs_DelMax ||
            fabs (dtptr->delta_Z) > cs_DelMax ||
            fabs (dtptr->rot_X) > cs_RotMax    ||
            fabs (dtptr->rot_Y) > cs_RotMax    ||
            fabs (dtptr->rot_Z) > cs_RotMax    ||
            fabs (dtptr->bwscale) > cs_SclMax)
    {
        CS_stncp (csErrnam,dat_nam,MAXPATH);
        CS_erpt (cs_DTDEF_INV);
        goto error;
    }

    /* Return the initialized datum structure to the user. */
    return (dtptr);

error:
    if (strm != NULL) CS_dtDictCls (strm);
    if (dtptr != NULL)
    {
        CS_free (dtptr);
        dtptr = NULL;
    }
    return (dtptr);
}
コード例 #4
0
ファイル: CS_japanNew.c プロジェクト: asir6/Colt
/* Given a lat/long, we extract the grid cell which covers the point. */
int CSextractJgd2kGridFile (struct cs_Japan_ *thisPtr,Const double* sourceLL)
{
	extern char csErrnam [];
	extern double cs_Sec2Deg;

	int flag;
	size_t rdCnt;

	long32_t startFP;
	ulong32_t meshCode;
	ulong32_t iLng, iLat;

	double density;
	double swLL [2], seLL [2], neLL [2], nwLL [2];

	struct csJgd2kGridRecord_ srchKey;
	struct csJgd2kGridRecord_ swRec, seRec, neRec, nwRec;

	/* If the cuirrent grid cell objects saved within this object cover
	   the provided point, there is no need to repeat the bulk of this
	   function.  Once a point is converted, it is quite liekly that the
	   sunsequent point is in the same grid cell, so this check usually
	   saves mucho processing time. */
	if (CStestCoverage (&thisPtr->lngCell.coverage,sourceLL) != 0.0)
	{
		/* The longitude cell covers this point.  The latitude cell always
		   covers the exact same cell, no need to waste time checking it.
		   
		   Since we already have the appropriate grid cell available, we're
		   done.  */
		return csGRIDI_ST_OK;
	}

	/* Ok, the provided point is not in the same cell as the last point.  We
	   have lots of work to do; but only if the point provided is within the
	   rectangular region of coverage of the file.  While this check is usually
	   performed prior to calling this function, we repeat it again here as
	   it precludes a lot of overflow and bounds checking below.  Thus, the
	   price of the this additional check is fully paid for. */
	density = CStestCoverage (&thisPtr->coverage,sourceLL);
	if (density == 0.0)
	{
		/* Out of range.  This check eliminates the need for lots of error
		   checking below */
		return csGRIDI_ST_COVERAGE;
	}

	/* Open the binary image file if is isn't open already. */
	if (thisPtr->strm == NULL)
	{
		/* Open the binary file, since it isn't open already. */
		thisPtr->strm = CS_fopen (thisPtr->filePath,_STRM_BINRD);
		if (thisPtr->strm == NULL)
		{
			CS_stncp (csErrnam,thisPtr->filePath,MAXPATH);
			CS_erpt (cs_DTC_FILE);
			return csGRIDI_ST_SYSTEM;
		} 
	}

	/* Note, we don't use a buffer (anymore, we used to).  If bufferSize
	   is not zero, we instuct the OS to use a buffer of the indicated size. */
	if (thisPtr->bufferSize > 128L /*&& thisPtr->dataBuffer == NULL*/)
	{
		setvbuf (thisPtr->strm,NULL,_IOFBF,(size_t)thisPtr->bufferSize);
	}

	/* The first two records in the binary image are the min/max of the file
	   coverage.  Thus, we instruct the binary search function to use the
	   thrid record as the front end of the binary search using the startFP
	   variable. */
	startFP = sizeof (struct csJgd2kGridRecord_) + sizeof (struct csJgd2kGridRecord_);

	/* Locate and read the four corners.  This is quite brutal, but
	   this is the only general way to determine coverage is to see
	   if all four corners of the cell exist.  This is a very specific
	   feature of the Japanese file.  This means that the data file does
	   not need to contain thousands of bogus values covering the
	   Pacific Ocean.  Unlike many other nations, a rectangular coverage
	   region does not work well for Japan.

	   The rather strange nature of this code is the result of our
	   desire to keep all information about the nature of the 'mesh'
	   in the two functions defined above.
	   
	   The sequence which appears immediately below produces the mesh code
	   of the southwest corner of the desired grid cell. */
	meshCode = CSjpnLlToMeshCode (sourceLL);
	if (meshCode == 0UL)
	{
		return csGRIDI_ST_SYSTEM;
	}
	CSjpnMeshCodeToLl (swLL,meshCode);
	iLng = (ulong32_t)CS_degToSec (swLL [0]);
	iLat = (ulong32_t)CS_degToSec (swLL [1]);

	srchKey.meshCode = meshCode;
	flag = CS_bins (thisPtr->strm,startFP,-1L,sizeof (struct csJgd2kGridRecord_),&srchKey,(CMPFUNC_CAST)CScompareJgd2kGridRecord);
	if (flag < 0) return -1;
	if (!flag) return 1;			/* mesh code does not exist in the file, thus no coverage for this point */
	rdCnt = CS_fread (&swRec,1,sizeof (swRec),thisPtr->strm);
	if (rdCnt != sizeof (swRec))
	{
		CS_erpt (cs_IOERR);
		return csGRIDI_ST_SYSTEM;
	}

	/* Now for the southeast corner of the cell. */
	iLng += 45;
	seLL [0] = (double)iLng * cs_Sec2Deg;
	seLL [1] = (double)iLat * cs_Sec2Deg;
	meshCode = CSjpnLlToMeshCode (seLL);
	if (meshCode == 0UL) return -1;
	srchKey.meshCode = meshCode;
	flag = CS_bins (thisPtr->strm,0L,-1L,sizeof (struct csJgd2kGridRecord_),&srchKey,(CMPFUNC_CAST)CScompareJgd2kGridRecord);
	if (flag < 0) return -1;
	if (!flag) return 1;			/* mesh code does not exist in the file, thus no coverage for this point */
	rdCnt = CS_fread (&seRec,1,sizeof (seRec),thisPtr->strm);
	if (rdCnt != sizeof (seRec))
	{
		CS_erpt (cs_IOERR);
		return csGRIDI_ST_SYSTEM;
	}

	/* The northeast corner of the grid cell. */
	iLat += 30;
	neLL [0] = (double)iLng * cs_Sec2Deg;
	neLL [1] = (double)iLat * cs_Sec2Deg;
	meshCode = CSjpnLlToMeshCode (neLL);
	if (meshCode == 0UL) return -1;
	srchKey.meshCode = meshCode;
	flag = CS_bins (thisPtr->strm,0L,-1L,sizeof (struct csJgd2kGridRecord_),&srchKey,(CMPFUNC_CAST)CScompareJgd2kGridRecord);
	if (flag < 0) return -1;
	if (!flag) return 1;			/* mesh code does not exist in the file, thus no coverage for this point */
	rdCnt = CS_fread (&neRec,1,sizeof (neRec),thisPtr->strm);
	if (rdCnt != sizeof (neRec))
	{
		CS_erpt (cs_IOERR);
		return csGRIDI_ST_SYSTEM;
	}

	/* Finally, the northwest corner of the grid cell. */
	iLng -= 45;
	nwLL [0] = (double)iLng * cs_Sec2Deg;
	nwLL [1] = (double)iLat * cs_Sec2Deg;
	meshCode = CSjpnLlToMeshCode (nwLL);
	if (meshCode == 0UL) return -1;
	srchKey.meshCode = meshCode;
	flag = CS_bins (thisPtr->strm,0L,-1L,sizeof (struct csJgd2kGridRecord_),&srchKey,(CMPFUNC_CAST)CScompareJgd2kGridRecord);
	if (flag < 0) return -1;
	if (!flag) return 1;			/* mesh code does not exist in the file, thus no coverage for this point */
	rdCnt = CS_fread (&nwRec,1,sizeof (nwRec),thisPtr->strm);
	if (rdCnt != sizeof (nwRec))
	{
		CS_erpt (cs_IOERR);
		return csGRIDI_ST_SYSTEM;
	}

	/* If we're still here, we have all four corners and finally, at last,
	   know that we have coverage for the provided point. */

	/* Populate the two cell structures involved.  Note that these cells have their
	   own rather general coverage structures.  Thus, on the next transformation
	   involving this object, we can quickly determine if the new point is in the same
	   cell as the last point (quite likely), and all of the above can be skipped.  */
	CSsetCoverage (&thisPtr->lngCell.coverage,swLL,neLL);
	thisPtr->lngCell.coverage.density = thisPtr->ewDelta;
	thisPtr->lngCell.currentAA = (double)swRec.deltaLng / 100000.0;
	thisPtr->lngCell.currentBB = (double)(seRec.deltaLng - swRec.deltaLng) / 100000.0;
	thisPtr->lngCell.currentCC = (double)(nwRec.deltaLng - swRec.deltaLng) / 100000.0;
	thisPtr->lngCell.currentDD = (double)(swRec.deltaLng - seRec.deltaLng - nwRec.deltaLng + neRec.deltaLng) / 100000.0;

	CSsetCoverage (&thisPtr->latCell.coverage,swLL,neLL);
	thisPtr->latCell.coverage.density = thisPtr->nsDelta;
	thisPtr->latCell.currentAA = (double)swRec.deltaLat / 100000.0;
	thisPtr->latCell.currentBB = (double)(seRec.deltaLat - swRec.deltaLat) / 100000.0;
	thisPtr->latCell.currentCC = (double)(nwRec.deltaLat - swRec.deltaLat) / 100000.0;
	thisPtr->latCell.currentDD = (double)(swRec.deltaLat - seRec.deltaLat - nwRec.deltaLat + neRec.deltaLat) / 100000.0;

	/* Identify the source of data for the grid cell. */
	CS_stncp (thisPtr->lngCell.sourceId,thisPtr->fileName,sizeof (thisPtr->lngCell.sourceId));
	CS_stncp (thisPtr->latCell.sourceId,thisPtr->fileName,sizeof (thisPtr->lngCell.sourceId));

	/* We're done, some one else does the actual calculation. */
	return csGRIDI_ST_OK;
}
コード例 #5
0
ファイル: CS_dtio.c プロジェクト: auranet/csmap
int EXP_LVL3 CS_dtupd (struct cs_Dtdef_ *dtdef,int crypt)
{
    extern char csErrnam [];
    extern short cs_Protect;
    extern char cs_Unique;

    short cs_time;

    int st;
    int flag;
    int dummy;

    csFILE *strm;

    long fpos;

    char *cp;

    __ALIGNMENT__1		/* For some versions of Sun compiler. */

    struct cs_Dtdef_ my_dtdef;

    /* Capture the current time. For our purposes here, time is
       the number of days since (approx) January 1, 1990. If this
       record does get written, the protect field will indicate
       that it has changed. */

    cs_time = (short)((CS_time ((cs_Time_ *)0) - 630720000L) / 86400L);
    if (dtdef->protect >= 0)
    {
        dtdef->protect = cs_time;
    }

    /* Prepare for a possible error. */
    strm = NULL;

    /* Adjust the name and make sure it is all upper
       case.  By convention, datum names are case
       insensitive. */
    st = CS_nampp (dtdef->key_nm);
    if (st != 0) goto error;

    /* Open up the Datum Dictionary and verify its magic number. */
    strm = CS_dtopn (_STRM_BINUP);
    if (strm == NULL)
    {
        goto error;
    }

    /* See if we have a datum with this name already. */
    flag = CS_bins (strm,(long)sizeof (cs_magic_t),0L,sizeof (*dtdef),
                    (char *)dtdef,(CMPFUNC_CAST)CS_dtcmp);
    if (flag < 0) goto error;
    if (flag)
    {
        /* Here when the datum already exists. See if we are
           allowed to change this definition. */
        if (cs_Protect >= 0)
        {
            /* Distribution protection is enabled. */
            fpos = CS_ftell (strm);
            if (fpos < 0L)
            {
                CS_erpt (cs_IOERR);
                goto error;
            }
            st = CS_dtrd (strm,&my_dtdef,&dummy);
            if (st == 0) CS_erpt (cs_INV_FILE);
            if (st <= 0)
            {
                goto error;
            }

            if (my_dtdef.protect == 1)
            {
                CS_stncp (csErrnam,dtdef->key_nm,MAXPATH);
                CS_erpt (cs_DT_PROT);
                goto error;
            }
            if (cs_Protect > 0 && my_dtdef.protect > 0)
            {
                if (my_dtdef.protect < (cs_time - cs_Protect))		/*lint !e644 */
                {
                    CS_stncp (csErrnam,dtdef->key_nm,MAXPATH);
                    CS_erpt (cs_DT_UPROT);
                    goto error;
                }
            }
            st  = CS_fseek (strm,fpos,SEEK_SET);
            if (st < 0L)
            {
                CS_erpt (cs_IOERR);
                goto error;
            }
        }

        /* If we're still here, it's OK to update this definition. */
        if (CS_dtwr (strm,dtdef,crypt))
        {
            goto error;
        }
    }
    else
    {
        /* Here if the datum definition doesn't exist.  We
           have to add it. If cs_Unique is not zero, we
           require that a cs_Unique character be present
           in the key name before we'll allow it to be
           written. */
        if (cs_Unique != '\0')
        {
            cp = strchr (dtdef->key_nm,cs_Unique);
            if (cp == NULL)
            {
                csErrnam [0] = cs_Unique;
                csErrnam [1] = '\0';
                CS_erpt (cs_UNIQUE);
                goto error;
            }
        }

        /* Now we can add it. Write to the end of the file, and then
           sort the file. */
        st = CS_fseek (strm,0L,SEEK_END);
        if (st != 0)
        {
            CS_erpt (cs_IOERR);
            goto error;
        }
        if (CS_dtwr (strm,dtdef,crypt))
        {
            goto error;
        }

        /* Sort the file into proper order, thereby
           moving the new datum to its proper place
           in the dictionary. */
        st = CS_fseek (strm,(long)sizeof (cs_magic_t),SEEK_SET);
        if (st != 0)
        {
            CS_erpt (cs_IOERR);
            goto error;
        }
        st = CS_ips (strm,sizeof (*dtdef),0L,(CMPFUNC_CAST)CS_dtcmp);
        if (st < 0) goto error;
    }

    /* The Datum Dictionary has been updated. */
    CS_dtDictCls (strm);
    return (flag);

error:
    if (strm != NULL) CS_dtDictCls (strm);
    return (-1);
}