IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27431


Ignore:
Timestamp:
Mar 24, 2010, 11:15:44 AM (16 years ago)
Author:
rhenders
Message:

pspsSchema2xml now generates C header files with enums detailing table columns

Location:
trunk/ippToPsps
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/scripts/pspsSchema2xml.pl

    r27364 r27431  
    2323        -msg => "\n   Required options:\n\n".
    2424        "--schema <path to PSPS schema>\n".
    25         "--type <IN|DT|OB>\n".
     25        "--type <init|det|diff|stack>\n".
    2626        -exitval => 3
    2727        ) unless
     
    2929defined $type;
    3030
    31 if ($type ne "DT" && $type ne "IN" && $type ne "OB" && $type ne "ST") {
     31if ($type ne "init" && $type ne "det" && $type ne "diff" && $type ne "stack") {
    3232
    3333    print "Don't understand type '$type'\n";
    3434    die;
    3535}
     36
     37my $enumsHeader = "ippToPsps".ucfirst($type)."Enums";
     38open(OUT, ">".$enumsHeader.".h") or die("Error");
     39
     40print OUT "#ifndef ".uc($enumsHeader)."_H\n";
     41print OUT "#define ".uc($enumsHeader)."_H\n\n";
    3642
    3743
     
    4248$writer->startTag('tableDescriptions', "type" => "$type");
    4349
    44 if ($type eq "IN") {createInit();}
    45 elsif ($type eq "DT") {createDetections();}
    46 elsif ($type eq "OB") {createDiffs();}
    47 elsif ($type eq "ST") {createStacks();}
     50if ($type eq "init") {createInit();}
     51elsif ($type eq "det") {createDetections();}
     52elsif ($type eq "diff") {createDiffs();}
     53elsif ($type eq "stack") {createStacks();}
    4854
    4955# finish up XML
     
    5157$writer->end();
    5258
    53 
    54 ######################################################################################3
    55 
    56 # finds the schema file containing this table description
     59print OUT "\n#endif";
     60close OUT;
     61
     62
     63#######################################################################################
     64#
     65# Finds the schema file containing the table name passed in
     66#
     67#######################################################################################
    5768sub findSchemaFile {
    5869    my ($tableName) = @_;
     
    8697}
    8798
    88 # creates detections tables
     99#######################################################################################
     100#
     101# Creates detection batch tables
     102#
     103#######################################################################################
    89104sub createInit {
    90105
     
    101116}
    102117
    103 # creates init batch tables
     118#######################################################################################
     119#
     120# Creates initialisation batch tables
     121#
     122#######################################################################################
    104123sub createDetections {
    105124
     
    111130}
    112131
    113 # creates diff batch tables
     132#######################################################################################
     133#
     134# Creates difference batch tables
     135#
     136#######################################################################################
    114137sub createDiffs {
    115138
     
    118141    parseTable("StackLowSigDelta");
    119142    parseTable("StackHighSigDelta");
    120 }
    121 
    122 # creates stack batch tables
     143    parseTable("ObjectCalColor");
     144}
     145
     146#######################################################################################
     147#
     148# Creates stack batch tables
     149#
     150#######################################################################################
    123151sub createStacks {
    124152
     
    130158}
    131159
    132 
    133 # parses out a table
     160#######################################################################################
     161#
     162# Parses a particular table from the SQL file and converts it to an XML description
     163#
     164#######################################################################################
    134165sub parseTable {
    135166    my ($tableName, $newName) = @_;
     
    144175    else {$tableNameOut = $tableName}
    145176
     177    print OUT "\ntypedef enum {\n";
    146178    $writer->startTag('table', "name" => $tableNameOut);
    147179
     
    150182    my $reading = 0;
    151183    my $found = 0;
     184    my $colNum = 0;
    152185    my $table;
    153186
     
    163196                $reading = 1;
    164197                $found = 1;
     198                $colNum = 0;
    165199                next;
    166200            }
     
    180214        if ($line =~ m/\*\//) {next;}
    181215
    182         processLine($line, $tableName);
     216        $colNum = processLine($line, $tableName, $colNum);
    183217
    184218    }
     
    186220    if (!$found) {print "Could not find table '$tableName'\n";}
    187221    $writer->endTag();
     222    print OUT "} ".$tableNameOut.";\n";
    188223
    189224    close SCHEMA;
    190225}
    191226
    192 # process line
     227#######################################################################################
     228#
     229# Processes a line from the PSPS schema table description and converts to XML
     230#
     231#######################################################################################
    193232sub processLine {
    194     my ($line, $tableName) = @_;
     233    my ($line, $tableName, $colNum) = @_;
    195234
    196235    my $name;
     
    223262
    224263        print "In '$tableName', can't process: '$line'\n";
    225         return 0
     264        return $colNum
    226265    }
    227266
     
    263302    if ($type eq "TSTRING" && $default eq "") {$default = " ";}
    264303
     304    $colNum++;
     305
     306    print OUT "  ".uc($tableName)."_".uc($name)." = ".$colNum.",\n";
     307
    265308    $writer->startTag('column',
    266309            "name" => $name,
     
    270313
    271314    $writer->endTag();
    272 }
    273 
    274 
    275 
    276 
    277 
    278 
    279 
     315
     316    return $colNum;
     317}
  • trunk/ippToPsps/src/ippToPspsBatchDetection.c

    r27345 r27431  
    77 */
    88
    9 # include <limits.h>
     9#include <limits.h>
    1010#include "ippToPsps.h"
    1111#include "ippToPspsConfig.h"
     12#include "ippToPspsDetEnums.h"
    1213#include "fitsio.h"
    1314
     
    6162
    6263    // FrameMeta values
    63     fits_write_col(this->fitsOut, TLONG, 1, 1, 1, 1, &this->expId, &status);
     64    fits_write_col(this->fitsOut, TLONG, FRAMEMETA_FRAMEID, 1, 1, 1, &this->expId, &status);
    6465
    6566    int8_t surveyID = 0; // TODO
    66     fits_write_col(this->fitsOut, TBYTE, 2, 1, 1, 1, &surveyID, &status);
     67    fits_write_col(this->fitsOut, TBYTE, FRAMEMETA_SURVEYID, 1, 1, 1, &surveyID, &status);
    6768
    6869    int8_t filterID = -1;
    6970    ippToPspsConfig_getFilterId(this->config, filterType, &filterID);
    70     fits_write_col(this->fitsOut, TBYTE, 3, 1, 1, 1, &filterID, &status);
     71    fits_write_col(this->fitsOut, TBYTE, FRAMEMETA_FILTERID, 1, 1, 1, &filterID, &status);
    7172
    7273    int16_t cameraID = 1; // TODO
    73     fits_write_col(this->fitsOut, TSHORT, 4, 1, 1, 1, &cameraID, &status);
     74    fits_write_col(this->fitsOut, TSHORT, FRAMEMETA_CAMERAID, 1, 1, 1, &cameraID, &status);
    7475
    7576    int16_t cameraConfigID = 1; // TODO
    76     fits_write_col(this->fitsOut, TSHORT, 5, 1, 1, 1, &cameraConfigID, &status);
     77    fits_write_col(this->fitsOut, TSHORT, FRAMEMETA_CAMERACONFIGID, 1, 1, 1, &cameraConfigID, &status);
    7778
    7879    int16_t telescopeID = 1; // TODO
    79     fits_write_col(this->fitsOut, TSHORT, 6, 1, 1, 1, &telescopeID, &status);
     80    fits_write_col(this->fitsOut, TSHORT, FRAMEMETA_TELESCOPEID, 1, 1, 1, &telescopeID, &status);
    8081
    8182    // stuff to keep from psf.hdr header
     
    200201
    201202
    202             // TODO check numSmfDetections < MAXDETECT
     203            // TODO check nDet < MAXDETECT
    203204
    204205            // create ImageMeta
    205206            ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "ImageMeta", true);
    206207            psfFwhm = (fwhmMaj+fwhmMin)/2;
    207             fits_write_col(this->fitsOut, TLONGLONG, 1, 1, 1, 1, &pspsImageId, &status); // TODO enums for thse col numbers
    208             fits_write_col(this->fitsOut, TLONG, 2, 1, 1, 1, &this->expId, &status);
    209             fits_write_col(this->fitsOut, TSHORT, 3, 1, 1, 1, &pImage->ccdnum, &status);
    210             // fits_write_col(this->fitsOut, TLONG, 4, 1, 1, 1, &pImage->photcode, &status); TODO
     208            fits_write_col(this->fitsOut, TLONGLONG, IMAGEMETA_IMAGEID, 1, 1, 1, &pspsImageId, &status); // TODO enums for thse col numbers
     209            fits_write_col(this->fitsOut, TLONG, IMAGEMETA_FRAMEID, 1, 1, 1, &this->expId, &status);
     210            fits_write_col(this->fitsOut, TSHORT, IMAGEMETA_CCDID, 1, 1, 1, &pImage->ccdnum, &status);
     211            // fits_write_col(this->fitsOut, TLONG, IMAGEMETA_PHOTOCALID, 1, 1, 1, &pImage->photcode, &status); TODO
    211212            psLogMsg("ippToPsps", PS_LOG_INFO, "photocode %d", pImage->photcode);
    212             fits_write_col(this->fitsOut, TBYTE, 5, 1, 1, 1, &filterID, &status);
    213             fits_write_col(this->fitsOut, TFLOAT, 14, 1, 1, 1, &zptObs, &status);
    214             fits_write_col(this->fitsOut, TFLOAT, 19, 1, 1, 1, &psfFwhm, &status);
    215             fits_write_col(this->fitsOut, TFLOAT, 38, 1, 1, 1, &zptObs, &status);
     213            fits_write_col(this->fitsOut, TBYTE, IMAGEMETA_FILTERID, 1, 1, 1, &filterID, &status);
     214            fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOSCAT, 1, 1, 1, &zptObs, &status);
     215            fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PSFFWHM, 1, 1, 1, &psfFwhm, &status);
     216            fits_write_col(this->fitsOut, TFLOAT, IMAGEMETA_PHOTOZERO, 1, 1, 1, &zptObs, &status);
    216217
    217218            // move to detections table in smf
     
    223224            }
    224225
    225             long numSmfDetections = 0;
    226             if (fits_get_num_rows(fitsIn, &numSmfDetections, &status)) {
     226            long nDet = 0;
     227            if (fits_get_num_rows(fitsIn, &nDet, &status)) {
    227228                fits_report_error(stderr, status);
    228229            }
     
    232233
    233234            anynull = 0;
    234             fits_read_col(fitsIn, TLONG, 1, 1, 1, numSmfDetections, &longnull, ippIDet, &anynull, &status);
    235             fits_read_col(fitsIn, TFLOAT, 8, 1, 1, numSmfDetections, &floatnull, instMag, &anynull, &status);
    236             fits_read_col(fitsIn, TFLOAT, 9, 1, 1, numSmfDetections, &floatnull, instMagErr, &anynull, &status);
    237             fits_read_col(fitsIn, TFLOAT, 12, 1, 1, numSmfDetections, &floatnull, peakMag, &anynull, &status);
     235            fits_read_col(fitsIn, TLONG, 1, 1, 1, nDet, &longnull, ippIDet, &anynull, &status);
     236            fits_read_col(fitsIn, TFLOAT, 8, 1, 1, nDet, &floatnull, instMag, &anynull, &status);
     237            fits_read_col(fitsIn, TFLOAT, 9, 1, 1, nDet, &floatnull, instMagErr, &anynull, &status);
     238            fits_read_col(fitsIn, TFLOAT, 12, 1, 1, nDet, &floatnull, peakMag, &anynull, &status);
    238239
    239240            // DVO detections are ordered by IPP_IDET, which increments from 0 in SMF table
    240241            // both DVO detections and smf detections should increment. however, there may be gaps in smf and 'invalid' rows in dvo
    241242            numOfDuplicates = 0;
    242             for (long s = 0; s<numSmfDetections; s++) {
     243            for (long s = 0; s<nDet; s++) {
    243244
    244245                // count jumps in smf file
     
    296297
    297298            // detections
    298             ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, numSmfDetections, "Detection", false);
    299             fits_write_col(this->fitsOut, TLONGLONG, 1, 1, 1, numSmfDetections, objID, &status);
    300             fits_write_col(this->fitsOut, TLONGLONG, 2, 1, 1, numSmfDetections, detectID, &status);
    301             fits_write_col(this->fitsOut, TLONGLONG, 3, 1, 1, numSmfDetections, ippObjID, &status);
    302             fits_write_col(this->fitsOut, TLONGLONG, 4, 1, 1, numSmfDetections, ippDetectID, &status);
    303             fits_write_col(this->fitsOut, TBYTE, 5, 1, 1, numSmfDetections, filterIDs, &status);
    304             fits_write_col(this->fitsOut, TBYTE, 6, 1, 1, numSmfDetections, surveyIDs, &status);
    305             fits_write_col(this->fitsOut, TLONGLONG, 7, 1, 1, numSmfDetections, imageID, &status);
    306             fits_write_col(this->fitsOut, TFLOAT, 8, 1, 1, numSmfDetections, obsTimes, &status);
    307             fits_write_col(this->fitsOut, TFLOAT, 13, 1, 1, numSmfDetections, instFlux, &status);
    308             fits_write_col(this->fitsOut, TFLOAT, 14, 1, 1, numSmfDetections, instFluxErr, &status);
    309             fits_write_col(this->fitsOut, TFLOAT, 15, 1, 1, numSmfDetections, peakFlux, &status);
    310             fits_write_col(this->fitsOut, TSTRING, 26, 1, 1, numSmfDetections, assocDate, &status);
     299            ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "Detection", false);
     300            fits_write_col(this->fitsOut, TLONGLONG, DETECTION_OBJID, 1, 1, nDet, objID, &status);
     301            fits_write_col(this->fitsOut, TLONGLONG, DETECTION_DETECTID, 1, 1, nDet, detectID, &status);
     302            fits_write_col(this->fitsOut, TLONGLONG, DETECTION_IPPOBJID, 1, 1, nDet, ippObjID, &status);
     303            fits_write_col(this->fitsOut, TLONGLONG, DETECTION_IPPDETECTID, 1, 1, nDet, ippDetectID, &status);
     304            fits_write_col(this->fitsOut, TBYTE, DETECTION_FILTERID, 1, 1, nDet, filterIDs, &status);
     305            fits_write_col(this->fitsOut, TBYTE, DETECTION_SURVEYID, 1, 1, nDet, surveyIDs, &status);
     306            fits_write_col(this->fitsOut, TLONGLONG, DETECTION_IMAGEID, 1, 1, nDet, imageID, &status);
     307            fits_write_col(this->fitsOut, TFLOAT, DETECTION_OBSTIME, 1, 1, nDet, obsTimes, &status);
     308            fits_write_col(this->fitsOut, TFLOAT, DETECTION_INSTFLUX, 1, 1, nDet, instFlux, &status);
     309            fits_write_col(this->fitsOut, TFLOAT, DETECTION_INSTFLUXERR, 1, 1, nDet, instFluxErr, &status);
     310            fits_write_col(this->fitsOut, TFLOAT, DETECTION_PEAKFLUX, 1, 1, nDet, peakFlux, &status);
     311            fits_write_col(this->fitsOut, TSTRING, DETECTION_ASSOCDATE, 1, 1, nDet, assocDate, &status);
    311312            if (numOfDuplicates) fits_delete_rowlist(this->fitsOut, duplicateList, numOfDuplicates, &status);
    312313
    313314            // skinny object
    314             ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, numSmfDetections, "SkinnyObject", false);
    315             fits_write_col(this->fitsOut, TLONGLONG, 1, 1, 1, numSmfDetections, objID, &status);
    316             fits_write_col(this->fitsOut, TLONGLONG, 2, 1, 1, numSmfDetections, ippObjID, &status);
     315            ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "SkinnyObject", false);
     316            fits_write_col(this->fitsOut, TLONGLONG, SKINNYOBJECT_OBJID, 1, 1, nDet, objID, &status);
     317            fits_write_col(this->fitsOut, TLONGLONG, SKINNYOBJECT_IPPOBJID, 1, 1, nDet, ippObjID, &status);
    317318            if (numOfDuplicates) fits_delete_rowlist(this->fitsOut, duplicateList, numOfDuplicates, &status);
    318319
    319320            // object calibration color
    320             ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, numSmfDetections, "ObjectCalColor", false);
    321             fits_write_col(this->fitsOut, TLONGLONG, 1, 1, 1, numSmfDetections, objID, &status);
    322             fits_write_col(this->fitsOut, TLONGLONG, 2, 1, 1, numSmfDetections, ippObjID, &status);
    323             fits_write_col(this->fitsOut, TBYTE, 3, 1, 1, numSmfDetections, filterIDs, &status);
     321            ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, nDet, "ObjectCalColor", false);
     322            fits_write_col(this->fitsOut, TLONGLONG, OBJECTCALCOLOR_OBJID, 1, 1, nDet, objID, &status);
     323            fits_write_col(this->fitsOut, TLONGLONG, OBJECTCALCOLOR_IPPOBJID, 1, 1, nDet, ippObjID, &status);
     324            fits_write_col(this->fitsOut, TBYTE, OBJECTCALCOLOR_FILTERID, 1, 1, nDet, filterIDs, &status);
    324325            if (numOfDuplicates) fits_delete_rowlist(this->fitsOut, duplicateList, numOfDuplicates, &status);
    325326
     
    329330                    "|  %s |  %5ld  |   %5ld  |      %5d       |    %5d      |\n"
    330331                    "|___________|_________|__________|__________________|_______________|\n",
    331                     extensionName, numSmfDetections, numDetectionsOut, unmatched, numOfDuplicates);
     332                    extensionName, nDet, numDetectionsOut, unmatched, numOfDuplicates);
    332333
    333334            if (dvoDetections!= NULL) dvoFree(dvoDetections);
  • trunk/ippToPsps/src/ippToPspsBatchDifference.c

    r27345 r27431  
    99#include "ippToPsps.h"
    1010#include "ippToPspsConfig.h"
     11#include "ippToPspsDiffEnums.h"
    1112
    1213/**
     
    4142
    4243    for (uint16_t i = 0; i<this->numOfInputFiles; i++) {
    43     //for (uint16_t i = 0; i<3; i++) {
    4444
    4545        if (fits_open_file(&fitsIn, this->inputFiles[i], READONLY, &status)) {
     
    5757        fits_get_hdrspace(fitsIn, &nKeys, NULL, &status);
    5858        ippToPspsConfig_writeTable(this->config, fitsIn,  this->fitsOut, 1, "StackMeta", true);
    59         fits_write_col(this->fitsOut, TLONG, 2, 1, 1, 1, &skycell, &status);
     59        fits_write_col(this->fitsOut, TLONG, STACKMETA_SKYCELLID, 1, 1, 1, &skycell, &status);
    6060
    6161        // build StackToImage
     
    107107        ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, 1, "StackLowSigDelta", false);
    108108        ippToPspsConfig_writeTable(this->config, fitsIn, this->fitsOut, tableSize, "StackHighSigDelta", false);
    109         fits_write_col(this->fitsOut, TFLOAT, 5, 1, 1, tableSize, obsTimes, &status);
     109        fits_write_col(this->fitsOut, TFLOAT, STACKHIGHSIGDELTA_OBSTIME, 1, 1, tableSize, obsTimes, &status);
    110110        if (numLowSig) fits_delete_rowlist(this->fitsOut, lowSig, numLowSig, &status);
    111111
Note: See TracChangeset for help on using the changeset viewer.