Index: /tags/ipp-pv3-20140717/ippScripts/scripts/sc_mk_staticsky_mdc.pl
===================================================================
--- /tags/ipp-pv3-20140717/ippScripts/scripts/sc_mk_staticsky_mdc.pl	(revision 37442)
+++ /tags/ipp-pv3-20140717/ippScripts/scripts/sc_mk_staticsky_mdc.pl	(revision 37442)
@@ -0,0 +1,96 @@
+#! /usr/bin/env perl                                                                                                                                                       
+use Carp;
+use warnings;
+use strict;
+
+use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
+use Pod::Usage qw( pod2usage );
+
+
+my $remote_root = '/scratch3/watersc1/';
+
+my ($compmap_file);
+GetOptions(
+    'compmap=s'   => \$compmap_file,
+    ) or pod2usage( 2 );
+
+pod2usage( -msg => "Required options: --compmap", -exitval => 3) unless
+    defined($compmap_file);
+
+if ($#ARGV % 2 != 0) { 
+    die "Do not have a matched pair of path_base/stack_id values";
+}
+
+my %component_map = ();
+open(CM,$compmap_file) || die "Cannot find requested compmap file";
+while(<CM>) {
+    chomp;
+    my ($symbolic_name,$disk_name) = split /\s+/;
+    $component_map{$symbolic_name} = $disk_name;
+}
+close(CM);
+
+my $counter = 0;
+
+
+$mdc_content .= "INPUT  MULTI\n";
+
+#foreach my $path_base (@ARGV) {
+for (my $index = 0; $index <= $#ARGV; $index += 2) {
+    my $path_base = $ARGV[$index];
+    my $stack_id  = $ARGV[$index+1];
+    my $mdc_content = "";
+    my $file = "";
+    my $error = 0;
+    
+
+#   print "PB: $path_base\n";
+
+    #header
+    $mdc_content .= "INPUT${counter}  METADATA\n";
+    $mdc_content .= "    STACK_ID        S64  " . $stack_id . "\n";
+
+    # check each file against its possible locations, incrementing the error counter if not found
+    $file = do_checks("${path_base}.unconv.fits",$error);
+    $mdc_content .=  "   RAW:IMAGE           STR     $file\n";
+
+    $file = do_checks("${path_base}.unconv.mask.fits",$error);
+    $mdc_content .=  "   RAW:MASK            STR     $file\n";
+
+    $file = do_checks("${path_base}.unconv.wt.fits",$error);
+    $mdc_content .=  "   RAW:VARIANCE        STR     $file\n";
+    
+    $file = do_checks("${path_base}.psf",$error);
+    $mdc_content .=  "   PSF             STR     $file\n";
+
+    $file = do_checks("${path_base}.unconv.num.fits",$error);
+    $mdc_content .=  "   RAW:EXPNUM             STR     $file\n";
+    
+    $file = do_checks("${path_base}.cmf",$error);
+    $mdc_content .=  "   SOURCES         STR     $file\n";
+
+    $mdc_content .=  "END\n\n";
+#    print "MDC: $mdc_content\n";
+    # If we had no errors, print it and move on.
+    if ($error == 0) {
+	print $mdc_content;
+    }
+
+    $counter++;
+}
+
+sub do_checks {
+    my ($cfile,$error) = @_;
+#    print  ">$cfile<\n";
+    if (! ((-e $cfile)&&(-s $cfile))) { # This cfile does not exist or is zero size.
+	my $disk = $component_map{$cfile};
+	$cfile = "${disk}";
+	if (! ((-e $cfile)&&(-s $cfile))) { # The other expected cfile did not exist.
+#	    $cfile = '';
+	    $error++;
+	    die "Missing cfile $cfile!";
+	}
+    }
+    return($cfile);
+}
+    
