; function getidate,$ iyear,ut,$ ; inputs : 4-digit year, and ut (ut includes model day) hrs,iday ; outputs: float hrs, and julian iday ; ; idate is yymmdd, e.g. 910621 for June 21, 1991 ; iyr = long(iyear-iyear/100*100) iday = long(ut/24.) caldat,iday,month,day,year,hour,minute,second idate = iyr*10000 + month*100+day hrs = ut-float(iday*24) return,idate end ;-------------------------------------------------------- pro wrfile,lu,iyear,emis,dopt,dopu,dopv,type,iday0,iday1 ; ; Write data for one or more days at one location for an emission ; (E5577 or OH8400 according to type) to output file. ; On input, frame structures emis,dopt,dopu,dopv are defined for ; one or more days at a given location. Output file is opened ; and connected to lu. Type is either 'E5577' or 'OH8400'). ; iyear is defined as 4-digit year. ; loc_code = emis.loccode nx = emis.nx xx = emis.xx ; ; Data records: ; (idate is yymmdd. Getidate also returns hrs (fractional ut after day ; is taken out), and iday (julian day == model day) ; idayp = -1 for i=0,nx-1 do begin idate = getidate(iyear,xx(i),hrs,iday) if (i eq 0) then iday0 = iday if (i eq nx-1) then iday1 = iday if (iday gt idayp) then begin ; begin new day ; ; Look ahead to find number of points (np) for the new day: np = 0 for ii=i,nx-1 do begin iidate = getidate(iyear,xx(ii),hhrs,iiday) if (iiday gt iday) then goto,npdone else np = np+1 endfor npdone: np = np*2 ; Gonzalo needs number of data lines rather than # points ; ; First 3 lines of new day are location code, blank line, and header. ; icol = 2 for E5577, icol = 4 for OHB62 (8400A) ; if (type eq 'E5577') then icol = 2 else icol = 4 ip = 0 & azcode = 0 printf,lu,loc_code printf,lu,' ' printf,lu,format="(10x,a10,6i10)",loc_code,idate,iday,ip,np,azcode,icol idayp = iday endif hr = float(fix(hrs)) rmin = float(hrs-hr)*60. hhmm = hr*100.+rmin hhcc = hr*100.+rmin*100./60. dtemp = 1. & dwind = 1. & dbright = 1. & anp = 0. idirnorth = 1 & idireast = 3 & ireject = 0 printf,lu,format="(1x,5f8.0,1x,'N ',f8.0,2f8.2,f4.0,i4,i2)",$ hhmm,hhcc,dopt.zz(i,0),dtemp,dopv.zz(i,0),dwind,emis.zz(i,0),$ dbright,anp,idirnorth,ireject printf,lu,format="(1x,5f8.0,1x,'E ',f8.0,2f8.2,f4.0,i4,i2)",$ hhmm,hhcc,dopt.zz(i,0),dtemp,dopu.zz(i,0),dwind,emis.zz(i,0),$ dbright,anp,idireast,ireject endfor return end ;-------------------------------------------------------- pro wrdat,frames,nframes ; ; Write output files formatted for Gonzalo. Frames(nframes) are defined ; from ascii input data file. ; ; Get list of available locations (loc_codes(nlocs)): ; mxlocs = 10 loc_codes = strarr(mxlocs) nlocs = 0 for i=0,nframes-1 do begin found = 0 for ii=0,mxlocs-1 do begin if (frames(i).loccode eq loc_codes(ii)) then found = 1 endfor if (found eq 0) then begin loc_codes(nlocs) = frames(i).loccode nlocs = nlocs+1 endif endfor if (nlocs le 0) then begin print,'>>> wrdat: no known locations.' return endif print,'nlocs=',nlocs,' loc_codes=',loc_codes ; ; Year is arbitrary (use 1997 for tgcm/ccm3 coupled run): iyear = 1997 ; ; Loop 1st for E5577, 2nd for OH (6-2 band). ; for itype = 1,2 do begin if (itype eq 1) then type = 'E5577' else type = 'OH8400' ; ; Loop through available locations, writing a separate file for each ; emission (E5577, OH), and each location: ; for l=0,nlocs-1 do begin ; ; Find frames with the required fields at current location: ; Use frame.sname to distinguish E5577 vs OH8400, which was ; set by rdascii based on fname as follows: ; ; case frame.fname of ; 'GREENLINE EMISSION (E5577) (RAYLEIGHS)': sname = 'E5577' ; 'E5577 DOPPLER TEMPERATURE (DEG K)' : sname = 'EDOPT' ; 'E5577 DOPPLER ZONAL WIND (M/S)' : sname = 'EDOPU' ; 'E5577 DOPPLER MERIDIONAL WIND (M/S)' : sname = 'EDOPV' ; 'OH EMISSION BANDS (KILO-RAYLEIGHS)' : sname = 'OHBAND' ; 'OH EMISSION BANDS DOPPLER TEMPERATURE (DEG K)' : sname = 'OHDOPT' ; 'OH EMISSION BANDS DOPPLER ZONAL WIND (M/S)' : sname = 'OHDOPU' ; 'OH EMISSION BANDS DOPPLER MERIDIONAL WIND (M/S)' : sname = 'OHDOPV' ; endcase ; iframe_emis=-1 & iframe_dopt=-1 & iframe_dopu=-1 & iframe_dopv=-1 for i=0,nframes-1 do begin if (frames(i).loccode eq loc_codes(l)) then begin if (type eq 'E5577') then begin case frames(i).sname of 'E5577' : iframe_emis = i 'EDOPT' : iframe_dopt = i 'EDOPU' : iframe_dopu = i 'EDOPV' : iframe_dopv = i else: endcase endif else begin ; OH type case frames(i).sname of 'OHBAND' : iframe_emis = i 'OHDOPT' : iframe_dopt = i 'OHDOPU' : iframe_dopu = i 'OHDOPV' : iframe_dopv = i else: endcase endelse endif ; frame is at current location endfor if (iframe_emis lt 0 or iframe_dopt lt 0 or $ iframe_dopu lt 0 or iframe_dopv lt 0) then begin print,'>>> Cannot find all needed fields for loc ',loc_codes(l),':' print,' iframe_emis=',iframe_emis print,' iframe_dopt=',iframe_dopt print,' iframe_dopu=',iframe_dopu print,' iframe_dopv=',iframe_dopv goto,next_type endif frame_emis = frames(iframe_emis) frame_dopt = frames(iframe_dopt) frame_dopu = frames(iframe_dopu) frame_dopv = frames(iframe_dopv) ; ; Open output file: outfile = loc_codes(l) + '_' + type + '.dat' openw,luout,outfile,/get_lun ; print,'Opened output file ',outfile ; ; Write to output file: wrfile,luout,iyear,frame_emis,frame_dopt,frame_dopu,frame_dopv,type,$ iday0,iday1 close,luout newfile = loc_codes(l) + '_' + type + '_d' + $ strcompress(string(iday0),/remove_all) + '-' + $ strcompress(string(iday1),/remove_all) + '.dat' cmd = 'mv ' + outfile + ' ' + newfile spawn,cmd print,'Saved output file ',newfile endfor ; l=0,nlocs-1 next_type: endfor ; itype = 1,2 (E5577,OH8400) return end