Index: /tags/ipp-20121218/ippScripts/scripts/chip_imfile.pl
===================================================================
--- /tags/ipp-20121218/ippScripts/scripts/chip_imfile.pl	(revision 35083)
+++ /tags/ipp-20121218/ippScripts/scripts/chip_imfile.pl	(revision 35084)
@@ -338,5 +338,5 @@
 	    my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
 	    unless ($repair_success) {
-		&my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+		&my_die("Missing file: Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
 	    }
 	    $uriReal = $ipprc->file_resolve( $uri );
@@ -345,64 +345,69 @@
         &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
 
-        # 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) {
-	    # Catch errors here
-	    my $repair_cmd = "$nebrepair $uri";
-	    my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
-	    unless ($repair_success) {
-		&my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
-	    }
+        my $funpack_is_compressed = "$funpack -L $uriReal";
+        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_is_compressed, verbose => $verbose);
+	if ($stdout_buf =~ /compressed/) {
+	    # funpack into the temp file if the file is compressed
+	    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 );
-	    if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
-		my $repair_cmd = "$nebrepair $burntoolTable_uri";
+	    unless ($success) {
+		# Catch errors here
+		my $repair_cmd = "$nebrepair $uri";
 		my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
 		unless ($repair_success) {
-		    &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+		    &my_die("funpack -S failed: Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
 		}
+		( $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 );
+		if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) {
+		    my $repair_cmd = "$nebrepair $burntoolTable_uri";
+		    my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose);
+		    unless ($repair_success) {
+			&my_die("Repair failed: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR);
+		    }
+		    $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
+		}
+		unless ($ipprc->file_exists($burntoolTable_uri)) {
+		    # Catch errors here
+		    &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} persist=t apply=t";
 	    }
-            unless ($ipprc->file_exists($burntoolTable_uri)) {
-		# Catch errors here
-                &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} persist=t apply=t";
-        }
-        elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
-            $burntool_cmd .= "$tempName persist=t 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);
-        }
-
+	    elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
+		$burntool_cmd .= "$tempName persist=t 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);
+	    }
+	} else {
+	    warn ("Non compressed image. Skipping neb-repair");
+	}
 #       print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
 #       exit(100);
