Index: /trunk/ippScripts/scripts/staticsky.pl
===================================================================
--- /trunk/ippScripts/scripts/staticsky.pl	(revision 33912)
+++ /trunk/ippScripts/scripts/staticsky.pl	(revision 33913)
@@ -144,4 +144,5 @@
             my $path_base = $file->{path_base};
             print "input: $path_base\n";
+            my $stack_id = $file->{stack_id};
 
             my $imageCnv  = $ipprc->filename("PPSTACK.OUTPUT",          $path_base ); # Image name
@@ -172,4 +173,5 @@
             &my_die("Couldn't find input: $sources",   $sky_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists("$sources");
 
+            print $listFile "  STACK_ID      S64  " . $stack_id  . "\n";
             print $listFile "  RAW:IMAGE     STR  " . $imageRaw  . "\n";
             print $listFile "  RAW:MASK      STR  " . $maskRaw   . "\n";
Index: /trunk/psModules/src/camera/pmFPAfile.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAfile.c	(revision 33912)
+++ /trunk/psModules/src/camera/pmFPAfile.c	(revision 33913)
@@ -382,5 +382,5 @@
         // Number of the file in list
         psString num = NULL;            // Number to use
-        psStringAppend(&num, "%03d", file->fileID);
+        psStringAppend(&num, "%" PRId64, file->fileID);
         psStringSubstitute(&newRule, num, "{FILE.ID}");
         psFree(num);
Index: /trunk/psModules/src/camera/pmFPAfile.h
===================================================================
--- /trunk/psModules/src/camera/pmFPAfile.h	(revision 33912)
+++ /trunk/psModules/src/camera/pmFPAfile.h	(revision 33913)
@@ -114,5 +114,5 @@
 
     int fileIndex;			// Index of file
-    int fileID;				// internal sequence number
+    psS64 fileID;		        // internal sequence number
 
     psS64 imageId, sourceId;            // Image and source identifiers
Index: /trunk/psphot/src/psphotStackParseCamera.c
===================================================================
--- /trunk/psphot/src/psphotStackParseCamera.c	(revision 33912)
+++ /trunk/psphot/src/psphotStackParseCamera.c	(revision 33913)
@@ -129,4 +129,9 @@
 	}
 
+        psS64 stack_id = psMetadataLookupS64(&status, input, "STACK_ID");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false, "Unable to find STACK_ID from sources %d", i);
+            return false;
+        }
 	// generate an pmFPAimage for the output convolved image
 	// XXX output of these files should be optional
@@ -139,5 +144,5 @@
 	    }
 	    outputImage->save = true;
-	    outputImage->fileID = i;		// this is used to generate output names
+	    outputImage->fileID = stack_id;		// this is used to generate output names
 
 	    pmFPAfile *outputMask = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.MASK");
@@ -151,5 +156,5 @@
 	    }
 	    outputMask->save = true;
-	    outputMask->fileID = i;		// this is used to generate output names
+	    outputMask->fileID = stack_id;		// this is used to generate output names
 
 	    pmFPAfile *outputVariance = pmFPAfileDefineOutput(config, outputImage->fpa, "PSPHOT.STACK.OUTPUT.VARIANCE");
@@ -163,5 +168,5 @@
 	    }
 	    outputVariance->save = true;
-	    outputVariance->fileID = i;		// this is used to generate output names
+	    outputVariance->fileID = stack_id;		// this is used to generate output names
 
 	    // the output sources are carried on the outputImage->fpa structures
@@ -172,5 +177,5 @@
 	    }
 	    outsources->save = true;
-	    outsources->fileID = i;		// this is used to generate output names
+	    outsources->fileID = stack_id;		// this is used to generate output names
 	}
     }
