#!/usr/bin/perl

# takes about 40 minutes with 33 colour pictures on netwinder with 64m RAM

$Ps = sprintf("Parameters_pairwise.txt"); # cumulative, plurality of parameters


$firstframe=110;  # always 0 for now
$lastframe=129;  # e.g. if there are 34 frames numbered 0 to 33, enter 33
# in this case Parameters should have 34 entries


for ($counter=$firstframe; $counter<=$lastframe; $counter++) {
  # allows use of Parameters_pairise, where 1st line corresponds to
  # $firstframe, and not always frame v000.jpg
  $count1 = $counter-$firstframe+1;
  printf("counter = $counter   count1 = $count1\n");

  $filein = sprintf("s%03d.jpg", $counter);
  $fileout = sprintf("s%03dd.ppm", $counter);
  printf("about to djpeg $filein\n");
  `djpeg $filein > deleteme_deleteme.ppm`;

  # open file and write header
  #`head -$count1 $Ps | tail -1 > $P`;
  # e.g. to get 4th entry: head -4 Parameters_pairwise.txt | tail -1
  my $pchirp_parameters = `head -$count1 $Ps | tail -1`;
  `pchirp2nocrop deleteme_deleteme.ppm $fileout $pchirp_parameters`;
}
