PRO rawsurface_AZP, year, current_year, shorto3 ;+ ;This script reads in the AZP/PCO files, ;puts them into the same format as the other surface files ;Laura P ;10/06/11 ; ;- site_code='PCO' ground_site_lookup,site_code,info_str loc=info_str.loc datapath1=info_str.raw_data_loc dummy= info_str.processed_data_loc stnid=info_str.code ;station ID hagl=info_str.inlet_hgt ;Height above ground level lt_adj=info_str.gmt_offset ; local time adjustment datapath1=info_str.raw_data_loc ;where to find the raw files year_start=info_str.year_started years=indgen(abs(long(year_start)-long(current_year))+1)+long(year_start) ;read in the directory with the raw downloads ;can only read in one year of data at a time! ;first read in SRC datapath= StrJoin(StrSplit(datapath1,'year_str',/extract,/REGEX),strmid(year,2,2)) IF !Version.OS_family EQ 'unix' THEN datafiles=file_search(datapath+'orig_data/*.src',Count=counts,FOLD_CASE=1) IF !Version.OS_family EQ 'Windows' THEN datafiles=file_search(datapath+'orig_data\*.src') ; array of all data ct=44640L ; how many 5-minutes in a month data={var_units:['station_id','time','date','flags' ,'O3 (ppbv)'],model:'',$ site_code:site_code,site_location:loc,stnid:stnid,hagl:hagl,$ time_string:strarr(31,24,60),date_string:strarr(31,24,60),flags:strarr(31,24,60),$ o3ppbv:fltarr(31,24,60)*!Values.F_NaN} shorto3=REPLICATE(data,12,n_elements(years)) ; for each month ;and then for two years to get the first 7 hours ;of Jan of the next year for Local time calculation ct=0L mo=0 model='49I' ;calculate date of next year in LOCAL TIME ;calculate julian date and time ;if time is negative ;if float(lt_adj) lt 0 then wrap_date_time=julday(1,1,float(ystr)+1,abs(Float(lt_adj))-1,59,59) ;if float(lt_adj) gt 0 then wrap_date_time=julday(12,31,float(ystr)-1,23-(float(lt_adj)),59,59) ;would rarely use (for other side of GMT line) for j=0,n_elements(datafiles) -1 do begin openr,lun,datafiles(j),/get_lun print, datafiles(j) data_str='' mo=0 ct=0l start_read: WHILE ~ EOF(lun) DO BEGIN ;Read a line of text: READF,lun,data_str ;parse into fields data_string=STRSPLIT(data_str,' ',/extract) if n_elements(data_string) eq 1 then goto, skip1 mi=long(strcompress(strmid(data_string(1),0,2),/remove)) if mi ne mo then begin ct=0L mo=mi endif hi=long(strmid(data_string(0),0,2)) mini=long(strmid(data_string(0),3,2)) di=long(strmid(data_string(1),3,2)) yi=LONG(strmid(data_string(1),6,2)) ynst=STRCOMPRESS(yi,/remove) year_ind=where(years eq '20'+ynst) shorto3(mi-1,year_ind).date_string(di-1,hi,mini)=data_string(1)+'-'+ynst shorto3.stnid=stnid shorto3(mi-1,year_ind).model=model shorto3(mi-1,year_ind).time_string(di-1,hi,mini)=data_string(0) shorto3(mi-1,year_ind).flags(di-1,hi,mini)=data_string(3) shorto3(mi-1,year_ind).o3ppbv(di-1,hi,mini)=float(data_string(5)) skip1: ENDWHILE skip4: free_lun,lun close, lun endfor ; end of each file ;read in long files data to fill the gap rawsurface_longfiles_azp,site_code,year,current_year,longo3 ;check where there are values missing for i=0,n_elements(shorto3(0,*)) -1 do begin ;for each year for mi=0,11 do begin IF STRMATCH(shorto3(mi,i).model,'49?',/FOLD_CASE) ne 1 THEN BEGIN b=WHERE(STRMATCH(shorto3(*,i).model,'49?',/FOLD_CASE) eq 1,ctm) IF ctm ge 1 THEN shorto3(mi,i).model=shorto3(b(0),i).model ENDIF sind=where(strcompress(shorto3(mi,i).o3ppbv,/remove) ne 'NaN',ctrs) lind=where(strcompress(longo3(mi,i).o3ppbv,/remove) ne 'NaN',ctrl) if ctrl lt 10 and ctrs lt 10 then goto, skiphere for di=0,30 do begin for hi=0,23 do begin ;how many values are there? ;if less than #? then will need to grab the long value sind=where(strcompress(shorto3(mi,i).o3ppbv(di,hi,*),/remove) ne 'NaN',ctw) if ctw eq 0 then begin lind=where(strcompress(longo3(mi,i).o3ppbv(di,hi,*),/remove)ne 'NaN',ctl) if ctl ne 0 then begin shorto3(mi,i).o3ppbv(di,hi,lind)=longo3(mi,i).o3ppbv(di,hi,lind) shorto3(mi,i).time_string(di,hi,lind)= longo3(mi,i).time_string(di,hi,lind) shorto3(mi,i).flags(di,hi,lind)= longo3(mi,i).flags(di,hi,lind) shorto3(mi,i).date_string(di,hi,lind)= longo3(mi,i).date_string(di,hi,lind) endif endif endfor ;end of hi endfor ;end of di skiphere: ;skip to next month endfor ; end of mi endfor; end of year ;write out the files for i=0,n_elements(years) -1 do begin for mi=0,11 do begin cind=where(strcompress(shorto3(mi,i).o3ppbv,/remove) ne 'NaN',ctrl) if ctrl lt 10 then goto, skipout if mi+1 lt 10 then outfile=datapath+STRLOWCASE(site_code)+'0'+ strcompress(mi+1,/remove)+strcompress(years(i),/remove)+'.src' $ else outfile=datapath+strlowcase(site_code)+ strcompress(mi+1,/remove)+strcompress(years(i),/remove)+'.src' ;if site_code eq 'BAO' then outfile='\\ccgg\ccg\towers\SharedFiles\RadonOzoneCeilometerData\BAOgroundBasedOzone\bao_'+dates(0)+'.src' openw,lun,/get,outfile IF mi NE 0 AND STRCOMPRESS(shorto3(mi,i).model,/remove) EQ '' THEN shorto3(mi,i).model=shorto3(mi-1,i).model printf, lun,';;' printf, lun,';; Stn: ',stnid," ", shorto3(mi,i).site_code printf, lun,';;' printf, lun,';; Model ', shorto3(mi,i).model print, shorto3(mi,i).model,' model ', 'mi ',mi,' i ',years(i) printf, lun,';;' printf, lun,'Time Date Flags o3 (ppbv)' for di=0,30 do begin for hi=0,23 do begin for mini=0,59 do begin if strcompress(shorto3(mi,i).o3ppbv(di,hi,mini),/remove) ne 'NaN' then begin ;if shorto3(mi,i).o3ppbv(di,hi,mini) gt -5000 and shorto3(mi,i).o3ppbv(di,hi,mini) lt 15000. then begin printf,lun,format='(A5," ",A8," ",A8," ",F8.4)', shorto3(mi,i).time_string(di,hi,mini),shorto3(mi,i).date_string(di,hi,mini),shorto3(mi,i).flags(di,hi,mini),shorto3(mi,i).o3ppbv(di,hi,mini) endif endfor ;mini endfor ; hi endfor ;di close, lun free_lun,lun skipout: endfor endfor END