PRO surf_calibrations,site, year ;set up plots to screen ;DEVICE, decomp=0 ;!p.background=255 ;!p.color=0 ;get site information ground_site_lookup,site,info_str path= info_str.processed_data_loc folder= StrJoin(StrSplit(path,'year_str',/extract,/REGEX),STRmid(year,2,2)) ;infile is the cal file that's been edited infile=dialog_pickfile(path=folder,filter='*cal*dat') OPENR, lun, infile, /get_lun ;open the file to read in ;grab calibration chunks strings='' cal=0 timeint=0 ;set to zero- minutes btwn measurements minslasttime='0';init. the mins from the last two readings WHILE ~EOF(lun) DO BEGIN READF,lun,strings print, strings strext=STRSPLIT(strings,' ',/extract) IF STRCOMPRESS(strings,/remove) EQ '' OR strext(0) EQ '#j' OR strext(0) EQ '#g'$ OR N_ELEMENTS(strext) EQ 4 THEN GOTO, skiptonextpt ;if I paste in values in the calibration, they will get caught in the calibration section ; just put them in between # ;find the beginning of a calibration IF strext(0) EQ '#b' THEN BEGIN cting=0l calarray=fltarr(300)*!Values.f_nan ;make this a subroutine flag='beg' WHILE flag NE '#e' DO BEGIN READF,lun,strings flag=STRCOMPRESS(strext(0),/remove) strext=strsplit(strings,' ',/extract) IF N_ELEMENTS(strext) LE 1 THEN GOTO, skiptocal ;print, strext ;if there is a #c in front IF STRCOMPRESS(strext(0),/remove) EQ '#c' THEN BEGIN flag=STRCOMPRESS(strext(0),/remove) stnid=STRCOMPRESS(strext(1),/remove) yyyys=STRCOMPRESS(strext(2),/remove) mms=STRCOMPRESS(strext(3),/remove) month=long(mms) dds=STRCOMPRESS(strext(4),/remove) hhs=STRCOMPRESS(strext(5),/remove) mins=STRCOMPRESS(strext(6),/remove) IF minslasttime NE '0' THEN timeint=long(mins)-long(minslasttime) minslasttime=mins o3vals=STRCOMPRESS(strext(7),/remove) ENDIF ELSE BEGIN ;this is the case WHERE I just pased it in? ;if STRCOMPRESS(strext(0),/remove) ne '#c' 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 minslasttime NE '0' THEN timeint=long(mins)-long(minslasttime) minslasttime=mins o3vals=float(strext(3)) flags=strext(2) month=long(mms) ENDELSE calarray(cting)=o3vals cting=cting+1 ENDWHILE ; while flag does not eq '#' which signals the end of the cal skiptocal: calarray=calarray(where(finite(calarray))) calarray=calarray(sort(calarray)) ;calculate the slope ; if there are more than a certain number of points and it's a one minute interval indlev1= WHERE(abs(calarray) lt (calarray(0) + 5.0),ctind) ; give a window of 2 on either side of value ;print, 'indleve1', indlev1 IF (timeint EQ 5 or timeint EQ 0 or Timeint EQ -55) AND ctind EQ 0 THEN indlev1=0 otherlevs=WHERE(calarray gt (calarray(0)+10.0)) meansTEI=fltarr(10)-999 stddevTEI=fltarr(10)-999 meansTEI(0)=mean(calarray(indlev1)) IF ctind EQ 1 THEN stddevTEI(0)='NaN' ELSE stddevTEI(0)=STDDEV(calarray(indlev1)) IF abs(timeint) EQ 5 or timeint eq 10 OR timeint EQ -55 THEN BEGIN ;if there is a 5-minute calibration IF site EQ 'BAO' AND year NE '2009' THEN BEGIN ;THIS WAS put in here bc the interval changes during 2009 indstart=otherlevs(0);indlev1(0) endind=otherlevs(n_elements(otherlevs)-1) ;print, 'indstart=',indstart if indstart eq 15 then stop ENDIF ELSE BEGIN indstart=otherlevs(0+1) endind=indstart+n_elements(otherlevs)-3 ;print, 'here' ENDELSE ENDIF ELSE BEGIN indstart=otherlevs(0+2) endind=indstart+n_elements(otherlevs)-3 ENDELSE mind=1 WHILE indstart lt endind do BEGIN TEI_Sub=calarray(indstart:endind) indlev= WHERE(TEI_Sub lt (calarray(indstart)+10.0) and TEI_sub gt (calarray(indstart)-10.0),ct) ;print, calarray(indlev) if ct eq 0 then meansTEI(mind)= TEI_sub(indlev) else meansTEI(mind)=mean(TEI_Sub(indlev)) if mind ge 1 then if meansTEI(mind) eq meansTEI(mind-1) then stop if n_elements(indlev1) eq 1 then stddevTEI(mind)='NaN' else stddevTEI(mind)=stddev(calarray(indlev1)) if timeint eq 5 or timeint eq -55 then indstart=indstart+ct+1 else indstart=indstart+ct+3 mind=mind+1 ;print, indstart ENDWHILE ab=WHERE(meansTEI gt -100,pts) surfo3=meansTEI(ab) vals=surfo3 ;print, 'surfo3', surfo3 if cal eq 0 then begin data={surfo3:fltarr(15)*!values.F_nan} calstruc=replicate(data,100) endif ; if n_elements(surfo3) eq 2 then stop calstruc(cal).surfo3=surfo3 help, surfo3 ;then find the file that has the values for site and year in it ;if strupcase(groundo3(0).site_code) eq 'WKT' then if FLOAT(mms) gt 12 then stop ;mms is the real month number string monthnum_to_monthstring,mms,monstr if cal ge 1 then begin ;window,cal-1 x=calstruc(cal-1).surfo3(where(finite(calstruc(cal-1).surfo3),xe)) y=calstruc(cal).surfo3(where(finite(calstruc(cal).surfo3),ye)) If xe ne ye then begin ynew=fltarr(xe)*!Values.f_nan xnew=fltarr(xe)*!Values.f_nan ctx=0 for ft=0,xe -1 do begin ind=WHERE(y gt x(ft) -5 and y lt x(ft)+5,inct) if inct ne 0 then begin ynew(ctx)=y(ind) xnew(ctx)=x(ft) ctx=ctx+1 endif endfor y=ynew(where(finite(ynew))) x=xnew(where(finite(xnew))) ENDIF print, x print,y coef= linfit(x,y,yfit=yfit) if abs(coef(1)) eq 1 then stop xra=[min(calstruc(cal-1).surfo3),max(calstruc(cal-1).surfo3)] ;plot, calarray,yfit,color=40,TITLE=monstr+' '+dds + year, $ ;ytitle='O!I3!N (ppbv) '+site+' TEI',xrange=xra+20,xstyle=1,$ ;ystyle=1,yrange=xra+20,xtitle='O!I3!N Last (ppbv)',psym=4; ;oplot, calstruc(cal).surfo3, yfit,color=130,psym=4 ;for i=0,cal oplot, calstruc(i).surfo3, calstruc(i).surfo3,color=130 ;calculate the slope between the last calibration ;xyouts, .75,.75,STRCOMPRESS(coef(0),/rem)+' '+STRCOMPRESS(coef(1),/rem),/normal ;oplot, nist,(surfo3+coef(0))*coef(1),color=75 ; finish if have a cal ;read in older calibration values endif ; if there's more than one calibration openr,2,folder+strlowcase(site)+'chd'+STRMID(year,2,2) ;print, folder string10='' while ~EOF(2) do begin readf, 2, string10 ;print, string10 strext10=strsplit(string10,' ',/extract) if n_elements(strext10) ne 1 and STRCOMPRESS(strext10(0),/remove) ne '' then string2=string10 ENDWHILE close, 2 openw, 3,folder+strlowcase(site)+'chd'+STRMID(year,2,2),/append ;print,'string2',string2 strext2=strsplit(string2,' ',/extract) ;3480110 2 2431 1 1.032 1 0.72 TEI5028 ;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) inst=STRMID(strext2(0),0,3) instid=strext2(7) yy=STRMID(year,2,2) if cal ge 1 then sl=coef(1) else sl=1.000 printf,3,format='(A3,A2,A2,2x,A1,1x,A2,A2,8x,A1,2x,f5.3,2x,A1,1x,f5.2,3x,A7)',$ inst,mms,yy,'2',hhs,dds,'1',sl,'1', calstruc(cal).surfo3(0),instid close, 3 ;use a counter to know how many cals there have been cal=cal+1 endif skiptonextpt: ENDWHILE ; while not the end of file close,lun,/force free_lun, lun end