;The procedure calsave_lc.pro saves the slope, intercept and various ;statistical properies of H2O and CO2 calibration fits found using ;calibrate_lc.pro for the Lost Creek flux tower. This rountine takes the ;existing master calibration file and adds the data to it. If the date being ;added exists, it is overwritten. ;Use is as follows: ; calsave_lc,date,ndays,corq,mandb,stats,goodflag ;Where all parameters are inputs. ;mandb and stats are determined by calfit_lc.pro ;date,ndays and corq are used to generate labels and file names. ; ;Format of mastercal file: ;[yyyy mm dd ndays ma ba m b sigmasq sigbasq sigysq delta n rsq goodflag] ;where ; yyyy = 4-digit year ; mm = month ; dd = day start day of fit ; ndays = number of days in fit ; ma,ba = slope and intercept of plot on screen ; m,b = slope and intercept for clicor and qlicor code ; m=1/ma,b=-ba/ma ; sigmasq,sigbasq,sigysq,delta = statistics from fit ; n = number of points in fit ; rsq = r^2 value of fit ; goodflag = 1 if operator said fit was good, =0 otherwise ; ;Written by BWBerger 7/27/99 - Based on calsave.pro for WLEF ;Modified by BWB 2/23/00 to use /data/davis/cheas/wcreek/data/cal/mastercal/ ; instead of /data/davis2/wcreek/data/cal/mastercal/. ;Modified by Bruce Cook - November 2000 - for use with Lost Creek pro calsave_lc,date,ndays,corq,mandb,stats,goodflag dates=strtrim(string(date),2) ;yyyymmdd date in strimg form yrss=strmid(dates,2,2) ;The short year in string form (eg '98' for 1998) yrls=strmid(dates,0,4) ;The long year in string form (eg '1998' for 1998) yrs=fix(yrss) ;The short year in integer form yrl=fix(yrls) ;The long year in integer form mos=strmid(dates,4,2) mo=fix(mos) dy=fix(strmid(dates,6,2)) julian,yrl,mo,dy,jday ;Load the existing master calibration file - call it mastercal cmd="load,'/eddy/s4/lcreek/data/cal/mastercal/"+yrls+"/mastercal_lc_"+corq+".dat',mastercal" r=execute(cmd) if jday lt jdate2(mastercal(0,0),mastercal(1,0),mastercal(2,0)) then begin ;new entry should be first entry in list mastercal=[[yrl,mo,dy,ndays,mandb,stats,goodflag],[mastercal]] endif else begin ;if new entry is not first, sort through mastercal to find where it goes sortflag=0 i=0 while sortflag ne 1 do begin if jday eq jdate2(mastercal(0,i),mastercal(1,i),mastercal(2,i)) then begin ;Overwrite if date already exists mastercal(*,i)=[yrl,mo,dy,ndays,mandb,stats,goodflag] sortflag=1 endif else begin ;does it go between the i and i+1 line? if i ne row(mastercal)-1 then begin ;can't check i+1 if i is last line if jday lt jdate2(mastercal(0,i+1),mastercal(1,i+1),mastercal(2,i+1)) then begin ;insert between i and i+1 mastercal=[[mastercal(*,0:i)],[yrl,mo,dy,ndays,mandb,stats,goodflag],[mastercal(*,i+1:row(mastercal)-1)]] sortflag=1 endif endif else begin ;i is last line and since entry didnt overwrite last ;line new entry is the new last line mastercal=[[mastercal],[yrl,mo,dy,ndays,mandb,stats,goodflag]] sortflag=1 endelse endelse i=i+1 endwhile endelse ;Save the updated mastercal cmd="saveascii3_lc,mastercal,'/eddy/s4/lcreek/data/cal/mastercal/"+yrls+"/mastercal_lc_"+corq+".dat'" r=execute(cmd) return end