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_exp.pl

    r11298 r11316  
    88
    99use IPC::Cmd qw( can_run run );
    10 use PS::IPP::Metadata::Config;
     10use PS::IPP::Metadata::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    );
    1119use PS::IPP::Metadata::List qw( parse_md_list );
    1220use Statistics::Descriptive;
     
    4957my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    5058my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    51 die "Can't find required tools.\n" if $missing_tools;
     59if ($missing_tools) {
     60    warn("Can't find required tools.");
     61    exit($PS_EXIT_CONFIG_ERROR);
     62}
    5263
    5364my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    6071    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6172        run(command => $command, verbose => 1);
    62     die "Unable to perform dettool -normalizedimfile: $error_code\n" if not $success;
    63     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    64         or die "unable to parse metadata config doc";
    65     $files = parse_md_list($metadata);
     73    unless ($success) {
     74        $error_code >> 8;
     75        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $error_code);
     76    }
     77    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     78        &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     79    $files = parse_md_list($metadata) or
     80        &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
    6681}
    6782
     
    7287    my @variances;    # Array of variances for each component
    7388    foreach my $file (@$files) {
    74         die "Unable to find class id\n" unless defined $file->{class_id};
     89        &my_die("Unable to find class id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id};
    7590        my $class_id = $file->{class_id};
    76         die "Unable to find bg for class_id=$class_id\n" unless defined $file->{bg};
    77         die "Unable to find bg_mean_stdev for class_id=$class_id\n" unless defined $file->{bg_mean_stdev};
     91        &my_die("Unable to find bg for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
     92        &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
    7893        push @backgrounds, $file->{bg};
    7994        push @variances, $file->{bg_stdev}**2;
     
    127142    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128143        run(command => $command, verbose => 1);
    129     die "Unable to find expected output file: $jpeg1Name\n" if not -f $jpeg1Name;
     144    &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg1Name;
    130145}
    131146
     
    135150    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136151        run(command => $command, verbose => 1);
    137     die "Unable to find expected output file: $jpeg2Name\n" if not -f $jpeg2Name;
     152    &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg2Name;
    138153}
    139154
     
    148163    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    149164        run(command => $command, verbose => 1);
    150     die "Unable to perform dettool -addnormalizedexp: $error_code\n" if not $success;
     165    unless ($success) {
     166        $error_code >> 8;
     167        &my_die("Unable to perform dettool -addnormalizedexp: $error_code", $det_id, $iter, $error_code);
     168    }
    151169
    152170    unlink $list1Name;
    153171    unlink $list2Name;
     172}
     173
     174
     175sub my_die
     176{
     177    my $msg = shift; # Warning message on die
     178    my $det_id = shift;         # Detrend identifier
     179    my $iter = shift;           # Iteration
     180    my $exit_code = shift; # Exit code to add
     181
     182    warn($msg);
     183    if ($det_id and $iter) {
     184        my $command = "$dettool -addprocessedimfile -det_id $det_id -iter $iter -code $exit_code";
     185        $command .= " -dbname $dbname" if defined $dbname;
     186        system ($command);
     187    }
     188    exit $exit_code;
    154189}
    155190
Note: See TracChangeset for help on using the changeset viewer.