NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Question about units package...

All,

Below is a snippet of of Perl code that uses UDUNITS to translate a date as it
is stored in our netCDF files to something a human can read.

Digging around in the various examples and docs, I have not been able to figure
out how to do the equivalent using the Java units package.  Can somebody please
provide me with a pointer a specific example or tutorial that covers this?

Thanks,
Roland
-- 
Roland Schweitzer
NOAA-CIRES Climate Diagnostics Center           325 Broadway
NOAA/ERL/CDC - (R/CDC1)                         Boulder, CO 80303
.... (303) 497-6249 .... (303) 497-7013 FAX .... rhs@xxxxxxxxxxxx ....

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#!/usr/bin/perl -w

use UDUNITS;

   UDUNITS::init('');

   $time_units = "hours since 1700-1-1";

   if ( !($unit = UDUNITS::scan("$time_units"))) {
      print STDERR "Having trouble finding the units for time.\n";
      print STDERR "$time_units is not a valid time unit.\n";
      die;
   }

   $udtim = 2298168.0;

   $unit->valtocal($udtim, $yr, $mon, $day,
                           $hour, $min, $sec);


   print "The time units are $time_units\n";
   print "The encoded time $udtim is $yr-$mon-$day $hour:$min:$sec\n";


  • 2000 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: