PROGRAM malathion_lifestage

!Abbreviations: --remember to put the variability terms back in
  
  !MAL--malathion
  !MOX--malaoxon
  !DMP--dimethyl phosphate metabolites
  !MCA--malathion monocarboxylic acid 
  !DCA--malathion dicarboxylic acid
  !AChE--acetylcholinesterase
  !BuChE--butyrlcholinesterase
  !CaE--carboxylesterase

  !skin compartment/dermal exposure for malathion only
  !lung compartment/inhalation exposure for malathion only

  !compartments included for liver, kidney, brain, fat, and lumped for slow and rapidly perfused. 
  !exposure routes:  oral, dermal, inhalation (malathion); oral (oxon)
  !bioactivation (MAL -> MOX) occurs in liver
  !inhibition of B-esterases (AChE, BuChE, CaE) described in liver, kidney, brain, plasma, RBCs. 

  !detoxification of MAL by CaE occurs in liver, kidney, brain, plasma, RBCs (to MCA/DCA; these are modeled as a single compartment). 
  !detoxification of oxon by B-esterases is stoichiometric; the oxon-enzyme complex serves as a "trap" for the oxon.
  !CaE assumed to undergo reactivation; AChE and BuChE assumed to undergo reactivation/aging.
  !catalytic detoxification of oxon in liver, brain, kidney (plasma for rat only)
 

INITIAL
!constants should be in human parameters m file
VARIABLE TIME=0.0	 !hr
CONSTANT AGE0=0.0	 !Initial age (D for rats; Y for humans)
CONSTANT SPECIES=0	!Species dummy variable: 0=male rat, 1=male human

CONSTANT BWSW=0.0 !Switch for age (set =0) or set (set =1) determination of BW
CONSTANT BWST=0.0 !Set value of BW (kg)

! Gompertz equation parameters
CONSTANT B1=0.0
CONSTANT B2=0.0
CONSTANT B3=0.0
CONSTANT B4=0.0
CONSTANT B5=0.0
CONSTANT B6=0.0
CONSTANT B7=0.0
CONSTANT B8=0.0
CONSTANT AGE1=0.0
CONSTANT AGE2=0.0
CONSTANT AGE3=0.0
CONSTANT SEX=0	

! Age dependent B4 & B8 for humans (Luecke 2007)
IF ((AGE0 .GE. AGE1) .AND. (AGE0 .LT. AGE2) .AND. (SPECIES .EQ. 1)) THEN
B4x=B4;B8x=0
ELSE IF ((AGE0 .GE. AGE3) .AND. (SPECIES .EQ. 1)) THEN
B4x=0;B8x=B8
ELSE
B4x=0;B8x=0
END IF

! Initial BWT (kg) (Luecke 2007)
IF (AGE0 .GE. AGE2) THEN					
BWT=B5*EXP((B6/B7)*(1-EXP(-B7*(AGE0-AGE2))))+B8x*(AGE0-AGE3)		
ELSE
BWT=B1*EXP((B2/B3)*(1-EXP(-B3*AGE0)))+B4x*(AGE0-AGE1)
END IF
BWT=BWT*(1.-BWSW)+BWST*BWSW
! BWT kg to grams for compartment volume calculations
BWTG=BWT*1000			

! Log of BWT for rat brain calculation
IF (SPECIES .EQ. 0) THEN	
LBWT=LOG(BWT)			
ELSE
LBWT=BWT*1000
END IF

! Initial Height (HT: fit to CDC growth chart	(human))	
HT=19.994+(5.5408*BWT)-(0.0671*BWT**2)+0.0003*BWT**3


! Initial compartment volumes (frac of BWT)(developed by Luecke 2007 & Young 2009; Described in Smith et al., 2013)
!Brain
VBrC=VB0+(VB1*LBWT)+(VB2*LBWT**2)+(VB3*LBWT**3)+(VB4*LBWT**4)+(VB5*LBWT**5)+(VB6*LBWT**6)
!Liver
VHC=VH0+(VH1*BWTG)+(VH2*BWTG**2)+(VH3*BWTG**3)+(VH4*BWTG**4)	
!Blood
VBLC=VBL0+(VBL1*BWTG)+(VBL2*BWTG**2)				
!Fat
VFC=VF0+(VF1*BWTG)+(VF2*BWTG**2)+(VF3*BWTG**3)+(VF4*BWTG**4)+(VF5*BWTG**5)+(VF6*BWTG**6)	
!Adipose
VAC=VA0+(VA1*BWTG)+(VA2*BWTG**2)+(VA3*BWTG**3)+(VA4*BWTG**4)+(VA5*BWTG**5)+(VA6*BWTG**6)	
!Kidney (in rapidly perfused tissues)
VKC=VK0+(VK1*BWTG)+(VK2*BWTG**2)				
!Spleen (in rapidly perfused tissues)
VSPC=VSP0+(VSP1*BWTG)+(VSP2*BWTG**2) 	
!Lung (in rapidly perfused tissues)		
VLC=VL0+(VL1*BWTG)+(VL2*BWTG**2)				
!GI, both stomach and intestine (in rapidly perfused tissues)
VGIC=VGI0+(VGI1*BWTG)+(VGI2*BWTG**2)+(VGI3*BWTG**3)		
!Muscle (in slowly perfused tissues)
VMC=VM0+(VM1*BWTG)+(VM2*BWTG**2)+(VM3*BWTG**3)+(VM4*BWTG**4)
!Skin  
VSKC=VSK0+(VSK1*BWTG)+(VSK2*BWTG**2)+(VSK3*BWTG**3)+(VSK4*BWTG**4)+(VSK5*BWTG**5)


CONSTANT FATVAR = 0.0
CONSTANT VOLUNCERT = 0.0
CONSTANT VHCv=0.0
!CONSTANT VBLC=0.0
VFCv=GAUSS(0.,FATVAR*VFC)
VFCv = RSW(VFC+VFCv .LT. 0.1*VFC, 0.1*VFC, VFCv) ! check to ensure that vol is > 0
VFC=VFC+VFCv
CONSTANT VBMC=0.0						      ! Bone marrow (in slow)
VRC=VKC+VSPC+VLC+VGIC+VPC					! Rapid
VSC=VMC+VSKC+VBMC+(VAC-VFC)				! Slow
!CONSTANT VDC=0.0						      ! Diaphram
CONSTANT VPC=0.0						       ! Pancreas (in rapid)
!CONSTANT VINTC=0.0					      ! Small intestine

! Volume variability, set VOLUNCERT=0 to turn off
VSCu=GAUSS(0.,VOLUNCERT*VSC)
VRCu=GAUSS(0.,VOLUNCERT*VRC)
VBCu=GAUSS(0.,VOLUNCERT*VSC)
!VHCu=GAUSS(0.,VOLUNCERT*VHC) !This can be used if total uncertainty is desired, or the next line to vary just hepatic volume based on P3M
VHCu=GAUSS(0.,VHCv*VHC)
VFCu=GAUSS(0.,VOLUNCERT*VFC)
VBLCu=GAUSS(0.,VOLUNCERT*VBLC)
!VBLCu=GAUSS(0.,VBLcV*VBLC)
!VDCu=GAUSS(0.,VOLUNCERT*VDC)
VINTCu=GAUSS(0.,VOLUNCERT*VINTC)
VSCu = RSW(VSC+VSCu .LT. 0.1*VSC, 0.1*VSC, VSCu) ! check to ensure that vol is > 0
VRCu = RSW(VRC+VRCu .LT. 0.1*VRC, 0.1*VRC, VRCu) ! check to ensure that vol is > 0
VBCu = RSW(VBC+VBCu .LT. 0.1*VBC, 0.1*VBC, VBCu) ! check to ensure that vol is > 0
VHCu = RSW(VHC+VHCu .LT. 0.1*VHC, 0.1*VHC, VHCu) ! check to ensure that vol is > 0
VFCu = RSW(VFC+VFCu .LT. 0.1*VFC, 0.1*VFC, VFCu) ! check to ensure that vol is > 0
VBLCu = RSW(VBLC+VBLCu .LT. 0.1*VBLC, 0.1*VBLC, VBLCu) ! check to ensure that vol is > 0
!VDCu = RSW(VDC+VDCu .LT. 0.1*VDC, 0.1*VDC, VDCu) ! check to ensure that vol is > 0
VINTCu = RSW(VINTC+VINTCu .LT. 0.1*VINTC, 0.1*VINTC, VINTCu) ! check to ensure that vol is > 0

VSC=VSC+VSCu
VRC=VRC+VRCu
VBC=VBC+VBCu
VHC=VHC+VHCu
VFC=VFC+VFCu
VBLC=VBLC+VBLCu
!VDC=VDC+VDCu
VINTC=VINTC+VINTCu
 				

! Compartment volume polynomial parameters
CONSTANT VB0=0.0;CONSTANT VB1=0.0;CONSTANT VB2=0.0;CONSTANT VB3=0.0;CONSTANT VB4=0.0
CONSTANT VB5=0.0;CONSTANT VB6=0.0
CONSTANT VH0=0.0;CONSTANT VH1=0.0;CONSTANT VH2=0.0;CONSTANT VH3=0.0;CONSTANT VH4=0.0
CONSTANT VBL0=0.0;CONSTANT VBL1=0.0;CONSTANT VBL2=0.0
CONSTANT VF0=0.0;CONSTANT VF1=0.0;CONSTANT VF2=0.0;CONSTANT VF3=0.0;CONSTANT VF4=0.0
CONSTANT VF5=0.0;CONSTANT VF6=0.0
CONSTANT VA0=0.0;CONSTANT VA1=0.0;CONSTANT VA2=0.0;CONSTANT VA3=0.0;CONSTANT VA4=0.0
CONSTANT VA5=0.0;CONSTANT VA6=0.0
CONSTANT VK0=0.0;CONSTANT VK1=0.0; CONSTANT VK2=0.0
CONSTANT VSP0=0.0;CONSTANT VSP1=0.0;CONSTANT VSP2=0.0
CONSTANT VL0=0.0;CONSTANT VL1=0.0;CONSTANT VL2=0.0
CONSTANT VGI0=0.0;CONSTANT VGI1=0.0;CONSTANT VGI2=0.0;CONSTANT VGI3=0.0
CONSTANT VM0=0.0;CONSTANT VM1=0.0;CONSTANT VM2=0.0;CONSTANT VM3=0.0;CONSTANT VM4=0.0
CONSTANT VSK0=0.0;CONSTANT VSK1=0.0;CONSTANT VSK2=0.0;CONSTANT VSK3=0.0;
CONSTANT VSK4=0.0;CONSTANT VSK5=0.0

! Compartment volumes (L)
VBr=VBrC*BWT        !brain
VH=VHC*BWT          !liver
VBL=VBLC*BWT        !blood
VAB=0.46*VBL        !arterial blood
VF=VFC*BWT          !fat
VR=VRC*BWT          !rapidly perfused
VS=VSC*BWT          !slowly perfused
VINT=VINTC*BWT      !intestine
VL=VL*BWT           !lung
VPLAS=VBL*(1-HCT)   !plasma
VRBC=VBL*HCT        !RBC
VK=VKC*BWT          !kidney


! Blood flow to each compartment (L/h/kg) 
CONSTANT QFC=0.0	  !fat
CONSTANT QHC=0.0	  !liver
CONSTANT QSC=0.0 	 !slowly perfused
CONSTANT QBrC=0.0	 !brain
constant QKC=0.0    !kidney
CONSTANT QRC=0.0	  !rapidly perfused

!Variability to to activity level
CONSTANT WORK= 0.0 !Work in Watts
DVO2=WORK*10.1/1000.;
! Blood Flow adjustments
QFCv	=	0.017*DVO2*60.
!QHCv	=	-0.19*DVO2*60.  !FOR WORK, OR FOR VARIABILITY COMMENT OUT and use following line
QHCv=GAUSS(0.,QHCv*QHC)
QSCv  =  7.38*DVO2*60.
QRCv  =  -0.08*DVO2*60.


!Partition coefficients (tissue:blood); from 2009 USEPA malathion lice assessment
!malathion
  constant PMalF = 0.0    !fat:blood
  constant PMalR = 0.0    !richly perfused:blood
  constant PMalL = 0.0    !liver:blood
  constant PMalK = 0.0    !kidney:blood
  constant PMalBr = 0.0   !brain:blood
  constant PMalS = 0.0    !slowly perfused:blood
  constant PSKL = 0.0     !skin:blood
  constant PLAir = 0.0    !tissue:air PC

!malaoxon
  constant PMoxF = 0.0   !fat:blood
  constant PMoxR = 0.0   !richly perfused:blood
  constant PMoxL = 0.0   !liver:blood
  constant PMoxK = 0.0   !kidney:blood
  constant PMoxBr = 0.0  !brain:blood
  constant PMoxS = 0.0   !slowly perfused: blood

  !volumes of distribution for metabolite compartments (L)
  constant V1 = 0.0      !MCA + DCA 

  !constant HCT=0.0   !hematocrit

!metabolism parameters
  !maximum rates of metabolism (umol/hr/kg tissue)
  !malathion detoxification 
  constant VMAXMALLC = 0.0        !liver--CaE; based on in vitro data (Chambers & Meek 2017)
  constant VMAXMALKC = 0.0        !kidney--CaE; 60% of liver based on Talcott 1979
  constant VMAXMALBLC = 0.0       !plasma--CaE(umol/hr/L); 74% of liver based on Talcott 1979
  constant VMAXMALBRC = 0.0       !brain--CaE; 5% of liver
 

  !malathion oxidation--malathion to oxon
  constant VMAXMALMOXC = 0.0      !liver--CYPs; based on in vitro data (Chambers & Meek 2017) 
  
  !oxon detox
  constant VMOXDMPLC = 0.0       !liver
  constant VMOXDMPPC = 0.0       !plasma
  constant VMOXDMPBC = 0.0       !brain
  constant VMOXDMPKC = 0.0       !kidney

  !affinity constants (umol/L)
  !malathion detoxification
  constant KMMALL = 0.0    !liver--CaE--Chambers & Meek 2017
  constant KMMALK = 0.0    !kidney--CaE
  constant KMMALBL = 0.0   !plasma--CaE
  constant KMMALBR = 0.0   !brain--CaE

  !malathion oxidation--malathion to oxon
  constant KMMALMOX = 0.0  !liver--CYPs; based on in vitro data (Chambers & Meek 2017)

  !oxon detox
  constant KMOXDMPL = 0.0        !liver
  constant KMOXDMPP = 0.0        !plasma
  constant KMOXDMPB = 0.0        !brain
  constant KMOXDMPK = 0.0        !kidney
  constant KI = 0.0              !dissociation constant

 !pharmacodynamics--esterase inhibition
  !Enzyme turnover rates (umol hydrolysis/h/umol active sites)--not chemical specific
  constant TRCE=0.0		!AChE (all tissues)
  constant TRBE=0.0		!BuCHE (all tissue)
  !constant TRCR=0.0		!CaE  (all tissues)

 !Enzyme activities (umol/hr/kg tissue)--not chemical-specific
  !AChE
  constant BACHE=0.0		!brain AChE
  constant HACHE=0.0		!liver AChE
  constant BLACHE=0.0	 !Plasma AChE
  constant RBCHE=0.0		!RBC AChE
  constant KACHE=0.0    !kidney AChE

  !BuChE
  constant BBUCE=0.0		!brain BuChE
  constant HBUCE=0.0		!liver BuChE
  constant BLBUCE=0.0	 !Plasma BuChE
  constant KBUCE=0.0    !kidney BuChE

  !CaE
  constant BRCE=0.0     !Brain CaE
  !constant HECE=0.0     !liver CaE
  constant PLOCE=0.0		!Plasma CaE
  constant KECE=0.0     !kidney CaE
 
  
!chemical-specific parameters for inhibition
  !liver AChE rate constants
  constant KDHCE=0.0	! degradation of esterase (/hr)
  constant KIHCE=0.0	! inhibition of esterase (per umol/L/hr)
  constant KRHCE=0.0	! reactivation of esterase (/hr)
  constant KAHCE=0.0	! aging of esterase (/hr)

 !liver BuChE rate constants
  constant KDHBE=0.0	! degradation of esterase (/hr)
  constant KIHBE=0.0	! inhibition of esterase (per umol/L/hr)
  constant KRHBE=0.0	! reactivation of esterase (/hr)
  constant KAHBE=0.0	! aging of esterase (/hr)

 !liver CaE rate constants
  constant KDHCR=0.0	! degradation of esterase (/hr)
  constant KIHCR=0.0	! inhibition of esterase (per umol/L/hr)
  !constant KRHCR=0.0	! reactivation of esterase (/hr)
  constant KAHCR=0.0	! aging of esterase (/hr)

 !brain AChE rate constants
 constant KDBCE=0.0	! degradation of esterase (/hr)
 constant KIBCE=0.0	! inhibition of esterase (per umol/L/hr)
 constant KRBCE=0.0	! reactivation of esterase (/hr)
 constant KABCE=0.0	! aging of esterase (/hr)

 !brain BuChE rate constants
 constant KDBBE=0.0	! degradation of esterase (/hr)
 constant KIBBE=0.0	! inhibition of esterase (per umol/L/hr)
 constant KRBBE=0.0	! reactivation of esterase (/hr)
 constant KABBE=0.0	! aging of esterase (/hr)

 !brain CaE rate constants
 constant KDBCR=0.0	!degradation of esterase (/hr)
 constant KIBCR=0.0	!inhibition of esterase (per umol/L/hr)
 constant KRBCR=0.0	!reactivation of esterase (/hr)
 constant KABCR=0.0	!aging of esterase (/hr)

!kidney AChE rate constants
constant KDKCE=0.0	! degradation of esterase (/hr)
constant KIKCE=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKCE=0.0	! HR-1;reactivation of esterase
constant KAKCE=0.0	! aging of esterase (/hr)

!kidney BuChE rate constants
constant KDKBE=0.0	! degradation of esterase (/hr)
constant KIKBE=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKBE=0.0	! reactivation of esterase (/hr)
constant KAKBE=0.0	! aging of esterase (/hr)

!kidney CaE rate constants
constant KDKCR=0.0	! degradation of esterase (/hr)
constant KIKCR=0.0	! inhibition of esterase (per umol/L/hr)
constant KRKCR=0.0	! reactivation of esterase (/hr)
constant KAKCR=0.0	! aging of esterase (/hr)

!plasma AChE rate constants
constant KDBLCE=0.0		! degradation of esterase (/hr)
constant KIBLCE=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLCE=0.0		! reactivation of esterase (/hr)
constant KABLCE=0.0		! aging of esterase (/hr)

!plasma BuChE rate constants
constant KDBLBE=0.0		! degradation of esterase (/hr)
constant KIBLBE=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLBE=0.0	  ! reactivation of esterase (/hr)
constant KABLBE=0.0 	 ! aging of esterase (/hr)

!plasma CaE rate constants
constant KDBLCR=0.0		! degradation of esterase (/hr)
constant KIBLCR=0.0		! inhibition of esterase (per umol/L/hr)
constant KRBLCR=0.0		! reactivation of esterase (/hr)
constant KABLCR=0.0		! aging of esterase (/hr)

!RBC AChE rate constants
!constant KDRBCE=0.0		! degradation of esterase (/hr)
!constant KIRBCE=0.0		! inhibition of esterase (per umol/L/hr)
!constant KRRBCE=0.0		! reactivation of esterase (/hr)
constant KARBCE=0.0		! aging of esterase (/hr)

!uptake parameters
!malathion
constant KAS=0.0		  !transfer stomach to liver (/h)
!constant KSI=0.0	    !transfer stomach to intestine (/h)
constant KAI=0.0      !transfer intestine to liver (/h)
constant FA=0.0       !Fractional oral Absorption
constant KMUC=0.0     !rate constant for swallowing part of an inhaled dose (/h); mucocillary clearance
constant FRACIN=0.0   !fraction to deep lung

FRLUGI=1-FRACIN		   !FRACTIONAL transfer of MAL to GI tract 
  
!oxon
constant KASO=0.0  		 !transfer stomach to liver (/h)
constant KSIO=0.0	     !transfer stomach to intestine (/h)
constant KAIO=0.0       !transfer intestine to liver (/h)
constant FAO=0.0        !fractional oral Absorption

!elimination rate constants for metabolite compartment (/h)
constant KE1=0.0  !MCA + DCA


!molecular weights
constant MWMAL=0.0 !molecular wt of malathion (g/mol)
constant MWMOX=0.0 !molecular wt of malaoxon (g/mol)
  

!oral dosing--single oral dose
constant ORALMAL=0.0	      !MAL single oral bolus dose (ug/kg)
constant ORALMOX=0.0	      !oxon oral bolus dose (ug/kg)
  
!oral dosing--multiple doses
!put times in the array DT (in hours) (absolute time, NOT time since last dose)
!Put the oral dose of malathion in the array DORAL (ug/kg)(DORALO for oxon dosing)
!for dosing amount in ug (instead of ug/kg), use AMTMDOSE (malathion) or AMTODOSE (oxon)
!Add one additional dose of zero at a time greater than TSTOP to keep the model running
  DIMENSION DT(2000), DORAL(2000), DORALO(2000), AMTMDOSE(2000), AMTODOSE(2000)
  INTEGER indx
  indx=1  			! indx is a counter used to track multiple doses
  SCHEDULE DOSEX .AT. DT(indx)
  ODOSE=0.0     !oral dose (MAL; ug/kg BW)
  ODOSEO=0.0    !oral dose (oxon; ug/kg BW)
  ADOSEM=0.0    !oral dose (MAL; ug)
  ADOSEO=0.0    !oral dose (oxon; ug)


 !dermal dose
  constant DERM=0.0	                !dermal dose, ug/kg or ug; see lines below for DDOSE 
  constant SAF=0.0                   !fraction of total skin surface area exposed
  constant KDIS=0.0                  !dissipative loss rate (/hr)
  TSA=71.81*(BWT**0.425)*(HT**0.725) !total human skin surface area (cm2)
  SA=SAF*TSA                         !surface area exposed (cm2)
  !constant SA = 0.0
  VSKCC=VSKC*(SA/TSA)	              !volume of skin tissue exposed
  
  constant VLIQ=0.0	         !volume of liquid applied to skin (L)
  constant KPL=0.0	          !skin permeability coefficient (cm/hr)
  constant FAD=0.0	          !fraction of dermal dose absorbed; assume 100%
  DDOSE=((DERM*BWT)/MWMAL)*FAD !total dermal dose (umol); use when dose is ug/kg
  !DDOSE=DERM/MWMAL*FAD*VLIQ  !use this when dose is in ug
  constant TCHNG=12           !time that chemical is in contact with skin (hr)

  
  !inhalation
  constant CONCPPM = 0.0    !Inhaled conc of malathion (ppm)
  constant CONCMGM = 0.0		!Inhaled conc of malathion (mg/m3)
  constant CONCPPMO=0.0     !Inhaled conc of oxon (ppm)
  constant CONCMGMO=0.0     !Inhaled conc of oxon (mg/m3)
  constant TCHNG1=2         !total exposure time (hr)
 

  !oral dose--child exposure
  constant ODOSECHILD = 0.0  !ug/kg
  constant TCHNG4=504;       !total exposure time (21 days)
  ODMALCHILD=ODOSECHILD*(BWT/MWMAL)*FA   !MAL dose conversion (ug/kg to umol)

!oral dose molar conversion with fractional absorption
ODOSEMAL=ORALMAL*(BWT/MWMAL)*FA	 ! MAL dose conversion (ug/kg to umol)
ODOSEMOX=ORALMOX*(BWT/MWMOX)*FAO	! malaoxon dose conversion (ug/kg to umol)

! Blood flow to each compartment (L/h)
QF=QFC*VF     !fat
QH=QHC*VH     !liver
QR=QRC*VR     !rapidly perfused
QS=QSC*VS     !slowly perfused
QBr=QBrC*VBr      !brain
QK=QKC*VK         !kidney


QC=QF+QH+QR+QS+QBr+QK 	!Total cardiac output (L/h)

!scaling for Vmax for malathion detoxification (umol/hr/kg tissue to umol/hr)
  VMAXMALL = VMAXMALLC * VH                    !liver--CaE
  VMAXMALK = VMAXMALKC * VK                    !kidney--CaE
  VMAXMALBL = VMAXMALBLC * VBL * (1-HCT)       !plasma--CaE
  VMAXMALBR = VMAXMALBRC * VBR                 !brain--CaE

  !oxidation--malathion to oxon
  VMAXMALMOX = VMAXMALMOXC * VH                  !liver--CYPs

  !oxon detox
  VMOXDMPL = VMOXDMPLC*VH                        !liver oxon detox
  VMOXDMPP = VMOXDMPPC*VBL*(1-HCT)               !plasma oxon detox
  VMOXDMPB = VMOXDMPBC*VBr                       !brain oxon detox
  VMOXDMPK = VMOXDMPKC*VK                        !kidney oxon detox
  
!Enzyme activity (umol/h) in tissues
!AChE
SBACH=BACHE*VBr             !brain
SHACH=HACHE*VH	            !liver
SBLACH=BLACHE*VBL*(1-HCT)   !plasma
SRBACH=RBCHE*VBL*HCT        !RBC
SKACH=KACHE*VK              !kidney

!BuChE
SBBUC=BBUCE*VBr             !brain
SHBUC=HBUCE*VH	            !liver
SBLBUC=BLBUCE*VBL*(1-HCT)   !plasma
SKBUC=KBUCE*VK              !kidney

!CaE
SBRCE=BRCE*VBr	            !brain
SHECE=HECE*VH			         !liver
SPLOCE=PLOCE*VBL*(1-HCT)    !plasma
SKACE=KECE*VK               !kidney

!calculation of esterase binding sites (umol)
!AChE
IBCE=SBACH/TRCE		!total brain AchE (umol)
IHCE=SHACH/TRCE		!total liver AchE (umol)
IBLCE=SBLACH/TRCE	!total plasma AchE (umol)
IRBCE=SRBACH/TRCE	!total RBC AChE (umol)
IKCE=SKACH/TRCE		!total kidney AchE (umol)

!BuChE
IBBE=SBBUC/TRBE		!total brain BuChE (umol)
IHBE=SHBUC/TRBE		!total liver BuChE (umol)
IBLBE=SBLBUC/TRBE	!total plasma BuChE (umol)
IKBE=SKBUC/TRBE		!total kidney BuChE (umol)

!CaE
IBCR=SBRCE/TRCR		!total brain CaE (umol)
IHCR=SHECE/TRCR		!total liver CaE (umol)
IBLCR=SPLOCE/TRCR	!total plasma CaE (umol)
IKCR=SKACE/TRCR		!total kidney CaE (umol)


!calculation of enzyme synthesis rates in tissues (umol/hr)
!liver
KSHCE=IHCE*KDHCE	!AChE
KSHBE=IHBE*KDHBE	!BuChE
KSHCR=IHCR*KDHCR	!CaE
!brain
KSBCE=IBCE*KDBCE	!AChE
KSBBE=IBBE*KDBBE	!BuChE
KSBCR=IBCR*KDBCR	!CaE
!kidney
KSKCE=IKCE*KDKCE	!AChE
KSKBE=IKBE*KDKBE	!BuChE
KSKCR=IKCR*KDKCR	!CaE
!plasma
KSBLCE=IBLCE*KDBLCE	!AChE
KSBLBE=IBLBE*KDBLBE	!BuChE
KSBLCR=IBLCR*KDBLCR	!CaE
!RBC
KSRBCE=KDRBCE*IRBCE	!AChE

! Enzymatic variability
CONSTANT VMLv=0.0
CONSTANT VMBLv=0.0
CONSTANT VMHCPv=0.0
CONSTANT VMHHCOv=0.0
CONSTANT VMCBCPv=0.0
CONSTANT VMCBCOv=0.0
CONSTANT VINTTv=0.0
CONSTANT VINTOv=0.0

! lognormal distributions
VMLvv=exp(GAUSS(LOG(VMAXMALL)-(SQRT(LOG((VMLv)**2.+1))**2.)/2.,SQRT(LOG((VMLv)**2.+1))))-VMAXMALL              !malathion detox--liver
VMHCPvv=exp(GAUSS(LOG(VMAXMALK)-(SQRT(LOG((VMHCPv)**2.+1))**2.)/2.,SQRT(LOG((VMHCPv)**2.+1))))-VMAXMALK        !malathion detox--kidney
VMHHCOvv=exp(GAUSS(LOG(VMAXMALBR)-(SQRT(LOG((VMHHCOv)**2.+1))**2.)/2.,SQRT(LOG((VMHHCOv)**2.+1))))-VMAXMALBR   !malathion detox--brain
VMCBCPvv=exp(GAUSS(LOG(VMAXMALMOX)-(SQRT(LOG((VMCBCPv)**2.+1))**2.)/2.,SQRT(LOG((VMCBCPv)**2.+1))))-VMAXMALMOX !malathion activation
VMCBCOvv=exp(GAUSS(LOG(VMOXDMPL)-(SQRT(LOG((VMCBCOv)**2.+1))**2.)/2.,SQRT(LOG((VMCBCOv)**2.+1))))-VMOXDMPL     !oxon detox--liver
VINTOvv=exp(GAUSS(LOG(VMOXDMPB)-(SQRT(LOG((VINTOv)**2.+1))**2.)/2.,SQRT(LOG((VINTOv)**2.+1))))-VMOXDMPB        !oxon detox--brain
VINTTvv=exp(GAUSS(LOG(VMOXDMPK)-(SQRT(LOG((VINTTv)**2.+1))**2.)/2.,SQRT(LOG((VINTTv)**2.+1))))-VMOXDMPK        !oxon detox--kidney

!If the Vmax is less than 1% of the nominal, set equal to 1% of nonimal (by setting error to 99% of nominal)
VMLvv = RSW(VMLvv+VMAXMALL .LT. .01*VMAXMALL, -0.99*VMAXMALL, VMLvv)                 !malathion detox--liver
VMHCPvv = RSW(VMHCPvv+VMAXMALK .LT. .01*VMAXMALK, -0.99*VMAXMALK, VMHCPvv)           !malathion detox--kidney
VMHHCOvv = RSW(VMHHCOvv+VMAXMALBR .LT. .01*VMAXMALBR, -0.99*VMAXMALBR, VMHHCOvv)     !malathion detox--brain
VMCBCPvv = RSW(VMCBCPvv+VMAXMALMOX .LT. .01*VMAXMALMOX, -0.99*VMAXMALMOX, VMCBCPvv)  !malathion activation
VMCBCOvv = RSW(VMCBCOvv+VMOXDMPL .LT. .01*VMOXDMPL, -0.99*VMOXDMPL, VMCBCOvv)        !oxon detox--liver
VINTTvv = RSW(VINTTvv+VMOXDMPB .LT. .01*VMOXDMPB, -0.99*VMOXDMPB, VINTTvv)           !oxon detox--brain
VINTOvv = RSW(VINTOvv+VMOXDMPK .LT. .01*VMOXDMPK, -0.99*VMOXDMPK, VINTOvv)           !oxon detox--kidney

! set variable Vmax's
VMAXMALL=VMLvv+VMAXMALL
VMAXMALK=VMHCPvv+VMAXMALK
VMAXMALBR=VMHHCOvv+VMAXMALBR
VMAXMALMOX=VMCBCPvv+VMAXMALMOX
VMOXDMPL=VMCBCOvv+VMOXDMPL
VMOXDMPB=VINTTvv+VMOXDMPB
VMOXDMPK=VINTOvv+VMOXDMPK


!other variability based on point (LOCAL) senstivity analyses
CONSTANT KDRBCEv=0.0
CONSTANT KIRBCEv=0.0
CONSTANT HCTv=0.0
CONSTANT TRCRv=0.0
CONSTANT HECEv=0.0
CONSTANT KRHCRv=0.0
CONSTANT KSIv=0.0
CONSTANT KRRBCEv=0.0
! lognormal distributions
KDRBCEvv=exp(GAUSS(LOG(KDRBCE)-(SQRT(LOG((KDRBCEv)**2.+1))**2.)/2.,SQRT(LOG((KDRBCEv)**2.+1))))-KDRBCE
KIRBCEvv=exp(GAUSS(LOG(KIRBCE)-(SQRT(LOG((KIRBCEv)**2.+1))**2.)/2.,SQRT(LOG((KIRBCEv)**2.+1))))-KIRBCE
KRRBCEvv=exp(GAUSS(LOG(KRRBCE)-(SQRT(LOG((KRRBCEv)**2.+1))**2.)/2.,SQRT(LOG((KRRBCEv)**2.+1))))-KRRBCE
HCTvv=exp(GAUSS(LOG(HCT)-(SQRT(LOG((HCTv)**2.+1))**2.)/2.,SQRT(LOG((HCTv)**2.+1))))-HCT
TRCRvv=exp(GAUSS(LOG(TRCR)-(SQRT(LOG((TRCRv)**2.+1))**2.)/2.,SQRT(LOG((TRCRv)**2.+1))))-TRCR
KRHCRvv=exp(GAUSS(LOG(KRHCR)-(SQRT(LOG((KRHCRv)**2.+1))**2.)/2.,SQRT(LOG((KRHCRv)**2.+1))))-KRHCR
HECEvv=exp(GAUSS(LOG(HECE)-(SQRT(LOG((HECEv)**2.+1))**2.)/2.,SQRT(LOG((HECEv)**2.+1))))-HECE
KSIvv=exp(GAUSS(LOG(KSI)-(SQRT(LOG((KSIv)**2.+1))**2.)/2.,SQRT(LOG((KSIv)**2.+1))))-KSI
!IF value goes below 1%, set to 1% of nominal mean
KDRBCEvv = RSW(KDRBCEvv+KDRBCE .LT. .01*KDRBCE, -0.99*KDRBCE, KDRBCEvv)
KIRBCEvv = RSW(KIRBCEvv+KIRBCE .LT. .01*KIRBCE, -0.99*KIRBCE, KIRBCEvv)
KRRBCEvv = RSW(KRRBCEvv+KRRBCE .LT. .01*KRRBCE, -0.99*KRRBCE, KRRBCEvv)
HCTvv=RSW(HCTvv+HCT .LT. .01*HCT, -0.99*HCT, HCTvv)
TRCRvv = RSW(TRCRvv+TRCR .LT. .01*TRCR, -0.99*TRCR, TRCRvv)
KRHCRvv = RSW(KRHCRvv+KRHCR .LT. .01*KRHCR, -0.99*KRHCR, KRHCRvv)
HECEvv = RSW(HECEvv+HECE .LT. .01*HECE, -0.99*HECE, HECEvv)
KSIvv = RSW(KSIvv+KSI .LT. .01*KSI, -0.99*KSI, KSIvv)
! set variable params
KDRBCE=KDRBCEvv+KDRBCE
KIRBCE=KIRBCEvv+KIRBCE
KRRBCE=KRRBCEvv+KRRBCE
HCT=HCTvv+HCT
TRCR=TRCRvv+TRCR
HECE=HECEvv+HECE
KSI=KSIvv+KSI
KOSI=KSIvv+KOSI
KRHCR=KRHCRvv+KRHCR


!INITIALIZING MODEL VARIABLES BEFORE EACH SIMULATION
DZONE=1.0		 !turn dermal exposure on
INZONE=1.0	  !turn inhalation exposure on	
OZONE=1.0     !turn child oral exposure on

! TIMING COMMANDS
constant POINTS=100.0		!OUTPUT POINTS
constant TSTOP=0.0		   !STOP SIMULATION (HR)
CINT=TSTOP/POINTS        !Communication interval
VARIABLE time = 0.0      !simulation time in hour
 
 END ! INITIAL


DYNAMIC

ALGORITHM IALG = 2      !Gear algorithm
TERMT(TIME .GE. TSTOP)	!stop execution

! Age
IF (SPECIES .EQ. 0) THEN
AGE=AGE0+TIME/24.0		! Rat age (D)
ELSE
AGE=AGE0+TIME/8766		! Human age (Y)
END IF

! Age dependent B4 & B8 for humans (Luecke 2007)
IF ((AGE .GE. AGE1) .AND. (AGE .LT. AGE2) .AND. (SPECIES .EQ. 1)) THEN
B4x=B4;B8x=0
ELSE IF ((AGE .GE. AGE3) .AND. (SPECIES .EQ. 1)) THEN
B4x=0;B8x=B8
ELSE
B4x=0;B8x=0
END IF

! BWT (kg) Gompertz (Luecke 2007)
IF (AGE .GE. AGE2) THEN					
BWT=B5*EXP((B6/B7)*(1-EXP(-B7*(AGE-AGE2))))+B8x*(AGE-AGE3)		
ELSE
BWT=B1*EXP((B2/B3)*(1-EXP(-B3*AGE)))+B4x*(AGE-AGE1)
END IF
BWT=BWT*(1.-BWSW)+BWST*BWSW

BWTG=BWT*1000		! BWT kg to grams for compartment volume calculations

IF (SPECIES .EQ. 0) THEN
LBWT=LOG(BWT)		! Log of BWT for rat brain calc
ELSE
LBWT=BWT*1000
END IF

! Compartment volumes (frac of BWT)
!brain
VBrC=VB0+(VB1*LBWT)+(VB2*LBWT**2)+(VB3*LBWT**3)+(VB4*LBWT**4)+(VB5*LBWT**5)+(VB6*LBWT**6)
!liver
VHC=VH0+(VH1*BWTG)+(VH2*BWTG**2)+(VH3*BWTG**3)+(VH4*BWTG**4)	
!blood
VBLC=VBL0+(VBL1*BWTG)+(VBL2*BWTG**2)				
!fat--this is lipid content only
VFC=VF0+(VF1*BWTG)+(VF2*BWTG**2)+(VF3*BWTG**3)+(VF4*BWTG**4)+(VF5*LBWT**5)+(VF6*LBWT**6)	
!adipose--this is all tissue associated with adipose tissue (connective and lipid)
VAC=VA0+(VA1*BWTG)+(VA2*BWTG**2)+(VA3*BWTG**3)+(VA4*BWTG**4)+(VA5*BWTG**5)+(VA6*BWTG**6)	
!kidney (in rapidly perfused)
VKC=VK0+(VK1*BWTG)+(VK2*BWTG**2)			
!spleen (in rapidly perfused)
VSPC=VSP0+(VSP1*BWTG)+(VSP2*BWTG**2)
!lung
VLC=VL0+(VL1*BWTG)+(VL2*BWTG**2)
!intestines (in rapidly perfused)
VGIC=VGI0+(VGI1*BWTG)+(VGI2*BWTG**2)+(VGI3*BWTG**3)		
!muscle (in slowly perfused)
VMC=VM0+(VM1*BWTG)+(VM2*BWTG**2)+(VM3*BWTG**3)+(VM4*BWTG**4)
!skin (in slowly perfused)
VSKC=VSK0+(VSK1*BWTG)+(VSK2*BWTG**2)+(VSK3*BWTG**3)+(VSK4*BWTG**4)+(VSK5*BWTG**5)
								
VFC=VFC                         

VRC=VKC+VSPC+VGIC+VPC					      ! Rapid  +VLC
VSC=VMC+VSKC+VBMC+(VAC-VFC)					! Slow

VSC=VSC+VSCu
VRC=VRC+VRCu
VBC=VBC+VBCu
VHC=VHC+VHCu
VFC=VFC+VFCu
VBLC=VBLC+VBLCu
!VDC=VDC+VDCu
VINTC=VINTC+VINTCu


! Compartment volumes (L)
VBr=VBrC*BWT        !brain
VH=VHC*BWT        !liver
VBL=VBLC*BWT      !blood
VPLAS=VBL*(1-HCT) !plasma
VRBC=VBL*HCT      !RBC
VF=VFC*BWT        !fat
VR=VRC*BWT        !rapidly perfused
VS=VSC*BWT        !slow perfused
VK=VKC*BWT        !kidney
VINT=VINTC*BWT    !intestine
VL=VLC*BWT	    !lung


VTOTCOMPARTMENTS=(VLC+VFC+VSC+VRC+VBRC+VBLC+VKC+VINTC+VHC)/0.9 !should be ~0.9-1.1
BWTotal=(0.9*BWT)-(VL+VF+VS+VR+VBr+VBL+VK+VH) !should <10 for a human

! Blood flow to each compartment (L/h)
QF=QFC*VF 
QH=QHC*VH
QR=QRC*VR
QS=QSC*VS  
QBr=QBrC*VBr
QK=QKC*VK

QC=QF+QH+QR+QS+QBr+QK 	!total cardiac output (L/h)


constant BreatheRATE = 29   !L/min; HED Pesticide Exposure Database
QALV = BreatheRATE*60*0.7   !adult
!QALV = 330*0.7	           ! Kids


!scaling for Vmax for malathion detoxification (umol/hr/kg tissue to umol/hr)
  VMAXMALL = VMAXMALLC * VH                      !liver--CaE
  VMAXMALK = VMAXMALKC * VK                      !kidney--CaE
  VMAXMALBL = VMAXMALBLC * VBL * (1-HCT)         !plasma--CaE
  VMAXMALBR = VMAXMALBRC * VBR                   !brain--CaE
 
  !oxidation--malathion to oxon
  VMAXMALMOX = VMAXMALMOXC * VH                  !liver--CYPs

  !oxon detox
  VMOXDMPL = VMOXDMPLC*VH                        !liver oxon detox
  VMOXDMPP = VMOXDMPPC*VBL*(1-HCT)               !plasma oxon detox
  VMOXDMPB = VMOXDMPBC*VBr                       !brain oxon detox
  VMOXDMPK = VMOXDMPKC*VK                        !kidney oxon detox

!Enzyme activity (umol/h) in tissues
!AChE
SBACH=BACHE*VBr             !brain
SHACH=HACHE*VH	            !liver
SBLACH=BLACHE*VBL*(1-HCT)   !plasma
SRBACH=RBCHE*VBL*HCT        !RBC
SKACH=KACHE*VK              !kidney

!BuChE
SBBUC=BBUCE*VBr             !brain
SHBUC=HBUCE*VH	            !liver
SBLBUC=BLBUCE*VBL*(1-HCT)   !plasma
SKBUC=KBUCE*VK              !kidney

!CaE
SBRCE=BRCE*VBr	            !brain
SHECE=HECE*VH			         !liver
SPLOCE=PLOCE*VBL*(1-HCT)    !plasma
SKACE=KECE*VK               !kidney

!calculation of esterase binding sites (umol)
!AChE
IBCE=SBACH/TRCE		!total brain AchE (umol)
IHCE=SHACH/TRCE		!total liver AchE (umol)
IBLCE=SBLACH/TRCE	!total plasma AchE (umol)
IRBCE=SRBACH/TRCE	!total RBC AChE (umol)
IKCE=SKACH/TRCE		!total kidney AchE (umol)

!BuChE
IBBE=SBBUC/TRBE		!total brain BuChE (umol)
IHBE=SHBUC/TRBE		!total liver BuChE (umol)
IBLBE=SBLBUC/TRBE	!total plasma BuChE (umol)
IKBE=SKBUC/TRBE		!total kidney BuChE (umol)

!CaE
IBCR=SBRCE/TRCR		!total brain CaE (umol)
IHCR=SHECE/TRCR		!total liver CaE (umol)
IBLCR=SPLOCE/TRCR	!total plasma CaE (umol)
IKCR=SKACE/TRCR		!total kidney CaE (umol)


!calculation of enzyme synthesis rates in tissues (umol/hr)
!liver
KSHCE=IHCE*KDHCE	!AChE
KSHBE=IHBE*KDHBE	!BuChE
KSHCR=IHCR*KDHCR	!CaE
!brain
KSBCE=IBCE*KDBCE	!AChE
KSBBE=IBBE*KDBBE	!BuChE
KSBCR=IBCR*KDBCR	!CaE
!kidney
KSKCE=IKCE*KDKCE	!AChE
KSKBE=IKBE*KDKBE	!BuChE
KSKCR=IKCR*KDKCR	!CaE
!plasma
KSBLCE=IBLCE*KDBLCE	!AChE
KSBLBE=IBLBE*KDBLBE	!BuChE
KSBLCR=IBLCR*KDBLCR	!CaE
!RBC
KSRBCE=KDRBCE*IRBCE	!AChE

! variable enzymology
VMAXMALL=VMLvv+VMAXMALL
VMAXMALK=VMHCPvv+VMAXMALK
VMAXMALBR=VMHHCOvv+VMAXMALBR
VMAXMALMOX=VMCBCPvv+VMAXMALMOX
VMOXDMPL=VMCBCOvv+VMOXDMPL
VMOXDMPB=VINTTvv+VMOXDMPB
VMOXDMPK=VINTOvv+VMOXDMPK




!-------------------------------------------------------------------------------
!dosing

!oral dose molar conversion with fractional absorption
ODOSEMAL=ORALMAL*(BWT/MWMAL)*FA	 ! MAL dose conversion (ug/kg to umol)
ODOSEMOX=ORALMOX*(BWT/MWMOX)*FAO	! malaoxon dose conversion (ug/kg to umol)
ODMALCHILD=ODOSECHILD*(BWT/MWMAL)*FA  !MAL dose conversion for child (ug/kg to umol)

!oral dose
DISCRETE DOSEX				
ODOSE=ODOSE+DORAL(indx)*(BWT/MWMAL)*FA	  ! MAL dose molar conversion (ug/kg to umol) 
ODOSEO=ODOSEO+DORALO(indx)*(BWT/MWMOX)*FA ! oxon dose molar conversion (ug/kg to umol)
ADOSEM=ADOSEM+AMTMDOSE(indx)*FA/MWMAL     ! MAL dose conversion (ug to umol)
ADOSEO=ADOSEO+AMTODOSE(indx)*FA/MWMOX     ! oxon dose conversion (ug to umol)
indx=indx+1
SCHEDULE DOSEX .AT. DT(indx)
END


!dermal 
DISCRETE DOSEON1
  INTERVAL DOSEINT = 1440.0      !Interval to repeat dosing (hr); set to 1440 for 60 days
  SCHEDULE DOSEOFF1 .AT. (TIME+TCHNG)
  IF (Time.LE.TCHNG) THEN
  DZONE=1                         
																		
  ENDIF
END
 
DISCRETE DOSEOFF1
         DZONE = 0.0
					
END

!inhalation
DISCRETE DOSEON2
  INTERVAL DOSEINT = 1440.0      !Interval to repeat dosing (hr); set to 1440 for 60 days
  SCHEDULE DOSEOFF2 .AT. (TIME+TCHNG1)
  IF (Time.LE.TCHNG1) THEN
  INZONE=1
  ENDIF
END
 
DISCRETE DOSEOFF2
         INZONE=0.0
END

!oral exposure for child
DISCRETE DOSEON4
  INTERVAL DOSEINT = 1440.0      !Interval to repeat dosing (hr); set to 1440 for 60 days
  SCHEDULE DOSEOFF4 .AT. (TIME+TCHNG4)
  IF (Time.LE.TCHNG4) THEN
  OZONE=1
  ENDIF
END
 
DISCRETE DOSEOFF4
         ONZONE=0.0
END


!drinking H2O  
constant volume=0.688557  !L/day consumed
CONSTANT EVENTS=6         !times/day to drink

DERIVATIVE

!--------------------------------------------------------------
!malathion (parent compound)-----------------------------------
!---------------------------------------------------------------

!oral dose for child exposure
constant W4 = 21  !days exposed per year
constant D4 = 7   !days per week exposed
constant P4 = 1.5  !hr per day exposed
ODCHILD = ODMALCHILD*pulse(0,year*24,W4*24)*pulse(0,7*24,D4*24)*pulse(0,24,P4)   
ODCHILD2 = ODCHILD*OZONE

!stomach
RSTOM = -kas*Astom-ksi*Astom+Amuc*kmuc                       !rate of change in stomach (umol/hr)
AStom = ODOSE+ADOSEM+ODOSEMAL + integ(RStom,0.0)+ODCHILD2    !amount in stomach (umol)

!intestine
RInst = ksi*AStom - kai*AIntM                     !rate of change in intestine (umol/hr) 
AIntM=integ(RInst,0.0)                            !amount in intestine (umol)                                 
CINTM = AINTM/VINT                                !concentration in intestine (umol/L)

!liver
RALM=QH*CBL-QH*CVLM+kai*AIntM+kas*AStom-RALM1-RALM2          !rate of change in liver (umol/hr)
ALM = integ(RALM,0.0)                                        !amt in liver (umol)
CLM = ALM/VH                                                 !concentration in liver (umol/L)
CVLM = CLM/PMalL                                             !concn in venous blood leaving liver (umol/L)

!Liver metabolism of Mal by CYPs--oxidation
RALM1 = (VmaxMalMox*CVLM)/(KmMalMox+CVLM)            !rate of metabolite formation (umol/hr)
ALM1 = integ(RALM1, 0.0)                             !amt oxon formed (umol)

!Liver--metabolism of MAL to MCA/DCA by CaE 
RALM2 = VMAXMALL*CVLM/(KMMALL*(1+CVLO/KI)+CVLM) !rate of metabolites formed (umol/hr) 
ALM2 = integ(RALM2,0.0)                           !amount of metabolites formed (umol)


!kidney
RAKM = QK*CBL-QK*CVKM -RAKM2                          !rate of change in kidney (umol/hr)
AKM = integ(RAKM,0.0)                                !amt in kidney (umol)
CKM = AKM/VK                                         !concn in kidney (umol/L)
CVKM = CKM/PMalK                                     !concn in venous blood leaving kidney (umol/L)

!kidney--metabolism of MAL to MCA/DCA by CaE
RAKM2 = VMAXMALK*CVKM/(KMMALK*(1+CVKO/KI)+CVKM)   !rate of metabolites formed (umol/hr)
AKM2 = integ(RAKM2,0.0)                           !amount of metabolites formed (umol)

!fat
RAFM = QF*CBL-QF*CVFM                                !rate of change in fat (umol/hr)
AFM = integ(RAFM, 0.0)                               !amt in fat (umol)
CFM = AFM/VF                                         !concn. in fat (umol/L)
CVFM = CFM/PMalF                                     !concn. in venous blood leaving fat (umol/L)

!slowly perfused
RASM = QS*CBL-QS*CVSM                                !rate of change in slowly perfused (umol/hr)
ASMal = integ(RASM, 0.0)                             !amt in slowly perfused (umol)
CSM = ASMal/VS                                       !concn. in slowly perfused (umol/L)
CVSM = CSM/PMalS                                     !concn. in venous blood leaving slowly perfused (umol/L)

!brain
RABrM = QBr*CBL-QBr*CVBrM-RABRM2                     !rate of change in brain (umol/hr)
ABrM = integ(RABrM,0.0)                              !amt. in brain (umol)
CBrM = ABrM/VBr                                      !concn in brain (umol/L)
CVBrM = CBrM/PMalBr                                  !concn. in venous blood leaving brain (umol/L)

!brain--metabolism of MAL to MCA/DCA by CaE
RABRM2 = VMAXMALBR*CVBrM/(KMMALBr*(1+CVBrO/KI)+CVBrM)!rate of metabolites formed (umol/hr)
ABRM2 = integ(RABRM2,0.0)                            !amount of metabolites formed (umol)

!rapidly perfused tissues
RARM = QR*CBL-QR*CVRM                                !rate of change in rapidly perfused (umol/hr)
ARM = integ(RARM,0.0)                                !amt in rapidly perfused (umol)
CRM = ARM/VR                                         !concn in rapidly perfused (umol/L)
CVRM = CRM/PMalR                                     !concn in venous blood leaving rapidly perfused (umol/L)


! Dermal exposure
constant year = 364      !days
constant w2 = 21         !days exposed per year
constant d2 = 5          !days exposed/week
constant p2 = 8          !hr exposed/day
DDOSE2 = DDOSE*pulse(0,year*24,w2*24)*pulse(0,7*24,d2*24)*pulse(0,24,p2)
DDOSE3 = DDOSE2*DZONE

ASURF=integ(RASURF,0.0)+DDOSE3                                !amt at skin surface (umol)
CSURF=ASURF/VLIQ                                              !concn at skin surface (umol/L)
RASURF=-((((KPL*SA/1000)*CSURF))*DZONE)                       !rate of change at skin surface (umol/hr)

RADL=((((KPL*SA/1000)*CSURF))*DZONE)-RADLL                    !rate of uptake into skin tissue from skin surface (umol/hr)
ADL=INTEG(RADL,0.0)                                           !amout of uptake (umol)

RADLL=ADL*PSKL					!rate of absorption (umol/hr)
ADLT=INTEG(RADLL,0.0)   !total amt absorbed (umol)
CADERM=ADL/VSKCC        !concn absorbed (umol/L)


!Inhalation Exposures
constant w3 = 21      !days exposed per year
constant d3 = 5       !days exposed per week
constant P3 = 8       !hr exposed per day
CIM = (concmgm/1000)*pulse(0,year*24,w3*24)*pulse(0,7*24,d3*24)*pulse(0,24,P3) !mg/L

CI=CIM/MWMAL*1000*INZONE	                             !inhaled dose concentration (from mg/L to umol/L)

!lung --update with Cecelia's modifications--make sure this is correct
RALINH = QALV * FRACIN * CI                              !rate of uptake into lung (umol/hr)
RALU=QC*(CV-CBL)-(QALV*CLEX) + RALINH                    !rate of change in lung (umol/hr)
ALU=INTEG(RALU,0.0)	                                    !amt in lung (umol)
CLU=ALU/VL 		                                          !concn in lung (umol/L)

ALUINH=INTEG(RALINH,0.0)                                 !amt absorbed in lung (umol)
INMG=ALUINH*MWMAL/BWT/1000                               !amt absorbed (mg/kg)

!for swallowing part of an inhaled dose
RLUGI=FRLUGI*CI*QALV-AMUC*KMUC                   !rate of transfer from lung to GI (umol/hr)
AMUC=INTEG(RLUGI,0.0)                            !amount transferred (umol)
RMUCOS = AMUC*KMUC                               !rate of absorption from GI tract (umol/hr)
ALUNGDOSE = INTEG(RMUCOS, 0.0)                   !amount absorbed in GI tract (umol)

!amt exhaled
CLEX = CBL / PLAIR            !concn exhaled (umol/L)
RAEX = QALV * CLEX            !rate of exhalation (umol/hr)
AEX = INTEG(RAEX, 0.0)        !amt exhaled (umol)

!plasma
RABL=QC*(CV-CBL)+RADLL        	                 !rate of change in mixed blood (arterial & venous; umol/hr)
ABL=INTEG(RABL,0.0)                  		        !amount in mixed blood (umol)
CBL=ABL/VBL			                                !concn in mixed blood (umol/L)

CV=(QH*CVLM+QF*CVFM+QK*CVKM+QS*CVSM+QBr*CVBrM+QR*CVRM)/QC   !concentration in venous blood (umol/L)


!-------------------------------------------------------------------------------
!oxon
!-------------------------------------------------------------------------------

!stomach
RAstomO = -ksiO*AStomO-kasO*AStomO                       !rate of change in stomach (umol/hr)--do we have the drinkingwater here?? 
AStomO = integ(RASTomO,0.0)+ODOSEO+ADOSEO+ODOSEMOX       !amount in stomach (umol)

!intestine
RAIntO = -kaiO*AINTO+ksiO*AStomO                                          !rate of change in intestine (umol/hr)
AintO = integ(RAIntO,0.0)                                                 !amount in intestine (umol)
CINTO = AINTO/VINT                                                        !concn in intestine (umol/L)

!liver
RALO = QH*(CBLO-CVLO)+kaiO*AINTO+kasO*AStomO-RALOD+RALM1-(RHPCE+RHPBE+RHPCR)!rate of change in liver (umol/hr)
ALO = integ(RALO,0.0)                                     !amt in liver (umol)
CLO = ALO/VH                                              !concentration in liver (umol/L)
CVLO = CLO/PMOXL                                          !concn in venous blood leaving liver (umol/L)

!oxon detox--catalytic
RALOD = (VMOXDMPL*CVLO)/(KMOXDMPL*(1+CVLO/KI)+CVLO)
AALOD = integ(RALOD,0.0)

!AChE activity--liver
RHCE=KSHCE-AHCE*(KDHCE+KIHCE*CLO)+HOCE*KRHCE	     ! rate of AChE activity (umol/hr)
AHCE=INTEG(RHCE,IHCE)				                      ! liver AChE activity (umol)
RNHCE=KSHCE-ANHCE*KDHCE				                    ! rate of baseline AChE activity (umol/hr)
ANHCE=INTEG(RNHCE,IHCE)				                    ! Amt of baseline AChE (umol)
RHOCE=AHCE*KIHCE*CLO-HOCE*(KAHCE+KRHCE)		        ! rate of AChE inhibition (umol/hr)
HOCE=INTEG(RHOCE,0.0)				                      ! amt of liver AChE inhibited (umol)
RHPCE=AHCE*KIHCE*CLO				                       ! rate of oxon consumption (umol/hr)
AHPCE=integ(RHPCE,0.0)                             ! amt of oxon consumed (umol)
        
!BuChE activity--liver
RHBE=KSHBE-AHBE*(KDHBE+KIHBE*CLO)+HOBE*KRHBE	     ! rate of BuChE activity (umol/hr)
AHBE=INTEG(RHBE,IHBE)				                      ! liver BuChE activity (umol)
RNHBE=KSHBE-ANHBE*KDHBE				                    ! rate of baseline BuChE act (umol/hr)
ANHBE=INTEG(RNHBE,IHBE)				                    ! Amt of baseline BuChE (umol)
RHOBE=AHBE*KIHBE*CLO-HOBE*(KAHBE+KRHBE)		        ! rate of BuChE inhibition (umol/hr)
HOBE=INTEG(RHOBE,0.0)				                      ! amount of liver BuChE inhibited (umol)
RHPBE=AHBE*KIHBE*CLO				                       ! rate of oxon consumption (umol/hr)
AHPBE=integ(RHPBE,0.0)                             ! amt of oxon consumed (umol)
        
!CaE activity--liver
RHCR=KSHCR-AHCR*(KDHCR+KIHCR*CLO)+HOCR*KRHCR	     ! rate of CaE activity (umol/hr)
AHCR=INTEG(RHCR,IHCR)				                      ! liver CaE activity (umol)
RNHCR=KSHCR-ANHCR*KDHCR				                    ! rate of baseline CaE act (umol/hr)
ANHCR=INTEG(RNHCR,IHCR)				                    ! Amt of baseline CaE (umol)
RHOCR=AHCR*KIHCR*CLO-HOCR*(KAHCR+KRHCR)		        ! rate of CaE inhibition (umol/hr)
HOCR=INTEG(RHOCR,0.0)				                      ! amount of liver CaE inhibited (umol)
RHPCR=AHCR*KIHCR*CLO				                       ! rate of oxon consumption (umol/hr)
AHPCR=integ(RHPCR,0.0)                             ! amt of oxon consumed (umol)


!liver B-esterase (AChE, BuChE, and CaE) activity
HBE=AHCE+AHBE+AHCR			                           ! total B-esterase=AChE+BuChE+CaE (umol)
IHE=100*(HBE/(ANHCE+ANHBE+ANHCR))	                ! % total B-esterase inhibition
HCE=100*(AHCE/ANHCE)			                         ! % AChE inhibition
HBES=100*(AHBE/ANHBE)			                        ! % BuChE inhibition
HCR=100*(AHCR/ANHCR)			                         ! % CaE inhibition


!fat
RAFO = QF*CBLO-QF*CVFO                             !rate of change in fat (umol/hr)
AFO = integ(RAFO, 0.0)                             !amt in fat (umol)
CFO = AFO/VF                                       !concn. in fat (umol/L)
CVFO = CFO/PMOXF                                   !concn. in venous blood leaving fat (umol/L)

!slowly perfused
RASO = QS*CBLO-QS*CVSO                             !rate of change in slowly perfused (umol/hr)
ASO = integ(RASO, 0.0)                             !amt in slowly perfused (umol)
CSO = ASO/VS                                       !concn. in slowly perfused (umol/L)
CVSO = CSO/PMOXS                                   !concn. in venous blood leaving slowly perfused (umol/L)

!rapidly perfused tissues
RARO = QR*CBLO-QR*CVRO                            !rate of change in rapidly perfused (umol/hr)
ARO = integ(RARO,0.0)                             !amt in rapidly perfused (umol)
CRO = ARO/VR                                      !concn in rapidly perfused (umol/L)
CVRO = CRO/PMOXR                                  !concn in venous blood leaving rapidly perfused (umol/L)

!brain
RABrO = QBr*CBLO-QBr*CVBrO-RABROD-(RBPCE+RBPBE+RBPCR)!rate of change in brain (umol/hr)
ABrO = integ(RABrO,0.0)                           !amt. in brain (umol)
CBrO = ABrO/VBr                                   !concn in brain (umol/L)
CVBrO = CBrO/PMOXBR                               !concn. in venous blood leaving brain (umol/L)

!oxon detox--catalytic
RABROD = (VMOXDMPB*CVBrO)/(KMOXDMPB*(1+CVBrO/KI)+CVBrO)
AABRO = integ(RABROD,0.0)

!AChE activity--brain
RBCE=KSBCE-ABCE*(KDBCE+KIBCE*CBrO)+BOCE*KRBCE	       ! rate of AChE activity (umol/hr)
ABCE=INTEG(RBCE,IBCE)				                         ! brain AChE activity (umol)
RNBCE=KSBCE-ANBCE*KDBCE				                       ! rate of baseline AChE act (umol/hr)
ANBCE=INTEG(RNBCE,IBCE)				                       ! Amt of baseline AChE (umol)
RBOCE=ABCE*KIBCE*CBrO-BOCE*(KABCE+KRBCE)		          ! rate of AChE inhibition (umol/hr)
BOCE=INTEG(RBOCE,0.0)				                         ! amount of brain AChE inhibited (umol)
RBPCE=ABCE*KIBCE*CBrO				                         ! rate of oxon consumption (umol/hr)
ABPCE=integ(RBPCE,0.0)                                ! amt of oxon consumed (umol)
        
!BuChE activity--brain
RBBE=KSBBE-ABBE*(KDBBE+KIBBE*CBrO)+BOBE*KRBBE	       ! rate of BuChE activity (umol/hr)
ABBE=INTEG(RBBE,IBBE)				                         ! brain BuChE activity (umol)
RNBBE=KSBBE-ANBBE*KDBBE				                       ! rate of baseline BuChE act (umol/hr)
ANBBE=INTEG(RNBBE,IBBE)				                       ! Amt of baseline BuChE (umol)
RBOBE=ABBE*KIBBE*CBrO-BOBE*(KABBE+KRBBE)		          ! rate of BuChE inhibition (umol/hr)
BOBE=INTEG(RBOBE,0.0)				                         ! amount of brain BuChE inhibited (umol)
RBPBE=ABBE*KIBBE*CBrO 				                        ! rate of oxon consumption (umol/hr)
ABPBE=integ(RBPBE,0.0)                                ! amt of oxon consumed (umol)
        
!CaE activity--brain
RBCR=KSBCR-ABCR*(KDBCR+KIBCR*CBrO)+BOCR*KRBCR	       ! rate of CaE activity (umol/hr)
ABCR=INTEG(RBCR,IBCR)				                         ! brain CaE activity (umol)
RNBCR=KSBCR-ANBCR*KDBCR				                       ! rate of baseline CaE act (umol/hr)
ANBCR=INTEG(RNBCR,IBCR)				                       ! Amt of baseline CaE (umol)
RBOCR=ABCR*KIBCR*CBrO-BOCR*(KABCR+KRBCR)		          ! rate of CaE inhibition (umol/hr)
BOCR=INTEG(RBOCR,0.0)				                         ! amount of brain CaE inhibited (umol)
RBPCR=ABCR*KIBCR*CBrO				                         ! rate of oxon consumption (umol/hr)
ABPCR=integ(RBPCR,0.0)                                ! amt of oxon consumed (umol)

!brain B-esterase (AChE, BuChE, and CaE) activity
BBE=ABCE+ABBE+ABCR			                              ! total B-esterase=AChE+BuChE+CaE (umol)
IBE=100*(BBE/(ANBCE+ANBBE+ANBCR))	                   ! total B-esterase inhibition
BCE=100*(ABCE/ANBCE)			                            ! % AChE inhibition
BBES=100*(ABBE/ANBBE)			                           ! % BuChE inhibition
BCR=100*(ABCR/ANBCR)			                            ! % CaE inhibition

!kidney
RAKO = QK*CBLO-QK*CVKO-RAKOD -(RKPCE+RKPBE+RKPCR)  !rate of change in kidney (umol/hr)
AKO = integ(RAKO,0.0)                              !amt in kidney (umol)
CKO = AKO/VK                                       !concn in kidney (umol/L)
CVKO = CKO/PMOXK                                   !concn in venous blood leaving kidney  (umol/L)

!oxon detox--catalytic
RAKOD = (VMOXDMPK*CVKO)/(KMOXDMPK*(1+CVKO/KI)+CVKO)
AAKOD = integ(RAKOD,0.0)

! AChE activity--kidney
RKCE=KSKCE-AKCE*(KDKCE+KIKCE*CKO)+KOCE*KRKCE	            ! rate of AChE activity (umol/hr)
AKCE=INTEG(RKCE,IKCE)				                             ! kidney AChE activity (umol)
RNKCE=KSKCE-ANKCE*KDKCE				                           ! rate of baseline AChE act (umol/hr)
ANKCE=INTEG(RNKCE,IKCE)				                           ! Amt of baseline AChE (umol)
RKOCE=AKCE*KIKCE*CKO-KOCE*(KAKCE+KRKCE)		               ! rate of AChE inhibition (umol/hr)
KOCE=INTEG(RKOCE,0.0)				                             ! amount of kidney AChE inhibited (umol)
RKPCE=AKCE*KIKCE*CKO				                              ! rate of oxon consumption (umol/hr)
AKPCE=integ(RKPCE,0.0)                                    ! amt of oxon consumed (umol)
        
! BuChE activity--kidney
RKBE=KSKBE-AKBE*(KDKBE+KIKBE*CKO)+KOBE*KRKBE	            ! rate of BuChE activity (umol/hr)
AKBE=INTEG(RKBE,IKBE)				                             ! kidney BuChE activity (umol)
RNKBE=KSKBE-ANKBE*KDKBE				                           ! rate of baseline BuChE act (umol/hr)
ANKBE=INTEG(RNKBE,IKBE)				                           ! Amt of baseline BuChE (umol)
RKOBE=AKBE*KIKBE*CKO-KOBE*(KAKBE+KRKBE)		               ! rate of BuChE inhibition (umol/hr)
KOBE=INTEG(RKOBE,0.0)				                             ! amount of kidney BuChE inhibited (umol)
RKPBE=AKBE*KIKBE*CKO 				                             ! rate of oxon consumption (umol/hr)
AKPBE=integ(RKPBE,0.0)                                    ! amt of oxon consumed (umol)
        
! CaE activity--kidney
RKCR=KSKCR-AKCR*(KDKCR+KIKCR*CKO)+KOCR*KRKCR	            ! rate of CaE activity (umol/hr)
AKCR=INTEG(RKCR,IKCR)				                             ! kidney CaE activity (umol)
RNKCR=KSKCR-ANKCR*KDKCR				                           ! rate of baseline CaE act (umol/hr)
ANKCR=INTEG(RNKCR,IKCR)				                           ! Amt of baseline CaE (umol)
RKOCR=AKCR*KIKCR*CKO-KOCR*(KAKCR+KRKCR)		               ! rate of CaE inhibition (umol/hr)
KOCR=INTEG(RKOCR,0.0)				                             ! amount of kidney CaE inhibited (umol)
RKPCR=AKCR*KIKCR*CKO				                              ! rate of oxon consumption (umol/hr)
AKPCR=integ(RKPCR,0.0)                                    ! amt of oxon consumed (umol)

!kidney B-esterase (AChE, BuChE, and CaE) activity
KBE=AKCE+AKBE+AKCR			                                  ! total B-esterase=AChE+BuChE+CaE (umol)
IKE=100*(KBE/(ANKCE+ANKBE+ANKCR))	                       ! % total B-esterase inhibition
KCE=100*(AKCE/ANKCE)			                                ! % AChE inhibition
KBES=100*(AKBE/ANKBE)			                               ! % BuChE inhibition
KCR=100*(AKCR/ANKCR)			                                ! % CaE inhibition


!blood
RABLO=QC*(CVO-CBLO)-(RBLPBE+RBLPCR+RBLPCE+RRBPCE) !rate of change in blood (umol/hr)
ABLO=integ(RABLO,0.0)                          !amount in blood (umol)
CBLO=ABLO/VBL				                          !concn in blood (umol/L)

CVO=(QH*CVLO+QF*CVFO+QS*CVSO+QR*CVRO+QBr*CVBrO+QK*CVKO)/QC   !concn in venous blood (umol/L)


! AChE activity--plasma
RBLCE=KSBLCE-ABLCE*(KDBLCE+KIBLCE*CBLO)+BLOCE*KRBLCE	! rate of AChE activity (umol/hr)
ABLCE=INTEG(RBLCE,IBLCE)      				                ! plasma AChE activity (umol)
RNBLCE=KSBLCE-ANBLCE*KDBLCE				                   ! rate of baseline AChE act (umol/hr)
ANBLCE=INTEG(RNBLCE,IBLCE)				                    ! Amt of baseline AChE (umol)
RBLOCE=ABLCE*KIBLCE*CBLO-BLOCE*(KABLCE+KRBLCE)		    ! rate of AChE inhibition (umol/hr)
BLOCE=INTEG(RBLOCE,0.0)					                     ! amount of plasma AChE inhibited (umol)
RBLPCE=ABLCE*KIBLCE*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPCE=integ(RBLPCE,0.0)                              ! amt of oxon consumed (umol)

! BuChE activity--plasma
RBLBE=KSBLBE-ABLBE*(KDBLBE+KIBLBE*CBLO)+BLOBE*KRBLBE	! rate of BuChE activity (umol/hr)
ABLBE=INTEG(RBLBE,IBLBE)				                      ! plasma BuChE activity (umol)
RNBLBE=KSBLBE-ANBLBE*KDBLBE				                   ! rate of baseline BuChE act (umol/hr)
ANBLBE=INTEG(RNBLBE,IBLBE)				                    ! Amt of baseline BuChE (umol)
RBLOBE=ABLBE*KIBLBE*CBLO-BLOBE*(KABLBE+KRBLBE)		    ! rate of BuChE inhibition (umol/hr)
BLOBE=INTEG(RBLOBE,0.0)					                     ! amount of plasma BuChE inhibited (umol)
RBLPBE=ABLBE*KIBLBE*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPBE=integ(RBLPBE,0.0)                              ! Amt of oxon consumed (umol)
        
! CaE activity--plasma
RBLCR=KSBLCR-ABLCR*(KDBLCR+KIBLCR*CBLO)+BLOCR*KRBLCR	! rate of CaE activity (umol/hr)
ABLCR=INTEG(RBLCR,IBLCR)				                      ! plasma CaE activity (umol)
RNBLCR=KSBLCR-ANBLCR*KDBLCR				                   ! rate of baseline CaE act (umol/hr)
ANBLCR=INTEG(RNBLCR,IBLCR)				                    ! Amt of baseline CaE (umol)
RBLOCR=ABLCR*KIBLCR*CBLO-BLOCR*(KABLCR+KRBLCR)		    ! rate of CaE inhibition (umol/hr)
BLOCR=INTEG(RBLOCR,0.0)					                     ! amount of plasma CaE inhibited (umol)
RBLPCR=ABLCR*KIBLCR*CBLO				                      ! rate of oxon consumption (umol/hr)
ABLPCR=integ(RBLPCR,0.0)                              ! amt of oxon consumed (umol)

!plasma B-esterase (AChE, BuChE, and CaE) activity
BLBE=ABLCE+ABLBE+ABLCR				                !total B-esterase=AChE+BuChE+CaE (umol)
IBLE=100*(BLBE/(ANBLCE+ANBLBE+ANBLCR))		    ! % Total B-esterase inhibition in plasma
BLCE=100*(ABLCE/ANBLCE)				               ! % AChE inhibition in plasma
BLBES=100*(ABLBE/ANBLBE)			                ! % BuChE inhibition in plasma
BLCR=100*(ABLCR/ANBLCR)				               ! % CaE inhibition in plasma

! AChE activity--RBCs
RRBCCE=KSRBCE-ARBCE*(KDRBCE+KIRBCE*CBLO)+RBCOCE*KRRBCE	! rate of AChE activity (umol/hr)
ARBCE=INTEG(RRBCCE,IRBCE)				                       ! RBC AChE activity (umol)
RNRBCCE=KSRBCE-ANRBCE*KDRBCE				                    ! rate of baseline AChE act (umol/hr)
ANRBCE=INTEG(RNRBCCE,IRBCE)				                     ! Amt of baseline AChE (umol)
RRBOCE=ARBCE*KIRBCE*CBLO-RBCOCE*(KARBCE+KRRBCE)		     ! rate of AChE inhibition (umol/hr)
RBCOCE=INTEG(RRBOCE,0.0)				                        ! amount of RBC AChE inhibited (umol)
RRBPCE=ARBCE*KIRBCE*CBLO				                        ! rate of oxon consumption (umol/hr)
ARBPCE=integ(RRBPCE,0.0)                                ! amt of oxon consumed (umol)

!RBC B-esterase (AChE only)activity
RBCCE=100*(ARBCE/ANRBCE)			                          ! % AChE inhibition in RBCs
RBCPERC=100-RBCCE							                         ! % inhibited versus inhibition


!--------------------------------------------------------------------------------------
!metabolite excretion
!MCA + DCA metabolites--compartment 1
RAMCA = RAKM2+RABRM2+RALM2             !total rate of metabolite formation (umol/hr)
AMCA = integ(RAMCA, 0.0)                      !amount of MCA+DCA (umol)
RA1 = RAMCA-RAMCAex                           !rate of change of MCA+DCA in compartment 1 (umol/hr)
A1 = integ(RA1,0.0)                           !amount of MCA+DCA in compartment 1 (umol)
CBMCA = A1/V1                                 !concentration of MCA+DCA in compartment 1 (umol/L)
RAMCAex = A1*KE1                              !rate of MCA+DCA excretion (umol/hr)
AMCAex = integ(RAMCAex,0.0)                   !amount of MCA+DCA excreted (umol)


end  !dynamic

!----------------------------------------------------------------------------------
!mass balance--update this
TMASSMAL=ASTOM+AINTM+ALM+AKM+AFM+ASMal+ABRM+ARM+ABL+ALU     !umol
TMASSMOX=ASTOMO+AINTO+ALO+AFO+ASO+AKO+ARO+ABRO+ABLO         !umol
TMASSMCA=A1+AMCAEX                                          !umol        
TMASSODT=AALOD+AAKOD+AABRO                                  !umol 
TMASSOXONNC=AHPCE+AHPBE+AHPCR+ABPCE+ABPBE+ABPCR+AKPCE+AKPBE+AKPCR+ABLPCE+ABLPBE+ABLPCR+ARBPCE     !non-catalytic oxon detox (umol)         
TMASSTOTAL=TMASSMAL+TMASSMOX+TMASSMCA+TMASSODT+TMASSOXONNC              !umol--total better add up to what went in 


TDOSE=ODOSE+ODOSEMAL+ODOSEMOX+ADOSEM+ADOSEO+ODOSEO+ODCHILD2+ALUINH+ALUNGDOSE-AEX+ADLT+ADL+ASURF  !total dose (umol) 
MASSBAL=TDOSE/(TMASSTOTAL+1E-99)  !should equal 1 (or really close to it)



end  !derivative
end  !program
