pro gofilename2header,pp,file,forecast=forecast ; Purpose: add date-time-sc-etc info to pp-header from Grib-out filename ; Category: io data-conversion specialised ; Note: distinguishes between daily fields (reads time info from file name) ; and monthlies (will adjust time) according to file name ending in "avg" ; Note: expects input files to be named as for the output of "wmc_grib.pl" in ; order to deduce time and variable info ; Note: grid info needs to be done somewhere else ; Note: for some fields (geopotential) scaling is done (to geopot h) @comm_error ; Get y, m, d, h from the file name. ; Different if a monthly (ends in ".avg") as=str_sep(strmid(file,strpos(file,'Grib-out.'),strlen(file)),'.') n=n_elements(as) avgq=as(n-1) if (avgq eq "gz") then begin & n=n-1 & avgq=as(n-1) & endif if (avgq eq 'avg') then n=n-1 if (n eq 8) then havelevel=1 else havelevel=0 y=1900 & reads,as(3+havelevel),y m=1 & reads,as(4+havelevel),m d=1 & reads,as(5+havelevel),d var=1 & reads,as(1),var lev=0 & reads,as(2),lev h=0 & reads,as(6+havelevel),h if (avgq eq 'avg') then begin md=(m mod 12)+1 if (md eq 1) then yd=y+1 else yd=y pp.lbyr=y & pp.lbmon=m & pp.lbyrd=yd & pp.lbmond=md pp.lbdat=1 & pp.lbdatd=1 & pp.lbhr=h & pp.lbhrd=h pp.lbtim=132 & pp.lbproc=128 endif else begin pp.lbyr=y & pp.lbmon=m & pp.lbdat=d & pp.lbhr=h pp.lbtim=1 & pp.lbproc=0 endelse ; "n" should now be 7 or 8 ; 7 is an old-style name, without the leveltype code ; 8 is new-style, with the leveltype code (add "LEVT_IN_OUTNAME=1 to wmc_grib1.pl) case n of 7: leveltype=0 8: begin & leveltype=0 & reads,as(3),leveltype & end else: message,'Error: wrong type of filename: '+file endcase ; Set up level info pp.blev=lev ; Level is "pressure" if lev>0 else sfc. if (lev gt 0) then pp.lbvc=8 else pp.lbvc=129 ; However, MSLP, u10, v10 and T2 are exceptions (in fact, ; only Tsfc isn't!) case var of 151: pp.lbvc=128 167: begin & pp.lbvc=1 & pp.blev=2 & end 165: begin & pp.lbvc=1 & pp.blev=10 & end 166: begin & pp.lbvc=1 & pp.blev=10 & end else: $ if (havelevel) then begin case leveltype of 109: pp.lbvc=9 ; Hybrid 100: pp.lbvc=8 ; Pressure 1 : pp.lbvc=129 ; Surface 102: pp.lbvc=128 ; Mean sea level 105: pp.lbvc=1 ; Height else: message,'Don''t recognise level code: '+shtstr(leveltype) endcase endif endcase ; Set up field code and stash code pp.lbuser(3)=ec2uks(var,pp.lbvc) pp.lbfc=sc2fc(pp.lbuser(3)) if (pp.lbfc eq 0) then message,'(continuing) Don''t recognise ecmwf code ('+as(1)+') : '+shtstr(var),/cont ; Setup level codes case pp.lbuser(3) of ; Soil temperatures 20: case var of 139: pp.lblev=1 170: pp.lblev=2 183: pp.lblev=3 236: pp.lblev=4 endcase 21: case var of 140: pp.lblev=1 171: pp.lblev=2 184: pp.lblev=3 237: pp.lblev=4 endcase else: endcase ; Set up exp id - 698265 - ERA pp.lbexp=698265l ; Scale if needed ; Need to be careful if we're 2-byte! if (pp.lbcode ne 81) then $ case pp.lbuser(3) of 16202: pp.data=pp.data/9.80665 else: endcase ; if (pp.lbcode ne 81) then $ case var of 152: pp.data=(exp(1d0))^pp.data else: endcase ; ; if (pp.lbcode eq 81) then $ case var of 152: pp.lbuser(4)=var else: endcase ; ; Specical kludge section for forecast... if (keyword_set(forecast)) then case forecast of 1: begin if (is_in([4203,3223],pp.lbuser(3),/ft)) then message,'forecast=1 is intended for ppn data: you have sc of: '+shtstr(pp.lbuser(3)),/cont ; Begin by adjusting to total ppn, but only if this *is* ppn! if (pp.lbuser(3) eq 4203) then begin pp.lbuser(3)=5216 endif ; This is really a daily mean pp.lbproc=128 pp.lbtim=21 ; Adjust date pp.lbhr=0 pp.lbhrd=23 ; nb this is recognised by pp_period ymd=next_day(pp.lbyr,pp.lbmon,pp.lbdat) pp.lbyr=ymd(0) pp.lbmon=ymd(1) pp.lbdat=ymd(2) pp.lbyrd=pp.lbyr pp.lbmond=pp.lbmon pp.lbdatd=pp.lbdat ; Do scaling (not known so far) end else: message,'wrong value of forecast set' endcase end