Changeset 31011 for trunk/ippToPsps/src/Batch.c
- Timestamp:
- Mar 22, 2011, 4:11:23 PM (15 years ago)
- File:
-
- 1 edited
-
trunk/ippToPsps/src/Batch.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippToPsps/src/Batch.c
r30968 r31011 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 psError(PS_ERR_UNKNOWN, false, "Failed, so deleting fits file"); 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 this->config->destroy(this->config); 102 90 103 91 pmConfigDone(); … … 151 139 Sets-up and reads command-line arguments 152 140 */ 153 static bool parseArguments(Batch* this, int argc, char **argv ) {141 static bool parseArguments(Batch* this, int argc, char **argv, char* configsDir, char* fitsOutFile) { 154 142 155 143 // first deal with DVO database … … 178 166 haveSurveyType = false; 179 167 168 char fitsOutPath[1000]; 169 char configsBaseDir[1000]; 170 180 171 // decode arguments 181 172 int32_t optind = 1; … … 193 184 else if(strcmp(sw, "-output") == 0 ) { 194 185 optind++; if( optind > ( argc-1 ) ) break; 195 strcpy( this->fitsOutPath, argv[optind]);186 strcpy(fitsOutPath, argv[optind]); 196 187 haveFitsOutPath = true; 197 188 } … … 203 194 else if(strcmp(sw, "-config") == 0 ) { 204 195 optind++; if( optind > ( argc-1 ) ) break; 205 strcpy( this->configsDir, argv[optind]);196 strcpy(configsBaseDir, argv[optind]); 206 197 haveConfig = true; 207 198 } … … 220 211 221 212 222 // setup command line arguments223 //psMetadataAddStr(this->arguments, PS_LIST_TAIL, "-survey", 0, "Survey type", NULL);224 225 226 // now check rest of arguments227 //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"));235 213 236 214 if (haveFitsInPath && !readInputFilePaths(this)) { … … 240 218 } 241 219 242 return true;243 }244 245 /**246 Initialises file paths, creates FITS file etc247 */248 bool init(Batch* this) {249 250 220 // create a config object 251 this->config = ippToPspsConfig_Constructor(this->configsDir); 221 strcat(configsBaseDir, configsDir); 222 this->config = new_Config(configsBaseDir); 252 223 if (this->config == NULL) { 253 224 … … 257 228 258 229 // 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)) { 260 231 261 232 this->exitCode = PS_EXIT_CONFIG_ERROR; … … 263 234 } 264 235 // create full FITS out path 265 sprintf ( this->fitsOutPath, "%s/%s", this->fitsOutPath, this->fitsOutFile);236 sprintf (fitsOutPath, "%s/%s", fitsOutPath, fitsOutFile); 266 237 267 238 // 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; 276 241 277 242 // create XML document for results … … 281 246 xmlNodePtr rootNode = xmlNewNode(NULL, BAD_CAST "ippToPsps_Results"); 282 247 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); 284 249 } 285 250 … … 298 263 printf("* numOfInputFiles : %d\n", this->numOfInputFiles); 299 264 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);303 265 } 304 266 … … 359 321 // set up function pointers 360 322 this->parseArguments = parseArguments; 361 this->init = init;323 //this->init = init; 362 324 this->print = print; 363 325 this->destroy = destroy;
Note:
See TracChangeset
for help on using the changeset viewer.
