##################INITIALIZATION EQUATIONS #################
$time=0;
$maxtime=24*$tend;
$available = 0;
$absorprate = .397;
if($isotope eq "Penicillin G potassium" or $isotope eq "Penicillin G sodium"){
$vd=500;
$percbound=.65;
$available=.3;
$clearance=.28;
}else{
$vd=400;
$percbound=.8;
$available=.6;
$clearance=.26;
}
if($isotope eq "Penicillin G sodium" or $isotope eq "Penicillin V potassium"){
$mgperunit=.6E-4;
}else}
$mgperunit=.625E-4;
}
$unitsdose = $mgdose/$mgperunit;
$dosing = 0;
$absorbed = $available*$absorprate;
$plasma = 0;
$vd = $weight*$vdperkg;
$conc = $plasma/$vd;
$gfr = 7500;
$excretion = $clearance*$conc*$gfr;
$binding = $plasma*$percbound;
$metarate = .2;
$metabolize = $plasma*$metarate;
$excreted = 0;
$proteinbound = 0;
$metabolite = 0;
$interval=24/$frequency;
$pulse=0;
$xmax=24*$xmax;
################## RUNTIME EQUATIONS ######################
open (PEN, "> /tmp/pen$$.dat") || die "couldn't open pen$$.dat: $! \n";
open (TH, "> /tmp/th$$.dat") || die "couldn't open th$$.dat: $! \n";
for ($time=0;$time<=$maxtime;$time +=$dt) {
print PEN "$time $conc\n";
print TH "$time $threshold\n";
$available = $available + ($dosing - $absorbed) * $dt;
$plasma = $plasma + ($absorbed - $excretion - $binding - $metabolize) * $dt;
$excreted = $excreted + ($excretion) * $dt;
$proteinbound = $proteinbound + ($binding) * $dt;
$metabolite = $metabolite + ($metabolize) * $dt;
if ($time == $pulse) {
$dosing=($unitsdose*$percentavail/$dt);
$pulse +=$interval;
}else {
$dosing=0;
{
$absorbed = $available*$absorprate;
$conc = $plasma/$vd;
$excretion = $clearance*$conc*$gfr;
$binding = $plasma*$percbound;
$metabolize = $plasma*$metarate;
}
close (TH);
close (PEN);