[Thread Prev][Thread Next][Index]

Re: How to output day of the year out of a netcdf file?



Hi Ansley
       Thanks a lot for your help.
       I figured out a way to calculate day of the year using perl.
Personally it's more convenient than ferret for me because I'm using
ferret as backend application of LAS and therefore I'm using perl
to manipulate the text output from ferret.
       Thanks a lot anyway.
       Cheers, Ding

Ansley Manke wrote:

Hi Ding,
There are functions which will let you list the days, though
it is a little roundabout to get it.

We'll look at these two functions, which relate time to the
default origin of time axes in Ferret. If your time axis has
a different time origin, that is fine.

yes? SHOW FUNCTION DAYS1900TOYMDHMS
DAYS1900TOYMDHMS(day1900)
Convert Julian day to values y,m,d,h,m,s on k=1,...,6
day1900: Julian day counted from 1-jan-1900 (none)

yes? SHOW FUNCTION DATE1900
DATE1900(formatted date)
Convert a date into Julian days since 1-Jan-1900
formatted date: dd-MMM-yy or dd-MMM-yyyy (e.g. "20-Dec-00") (none) (STRING)

! As an example, look at this data, part of the Ferret distribution.
! Use the RETURN keyword to get the time origin and the time units.

yes? USE monthly_navy_winds

yes? SAY `uwnd,RETURN=T0`
!-> MESSAGE/CONTINUE 14-JAN-1980 14:00:00 14-JAN-1980 14:00:00

yes? SAY `uwnd,RETURN=TUNITS`
!-> MESSAGE/CONTINUE hour
hour

! The units are hours, so define a variable dividing the time
! coordinates to represent time in days.

yes? LET tdays = T[GT=time]/24
yes? LIST/L=1:5 tdays
VARIABLE : T[GT=TIME]/24
SUBSET : 5 points (TIME)
16-JAN-1982 / 1: 733.2
16-FEB-1982 / 2: 763.7
18-MAR-1982 / 3: 794.1
18-APR-1982 / 4: 824.6
18-MAY-1982 / 5: 855.0

! List part of the output of the DAYS1900TOYMDHMS function. The
! output is yes, month, day, hour, minute, second for each time, where
! datevar[k=1] is the year, datevar[k=2] is the month, and so on.
! I add DATE1900("`uwnd,RETURN=T0`") so that the argument to
! the function DAYS1900TOYMDHMS is in days since 1-jan-1900.

yes? LET datevar = DAYS1900TOYMDHMS(tdays + DATE1900("`uwnd,RETURN=T0`") )
yes? LIST/l=1:5 datevar
!-> LIST/l=1:5 DAYS1900TOYMDHMS(tdays + DATE1900("14-JAN-1980 14:00:00") )
VARIABLE : DAYS1900TOYMDHMS(TDAYS + DATE1900("14-JAN-1980 14:00:00") )
SUBSET : 6 by 5 points (Z-TIME)
1 2 3 4 5 6 1 2 3 4 5 6
16-JAN-1982 / 1: 1982. 1. 16. 6. 0. 0.
16-FEB-1982 / 2: 1982. 2. 15. 16. 30. 0.
18-MAR-1982 / 3: 1982. 3. 18. 3. 0. 0.
18-APR-1982 / 4: 1982. 4. 17. 13. 30. 0.
18-MAY-1982 / 5: 1982. 5. 18. 0. 0. 0.

!Or, what you wanted, was the fractional day of the year, the
!day, plus hours, minutes, and seconds as a fraction of the day.
!(I have used the backslash continuation character in this long command.


yes? LIST/L=1:5 datevar[k=3] + datevar[k=4]/24 + \
datevar[k=5]/(24*60) + datevar[k=6]/(24*60*60)
VARIABLE : DATEVAR[K=3] + DATEVAR[K=4]/24 + DATEVAR[K=5]/(24*60) + DATEVAR[K=6]/(24*60*60)
SUBSET : 5 points (TIME)
Z : 3
16-JAN-1982 / 1: 16.25
16-FEB-1982 / 2: 15.69
18-MAR-1982 / 3: 18.12
18-APR-1982 / 4: 17.56
18-MAY-1982 / 5: 18.00



Ansley Manke


Chi Ding wrote:

Hi ferret users
I need to output ascii data out of netcdf
files and the time values needs to be in "day of
the year" format, say "221.24".
When I use commands like this
list/clobber/noheader/file="test2.txt"/t="01-JUN-2003":"01-JUL-2003" air_temperature,
the output is like
01-JUN-2003 00:00 / 244: 9.19
01-JUN-2003 01:00 / 245: 8.47
01-JUN-2003 02:00 / 246: 8.33
01-JUN-2003 03:00 / 247: 8.41
01-JUN-2003 04:00 / 248: 8.12
01-JUN-2003 05:00 / 249: 7.75
01-JUN-2003 06:00 / 250: 7.41
01-JUN-2003 07:00 / 251: 7.56
01-JUN-2003 08:00 / 252: 7.44
01-JUN-2003 09:00 / 253: 7.27
01-JUN-2003 10:00 / 254: 7.15
01-JUN-2003 11:00 / 255: 7.27
01-JUN-2003 12:00 / 256: 7.70

I'm wondering how to print the time in day of the year using ferret?
Or is there other way to convert "01-JUN-2003 01:00" to day of the year?
Ferret or other languages are all ok.
Thanks a lot, Ding





[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement