Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 25442)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 25471)
@@ -145,114 +145,114 @@
     my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
     if ($useDeburnedImage) {
-	## Check that we have required programs:
-#	print STDERR "Inside burntool loop!\n";
-	my $regtool  = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	
-	## Check the current burntool processing version:
-	my $regtool_state_cmd = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -limit 1";
-	if (defined($dbname)) {
-	    $regtool_state_cmd .= " -dbname $dbname";
-	}
-	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $regtool_state_cmd, verbose => $verbose);
-
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform regtool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	my $regData = $mdcParser->parse(join "", @$stdout_buf) or
-	    &my_die("Unable to parse regtool metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	my $regData2 = parse_md_list($regData);
-
-	my $burntoolState = 999;
-	foreach my $regEntry (@$regData2) {
-#	    print "$regEntry->{exp_id} $regEntry->{burntool_state}\n";
-
-	    if ($regEntry->{exp_id} == $exp_id) {
-		$burntoolState = $regEntry->{burntool_state};
-	    }
-	}
-	if ($burntoolState == 999) {
-	    &my_die("Unable to find burntool_state in metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	## Read camera config to get the current good burntool state :
-	## XXX This is extremely slow. Any better way to do this?
-	my $camera_config_cmd = "$ppConfigDump -camera $camera -dump-camera -";
-	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	    run(command => $camera_config_cmd, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	my $camData = $mdcParser->parse(join "", @$stdout_buf) or
-	    &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-
-	my $burntoolStateGood;
-	foreach my $camEntry (@$camData) {
-	    if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") {
-		$burntoolStateGood = $camEntry->{value};
-	    }
-	}
-
-	if (abs($burntoolState) != $burntoolStateGood) {
-	    &my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	## We now know that we have an image that has been burntooled.  
-	my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX", 
-					      UNLINK => !$save_temps, SUFFIX => '.fits' );
-	
-	# get the UNIX version of the (possible) neb: or path: filename
-	my $uriReal = $ipprc->file_resolve( $uri );
-
-	# funpack into the temp file.
-	my $funpack_cmd = "$funpack -S $uriReal > $tempName";
-	( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-	
-	## Construct commands to apply the pre-calculated burntool trailfits to the pixel data.
-	my ($burntoolTable_uri, $burntoolTable_uriReal);
-	my $burntool_cmd = "$burntool ";
-
-	if ($burntoolState == -1 * $burntoolStateGood) {   # Burntool information stored in an external table.
-	    $burntoolTable_uri = $uri;
-	    $burntoolTable_uri =~ s/fits$/burn.tbl/;
-	    $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
-	    unless ($ipprc->file_exists($burntoolTable_uri)) {
-		&my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
-	    }
-
-	    $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} apply=t";
-	}
-	elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
-	    $burntool_cmd .= "$tempName apply=t";
-	}
-	else {
-	    &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	## Run burntool to change the pixels of tempfile, and repoint $uri to that file.
-	($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
-	    run(command => $burntool_cmd, verbose => $verbose);
-	unless ($success) {
-	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	    &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}
-
-	$uri = $tempName;
-	unless ($ipprc->file_exists($uri)) {
-	    &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	}	
-
-#	print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
-#	exit(100);	
+        ## Check that we have required programs:
+#       print STDERR "Inside burntool loop!\n";
+        my $regtool  = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+
+        ## Check the current burntool processing version:
+        my $regtool_state_cmd = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -limit 1";
+        if (defined($dbname)) {
+            $regtool_state_cmd .= " -dbname $dbname";
+        }
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $regtool_state_cmd, verbose => $verbose);
+
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform regtool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        my $regData = $mdcParser->parse(join "", @$stdout_buf) or
+            &my_die("Unable to parse regtool metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        my $regData2 = parse_md_list($regData);
+
+        my $burntoolState = 999;
+        foreach my $regEntry (@$regData2) {
+#           print "$regEntry->{exp_id} $regEntry->{burntool_state}\n";
+
+            if ($regEntry->{exp_id} == $exp_id) {
+                $burntoolState = $regEntry->{burntool_state};
+            }
+        }
+        if ($burntoolState == 999) {
+            &my_die("Unable to find burntool_state in metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        ## Read camera config to get the current good burntool state :
+        ## XXX This is extremely slow. Any better way to do this?
+        my $camera_config_cmd = "$ppConfigDump -camera $camera -dump-camera -";
+        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $camera_config_cmd, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        my $camData = $mdcParser->parse(join "", @$stdout_buf) or
+            &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+
+        my $burntoolStateGood;
+        foreach my $camEntry (@$camData) {
+            if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") {
+                $burntoolStateGood = $camEntry->{value};
+            }
+        }
+
+        if (abs($burntoolState) != $burntoolStateGood) {
+            &my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        ## We now know that we have an image that has been burntooled.
+        my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
+                                              UNLINK => !$save_temps, SUFFIX => '.fits' );
+
+        # get the UNIX version of the (possible) neb: or path: filename
+        my $uriReal = $ipprc->file_resolve( $uri );
+
+        # funpack into the temp file.
+        my $funpack_cmd = "$funpack -S $uriReal > $tempName";
+        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        ## Construct commands to apply the pre-calculated burntool trailfits to the pixel data.
+        my ($burntoolTable_uri, $burntoolTable_uriReal);
+        my $burntool_cmd = "$burntool ";
+
+        if ($burntoolState == -1 * $burntoolStateGood) {   # Burntool information stored in an external table.
+            $burntoolTable_uri = $uri;
+            $burntoolTable_uri =~ s/fits$/burn.tbl/;
+            $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
+            unless ($ipprc->file_exists($burntoolTable_uri)) {
+                &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
+            }
+
+            $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} apply=t";
+        }
+        elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
+            $burntool_cmd .= "$tempName apply=t";
+        }
+        else {
+            &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        ## Run burntool to change the pixels of tempfile, and repoint $uri to that file.
+        ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
+            run(command => $burntool_cmd, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+        $uri = $tempName;
+        unless ($ipprc->file_exists($uri)) {
+            &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+        }
+
+#       print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
+#       exit(100);
     }
 
@@ -261,48 +261,48 @@
     if ($tiltystreakApply) {
 
-	my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS');
-	my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id");
-	if ($tiltystreakClassApply) {
-
-	    my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id");
-	    if ($tiltystreakClassOptions eq "none") {
-		$tiltystreakClassOptions = "";
-	    }
-
-	    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
-
-	    # XXX make these optional (must be built by psbuild as well...)
-	    my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	    my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-
-	    # create an temporary output file:
-	    my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );
-
-	    print "uri: $uri\n";
-
-	    # get the UNIX version of the (possible) neb: or path: filename
-	    my $uriReal = $ipprc->file_resolve( $uri );
-
-	    print "uriReal: $uriReal\n";
-
-	    # unpack the data (is a NOP if not compressed)
-	    $command = "$funpack -S $uriReal > $tempName";
-	    ( $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 funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	    }
-
-	    # run tiltystreak
-	    $command = "$tiltystreak $tempName $tiltystreakClassOptions";
-	    ( $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 tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	    }
-
-	    # supply the output file as the new input file
-	    $uri = $tempName;
-	}
+        my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS');
+        my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id");
+        if ($tiltystreakClassApply) {
+
+            my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id");
+            if ($tiltystreakClassOptions eq "none") {
+                $tiltystreakClassOptions = "";
+            }
+
+            my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);
+
+            # XXX make these optional (must be built by psbuild as well...)
+            my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+            my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+
+            # create an temporary output file:
+            my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );
+
+            print "uri: $uri\n";
+
+            # get the UNIX version of the (possible) neb: or path: filename
+            my $uriReal = $ipprc->file_resolve( $uri );
+
+            print "uriReal: $uriReal\n";
+
+            # unpack the data (is a NOP if not compressed)
+            $command = "$funpack -S $uriReal > $tempName";
+            ( $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 funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+            }
+
+            # run tiltystreak
+            $command = "$tiltystreak $tempName $tiltystreakClassOptions";
+            ( $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 tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+            }
+
+            # supply the output file as the new input file
+            $uri = $tempName;
+        }
     }
 
@@ -362,21 +362,5 @@
         }
         chomp $cmdflags;
-        if (($camera ne "GPC1") or ($class_id ne "XY27") or ($exp_id < 53171)) {
-            ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
-        } else {
-            # hack to kick ota 27 out of subsequent analysis by setting quality flag to a non-zero value
-            my ($before, $after) = split " -quality ", $cmdflags;
-
-            # get the current value
-            ($quality) = $after =~ /^(\d+)/;
-            $after = substr($after, length($quality));
-
-            # replace it if it is zero
-            $quality = 42 if !$quality;
-
-            # rebuild the cmdflags
-            $cmdflags = $before . " -quality $quality";
-            $cmdflags .= " $after" if $after;
-        }
+        ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
     }
 
