- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourceIO.c
r32633 r33638 57 57 #define BLANK_HEADERS "BLANK.HEADERS" // Name of metadata in camera configuration containing header names 58 58 // for putting values into a blank PHU 59 static bool pmReadoutReadXSRC(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex); 60 static bool pmReadoutReadXFIT(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 61 static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex); 59 62 60 63 // lookup the EXTNAME values used for table data and image header segments … … 961 964 psString dataname = NULL; 962 965 psString deteffname = NULL; 963 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, NULL, NULL, NULL, file, view)) { 966 psString xsrcname = NULL; 967 psString xfitname = NULL; 968 psString xradname = NULL; 969 970 // determine the output table format. Assume if we need to output extendend source 971 // parameters that they may exist in the input. 972 // XXX: Perhaps we should use different recipe values. 973 // I.E. EXTENDED_SOURCE_ANALYSIS_READ or something like that 974 psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT"); 975 if (!status) { 976 psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data"); 977 return false; 978 } 979 // if this is not TRUE, the output files only contain the psf measurements. 980 bool XSRC_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_ANALYSIS"); 981 bool XFIT_OUTPUT = psMetadataLookupBool(&status, recipe, "EXTENDED_SOURCE_FITS"); 982 bool XRAD_OUTPUT = psMetadataLookupBool(&status, recipe, "RADIAL_APERTURES"); 983 984 if (!pmSourceIOextnames(&headname, &dataname, &deteffname, 985 XSRC_OUTPUT ? &xsrcname : NULL, 986 XFIT_OUTPUT ? &xfitname : NULL, 987 XRAD_OUTPUT ? &xradname : NULL, 988 file, view)) { 964 989 return false; 965 990 } … … 1039 1064 } 1040 1065 1066 long *sourceIndex = NULL; 1067 if (XSRC_OUTPUT || XFIT_OUTPUT || XRAD_OUTPUT) { 1068 long seq_max = -1; 1069 for (long i = sources->n -1; i >= 0; i--) { 1070 pmSource *source = sources->data[i]; 1071 if (source->seq < 0) { 1072 // This can happen cmf files that have been corrupted 1073 psError(PS_ERR_IO, true, "seq < 0 for source %ld: Suspect %s is corrupt", i, file->origname); 1074 return false; 1075 } 1076 if (source->seq > seq_max) { 1077 seq_max = source->seq; 1078 } 1079 } 1080 sourceIndex = psAlloc((seq_max + 1) * sizeof(long)); 1081 for (long i = 0; i < seq_max; i++) { 1082 sourceIndex[i] = -1; 1083 } 1084 for (long i = 0; i < sources->n; i++) { 1085 pmSource *source = sources->data[i]; 1086 sourceIndex[source->seq] = i; 1087 } 1088 } 1089 if (XSRC_OUTPUT && xsrcname) { 1090 if (!pmReadoutReadXSRC(file, exttype, hdu->header, xsrcname, sources, sourceIndex)) { 1091 // XXX: is this an error? 1092 psErrorClear(); 1093 } 1094 psFree(xsrcname); 1095 } 1096 if (XFIT_OUTPUT && xfitname) { 1097 if (!pmReadoutReadXFIT(file, exttype, hdu->header, xfitname, sources, sourceIndex)) { 1098 // XXX: is this an error? 1099 psErrorClear(); 1100 } 1101 psFree(xfitname); 1102 } 1103 if (XRAD_OUTPUT && xradname) { 1104 if (!pmReadoutReadXRAD(file, readout, exttype, hdu->header, xradname, sources, sourceIndex)) { 1105 // XXX: is this an error? 1106 psErrorClear(); 1107 } 1108 psFree(xradname); 1109 } 1110 psFree(sourceIndex); 1111 1041 1112 if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) { 1042 1113 #if 0 … … 1165 1236 } 1166 1237 1167 1238 // XXX: We might be able to macroize this and reuse for the other types 1239 1240 static bool pmReadoutReadXSRC(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex) 1241 { 1242 if (!psFitsMoveExtName (file->fits, xsrcname)) { 1243 psError(PS_ERR_UNKNOWN, false, "cannot find xsrc extension %s in %s", xsrcname, file->filename); 1244 return false; 1245 } 1246 1247 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1248 if (!tableHeader) psAbort("cannot read table header"); 1249 1250 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1251 if (!xtension) psAbort("cannot read table type"); 1252 if (strcmp (xtension, "BINTABLE")) { 1253 psWarning ("no binary table in extension %s, skipping\n", xsrcname); 1254 return false; 1255 } 1256 1257 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1258 bool status = false; 1259 if (file->type == PM_FPA_FILE_CMF) { 1260 if (!strcmp (exttype, "PS1_SV1")) { 1261 status = pmSourcesRead_CMF_PS1_SV1_XSRC (file->fits, hduHeader, sources, sourceIndex); 1262 } 1263 } 1264 psFree(tableHeader); 1265 return status; 1266 } 1267 1268 static bool pmReadoutReadXFIT(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex) 1269 { 1270 if (!psFitsMoveExtName (file->fits, extname)) { 1271 psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename); 1272 return false; 1273 } 1274 1275 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1276 if (!tableHeader) psAbort("cannot read table header"); 1277 1278 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1279 if (!xtension) psAbort("cannot read table type"); 1280 if (strcmp (xtension, "BINTABLE")) { 1281 psWarning ("no binary table in extension %s, skipping\n", extname); 1282 return false; 1283 } 1284 1285 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1286 bool status = false; 1287 if (file->type == PM_FPA_FILE_CMF) { 1288 if (!strcmp (exttype, "PS1_SV1")) { 1289 status = pmSourcesRead_CMF_PS1_SV1_XFIT (file->fits, hduHeader, sources, sourceIndex); 1290 } 1291 } 1292 psFree(tableHeader); 1293 return status; 1294 } 1295 static bool pmReadoutReadXRAD(pmFPAfile *file, pmReadout *readout, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex) 1296 { 1297 if (!psFitsMoveExtName (file->fits, extname)) { 1298 psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename); 1299 return false; 1300 } 1301 1302 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1303 if (!tableHeader) psAbort("cannot read table header"); 1304 1305 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1306 if (!xtension) psAbort("cannot read table type"); 1307 if (strcmp (xtension, "BINTABLE")) { 1308 psWarning ("no binary table in extension %s, skipping\n", extname); 1309 return false; 1310 } 1311 1312 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1313 bool status = false; 1314 if (file->type == PM_FPA_FILE_CMF) { 1315 if (!strcmp (exttype, "PS1_SV1")) { 1316 status = pmSourcesRead_CMF_PS1_SV1_XRAD (file->fits, readout, hduHeader, sources, sourceIndex); 1317 } 1318 } 1319 psFree(tableHeader); 1320 return status; 1321 }
Note:
See TracChangeset
for help on using the changeset viewer.
