#!/usr/bin/perl

$hcidname = shift;

$hcid       = 0;
$tp         = 0;
$zs         = 0;
$distrkl    = 0;
$csmtrkl    = 0;
$opts       = 0;
$zs_adcmask = 0;
$zs_zstrckl = 2;

if ($hcidname =~ /^zs/) {
    $zs = 1;
}

if ($hcidname =~ /-deh/) {
    $opts  = $opts | 1;
}

if ($hcidname =~ /-e(\d*)/) {
    print "full readout every $1 events\n";
    if ($1 == 128) { 
	$opts = 1;
    }
    elsif ($1 == 256) {
	$opts = 2;
    }
    elsif ($1 == 1024) {
	$opts = 3;
    }
}

if ($hcidname =~ /-notrk/) {
    $distrkl = 1;
}

if ($hcidname =~ /-csmtrk/) {
    $csmtrkl = 1;
}

if ($hcidname =~ /-stat/) {
    $opts = $opts | 1;
}

if ($hcidname =~ /^testpattern(\d).*/) {
    $tp = 1;
    $opts = $1;
    $distrkl = 1; # tracklets should be disabled in testpattern mode
}

$hcid = $tp << 14 | $zs << 13 | $distrkl << 12 | $csmtrkl << 11| $opts << 8 | $zs_adcmask << 2 | $zs_zstrckl;

print "22 0 $hcid 0 0\n";

open outfile, ">src/hcid/$hcidname.DAT";

print outfile "22 0 $hcid 0 0\n";

close outfile;
