- Timestamp:
- Mar 30, 2011, 9:36:02 AM (15 years ago)
- 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 9 9 config.h.in 10 10 stamp-h1 11 ippToPspsVersionDefinitions.h 11 VersionDefinitions.h 12 detectionbatch 13 initbatch 14 stackbatch 15
-
- Property svn:ignore
-
branches/eam_branches/ipp-20110213/ippToPsps/src/Batch.c
r30191 r31083 18 18 #include <pslib.h> 19 19 #include <psmodules.h> 20 20 21 #include "Batch.h" 21 22 … … 62 63 if (this->exitCode != PS_EXIT_SUCCESS) { 63 64 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); 71 67 } 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); 82 70 } 83 71 … … 99 87 if (this->dvoConfig != NULL) dvoConfigFree(this->dvoConfig); 100 88 101 ippToPspsConfig_Destructor(this->config); 89 // destroy objects 90 this->fitsGenerator->destroy(this->fitsGenerator); 91 this->initData->destroy(this->initData); 102 92 103 93 pmConfigDone(); … … 115 105 if (file == NULL) { 116 106 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); 118 108 return false; 119 109 } … … 123 113 while (fgets(line, 1000, file) != NULL) this->numOfInputFiles++; 124 114 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" : ""); 126 117 127 118 if (this->numOfInputFiles < 1) return false; … … 151 142 Sets-up and reads command-line arguments 152 143 */ 153 static bool parseArguments(Batch* this, int argc, char **argv ) {144 static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) { 154 145 155 146 // first deal with DVO database … … 166 157 if (!this->pmconfig) { 167 158 168 psError(PS_ERR_UNKNOWN, false, "Unable to read configuration.");159 this->logger->print(this->logger, MSG_ERROR, "Batch", "Unable to read configuration\n"); 169 160 this->exitCode = PS_EXIT_CONFIG_ERROR; 170 161 return false; … … 178 169 haveSurveyType = false; 179 170 171 char fitsOutPath[1000]; 172 char configsBaseDir[1000]; 173 180 174 // decode arguments 181 175 int32_t optind = 1; … … 193 187 else if(strcmp(sw, "-output") == 0 ) { 194 188 optind++; if( optind > ( argc-1 ) ) break; 195 strcpy( this->fitsOutPath, argv[optind]);189 strcpy(fitsOutPath, argv[optind]); 196 190 haveFitsOutPath = true; 197 191 } … … 203 197 else if(strcmp(sw, "-config") == 0 ) { 204 198 optind++; if( optind > ( argc-1 ) ) break; 205 strcpy( this->configsDir, argv[optind]);199 strcpy(configsBaseDir, argv[optind]); 206 200 haveConfig = true; 207 201 } … … 211 205 haveSurveyType = true; 212 206 } 207 else if(strcmp(sw, "-test") == 0 ) { 208 this->testMode = true; 209 } 213 210 } 214 211 … … 216 213 } 217 214 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 233 216 if (haveFitsInPath && !readInputFilePaths(this)) { 234 217 … … 237 220 } 238 221 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)) { 250 226 251 227 this->exitCode = PS_EXIT_CONFIG_ERROR; … … 253 229 } 254 230 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 261 235 // create full FITS out path 262 sprintf (this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);236 sprintf(fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile); 263 237 264 238 // 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; 273 241 274 242 // create XML document for results … … 278 246 xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results"); 279 247 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); 281 249 } 282 250 … … 289 257 static void print(Batch* this) { 290 258 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"); 300 267 } 301 268 … … 342 309 Constructor. Takes a Batch object and initialises it. 343 310 */ 344 bool new_Batch(Batch *this) { 345 311 bool new_Batch(Logger* logger, Batch *this) { 312 313 this->logger = logger; 346 314 this->surveyID = -1; 347 315 this->resultsXmlDoc = NULL; … … 349 317 this->inputFiles = NULL; 350 318 this->fitsOut = NULL; 351 this-> config= NULL;319 this->fitsGenerator = NULL; 352 320 this->pmconfig = NULL; 353 321 this->exitCode = PS_EXIT_SUCCESS; 354 322 this->testMode = false; 323 324 // set up function pointers 355 325 this->parseArguments = parseArguments; 356 this->init = init;357 326 this->print = print; 358 this->destroy = destroy;359 360 327 this->gotResultsPath = gotResultsPath; 361 328 this->gotFitsInPath = gotFitsInPath; … … 363 330 this->gotConfig = gotConfig; 364 331 this->gotSurveyType = gotSurveyType; 332 this->destroy = destroy; 365 333 366 334 assert(this);
Note:
See TracChangeset
for help on using the changeset viewer.
