Index: trunk/ippScripts/scripts/warp_skycell.pl
===================================================================
--- trunk/ippScripts/scripts/warp_skycell.pl	(revision 27019)
+++ trunk/ippScripts/scripts/warp_skycell.pl	(revision 27039)
@@ -77,7 +77,8 @@
 # Recipes to use based on reduction class
 $reduction = 'DEFAULT' unless defined $reduction;
-my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use for ppImage
-unless ($recipe_pswarp) {
-    &my_die("Couldn't find selected reduction for WARP_PSWARP: $reduction\n", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR);
+my $recipe_pswarp = $ipprc->reduction($reduction, 'WARP_PSWARP'); # Recipe to use
+my $recipe_psastro = $ipprc->reduction($reduction, 'PSASTRO'); # Recipe to use
+unless ($recipe_pswarp and $recipe_psastro) {
+    &my_die("Couldn't find selected reduction: $reduction\n", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR);
 }
 
@@ -121,4 +122,21 @@
     $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
 }
+
+my $dynamicMasks;               # Use dynamic masks?
+{
+    # Get the PSASTRO recipe
+    my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe ADDSTAR -";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $verbose);
+    unless ($success) {
+        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+        &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $PS_EXIT_CONFIG_ERROR);
+    }
+    my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+        &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_CONFIG_ERROR);
+
+    $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK');
+}
+
 
 my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
@@ -153,5 +171,11 @@
     my $image = $imfile->{uri}; # Image name
     my $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name
-    my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id}); # Mask name
+
+    my $mask;                   # Mask name
+    if ($dynamicMasks) {
+        $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
+    } else {
+        $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id});
+    }
 
     &my_die("Couldn't find input file: $image", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($image);
