source: trunk/SRC/ReadWrite/ncdf_timeget.pro @ 231

Last change on this file since 231 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1;+
2; @file_comments
3; get the time axis from a netcdf_file and transforms it in
4; Julian days of IDL.
5;
6; @categories
7; Reading
8;
9; @param CDFID {in}{required}
10; the ID of the ncdf_file, which is already open
11;
12; @param TIMEID {in}{required}
13; the ID or the name of the variable which describe the calendar
14;
15; @keyword YYYYMMDD
16; active to obtain the date as a long integer with
17; the format YearYearYearYearMonthMonthDayDay
18;
19; @keyword _EXTRA
20; the keyword parameters of ncdf_varget
21;
22; @returns
23; a long array of IDL Julian days
24;
25; @restrictions
26; the calendar variable must have the units attribute
27; following the syntax bellow:
28;
29; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
30; time_counter:units = "hours since 0001-01-01 00:00:00" ;
31; time_counter:units = "days since 1979-01-01 00:00:00" ;
32; time_counter:units = "months since 1979-01-01 00:00:00" ;
33; time_counter:units = "years since 1979-01-01 00:00:00" ;
34;
35; @history Sebastien Masson (smasson\@lodyc.jussieu.fr)
36;                      June 2001
37; @version $Id$
38;-
39;
40FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _EXTRA = ex
41;
42  compile_opt idl2, strictarrsubs
43;
44
45   insidetime=ncdf_varinq(cdfid,timeid)
46   if insidetime.natts NE 0 then begin
47      attnames = strarr(insidetime.natts)
48      for attiq=0,insidetime.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,timeid,attiq))
49   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
50; reading of the time axis
51   ncdf_varget, cdfid, timeid, time, _extra = ex
52;
53; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
54; time_counter:units = "hours since 0001-01-01 00:00:00" ;
55; time_counter:units = "days since 1979-01-01 00:00:00" ;
56; time_counter:units = "months since 1979-01-01 00:00:00" ;
57; time_counter:units = "years since 1979-01-01 00:00:00" ;
58;
59   if (where(attnames EQ 'units'))[0] NE -1 then begin
60      ncdf_attget,cdfid,timeid,'units',value
61      value = strtrim(strcompress(string(value)), 2)
62      words = str_sep(value, ' ')
63      unite = words[0]
64      start = str_sep(words[2], '-')
65      case strlowcase(unite) of
66         'seconds':time = julday(start[1], start[2], start[0])+time/(long(24)*3600)
67         'hours':time = julday(start[1], start[2], start[0])+time/long(24)
68         'days':time = julday(start[1], start[2], start[0])+time
69         'months':BEGIN
70            for t = 0, n_elements(time)-1  do begin
71               time[t] = julday(start[1]+time[t], start[2], start[0])
72            endfor
73         END
74         'years':BEGIN
75            for t = 0, n_elements(time)-1  do begin
76               time[t] = julday(start[1], start[2], start[0]+time[t])
77            endfor
78         END
79         ELSE:return, report('bad syntax of the units attribut of the variable '+timeid)
80      ENDCASE
81   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
82   if keyword_set(yyyymmdd) then time = jul2date(time)
83   return, time
84end
Note: See TracBrowser for help on using the repository browser.