; this function is designed to return an array
; of the contaminant concentrations of a
; given chemical for a given cell
; three variables are passed
; to the procedure, c_id, s_time, and chemical
; the array gives the mass and elevation for the cell
function cont_conc, c_id, s_time, chemical
;remember to put each variable in quotes
; c_id = a one character designation for the cell
; s_time = sampling time pre or post
; chemical = chemical abreviation which you want to
; determine the contaminant mass
env_handle=ODBC_INIT()
;connect to database
access_id=ODBC_CONNECT(env_handle,'MS Access 97 Database','Admin/')
cell = string(c_id, Format='(A1)')
;print, cell
;print, s_time
;print, chemical
;
;data required to make the sample have any value
;one needs to know at a minimum;
;field_vial_water_mecl_wt, and field_vial_water_mecl_solid_wt
;we will assume that concentrations that are not reported
;are nulls can be considered to be 0.0001 a number above
;zero was selected to permit doing a log transformation
;
data_sel = "SELECT northing,easting,elevation,sample_top,sample_bottom"+$
" ,lab_vial_water_wt, lab_vial_water_mecl_wt, "+$
" field_vial_water_mecl_wt,field_vial_water_mecl_solid_wt,"+$
" wet_wt_solid,dry_wt_solid,sample_category"
data_sel = data_sel + ", " + chemical
data_sel = data_sel + " FROM tblObjects_locations "+$
" INNER JOIN (tblCore_samples INNER JOIN tblCore_sample_chemistry "+$
" ON tblCore_samples.sample = tblCore_sample_chemistry.sample) ON (tblObjects_locations.key = "+$
" tblCore_samples.tblkey) AND (tblObjects_locations.key = tblCore_sample_chemistry.tblkey) "+$
" where "+$
" elevation is not null and field_vial_water_mecl_wt is not null"+$
" and field_vial_water_mecl_solid_wt is not null"
data_sel = data_sel + ' and tblCore_sample_chemistry.cell_id = ' + "'" + cell +"'"
data_sel = data_sel + ' and sample_category like '
data_sel = data_sel + "'%"+s_time+"%'"+ "ORDER BY elevation"
;print, data_sel
borings=odbc_sql(access_id, data_sel)
;info
on_error_GOTO, finish
;put borings data into arrays
boringsarrayx=borings.easting
boringsarrayy=borings.northing
boringsarrayz=borings.elevation-((borings.sample_top + borings.sample_bottom)/2)
boringsarraylww= borings.lab_vial_water_wt
boringsarraylwmw = borings.lab_vial_water_mecl_wt
boringsarrayfwmw = borings.field_vial_water_mecl_wt
boringsarrayfwmsw = borings.field_vial_water_mecl_solid_wt
boringsarraywws = borings.wet_wt_solid
boringsarraydws = borings.dry_wt_solid
;
; assume laboratory weights determine amount of mecl present
; and field weights determine the amount of soil and moisture in soil
;
;
;The chemical concentration is in the 13 field of data so
;use the tag index to eatract the correct field for chemical
;concentration (field-1 or 12)
;
bchem=borings.(12)
;print, bchem
;determine number of observations
xx=size(borings)
lastrow=xx(1)
for i = 0,lastrow - 1 do begin
;print, i
if bchem(i) eq 0.0 then bchem(i)= 0.000100
;print,bchem(i),boringsarraylww(i),boringsarraylwmw(i),boringsarrayfwmsw(i)
if boringsarraylwmw(i) eq 0.0 $
and boringsarraydws(i) ne 0.0 then begin
bchem(i)=$
bchem(i)*(boringsarrayfwmw(i) - $
boringsarraylww(i)) / ((boringsarrayfwmsw(i) - $
boringsarrayfwmw(i))*boringsarraydws(i) $
/boringsarraywws(i))
goto, jump1
endif $
else if boringsarraylwmw(i) eq 0.0 then begin
bchem(i)=$
bchem(i)*(boringsarrayfwmw(i) - $
boringsarraylww(i)) / ((boringsarrayfwmsw(i) - $
boringsarrayfwmw(i))*1.1)
goto, jump1
endif $
else if boringsarraydws(i) ne 0.0 then begin
bchem(i)=$
bchem(i)*(boringsarraylwmw(i) - $
boringsarraylww(i)) / ((boringsarrayfwmsw(i) - $
boringsarrayfwmw(i))*boringsarraydws(i) $
/boringsarraywws(i))
goto, jump1
endif else begin
bchem(i)=$
bchem(i)*(boringsarraylwmw(i) - $
boringsarraylww(i)) / ((boringsarrayfwmsw(i) - $
boringsarrayfwmw(i))*1.1)
endelse ;end of else clause
jump1: ;print,bchem(i)
endfor
;
; this should have created an array of values in bchem which
; is all of the masses on a soil weight basis for the given
; sampling period and given cell for the contaminant of choice
;create an empty array that is (4,n) in size
conc=dblarr(4,lastrow)
conc(0,*)=bchem
conc(1,*)=boringsarrayx
conc(2,*)=boringsarrayy
conc(3,*)=boringsarrayz
ODBC_DISCONNECT, access_id
return, conc
finish:
;info
end