#!/usr/bin/perl


    $totalmode = 1;



@hv = ( {"anode" => 160, "drift" => 100, "firstoff" => 80, "c0" => 110, "c1" => 125, "s2off" => -5 },
	{"anode" => 160, "drift" => 100, "firstoff" => 80, "c0" => 110, "c1" => 125, "s2off" => -5 },
	{"anode" => 135, "drift" =>  90, "firstoff" => 85, "c0" => 110, "c1" => 135, "s2off" => -5 },
	{"anode" => 130, "drift" =>  90, "firstoff" => 90, "c0" => 110, "c1" => 140, "s2off" => -5 },
	{"anode" => 145, "drift" => 100, "firstoff" => 95, "c0" => 110, "c1" => 150, "s2off" => -5 },
	{"anode" => 160, "drift" => 115, "firstoff" => 95, "c0" => 110, "c1" => 150, "s2off" => -5 }
	);

$hvadd{'anode'} =  0;
$hvadd{'drift'} = 20;


@textnr = ('zero','one','two','three','four','five');

for ($l=0; $l<6; $l++) {
    
#    @length[$l] = ( {"anode", "drift"}, {"anode", "drift"}, {"anode", "drift"}, 
#		    {"anode", "drift"}, {"anode", "drift"} ); 

    foreach $t ('anode', 'drift') {
	
	$length[$s][$l]{$t} = 1;
	print "\\newcommand{\\hvCable".$t."L".$textnr[$l]."Extent}{".$hv[$l]{$t}."}\n";
	
	$extent[$l]{$t}    = $hv[$l]{$t};
	$length[0][$l]{$t} = $hv[$l]{$t} + $hv[$l]{'firstoff'} + $hvadd{$t};
	$length[1][$l]{$t} = $length[0][$l]{$t} + $hv[$l]{'c1'};
	$length[2][$l]{$t} = $length[1][$l]{$t} + $hv[$l]{'c0'};# + $hv[$l]{'s2off'};
	$length[3][$l]{$t} = $length[2][$l]{$t} + $hv[$l]{'c1'};# - $hv[$l]{'s2off'};
	$length[4][$l]{$t} = $length[3][$l]{$t} + $hv[$l]{'c1'};
	
	
       
    }
}

if ($totalmode) {
    for ($l=0; $l<6; $l++) {
	    for ($s=0; $s<5; $s++) {

		$totaldrift += $length[$s][$l]{"drift"};
		$totalanode += $length[$s][$l]{"anode"};

		
	}
    }

    print "Anode: ".($totalanode/100)."\n";
    print "Drift: ".($totaldrift/100)."\n";
    print "Total: ".(($totaldrift+$totalanode)/100)."\n";

    exit;
}


for ($l=0; $l<6; $l++) {
    foreach $t ('anode', 'drift') {

    print "\\newcommand{\\hvCable".$t."L".$textnr[$l]."Extent}{".$extent[$l]{$t}."}\n";

    for ($s=0; $s<5; $s++) {
    
	    
	    print "\\newcommand{\\hvCable".$t."L".$textnr[$l]."S".$textnr[$s]."}{";
	    print $length[$s][$l]{$t}."}\n";
	}
    }
}
