; Working directory: c:\Projects\PV_wave_code

; Date: Tue Feb 10 13:59:01 1998

;last edited by CGE 2/12/98

pro plot_ew,c_id,c_des,chem,chem_name,ext_loc,n_extractors

tek_color

cell = string(c_id, Format='(A1)')

ext_loc=string(ext_loc)

n_extractors=fix(n_extractors)

c_id=string(c_id)

c_des=string(c_des)

chem=string(chem)

chem_f=chem+'_flag'

chem_name=string(chem_name)

string_t='Cell '+c_id+' '+c_des+' Chemical '+chem_name

 

env_handle=ODBC_INIT()

;connect to database

access_id=ODBC_CONNECT(env_handle,'MS Access 97 Database','Admin/')

;determine maximum concentration and if there is sufficient

;data to plot or analyze

data_sel = "SELECT cell_id,object_type,test_type"

data_sel = data_sel + ", " + chem ; concentration is in mg/l

data_sel = data_sel + " FROM tblFluid_sample_chemistry"+$

" where "

data_sel = data_sel + ' cell_id = ' + "'" + cell +"'"

data_sel = data_sel + ' and object_type =' + "'" + ext_loc +"'"

data_sel = data_sel + ' and start_date_time is not null'

data_sel = data_sel + ' and test_type like '

data_sel = data_sel + "'%"+"rt"+"%'"

effluent=odbc_sql(access_id, data_sel)

ON_ERROR_GOTO, finish

if N_Elements(effluent) lt 5 then goto, finish

sum_conc=sum(effluent.(3),0); sums concentrations

;print, sum_conc

if sum_conc LT 1. then goto, finish ; ignore samll amounts

max_conc=max(effluent.(3))

;print, max_conc, 'max concentration'

;finished determining maximum concentration it is now time to colect data for evaluation

Window,0,XSize=1000,YSize=900

!P.Multi = [0,1,2,0,0]

for i = 1, n_extractors DO BEGIN

print, ' well ',i

counter=string(i)

counter = strtrim(counter,2)

data_sel = "SELECT cell_id,object_type,object_id,test_type,start_date_time"

data_sel = data_sel + ", " + chem +", " +chem_f

data_sel = data_sel + " FROM tblFluid_sample_chemistry"+$

" where "

data_sel = data_sel + ' cell_id = ' + "'" + cell +"'"

data_sel = data_sel + ' and object_type =' + "'" + ext_loc +"'"

data_sel = data_sel + ' and object_id =' + "'" + counter +"'"

data_sel = data_sel + ' and start_date_time is not null'

data_sel = data_sel + ' and test_type like '

data_sel = data_sel + "'%"+"rt"+"%'"

effluent=odbc_sql(access_id, data_sel)

conc=effluent.(5)

flag=effluent.(6)

;print,flag

;print, 'flag'

; set conc = 0.0001 if there is a flag equal to bdl

for m=0,N_Elements(flag)-1 DO BEGIN

if flag(m) eq 'bdl' then conc(m)=0.0001

if flag(m) eq 'bql' then conc(m)=0.0001

;print, flag(m),conc(m)

endfor

da_time=string(effluent.start_date_time)

; da_time is in Access format and must be converted to Wave

; format before use

lastrow=n_elements(da_time)

s_day=today()

date_time=dtgen(s_day,n_elements(da_time),hour=1)

;info

for j=0, lastrow-1 do begin

date_time(j)=time_conv(da_time(j))

endfor

conc_data= BUILD_TABLE('conc,date_time')

conc_data=QUERY_TABLE(conc_data,'* Order By date_time')

;info, /Structure, conc_data

data=QUERY_TABLE(conc_data, '* where conc ne "0"')

;create a master data table for the interpolated results

tarray=data.date_time

stime=min(tarray.Julian); start time

etime=max(tarray.Julian); end time

j_tarray=tarray.Julian ; Julian time is in days

carray=data.conc

t_min=tarray(0)

t_max=tarray(N_Elements(tarray)-1)

e_t=dt_duration(t_max,t_min)

n_hrs=fix(e_t*24) ; determine elapsed time in hours

if i eq 1 then begin

plot, data.date_time, data.conc, Psym=4, /box, color = (i-1)*2,$

background=255,YTitle='CONCENTRATION (mg/l)',$

Title=string_t,YCharsize=1.2,XCharsize=1.2, YStyle=8,$

XMargin=[15,10],Yrange=[0,max_conc],$

DT_range=[stime,etime]

master_conc=findgen(n_hrs,n_extractors*3)

master_conc(*,*)=0

endif

if i gt 1 then begin

print, "i gt 1 = ", i

oplot, data.date_time, data.conc, Psym = (4+i), color = (i-1)*2

endif

;create a time vector to to evaluate a spline fit to the

;data

spline_t=dtgen(t_min,n_hrs,hour=1)

j_spline_t=spline_t.Julian

;print, j_spline_t

int_conc=interpol(carray,j_tarray,j_spline_t)

; make sure there are no negative values

for m=0, N_Elements(int_conc)-1 DO BEGIN

if int_conc(m) LT 0. then int_conc(m) = 0.

endfor

oplot,spline_t,int_conc,color=(i-1)*2

n_times= N_Elements(master_conc)/(3*N_extractors)

;print, n_times

if N_Elements(int_conc) lt n_times then n_times = N_Elements(int_conc)

;print, n_times

for k = 0, n_times-1 DO BEGIN

;print, k, ' ',N_Elements(int_conc), ' ',N_Elements(j_spline_t)

;print, int_conc(k),j_spline_t(k),k

master_conc(k,i-1)=int_conc(k)

master_conc(k,i-1+n_extractors)=j_spline_t(k)

endfor

for k = 0, N_Elements(master_conc)/(n_extractors*3)-1 do begin

;print, master_conc(k,0),master_conc(k,1),master_conc(k,2),master_conc(k,3),master_conc(k,4),master_conc(k,5),master_conc(k,6),master_conc(k,7),master_conc(k,8)

endfor

endfor

;info, master_conc

 

;get the data for the fluid fluxes

for i = 1, n_extractors DO BEGIN

counter=string(i)

counter = strtrim(counter,2)

data_sel = "SELECT cell_id,object_type,object_id,test_type,"+$

"measurement_date_time,flux_rate"

data_sel = data_sel + " FROM tblFluid_flux"+$

" where "

data_sel = data_sel + ' cell_id = ' + "'" + cell +"'"

data_sel = data_sel + ' and object_type =' + "'" + ext_loc +"'"

data_sel = data_sel + ' and object_id =' + "'" + counter +"'"

data_sel = data_sel + ' and measurement_date_time is not null'

data_sel = data_sel + ' and test_type like '

data_sel = data_sel + "'%"+"rt"+"%'"

;print, data_sel

flux=odbc_sql(access_id, data_sel)

ON_ERROR_GOTO, finish

da_time=string(flux.measurement_date_time)

lastrow=n_elements(da_time)

s_day=today()

date_time=dtgen(s_day,n_elements(da_time),hour=1);set up initialized date_time array

flux_d=flux.flux_rate

 

;info

for j=0, lastrow-1 do begin

date_time(j)=time_conv(da_time(j))

endfor

flux_data= BUILD_TABLE('flux_d,date_time')

flux_data=QUERY_TABLE(flux_data,'* Order By date_time')

;info, /Structure, flux_data

data=flux_data

for j = 0, N_ELEMENTS(data)-1 do begin

print, data(j)

endfor

if i eq 1 then begin

;put the second y axes on the graph

; AXIS, YAxis=1, YStyle=1, YTitle='FLUID FLUX (l/min)',color=(i-1)*2,$

; YRange =[0,1.2*MAX(flux_d)],$

; /save,charsize=1.2,thick=2

plot, data.date_time, data.flux_d, Psym=4,YCharsize=1.2,XCharsize=0.1, YStyle=8,$

XMargin=[15,10],YMargin=[10,1],$

YTitle='FLUID FLUX (l/min)',YRange =[0,1.2*MAX(flux_d)],$

DT_range=[min(master_conc(*,3)),max(master_conc(*,3))],$

color=(i-1)*2,linestyle=2

endif

if i gt 1 then begin

oplot, data.date_time, data.flux_d, Psym = (4+i),$

color = (i-1)*2,linestyle=2

endif

farray=data.flux_d

;farray=smooth(farray,3)

tarray=data.date_time

j_tarray=tarray.Julian

;determine if time array is monotonic it has already been ordered by date_time

;so should be increasing if not monotonic make it by adding a small amount

;to the time

for m=0, N_Elements(j_tarray)-2 DO BEGIN

if j_tarray(m) EQ j_tarray(m+1) then j_tarray(m+1)=j_tarray(m+1)+0.00001

endfor

;use the interpretation times that were generated for the first concentration

;data

int_t=master_conc(*,n_extractors)

;print,int_t

;int_flux=spline(j_tarray,farray,int_t,8) ;this is an hourly interpretation of flux

int_flux = interpol(farray,j_tarray,int_t)

; make sure there are no negative values

for m=0, N_Elements(int_flux)-1 DO BEGIN

if int_flux(m) LT 0. then int_flux(m) = 0.

if int_flux(m) GT max(farray) then int_flux(m) = max(farray)

endfor

;print, int_flux

oplot,spline_t,int_flux,color=(i-1)*2,linestyle=2

n_times= N_Elements(master_conc)/(3*N_extractors)

;print, n_times

if N_Elements(int_conc) gt n_hrs then n_times = n_hrs

;print, n_times

for k = 0, n_times-1 DO BEGIN

;for k = 0, N_Elements(int_conc)-1 DO BEGIN

master_conc(k,i-1+2*n_extractors)=int_flux(k)

endfor

;print,conc

 

endfor

 

;print, master_conc

 

;info

ODBC_DISCONNECT, access_id

mass_ext=findgen(n_hrs)

for i=0, n_extractors-1 DO BEGIN

mass_ext=(master_conc(*,i)*master_conc(*,i+2*N_extractors)*0.06)

;flow rates are in l/m, concentration mg/l and each value represents 1 hr

mass_e=sum(mass_ext,0)

;print, mass_e

;info

str_mass=string(mass_e)

well=string(i+1)

strmass= 'Mass Extracted from well '+well+' = '+str_mass+' g'

strmass=strcompress(strmass)

;postmass=string(mass1,Format='(E9.1)')

;stringpost='Post-Remdiation mass(g)= '+postmass

;stringpost=strcompress(stringpost)

zval=float(0.1-(i*0.02))

xyouts,.1,zval,strmass, /normal, color=2*i

endfor

finish:

end