;+ ; ; @file_comments ; get the time axis from a netcdf_file and transforms it in ; Julian days of IDL. ; ; @categories ; Reading ; ; @param CDFID {in}{required} ; the ID of the ncdf_file, which is already open ; ; @param TIMEID {in}{required} ; the ID or the name of the variable which describe the calendar ; ; @keyword YYYYMMDD ; active to obtain the date as a long integer with ; the format YearYearYearYearMonthMonthDayDay ; ; @keyword _EXTRA ; the keyword parameters of ncdf_varget ; ; @returns ; a long array of IDL Julian days ; ; @restrictions ; the calendar variable must have the units attribute ; following the syntax bellow: ; ; time_counter:units = "seconds since 0001-01-01 00:00:00" ; ; time_counter:units = "hours since 0001-01-01 00:00:00" ; ; time_counter:units = "days since 1979-01-01 00:00:00" ; ; time_counter:units = "months since 1979-01-01 00:00:00" ; ; time_counter:units = "years since 1979-01-01 00:00:00" ; ; ; @history ; Sebastien Masson (smasson\@lodyc.jussieu.fr) ; June 2001 ; @version ; $Id$ ;- ; FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _EXTRA = ex ; compile_opt idl2, strictarrsubs ; insidetime=ncdf_varinq(cdfid,timeid) if insidetime.natts NE 0 then begin attnames = strarr(insidetime.natts) for attiq=0,insidetime.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,timeid,attiq)) ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut') ; reading of the time axis ncdf_varget, cdfid, timeid, time, _extra = ex ; ; time_counter:units = "seconds since 0001-01-01 00:00:00" ; ; time_counter:units = "hours since 0001-01-01 00:00:00" ; ; time_counter:units = "days since 1979-01-01 00:00:00" ; ; time_counter:units = "months since 1979-01-01 00:00:00" ; ; time_counter:units = "years since 1979-01-01 00:00:00" ; ; if (where(attnames EQ 'units'))[0] NE -1 then begin ncdf_attget,cdfid,timeid,'units',value value = strtrim(strcompress(string(value)), 2) words = str_sep(value, ' ') unite = words[0] start = str_sep(words[2], '-') case strlowcase(unite) of 'seconds':time = julday(start[1], start[2], start[0])+time/(long(24)*3600) 'hours':time = julday(start[1], start[2], start[0])+time/long(24) 'days':time = julday(start[1], start[2], start[0])+time 'months':BEGIN for t = 0, n_elements(time)-1 do begin time[t] = julday(start[1]+time[t], start[2], start[0]) endfor END 'years':BEGIN for t = 0, n_elements(time)-1 do begin time[t] = julday(start[1], start[2], start[0]+time[t]) endfor END ELSE:return, report('bad syntax of the units attribut of the variable '+timeid) ENDCASE ENDIF ELSE return, report('the variable '+timeid+' must have the units attribut') if keyword_set(yyyymmdd) then time = jul2date(time) return, time end