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/phase3.pl

    r11298 r11316  
    1212use Statistics::Descriptive;
    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;
     
    4553my $p3tool = can_run('p3tool') or (warn "Can't find p3tool" and $missing_tools = 1);
    4654my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    47 die "Can't find required tools.\n" if $missing_tools;
     55if ($missing_tools) {
     56    warn("Can't find required tools.");
     57    exit($PS_EXIT_CONFIG_ERROR);
     58}
    4859
    4960my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    5667    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    5768        run(command => $command, verbose => 1);
    58     die "Unable to perform p3tool -pendingimfile: $error_code\n" if not $success;
    59     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    60         or die "unable to parse metadata config doc";
    61     $files = parse_md_list($metadata);
     69    unless ($success) {
     70        $error_code >> 8;
     71        &my_die("Unable to perform p3tool: $error_code", $exp_tag, $error_code);
     72    }
     73    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     74        &my_die("Unable to parse metadata config doc", $exp_tag, $PS_EXIT_PROG_ERROR);
     75    $files = parse_md_list($metadata) or
     76        &my_die("Unable to parse metadata list", $exp_tag, $PS_EXIT_PROG_ERROR);
    6277}
    6378
     
    7489#    my @zp;                    # Array of photometric zero points
    7590    foreach my $file (@$files) {
    76         die "Unable to find class id\n" unless defined $file->{class_id};
     91        &my_die("Unable to find class id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id};
    7792        my $class_id = $file->{class_id};
    78         die "Unable to find bg for class_id=$class_id\n" unless defined $file->{bg};
    79         die "Unable to find bg_mean_stdev for class_id=$class_id\n" unless defined $file->{bg_mean_stdev};
    80 #       die "Unable to find sigma_ra for class_id=$class_id\n" unless defined $file->{sigma_ra};
    81 #       die "Unable to find sigma_dec for class_id=$class_id\n" unless defined $file->{sigma_dec};
    82 #       die "Unable to find zp for class_id=$class_id\n" unless defined $file->{zp};
     93        &my_die("Unable to find bg for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
     94        &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
     95#       &my_die("Unable to find sigma_ra for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_ra};
     96#       &my_die("Unable to find sigma_dec for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_dec};
     97#       &my_die("Unable to find zp for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{zp};
    8398        push @backgrounds, $file->{bg};
    8499        push @variances, $file->{bg_stdev}**2;
     
    132147    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    133148        run(command => $command, verbose => 1);
    134     die "Unable to find expected output file: $jpeg1\n" if not -f $jpeg1;
     149    unless ($success) {
     150        $error_code >> 8;
     151        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $error_code);
     152    }
     153    &my_die("Unable to find expected output file: $jpeg1", $exp_tag, $PS_EXIT_PROG_ERROR) unless -f $jpeg1;
    135154}
    136155
     
    140159    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    141160        run(command => $command, verbose => 1);
    142     die "Unable to find expected output file: $jpeg2\n" if not -f $jpeg2;
     161    unless ($success) {
     162        $error_code >> 8;
     163        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $error_code);
     164    }
     165    &my_die("Unable to find expected output file: $jpeg2", $exp_tag, $PS_EXIT_PROG_ERROR) unless -f $jpeg2;
    143166}
    144167
     
    156179    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    157180        run(command => $command, verbose => 1);
    158     die "Unable to perform p3tool -addprocessedexp: $error_code\n" if not $success;
     181    unless ($success) {
     182        $error_code >> 8;
     183        warn("Unable to perform dettool -addprocessedexp: $error_code\n");
     184        exit($error_code);
     185    }
    159186
    160187    unlink $list1Name;
    161188    unlink $list2Name;
    162189}
     190
     191
     192sub my_die
     193{
     194    my $msg = shift; # Warning message on die
     195    my $exp_tag = shift; # Exposure tag
     196    my $exit_code = shift; # Exit code to add
     197
     198    warn($msg);
     199    if ($exp_tag) {
     200        my $command = "$dettool -addprocessedexp -exp_tag $exp_tag -code $exit_code";
     201        $command .= " -dbname $dbname" if defined $dbname;
     202        system ($command);
     203    }
     204    exit $exit_code;
     205}
     206
    163207
    164208END {
Note: See TracChangeset for help on using the changeset viewer.