#!/usr/bin/perl -w

my $usage = "USAGE: $0 linetype width code [linetype]
  width will be the width of each code symbol
  code should be a string of 1s and 0s (which will be 1s and -1s when done)
  lt is an optional linetype (an integer)
  EG:  $0 8 000111010111010001110111010111000 4\n";
my $w    = shift or die $usage;
my $code = shift or die $usage;
my $lt   = shift || 1;

my $x = $w / 2;
for (split //, $code) {
    print 'set label "',
      $_ || -1, '" at ', $x, ",0 center\n";
    $x += $w;
}

print "plot '-' with lines lt $lt\n";
if ($code =~ /^1/) {
    print "0 -1\n";
} else {
    print "0 1\n";
}

$x = 0;
for (split //, $code) {
    print $x, " ", $_||-1, "\n";
    $x += $w;
    print $x, " ", $_||-1, "\n";
}

if ($code =~ /1$/) {
    print "$x -1\ne\n";
} else {
    print "$x 1\ne\n";
}

