Index: trunk/ippScripts/scripts/addstar_run.pl
===================================================================
--- trunk/ippScripts/scripts/addstar_run.pl	(revision 33988)
+++ trunk/ippScripts/scripts/addstar_run.pl	(revision 33989)
@@ -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: trunk/ippTasks/addstar.pro
===================================================================
--- trunk/ippTasks/addstar.pro	(revision 33988)
+++ trunk/ippTasks/addstar.pro	(revision 33989)
@@ -321,5 +321,5 @@
     end
     if ("$STAGE" == "staticsky")
-      $run = $run --multi_num $STAGE_EXTRA1
+      $run = $run --stage_extra1 $STAGE_EXTRA1  --stage_id $STAGE_ID
     end
     if ("$STAGE" == "cam") 
Index: trunk/ippTools/share/addtool_find_sky_id_multi.sql
===================================================================
--- trunk/ippTools/share/addtool_find_sky_id_multi.sql	(revision 33988)
+++ trunk/ippTools/share/addtool_find_sky_id_multi.sql	(revision 33989)
@@ -2,5 +2,5 @@
      distinct(sky_id) as stage_id,
      staticskyRun.*,
-    staticskyResult.num_inputs
+    staticskyResult.num_inputs, stack_id
 FROM 
      staticskyRun
Index: trunk/ippTools/share/addtool_find_sky_id_multi_dvo.sql
===================================================================
--- trunk/ippTools/share/addtool_find_sky_id_multi_dvo.sql	(revision 33988)
+++ trunk/ippTools/share/addtool_find_sky_id_multi_dvo.sql	(revision 33989)
@@ -1,3 +1,3 @@
-SELECT distinct(sky_id) as stage_id, staticskyRun.*, staticskyResult.num_inputs FROM staticskyResult
+SELECT distinct(sky_id) as stage_id, staticskyRun.*, staticskyResult.num_inputs, stack_id FROM staticskyResult
 JOIN staticskyRun USING(sky_id)
 join staticskyInput using(sky_id)
Index: trunk/ippTools/src/addtool.c
===================================================================
--- trunk/ippTools/src/addtool.c	(revision 33988)
+++ trunk/ippTools/src/addtool.c	(revision 33989)
@@ -292,5 +292,5 @@
       // }
     if (strcmp(stage,"staticsky") == 0) {
-      psStringAppend(&query, " GROUP BY sky_id");  //some reason it needs this
+      psStringAppend(&query, " GROUP BY sky_id, stack_id");  //some reason it needs this
       }
 
@@ -525,7 +525,9 @@
 	psS64 stage_id =0; 
 	bool status = false;
-	psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs");
+	//psS32 num_inputs = psMetadataLookupS32(&status, md, "num_inputs");
+	psS32 stack_id = psMetadataLookupS32(&status, md, "stack_id");
+
 	if (!status) {
-	  psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item num_inputs");
+	  psError(PS_ERR_UNKNOWN, true, "failed to lookup value for item stack_id");
 	  return false;
 	}
@@ -540,9 +542,9 @@
 
         // queue the exp
-	for (int filter_id = 0; filter_id < num_inputs; filter_id++) {  
-        if (!pxaddQueueByCamID(config,
+      	//for (int filter_id = 0; filter_id < num_inputs; filter_id++) {  
+	  if (!pxaddQueueByCamID(config,
 			       stage,
-                               stage_id,
-			       filter_id,
+			       stage_id,
+			       stack_id,
                                workdir     ? workdir   : row->workdir,
                                reduction   ? reduction : row->reduction,
@@ -555,7 +557,7 @@
                                minidvodb_group,
                                minidvodb_name
-        )) {
+				 )) {
             if (!psDBRollback(config->dbh)) {
-                psError(PS_ERR_UNKNOWN, false, "database error sfg");
+	      psError(PS_ERR_UNKNOWN, false, "database error sfg");
             }
             psError(PS_ERR_UNKNOWN, false,
@@ -564,6 +566,6 @@
             psFree(output);
             return false;
-        }
-	}
+	  }
+	  //}
         psFree(row);
     }
