;**************************************************************** ; This program reads in a mwr text file. It plots the entire file ; in one gif and then writes out daily netcdf files of the mwr data ;**************************************************************** pro mwr_txt_to_cdf ;**************************************************************** ; mwr text file and directory ;**************************************************************** ; Directory of mwr text file filedir='' ; Name of mwr text file ;filename='51400711.los' filename='60752001_20160317.los' ;filename='60752001_20160316.los' filename='60772219_20160318.los' filename='60790020_20160319.los' filename='60790020_20160320.los' filename='60790020_20160321.los' filename='60790020_20160322.los' filename='60820923_20160323.los' filename='60820923_20160324.los' filename='60820923_20160325.los' filename='60820923_20160326.los' filename='60860501_20160327.los' filename='60860501_20160328.los' filename='60860501_20160329.los' filename='60860501_20160330.los' filename='60900032_20160331.los' filename='60900032_20160401.los' filename='60900032_20160402.los' filename='60940332_20160403.los' filename='60940332_20160404.los' filename='60940332_20160405.los' filename='60962322_20160406.los' filename='60962322_20160407.los' filename='60962322_20160408.los' filename='60962322_20160409.los' filename='60962322_20160410.los' ; Output directory for gifs and netcdf files ;output_dir='/uufs/chpc.utah.edu/common/home/u0079358/mwr_utah/' output_dir='/Users/u0029340/Documents/data/Capricorn/MWR/' input_dir=output_dir ;**************************************************************** ; Information to set up the mwr text file structure ;**************************************************************** ;x=ascii_template(filename) ;stop ;IDL> print,x ;{ 1.00000 9 32 NaN 16 7 7 4 4 4 4 ;4 4 4 4 4 4 4 4 4 4 ;FIELD01 FIELD02 FIELD03 FIELD04 FIELD05 FIELD06 FIELD07 FIELD08 FIELD09 FIELD10 FIELD11 FIELD12 FIELD13 FIELD14 FIELD15 FIELD16 ;0 9 20 28 35 45 54 62 72 77 ;83 90 96 103 109 117 ;0 1 2 3 4 5 6 7 8 9 ;10 11 12 13 14 15 ;} ;IDL> help,/struct,x ;** Structure , 10 tags, length=488, data length=481, refs=1: ;VERSION FLOAT 1.00000 ;DATASTART LONG 9 ;DELIMITER BYTE 32 ;MISSINGVALUE FLOAT NaN ;COMMENTSYMBOL STRING '' ;FIELDCOUNT LONG 16 ;FIELDTYPES LONG Array[16] ;FIELDNAMES STRING Array[16] ;FIELDLOCATIONS LONG Array[16] ;FIELDGROUPS LONG Array[16] ;************************************************* ; Define the structure ;************************************************* ; Structure field names field_names=['FIELD01','FIELD02','FIELD03','FIELD04','FIELD05','FIELD06','FIELD07',$ 'FIELD08','FIELD09','FIELD10','FIELD11','FIELD12','FIELD13','FIELD14','FIELD15','FIELD16'] ; Structure field locations field_locations=[0,9,20,28,35,45,54,62,72,77,83,90,96,103,109,117] ; Structure field types field_types=[7,7,4,4,4,4,4,4,4,4,4,4,4,4,4,4] ; Structure field groups field_groups=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] ; Structure field count field_count=[16] ; Ascii template structure b={btemplate,$ VERSION:1.0,$ DATASTART:9,$ DELIMITER:32b,$ MISSINGVALUE:-9999.0,$ COMMENTSYMBOL:'',$ FIELDCOUNT:field_count,$ FIELDTYPES:field_types,$ FIELDNAMES:field_names,$ FIELDLOCATIONS:field_locations,$ FIELDGROUPS:field_groups} ;****************************************************** ; Read the file ;****************************************************** missing=-9999 files=file_search(input_dir+filename,count=num_files) print,files print,'num_files',num_files if num_files ne 1 then stop dbase=read_ascii(files[0], template=b) sdate=dbase.field01 ;mm/dd/yy time=dbase.field02 ;hr:mi:ss tbsky23=dbase.field03 tbsky31=dbase.field04 tkbb=dbase.field05 vapcm=dbase.field06 liqcm=dbase.field07 delcm=dbase.field08 azact=dbase.field09 elact=dbase.field10 tau23=dbase.field11 tau31=dbase.field12 tamb=dbase.field13 rh=dbase.field14 pres=dbase.field15 rain=dbase.field16 mm=strmid(sdate,0,2) dd=strmid(sdate,3,2) yy='20'+strmid(sdate,6,2) hr=strmid(time,0,2) mi=strmid(time,3,2) ss=strmid(time,6.2) result=where(tbsky23 lt 2.73 or tbsky23 gt 100.0,count) if count gt 0 then tbsky23[result]=missing result=where(tbsky31 lt 2.73 or tbsky31 gt 100.0,count) if count gt 0 then begin tbsky31[result]=missing vapcm[result]=missing liqcm[result]=missing delcm[result]=missing tau31[result]=missing tau23[result]=missing endif ; Convert time to julian_day julian_day=julday(mm,dd,yy,hr,mi,ss) ;**************************************** ; Plot of the variables in the file ;**************************************** ; gifs will be named with the starting date in the file date=yy[0]+mm[0]+dd[0] dummy = label_date(DATE_FORMAT=['%D/%M!C%H:%I']) loadct,39 ; Position the plots xl=0.12 & xr=0.97 yb=0.08 & yt=0.9 sx=0.14 sy=0.05 numplots_x=1 numplots_y=5 position_plots,xl,xr,yb,yt,sx,sy,numplots_x,numplots_y,pos alldata=[tbsky23,tbsky31] result=where(alldata ne missing,count) dmax=max(alldata[result]) dmin=min(alldata[result]) p0=plot(julian_day,tbsky23,position=reform(pos[0,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='tbsky',dimensions=[800,800]) p1=plot(julian_day,tbsky31,/overplot,color='red') alldata=[tau23,tau31] result=where(alldata ne missing,count) dmax=max(alldata[result]) dmin=min(alldata[result]) p0=plot(julian_day,tau23,position=reform(pos[1,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],/current,ytitle='tau') p1=plot(julian_day,tau31,/overplot,color='red') alldata=[tkbb] dmax=max(alldata) dmin=min(alldata) p0=plot(julian_day,tkbb,position=reform(pos[2,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],/current,ytitle='tkbb') ;p1=plot(julian_day,tau31,/overplot,color='red') alldata=[vapcm] result=where(alldata ne missing) dmax=max(alldata[result]) dmin=min(alldata[result]) p0=plot(julian_day,vapcm,position=reform(pos[3,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],/current,ytitle='vap') alldata=[liqcm] result=where(alldata ne missing) dmax=max(alldata[result]) dmin=min(alldata[result]) p0=plot(julian_day,liqcm,position=reform(pos[4,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],/current,ytitle='liq') p0.save,output_dir+'tbsky23.'+date+'.gif',height=900 ; Another plot dmax=max(tamb) dmin=min(tamb) p0=plot(julian_day,Tamb,position=reform(pos[0,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='Tamb',dimensions=[800,800],color='black') dmax=max(rh) dmin=min(rh) p0=plot(julian_day,rh,position=reform(pos[1,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='RH',/current) dmax=max(pres) dmin=min(pres) p0=plot(julian_day,pres,position=reform(pos[2,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='pres',/current) dmax=max(rain) dmin=min(rain) p0=plot(julian_day,rain,position=reform(pos[3,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='rain',/current) dmax=max(azact) dmin=min(azact) p0=plot(julian_day,azact,position=reform(pos[4,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='azact',/current) p0.save,output_dir+'tamb.'+date+'.gif',height=900 ; Another plot dmax=max(elact) dmin=min(elact) p0=plot(julian_day,elact,position=reform(pos[0,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='elact',dimensions=[800,800],color='black') result=where(alldata ne missing) dmax=max(delcm[result]) dmin=min(delcm[result]) p0=plot(julian_day,delcm,position=reform(pos[1,*]),/buffer,$ xtickunits='time',xtickformat='label_date',xstyle=1,xminor=3,$ yrange=[dmin,dmax],ytitle='delcm',/current) p0.save,output_dir+'elact.'+date+'.gif',height=900 ;******************************* ; Create daily files ;******************************* ejulian_day=julian_day[-1] ;last time in file ifinished=0 ;while loop finishing flag idx=0 ;index of the first time in the day while idx lt n_elements(julian_day) do begin sjulian_day=julday(mm[idx],dd[idx],yy[0],0,0,0) result=where(julian_day ge sjulian_day and julian_day lt sjulian_day+1D,count) if count gt 0 then begin numtimes=count sub_julian_day=julian_day[result] sub_tbsky23=tbsky23[result] sub_tbsky31=tbsky31[result] sub_tkbb=tkbb[result] sub_vapcm=vapcm[result] sub_liqcm=liqcm[result] sub_delcm=delcm[result] sub_azact=azact[result] sub_elact=elact[result] sub_tau23=tau23[result] sub_tau31=tau31[result] sub_tamb=tamb[result] sub_rh=rh[result] sub_pres=pres[result] sub_rain=rain[result] ; Seconds in a day sec_per_day=double(24L*60L*60L) ; Get IDL julian day of day 1 day1=julday(1,1,1970,0,0,0) ; Calculate the seconds since 1970 time_offset=long(sec_per_day*(sub_julian_day-day1)) ; The first time is the base time base_time=time_offset[0] ; Time offset time_offset=time_offset-base_time ; Filename date_string=yy[idx]+mm[idx]+dd[idx] output_file='utmwrlosC1.b1.'+date_string+'.cdf' ; Open the netcdf file cdf_id=ncdf_create(output_dir+output_file,/clobber) ; Define dimensions time_did=ncdf_dimdef(cdf_id,'time',numtimes) ; Define the base_time variable base_time_id=ncdf_vardef(cdf_id,'base_time',/long) ncdf_attput,cdf_id,base_time_id,'string',date_string ncdf_attput,cdf_id,base_time_id,'long_name','Base time in Epoch' ncdf_attput,cdf_id,base_time_id,'units','seconds since 1970-01-01 00:00:00 00:00' ; Define the time_offset variable time_offset_id=ncdf_vardef(cdf_id,'time_offset',time_did,/double) ncdf_attput,cdf_id,time_offset_id,'long_name','Time offset from base_time' ncdf_attput,cdf_id,time_offset_id,'units','seconds since '+date_string tbsky23_id=ncdf_vardef(cdf_id,'tbsky23',time_did) ncdf_attput,cdf_id,tbsky23_id,'long_name','23.8 GHz sky brightness temperature' ncdf_attput,cdf_id,tbsky23_id,'units','K' ncdf_attput,cdf_id,tbsky23_id,'valid_min','2.73' ncdf_attput,cdf_id,tbsky23_id,'valid_max','100.0'; ncdf_attput,cdf_id,tbsky23_id,'missing_value','-9999' tbsky31_id=ncdf_vardef(cdf_id,'tbsky31',time_did) ncdf_attput,cdf_id,tbsky31_id,'long_name','31.4 GHz sky brightness temperature' ncdf_attput,cdf_id,tbsky31_id,'units','K' ncdf_attput,cdf_id,tbsky31_id,'valid_min','2.73' ncdf_attput,cdf_id,tbsky31_id,'valid_max','100.0' ncdf_attput,cdf_id,tbsky31_id,'missing_value','-9999' tkbb_id=ncdf_vardef(cdf_id,'tkbb',time_did) ncdf_attput,cdf_id,tkbb_id,'long_name','Blackbody kinetic temperature' ncdf_attput,cdf_id,tkbb_id,'units','K' ncdf_attput,cdf_id,tkbb_id,'valid_min','250' ncdf_attput,cdf_id,tkbb_id,'valid_max','320' ncdf_attput,cdf_id,tkbb_id,'missing_value','-9999' vap_id=ncdf_vardef(cdf_id,'vap',time_did) ncdf_attput,cdf_id,vap_id,'long_name','Total water vapor along LOS path' ncdf_attput,cdf_id,vap_id,'units','cm' ncdf_attput,cdf_id,vap_id,'valid_min','0' ncdf_attput,cdf_id,vap_id,'missing_value','-9999' liq_id=ncdf_vardef(cdf_id,'liq',time_did) ncdf_attput,cdf_id,liq_id,'long_name','Total liquid water along LOS path' ncdf_attput,cdf_id,liq_id,'units','cm' ncdf_attput,cdf_id,liq_id,'valid_min','-0.010261' ncdf_attput,cdf_id,liq_id,'missing_value','-9999' delcm_id=ncdf_vardef(cdf_id,'delcm',time_did) azact_id=ncdf_vardef(cdf_id,'azact',time_did) ncdf_attput,cdf_id,azact_id,'long_name','azimuth' elact_id=ncdf_vardef(cdf_id,'elact',time_did) ncdf_attput,cdf_id,elact_id,'long_name','elevation' tau23_id=ncdf_vardef(cdf_id,'tau23',time_did) tau31_id=ncdf_vardef(cdf_id,'tau31',time_did) tamb_id=ncdf_vardef(cdf_id,'tamb',time_did) ncdf_attput,cdf_id,tamb_id,'long_name','temperature' rh_id=ncdf_vardef(cdf_id,'rh',time_did) ncdf_attput,cdf_id,rh_id,'long_name','relative humidity' pres_id=ncdf_vardef(cdf_id,'pres',time_did) ncdf_attput,cdf_id,pres_id,'long_name','pressure' rain_id=ncdf_vardef(cdf_id,'rain',time_did) ; Change from define mode to data mode ncdf_control,cdf_id,/endef ; Put in the variables ncdf_varput,cdf_id,base_time_id,base_time ncdf_varput,cdf_id,time_offset_id,time_offset ncdf_varput,cdf_id,tbsky23_id,sub_tbsky23 ncdf_varput,cdf_id,tbsky31_id,sub_tbsky31 ncdf_varput,cdf_id,tkbb_id,sub_tkbb ncdf_varput,cdf_id,vap_id,sub_vapcm ncdf_varput,cdf_id,liq_id,sub_liqcm ncdf_varput,cdf_id,delcm_id,sub_delcm ncdf_varput,cdf_id,azact_id,sub_azact ncdf_varput,cdf_id,elact_id,sub_elact ncdf_varput,cdf_id,tau23_id,sub_tau23 ncdf_varput,cdf_id,tau31_id,sub_tau31 ncdf_varput,cdf_id,tamb_id,sub_tamb ncdf_varput,cdf_id,rh_id,sub_rh ncdf_varput,cdf_id,pres_id,sub_pres ncdf_varput,cdf_id,rain_id,sub_rain ; Close the file ncdf_close,cdf_id ; Grab the next day idx=idx+count endif endwhile end