예제 #1
0
/*==========================================================================================
 * The user specified some origin to the time units. For example, if the units string
 * were "days since 2005-10-15", then the origin date is 2005-10-15.  This routine
 * deduces the specified origin date from the passed units structure 
 */
static void get_origin( ut_unit *dataunits, int *y0, int *mon0, int *d0, int *h0, int *min0, double *s0 )
{
	double		s0lib, rez, tval, tval_conv, resolution;
	cv_converter	*conv_user_date_to_ref_date;
	ut_unit		*tmpu;
	int		y0lib, mon0lib, d0lib, h0lib, min0lib;
	char		ustr[1024];

	static ut_unit 	*udu_ref_date=NULL;	/* Saved between invocations */

	if( udu_ref_date == NULL ) {

		/* Make a timestamp units that refers to the udunits2 library's intrinsic
		 * time origin.  The first thing we do is parse a timestampe unit
		 * (any old timestamp unit) and immediately discard the result, to account
		 * for a bug in the udunits-2 library that fails to set the library's
		 * time origin unless this step is done first.  Without this, a call to
		 * ut_decode_time with tval==0 returns year=-4713 rather than 2001.
		 */
		if( (tmpu = ut_parse( ut_get_system(dataunits), "days since 2010-01-09", UT_ASCII )) == NULL ) {
			fprintf( stderr, "Internal error in routnie utCalendar2/get_origin: failed to parse temp timestamp string\n" );
			exit(-1);
			}
		ut_free( tmpu );

		tval = 0.0;
		ut_decode_time( tval, &y0lib, &mon0lib, &d0lib, &h0lib, &min0lib, &s0lib, &rez );
		sprintf( ustr, "seconds since %04d-%02d-%02d %02d:%02d:%f",
			y0lib, mon0lib, d0lib, h0lib, min0lib, s0lib );
		udu_ref_date = ut_parse( ut_get_system(dataunits), ustr, UT_ASCII );
		if( udu_ref_date == NULL ) {	
			fprintf( stderr, "internal error in routine utCalendar2/get_origin: could not parse origin string \"%s\"\n",
				ustr );
			exit(-1);
			}
		}

	/* Get converter from passed units to the library's intrinsic time units */
	conv_user_date_to_ref_date = ut_get_converter( dataunits, udu_ref_date );

	/* convert tval=0 to ref date */
	tval = 0.0;
	tval_conv = cv_convert_double( conv_user_date_to_ref_date, tval );

	/* Now decode the converted value */
	ut_decode_time( tval_conv, y0, mon0, d0, h0, min0, s0, &resolution );

	cv_free( conv_user_date_to_ref_date );
}
예제 #2
0
/*
 * Convert a temporal value into a UTC Gregorian date and time.
 */
int
utCalendar(
    double		value,
    const utUnit	*unit,
    int			*year,
    int			*month,
    int			*day,
    int			*hour,
    int			*minute,
    float		*second)
{
    int		status = 0;	/* success */

    cv_converter* converter = ut_get_converter(unit->unit2, encodedTimeUnit);
    if (converter == NULL) {
	status = encodedTimeUnit == NULL ? UT_ENOINIT : UT_EINVALID;
    }
    else {
	double	encodedTime = cv_convert_double(converter, value);
	double	sec, res;

	ut_decode_time(encodedTime, year, month, day, hour, minute, &sec, &res);
	*second = (float)sec;
	cv_free(converter);
    }
    return status;
}
예제 #3
0
파일: NFtime.c 프로젝트: bmfekete/nFrames
bool NFtimeSetFromVariable(NFtime_p timePtr, double variable) {
    int year;
    int month;
    int day;
    int hour;
    int minute;
    double second, resolution;

    ut_decode_time(variable, &year, &month, &day, &hour, &minute, &second, &resolution);
    return (NFtimeSet(timePtr, year, month, day, hour, minute));
}