IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 22, 2011, 4:11:23 PM (15 years ago)
Author:
rhenders
Message:

Using new Fits class and Config class

File:
1 edited

Legend:

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

    r30968 r31011  
    1818#include <pslib.h>
    1919#include <psmodules.h>
     20
    2021#include "Batch.h"
    2122
     
    6263        if (this->exitCode != PS_EXIT_SUCCESS) {
    6364
    64             psError(PS_ERR_UNKNOWN, false, "Failed, so deleting %s", this->fitsOutPath);
    65 
    66             // if process failed, we need to delete that FITS file
    67             if (remove(this->fitsOutPath) == -1) {
    68 
    69                 psError(PS_ERR_UNKNOWN, false, "Unable to delete %s", this->fitsOutPath);
    70             }
     65            psError(PS_ERR_UNKNOWN, false, "Failed, so deleting fits file");
     66            this->fitsOut->delete(this->fitsOut);
    7167        }
    72         // ...otherwise, close file
    73         else {
    74 
    75             int status = 0;
    76             if (fits_close_file(this->fitsOut, &status)) {
    77 
    78                 psError(PS_ERR_IO, false, "Unable to close FITS file %s", this->fitsOutPath);
    79                 fits_report_error(stderr, status);
    80             }
    81         }
     68
     69        this->fitsOut->destroy(this->fitsOut);
    8270    }
    8371
     
    9987    if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig);
    10088
    101     ippToPspsConfig_Destructor(this->config);
     89    this->config->destroy(this->config);
    10290
    10391    pmConfigDone();
     
    151139  Sets-up and reads command-line arguments
    152140*/
    153 static bool parseArguments(Batch* this, int argc, char **argv) {
     141static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) {
    154142
    155143    // first deal with DVO database
     
    178166    haveSurveyType = false;
    179167
     168    char fitsOutPath[1000];
     169    char configsBaseDir[1000];
     170
    180171    // decode arguments
    181172    int32_t optind = 1;
     
    193184            else if(strcmp(sw, "-output") == 0 ) {
    194185                optind++; if( optind > ( argc-1 ) ) break;
    195                 strcpy(this->fitsOutPath, argv[optind]);
     186                strcpy(fitsOutPath, argv[optind]);
    196187                haveFitsOutPath = true;
    197188            }
     
    203194            else if(strcmp(sw, "-config") == 0 ) {
    204195                optind++; if( optind > ( argc-1 ) ) break;
    205                 strcpy(this->configsDir, argv[optind]);
     196                strcpy(configsBaseDir, argv[optind]);
    206197                haveConfig = true;
    207198            }
     
    220211
    221212
    222     // setup command line arguments
    223     //psMetadataAddStr(this->arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL);
    224 
    225 
    226     // now check rest of arguments
    227     //if (argc < 2 || !psArgumentParse(this->arguments, &argc, argv)) {
    228 
    229       //  usage(this, argv[0]);
    230         //this->exitCode = PS_EXIT_CONFIG_ERROR;
    231         //return false;
    232    // }
    233 
    234     //this->surveyType = psMemIncrRefCounter(psMetadataLookupStr(NULL, this->arguments, "-survey"));
    235213
    236214    if (haveFitsInPath && !readInputFilePaths(this)) {
     
    240218    }
    241219
    242     return true;
    243 }
    244 
    245 /**
    246   Initialises file paths, creates FITS file etc
    247   */
    248 bool init(Batch* this) {
    249 
    250220    // create a config object
    251     this->config = ippToPspsConfig_Constructor(this->configsDir);
     221    strcat(configsBaseDir, configsDir);
     222    this->config = new_Config(configsBaseDir);
    252223    if (this->config == NULL) {
    253224
     
    257228
    258229    // get survey ID using config object
    259     if (strlen(this->surveyType) > 0 && !ippToPspsConfig_getSurveyId(this->config, this->surveyType, &this->surveyID)) {
     230    if (strlen(this->surveyType) > 0 && !this->config->getSurveyId(this->config, this->surveyType, &this->surveyID)) {
    260231
    261232        this->exitCode = PS_EXIT_CONFIG_ERROR;
     
    263234    }
    264235    // create full FITS out path
    265     sprintf (this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);
     236    sprintf (fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
    266237
    267238    // create an output FITS file
    268     int status=0;
    269     if (fits_create_file(&this->fitsOut, this->fitsOutPath, &status)) {
    270         fits_report_error(stderr, status);
    271         psError(PS_ERR_IO, false, "Unable to create file at: '%s'", this->fitsOutPath);
    272         this->exitCode = PS_EXIT_SYS_ERROR;
    273         this->fitsOut = NULL;
    274         return false;
    275     }
     239    this->fitsOut = new_Fits(fitsOutPath);
     240    if (this->fitsOut->getFilePtr(this->fitsOut) == NULL) return false;
    276241
    277242    // create XML document for results
     
    281246        xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results");
    282247        xmlDocSetRootElement(this->resultsXmlDoc, rootNode);
    283         xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST this->fitsOutFile);
     248        xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST fitsOutFile);
    284249    }
    285250
     
    298263    printf("* numOfInputFiles : %d\n", this->numOfInputFiles);
    299264    printf("* fitsInPath      : '%s'\n", this->fitsInPath);
    300     printf("* fitsOutFile     : '%s'\n", this->fitsOutFile);
    301     printf("* fitsOutPath     : '%s'\n", this->fitsOutPath);
    302     printf("* configsDir      : '%s'\n", this->configsDir);
    303265}
    304266
     
    359321    // set up function pointers
    360322    this->parseArguments = parseArguments;
    361     this->init = init;
     323    //this->init = init;
    362324    this->print = print;
    363325    this->destroy = destroy;
Note: See TracChangeset for help on using the changeset viewer.