Changeset 11316 for trunk/ippScripts/scripts/detrend_stack.pl
- Timestamp:
- Jan 25, 2007, 7:10:31 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/detrend_stack.pl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/detrend_stack.pl
r11298 r11316 12 12 use PS::IPP::Metadata::Stats; 13 13 14 use PS::IPP::Config; 14 use PS::IPP::Config qw( 15 $PS_EXIT_SUCCESS 16 $PS_EXIT_UNKNOWN_ERROR 17 $PS_EXIT_SYS_ERROR 18 $PS_EXIT_CONFIG_ERROR 19 $PS_EXIT_PROG_ERROR 20 $PS_EXIT_DATA_ERROR 21 $PS_EXIT_TIMEOUT_ERROR 22 ); 15 23 my $ipprc = PS::IPP::Config->new(); # IPP configuration 16 24 use File::Spec; … … 52 60 }; 53 61 54 my $recipe = RECIPES()->{lc($det_type)}; # Recipe to use in stacking55 die "Unrecognised detrend type: $det_type\n" if not defined $recipe;56 57 62 # Look for programs we need 58 63 my $missing_tools; 59 64 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1); 60 65 my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" and $missing_tools = 1); 61 die "Can't find required tools.\n" if $missing_tools; 66 if ($missing_tools) { 67 warn("Can't find required tools."); 68 exit($PS_EXIT_CONFIG_ERROR); 69 } 70 71 my $recipe = RECIPES()->{lc($det_type)}; # Recipe to use in stacking 72 &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR) unless defined $recipe; 62 73 63 74 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files … … 70 81 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 71 82 run(command => $command, verbose => 1); 72 die "Unable to perform dettool -processedimfile: $error_code\n" if not $success; 73 my $metadata = $mdcParser->parse(join "", @$stdout_buf) 74 or die "unable to parse metadata config doc"; 75 $files = parse_md_list($metadata); 83 unless ($success) { 84 $error_code >> 8; 85 &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code); 86 } 87 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 88 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 89 $files = parse_md_list($metadata) or 90 &my_die("Unable to parse metadata list", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR); 76 91 } 77 92 … … 101 116 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 102 117 run(command => $command, verbose => 1); 103 die "Unable to perform ppMerge: $error_code\n" if not $success; 104 die "Unable to find expected output file: $outputStack\n" if not -f $outputStack; 105 die "Unable to find expected output file: $outputStats\n" if not -f $outputStats; 118 unless ($success) { 119 $error_code >> 8; 120 &my_die("Unable to perform ppMerge: $error_code", $det_id, $iter, $class_id, $error_code); 121 } 122 &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStack; 123 &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats; 106 124 } 107 125 … … 109 127 my $stats; # Statistics from ppImage 110 128 { 111 open(my $statsFile, "$outputStats") 112 or die "Can't open statistics file $outputStats: $!\n";129 open(my $statsFile, "$outputStats") or 130 &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 113 131 my $contents = do { local $/; <$statsFile> }; # Contents of file 114 132 close($statsFile); 115 133 116 134 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 117 my $metadata = $mdcParser->parse($contents) 118 or die "unable to parse metadata config doc";135 my $metadata = $mdcParser->parse($contents) or 136 &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 119 137 $stats = PS::IPP::Metadata::Stats->new(); # Stats parser 120 $stats->parse($metadata) or die "Unable to find all values in statistics output.\n"; 138 $stats->parse($metadata) or 139 &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR); 121 140 } 122 141 … … 137 156 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 138 157 run(command => $command, verbose => 1); 139 die "Unable to perform dettool -addstacked: $error_code\n" if not $success; 158 unless ($success) { 159 $error_code >> 8; 160 warn("Unable to perform dettool -addstacked: $error_code\n"); 161 exit($error_code); 162 } 140 163 141 164 unlink $outputStats; 165 } 166 167 168 sub my_die 169 { 170 my $msg = shift; # Warning message on die 171 my $det_id = shift; # Detrend identifier 172 my $iter = shift; # Iteration 173 my $class_id = shift; # Class identifier 174 my $exit_code = shift; # Exit code to add 175 176 warn($msg); 177 if ($det_id and $iter and $class_id) { 178 my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code"; 179 $command .= " -dbname $dbname" if defined $dbname; 180 system ($command); 181 } 182 exit $exit_code; 142 183 } 143 184
Note:
See TracChangeset
for help on using the changeset viewer.
