IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 6, 2006, 2:11:25 PM (20 years ago)
Author:
Paul Price
Message:

Using Getopt::Long for arguments. Adding path support.

File:
1 edited

Legend:

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

    r9097 r9364  
    88use PS::IPP::Metadata::Stats;
    99use Data::Dumper;
     10use PS::IPP::Config;
     11my $ipprc = PS::IPP::Config->new(); # IPP configuration
     12use File::Spec;
    1013
    11 use constant RECIPE => 'PPIMAGE_OBDF.config'; # Recipe to use
    12 use constant PREFIX => 'obdf';  # Prefix to attach to filenames
    13 use constant DELETE_STATS => 0; # Delete the statistics file when done?
     14use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     15use Pod::Usage qw( pod2usage );
     16
     17use constant RECIPE => 'PPIMAGE_OBDSF.config'; # Recipe to use
    1418
    1519# Parse the command-line arguments
    16 if (scalar @ARGV != 4) {
    17     die "Perform phase 2 processing.\n\n" .
    18         "Usage: $0 EXP_ID CLASS_ID INPUT.fits OUTPUT_ROOT\n\n";
    19 }
    20 my $expTag = shift @ARGV;       # Exposure ID
    21 my $classId = shift @ARGV;      # Class ID
    22 my $input = shift @ARGV;        # Input FITS file
    23 my $output = shift @ARGV;       # Output root name
     20my ($expTag,                    # Exposure tag
     21    $classId,                   # Class Id
     22    $input,                     # Input FITS file
     23    $no_update                  # Don't update the database?
     24    );
     25GetOptions(
     26    'exp_tag|e=s'   => \$expTag,
     27    'class_id|i=s'  => \$classId,
     28    'uri|u=s'       => \$input,
     29    'no-update'     => \$no_update
     30) or pod2usage( 2 );
     31
     32pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
     33pod2usage(
     34    -msg => "Required options: --exp_tag --class_id --uri",
     35    -exitval => 3,
     36) unless defined $expTag
     37    and defined $classId
     38    and defined $input;
    2439
    2540# Look for programs we need
     
    3045
    3146### Output file name --- must match camera configuration!
    32 my $outputRoot =  PREFIX . '_' . $output;
    33 my $outputName = $outputRoot . '.' . $classId ;
    34 my $outputImage = $outputName . '.fit';
    35 my $outputStats = $outputName . '.stats';
    36 my $outputBin1Name = $outputName . 'b1.fit';
    37 my $outputBin2Name = $outputName . 'b2.fit';
     47my ($vol, $dir, $file) = File::Spec->splitpath( $input );
     48my $outputRoot =  $expTag . '.p2.';
     49$outputRoot = File::Spec->rel2abs( File::Spec->catpath( $vol, $dir, $outputRoot ), $ipprc->workdir() );
     50my $outputImage = $outputRoot  . '.' . $classId . '.fits';
     51my $outputStats = $outputRoot  . '.' . $classId . '.stats';
     52my $outputBin1Name = $outputRoot . '.' . $classId . 'b1.fits';
     53my $outputBin2Name = $outputRoot . '.' . $classId . 'b2.fits';
    3854
    3955# Run ppImage
     
    4561    die "Unable to perform ppImage on $input: $error_code\n" if not $success;
    4662    die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
     63    die "Couldn't find expected output file: $outputBin1Name\n" if not -f $outputBin1Name;
     64    die "Couldn't find expected output file: $outputBin2Name\n" if not -f $outputBin2Name;
     65    die "Couldn't find expected output file: $outputStats\n" if not -f $outputStats;
    4766}
    4867
     
    5170{
    5271    my $statsFile;              # File handle
    53     open $statsFile, "$outputStats" or die "Can't open statistics file $outputStats: $!\n";
     72    open $statsFile, $outputStats or die "Can't open statistics file $outputStats: $!\n";
    5473    my @contents = <$statsFile>; # Contents of file
    5574    close $statsFile;
     
    6281
    6382# Add the processed file to the database
    64 {
     83$outputImage = File::Spec->abs2rel( $outputImage, $ipprc->workdir() );
     84$outputBin1Name = File::Spec->abs2rel( $outputBin1Name, $ipprc->workdir() );
     85$outputBin2Name = File::Spec->abs2rel( $outputBin2Name, $ipprc->workdir() );
     86unless ($no_update) {
    6587    # Command to run dettool
    6688    my $command = "$p2tool -processed";
     
    79101    die "Unable to perform p2tool -processed for $expTag/$classId: $error_code\n"
    80102        if not $success;
     103
     104    unlink $outputStats;
    81105}
    82106
    83 unlink "$outputStats" if DELETE_STATS;
    84 
    85107__END__
Note: See TracChangeset for help on using the changeset viewer.