#!/usr/bin/perl

use warnings;

# This code opens up the NIST bit file given as parameter and returns the number of bits on
# each line. All samples (chips) MUST have the same number of bits/line -- an ERROR is generated
# if this is not true

if ($#ARGV != 0)
   { die "ERROR: get_bit_stream_length.pl: bitfile (directory/xxx.txt)\n"; }

$bitfile = $ARGV[0];

# Open up the input file
open(INFILE, "$bitfile") || die;

$i = 0;
while ( $_ = <INFILE> )
   {
   chomp;
   @bits = split(//);

   if ( $i == 0 )
      { $bit_stream_length = scalar @bits; }
   elsif ( scalar @bits != $bit_stream_length )
      { print "ERROR: BIT steam lengths DIFF in file $bitfile -- $bit_stream_length vs ", scalar @bits, "!\n"; die; }
   $i++;
   }
close INFILE;

print $bit_stream_length, "X", $i, "\n";
