IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 30, 2011, 9:36:02 AM (15 years ago)
Author:
eugene
Message:

merging changes from trunk

Location:
branches/eam_branches/ipp-20110213/ippToPsps/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110213/ippToPsps/src

    • Property svn:ignore
      •  

        old new  
        99config.h.in
        1010stamp-h1
        11 ippToPspsVersionDefinitions.h
         11VersionDefinitions.h
         12detectionbatch
         13initbatch
         14stackbatch
         15
  • branches/eam_branches/ipp-20110213/ippToPsps/src/Batch.c

    r30191 r31083  
    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            this->logger->print(this->logger, MSG_ERROR, "Batch", "Failed, so deleting fits file\n");
     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    // destroy objects
     90    this->fitsGenerator->destroy(this->fitsGenerator);
     91    this->initData->destroy(this->initData);
    10292
    10393    pmConfigDone();
     
    115105    if (file == NULL) {
    116106
    117         psError(PS_ERR_UNKNOWN, false, "Unable to open file at %s", this->fitsInPath);
     107        this->logger->print(this->logger, MSG_ERROR, "Batch", "Unable to open file at %s\n", this->fitsInPath);
    118108        return false;
    119109    }
     
    123113    while (fgets(line, 1000, file) != NULL) this->numOfInputFiles++;
    124114
    125     printf ("Number of input files %d\n", this->numOfInputFiles);
     115    this->logger->print(this->logger, MSG_INFO, "Batch",
     116            "%d input file%s found\n", this->numOfInputFiles, (this->numOfInputFiles > 1) ? "s" : "");
    126117
    127118    if (this->numOfInputFiles < 1) return false;
     
    151142  Sets-up and reads command-line arguments
    152143*/
    153 static bool parseArguments(Batch* this, int argc, char **argv) {
     144static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) {
    154145
    155146    // first deal with DVO database
     
    166157    if (!this->pmconfig) {
    167158
    168         psError(PS_ERR_UNKNOWN, false, "Unable to read configuration.");
     159        this->logger->print(this->logger, MSG_ERROR, "Batch", "Unable to read configuration\n");
    169160        this->exitCode = PS_EXIT_CONFIG_ERROR;
    170161        return false;
     
    178169    haveSurveyType = false;
    179170
     171    char fitsOutPath[1000];
     172    char configsBaseDir[1000];
     173
    180174    // decode arguments
    181175    int32_t optind = 1;
     
    193187            else if(strcmp(sw, "-output") == 0 ) {
    194188                optind++; if( optind > ( argc-1 ) ) break;
    195                 strcpy(this->fitsOutPath, argv[optind]);
     189                strcpy(fitsOutPath, argv[optind]);
    196190                haveFitsOutPath = true;
    197191            }
     
    203197            else if(strcmp(sw, "-config") == 0 ) {
    204198                optind++; if( optind > ( argc-1 ) ) break;
    205                 strcpy(this->configsDir, argv[optind]);
     199                strcpy(configsBaseDir, argv[optind]);
    206200                haveConfig = true;
    207201            }
     
    211205                haveSurveyType = true;
    212206            }
     207            else if(strcmp(sw, "-test") == 0 ) {
     208                this->testMode = true;
     209            }
    213210        }
    214211
     
    216213    }
    217214
    218 
    219     // setup command line arguments
    220     //psMetadataAddStr(this->arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL);
    221 
    222 
    223     // now check rest of arguments
    224     //if (argc < 2 || !psArgumentParse(this->arguments, &argc, argv)) {
    225 
    226       //  usage(this, argv[0]);
    227         //this->exitCode = PS_EXIT_CONFIG_ERROR;
    228         //return false;
    229    // }
    230 
    231     //this->surveyType = psMemIncrRefCounter(psMetadataLookupStr(NULL, this->arguments, "-survey"));
    232 
     215    // check we have some input paths
    233216    if (haveFitsInPath && !readInputFilePaths(this)) {
    234217
     
    237220    }
    238221
    239     return true;
    240 }
    241 
    242 /**
    243   Initialises file paths, creates FITS file etc
    244   */
    245 bool init(Batch* this) {
    246 
    247     // create a config object
    248     this->config = ippToPspsConfig_Constructor(this->configsDir);
    249     if (this->config == NULL) {
     222    // create an InitData object and get survey ID
     223    this->initData = new_InitData(configsBaseDir, this->logger);
     224    if (strlen(this->surveyType) > 0 &&
     225            !this->initData->getSurveyId(this->initData, this->surveyType, &this->surveyID)) {
    250226
    251227        this->exitCode = PS_EXIT_CONFIG_ERROR;
     
    253229    }
    254230
    255     // get survey ID using config object
    256     if (strlen(this->surveyType) > 0 && !ippToPspsConfig_getSurveyId(this->config, this->surveyType, &this->surveyID)) {
    257 
    258         this->exitCode = PS_EXIT_CONFIG_ERROR;
    259         return false;
    260     }
     231    // create a FitsGenerator object
     232    strcat(configsBaseDir, configsDir);
     233    this->fitsGenerator = new_FitsGenerator(this->logger, configsBaseDir);
     234
    261235    // create full FITS out path
    262     sprintf (this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);
     236    sprintf(fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile);
    263237
    264238    // create an output FITS file
    265     int status=0;
    266     if (fits_create_file(&this->fitsOut, this->fitsOutPath, &status)) {
    267         fits_report_error(stderr, status);
    268         psError(PS_ERR_IO, false, "Unable to create file at: '%s'", this->fitsOutPath);
    269         this->exitCode = PS_EXIT_SYS_ERROR;
    270         this->fitsOut = NULL;
    271         return false;
    272     }
     239    this->fitsOut = new_Fits(fitsOutPath, this->logger);
     240    if (this->fitsOut->getFilePtr(this->fitsOut) == NULL) return false;
    273241
    274242    // create XML document for results
     
    278246        xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results");
    279247        xmlDocSetRootElement(this->resultsXmlDoc, rootNode);
    280         xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST this->fitsOutFile);
     248        xmlNewChild(rootNode, NULL, BAD_CAST "filename", BAD_CAST fitsOutFile);
    281249    }
    282250
     
    289257static void print(Batch* this) {
    290258
    291     printf("\n");
    292     printf("* surveyType      : '%s'\n", this->surveyType);
    293     printf("* surveyID        : %d\n", this->surveyID);
    294     printf("* resultsPath     : '%s'\n", this->resultsPath);
    295     printf("* numOfInputFiles : %d\n", this->numOfInputFiles);
    296     printf("* fitsInPath      : '%s'\n", this->fitsInPath);
    297     printf("* fitsOutFile     : '%s'\n", this->fitsOutFile);
    298     printf("* fitsOutPath     : '%s'\n", this->fitsOutPath);
    299     printf("* configsDir      : '%s'\n", this->configsDir);
     259    this->logger->print(this->logger, MSG_INFO, "Batch", "\n");
     260    this->logger->print(this->logger, MSG_INFO, "Batch", "     Class fields:\n");
     261    this->logger->print(this->logger, MSG_INFO, "Batch", "surveyType      : %s\n", this->surveyType);
     262    this->logger->print(this->logger, MSG_INFO, "Batch", "surveyID        : %d\n", this->surveyID);
     263    this->logger->print(this->logger, MSG_INFO, "Batch", "resultsPath     : %s\n", this->resultsPath);
     264    this->logger->print(this->logger, MSG_INFO, "Batch", "numOfInputFiles : %d\n", this->numOfInputFiles);
     265    this->logger->print(this->logger, MSG_INFO, "Batch", "fitsInPath      : %s\n", this->fitsInPath);
     266    this->logger->print(this->logger, MSG_INFO, "Batch", "testMode        : %s\n", this->testMode ? "yes" : "no");
    300267}
    301268
     
    342309  Constructor. Takes a Batch object and initialises it.
    343310  */
    344 bool new_Batch(Batch *this) {
    345 
     311bool new_Batch(Logger* logger, Batch *this) {
     312
     313    this->logger = logger;
    346314    this->surveyID = -1;
    347315    this->resultsXmlDoc = NULL;
     
    349317    this->inputFiles = NULL;
    350318    this->fitsOut = NULL;
    351     this->config = NULL;
     319    this->fitsGenerator = NULL;
    352320    this->pmconfig = NULL;
    353321    this->exitCode = PS_EXIT_SUCCESS;
    354 
     322    this->testMode = false;
     323
     324    // set up function pointers
    355325    this->parseArguments = parseArguments;
    356     this->init = init;
    357326    this->print = print;
    358     this->destroy = destroy;
    359 
    360327    this->gotResultsPath = gotResultsPath;
    361328    this->gotFitsInPath = gotFitsInPath;
     
    363330    this->gotConfig = gotConfig;
    364331    this->gotSurveyType = gotSurveyType;
     332    this->destroy = destroy;
    365333
    366334    assert(this);
Note: See TracChangeset for help on using the changeset viewer.