#!/usr/bin/perl

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

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

$firstframe=0;  # always 0 for now

for ($counter=$firstframe; $counter<=$lastframe; $counter++) {
  $count1 = $counter+1;
  printf("counter = $counter   count1 = $count1\n");
  $pchirp2nocropcommandfile = sprintf("pchirp2nocropcommandfile%02d.sh",$counter);  # just one parameter (one line of text)
  printf("phcirp2nocropcommandfile = $pchirp2nocropcommandfile\n");

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

  # open file and write header
  open(PORKCOMMANDS, ">$pchirp2nocropcommandfile");
  print PORKCOMMANDS "#!/bin/sh\n";
  printf("about to print command pchirp2nocrop\n");
  print PORKCOMMANDS "pchirp2nocrop deleteme_deleteme.ppm $fileout ";  # no carriage ret
  close(PORKCOMMANDS);
  #`head -$count1 $Ps | tail -1 > $P`;
  # e.g. to get 4th entry: head -4 Parameters_pairwise.txt | tail -1
  `head -$count1 $Ps | tail -1 >> $pchirp2nocropcommandfile`;
  `chmod a+x $pchirp2nocropcommandfile`;
  #`$pchirp2nocropcommandfile`;
  #`/home/whatever/chirp2nocropcommandfile33.sh`;  # doesn't work
  `sh $pchirp2nocropcommandfile`;
}

