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

Last change on this file since 107 was 106, checked in by pinsard, 18 years ago

start to modify headers of ReadWrite? *.pro files for better idldoc output

  • 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   insidetime=ncdf_varinq(cdfid,timeid)
38   if insidetime.natts NE 0 then begin
39      attnames = strarr(insidetime.natts)
40      for attiq=0,insidetime.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,timeid,attiq))
41   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
42; reading of the time axis
43   ncdf_varget, cdfid, timeid, time, _extra = ex
44;
45; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
46; time_counter:units = "hours since 0001-01-01 00:00:00" ;
47; time_counter:units = "days since 1979-01-01 00:00:00" ;
48; time_counter:units = "months since 1979-01-01 00:00:00" ;
49; time_counter:units = "years since 1979-01-01 00:00:00" ;
50;
51   if (where(attnames EQ 'units'))[0] NE -1 then begin
52      ncdf_attget,cdfid,timeid,'units',value
53      value = strtrim(strcompress(string(value)), 2)
54      words = str_sep(value, ' ')
55      unite = words[0]
56      start = str_sep(words[2], '-')
57      case strlowcase(unite) of
58         'seconds':time = julday(start[1], start[2], start[0])+time/(long(24)*3600)
59         'hours':time = julday(start[1], start[2], start[0])+time/long(24)
60         'days':time = julday(start[1], start[2], start[0])+time
61         'months':BEGIN
62            for t = 0, n_elements(time)-1  do begin
63               time[t] = julday(start[1]+time[t], start[2], start[0])
64            endfor
65         END
66         'years':BEGIN
67            for t = 0, n_elements(time)-1  do begin
68               time[t] = julday(start[1], start[2], start[0]+time[t])
69            endfor
70         END
71         ELSE:return, report('bad syntax of the units attribut of the variable '+timeid)
72      ENDCASE
73   ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut')
74   if keyword_set(yyyymmdd) then time = jul2date(time)
75   return, time
76end
Note: See TracBrowser for help on using the repository browser.