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

    r11298 r11316  
    99use PS::IPP::Metadata::List qw( parse_md_list );
    1010use Data::Dumper;
     11
     12use PS::IPP::Config qw(
     13    $PS_EXIT_SUCCESS
     14    $PS_EXIT_UNKNOWN_ERROR
     15    $PS_EXIT_SYS_ERROR
     16    $PS_EXIT_CONFIG_ERROR
     17    $PS_EXIT_PROG_ERROR
     18    $PS_EXIT_DATA_ERROR
     19    $PS_EXIT_TIMEOUT_ERROR
     20    );
    1121
    1222use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    5464my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    5565my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
    56 die "Can't find required tools.\n" if $missing_tools;
    57 
    58 die "Unrecognised detrend type: $detType\n" unless exists NORMALIZE()->{lc($detType)};
    59 
     66if ($missing_tools) {
     67    warn("Can't find required tools.");
     68    exit($PS_EXIT_CONFIG_ERROR);
     69}
     70
     71unless (exists NORMALIZE()->{lc($detType)}) {
     72    warn("Unrecognised detrend type: $detType");
     73    exit($PS_EXIT_CONFIG_ERROR);
     74}
    6075
    6176my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    6984    my ( $stdin, $stdout, $stderr ); # Buffers for running program
    7085    print "Running [$command]...\n";
    71     run \@command, \$stdin, \$stdout, \$stderr or
    72         die "Unable to perform dettool -processedimfile on detrend $detId/$iter: $?";
     86    if (not run(\@command, \$stdin, \$stdout, \$stderr)) {
     87        warn("Unable to perform dettool -processedimfile on detrend $detId/$iter: $?");
     88        exit($PS_EXIT_SYS_ERROR);
     89    }
    7390#    print $stdout . "\n";
    7491   
     
    8299            push @single, "\n";
    83100
    84             my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) ) or
    85                 die "Unable to parse output from dettool.\n";
     101            my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     102            unless (defined $list) {
     103                warn("Unable to parse output from dettool.");
     104                exit($PS_EXIT_PROG_ERROR);
     105            }
    86106            push @files, @$list;
    87107            @single = ();
     
    119139        my @command = split /\s+/, $ppNormCalc;
    120140        print "Running [$ppNormCalc]...\n";
    121         run \@command, \$normData, \$stdout, \$stderr or
    122             die "Unable to perform ppNormCalc: $?";
     141        if (not run(\@command, \$normData, \$stdout, \$stderr)) {
     142            warn("Unable to perform ppNormCalc: $?");
     143            exit($PS_EXIT_SYS_ERROR);
     144        }
    123145        print $stdout . "\n";
    124146       
    125147        # Parse the output
    126         $norms = $mdcParser->parse($stdout)
    127             or die "unable to parse metadata config doc";
     148        $norms = $mdcParser->parse($stdout);
     149        unless ($norms) {
     150            warn("Unable to parse metadata config doc");
     151            exit($PS_EXIT_PROG_ERROR);
     152        }
    128153    }
    129154
     
    158183        my ( $stdin, $stdout, $stderr ); # Buffers for running program
    159184        print "Running [$command]...\n";
    160         run \@command, \$stdin, \$stdout, \$stderr or
    161             die "Unable to perform dettool -addnormstat for $className: $?";
     185        if (not run \@command, \$stdin, \$stdout, \$stderr) {
     186            warn("Unable to perform dettool -addnormstat for $className: $?");
     187            exit($PS_EXIT_SYS_ERROR);
     188        }
    162189        print $stdout . "\n";
    163190    }
     
    170197    $? = $status;
    171198}
     199
     200__END__
Note: See TracChangeset for help on using the changeset viewer.