IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8998


Ignore:
Timestamp:
Sep 26, 2006, 3:37:34 PM (20 years ago)
Author:
Paul Price
Message:

Reforming to use IPC::Run instead of IPC::Cmd, since we can feed input
into ppNormCalc's stdin. This saves us writing another file. Needs
testing!

File:
1 edited

Legend:

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

    r8887 r8998  
    44use strict;
    55
    6 use IPC::Cmd qw( can_run run );
     6use IPC::Cmd qw( can_run );
     7use IPC::Run qw ( run );
    78use PS::IPP::Metadata::Config;
    89use PS::IPP::Metadata::List qw( parse_md_list );
     
    1314
    1415
    15 use constant STATISTIC => 'bg'; # Background statistic to use from the database
    16 
    1716# Parse command-line arguments
    18 my ($detId,   # Detrend id
    19     $iter      # Iteration
     17my ($detId,                     # Detrend id
     18    $iter,                      # Iteration
     19    $camera,                    # Camera name
     20    $detType                    # Detrend type
    2021    );
    2122GetOptions(
    2223        'det_id|d=s'    => \$detId,
    2324        'iteration|i=s' => \$iter,
     25        'camera|c=s'    => \$camera,
     26        'det_type|t=s'  => \$detType
    2427        ) or pod2usage( 2 );
    2528
    2629pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    27 pod2usage( -msg => "Required options --det_id --iteration",
     30pod2usage( -msg => "Required options --det_id --iteration --camera --det_type",
    2831           -exitval => 3,
    29          ) unless defined $detId
    30               and defined $iter;
     32           ) unless defined $detId
     33    and defined $iter
     34    and defined $camera
     35    and defined $detType;
    3136
    3237
     
    4550{
    4651    my $command = "$dettool -processed -unmask -det_id $detId -iteration $iter"; # Command to run
    47     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    48         run(command => $command, verbose => 1);
    49     die "Unable to perform dettool -processed -unmask on detrend $detId/$iter: $error_code\n"
    50         if not $success;
     52    my @command = split /\s+/, $command;
     53    my ( $stdin, $stdout, $stderr ); # Buffers for running program
     54    run \@command, \$stdin, \$stdout, \$stderr or
     55        die "Unable to perform dettool -processed -unmask on detrend $detId/$iter: $?";
    5156   
    5257    # Parse the output
    53     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
     58    my $metadata = $mdcParser->parse(join "", @$stdout)
    5459        or die "unable to parse metadata config doc";
    5560    $files = parse_md_list($metadata);
     
    6772}
    6873
    69 my $normName = 'normCalc_' . $detId . '_' . $iter . '.mdc'; # Name for ppNormCalc input file
    70 my $normFile;                   # File handle for ppNormCalc input
    71 open $normFile, ">" . $normName;
     74# Generate the input for ppNormCalc
     75my $normData;                   # Normalisation data
    7276foreach my $expId (keys %matrix) {
    73     print $normFile "$expId\tMETADATA\n";
     77    $normData .= "$expId\tMETADATA\n";
    7478    foreach my $classId (keys %{$matrix{$expId}}) {
    75         print $normFile "\t" . $classId . "\tF32\t" . $matrix{$expId}->{$classId} . "\n";
     79        $normData .= "\t" . $classId . "\tF32\t" . $matrix{$expId}->{$classId} . "\n";
    7680    }
    77     print $normFile "END\n\n";
     81    $normData .= "END\n\n";
    7882}
    79 close $normFile;
    8083
    8184# Run ppNormCalc
    8285my $norms;
    8386{
    84     my $command = "$ppNormCalc $normName"; # Command to run
    85     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    86         run(command => $command, verbose => 1);
    87     die "Unable to perform ppNormCalc: $error_code\n"
    88         if not $success;
    89     $norms = $mdcParser->parse(join "", @$stdout_buf)
     87    my ( $stdout, $stderr ); # Buffers for running program
     88    my @command = split /\s+/, $ppNormCalc;
     89    run \@command, \$normData, \$stdout, \$stderr or
     90        die "Unable to perform ppNormCalc: $?";
     91
     92    # Parse the output
     93    $norms = $mdcParser->parse(join "", @$stdout)
    9094        or die "unable to parse metadata config doc";
    9195}
     
    99103        my $command = "$dettool -addnormstat -det_id $detId -iteration $iter -class_id $className ".
    100104            "-norm $normalisation"; # Command to run
    101         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    102             run(command => $command, verbose => 1);
    103         die "Unable to perform dettool -addnormstat: $error_code\n"
    104             if not $success;
     105        my @command = split /\s+/, $command;
     106
     107        my ( $stdin, $stdout, $stderr ); # Buffers for running program
     108        run \@command, \$stdin, \$stdout, \$stderr or
     109            die "Unable to perform dettool -addnormstat for $className: $?";
    105110    }
    106111}
Note: See TracChangeset for help on using the changeset viewer.