; $Header: /science/nmc/met_fields/programs/nmcr3d.pro,v 1.24 2004/11/10 22:02:25 nash Exp $ function nmcr3d,directory,quantity,source,date,data,badval,ndat, $ avespec=avespec,d2list=d2list,forecast=forecast,format=format, $ gridspec=gridspec,sequence=sequence,special=special, $ date_list=date_list,fcst_list=fcst_list, $ audit=audit,avals3=avals3,avinfo=avinfo,cal=cal,comment=comment, $ dim_quantity=dim_quantity,dim_unit=dim_unit,dim0_value=dim0_value, $ dim1_value=dim1_value,dim2_value=dim2_value,fname=fname,info=info, $ sup1=sup1,unit=unit,version=version ;+ ; NAME: ; nmcr3d ; PURPOSE: ; Reads in data from the df 3-D gridded files. ; CATEGORY: ; df ; CALLING SEQUENCE: ; result = nmcr3d (directory, quantity, source, date ,dat, badval, ndat) ; FUNCTION RETURN VALUE: ; integer: scalar ; Function returns zero if there were no erros, non-zero otherwise ; INPUT PARAMETERS: ; directory = (string) directory where data file resides ; quantity = (string) 4-chartacter quantity code string ; (number) numerical quantity code ; source = (string) 3-character source code ; (number) numerical source code ; date = (string or long) The date for the file name in the format yymmddhh ; OPTIONAL INPUT PARAMETERS: ; INPUT/OUTPUT PARAMETERS: ; OPTIONAL INPUT/OUTPUT PARAMETERS: ; OUTPUT PARAMETERS: ; data = (float array) data read from the file. Will be dimensioned as 'ndat' ; badval = (float) value of missing or bad data ; ndat = (long array) number of grid points along each dimension of 'dat'. ; Dimensioned [3] or [4] ; OPTIONAL OUTPUT PARAMETERS: ; INPUT KEYWORDS: ; avespec = (string) The time average code string. Defaults to 'I' for ; instantaneous. Note that this is the one letter code in the file ; name and not the codes as specified in nmcw3d ; d2list = (long array) list of indices into the 3rd index (usually pressure ; or heights ; forecast = (string) forecast time code string. Default is no forecast. If ; the file contains multiple forecasts, specify as 'FHXX' ; (integer) number of hours of the forecast lead-time. Default is ; no forecast. 'FH' will be prefixed to the value ; format = (string) format code. Defaults to 'X' for xdr format ; gridspec = (string) grid code string. Default is no gridding ; sequence = (string) The sequence code string. Default is no sequence code ; 'E' will be prefixed to the string ; (integer) The sequence number. Default is no sequence number. ; 'E' will be prefixed to the number ; special = (string) special code string. 'S' will be prefixed to the string. ; Default is no special code ; INPUT/OUTPUT KEYWORDS: ; date_list = (long array) ; INPUT: dates wanted in form yymmdd or yymmddhh ; OUTPUT: dates found in form yymmdd or yymmddhh ; fcst_list = (long array) forecasts wanted ; INPUT: forecasts wanted ; OUTPUT: forecasts found ; OUTPUT KEYWORDS: ; audit = (structure: Audit_type) audit trail ; avals3 = (any) values of any Level 3 dimensions ; avinfo = (lonarr [3]) The first element is the quantity code of the Level 3 ; dimension. The second element is the unit of the Level 3 ; dimension. The third element is averaging code (AVGCOD) of the ; Level 3 dimension ; cal= (long) calendar type: ; 0: GREGORIAN, 100: MODEL365 ; comment = (string array) comments from the COMMENT record ; dim_quantity = (long array [3]) numerical quantity codes of the dimensions ; dim_unit = (long array [3]) numerical unit codes of the dimensions ; dim0_value = (any array [ndat[0]]) grid points along the first dimension ; dim1_value = (any array [ndat[1]]) grid points along the second dimension ; dim2_value = (any array [ndat[2]]) grid points along the third dimension ; fname = (string) df file name ; info = (bytarr) bytes from the INFO record ; sup1 = (any array) suplemental info for the 3rd dimension (height, $ ; pressure, etc). ; unit = (long) quantity unit code ; version = (any) data version number or string ; COMMON BLOCKS: ; REQUIRED ROUTINES: ; @ FILES: ; RESTRICTIONS: ; Many - This assumes a 3-d spacial array with time as the fourth dimension. ; - Each dimension has only one quantity specification. ; SIDE EFFECTS: ; DIAGNOSTIC INFORMATION: ; PROCEDURE: ; EXAMPLES: ; REFERENCE: ; FURTHER INFORMATION: ; RELATED FUNCTIONS AND PROCEDURES: ; MODIFICATION HISTORY: ; $Log: nmcr3d.pro,v $ ; Revision 1.24 2004/11/10 22:02:25 nash ; now handles multiple version strings ; ; 1991-06-10:nash:written ; 1991-08-02:nash:fixed bug in call to dfget_proc (added nprocs) ; 1991-09-05:nash:major revision: Added multiple forecasts and dates, calls ; to new df routines, faster code. ; 1991-09-17:nash:added code for pulling off particular level 1 elements. ; This allows for the specification of particular heights. ; 1991-11-15:nash:added pakcode in df_unpkdata call ; 1992-03-03:nash:change in dfget_pack returns double precision values ; 1992-08-28:nash:dfget_pack returns string, added version, fixed minor bugs ; 1993-12-08:nash:added Level3 processing stuff; restructuring for efficiency ; 1994-02-07:nash:added comment processing ; 1994-03-16:nash:add format code specification, rearranged keywords ; 1995-10-17:nash:changed unpacking; uses less memory, but is slightly slower ; 2002-04-02:nash:complete rewrite: use dfread_grids; added calendar handling ; 2002-04-05:nash:reform the data to cut off trailing dimesnions of 1 ;- ; *****Initialize dfhead,/xdr,consts=const fdesc = {fdesc} ; *****get the variable codes q4 = quantity vartype = quantity df_trans_var,num=vartype,short=q4,err=res,direct=(size(quantity,/type) eq 7) if (temporary(res) eq 1) then begin message,/continue,'Unknown variable type: '+strcompress(quantity,/rem) return,1 endif ; *****get the source codes src3 = source isourc = source df_trans_source,num=temporary(isourc),short=src3,err=res, $ direct=(size(source,/type) eq 7) if (temporary(res) eq 1) then begin message,/continue,'Unknown source: '+strcompress(source,/rem) return,1 endif ; *****get the file name fname = df_make_name(temporary(q4),src3,date,avespec=avespec, $ forecast=forecast,format=format,gridspec=gridspec,sequence=sequence, $ special=special) ; *****get data err = dfread_grids(directory,fname,data,badval,ndat,audit=audit, $ comment=comment,diminfo=diminfo,dimavg=dimavg,info=info,procinfo=procinfo, $ unit=unit) if (err ne 0) then return,err if (n_elements(ndat) ne 4) then begin message,/continue,'Data is not dimensioned correctly: '+ $ strcompress(n_elements(ndat)) return,1 endif data = reform(data,/over) ndat = ndat[0:2] ; *****averaging info if (n_elements(dimavg) gt 0) then begin avals3 = dimavg.(0).avals avinfo = [dimavg.(0).destype,dimavg.(0).units,dimavg.(0).avgcod] endif else begin avals3 = 0 avinfo = temporary(avals3) junk = temporary(avinfo) endelse ; *****quantities and units dim_quantity = [diminfo.(0).destype,diminfo.(1).destype,diminfo.(2).destype] dim_unit = [diminfo.(0).units,diminfo.(1).units,diminfo.(2).units] dim0_value = diminfo.(0).avals dim1_value = diminfo.(1).avals dim2_value = diminfo.(2).avals ; *****supplemental info version = 0. sup1 = temporary(version) if ((where(tag_names(diminfo.(2)) eq 'SVALS'))[0] ne -1) $ then sup1 = diminfo.(2).svals $ else junk = temporary(sup1) ; *****calendar if ((where(tag_names(diminfo.(3)) eq 'SVALS'))[0] ne -1) then $ cal = long(diminfo.(3).svals[0]) $ else cal = 0L case cal of 0L : defsysv,'!calendar','GREGORIAN' 100L : defsysv,'!calendar','MODEL365' else : defsysv,'!calendar','UNKNOWN' endcase ; *****st up date array fdates = diminfo.(3).avals case diminfo.(3).units of -2142765056L : fdates = convert_date(temporary(fdates),/from_iso,/inc, $ /to_yymmdd,cal=cal) 1615331618L : fdates = convert_date(temporary(fdates),/from_day1900,/inc, $ /to_yymmdd,cal=cal) 1615331841L : fdates = long(temporary(fdates)) 1615331842L : fdates = long(temporary(fdates))*100L+ $ long((dates-long(dates))*12L) 1615331843L : fdates = long(temporary(fdates)) 1615331848 : fdates = long(temporary(fdates)) else : begin message,/continue,'Unknown date type: '+ $ strcompress(diminfo.(3).units,/rem) return,1 end endcase if (n_elements(date_list) ne 0) then begin dlist = where(in(fdates,date_list) ne -1) if (dlist[0] eq -1) then begin message,/continue,'Dates wanted not found in file '+date_list[0]+' '+ $ fdates[0] goto,bad_file endif endif else dlist = indgen(n_elements(diminfo.(3).gptnum)) ; *****get the forecasts check_fcst = (n_elements(fcst_list) ne 0) if (check_fcst) then fclist = long(fcst_list) ; *****process PROC stuff if (n_elements(procinfo) gt 0) then begin for iproc = 0L,n_tags(procinfo)-1L do begin prcnum = procinfo.(iproc).prcnum case procinfo.(iproc).code of 1L : begin if (check_fcst) then $ if ((where(fclist eq procinfo.(iproc).info[0]))[0] eq -1) $ then begin message,/cont,'Forecasts wanted not found in file '+ $ strcompress(procinfo.(iproc).info[0]) goto,bad_file endif fcst_list = lonarr(n_elements(dlist))+long(procinfo.(iproc).info[0]) end 2L : begin if (check_fcst) then begin fclist = where(in(long(procinfo.(iproc).info),fclist) ne -1) if (fclist[0] eq -1) then begin message,/continue,'Forecasts wanted not found in file '+$ strcompress(procinfo.(iproc).info[0],/rem) goto,bad_file endif dlist = dlist[where(in(fclist,dlist) ne -1)] endif fcst_list = long(procinfo.(iproc).info[dlist]) end 65536L : begin version = '' for i = 0L,prcnum-1L do begin vv = df_conv_fmt(procinfo.(iproc).info[i], $ const.str_xdr_cnt+256L,procinfo.(iproc).prcfmt[i]) version = temporary(version)+vv+' ' endfor version = strtrim(temporary(version),2) end else : message,/continue,'Unknown processing code: '+ $ strcompress(procinfo.(iproc).prccode,/rem) endcase endfor endif ; *****set the date_list date_list = fdates[dlist] return,0 bad_file: return,1 end