source: trunk/LECTURE/ncdf_timeget.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME: ncdf_timeget
6;
7; PURPOSE: get the time axis fom a netcdf_file and transforms it in
8; julian days of UDL.
9;
10; CATEGORY: reading ncdf_file
11;
12; CALLING SEQUENCE: time = ncdf_timeget(cdfid, timeid)
13;
14; INPUTS:cdfid: the ID of the ncdf_file, which is already open
15;        timeid: the ID or the name of the variable which describe the calendar
16;
17; KEYWORD PARAMETERS:
18;        /YYYYMMDD: active to obtain the date as a longinterger with
19;        the format YearYearYearYearMonthMonthDayDay
20;
21;        the keyword parameters of ncdf_varget
22;
23; OUTPUTS:a long array of IDL julian days
24;
25; COMMON BLOCKS:
26;
27; SIDE EFFECTS:
28;
29; RESTRICTIONS: the calendar variable must have the units attribute
30; folowing the syntaxe bellow:
31;
32; time_counter:units = "seconds since 0001-01-01 00:00:00" ;
33; time_counter:units = "hours since 0001-01-01 00:00:00" ;
34; time_counter:units = "days since 1979-01-01 00:00:00" ;
35; time_counter:units = "months since 1979-01-01 00:00:00" ;
36; time_counter:units = "years since 1979-01-01 00:00:00" ;
37;
38; EXAMPLE:
39;
40; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
41;                      June 2001
42;-
43;------------------------------------------------------------
44;------------------------------------------------------------
45;------------------------------------------------------------
46FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _extra = ex
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 = vairdate(time)
86   return, time
87end
Note: See TracBrowser for help on using the repository browser.