
subroutine scigrow(unit_output,chemname,application_rate,number_of_apps,koc,metabolic_halflife,conc )
!********************************************************
!this subroutine is the scigrow calculator, called from main interface
!SCIGROW is a program to calculate worst case groundwater
!concentrations of pesticides arising from maximum
!allowable labeled rate uses in areas with groundwater
!that is exceptionally vulnerable to contamination 
!file is scigrow.f90
!************************************************
!VERSION 2.3   originally coded by dfy: July 28 2003
!List of Modifications: none
!********************************************************
implicit none

integer,intent(in)  :: unit_output						!unit number of output file
character(len = 256),intent(in) :: chemname				!pesticide name
real, intent(in)				:: number_of_apps		!number of applications
real, intent(in)				:: application_rate		!lb/acre
real, intent(in)				:: koc					!Koc (ml/g)
real, intent(in)				:: metabolic_halflife	!aerobic soil half life (days)
real, intent(out)			:: conc					!output in ppb

!local variables
real		 :: total_pesticide_use						!total pestide use per year
real		 :: C,D,F									!intermediate variables used in calcs
real		 :: RILP									!see scigrow docs, relative intrinsic leaching potential
real		 :: normalized_conc
integer		 :: disclaimer								!high koc disclaimer flag
character(1) :: note									!star for disclaimer note
							
integer :: date_time(8)								!used for actual time of run in output
character (len = 12) :: real_clock(3)				!used for actual time of run in output


!****** half life dependent conditions***********************
D = log10(KOC + 5.)


if  (metabolic_halflife < 6.)then
	C = log10(metabolic_halflife/6.)
	RILP= C * D

else if(metabolic_halflife <=1500. .AND. metabolic_halflife >= 6.) then
	C = log10(metabolic_halflife-5.)
	RILP = C * (4-D)

else if (metabolic_halflife > 1500.)then
	C = 3.17609126		! = log10(1500)
	RILP = C * (4.-D)

end if

F = -2.241 + 0.610*RILP
normalized_conc = 10.**F
!*************************************************************


!***  special condition if Koc  > 9995 ***********************
disclaimer = 0
if (koc > 9995) then
	normalized_conc = .006  !default condition when Koc is gretater than 9995
	disclaimer = 1
end if
!************************************************************


total_pesticide_use = application_rate * number_of_apps		!total pesticide applied per year


conc = normalized_conc * total_pesticide_use				!output concentration






! *************Write to output******************


call date_and_time(real_clock(1),real_clock(2), real_clock(3), date_time)



write(unit_output,*)'SciGrow version 2.3'
write(unit_output,*)'chemical:', trim(CHEMNAME) 
write (unit_output,100) date_time(2) ,date_time(3), date_time(1),date_time(5),date_time(6),date_time(7)
100 format (' time is ',I2,'/', I2,'/',I4,'  ', I2,':',I2, ':', I2)


write(unit_output,*) '------------------------------------------------------------------------'
write(unit_output,*) ' Application      Number of       Total Use    Koc      Soil Aerobic'
write(unit_output,*) ' rate (lb/acre)  applications   (lb/acre/yr)  (ml/g)   metabolism (days)'
write(unit_output,*) '------------------------------------------------------------------------'

write(unit_output,51)application_rate,number_of_apps,total_pesticide_use,KOC,metabolic_halflife
51 format(1X,F10.3,10X,F4.1,6X,F10.3,4X,es10.2,1X,F10.1)

if (disclaimer == 1)then
	note = '*'
else
	note = ' '
endif

write(unit_output,*) '------------------------------------------------------------------------'
write(unit_output,60) conc,note
60 format(' groundwater screening cond (ppb) = ' ,es10.2, A1)

if (disclaimer == 1) then
	write(unit_output,*) '*Estimated concentrations of chemicals with Koc values greater than 9995 ml/g'
	write(unit_output,*) 'are beyond the scope of the regression data used in SCI-GROW development.'
	write(unit_output,*) 'If there are concerns for such chemicals, a higher tier groundwater exposure'
	write(unit_output,*) 'assessment should be considered, regardless of the concentration returned'
	write(unit_output,*) 'by SCI-GROW.'
endif
write(unit_output,*) '************************************************************************'
write(unit_output,*)



end subroutine scigrow

