pro read_in_found_calibrations, groundo3,year ;********************SECTION WHERE READ IN EDITED FILE******************************** ;read in file ;remove bad points, leave good ones and add calibration factor to array ;this does not calculate zero or slope restore, 'groundo3.sav' ground_site_lookup,groundo3(0).site_code,info_str dummy= info_str.processed_data_loc site_code=groundo3(0).site_code yst2=strmid(year,2,2) folder= StrJoin(StrSplit(dummy,'year_str',/extract,/REGEX),yst2) ;infile=dialog_pickfile(path=folder,filter='*.dat') ;infile='/owv/surface/data/wkt/10/wkt_calval_2010_6m_edited.dat' infile=file_search(folder+'*_edited.dat',FOLD_CASE=1) openr, 1, infile strings='' while ~EOF(1) do begin readf,1,strings strext=strsplit(strings,' ',/extract) if strcompress(strings,/remove) eq '' then goto, skiptonextpt ;this part is only for the values that I paste in that are junk ;if I paste in values in the calibration, they will get caught in the calibration section if strmid(strext(0),0,1) ne '#' then begin yyyys=strcompress('20'+ strmid(strext(1),6,2)) mms=strmid(strext(1),0,2) dds=strmid(strext(1),3,2) hhs=strmid(strext(0),0,2) mins=string(strmid(strext(0),3,2)) if strcompress(strext(3)) eq 'NaN' or strcompress(strext(3)) eq '********' then goto, skiptonextpt else o3vals=float(strext(3)) flag=strext(2) month=long(mms) badind= where(groundo3(month-1).day eq dds and groundo3(month-1).hour eq hhs, ct) if ct ge 1 then groundo3(month-1).o3ppbv(badind)=!Values.f_nan goto,skiptonextpt endif if n_elements(strext) gt 1 and strcompress(strext(0),/remove) eq '' then begin flag=strcompress(strext(0),/remove) stnid=strcompress(strext(1),/remove) yyyys=strcompress(strext(2),/remove) mms=strcompress(strext(3),/remove) dds=strcompress(strext(4),/remove) hhs=strcompress(strext(5),/remove) mins=strcompress(strext(6),/remove) o3vals=strcompress(strext(7),/remove) endif case strcompress(strext(0),/remove) of '#':goto,skiptonextpt '#b':goto,skiptonextpt '#e':goto, skiptonextpt '#g': goto, skiptonextpt '#j' : begin mms=strcompress(strext(3),/remove) dds=strcompress(strext(4),/remove) hhs=strcompress(strext(5),/remove) month=long(mms) badind= where(groundo3(month-1).day eq dds and groundo3(month-1).hour eq hhs, ct) if ct ge 1 then groundo3(month-1).o3ppbv(badind)=!Values.f_nan end '#r' : begin ;remove a range of dates and times (don't want to cut and paste) ; what do you need for foy ;#r 06:00 07-30-10 , 12:00 07-31-10 yyyyb=strcompress('20'+ strmid(strext(2),6,2)) mmsb=strmid(strcompress(strext(2),/remove),0,2) ddsb=strmid(strcompress(strext(2),/remove),3,2) hhsb=strmid(strcompress(strext(1),/remove),0,2) minutesb=strmid(strcompress(strext(1),/remove),3,2) yyyyt=strcompress('20'+ strmid(strcompress(strext(5),/remove),6,2)) mmst=strmid(strcompress(strext(5),/remove),0,2) ddst=strmid(strcompress(strext(5),/remove),3,2) hhst=strmid(strcompress(strext(4),/remove),0,2) minutest=strmid(strcompress(strext(4),/remove),3,2) doy=ymd2dn(float(yyyyb),float(mmsb),float(ddsb)) fod=(float(float(hhsb))+(float(minutesb))/60.)/24. foyb=doy+fod doy=ymd2dn(float(yyyyt),float(mmst),float(ddst)) fod=(float(float(hhst))+(float(minutest))/60.)/24. foyt=doy+fod month1=long(mmsb) month2=long(mmst) for month=month1,month2 do begin badind= where(groundo3(month-1).foy ge foyb and groundo3(month-1).foy le foyt, ct) if ct ge 1 then groundo3(month-1).o3ppbv(badind)=!Values.f_nan endfor end '#c' : begin mms=strcompress(strext(3),/remove) dds=strcompress(strext(4),/remove) hhs=strcompress(strext(5),/remove) month=long(mms) badind= where(groundo3(month-1).day eq dds and groundo3(month-1).hour eq hhs, ct) if ct ge 1 then groundo3(month-1).o3ppbv(badind)=!Values.f_nan end endcase skiptonextpt: endwhile close,1,/force ;open the calibration slope file and multiply everything by a value ; apply to array ;****************store values back in array and pass out ;read in values string2='' ;create an empty structure for values ;FIX THIS EVENTUALLY not tonight calstr={yyyy:strarr(60),mode:strarr(60),mm:strarr(60),dd:strarr(60),hh:strarr(60),slope:fltarr(60),zero:fltarr(60),interp:strarr(60),inst_num:strarr(60)} print,'MAKE SURE YOU HAVE EDITED THIS FILE' ;result=dialog_pickfile(path=folder,filter='wk*') ;result='/owv/surface/data/wkt/10/wktchd10' result=file_search(folder+strlowcase(site_code)+'chd'+yst2,FOLD_CASE=1 ) openr, lun2,result,/get readf,lun2,string2 ctc=0 while ~EOF(lun2) do begin readf, lun2, string2 print,string2 strext2=strsplit(string2,' ',/extract) if n_elements(strext2) le 1 then goto,skipline ;take out the month day and time of each and multiply values until the next date calstr.mm(ctc)=strmid(strext2(0),3,2) calstr.yyyy(ctc)=strmid(strext2(0),5,2) calstr.mode(ctc)=strcompress(strext2(1),/remove) calstr.hh(ctc)=strmid(strext2(2),0,2) calstr.dd(ctc)=strmid(strext2(2),2,2) calstr.slope(ctc)=float(strext2(4)) calstr.zero(ctc)=float(strext2(6)) calstr.inst_num=strcompress(strext2(7),/remove) calstr.interp(ctc)=strext2(1);not right but just needed to get done ctc=ctc+1 skipline: endwhile skipr: close, lun2,/force free_lun,lun2 ctc=ctc-1 ;calibration file is closed and read into array calstr ;find all instances of zero check (non-NIST) indz=where(calstr.mode eq '2',ctz) for pz=0,ctz -1 do begin bi=indz(pz) mo1=long(calstr.mm(bi)) ;create an foy1 and foy2 doy=ymd2dn(float(year),float(mo1) ,float(calstr.dd(bi))) fod=(float(calstr.hh(bi)))/24. foy1=doy+fod if pz ne ctz-1 then begin ei=indz(pz+1) mo2=long(calstr.mm(ei)) doy=ymd2dn(float(year),float(mo2) ,float(calstr.dd(ei))) fod=(float(calstr.hh(ei)))/24. foy2=doy+fod endif else begin ;calculate when the reading was the last one and last is not 12/31 ;calculate this just in case its a leap year - if this is the last calibration this will apply to the rest of the year mo2=12 doy=ymd2dn(float(year),float(12) ,float(31)) fod=1. & foy2=doy+fod endelse ;if calstr.zero(ei) eq 0. then stop ;multiply the values in between by the fraction for j=mo1,mo2 do begin ind=where(groundo3(j-1).foy ge foy1 and groundo3(j-1).foy le foy2,ctind) for k=0L,ctind-1 do begin ;groundo3(j-1).o3ppbv(ind(k))=(groundo3(j-1).o3ppbv(ind(k))*(calstr.slope(i)+((dsl/float(ctind))*(float(k)))))+((dz/float(ctind))*float(k)) if strcompress(groundo3(j-1).o3ppbv(ind(k)),/remove) eq 'NaN' then goto,skipcal if pz ne ctz -1 then groundo3(j-1).o3ppbv(ind(k))=(groundo3(j-1).o3ppbv(ind(k)))-((double(calstr.zero(ei)-calstr.zero(bi))/float(ctind))*float(k)) $ ;no slope is multiplied else groundo3(j-1).o3ppbv(ind(k))=groundo3(j-1).o3ppbv(ind(k))-calstr.zero(bi) skipcal: endfor endfor ; multiply by each month ;print, 'reading in for month ', i+1 endfor ; end of i ;+++ ;MULTIPLY IT ALL BY THE NIST VALUES NOW THAT THE ZERO HAS BEEN APPLIED ; one to two per year indz=where(calstr.mode eq '1',ctz) ; every file should have at least one in it for pz=0,ctz -1 do begin bi=indz(pz) mo1=long(calstr.mm(bi)) ;create an foy1 and foy2 if strcompress('20'+calstr.yyyy(bi),/remove) ne year then foy1=0. else begin ;start at the beginning of the year doy=ymd2dn(float(year),float(mo1) ,float(calstr.dd(bi))) fod=(float(calstr.hh(bi)))/24. foy1=doy+fod endelse if pz ne ctz-1 then begin ei=indz(pz+1) mo2=long(calstr.mm(ei)) doy=ymd2dn(float(year),float(mo2) ,float(calstr.dd(ei))) fod=(float(calstr.hh(ei)))/24. foy2=doy+fod ;calculate if calstr.inst_num(bi) eq calstr.inst_num(ei) then begin dsl=double(calstr.slope(ei)-calstr.slope(bi)) dz=double(calstr.zero(ei)-calstr.zero(bi)) ;multiply the values in between by the fraction for j=mo1,mo2 do begin ind=where(groundo3(j-1).foy ge foy1 and groundo3(j-1).foy le foy2,ctind) for k=1l,ctind-1 do groundo3(j-1).o3ppbv(ind(k))=(groundo3(j-1).o3ppbv(ind(k))*(calstr.slope(bi)+((dsl/float(ctind)))*float(k)))+((dz/float(ctind))*float(k)) print, 'reading in for month ',j,' dsl=',dsl,' dz=',dz endfor ; multiply by each month endif else begin ;multiply the values in between by a straight slope and add zero for j=mo1,mo2 do begin ind=where(groundo3(j-1).foy ge foy1 and groundo3(j-1).foy le foy2,ctind) for k=0L,ctind-1 do groundo3(j-1).o3ppbv(ind(k))=(groundo3(j-1).o3ppbv(ind(k))*calstr.slope(bi))+calstr.zero(bi) endfor ; multiply by each month endelse endif else begin ;calculate when the reading was the last one and it is not 12/31 ;calculate this just in case its a leap year - if this is the last calibration this will apply to the rest of the year mo2=12 doy=ymd2dn(float(year),float(12) ,float(31)) fod=(float(23)+(60.)/60.)/24. foy2=doy+fod ;multiply the values in between by a straight slope and add zero for j=mo1,mo2 do begin ind=where(groundo3(j-1).foy ge foy1 and groundo3(j-1).foy le foy2,ctind) for k=0L,ctind-1 do groundo3(j-1).o3ppbv(ind(k))=(groundo3(j-1).o3ppbv(ind(k))*calstr.slope(bi))+calstr.zero(bi) endfor ; multiply by each month endelse endfor ; end of i end