pro rawsurface_longfiles_azp,site_code,year,current_year,rawlongo3 ;this is a program to read in surface data and make files for reading into the other program.It just appends them. ;just do one year at a time ;original files MUST be separated by year (i.e. don't let 12/31 roll to 01/01 because 49C does not put date in ;which year?? ; BAO site code = 348 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! 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/*.txt',Count=counts,FOLD_CASE=1) IF !Version.OS_family EQ 'Windows' THEN datafiles=file_search(datapath+'orig_data\*.txt') ; 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,intena:lonarr(31,24,60)*!Values.F_NaN,$ intenb:lonarr(31,24,60)*!Values.F_NaN,bencht:fltarr(31,24,60)*!Values.F_NaN,$ lampt:fltarr(31,24,60)*!Values.F_NaN,flowa:fltarr(31,24,60)*!Values.F_NaN,$ flowb:fltarr(31,24,60)*!Values.F_NaN,pres:fltarr(31,24,60)*!Values.F_NaN,o3lampt:fltarr(31,24,60)*!Values.F_NaN} rawlongo3=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' FOR j=0,n_elements(datafiles) -1 DO BEGIN openr,lun,datafiles(j),/get_lun ;print, datafiles(j) data_str='' mo=0 ct=0l 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 ;print, data_string(1) mi=long(strcompress(strmid(data_string(1),0,2),/remove)) ; print, mi if long(data_string(1)) eq 2000 then goto, skip1 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)) yst=strmid(data_string(1),6,2) yi=long(yst) year_ind=where(years eq '20'+yst) rawlongo3(mi-1,year_ind).model=model rawlongo3(mi-1,year_ind).date_string(di-1,hi,mini)=data_string(1) rawlongo3(mi-1,year_ind).intena(di-1,hi,mini)=float(data_string(5)) rawlongo3(mi-1,year_ind).intenb(di-1,hi,mini)=float(data_string(6)) rawlongo3(mi-1,year_ind).bencht(di-1,hi,mini)=float(data_string(7)) rawlongo3(mi-1,year_ind).lampt(di-1,hi,mini)=float(data_string(8)) rawlongo3(mi-1,year_ind).o3lampt(di-1,hi,mini)=float(data_string(9)) rawlongo3(mi-1,year_ind).flowa(di-1,hi,mini)=float(data_string(10)) rawlongo3(mi-1,year_ind).flowb(di-1,hi,mini)=float(data_string(11)) rawlongo3(mi-1,year_ind).pres(di-1,hi,mini)=float(data_string(12)) ;save in proper position in array rawlongo3.stnid=stnid rawlongo3(mi-1,year_ind).time_string(di-1,hi,mini)=data_string(0) rawlongo3(mi-1,year_ind).flags(di-1,hi,mini)=data_string(2) rawlongo3(mi-1,year_ind).o3ppbv(di-1,hi,mini)=float(data_string(3)) ct=ct+1l skip1: ENDWHILE skip4: free_lun,lun close, lun endfor ; end of each file ;read in long files data to fill the gap ; ;write out the files for i=0,n_elements(years) -1 do begin for mi=0,11 do begin cind=where(strcompress(rawlongo3(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)+'.lrc' $ else outfile=datapath+strlowcase(site_code)+ strcompress(mi+1,/remove)+strcompress(years(i),/remove)+'.lrc' ;if site_code eq 'BAO' then outfile='\\ccgg\ccg\towers\SharedFiles\RadonOzoneCeilometerData\BAOgroundBasedOzone\bao_'+dates(0)+'.src' openw,lun,/get,outfile printf, lun,';;' printf, lun,';; Stn: ',stnid," ", rawlongo3(mi,i).site_code printf, lun,';;' printf, lun,';; Model ', rawlongo3(mi,i).model printf, lun,';;' colhdr=' Time Date Alarms O3 Inten A Inten B Bench Temp Lamp Temp O3 Lamp Temp Flow A Flow B Pres' printf, lun,colhdr for di=0,30 do begin for hi=0,23 do begin for mini=0,59 do begin if strcompress(rawlongo3(mi,i).o3ppbv(di,hi,mini),/remove) ne 'NaN' then begin ;if rawlongo3(mi,i).o3ppbv(di,hi,mini) gt -5000 and rawlongo3(mi,i).o3ppbv(di,hi,mini) lt 15000. then begin printf,lun,format='(A5," ",A8," ",A8," ",F8.4," ",I8," ",I8," ",f8.4," ",f8.4," ",f8.4," ",f8.4," ",f8.4," ",f8.4)',$ rawlongo3(mi,i).time_string(di,hi,mini),rawlongo3(mi,i).date_string(di,hi,mini),rawlongo3(mi,i).flags(di,hi,mini),$ rawlongo3(mi,i).o3ppbv(di,hi,mini),rawlongo3(mi,i).intena(di,hi,mini),rawlongo3(mi,i).intenb(di,hi,mini),rawlongo3(mi,i).bencht(di,hi,mini),$ rawlongo3(mi,i).lampt(di,hi,mini),rawlongo3(mi,i).o3lampt(di,hi,mini),rawlongo3(mi,i).flowa(di,hi,mini),rawlongo3(mi,i).flowb(di,hi,mini),$ rawlongo3(mi,i).pres(di,hi,mini) endif endfor ;mini endfor ; hi endfor ;di close, lun free_lun,lun skipout: endfor endfor end