- Timestamp:
- Apr 21, 2014, 5:42:34 AM (12 years ago)
- Location:
- branches/eam_branches/ps2-tc3-20130727
- Files:
-
- 4 edited
-
. (modified) (1 prop)
-
psModules (modified) (1 prop)
-
psModules/src/objects (modified) (1 prop)
-
psModules/src/objects/pmSourceIO.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ps2-tc3-20130727
- Property svn:mergeinfo changed
-
branches/eam_branches/ps2-tc3-20130727/psModules
- Property svn:mergeinfo deleted
-
branches/eam_branches/ps2-tc3-20130727/psModules/src/objects
- Property svn:ignore
-
old new 12 12 pmSourceIO_CMF_PS1_V1.v1.c 13 13 pmSourceIO_CMF_PS1_V4.c 14 pmSourceIO_CMF_PS1_V5.c 14 15 pmSourceIO_CMF_PS1_SV1.c 15 16 pmSourceIO_CMF_PS1_SV2.c
-
- Property svn:ignore
-
branches/eam_branches/ps2-tc3-20130727/psModules/src/objects/pmSourceIO.c
r35610 r36680 47 47 #include "pmSourceDiffStats.h" 48 48 #include "pmSourceSatstar.h" 49 #include "pmSourceLensing.h" 49 50 #include "pmSource.h" 50 51 #include "pmSourceFitModel.h" … … 61 62 static bool pmReadoutReadXFIT(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 62 63 static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 64 static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 63 65 64 66 // lookup the EXTNAME values used for table data and image header segments … … 69 71 psString *xfitname, // Extension name for extended fitted measurements 70 72 psString *xradname, // Extension name for radial apertures 73 psString *xgalname, // Extension name for galaxy shapes 71 74 const pmFPAfile *file, // File of interest 72 75 const pmFPAview *view // View to level of interest … … 140 143 } 141 144 *xradname = pmFPAfileNameFromRule (rule, file, view); 145 } 146 147 // EXTNAME for radial apertures 148 if (xgalname) { 149 const char *rule = psMetadataLookupStr(&status, menu, "CMF.XGAL"); 150 if (!rule) { 151 psError(PS_ERR_UNKNOWN, true, "missing entry for CMF.XGAL in EXTNAME.RULES in camera.config"); 152 return false; 153 } 154 *xgalname = pmFPAfileNameFromRule (rule, file, view); 142 155 } 143 156 … … 362 375 status &= pmSourcesWrite_##TYPE##_XRAD (file->fits, readout, sources, file->header, xradname, recipe); \ 363 376 } \ 377 if (xgalname) { \ 378 status &= pmSourcesWrite_##TYPE##_XGAL (file->fits, readout, sources, xgalname, recipe); \ 379 } \ 364 380 } 365 381 … … 464 480 } 465 481 466 // if this is not TRUE, the output files only contain the psf measurements. 467 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 482 // if none of these are TRUE, the output files only contain the psf measurements. 483 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 484 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 485 bool XSRC_OUTPUT = doPetrosian || doAnnuli; 468 486 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 469 487 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 488 bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES"); 470 489 471 490 // define the EXTNAME values for the different data segments: … … 476 495 psString xfitname = NULL; 477 496 psString xradname = NULL; 497 psString xgalname = NULL; 478 498 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 479 499 XSRC_OUTPUT ? &xsrcname : NULL, 480 500 XFIT_OUTPUT ? &xfitname : NULL, 481 501 XRAD_OUTPUT ? &xradname : NULL, 502 XGAL_OUTPUT ? &xgalname : NULL, 482 503 file, view)) { 483 504 return false; … … 563 584 psMetadataAddStr (outhead, PS_LIST_TAIL, "XRADNAME", PS_META_REPLACE, "name of XRAD table extension", xradname); 564 585 } 586 if (xgalname) { 587 psMetadataAddStr (outhead, PS_LIST_TAIL, "XGALNAME", PS_META_REPLACE, "name of XGAL table extension", xgalname); 588 } 565 589 566 590 // these are case-sensitive since the EXTYPE is case-sensitive … … 574 598 PM_SOURCES_WRITE("PS1_V3", CMF_PS1_V3); 575 599 PM_SOURCES_WRITE("PS1_V4", CMF_PS1_V4); 600 PM_SOURCES_WRITE("PS1_V5", CMF_PS1_V5); 576 601 PM_SOURCES_WRITE("PS1_SV1", CMF_PS1_SV1); 577 602 PM_SOURCES_WRITE("PS1_SV2", CMF_PS1_SV2); … … 609 634 psFree (xfitname); 610 635 psFree (xradname); 636 psFree (xgalname); 611 637 psFree (deteffname); 612 638 … … 620 646 psFree (xfitname); 621 647 psFree (xradname); 648 psFree (xgalname); 622 649 psFree (deteffname); 623 650 return false; 624 651 652 case PM_FPA_FILE_CFF: { 653 // determine the output table format 654 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 655 if (!status) { 656 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 657 return false; 658 } 659 660 hdu = pmFPAviewThisHDU (view, fpa); 661 pmConfigConformHeader(hdu->header, file->format); 662 psFitsWriteBlank (file->fits, hdu->header, NULL); 663 file->header = hdu->header; 664 file->wrote_phu = true; 665 if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) { 666 psError(PS_ERR_UNKNOWN, false, "failed to write CFF"); 667 return false; 668 } 669 break; 670 } 671 625 672 default: 626 673 fprintf (stderr, "warning: type mismatch\n"); … … 914 961 psArray *sources = NULL; 915 962 pmHDU *hdu; 963 964 // define the EXTNAME values for the different data segments: 965 psString headname = NULL; 966 psString dataname = NULL; 967 psString deteffname = NULL; 968 psString xsrcname = NULL; 969 psString xfitname = NULL; 970 psString xradname = NULL; 971 psString xgalname = NULL; 972 973 psMetadata *tableHeader = NULL; 974 char *xtension = NULL; 916 975 917 976 switch (file->type) { … … 963 1022 hdu = pmFPAviewThisHDU (view, file->fpa); 964 1023 965 // define the EXTNAME values for the different data segments:966 psString headname = NULL;967 psString dataname = NULL;968 psString deteffname = NULL;969 psString xsrcname = NULL;970 psString xfitname = NULL;971 psString xradname = NULL;972 973 1024 // determine the output table format. Assume if we need to output extendend source 974 1025 // parameters that they may exist in the input. … … 981 1032 } 982 1033 983 // if this is not TRUE, the output files only contain the psf measurements. 984 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 1034 // if none of these are TRUE, we only read the psf measurements 1035 // XXX: shouldn't we look for these extensions and read the regardless of the recipe values? 1036 bool doPetrosian = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_PETROSIAN"); 1037 bool doAnnuli = psMetadataLookupBool (&status, recipe, "EXTENDED_SOURCE_ANNULI"); 1038 bool XSRC_OUTPUT = doPetrosian || doAnnuli; 985 1039 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 986 1040 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 1041 bool XGAL_OUTPUT = psMetadataLookupBool(&status, recipe, "GALAXY_SHAPES"); 987 1042 988 1043 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, … … 990 1045 XFIT_OUTPUT ? &xfitname : NULL, 991 1046 XRAD_OUTPUT ? &xradname : NULL, 1047 XGAL_OUTPUT ? &xgalname : NULL, 992 1048 file, view)) { 993 1049 return false; … … 1033 1089 } 1034 1090 1035 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header1091 tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1036 1092 if (!tableHeader) psAbort("cannot read table header"); 1037 1093 1038 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");1094 xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1039 1095 if (!xtension) psAbort("cannot read table type"); 1040 1096 if (strcmp (xtension, "BINTABLE")) { … … 1062 1118 PM_SOURCES_READ_PSF("PS1_V3", CMF_PS1_V3); 1063 1119 PM_SOURCES_READ_PSF("PS1_V4", CMF_PS1_V4); 1120 PM_SOURCES_READ_PSF("PS1_V5", CMF_PS1_V5); 1064 1121 PM_SOURCES_READ_PSF("PS1_SV1", CMF_PS1_SV1); 1065 1122 PM_SOURCES_READ_PSF("PS1_SV2", CMF_PS1_SV2); … … 1069 1126 1070 1127 long *sourceIndex = NULL; 1071 if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) { 1128 if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT || XGAL_OUTPUT) { 1129 // Build sourceIndex. Lookup table from source->seq to index in sources array. 1130 // Consists of an array of length max(source->seq) + 1. 1131 1132 // find maximum sequence number 1072 1133 long seq_max = -1; 1073 1134 for (long i = sources->n -1; i >= 0; i--) { … … 1082 1143 } 1083 1144 } 1145 // allocate and initialize the index 1084 1146 sourceIndex = psAlloc((seq_max + 1) * sizeof(long)); 1085 1147 for (long i = 0; i < seq_max; i++) { 1086 1148 sourceIndex[i] = -1; 1087 1149 } 1150 // populate the index 1088 1151 for (long i = 0; i < sources->n; i++) { 1089 1152 pmSource *source = sources->data[i]; … … 1112 1175 psFree(xradname); 1113 1176 } 1177 if (XGAL_OUTPUT && xgalname) { 1178 // a cmf file may have an XGAL extension, but it is not required 1179 if (!pmReadoutReadXGAL(file, readout, exttype, hdu->header, xgalname, sources, sourceIndex)) { 1180 // do anything? 1181 } 1182 psFree(xgalname); 1183 } 1114 1184 psFree(sourceIndex); 1115 1185 … … 1132 1202 break; 1133 1203 1204 case PM_FPA_FILE_CFF: 1205 // read in header, if not yet loaded 1206 hdu = pmFPAviewThisHDU (view, file->fpa); 1207 1208 // look these up in the camera config? 1209 // headrule = {CHIP.NAME}.hdr 1210 // datarule = {CHIP.NAME}.cff 1211 1212 // define the EXTNAME values for the different data segments: 1213 headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view); 1214 dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view); 1215 1216 // advance to the IMAGE HEADER extension 1217 if (hdu->header == NULL) { 1218 // if the IMAGE header does not exist, we have no data for this view 1219 if (!psFitsMoveExtNameClean (file->fits, headname)) { 1220 readout->data_exists = false; 1221 psFree (headname); 1222 psFree (dataname); 1223 return true; 1224 } 1225 hdu->header = psFitsReadHeader (NULL, file->fits); 1226 } 1227 1228 // advance to the table data extension 1229 // since we have read the IMAGE header, the TABLE header should exist 1230 if (!psFitsMoveExtName (file->fits, dataname)) { 1231 psAbort("cannot find data extension %s in %s", dataname, file->filename); 1232 } 1233 1234 tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1235 if (!tableHeader) psAbort("cannot read table header"); 1236 1237 // verify this is a binary table 1238 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1239 if (!xtension) psAbort("cannot read table type"); 1240 if (strcmp (xtension, "BINTABLE")) { 1241 psWarning ("no binary table in extension %s, skipping\n", dataname); 1242 psFree(tableHeader); 1243 return false; 1244 } 1245 1246 sources = pmSourcesRead_CFF(file->fits, hdu->header); 1247 1248 psTrace("psModules.objects", 6, "read CMF table from %s : %s : %s", file->filename, headname, dataname); 1249 psFree (headname); 1250 psFree (dataname); 1251 psFree (tableHeader); 1252 break; 1253 1134 1254 default: 1135 1255 fprintf (stderr, "warning: type mismatch\n"); … … 1272 1392 PM_SOURCES_READ_XSRC("PS1_V3", CMF_PS1_V3); 1273 1393 PM_SOURCES_READ_XSRC("PS1_V4", CMF_PS1_V4); 1394 PM_SOURCES_READ_XSRC("PS1_V5", CMF_PS1_V5); 1274 1395 PM_SOURCES_READ_XSRC("PS1_SV1", CMF_PS1_SV1); 1275 1396 PM_SOURCES_READ_XSRC("PS1_SV2", CMF_PS1_SV2); … … 1311 1432 PM_SOURCES_READ_XFIT("PS1_V3", CMF_PS1_V3); 1312 1433 PM_SOURCES_READ_XFIT("PS1_V4", CMF_PS1_V4); 1434 PM_SOURCES_READ_XFIT("PS1_V5", CMF_PS1_V5); 1313 1435 PM_SOURCES_READ_XFIT("PS1_SV1", CMF_PS1_SV1); 1314 1436 PM_SOURCES_READ_XFIT("PS1_SV2", CMF_PS1_SV2); … … 1349 1471 PM_SOURCES_READ_XRAD("PS1_V3", CMF_PS1_V3); 1350 1472 PM_SOURCES_READ_XRAD("PS1_V4", CMF_PS1_V4); 1473 PM_SOURCES_READ_XRAD("PS1_V5", CMF_PS1_V5); 1351 1474 PM_SOURCES_READ_XRAD("PS1_SV1", CMF_PS1_SV1); 1352 1475 PM_SOURCES_READ_XRAD("PS1_SV2", CMF_PS1_SV2); … … 1358 1481 return status; 1359 1482 } 1483 static bool pmReadoutReadXGAL(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString xgalname, psArray *sources, long *sourceIndex) 1484 { 1485 if (!psFitsMoveExtNameClean (file->fits, xgalname)) { 1486 psTrace ("pmFPAfile", 1, "cannot find xgal extension %s in %s, skipping", xgalname, file->filename); 1487 return false; 1488 } 1489 1490 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1491 if (!tableHeader) psAbort("cannot read table header"); 1492 1493 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1494 if (!xtension) psAbort("cannot read table type"); 1495 if (strcmp (xtension, "BINTABLE")) { 1496 psFree(tableHeader); 1497 psWarning ("no binary table in extension %s, skipping\n", xgalname); 1498 return false; 1499 } 1500 1501 # define PM_SOURCES_READ_XGAL(NAME,TYPE) \ 1502 if (!strcmp (exttype, NAME)) { \ 1503 status = pmSourcesRead_##TYPE##_XGAL(file->fits, readout, hduHeader, tableHeader, sources, sourceIndex); \ 1504 } 1505 1506 bool status = false; 1507 if (file->type == PM_FPA_FILE_CMF) { 1508 PM_SOURCES_READ_XGAL("PS1_V1", CMF_PS1_V1); 1509 PM_SOURCES_READ_XGAL("PS1_V2", CMF_PS1_V2); 1510 PM_SOURCES_READ_XGAL("PS1_V3", CMF_PS1_V3); 1511 PM_SOURCES_READ_XGAL("PS1_V4", CMF_PS1_V4); 1512 PM_SOURCES_READ_XGAL("PS1_V5", CMF_PS1_V5); 1513 PM_SOURCES_READ_XGAL("PS1_SV1", CMF_PS1_SV1); 1514 PM_SOURCES_READ_XGAL("PS1_SV2", CMF_PS1_SV2); 1515 PM_SOURCES_READ_XGAL("PS1_DV1", CMF_PS1_DV1); 1516 PM_SOURCES_READ_XGAL("PS1_DV2", CMF_PS1_DV2); 1517 PM_SOURCES_READ_XGAL("PS1_DV3", CMF_PS1_DV3); 1518 } 1519 psFree(tableHeader); 1520 return status; 1521 }
Note:
See TracChangeset
for help on using the changeset viewer.
