Changeset 12832 for trunk/psModules/src/objects/pmSourceIO.c
- Timestamp:
- Apr 13, 2007, 5:22:48 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/objects/pmSourceIO.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceIO.c
r12706 r12832 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1.3 3$ $Name: not supported by cvs2svn $6 * @date $Date: 2007-0 3-31 04:18:04$5 * @version $Revision: 1.34 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2007-04-14 03:22:48 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 66 66 67 67 // Given a FITS file pointer, write the table of object data 68 bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, pmConfig *config)68 bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 69 69 { 70 70 … … 125 125 126 126 // read in all chip-level Objects files for this FPA 127 bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config)127 bool pmFPAWriteObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 128 128 { 129 129 … … 140 140 141 141 // read in all cell-level Objects files for this chip 142 bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config)142 bool pmChipWriteObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 143 143 { 144 144 … … 155 155 156 156 // read in all readout-level Objects files for this cell 157 bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config)157 bool pmCellWriteObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 158 158 { 159 159 … … 170 170 171 171 // write out all readout-level Objects files for this cell 172 bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)172 bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 173 173 { 174 174 … … 260 260 // we only need a PHU if chips->n > 1 and file->fileLevel == FPA 261 261 // otherwise, the chip header fills the PHU location 262 // XXX this code could be placed in a 'pmSource_CMF_WritePHU' function and called263 // from pmFPAfileIO.c.262 // XXX this code could be placed in a 'pmSource_CMF_WritePHU' function and called 263 // from pmFPAfileIO.c. 264 264 if ((file->fileLevel == PM_FPA_LEVEL_FPA) && (file->fpa->chips->n > 1) && !file->phu) { 265 265 … … 275 275 pmConfigConformHeader (outhead, file->format); 276 276 277 psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information278 const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME");279 if (fpaNameHdr && strlen(fpaNameHdr) > 0) {280 const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME");281 psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName);282 }277 psMetadata *fileData = psMetadataLookupMetadata(NULL, file->format, "FILE"); // File information 278 const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.NAME"); 279 if (fpaNameHdr && strlen(fpaNameHdr) > 0) { 280 const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.NAME"); 281 psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE, "FPA name", fpaName); 282 } 283 283 } 284 284 … … 298 298 // lookup the EXTNAME values used for table data and image header segments 299 299 char *rule = NULL; 300 // Menu of EXTNAME rules301 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 302 if (!menu) {303 psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");304 return false;305 }306 // EXTNAME for image header307 rule = psMetadataLookupStr(&status, menu, "CMF.HEAD"); 308 if (!rule) {309 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config");310 return false;311 }300 // Menu of EXTNAME rules 301 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 302 if (!menu) { 303 psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config"); 304 return false; 305 } 306 // EXTNAME for image header 307 rule = psMetadataLookupStr(&status, menu, "CMF.HEAD"); 308 if (!rule) { 309 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config"); 310 return false; 311 } 312 312 headname = pmFPAfileNameFromRule (rule, file, view); 313 // EXTNAME for table data314 rule = psMetadataLookupStr(&status, menu, "CMF.DATA"); 315 if (!rule) {316 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config");317 return false;318 }313 // EXTNAME for table data 314 rule = psMetadataLookupStr(&status, menu, "CMF.DATA"); 315 if (!rule) { 316 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config"); 317 return false; 318 } 319 319 dataname = pmFPAfileNameFromRule (rule, file, view); 320 320 … … 348 348 } 349 349 350 // create a header to hold the output data351 outhead = psMetadataAlloc ();352 353 // determine the output table format 354 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");355 if (!status) {356 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");357 return false;358 }359 exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));360 if (!exttype) {361 exttype = psStringCopy ("SMPDATA");362 } 363 364 // write the links to the image header350 // create a header to hold the output data 351 outhead = psMetadataAlloc (); 352 353 // determine the output table format 354 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 355 if (!status) { 356 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 357 return false; 358 } 359 exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT")); 360 if (!exttype) { 361 exttype = psStringCopy ("SMPDATA"); 362 } 363 364 // write the links to the image header 365 365 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname); 366 366 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype); 367 367 psFree (exttype); 368 368 369 // XXX these are case-sensitive since the EXTYPE is case-sensitive370 status = false;371 if (!strcmp (exttype, "SMPDATA")) {372 status = pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname);373 }374 if (!strcmp (exttype, "PS1_DEV_0")) {375 status = pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname);376 }369 // XXX these are case-sensitive since the EXTYPE is case-sensitive 370 status = false; 371 if (!strcmp (exttype, "SMPDATA")) { 372 status = pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname); 373 } 374 if (!strcmp (exttype, "PS1_DEV_0")) { 375 status = pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname); 376 } 377 377 378 378 if (!status) { … … 400 400 401 401 // Given a FITS file pointer, read the table of object data 402 bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file, pmConfig *config)402 bool pmFPAviewReadObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 403 403 { 404 404 pmFPA *fpa = file->fpa; … … 439 439 440 440 // read in all chip-level Objects files for this FPA 441 bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, pmConfig *config)441 bool pmFPAReadObjects (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 442 442 { 443 443 for (int i = 0; i < fpa->chips->n; i++) { … … 449 449 450 450 // read in all cell-level Objects files for this chip 451 bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, pmConfig *config)451 bool pmChipReadObjects (pmChip *chip, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 452 452 { 453 453 chip->data_exists = false; … … 455 455 pmCell *cell = chip->cells->data[i]; 456 456 pmCellReadObjects (cell, view, file, config); 457 if (!cell->data_exists) continue;458 chip->data_exists = true;457 if (!cell->data_exists) continue; 458 chip->data_exists = true; 459 459 } 460 460 return true; … … 462 462 463 463 // read in all readout-level Objects files for this cell 464 bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, pmConfig *config)464 bool pmCellReadObjects (pmCell *cell, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 465 465 { 466 466 // multiple readout mode is not yet defined for CMP or CMF files … … 475 475 pmReadout *readout = cell->readouts->data[i]; 476 476 pmReadoutReadObjects (readout, view, file, config); 477 if (!readout->data_exists) {478 continue;479 }480 481 // load in the concept information for this cell482 if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) {483 //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell");484 //return false;485 psWarning("Difficulty reading concepts for cell; attempting to proceed.");486 }477 if (!readout->data_exists) { 478 continue; 479 } 480 481 // load in the concept information for this cell 482 if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) { 483 //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell"); 484 //return false; 485 psWarning("Difficulty reading concepts for cell; attempting to proceed."); 486 } 487 487 cell->data_exists = true; 488 488 } … … 491 491 492 492 // read in all readout-level Objects files for this cell 493 bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, pmConfig *config)493 bool pmReadoutReadObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config) 494 494 { 495 495 … … 500 500 switch (file->type) { 501 501 case PM_FPA_FILE_OBJ: 502 psError(PS_ERR_UNKNOWN, true, "OBJ is not supported as an input object format");503 return false;502 psError(PS_ERR_UNKNOWN, true, "OBJ is not supported as an input object format"); 503 return false; 504 504 505 505 case PM_FPA_FILE_SX: 506 psError(PS_ERR_UNKNOWN, true, "SX is not supported as an input object format");507 return false;506 psError(PS_ERR_UNKNOWN, true, "SX is not supported as an input object format"); 507 return false; 508 508 509 509 case PM_FPA_FILE_CMP: … … 530 530 psString realname = pmConfigConvertFilename (file->filename, config, create); 531 531 532 // read the PHU from this file 532 // read the PHU from this file 533 533 file->fits = psFitsOpen (realname, "r"); 534 534 if (hdu->header != NULL) { … … 549 549 // lookup the EXTNAME values used for table data and image header segments 550 550 char *rule = NULL; 551 // Menu of EXTNAME rules551 // Menu of EXTNAME rules 552 552 psMetadata *menu = psMetadataLookupMetadata(&status, file->camera, "EXTNAME.RULES"); 553 if (!menu) {554 psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config");555 return false;556 }557 // EXTNAME for image header558 rule = psMetadataLookupStr(&status, menu, "CMF.HEAD");559 if (!rule) {560 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config");561 return false;562 }553 if (!menu) { 554 psError(PS_ERR_UNKNOWN, true, "missing EXTNAME.RULES in camera.config"); 555 return false; 556 } 557 // EXTNAME for image header 558 rule = psMetadataLookupStr(&status, menu, "CMF.HEAD"); 559 if (!rule) { 560 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.HEAD in EXTNAME.RULES in camera.config"); 561 return false; 562 } 563 563 char *headname = pmFPAfileNameFromRule (rule, file, view); 564 // EXTNAME for table data564 // EXTNAME for table data 565 565 rule = psMetadataLookupStr(&status, menu, "CMF.DATA"); 566 if (!rule) {567 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config");568 return false;569 }566 if (!rule) { 567 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.DATA in EXTNAME.RULES in camera.config"); 568 return false; 569 } 570 570 char *dataname = pmFPAfileNameFromRule (rule, file, view); 571 571 572 // advance to the IMAGE HEADER extension572 // advance to the IMAGE HEADER extension 573 573 if (hdu->header == NULL) { 574 // if the IMAGE header does not exist, we have no data for this view574 // if the IMAGE header does not exist, we have no data for this view 575 575 if (!psFitsMoveExtName (file->fits, headname)) { 576 readout->data_exists = false;577 psFree (headname);578 psFree (dataname);579 return true;580 }576 readout->data_exists = false; 577 psFree (headname); 578 psFree (dataname); 579 return true; 580 } 581 581 hdu->header = psFitsReadHeader (NULL, file->fits); 582 582 } … … 587 587 if (extdata) { 588 588 // if EXTDATA is defined in the header, use that value for 'dataname' 589 psFree (dataname);590 dataname = psMemIncrRefCounter (extdata);591 } 592 593 // advance to the table data extension594 // since we have read the IMAGE header, the TABLE header should exist589 psFree (dataname); 590 dataname = psMemIncrRefCounter (extdata); 591 } 592 593 // advance to the table data extension 594 // since we have read the IMAGE header, the TABLE header should exist 595 595 if (!psFitsMoveExtName (file->fits, dataname)) { 596 596 psAbort("cannot find data extension %s in %s", dataname, file->filename); 597 597 } 598 598 599 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header600 if (!tableHeader) psAbort("cannot read table header");599 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 600 if (!tableHeader) psAbort("cannot read table header"); 601 601 602 602 char *exttype = psMetadataLookupStr (NULL, tableHeader, "EXTTYPE"); 603 if (!exttype) psAbort("cannot read table type");604 605 // XXX these are case-sensitive since the EXTYPE is case-sensitive606 if (!strcmp (exttype, "SMPDATA")) {607 sources = pmSourcesRead_SMPDATA (file->fits, hdu->header);608 }609 if (!strcmp (exttype, "PS1_DEV_0")) {610 sources = pmSourcesRead_PS1_DEV_0 (file->fits, hdu->header);611 }603 if (!exttype) psAbort("cannot read table type"); 604 605 // XXX these are case-sensitive since the EXTYPE is case-sensitive 606 if (!strcmp (exttype, "SMPDATA")) { 607 sources = pmSourcesRead_SMPDATA (file->fits, hdu->header); 608 } 609 if (!strcmp (exttype, "PS1_DEV_0")) { 610 sources = pmSourcesRead_PS1_DEV_0 (file->fits, hdu->header); 611 } 612 612 613 613 psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname); 614 psFree (headname);614 psFree (headname); 615 615 psFree (dataname); 616 psFree (tableHeader);616 psFree (tableHeader); 617 617 break; 618 618
Note:
See TracChangeset
for help on using the changeset viewer.
