#!/usr/bin/perl

# don't do too many at beginning or it won't work
#$steps = sprintf("-steps 4 8 7 6 5");
#doesnt work $steps = sprintf("-steps 5 32 16 8 4 2");
# works with 97to98 $steps = sprintf("-steps 5 4 4 4 4 4");
# works great 97to98 $steps = sprintf("-steps 5 8 4 4 4 4");

# works great for 98to99 $steps = sprintf("-steps  4 8 32 8 2");
# works great for 98to99 $steps = sprintf("-steps  3 32 8 2");
$steps = sprintf("-steps  3 64 16 1");

# example: 4 4 3 2 1   does 4 then 3 then 2, then 1 (1 means none)
#          4 3 3 3 3   does 3 repetitions at each of the 4 levels

$fileO = sprintf("parameters_pairwise.txt"); # cumulative
`rm $fileO`; # initialize to empty

$firstframe=90; $lastframe=112;  # e.g. if there are 250 frames numbered 0 to 249, enter 249

$firstframe=97; $lastframe=98;
$firstframe=86; $lastframe=119;

printf("\n");
for ($counter=$firstframe+1; $counter<=$lastframe; $counter++) {
  $filea = sprintf("orbit2/v%04d.jpg", $counter-1);
  $fileb = sprintf("orbit2/v%04d.jpg", $counter);

  $fileo = sprintf("porkparameters%03d_%03d.txt", $counter,$counter-1);
  # last line of above file is the final answer
  # above file is cumulative result

  printf("about to djpeg $filea and $fileb\n");
  `djpeg -grayscale $filea > deleteme_deletemea.pgm`;
  `djpeg -grayscale $fileb > deleteme_deletemeb.pgm`;
  printf("about to estpchirp2m\n");
  `estpchirp2m deleteme_deletemea.pgm deleteme_deletemeb.pgm -outp $fileo -display $steps > pork_stdout.txt`;

  # cat files together
  `tail -1 $fileo > porkparameter`;
  `cat porkparameter >> $fileO`;

}

