IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30967


Ignore:
Timestamp:
Mar 18, 2011, 11:33:22 AM (15 years ago)
Author:
rhenders
Message:

XML result writing now in it's own method; support for 'test mode', meaning, no current dat used in FITS, and only running over chip 33

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/src/DetectionBatch.c

    r30193 r30967  
    1515    free (this->expName);
    1616    free (this);
     17}
     18
     19/**
     20  Writes results to XML file
     21  */
     22static bool writeResults(DetectionBatch* this, long minObjID, long maxObjID, long totalDetectionsOut) {
     23
     24    if (!this->base.resultsXmlDoc) return false;
     25
     26    xmlNodePtr rootNode = xmlDocGetRootElement(this->base.resultsXmlDoc);
     27    char tmp[100];
     28    sprintf(tmp, "%ld", minObjID);
     29    xmlNewChild(rootNode, NULL, BAD_CAST "minObjID", BAD_CAST tmp);
     30    sprintf(tmp, "%ld", maxObjID);
     31    xmlNewChild(rootNode, NULL, BAD_CAST "maxObjID", BAD_CAST tmp);
     32    sprintf(tmp, "%ld", totalDetectionsOut);
     33    xmlNewChild(rootNode, NULL, BAD_CAST "totalDetections", BAD_CAST tmp);
     34
     35    return true;
    1736}
    1837
     
    119138        filterIDs[s] = filterID;
    120139        surveyIDs[s] = this->base.surveyID;
    121         strcpy(assocDate[s], this->base.todaysDate);
     140
     141        // if running in test mode, don't use today's date
     142        if (this->base.testMode) strcpy(assocDate[s], "2010-01-01");
     143        else strcpy(assocDate[s], this->base.todaysDate);
    122144    }
    123145
     
    133155    int ippIDetNum, instMagNum, instMagErrNum, peakMagNum;
    134156    bool error = false;
    135 
    136     // loop round all 60 chips
    137     for (int x=0; x<8; x++) {
    138         for (int y=0; y<8; y++) {
     157    int startX, stopX, startY, stopY;
     158
     159    // in test mode, only run for chip 33
     160    if (this->base.testMode) {
     161
     162        startX = 3;
     163        stopX = 4;
     164        startY = 3;
     165        stopY = 4;
     166    }
     167    // in 'normal' mode, run for all chips
     168    else {
     169   
     170        startX = 0;
     171        stopX = 8;
     172        startY = 0;
     173        stopY = 8;
     174    }
     175
     176    // loop round chips
     177    for (int x=startX; x<stopX; x++) {
     178        for (int y=startY; y<stopY; y++) {
    139179
    140180            // dodge the corners
     
    148188            // check we can move to detections table in smf
    149189            sprintf(extensionName, "XY%s.psf", ccdNumber);
    150             status=0;
    151             if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) {
    152                 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping this chip\n", extensionName);
    153                 continue;
    154             }
     190            if (!ippToPspsConfig_moveToExtensionTable(fitsIn, extensionName)) continue;
    155191
    156192            // move to header extension
    157193            sprintf(extensionName, "XY%s.hdr", ccdNumber);
    158             status=0;
    159             if (fits_movnam_hdu(fitsIn, IMAGE_HDU, extensionName, 0, &status)) {
    160                 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping this chip\n", extensionName);
    161                 continue;
    162             }
     194            if (!ippToPspsConfig_moveToExtensionHeader(fitsIn, extensionName)) continue;
    163195
    164196            // stuff to save from psf.hdr
     
    214246            // now move BACK to detections table in smf
    215247            sprintf(extensionName, "XY%s.psf", ccdNumber);
    216             status=0;
    217             if (fits_movnam_hdu(fitsIn, BINARY_TBL, extensionName, 0, &status)) {
    218                 psError(PS_ERR_IO, false, "Can't move to extension: %s skipping\n", extensionName);
    219                 continue;
    220             }
     248            if (!ippToPspsConfig_moveToExtensionTable(fitsIn, extensionName)) continue;
    221249
    222250            // keep a running count of 'images' we find in order to write total to FrameMeta at the end
     
    312340
    313341                    // check for invalid flux values, and skip them
    314                     if ( !peakFluxOk || !instFluxOk) {
     342                    if (!peakFluxOk || !instFluxOk) {
    315343                        removeList[numOfDuplicates+numInvalidFlux+numOfInvalidIppIDet] = s+1;
    316344                        numInvalidFlux++;
     
    408436
    409437    // write number of images we have found into FrameMeta table
    410     status=0;
    411     if (fits_movnam_hdu(this->base.fitsOut, BINARY_TBL, "FrameMeta", 0, &status))
    412         psError(PS_ERR_IO, false, "Can't move back to FrameMeta extension to write number of OTAs\n");
    413     else {
     438    if (ippToPspsConfig_moveToExtensionTable(this->base.fitsOut, "FrameMeta")) {
     439
    414440        fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_NOTA, 1, 1, 1, &nOta, &status);
    415441        fits_write_col(this->base.fitsOut, TSHORT, FRAMEMETA_NUMPHOTOREF, 1, 1, 1, &totalNumPhotoRef, &status);
    416442    }
     443
    417444    status=0;
    418445    if (fits_close_file(fitsIn, &status)) fits_report_error(stderr, status);
    419     // write results
    420     if (this->base.resultsXmlDoc) {
    421 
    422         xmlNodePtr rootNode = xmlDocGetRootElement(this->base.resultsXmlDoc);
    423         char tmp[100];
    424         sprintf(tmp, "%ld", minObjID);
    425         xmlNewChild(rootNode, NULL, BAD_CAST "minObjID", BAD_CAST tmp);
    426         sprintf(tmp, "%ld", maxObjID);
    427         xmlNewChild(rootNode, NULL, BAD_CAST "maxObjID", BAD_CAST tmp);
    428         sprintf(tmp, "%ld", totalDetectionsOut);
    429         xmlNewChild(rootNode, NULL, BAD_CAST "totalDetections", BAD_CAST tmp);
    430     }
     446
     447    writeResults(this, minObjID, maxObjID, totalDetectionsOut);
    431448
    432449    psLogMsg("ippToPsps", PS_LOG_INFO, "Data written for a total of %d chips/OTAs", nOta);
     
    437454    return this->base.exitCode;
    438455}
    439 
    440456
    441457/**
Note: See TracChangeset for help on using the changeset viewer.