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

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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