#!/usr/bin/perl -w

use strict;
my $scale = shift @ARGV;

sub sc($) {
    my $val = shift;
    my $off = 0.5;
    if ($val < 0) { $off = -$off; }

    int($scale * $val + $off);
}

my $Tcnt = 0;
my $Hcnt = 0;
while (<>) {
    chomp;

    my @fld = split;

    if      ($Tcnt) {
	$Tcnt--;
    } elsif ($Hcnt) {
	my @lst = split(/[ ,]+/, $_);
	$Hcnt--;
	if (m/^M/) {
	    printf("%s %s,%s\n", $lst[0], sc($lst[1]), sc($lst[2]));
	} elsif (m/^L/) {
	    printf("%s %s,%s\n", $lst[0], sc($lst[1]), sc($lst[2]));
	} elsif (m/^C/) {
	    printf("%s %s,%s %s,%s %s,%s\n", $lst[0], sc($lst[1]), sc($lst[2]), sc($lst[3]), sc($lst[4]), sc($lst[5]), sc($lst[6]));
	} elsif (m/^Z/i) {
	    print "z\n";
	}
	next;
    } elsif (m/^(v|{|})/) {
    } elsif (m/^L/) {
	for my $ix ((1,2,3,4,6,9,10)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^B/) {
	for my $ix ((1,2,3,4,6,9,10,12,14,16)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^V/) {
	for my $ix ((1,2,3,5,6,8,9,11,13,15)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^A/) {
	for my $ix ((1,2,3,7,10,11)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^T/) {
	for my $ix ((1,2,4)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
	$Tcnt = $fld[9];
    } elsif (m/^N/) {
	for my $ix ((1,2,3,4)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^B/) {
	for my $ix ((1,2,3,4)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^P/) {
	for my $ix ((1,2,3,4)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^C/) {
	for my $ix ((1,2)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
    } elsif (m/^H/) {
	for my $ix ((2,5,6,8,10,12)) {
	    $fld[$ix] = sc($fld[$ix]);
	}
	$Hcnt = $fld[13];
    } else {
	print "warn fallthrough\n";
    }

    print join(" ", @fld), "\n";
}

__END__
