Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/addstar_run.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/addstar_run.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/addstar_run.pl	(revision 34047)
@@ -38,6 +38,6 @@
 }
 my $minidvodb_path;
-my $stage_extra1 ;
-my ( $add_id, $camera, $stage, $stage_id, $multi_num, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,
+
+my ( $add_id, $camera, $stage, $stage_id, $stage_extra1, $outroot, $stageroot, $dbname, $reduction, $dvodb, $minidvodb, $minidvodb_name, $minidvodb_group, $image_only, $verbose, $no_update,
      $no_op, $redirect, $save_temps);
 GetOptions(
@@ -46,5 +46,5 @@
     'stage|s=s'        => \$stage, # Camera
     'stage_id|w=s'   => \$stage_id,
-    'multi_num|w=s'    => \$multi_num, # the number for a staticskymulti (for finding cmf)
+    'stage_extra1|w=s'    => \$stage_extra1, # the number for a staticskymulti (for finding cmf), or stack_id
     'dbname|d=s'        => \$dbname, # Database name
     'outroot|w=s'       => \$outroot, # output file base name
@@ -162,17 +162,47 @@
     }
 }
-if (($stage =~/staticsky/) || ($stage =~/stack/)) {
+if (($stage =~/stack/)) {
     $fpaObjects =~ s/smf$/cmf/;
     $fpaObjectsAlt =~ s/smf$/cmf/;
-}
+
+}
+my $fpaObjects1;
+my $fpaObjects2;
 my $checkalt = 0;
 if ($stage =~/staticsky/) {
-    $fpaObjects =~ s/smf$/cmf/; #this should do nothing because it was already modded above
-    &my_die( "can't find the filter_num for staticsky_multi, giving up.", $add_id, $PS_EXIT_SYS_ERROR) unless (defined $multi_num);
-    my $nice_num = sprintf ("%03d", $multi_num);
-    $fpaObjects =~ s/cmf$/$nice_num.cmf/;  #this make it look for .001.cmf, etc
-    if ($multi_num == 0) {
-	$checkalt =1 ; #if it's staticsky and multi_num = 0 there's an alternate file to try if this one doesn't work
-    }
+    $checkalt = 1;
+    my $sources   = $ipprc->filename("PSPHOT.OUT.CMF.MEF", $stageroot); #this is mostly rigtht except the .cmf needs either
+    # .000.cmf or .stk.xxxxx.cmf
+    print "$sources\n\n\n";
+    &my_die( "can't find the filter_num for staticsky_multi, giving up.", $add_id, $PS_EXIT_SYS_ERROR) unless (defined $stage_extra1);
+
+    
+    $fpaObjects1 = $sources;
+    $fpaObjects2 = $sources;
+    $fpaObjects = $sources;
+
+    my $nice_num = sprintf ("%03d", $stage_extra1);
+
+    $fpaObjects1 =~ s/cmf$/stk.$stage_extra1.cmf/;
+    $fpaObjects2 =~ s/cmf$/$nice_num.cmf/;  #this make it look for .001.cmf, etc
+ # we have 3 of them to try
+    my $realFile = $ipprc->file_resolve($fpaObjects);
+    my $realFile1 = $ipprc->file_resolve($fpaObjects1);
+    my $realFile2 = $ipprc->file_resolve($fpaObjects2);
+    if (!defined($realFile1)) {
+	if (!defined($realFile2)) {
+	    print "using $fpaObjects\n";
+	    
+	} else {
+	    print "using $fpaObjects2\n";
+	    $fpaObjects = $fpaObjects2;
+	}
+	
+    } else {
+	print "using $fpaObjects1\n";
+	$fpaObjects = $fpaObjects1;
+    }
+     
+
 }
 
@@ -230,17 +260,8 @@
 	    my $camdir = $ipprc->dvo_cameradir(); # Camera directory for addstar
 	   
-	    my $realFile = $ipprc->file_resolve($fpaObjects);
-	    if (!defined($realFile)) {
-		print "can't find $fpaObjects\n";
-		if ($checkalt)  {
-		    $realFile = $ipprc->file_resolve($fpaObjectsAlt) or &my_die("Unable to resolve $fpaObjectsAlt", $add_id, $PS_EXIT_SYS_ERROR);
-		    $fpaObjects = $fpaObjectsAlt; # want to make sure the correct value is used.
-		} else {
-		    # try the 'good one' again and fail i
-		    #$realFile = $ipprc->file_resolve($fpaObjects) or 
-		    &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR);
-		}
-		
-	    }
+	    my $realFile = $ipprc->file_resolve($fpaObjects) or  &my_die("Unable to resolve $fpaObjects", $add_id, $PS_EXIT_SYS_ERROR);
+	    
+	    
+	   
 
 	    # require a defined output dvo database to run addstar (ie, refuse to use the .ptolemyrc default)
Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/automate_stacks.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/automate_stacks.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/automate_stacks.pl	(revision 34047)
@@ -1588,8 +1588,13 @@
 
 sub init_gpc_db {
+    ## change to use the site.config setting now, however may want to use replicated scidbs instead
+    my $ipprc =  PS::IPP::Config->new(); # IPP Configuration
+    my $siteConfig = $ipprc->{_siteConfig};
     use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
-    my $dbserver = 'ippdb01';
+    # my $dbserver = 'ippdb01';
     my $dbuser = 'ippuser';
     my $dbpass = 'ippuser';
+    my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER');
+    die "database configuration set up" unless defined($dbserver);
     $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
                        "mysql_socket=" . DB_SOCKET(),
Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/bundle_detrends.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/bundle_detrends.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/bundle_detrends.pl	(revision 34047)
@@ -128,8 +128,12 @@
 
 sub init_gpc_db {
+    ## change to use the site.config setting now, however may want to use replicated scidbs instead
+    my $siteConfig = $ipprc->{_siteConfig};
     use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
-    my $dbserver = 'ippdb01';
+    # my $dbserver = 'ippdb01';
     my $dbuser = 'ippuser';
     my $dbpass = 'ippuser';
+    my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER');
+    die "database configuration set up" unless defined($dbserver);
     $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
                        "mysql_socket=" . DB_SOCKET(),
Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/make_burntool_pcontrol.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/make_burntool_pcontrol.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/make_burntool_pcontrol.pl	(revision 34047)
@@ -29,8 +29,13 @@
 
 # Load database
+## change to use the site.config setting now
 $dbname = 'gpc1';
-$dbserver = 'ippdb01';
+#$dbserver = 'ippdb01';
 $dbuser = 'ipp';
 $dbpass = 'ipp';
+my $ipprc =  PS::IPP::Config->new(); # IPP Configuration
+my $siteConfig = $ipprc->{_siteConfig};
+my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER');
+die "database configuration not set up" unless defined($dbserver);
 $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
                    "mysql_socket=" . DB_SOCKET(),
Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/nightly_science.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/nightly_science.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/nightly_science.pl	(revision 34047)
@@ -32,4 +32,8 @@
     exit($PS_EXIT_CONFIG_ERROR);
 }
+
+## for DB connection, want to use siteConfig DB settings
+my $ipprc =  PS::IPP::Config->new(); # IPP Configuration
+my $siteConfig = $ipprc->{_siteConfig};
 
 my $db;
@@ -2052,8 +2056,15 @@
 
 sub init_gpc_db {
+    ## change to use the siteConfig setting, while readonly probably do not want to use a readonly replicated DB incase it gets behind
+    my $dbserver = metadataLookupStr($siteConfig, 'DBSERVER');
+    my $dbuser = metadataLookupStr($ipprc->{_siteConfig}, "RO_DBUSER");
+    my $dbpass = metadataLookupStr($ipprc->{_siteConfig}, "RO_DBPASSWORD");
+    die "database configuration not set up" unless defined($dbserver);
+    die "database configuration not set up" unless defined($dbuser);
+    die "database configuration not set up" unless defined($dbpass);
+    #my $dbserver = 'ippdb01';
+    #my $dbuser = 'ippuser';
+    #my $dbpass = 'ippuser';
     use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
-    my $dbserver = 'ippdb01';
-    my $dbuser = 'ippuser';
-    my $dbpass = 'ippuser';
     $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
                        "mysql_socket=" . DB_SOCKET(),
Index: branches/eam_branches/ipp-20120601/ippScripts/scripts/staticsky.pl
===================================================================
--- branches/eam_branches/ipp-20120601/ippScripts/scripts/staticsky.pl	(revision 34043)
+++ branches/eam_branches/ipp-20120601/ippScripts/scripts/staticsky.pl	(revision 34047)
@@ -81,5 +81,5 @@
     -msg => "Required options: --sky_id --outroot --camera",
     -exitval => 3,
-          ) unless 
+          ) unless
     defined $sky_id and
     defined $outroot and
@@ -120,5 +120,5 @@
 
 
-# generate the input 
+# generate the input
 print $listFile "INPUT   MULTI\n";
 my $nInputs = @$files;
@@ -194,5 +194,5 @@
         # Perform stack photometry analysis
         {
-            my $command = "$psphotStack $outroot.stk";
+            my $command = "$psphotStack $outroot";
             $command .= " -input $listName";
             $command .= " -threads $threads" if defined $threads;
@@ -235,8 +235,9 @@
                     # we have one set of output files per input file set
                     for (my $i = 0; $i < @$files; $i++) {
-                        my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $i);
-                        my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $i);
-                        my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $i);
-                        my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $i);
+                        my $stack_id = @$files[$i]->{stack_id};
+                        my $outputName     = $ipprc->filename("PSPHOT.STACK.OUTPUT.IMAGE", $outroot, $stack_id);
+                        my $outputMask     = $ipprc->filename("PSPHOT.STACK.OUTPUT.MASK", $outroot, $stack_id);
+                        my $outputVariance = $ipprc->filename("PSPHOT.STACK.OUTPUT.VARIANCE", $outroot, $stack_id);
+                        my $outputSources  = $ipprc->filename("PSPHOT.STACK.OUTPUT", $outroot, $stack_id);
 
                         # XXX these are optional and not generated by default
@@ -256,6 +257,6 @@
 
                     # XXX check the recipe -- should we expect these to exist?
-                    # &my_die("Couldn't find expected output file: $chisqName", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
-                    # &my_die("Couldn't find expected output file: $chisqMask", 	  $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
+                    # &my_die("Couldn't find expected output file: $chisqName",           $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqName);
+                    # &my_die("Couldn't find expected output file: $chisqMask",           $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqMask);
                     # &my_die("Couldn't find expected output file: $chisqVariance", $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($chisqVariance);
                 }
@@ -346,5 +347,5 @@
                 }
 
-                &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR) 
+                &my_die("Couldn't find expected output file: $configuration", $sky_id, $PS_EXIT_SYS_ERROR)
                     unless $ipprc->file_exists($configuration);
             } else {
@@ -359,9 +360,9 @@
     {
         my $command = "$staticskytool -sky_id $sky_id";
-	$command .= " -addresult -path_base $outroot";
-	$command .= " -num_inputs $nInputs";
-	# $command .= " $cmdflags";
-	$command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-	$command .= " -hostname $host" if defined $host;
+        $command .= " -addresult -path_base $outroot";
+        $command .= " -num_inputs $nInputs";
+        # $command .= " $cmdflags";
+        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
+        $command .= " -hostname $host" if defined $host;
         $command .= " -dbname $dbname" if defined $dbname;
 
@@ -371,6 +372,6 @@
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
             my $err_message = "Unable to perform staticskytool -addresult";
-	    warn($err_message);
-	    exit $error_code;
+            warn($err_message);
+            exit $error_code;
         }
     }
@@ -389,9 +390,9 @@
     if (defined $sky_id and not $no_update) {
         my $command = "$staticskytool -sky_id $sky_id -fault $exit_code";
-	$command .= " -addresult";
-	$command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
-	$command .= " -hostname $host" if defined $host;
-	$command .= " -path_base $outroot" if defined $outroot;
-	$command .= " -dbname $dbname" if defined $dbname;
+        $command .= " -addresult";
+        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
+        $command .= " -hostname $host" if defined $host;
+        $command .= " -path_base $outroot" if defined $outroot;
+        $command .= " -dbname $dbname" if defined $dbname;
         run(command => $command, verbose => $verbose);
     }
