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

    r11298 r11316  
    1212use PS::IPP::Metadata::Stats;
    1313
    14 use PS::IPP::Config;
     14use 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    );
    1523my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1624use File::Spec;
     
    5260    };
    5361
    54 my $recipe = RECIPES()->{lc($det_type)}; # Recipe to use in stacking
    55 die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
    56 
    5762# Look for programs we need
    5863my $missing_tools;
    5964my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    6065my $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;
     66if ($missing_tools) {
     67    warn("Can't find required tools.");
     68    exit($PS_EXIT_CONFIG_ERROR);
     69}
     70
     71my $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;
    6273
    6374my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    7081    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    7182        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);
    7691}
    7792
     
    101116    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    102117        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;
    106124}
    107125
     
    109127my $stats;                      # Statistics from ppImage
    110128{
    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);
    113131    my $contents = do { local $/; <$statsFile> }; # Contents of file
    114132    close($statsFile);
    115133
    116134    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);
    119137    $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);
    121140}
    122141
     
    137156    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    138157        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    }
    140163
    141164    unlink $outputStats;
     165}
     166
     167
     168sub 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;
    142183}
    143184
Note: See TracChangeset for help on using the changeset viewer.