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

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