;The program tablemake.pro takes data from the mastercal files and makes ;arrays (tables) containing good calibration values, long term averaged ;calibration values and a list of dates for bad calibration values. This ;is done interactively using plots of the data. Removing a bad slope value ;will also remove its corresponding intercept value and visa versa. ;Use is as follows: ; tablemake,year,lev,corq,num,mastercal,mandbfits,baddates,mandbavg,$ ; xrng,yrngm,yrngb,refdates ;Where ; | year = year for data ; | ; input | corq = 'c' for co2 or 'q' for h2o ; | num = the number of half days to average m or b over ; | mastercal = the raw calibration array ; ; | mandbfits = array of good fits remaining after weeding ; | out bad values. Format:[jdate,m,b] ; | baddates = a list of the dates for weeded out values ; | See tablemain.pro for format ; | mandbavg = a final list of averaged m and b values ; output | (averaged over num). Format:[jdate,m,b] ; | xrng = range of jdates for plotting later ; | yrngm = range of m for plotting later ; | yrngb = range of b for plotting later ; | refdates = a list of jdates for the first of each month ; ;Written by BWBerger 1999 ;Modified by BWBerger 7/12/99 to conform to new mastercal file format where ;the first column used to hold the date as yymmdd but was changed to the first ;three columns as yyyy mm dd. ;All mastercal files have been changed to use this new format - the purpose ;of the change is y2k compatibility. ;modified by weiguo Wang 11/3/99 for wcreek pro tablemake_wc,year,corq,num,mastercal,mandbfits,baddates,mandbavg,$ xrng,yrngm,yrngb,refdates top: baddates=fltarr(4,1)-999. ;initialize a baddate variable ;find where mastercal has goodflag=1 print,mastercal(14,*) ;print,mandb rg=where(mastercal(14,*) eq 1,cg) if cg eq 0 then begin print,'No good values in mastercal_wc_'+corq+'.dat' mandbfits=fltarr(3,row(mastercal))-999. baddates=[mastercal(0,*),mastercal(1,*),mastercal(2,*),fltarr(1,row(mastercal))] mandbavg=fltarr(3,row(mastercal))-999. xrng=[-999.,-999.] yrngm=[-999.,-999.] yrngb=[-999.,-999.] goto, fini endif else begin mastercaltemp=mastercal(*,rg) endelse ;find where mastercal isn't good and write to baddates rb=where(mastercal(14,*) ne 1,cb) if cb ne 0 then begin baddates=[mastercal(0,rb),mastercal(1,rb),mastercal(2,rb),mastercal(14,rb)] endif else begin baddates=[-999.,-999.,-999.,-999.] endelse ;Work on slope plot first x=jdate2(mastercaltemp(0,*),mastercaltemp(1,*),mastercaltemp(2,*))+0.5*mastercaltemp(3,*) ;the julian date of the center of the fit duration (ie if the fits ;are over two days then 1 day is added to the fit start date) y=mastercaltemp(6,*) ;the slope stopflag=0 while stopflag ne 1 do begin ;get the running average over 'num' half days of the slopes (and ;intercepts - although they are not used for anything in this loop) calrunavg2_wc,num,mastercaltemp,caltemp,mandb,mandboutd,mandboutds,table ;get ranges for plotting xmax=max(x) ;the jdate max xmin=min(x) ;the jdate min xrng=[xmin-(xmax-xmin)*.03, xmax+(xmax-xmin)*.03] ymaxm=max(y) ;the slope max yminm=min(y) ;the slope min yrngm=[yminm-(ymaxm-yminm)*.03, ymaxm+(ymaxm-yminm)*.03] ;get an array of firsts of the month to use for reference lines in plots yrls=strtrim(string(year),2) refdates=jdate(long(yrls+['0101','0201','0301','0401','0501','0601','0701','0801','0901','1001','1101','1201'])) ;Plot the slopes plot,x,y,$ psym=2,xrange=xrng,yrange=yrngm,xstyle=1,ystyle=1,$ title='m'+corq, ytitle='m'+corq oplot,mandboutds(0,*),mandboutds(1,*) refline,1,0,refdates,0 ;Remove bad points print,'Do you wish to remove points: y/n?' remove='' read,remove if remove eq 'y' then begin wshow,0 wset,0 print,'Place cursor on point to be discarded and press Enter.' ent='' read,ent cursor,xbad,ybad,0,/data ;Couldn't get mouse to work any other way with pc sweep=1. ;Loop through data set looking for point cursor was on for i=0L,len(x)-1 do begin ;If cursor is within a certain square (approx) area surrounding ;a point, make point a badval. 104 and 84 divisors gives about 1/16 in ;inch divisions for plot axis size of 6.5 and 5.25 inches for ;x and y axes, respectively. So, when sweep equals 1 the cursor ;should be within about 1/16 in from a point to remove it (them). ;Sweep changes this number linearly. if (abs(x(i)-xbad) lt sweep*(xrng(1)-xrng(0))/104.) and (abs(y(i)-ybad) lt sweep*(yrngm(1)-yrngm(0))/84.) then begin x(i)=-9999. y(i)=-9999. baddates=[[baddates],[mastercaltemp(0,i),mastercaltemp(1,i),mastercaltemp(2,i),1]] mastercaltemp(0,i)=-9999. endif endfor ;Find where flags are placed in x,y and mastercaltemp and remove rx=where(x ne -9999.,cx) if cx ne 0 then begin x=x(rx) endif ry=where(y ne -9999.,cy) if cy ne 0 then begin y=y(ry) endif rmast=where(mastercaltemp(0,*) ne -9999.,cmast) if cmast ne 0 then begin mastercaltemp=mastercaltemp(*,rmast) endif endif else begin ;No point removal requested print,'Is slope curve acceptable: y/n?' print,'Answering yes will advance program to intercept.' ent='' read,ent if ent eq 'y' then begin stopflag=1 endif else begin print,'Do you wish to start over with all points: y/n?' ent='' read,ent if ent eq 'y' then begin goto, top endif endelse endelse endwhile ;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& ;intercepts x=jdate2(mastercaltemp(0,*),mastercaltemp(1,*),mastercaltemp(2,*))+0.5*mastercaltemp(3,*) ;jdate (same as before) y=mastercaltemp(7,*) ;intercept stopflag=0 while stopflag ne 1 do begin ;get the running average of the slopes and intercepts - (only the intercepts ;are used for the plots, but the running average of both slopes and ;intercepts are output if plot is acceptable). calrunavg2_wc,num,mastercaltemp,caltemp,mandb,mandboutd,mandboutds,table ;get ranges for plotting xmax=max(x) xmin=min(x) xrng=[xmin-(xmax-xmin)*.03, xmax+(xmax-xmin)*.03] ymaxb=max(y) ;max of intercept yminb=min(y) ;min of intercept yrngb=[yminb-(ymaxb-yminb)*.03, ymaxb+(ymaxb-yminb)*.03] ;Plot the intercepts plot,x,y,$ psym=2,xrange=xrng,yrange=yrngb,xstyle=1,ystyle=1,$ title='b'+corq, ytitle='b'+corq oplot,mandboutds(0,*),mandboutds(2,*) refline,1,0,refdates,0 ;Remove bad points print,'Do you wish to remove points: y/n?' remove='' read,remove if remove eq 'y' then begin wshow,0 wset,0 print,'Place cursor on point to be discarded and press Enter.' ent='' read,ent cursor,xbad,ybad,0,/data ;Couldn't get mouse to work any other way with pc sweep=1. ;Loop through data set looking for point cursor was on for i=0L,len(x)-1 do begin ;If cursor is within a certain square (approx) area surrounding ;a point, make point a badval. 104 and 84 divisors gives about 1/16 in ;inch divisions for plot axis size of 6.5 and 5.25 inches for ;x and y axes, respectively. So, when sweep equals 1 the cursor ;should be within about 1/16 in from a point to remove it (them). ;Sweep changes this number linearly. if (abs(x(i)-xbad) lt sweep*(xrng(1)-xrng(0))/104.) and (abs(y(i)-ybad) lt sweep*(yrngb(1)-yrngb(0))/84.) then begin x(i)=-9999. y(i)=-9999. baddates=[[baddates],[mastercaltemp(0,i),mastercaltemp(1,i),mastercaltemp(2,i),2]] mastercaltemp(0,i)=-9999. endif endfor ;Find where flags are placed in x,y and mastercaltemp and remove rx=where(x ne -9999.,cx) if cx ne 0 then begin x=x(rx) endif ry=where(y ne -9999.,cy) if cy ne 0 then begin y=y(ry) endif rmast=where(mastercaltemp(0,*) ne -9999.,cmast) if cmast ne 0 then begin mastercaltemp=mastercaltemp(*,rmast) endif endif else begin ;No point removal requested print,'Is intercept curve acceptable: y/n?' print,'Answering yes will advance code to plot and/or save if requested.' ent='' read,ent if ent eq 'y' then begin stopflag=1 endif else begin print,'Do you wish to start over with all points: y/n?' print,'If yes, you must start with slope curve then intercept curve.' ent='' read,ent if ent eq 'y' then begin goto, top endif endelse endelse endwhile mandbavg=mandboutds mandbfits=[jdate2(mastercaltemp(0,*),mastercaltemp(1,*),mastercaltemp(2,*))+0.5*mastercaltemp(3,*),mastercaltemp(6,*),mastercaltemp(7,*)] ;sort the baddates if baddates(0,0) ne -999. then begin if row(baddates) ne 1 then begin rsort=sort(jdate2(baddates(0,*),baddates(1,*),baddates(2,*))) baddates=baddates(*,rsort) endif endif fini: return end