;------------------------------------------------------------------------------ ; The procedure CALIBRATE_LC.PRO puts calibration plots on screen for ; checking and badval removing, and gives out slope and intercepts for the ; CO2 and H2O calibration over a selected time period. It also prints ; the plots to files if desired. ; Use it as follows: ; calibrate_lc ; ; Input: All input is prompted from the operator. It is: ; startdate = the date to start calibration fit (yyyymmdd integer) ; ndays = the number of days over which to do the fit ; plt = 1 if you want plots of the fits printed to files, 0 otherwise ; Files are written to: ; /eddy/s4/lcreek/data/cal/plots/19XX/fityyddd.ps ; /eddy/s4/lcreek/data/cal/plots/19XX/fityyddd.ps ; sav = 1 to modify the master calibration files, 0 otherwise ; gis = 1 if operator is running program from a GIS terminal ; = 0 if operator is running program from a PC ; When removing unwanted points from the fit, this makes the ; mouse work best for the computer being used. ; ; Master calibration files are: ; /eddy/s4/lcreek/data/cal/mastercal/19XX/mastercallc_S.dat ; where S=c for CO2 or =q for H2O calibrations; ; if sav=1 then plt=1 automatically - i.e. anytime ; a fit is saved to the mastercal tables a plot ; must be made as a record. ; ; Written by BWBerger 6/23/99 - Code is modified version of calibrate.pro ; used for WLEF ; ; Modified by Dana P Carrington, June 1999, for use with Willow Creek data. ; Modified by BWBerger 3/16/00 to allow h2o fit to take place if ; only co2 data is bad or not available. ; Modified by Bruce Cook - November 2000 - for use with Lost Creek ;------------------------------------------------------------------------------ pro calibrate_lc print,'Enter start date in yyyymmdd format:' startdate=0L read,startdate if startdate lt 19900000L then begin print,'Sorry. Please enter start date in 4-digit year format: yyyymmdd.' goto,fini endif print,'Enter number of days to do fit over:' ndays=0 read,ndays print,'Do you wish to save plots: y/n?' plt='' read,plt if plt eq 'y' then begin plt=1 endif else begin plt=0 endelse print,'Do you wish to save fit results to mastercal files: y/n?' sav='' read,sav if sav eq 'y' then begin sav=1 if plt ne 1 then begin print,'Note: Plots are automatically saved if fits are saved to mastercal files.' plt=1 endif endif else begin sav=0 endelse print,'Are you running this code from a GIS terminal: y/n?' print,'(Enter n if you are running from a PC)' gis='' read,gis if gis eq 'y' then begin gis=1 endif else begin gis=0 endelse ;Set up windows for viewing window,0 window,1 if sav eq 1 then begin print,'You have requested that calibrations be saved to mastercal tables.' print,'Plots are being saved even if you have set plt=0' plt=1 endif date = startdate top: ;Get strings and integers related to the date chosen yyyymmdd = strtrim(string(date),2) ;string of startdate yrss = strmid(yyyymmdd,2,2) ;string of 2-digit year yrls = strmid(yyyymmdd,0,4) ;string of 4-digit year yrl=fix(yrls) ;integer of 4-digit year jday = jdate(date) ;integer jday print,'Fit Start Date:' print,'yyyymmdd=',yyyymmdd print,'jday=',jday ;initialize the halt program flag hltprgm=0 ;------------------------------------------------------------------------------ ; Data ; cv,qv - the licor voltages for co2 and h2o ; pl,tl - the licor pressure (mb) and temperature (C) ; cs,w - `slow' co2 and h2o mixing ratio from Vaisala ; r - a vector of indicies telling where all the good data are ; tm - the time vector (in seconds from the start time) ; Load the data calload_lc,jday,yrss,ndays,cv,qv,pl,tl,w,cs,tm,hltprgm r_h2o = where ((qv ne -999.) and (pl ne -999.) and (tl ne -999.) and (w ne -999.), ct_h2o) if (ct_h2o eq 0) then begin print, 'There are no good h2o data points for the given days.' print, 'Fit cannot be done for h2o or co2 for these days.' goto, startagain endif r_co2 = where ((cv ne -999.) and (qv ne -999.) and (pl ne -999.) and (tl ne -999.) and (cs ne -999.) and (w ne -999.), ct_co2) if (ct_co2 eq 0) then begin print, 'There are no good co2 data points for the given days.' print, 'Only h2o will be fitted.' endif ;------------------------------------------------------------------------------ ; This lets user choose a new date - see bottom of this prgm ;if hltprgm eq 1 then begin IF ct_h2o EQ 0 AND ct_co2 EQ 0 THEN begin print,'DATA PROBLEMS FOR DATES CHOSEN' goto, startagain endif ;------------------------------------------------------------------------------ tref=273.15 pref=1000. qref=0. cref=0. fitagain: ; Now ready to do fits ; H20 print,'Fitting H2O' calfit_lc,gis,date,jday,yrss,ndays,tm,'q',qv,w,pl,pref,tl,tref,qref,r_h2o,w,$ mandb_q,stats_q,x_q,y_q,xev_q,yev_q,xrng_q,yrng_q,goodflag_q if ct_co2 ne 0 then begin ; C02 print,'CO2' calfit_lc,gis,date,jday,yrss,ndays,tm,'c',cv,w,pl,pref,tl,tref,cref,r_co2,cs,$ mandb_c,stats_c,x_c,y_c,xev_c,yev_c,xrng_c,yrng_c,goodflag_c endif else begin mandb_c=[-999.,-999.,-999.,-999.] stats_c=[-999.,-999.,-999.,-999.,-999.,-999.] x_c=-999. y_c=-999. xev_c=-999. yev_c=-999. xrng_c=[-1000,-990] yrng_c=[-1000,-990] goodflag_c=0 endelse ; See if you want to re-run the fits print,'Would you like to re-run the fits: y/n?' print,'Note:If yes, CO2 and H2O must both be refitted this date.' redo='' read,redo if redo eq 'y' then begin goto, fitagain endif ;*************************************************************** ;Plot fits in .ps file. if plt eq 1 then begin count=1 counttot=2 calplot_lc,date,ndays,'q',count,counttot,$ mandb_q,stats_q,x_q,y_q,xev_q,yev_q,xrng_q,yrng_q,goodflag_q calplot_lc,date,ndays,'c',count,counttot,$ mandb_c,stats_c,x_c,y_c,xev_c,yev_c,xrng_c,yrng_c,goodflag_c endif ;**************************************************************** ; Save calibrations to mastercal files if desired. if sav eq 1 then begin calsave_lc,date,ndays,'q',mandb_q,stats_q,goodflag_q calsave_lc,date,ndays,'c',mandb_c,stats_c,goodflag_c endif startagain: print, 'Do you wish to continue with the next '+strtrim(string(ndays),2)+' days of data: y/n?' ent='' read,ent if ent eq 'y' then begin date=jdatetodate(jday+ndays,yrl) goto,top endif else begin print, 'Do you wish to continue with another date of your choice: y/n?' ent2='' read,ent2 if ent2 eq 'y' then begin print,'Enter new start date.' read,date print,'Enter number of days to fit.' read,ndays goto,top endif endelse fini: return end