;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: ncdf_timeget ; ; PURPOSE: get the time axis fom a netcdf_file and transforms it in ; julian days of UDL. ; ; CATEGORY: reading ncdf_file ; ; CALLING SEQUENCE: time = ncdf_timeget(cdfid, timeid) ; ; INPUTS:cdfid: the ID of the ncdf_file, which is already open ; timeid: the ID or the name of the variable which describe the calendar ; ; KEYWORD PARAMETERS: ; /YYYYMMDD: active to obtain the date as a longinterger with ; the format YearYearYearYearMonthMonthDayDay ; ; the keyword parameters of ncdf_varget ; ; OUTPUTS:a long array of IDL julian days ; ; COMMON BLOCKS: ; ; SIDE EFFECTS: ; ; RESTRICTIONS: the calendar variable must have the units attribute ; folowing the syntaxe 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" ; ; ; EXAMPLE: ; ; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr) ; June 2001 ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ FUNCTION ncdf_timeget, cdfid, timeid, YYYYMMDD = yyyymmdd, _extra = ex 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 = vairdate(time) return, time end