IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2010, 9:31:50 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/eam_branches/ipp-20100621/pstamp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/pstamp

    • Property svn:ignore
      •  

        old new  
        1616ltmain.sh
        1717libtool
         18ppstamp.pc
  • branches/eam_branches/ipp-20100621/pstamp/scripts/detect_query_read

    r27788 r28794  
    2626my $no_print_header = 0;    # omit the header keywords
    2727my $no_print_rows   = 0;    # omit the rows
    28 
     28my $version = 0;
    2929
    3030my ( $input,                    # Name of input text file
     
    5252my $status = 0;
    5353
    54 # The required keywords
    55 my $header = {
    56         'QUERY_ID' => { name => 'QUERY_ID',
    57                         writetype => TSTRING,
    58                         comment => 'MOPS Query ID for this batch query',
    59                         value => undef
    60                       },
    61         'FPA_ID'   => { name => 'FPA_ID',
    62                         writetype => TSTRING,
    63                         comment => 'orginal FPA_ID used at ingest',
    64                         value => undef
    65                       },
    66         'MJD_OBS'  => { name => 'MJD-OBS',
    67                         writetype => TDOUBLE,
    68                         comment => 'starting time of the exposure, MJD',
    69                         value => undef
    70                       },
    71         'FILTER'   => { name => 'FILTER',
    72                         writetype => TSTRING,
    73                         comment => 'effective filter use for the exposure',
    74                         value => undef
    75                       },
    76         'OBSCODE'  => { name => 'OBSCODE',
    77                         writetype => TSTRING,
    78                         comment => 'site identifier (MPC observatory code)',
    79                         value => undef
    80                       },
    81         'STAGE'    => {
    82                         name => 'STAGE',
    83                         writetype => TSTRING,
    84                         comment => 'processing stage to examine',
    85                         value => undef
    86                       }
    87 };
    88 
    89 # key_array insures that the order that the keywords is printed out is
    90 # the same as the ICD
    91 my @key_array = qw( QUERY_ID FPA_ID MJD_OBS FILTER OBSCODE STAGE);
     54# Read the input file
     55
     56my $inFits = Astro::FITS::CFITSIO::open_file( $input, READONLY, $status ); # FITS file handle
     57check_fitsio($status);
     58
     59$inFits->movnam_hdu(BINARY_TBL, EXTNAME, 0, $status) and check_fitsio($status);
     60
     61my $inHeader = $inFits->read_header(); # Header for input
     62
     63my $numRows;                    # Number of rows in table
     64$inFits->get_num_rows($numRows, $status) and check_fitsio($status);
     65
     66# The keywords found in the header
     67# my $header = {
     68#         'EXTVER'   => { name => 'EXTVER',
     69#                      writetype => TSTRING,
     70#                      comment => 'Extension version',
     71#                      value => undef
     72#                       },
     73#         'EXTNAME'  => { name => 'EXTNAME',
     74#                      writetype => TSTRING,
     75#                      comment => 'name of this binary table extension',
     76#                      value => undef
     77#                     },
     78#         'QUERY_ID' => { name => 'QUERY_ID',
     79#                         writetype => TSTRING,
     80#                         comment => 'MOPS Query ID for this batch query',
     81#                         value => undef
     82#                       },
     83#         'FPA_ID'   => { name => 'FPA_ID',
     84#                         writetype => TSTRING,
     85#                         comment => 'orginal FPA_ID used at ingest',
     86#                         value => undef
     87#                       },
     88#         'MJD_OBS'  => { name => 'MJD-OBS',
     89#                         writetype => TDOUBLE,
     90#                         comment => 'starting time of the exposure, MJD',
     91#                         value => undef
     92#                       },
     93#         'FILTER'   => { name => 'FILTER',
     94#                         writetype => TSTRING,
     95#                         comment => 'effective filter use for the exposure',
     96#                         value => undef
     97#                       },
     98#         'OBSCODE'  => { name => 'OBSCODE',
     99#                         writetype => TSTRING,
     100#                         comment => 'site identifier (MPC observatory code)',
     101#                         value => undef
     102#                       },
     103#       'STAGE'    => {
     104#                       name => 'STAGE',
     105#                       writetype => TSTRING,
     106#                       comment => 'processing stage to examine',
     107#                       value => undef
     108#                     }
     109# };
     110
     111my $parse_error = 0;
     112# Parse the header to determine what we expect to find.
     113foreach my $header_key (keys %{ $inHeader }) {
     114    $inHeader->{$header_key} =~ s/\s+//g;
     115    $inHeader->{$header_key} =~ s/\'//g;
     116}
     117my ($EXTVER,$headerEXTNAME,$QUERY_ID,$FPA_ID,$MJD_OBS,$FILTER,$OBSCODE,$STAGE) =
     118    ($inHeader->{EXTVER},$inHeader->{EXTNAME},$inHeader->{QUERY_ID},$inHeader->{FPA_ID},
     119     $inHeader->{'MJD-OBS'},$inHeader->{FILTER},$inHeader->{OBSCODE},$inHeader->{STAGE});
     120unless(defined($EXTVER) && defined($headerEXTNAME) &&
     121       (($EXTVER == 1)||($EXTVER == 2)) &&
     122       ($headerEXTNAME eq EXTNAME)) {
     123    $parse_error = 1;
     124}
     125unless(($EXTVER == 2)||
     126       ((defined($QUERY_ID))&&(defined($FPA_ID))&&(defined($MJD_OBS))&&
     127        (defined($FILTER))&&(defined($OBSCODE)))) {
     128    $parse_error = 2;
     129}
    92130
    93131# Specification of columns
    94132my $column_defs = [
    95133        # matching rownum from detectability original request
    96         { name => 'ROWNUM',   type => '20A', writetype => TSTRING },
     134        { name => 'ROWNUM',   type => '20A', writetype => TSTRING, version => 1 },
    97135        # coordinate at start of exposure, in degrees
    98         { name => 'RA1_DEG',  type => 'D',   writetype => TDOUBLE },
     136        { name => 'RA1_DEG',  type => 'D',   writetype => TDOUBLE, version => 1 },
    99137        # coordinate at start of exposure, in degrees
    100         { name => 'DEC1_DEG', type => 'D',   writetype => TDOUBLE },
     138        { name => 'DEC1_DEG', type => 'D',   writetype => TDOUBLE, version => 1 },
    101139        # coordinate at end of exposure, in degrees
    102         { name => 'RA2_DEG',  type => 'D',   writetype => TDOUBLE },
     140        { name => 'RA2_DEG',  type => 'D',   writetype => TDOUBLE, version => 1 },
    103141        # coordinate at end of exposure, in degrees
    104         { name => 'DEC2_DEG', type => 'D',   writetype => TDOUBLE },
     142        { name => 'DEC2_DEG', type => 'D',   writetype => TDOUBLE, version => 1 },
    105143        # apparent magnitude
    106         { name => 'MAG',      type => 'D',   writetype => TDOUBLE },
     144        { name => 'MAG',      type => 'D',   writetype => TDOUBLE, version => 1 },
     145    # v2 query_id: MOPS query ID for this batch query
     146    { name => 'QUERY_ID', type => '20A', writetype => TSTRING, version => 2, default => $QUERY_ID },
     147    # v2 fpa_id: original FPA_ID used at ingest
     148    { name => 'FPA_ID', type => '20A', writetype => TSTRING, version => 2, default => $FPA_ID },
     149    # v2 mjd obs: starting time of the exposure, MJD
     150    { name => 'MJD-OBS', type => 'D', writetype => TDOUBLE, version => 2, default => $MJD_OBS },
     151    # v2 filter: effective filter used for the exposure as a string, allowed values of g, r, i, z, y, B, V, w
     152    { name => 'FILTER', type => '3A', writetype => TSTRING, version => 2, default => $FILTER },
     153    # v2 obscode: site identifier (MPC observatory code)
     154    { name => 'OBSCODE', type => '3A', writetype => TSTRING, version => 2, default => $OBSCODE },
     155    # v2 stage: stage name to perform query on, allowed values of 'chip', 'warp', 'stack', and 'diff'
     156    { name => 'STAGE', type => '20A', writetype => TSTRING, version => 2, default => $STAGE },
    107157];
    108158
     
    118168}
    119169
    120 # Read the input file
    121 
    122 my $inFits = Astro::FITS::CFITSIO::open_file( $input, READONLY, $status ); # FITS file handle
    123 check_fitsio($status);
    124 
    125 $inFits->movnam_hdu(BINARY_TBL, EXTNAME, 0, $status) and check_fitsio($status);
    126 
    127 my $inHeader = $inFits->read_header(); # Header for input
    128 
    129 my $numRows;                    # Number of rows in table
    130 $inFits->get_num_rows($numRows, $status) and check_fitsio($status);
    131 
    132170foreach my $col (@$column_defs) {
    133171    my ($col_num, $col_type, $col_data);
    134172
     173    if ($col->{version} > $EXTVER) {
     174        @{ $colData{$col->{name}} } = map { $col->{default} } (0 .. $numRows);
     175        next;
     176    }
    135177    $inFits->get_colnum(0, $col->{name}, $col_num, $status) and check_fitsio($status);
    136178    $inFits->get_coltype($col_num, $col_type, undef, undef, $status) and check_fitsio($status);
     
    138180                                                                    and check_fitsio($status);
    139181    $colData{$col->{name}} = $col_data;
    140 }
    141 
    142 # Now produce the output
    143 
    144 if (!$no_print_header) {
    145     my $label;
    146     my $data;
    147     # I don't do this because I want the keys to be printed in a particular order
    148     #foreach my $key (keys %$header) {
    149     foreach my $key (@key_array) {
    150         my $name = $header->{$key}->{name};
    151         my $value = $inHeader->{$name};
    152         if (($key eq 'STAGE')&& !(defined($value))) {
    153             $value = 'DIFF';
    154         }
    155         # get rid of quotes and whitespace
    156         $value =~ s/\'//g;
    157         if (defined $value) {
    158             #print "$key\t\t\t$value\n";
    159             $label .= sprintf "%-12s ", $key;
    160             $data  .= sprintf "%-12s ", $value;
    161         } else {
    162             die "keyword $key not found in $input\n";
    163         }
    164     }
    165     print "# " . $label . "\n" unless $no_print_label;
    166     print $data  . "\n";
    167 }
    168 
    169 if (!$no_print_rows) {
    170     if (!$no_print_label) {
    171         print "# ";
    172         foreach my $col (@$column_defs) {
    173             printf "%-12s ", $col->{name};
    174         }
    175         print "\n";
    176     }
    177 
    178     for (my $i = 0; $i < $numRows; $i++) {
    179         foreach my $col (@$column_defs) {
    180             printf "%-12s ", $colData{$col->{name}}->[$i];
     182    if ($col->{name} eq 'MJD-OBS') {
     183        print @{ $col_data } . "\n";
     184    }
     185}
     186
     187# Verify uniqueness of important columns:
     188my @unique_fields = ('QUERY_ID','OBSCODE','STAGE');
     189foreach my $colName (@unique_fields) {
     190    my %counter = ();
     191    foreach my $row (@{ $colData{$colName} }) {
     192        $counter{$row} = 1;
     193    }
     194    if (scalar(keys(%counter)) != 1) {
     195        $parse_error = 3;
     196    }
     197}
     198if ($parse_error) {
     199    die "Unable to parse detectability query: $parse_error " . &error_message($parse_error) . "\n";;
     200}
     201
     202# # Now produce the output
     203
     204
     205if (!$no_print_label) {
     206    print "# ";
     207    foreach my $col (@$column_defs) {
     208        printf "%-12s ", $col->{name};
     209    }
     210    print "\n";
     211}
     212
     213for (my $i = 0; $i < $numRows; $i++) {
     214    foreach my $col (@$column_defs) {
     215        printf "%-12s ", $colData{$col->{name}}->[$i];
    181216        #foreach my $aref (@col_arrays) {
    182             #printf "%-12s ", $aref->[$i];
    183         }
    184         print "\n";
    185     }
     217        #printf "%-12s ", $aref->[$i];
     218    }
     219    print "\n";
    186220}
    187221
     
    202236}
    203237
     238sub error_message {
     239    my $error = shift;
     240    if ($error == 1) {
     241        return("Unknown EXTVER/EXTNAME");
     242    }
     243    if ($error == 2) {
     244        return("Required header field not found");
     245    }
     246    if ($error == 3) {
     247        return("Unique column not uniquely specified");
     248    }
     249    else {
     250        return("Unknown fault.");
     251    }
     252}
     253
     254
     255
    204256__END__
Note: See TracChangeset for help on using the changeset viewer.