This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Rosalyn,
> The units of a netcdf(CF) time variable must contain a reference time.
>
> E.g units = "days since 1970-01-01 00:00:00" [ Valid time units and
> reference time]
> utScan told me this was a valid unit and I used utCalendar to convert it
> into a UTC-referenced time. If conversion is successful it tells me the
> reference time was ok.
>
> E.g units="days" [Valid time units, but invalid/no reference time]
> utScan validates the time unit, but since there is no reference time,
> utCalendar fails indicating invalid/no reference time.
>
> So I'm hoping there is another way to do this in UDUNITS2?
Piece of cake. Just test if the "unit" in question is convertible with a known
timestamp "unit". For example:
#include <udunits2.h>
...
ut_system* system = ut_read_xml(NULL);
ut_unit* secsSinceEpoch = ut_parse(system, "seconds since 1970-01-01",
UT_ASCII);
...
ut_unit* testUnit = ...;
if (!ut_are_convertible(secsSinceEpoch, testUnit)) {
/* "testUnit" isn't a timestamp-unit */
}
else {
...
}
And Happy New Year!
> Thanks.
>
> Regards,
> Rosalyn.
> ------------------------------------------------------------------------
> Rosalyn Hatcher
> NCAS Computational Modelling Services
> Dept. of Meteorology, University of Reading,
> Earley Gate, Reading. RG6 6BB
> Email: address@hidden Tel: +44 (0) 118 378 6016
Regards,
Steve Emmerson
Ticket Details
===================
Ticket ID: CVV-877033
Department: Support UDUNITS
Priority: Normal
Status: Closed