- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psModules/src/objects/pmSourceIO.c
r25754 r27838 40 40 #include "pmPSF.h" 41 41 #include "pmModel.h" 42 #include "pmDetections.h" 42 43 #include "pmSource.h" 43 44 #include "pmModelClass.h" … … 342 343 pmHDU *hdu; 343 344 psMetadata *updates; 344 psMetadata *outhead;345 346 char *exttype = NULL;347 345 348 346 // if sources is NULL, write out an empty table 349 // input / output sources are stored on the readout->analysis as "PSPHOT.SOURCES" -- a better name might be something like PM_SOURCE_DATA 350 psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); 347 // input / output sources are stored on the readout->analysis as "PSPHOT.DETECTIONS" 348 349 psArray *sources = NULL; 350 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 351 if (detections) { 352 sources = detections->allSources; 353 } 351 354 if (!sources) { 355 detections = pmDetectionsAlloc(); 352 356 sources = psArrayAlloc(0); 353 psMetadataAddArray(readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_META_REPLACE, "Blank array of sources", sources); 354 psFree(sources); // Held onto by the metadata, so we can continue to use 357 detections->allSources = sources; 358 psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_UNKNOWN | PS_META_REPLACE, "Blank array of sources", detections); 359 psFree(detections); // Held onto by the metadata, so we can continue to use 355 360 } 356 361 … … 368 373 break; 369 374 370 case PM_FPA_FILE_CMP: 371 // a SPLIT format : only one header and object table per file 372 hdu = pmFPAviewThisHDU (view, fpa); 373 if (!hdu) { 374 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources."); 375 return false; 376 } 377 378 // copy the header to an output header, add the output header data 379 outhead = psMetadataCopy (NULL, hdu->header); 380 381 // copy over the entries saved by PSPHOT 382 updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER"); 383 if (updates) { 384 psMetadataCopy (outhead, updates); 385 } 386 387 // copy over the entries saved by PSASTRO 388 updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER"); 389 if (updates) { 390 psMetadataCopy (outhead, updates); 391 } 392 393 bool status = pmSourcesWriteCMP (sources, file->filename, outhead); 394 psFree (outhead); 395 396 if (!status) { 397 psError(PS_ERR_IO, false, "Failed to write CMP file\n"); 398 return false; 399 } 400 break; 401 402 case PM_FPA_FILE_CMF: 375 case PM_FPA_FILE_CMP: { 376 // a SPLIT format : only one header and object table per file 377 hdu = pmFPAviewThisHDU (view, fpa); 378 if (!hdu) { 379 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources."); 380 return false; 381 } 382 383 // copy the header to an output header, add the output header data 384 psMetadata *outhead = psMetadataCopy (NULL, hdu->header); 385 386 // copy over the entries saved by PSPHOT 387 updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER"); 388 if (updates) { 389 psMetadataCopy (outhead, updates); 390 } 391 392 // copy over the entries saved by PSASTRO 393 updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER"); 394 if (updates) { 395 psMetadataCopy (outhead, updates); 396 } 397 398 bool status = pmSourcesWriteCMP (sources, file->filename, outhead); 399 psFree (outhead); 400 401 if (!status) { 402 psError(PS_ERR_IO, false, "Failed to write CMP file\n"); 403 return false; 404 } 405 break; 406 } 407 408 case PM_FPA_FILE_CMF: 403 409 // write a header? (only if this is the first readout for cell) 404 410 // note that the file->header is set to track the last hdu->header written … … 415 421 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 416 422 if (!status) { 417 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");418 return false;423 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 424 return false; 419 425 } 420 426 … … 429 435 psString xsrcname = NULL; 430 436 psString xfitname = NULL; 431 if (!sourceExtensions(&headname, &dataname, &deteffname, XSRC_OUTPUT ? &xsrcname : NULL, 432 XFIT_OUTPUT ? &xfitname : NULL, file, view)) { 437 if (!sourceExtensions(&headname, &dataname, &deteffname, 438 XSRC_OUTPUT ? &xsrcname : NULL, 439 XFIT_OUTPUT ? &xfitname : NULL, 440 file, view)) { 433 441 return false; 434 442 } … … 489 497 } 490 498 491 // write out the TABLE data segment499 // write out the Object TABLE data segment(s) 492 500 { 493 501 // create a header to hold the output data 494 outhead = psMetadataAlloc ();495 496 exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));502 psMetadata *outhead = psMetadataAlloc (); 503 504 char *exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT")); 497 505 if (!exttype) { 498 506 exttype = psStringCopy ("SMPDATA"); … … 502 510 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname); 503 511 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype); 504 psFree (exttype);505 512 506 513 // if we request XSRC output, add the XSRC name to this header 507 514 if (xsrcname) { 508 psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);515 psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname); 509 516 } 510 517 if (xfitname) { 511 psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);518 psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname); 512 519 } 513 520 … … 532 539 status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname); 533 540 } 534 535 if (deteffname) { 536 status &= pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname); 541 if (!strcmp (exttype, "PS1_DV1")) { 542 status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname); 537 543 } 538 544 539 545 if (xsrcname) { 540 if (!strcmp (exttype, "PS1_DEV_1")) { 541 status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe); 542 } 543 if (!strcmp (exttype, "PS1_CAL_0")) { 544 status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 545 } 546 if (!strcmp (exttype, "PS1_V1")) { 547 status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, sources, xsrcname, recipe); 548 } 549 if (!strcmp (exttype, "PS1_V2")) { 550 status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, xsrcname, recipe); 551 } 546 if (!strcmp (exttype, "PS1_DEV_1")) { 547 status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe); 548 } 549 if (!strcmp (exttype, "PS1_CAL_0")) { 550 status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 551 } 552 if (!strcmp (exttype, "PS1_V1")) { 553 status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 554 } 555 if (!strcmp (exttype, "PS1_V2")) { 556 status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 557 } 558 if (!strcmp (exttype, "PS1_DV1")) { 559 status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe); 560 } 552 561 } 553 562 if (xfitname) { 554 if (!strcmp (exttype, "PS1_DEV_1")) { 555 status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname); 556 } 557 if (!strcmp (exttype, "PS1_CAL_0")) { 558 status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname); 559 } 560 if (!strcmp (exttype, "PS1_V1")) { 561 status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, sources, xfitname); 562 } 563 if (!strcmp (exttype, "PS1_V2")) { 564 status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, xfitname); 565 } 566 } 563 if (!strcmp (exttype, "PS1_DEV_1")) { 564 status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname); 565 } 566 if (!strcmp (exttype, "PS1_CAL_0")) { 567 status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname); 568 } 569 if (!strcmp (exttype, "PS1_V1")) { 570 status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, readout, sources, xfitname); 571 } 572 if (!strcmp (exttype, "PS1_V2")) { 573 status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, readout, sources, xfitname); 574 } 575 if (!strcmp (exttype, "PS1_DV1")) { 576 status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, readout, sources, xfitname); 577 } 578 } 579 psFree (outhead); 580 psFree (exttype); 581 567 582 if (!status) { 568 583 psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype); 569 psFree (headname); 570 psFree (dataname); 571 psFree (xsrcname); 572 psFree (xfitname); 573 psFree (outhead); 574 psFree (deteffname); 575 return false; 576 } 577 } 584 goto escape; 585 } 586 } 587 588 589 // write out the detection efficiency TABLE segments 590 if (deteffname) { 591 // create a header to hold the output data 592 psMetadata *outhead = psMetadataAlloc (); 593 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname); 594 psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "DETEFF"); 595 596 status = pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname); 597 psFree (outhead); 598 599 if (!status) { 600 psError(PS_ERR_IO, false, "writing DETEFF data to %s\n", file->filename); 601 goto escape; 602 } 603 } 604 psFree (headname); 605 psFree (dataname); 606 psFree (xsrcname); 607 psFree (xfitname); 608 psFree (deteffname); 578 609 579 610 psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type); 580 581 psFree (headname); 582 psFree (dataname); 583 psFree (xsrcname); 584 psFree (xfitname); 585 psFree (outhead); 611 break; 612 613 escape: 614 psFree (headname); 615 psFree (dataname); 616 psFree (xsrcname); 617 psFree (xfitname); 586 618 psFree (deteffname); 587 break;619 return false; 588 620 589 621 default: … … 592 624 } 593 625 return true; 626 594 627 } 595 628 // a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE... … … 936 969 if (hdu->header == NULL) { 937 970 // if the IMAGE header does not exist, we have no data for this view 938 if (!psFitsMoveExtName (file->fits, headname)) {971 if (!psFitsMoveExtNameClean (file->fits, headname)) { 939 972 readout->data_exists = false; 940 973 psFree (headname); … … 964 997 if (!tableHeader) psAbort("cannot read table header"); 965 998 999 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1000 if (!xtension) psAbort("cannot read table type"); 1001 if (strcmp (xtension, "BINTABLE")) { 1002 psWarning ("no binary table in extension %s, skipping\n", dataname); 1003 return false; 1004 } 1005 966 1006 char *exttype = psMetadataLookupStr (NULL, tableHeader, "EXTTYPE"); 967 1007 if (!exttype) psAbort("cannot read table type"); … … 983 1023 if (!strcmp (exttype, "PS1_V2")) { 984 1024 sources = pmSourcesRead_CMF_PS1_V2 (file->fits, hdu->header); 1025 } 1026 if (!strcmp (exttype, "PS1_DV1")) { 1027 sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header); 985 1028 } 986 1029 … … 1008 1051 } 1009 1052 readout->data_exists = true; 1010 status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "input sources", sources); 1011 psFree (sources); 1053 1054 pmDetections *detections = pmDetectionsAlloc(); 1055 detections->allSources = sources; 1056 status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "input sources", detections); 1057 psFree (detections); 1012 1058 return true; 1013 1059 } … … 1101 1147 bool status; 1102 1148 1103 // select the psf of interest 1104 pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES"); 1105 if (!psf) return false; 1106 return true; 1107 } 1108 1109 1149 // select the detections of interest 1150 pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS"); 1151 if (!detections) return false; 1152 if (!detections->allSources) return false; 1153 return true; 1154 } 1155 1156
Note:
See TracChangeset
for help on using the changeset viewer.
