IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 21934


Ignore:
Timestamp:
Feb 20, 2009, 11:02:01 AM (17 years ago)
Author:
Paul Price
Message:

Using pipes within a single IPC::Cmd run() wasn't working: an error from the first (e.g., unable to read file) wasn't being propagated to an unsuccessful result of the command as a whole. Moving over to use IPC::Run instead, which allows us to control the piping better, and gives us error codes for both independently.

File:
1 edited

Legend:

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

    r20118 r21934  
    1717use Storable qw(freeze thaw);
    1818use File::Basename qw( basename);
    19 use IPC::Cmd 0.36 qw( can_run run );
     19use IPC::Run qw( harness run );
    2020use PS::IPP::Config 1.01 qw( :standard );
    2121use PS::IPP::Metadata::Config;
    22 
    23 my $PI = 3.141592653589793238462643383279502;
     22use Math::Trig;
    2423
    2524my $ipprc = PS::IPP::Config->new(); # IPP configuration
     
    5857# Look for programs we need
    5958my $missing_tools;
    60 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    61 my $ppStats = can_run('ppStats') or (warn "Can't find ppStats" and $missing_tools = 1);
    62 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     59my $regtool = `which regtool` or (warn "Can't find regtool" and $missing_tools = 1);
     60my $ppStats = `which ppStats` or (warn "Can't find ppStats" and $missing_tools = 1);
     61my $ppStatsFromMetadata = `which ppStatsFromMetadata` or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     62chomp $regtool;
     63chomp $ppStats;
     64chomp $ppStatsFromMetadata;
     65
    6366
    6467if ($missing_tools) {
     
    8083# Run ppStats on the input file
    8184{
    82     my $command = "$ppStats $uri -recipe PPSTATS $RECIPE -level | $ppStatsFromMetadata - - REGISTER_IMFILE"; # Command to run ppStats and ppStatsFromMetadata
    83     $command .= " -dbname $dbname" if defined $dbname;
    84     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    85         cache_run(command => $command, verbose => $verbose);
    86     unless ($success) {
    87         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    88         &my_die ("Unable to perform ppStats on exposure id $exp_id: $error_code", $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $error_code);
    89     }
    90     foreach my $line (@$stdout_buf) {
    91         $cmdflags .= " $line";
    92     }
    93     chomp $cmdflags;
     85    my $command1 = "$ppStats $uri -recipe PPSTATS $RECIPE -level";
     86    my $command2 = "$ppStatsFromMetadata - - REGISTER_IMFILE";
     87
     88    # Since there are no spaces in the arguments, we can get away with this:
     89    my @command1 = split(/ /, $command1);
     90    my @command2 = split(/ /, $command2);
     91
     92    # Run ppStats
     93    my ($in1, $out1, $err1);    # Buffers for ppStats
     94    my $h1 = harness \@command1, \$in1, \$out1, \$err1;
     95    print "[Running $command1]\n";
     96    my $result1 = run $h1;
     97    print $out1;
     98    print $err1;
     99    &my_die("Unable to perform ppStats on exposure id $exp_id: " . $h1->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h1->result() ) unless $result1;
     100
     101    print "[Running " . join(' ', @command2) . "]\n";
     102    my ($out2, $err2);          # Buffers for ppStatsFromMetadata
     103    my $h2 = harness \@command2, \$out1, \$out2, \$err2;
     104    print "[Running $command2]\n";
     105    my $result2 = run $h2;
     106    print $out2;
     107    print $err2;
     108    &my_die("Unable to perform ppStatsFromMetadata on exposure id $exp_id: " . $h2->result(), $exp_id, $tmp_exp_name, $tmp_class_id, $uri, $h2->result() ) unless $result2;
     109    chomp $out2;
     110    $cmdflags = $out2;
    94111}
    95112
     
    123140# if the needed data is available, pass it to sunmoon:
    124141if ($longitude && $latitude && $ra && $dec && $dateobs) {
    125    
    126     $longitude *= 12.0 / $PI; # longitude is reported in West radians; sunmoon wants it in West Hours
    127     $latitude *= 180.0 / $PI; # latitude is reported in North radians; sunmoon wants it in North Degrees
    128     $ra *= 180.0 / $PI; # ra is reported in radians; sunmoon wants it in degrees
    129     $dec *= 180.0 / $PI; # dec is reported in radians; sunmoon wants it in degrees
     142
     143    $longitude *= 12.0 / pi; # longitude is reported in West radians; sunmoon wants it in West Hours
     144    $latitude *= 180.0 / pi; # latitude is reported in North radians; sunmoon wants it in North Degrees
     145    $ra *= 180.0 / pi; # ra is reported in radians; sunmoon wants it in degrees
     146    $dec *= 180.0 / pi; # dec is reported in radians; sunmoon wants it in degrees
    130147
    131148    my $sunmoon_cmd = "sunmoon -latitude $latitude -longitude $longitude -elevation $elevation $dateobs $ra $dec";
     
    137154
    138155    if ($?) {
    139         warn ("failure running $sunmoon_cmd, not supplying\n");
     156        warn ("failure running $sunmoon_cmd, not supplying\n");
    140157    } else {
    141         $command .= " $sunmoon_data";
     158        $command .= " $sunmoon_data";
    142159    }
    143160}
Note: See TracChangeset for help on using the changeset viewer.