IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 6, 2006, 4:32:51 PM (20 years ago)
Author:
jhoblitt
Message:

change from positional to named CLI options

File:
1 edited

Legend:

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

    r8715 r8763  
    44use strict;
    55
     6use vars qw( $VERSION );
     7$VERSION = '0.01';
     8
    69use IPC::Cmd qw( can_run run );
    710use PS::IPP::Metadata::Config;
    811use PS::IPP::Metadata::Stats;
    9 use Data::Dumper;
    1012
     13use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     14use Pod::Usage qw( pod2usage );
     15
     16my ($det_id, $exp_id, $class, $class_id, $det_type, $input_uri, $output_uri);
     17GetOptions(
     18    'det_id|d=s'        => \$det_id,
     19    'exp_id|e=s'        => \$exp_id,
     20    'class=s'           => \$class,     # unused
     21    'class_id|i=s'      => \$class_id,
     22    'det_type|t=s'      => \$det_type,
     23    'input_uri|u=s'     => \$input_uri,
     24    'output_uri|o=s'    => \$output_uri,
     25) or pod2usage( 2 );
     26
     27pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     28pod2usage(
     29    -msg => "Required options: --det_id --exp_id --class_id --det_type --input_uri --output_uri",
     30    -exitval => 3,
     31) unless defined $det_id
     32    and defined $exp_id
     33    and defined $class_id
     34    and defined $det_type
     35    and defined $input_uri
     36    and defined $output_uri;
    1137
    1238# Recipes to use, as a function of the detrend type
     
    2652use constant DELETE_STATS => 0; # Delete the statistics file when done?
    2753
    28 # Parse the command-line arguments
    29 if (scalar @ARGV != 6) {
    30     die "Perform detrend processing at the imfile level.\n\n" .
    31         "Usage: $0 DET_ID EXP_ID CLASS_ID DETREND_TYPE INPUT.fits OUTPUT_ROOT\n\n";
    32 }
    33 my $detId = shift @ARGV;        # Detrend ID
    34 my $expId = shift @ARGV;        # Exposure ID
    35 my $classId = shift @ARGV;      # Class ID
    36 my $detType = shift @ARGV;      # Detrend type
    37 my $input = shift @ARGV;        # Input FITS file
    38 my $output = shift @ARGV;       # Output root name
    39 
    4054# Look for programs we need
    4155my $missing_tools;
     
    4559
    4660# Recipe to use in processing
    47 my $recipe = RECIPES->{$detType};
    48 die "Unrecognised detrend type: $detType\n" if not defined $recipe;
    49 die "Unrecognised detrend type: $detType\n" if not defined PREFIX->{$detType};
     61my $recipe = RECIPES->{$det_type};
     62die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
     63die "Unrecognised detrend type: $det_type\n" if not defined PREFIX->{$det_type};
    5064
    5165### Output file name --- must match camera configuration!
    52 my $outputRoot =  PREFIX->{$detType} . '_' . $output;
    53 my $outputName = $outputRoot . '.' . $classId ;
     66my $outputRoot =  PREFIX->{$det_type} . '_' . $output_uri;
     67my $outputName = $outputRoot . '.' . $class_id ;
    5468my $outputImage = $outputName . '.fit';
    5569my $outputStats = $outputName . '.stats';
     
    5771# Run ppImage
    5872{
    59     my $command = "$ppImage -file $input $outputRoot -recipe PPIMAGE $recipe" .
     73    my $command = "$ppImage -file $input_uri $outputRoot -recipe PPIMAGE $recipe" .
    6074        " -stat $outputStats"; # Command to run ppImage
    6175    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6276        run(command => $command, verbose => 1);
    63     die "Unable to perform ppImage on $input: $error_code\n" if not $success;
     77    die "Unable to perform ppImage on $input_uri: $error_code\n" if not $success;
    6478    die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
    6579}
     
    8195# Add the processed file to the database
    8296{
    83     my $command = "$dettool -addprocessed -det_id $detId -exp_id $expId " .
    84         "-class_id $classId -recip $recipe -uri $outputImage"; # Command to run dettool
     97    my $command = "$dettool -addprocessed -det_id $det_id -exp_id $exp_id " .
     98        "-class_id $class_id -recip $recipe -uri $outputImage"; # Command to run dettool
    8599    $command .= " -bg " . $stats->bg_mean();
    86100    $command .= " -bg_stdev " . $stats->bg_stdev();
     
    89103    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    90104        run(command => $command, verbose => 1);
    91     die "Unable to perform dettool -addprocessed for $detId/$expId/$classId: $error_code\n"
     105    die "Unable to perform dettool -addprocessed for $det_id/$exp_id/$class_id: $error_code\n"
    92106        if not $success;
    93107}
Note: See TracChangeset for help on using the changeset viewer.