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

Last change on this file since 134 was 130, checked in by pinsard, 18 years ago

improvements of ReadWrite/?*.pro header

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