Re: Time

Steve Emmerson (steve@unidata.ucar.edu)
Thu, 13 Jan 1994 11:04:10 -0700

>Date: Thu, 13 Jan 1994 11:04:32 -0500 (EST)
>From: PEPKE@scri.fsu.edu
>To: netcdfgroup@unidata.ucar.edu
>Subject: Time

In the above message you wrote:

>I have a problem with time. I have netCDF and the udunits packages. I want to
>be able to write time-dependent meteorological datasets where the time is
>hours, minutes, and seconds, either local or Zulu time.
>
>I would like to do this, satisfying these conditions:
>
>A) I would like to do it in a standard, de facto standard, or quasistandard
>way.
>
>B) I would like my visualization program to be able to figure out, just by
>looking at the file without my having to press buttons, that the time should be
>displayed as hh:mm:ss.

I would store the times in a netCDF `double' variable with a unit
attribute something like "seconds since 1993-12-15 00:00 UTC". I'd then
interpret and display the netCDF file in something like the following
manner:

#include <udunits.h>
...

char string[128]; /* value & units print-buffer */
utUnit unit; /* input units */
double value; /* input value */
...
if (utIsTime(unit))
{
/*
* We're dealing with a temporal unit.
*/
int year, month, day, hour, minute;
float second;

(void) utCalendar(value, unit, &year, &month, &day, &hour,
&minute, &second);
(void) sprintf(string, "%d-%d-%d %d:%d:%d UTC", year, month,
day, hour, minute, (int)second);
}
else
{
/*
* We're dealing with a non-temporal unit.
*/
(void) sprintf(string, "%g ", value);
(void) utPrint(unit, string + strlen(string));
}

>Also, is there such a thing as a udunits document?

Yes. It's the manual page in the UDUNITS package.

--------
Steve Emmerson <steve@unidata.ucar.edu>