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