[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
[130] | 5 | ; @file_comments |
---|
[136] | 6 | ; get the time axis from a netcdf_file and transforms it in |
---|
| 7 | ; Julian days of IDL. |
---|
[2] | 8 | ; |
---|
[157] | 9 | ; @categories |
---|
| 10 | ; Reading |
---|
[2] | 11 | ; |
---|
[163] | 12 | ; @param CDFID {in}{required} |
---|
[130] | 13 | ; the ID of the ncdf_file, which is already open |
---|
[2] | 14 | ; |
---|
[163] | 15 | ; @param TIMEID {in}{required} |
---|
[130] | 16 | ; the ID or the name of the variable which describe the calendar |
---|
[2] | 17 | ; |
---|
[130] | 18 | ; @keyword YYYYMMDD |
---|
[136] | 19 | ; active to obtain the date as a long integer with |
---|
[130] | 20 | ; the format YearYearYearYearMonthMonthDayDay |
---|
[2] | 21 | ; |
---|
[130] | 22 | ; @keyword _EXTRA |
---|
| 23 | ; the keyword parameters of ncdf_varget |
---|
[2] | 24 | ; |
---|
[130] | 25 | ; @returns |
---|
[136] | 26 | ; a long array of IDL Julian days |
---|
[130] | 27 | ; |
---|
| 28 | ; @restrictions |
---|
| 29 | ; the calendar variable must have the units attribute |
---|
[136] | 30 | ; following the syntax bellow: |
---|
[2] | 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 | ; |
---|
[106] | 38 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 39 | ; June 2001 |
---|
[130] | 40 | ; @version $Id$ |
---|
[2] | 41 | ;- |
---|
| 42 | ;------------------------------------------------------------ |
---|
| 43 | ;------------------------------------------------------------ |
---|
| 44 | ;------------------------------------------------------------ |
---|
[130] | 45 | FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _EXTRA = ex |
---|
[114] | 46 | ; |
---|
| 47 | compile_opt idl2, strictarrsubs |
---|
| 48 | ; |
---|
[2] | 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 |
---|
[130] | 74 | 'months':BEGIN |
---|
[2] | 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') |
---|
[44] | 87 | if keyword_set(yyyymmdd) then time = jul2date(time) |
---|
[2] | 88 | return, time |
---|
| 89 | end |
---|