IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 25, 2007, 7:10:31 PM (19 years ago)
Author:
Paul Price
Message:

Adding error handling; not yet tested --- there may be compilation errors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/detrend_norm_apply.pl

    r11298 r11316  
    88use Data::Dumper;
    99
    10 use PS::IPP::Config;
     10use PS::IPP::Config qw(
     11    $PS_EXIT_SUCCESS
     12    $PS_EXIT_UNKNOWN_ERROR
     13    $PS_EXIT_SYS_ERROR
     14    $PS_EXIT_CONFIG_ERROR
     15    $PS_EXIT_PROG_ERROR
     16    $PS_EXIT_DATA_ERROR
     17    $PS_EXIT_TIMEOUT_ERROR
     18    );
    1119my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1220use File::Spec;
     
    6068my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    6169my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    62 die "Can't find required tools.\n" if $missing_tools;
     70
     71if ($missing_tools) {
     72    warn("Can't find required tools.");
     73    exit($PS_EXIT_CONFIG_ERROR);
     74}
    6375
    6476unless (defined $workdir) {
     
    8597    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8698        run(command => $command, verbose => 1);
    87     die "Unable to perform ppImage: $error_code\n" if not $success;
    88     die "Can't find expected output file: $output\n" if not -e $output;
    89     die "Can't find expected output file: $b1name\n" if not -e $b1name;
    90     die "Can't find expected output file: $b2name\n" if not -e $b2name;
    91     die "Can't find expected output file: $statsName\n" if not -e $statsName;
     99    unless ($success) {
     100        $error_code >> 8;
     101        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $class_id, $error_code);
     102    }
     103    &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $output;
     104    &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b2name;
     105    &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b1name;
     106    &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $statsName;
    92107}
    93108
     
    96111{
    97112    my $statsFile;              # File handle
    98     open $statsFile, $statsName or die "Can't open statistics file $statsName: $!\n";
     113    open $statsFile, $statsName or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    99114    my @contents = <$statsFile>; # Contents of file
    100115    close $statsFile;
    101116    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    102117    my $metadata = $mdcParser->parse(join "", @contents)
    103         or die "unable to parse metadata config";
     118        or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    104119    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    105     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     120    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    106121}
    107122
     
    127142    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128143        run(command => $command, verbose => 1);
    129     die "Unable to perform dettool -addnormalizedimfile: $error_code\n"
    130         if not $success;
     144    unless ($success) {
     145        $error_code >> 8;
     146        warn("Unable to perform dettool -addnormalizedimfile: $error_code\n");
     147        exit($error_code);
     148    }
    131149
    132150    unlink $statsName;
    133151}
     152
     153sub my_die
     154{
     155    my $msg = shift;            # Warning message on die
     156    my $det_id = shift;         # Detrend identifier
     157    my $iter = shift;           # Iteration
     158    my $class_id = shift;       # Class identifier
     159    my $exit_code = shift;      # Exit code to add
     160
     161    warn($msg);
     162    if ($det_id and $iter and $class_id) {
     163        my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code";
     164        $command .= " -dbname $dbname" if defined $dbname;
     165        system ($command);
     166    }
     167    exit $exit_code;
     168}
     169
    134170
    135171END {
     
    139175    $? = $status;
    140176}
     177
     178__END__
Note: See TracChangeset for help on using the changeset viewer.