#!/usr/bin/perl
#
#
# I took two sets of images:
#
#       sdss-021.fit    to    sdss-075.fit
#       sdss_a-001.fit        sdss_a-312.fit
#
# I want to rename the "_a" series so that the files have names like
#
#       sdss_a-001.fit      -->   sdss_076.fit
#       sdss_a-002.fit      -->   sdss_077.fit
#             ....                               
#       sdss_a-312.fit      -->   sdss_387.fit
#
# MWR 7/7/2010

$debug = 1;

$offset = 75;
for ($i = 1; $i <= 312; $i++) {
  $old_name = sprintf "sdss_a-%03d.fit", $i;
  $new_number = $i + $offset;
  $new_name = sprintf "sdss-%03d.fit", $new_number;
  
  $cmd = "cp $old_name $new_name";
  printf "cmd is ..%s.. \n", $cmd;
  $ret = exec_cmd($cmd);
}

exit 0;




##############################################################################
# PROCEDURE: exec_cmd
#
# DESCRIPTION: Execute the given shell command line.  If the $debug flag
#              is set, we print to stdout the command line, and
#              also print out the result string.
#
# RETURNS:
#              the result of the command
#
#
sub exec_cmd {

  my($cmd, $ret);

  $cmd = $_[0];

  if ($debug > 0) {
    printf "cmd is ..$cmd.. \n";
  }
  $ret = `$cmd`;
  if ($debug > 0) {
    printf "ret is ..$ret.. \n";
  }

  return($ret);
}


