Changeset 32971
- Timestamp:
- Dec 19, 2011, 1:22:04 PM (14 years ago)
- Location:
- trunk/psModules/src/objects
- Files:
-
- 3 edited
-
pmSourceIO.c (modified) (4 diffs)
-
pmSourceIO.h (modified) (1 diff)
-
pmSourceIO_CMF_PS1_SV1.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/objects/pmSourceIO.c
r32633 r32971 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, 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 > seq_max) { 1072 seq_max = source->seq; 1073 } 1074 } 1075 sourceIndex = psAlloc((seq_max + 1) * sizeof(long)); 1076 for (long i = 0; i < seq_max; i++) { 1077 sourceIndex[i] = -1; 1078 } 1079 for (long i = 0; i < sources->n; i++) { 1080 pmSource *source = sources->data[i]; 1081 sourceIndex[source->seq] = i; 1082 } 1083 } 1084 if (XSRC_OUTPUT && xsrcname) { 1085 if (!pmReadoutReadXSRC(file, exttype, hdu->header, xsrcname, sources, sourceIndex)) { 1086 // XXX: is this an error? 1087 psErrorClear(); 1088 } 1089 psFree(xsrcname); 1090 } 1091 if (XFIT_OUTPUT && xfitname) { 1092 if (!pmReadoutReadXFIT(file, exttype, hdu->header, xfitname, sources, sourceIndex)) { 1093 // XXX: is this an error? 1094 psErrorClear(); 1095 } 1096 psFree(xfitname); 1097 } 1098 if (XRAD_OUTPUT && xradname) { 1099 if (!pmReadoutReadXRAD(file, exttype, hdu->header, xradname, sources, sourceIndex)) { 1100 // XXX: is this an error? 1101 psErrorClear(); 1102 } 1103 psFree(xradname); 1104 } 1105 psFree(sourceIndex); 1106 1041 1107 if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) { 1042 1108 #if 0 … … 1165 1231 } 1166 1232 1167 1233 // XXX: We might be able to macroize this and reuse for the other types 1234 1235 static bool pmReadoutReadXSRC(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex) 1236 { 1237 if (!psFitsMoveExtName (file->fits, xsrcname)) { 1238 psError(PS_ERR_UNKNOWN, false, "cannot find xsrc extension %s in %s", xsrcname, file->filename); 1239 return false; 1240 } 1241 1242 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1243 if (!tableHeader) psAbort("cannot read table header"); 1244 1245 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1246 if (!xtension) psAbort("cannot read table type"); 1247 if (strcmp (xtension, "BINTABLE")) { 1248 psWarning ("no binary table in extension %s, skipping\n", xsrcname); 1249 return false; 1250 } 1251 1252 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1253 bool status = false; 1254 if (file->type == PM_FPA_FILE_CMF) { 1255 #ifdef notyet 1256 if (!strcmp (exttype, "SMPDATA")) { 1257 status = pmSourcesRead_SMPDATA_XSRC (file->fits, hduHeader, sources); 1258 } 1259 if (!strcmp (exttype, "PS1_DEV_0")) { 1260 status = pmSourcesRead_PS1_DEV_0_XSRC (file->fits, hduHeader, sources); 1261 } 1262 if (!strcmp (exttype, "PS1_DEV_1")) { 1263 status = pmSourcesRead_PS1_DEV_1_XSRC (file->fits, hduHeader, sources); 1264 } 1265 if (!strcmp (exttype, "PS1_V1")) { 1266 status = pmSourcesRead_CMF_PS1_V1_XSRC (file->fits, hduHeader, sources); 1267 } 1268 if (!strcmp (exttype, "PS1_V2")) { 1269 status = pmSourcesRead_CMF_PS1_V2_XSRC (file->fits, hduHeader, sources); 1270 } 1271 if (!strcmp (exttype, "PS1_V3")) { 1272 status = pmSourcesRead_CMF_PS1_V3_XSRC (file->fits, hduHeader, sources); 1273 } 1274 if (!strcmp (exttype, "PS1_V4")) { 1275 status = pmSourcesRead_CMF_PS1_V4_XSRC (file->fits, hduHeader, sources); 1276 } 1277 #endif // notyet 1278 if (!strcmp (exttype, "PS1_SV1")) { 1279 status = pmSourcesRead_CMF_PS1_SV1_XSRC (file->fits, hduHeader, sources, sourceIndex); 1280 } 1281 #ifdef notyet 1282 if (!strcmp (exttype, "PS1_DV1")) { 1283 status = pmSourcesRead_CMF_PS1_DV1_XSRC (file->fits, hduHeader, sources); 1284 } 1285 if (!strcmp (exttype, "PS1_DV2")) { 1286 status = pmSourcesRead_CMF_PS1_DV2_XSRC (file->fits, hduHeader, sources); 1287 } 1288 #endif // notyet 1289 } 1290 psFree(tableHeader); 1291 return status; 1292 } 1293 1294 static bool pmReadoutReadXFIT(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex) 1295 { 1296 if (!psFitsMoveExtName (file->fits, extname)) { 1297 psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename); 1298 return false; 1299 } 1300 1301 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1302 if (!tableHeader) psAbort("cannot read table header"); 1303 1304 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1305 if (!xtension) psAbort("cannot read table type"); 1306 if (strcmp (xtension, "BINTABLE")) { 1307 psWarning ("no binary table in extension %s, skipping\n", extname); 1308 return false; 1309 } 1310 1311 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1312 bool status = false; 1313 if (file->type == PM_FPA_FILE_CMF) { 1314 #ifdef notyet 1315 if (!strcmp (exttype, "SMPDATA")) { 1316 status = pmSourcesRead_SMPDATA_XFIT (file->fits, hduHeader, sources); 1317 } 1318 if (!strcmp (exttype, "PS1_DEV_0")) { 1319 status = pmSourcesRead_PS1_DEV_0_XFIT (file->fits, hduHeader, sources); 1320 } 1321 if (!strcmp (exttype, "PS1_DEV_1")) { 1322 status = pmSourcesRead_PS1_DEV_1_XFIT (file->fits, hduHeader, sources); 1323 } 1324 if (!strcmp (exttype, "PS1_V1")) { 1325 status = pmSourcesRead_CMF_PS1_V1_XFIT (file->fits, hduHeader, sources); 1326 } 1327 if (!strcmp (exttype, "PS1_V2")) { 1328 status = pmSourcesRead_CMF_PS1_V2_XFIT (file->fits, hduHeader, sources); 1329 } 1330 if (!strcmp (exttype, "PS1_V3")) { 1331 status = pmSourcesRead_CMF_PS1_V3_XFIT (file->fits, hduHeader, sources); 1332 } 1333 if (!strcmp (exttype, "PS1_V4")) { 1334 status = pmSourcesRead_CMF_PS1_V4_XFIT (file->fits, hduHeader, sources); 1335 } 1336 #endif // notyet 1337 if (!strcmp (exttype, "PS1_SV1")) { 1338 status = pmSourcesRead_CMF_PS1_SV1_XFIT (file->fits, hduHeader, sources, sourceIndex); 1339 } 1340 #ifdef notyet 1341 if (!strcmp (exttype, "PS1_DV1")) { 1342 status = pmSourcesRead_CMF_PS1_DV1_XFIT (file->fits, hduHeader, sources); 1343 } 1344 if (!strcmp (exttype, "PS1_DV2")) { 1345 status = pmSourcesRead_CMF_PS1_DV2_XFIT (file->fits, hduHeader, sources); 1346 } 1347 #endif // notyet 1348 } 1349 psFree(tableHeader); 1350 return status; 1351 } 1352 static bool pmReadoutReadXRAD(pmFPAfile *file, char *exttype, psMetadata *hduHeader, psString extname, psArray *sources, long *sourceIndex) 1353 { 1354 if (!psFitsMoveExtName (file->fits, extname)) { 1355 psError(PS_ERR_UNKNOWN, false, "cannot find extension %s in %s", extname, file->filename); 1356 return false; 1357 } 1358 1359 psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header 1360 if (!tableHeader) psAbort("cannot read table header"); 1361 1362 char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION"); 1363 if (!xtension) psAbort("cannot read table type"); 1364 if (strcmp (xtension, "BINTABLE")) { 1365 psWarning ("no binary table in extension %s, skipping\n", extname); 1366 return false; 1367 } 1368 1369 // XXX these are case-sensitive since the EXTYPE is case-sensitive 1370 bool status = false; 1371 if (file->type == PM_FPA_FILE_CMF) { 1372 #ifdef notyet 1373 if (!strcmp (exttype, "SMPDATA")) { 1374 status = pmSourcesRead_SMPDATA_XRAD (file->fits, hduHeader, sources); 1375 } 1376 if (!strcmp (exttype, "PS1_DEV_0")) { 1377 status = pmSourcesRead_PS1_DEV_0_XRAD (file->fits, hduHeader, sources); 1378 } 1379 if (!strcmp (exttype, "PS1_DEV_1")) { 1380 status = pmSourcesRead_PS1_DEV_1_XRAD (file->fits, hduHeader, sources); 1381 } 1382 if (!strcmp (exttype, "PS1_V1")) { 1383 status = pmSourcesRead_CMF_PS1_V1_XRAD (file->fits, hduHeader, sources); 1384 } 1385 if (!strcmp (exttype, "PS1_V2")) { 1386 status = pmSourcesRead_CMF_PS1_V2_XRAD (file->fits, hduHeader, sources); 1387 } 1388 if (!strcmp (exttype, "PS1_V3")) { 1389 status = pmSourcesRead_CMF_PS1_V3_XRAD (file->fits, hduHeader, sources); 1390 } 1391 if (!strcmp (exttype, "PS1_V4")) { 1392 status = pmSourcesRead_CMF_PS1_V4_XRAD (file->fits, hduHeader, sources); 1393 } 1394 #endif // notyet 1395 if (!strcmp (exttype, "PS1_SV1")) { 1396 status = pmSourcesRead_CMF_PS1_SV1_XRAD (file->fits, hduHeader, sources, sourceIndex); 1397 } 1398 #ifdef notyet 1399 if (!strcmp (exttype, "PS1_DV1")) { 1400 status = pmSourcesRead_CMF_PS1_DV1_XRAD (file->fits, hduHeader, sources); 1401 } 1402 if (!strcmp (exttype, "PS1_DV2")) { 1403 status = pmSourcesRead_CMF_PS1_DV2_XRAD (file->fits, hduHeader, sources); 1404 } 1405 #endif // notyet 1406 } 1407 psFree(tableHeader); 1408 return status; 1409 } -
trunk/psModules/src/objects/pmSourceIO.h
r32633 r32971 93 93 psArray *pmSourcesRead_CMF_PS1_V4 (psFits *fits, psMetadata *header); 94 94 psArray *pmSourcesRead_CMF_PS1_SV1 (psFits *fits, psMetadata *header); 95 bool pmSourcesRead_CMF_PS1_SV1_XSRC (psFits *fits, psMetadata *header, psArray *sources, long *); 96 bool pmSourcesRead_CMF_PS1_SV1_XFIT (psFits *fits, psMetadata *header, psArray *sources, long *); 97 bool pmSourcesRead_CMF_PS1_SV1_XRAD (psFits *fits, psMetadata *header, psArray *sources, long *); 95 98 psArray *pmSourcesRead_CMF_PS1_DV1 (psFits *fits, psMetadata *header); 96 99 psArray *pmSourcesRead_CMF_PS1_DV2 (psFits *fits, psMetadata *header); -
trunk/psModules/src/objects/pmSourceIO_CMF_PS1_SV1.c
r32347 r32971 539 539 } 540 540 541 bool pmSourcesRead_CMF_PS1_SV1_XSRC(psFits *fits, psMetadata *hduHeader, psArray *sources, long *sourceIndex) 542 { 543 PS_ASSERT_PTR_NON_NULL(fits, false); 544 PS_ASSERT_PTR_NON_NULL(sources, false); 545 546 bool status; 547 long numSources = psFitsTableSize(fits); // Number of sources in table 548 if (numSources == 0) { 549 psError(psErrorCodeLast(), false, "XSRC Table contains no entries\n"); 550 return false; 551 } 552 553 // petrosian mags are not saved, we need to calculate fluxes. For this we need exptime and zero point 554 float zeropt = psMetadataLookupF32(&status, hduHeader, "FPA.ZP"); 555 float exptime = psMetadataLookupF32(&status, hduHeader, "EXPTIME"); 556 float magOffset = zeropt + 2.5*log10(exptime); 557 558 for (long i = 0; i < numSources; i++) { 559 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 560 if (!row) { 561 psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i); 562 psFree(row); 563 return false; 564 } 565 // Find the source with this sequence number. 566 // XXX: I am assuming that sources is sorted in order of seq 567 long seq = psMetadataLookupU32 (&status, row, "IPP_IDET"); 568 pmSource *source = NULL; 569 #ifndef ASSUME_SORTED 570 long j = seq < sources->n ? seq : sources->n - 1; 571 for (; j >= 0; j--) { 572 source = sources->data[j]; 573 if (source->seq == seq) { 574 break; 575 } 576 } 577 #else 578 long j = sourceIndex[seq]; 579 psAssert(j >= 0 && j < sources->n, "invalid sourceIndex"); 580 source = sources->data[j]; 581 #endif 582 if (!source) { 583 psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq); 584 psFree(row); 585 return false; 586 } 587 588 if (!source->extpars) { 589 source->extpars = pmSourceExtendedParsAlloc (); 590 } 591 pmSourceExtendedPars *extpars = source->extpars; 592 593 // Assume that X_EXT Y_EXT and sigmas match the psf src so skip 594 595 // We don't have enough information to calculate the major and minor axis. Set major to 1. Should we scale this by 596 // psf size or something? 597 extpars->axes.major = 1.0; 598 extpars->axes.minor = extpars->axes.major * psMetadataLookupF32(&status, row, "F25_ARATIO"); 599 extpars->axes.theta = psMetadataLookupF32(&status, row, "F25_THETA"); 600 601 float mag = psMetadataLookupF32(&status, row, "PETRO_MAG"); 602 float magErr = psMetadataLookupF32(&status, row, "PETRO_MAG_ERR"); 603 if (isfinite(mag)) { 604 extpars->petrosianFlux = pow(10., (magOffset - mag) / 2.5); 605 if (isfinite(magErr)) { 606 extpars->petrosianFluxErr = extpars->petrosianFlux / magErr; 607 } 608 } 609 610 extpars->petrosianRadius = psMetadataLookupF32(&status, row, "PETRO_RADIUS"); 611 extpars->petrosianRadiusErr= psMetadataLookupF32(&status, row, "PETRO_RADIUS_ERR"); 612 extpars->petrosianR50 = psMetadataLookupF32(&status, row, "PETRO_RADIUS_50"); 613 extpars->petrosianR50Err = psMetadataLookupF32(&status, row, "PETRO_RADIUS_50_ERR"); 614 extpars->petrosianR90 = psMetadataLookupF32(&status, row, "PETRO_RADIUS_90"); 615 extpars->petrosianR90Err = psMetadataLookupF32(&status, row, "PETRO_RADIUS_90_ERR"); 616 extpars->petrosianFill = psMetadataLookupF32(&status, row, "PETRO_FILL"); 617 618 psVector *radSB = psMetadataLookupVector(&status, row, "PROF_SB"); 619 psVector *radFlux = psMetadataLookupVector(&status, row, "PROF_FLUX"); 620 psVector *radFill = psMetadataLookupVector(&status, row, "PROF_FILL"); 621 622 if (radSB && radSB->n > 0) { 623 extpars->radProfile = pmSourceRadialProfileAlloc(); 624 extpars->radProfile->binSB = psMemIncrRefCounter(radSB); 625 extpars->radProfile->binSum = psMemIncrRefCounter(radFlux); 626 extpars->radProfile->binFill = psMemIncrRefCounter(radFill); 627 } 628 629 psFree(row); 630 } 631 632 return true; 633 } 634 541 635 // XXX this layout is still the same as PS1_DEV_1 542 636 bool pmSourcesWrite_CMF_PS1_SV1_XFIT(psFits *fits, pmReadout *readout, psArray *sources, psMetadata *imageHeader, char *extname) … … 684 778 psFree (outhead); 685 779 psFree (table); 780 return true; 781 } 782 783 bool pmSourcesRead_CMF_PS1_SV1_XFIT(psFits *fits, psMetadata *hduHeader, psArray *sources, long *sourceIndex) 784 { 785 PS_ASSERT_PTR_NON_NULL(fits, false); 786 PS_ASSERT_PTR_NON_NULL(sources, false); 787 788 bool status; 789 long numSources = psFitsTableSize(fits); // Number of sources in table 790 if (numSources == 0) { 791 psError(psErrorCodeLast(), false, "XFIT Table contains no entries\n"); 792 return false; 793 } 794 795 for (long i = 0; i < numSources; i++) { 796 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 797 if (!row) { 798 psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i); 799 psFree(row); 800 return false; 801 } 802 // Find the source with this sequence number. 803 // XXX: I am assuming that sources is sorted in order of seq. 804 long seq = psMetadataLookupU32 (&status, row, "IPP_IDET"); 805 long j = seq < sources->n ? seq : sources->n - 1; 806 pmSource *source = NULL; 807 for (; j >= 0; j--) { 808 source = sources->data[j]; 809 if (source->seq == seq) { 810 break; 811 } 812 } 813 if (!source) { 814 psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq); 815 psFree(row); 816 return false; 817 } 818 if (!source->modelFits) { 819 // XXX: where to find the number of models to expect? 820 source->modelFits = psArrayAllocEmpty(5); 821 } 822 psString modelName = psMetadataLookupStr(&status, row, "MODEL_TYPE"); 823 if (!modelName) { 824 psError(PS_ERR_UNKNOWN, true, "Failed to find model name for row %ld\n", i); 825 psFree(row); 826 return false; 827 } 828 pmModelType modelType = pmModelClassGetType(modelName); 829 if (modelType < 0) { 830 psError(PS_ERR_UNKNOWN, true, "Failed to find model type for %s\n", modelName); 831 psFree(row); 832 return false; 833 } 834 pmModel *model = pmModelAlloc(modelType); 835 836 psF32 *PAR = model->params->data.F32; 837 psF32 *dPAR = model->dparams->data.F32; 838 839 PAR[PM_PAR_XPOS] = psMetadataLookupF32(&status, row, "X_EXT"); 840 PAR[PM_PAR_YPOS] = psMetadataLookupF32(&status, row, "Y_EXT"); 841 dPAR[PM_PAR_XPOS] = psMetadataLookupF32(&status, row, "X_EXT_SIG"); 842 dPAR[PM_PAR_YPOS] = psMetadataLookupF32(&status, row, "Y_EXT_SIG"); 843 844 model->mag = psMetadataLookupF32(&status, row, "EXT_INST_MAG"); 845 model->magErr = psMetadataLookupF32(&status, row, "EXT_INST_MAG_SIG"); 846 847 psEllipseAxes axes; 848 axes.major = psMetadataLookupF32(&status, row, "EXT_WIDTH_MAJ"); 849 axes.minor = psMetadataLookupF32(&status, row, "EXT_WIDTH_MIN"); 850 axes.theta = psMetadataLookupF32(&status, row, "EXT_THETA"); 851 if (!pmPSF_AxesToModel(PAR, axes, modelType)) { 852 // Do we need to fail here or can this happen? 853 psError(PS_ERR_UNKNOWN, false, "Failed to convert psf axes to model"); 854 psFree(model); 855 psFree(row); 856 return false; 857 } 858 // XXX: clean this up 859 if (model->params->n > 7) { 860 PAR[7] = psMetadataLookupF32(&status, row, "EXT_PAR_07"); 861 } 862 // read the covariance matrix 863 int nparams = model->params->n; 864 psImage *covar = psImageAlloc(nparams, nparams, PS_TYPE_F32); 865 for (int y = 0; y < nparams; y++) { 866 for (int x = 0; x < nparams; x++) { 867 char name[64]; 868 snprintf(name, 64, "EXT_COVAR_%02d_%02d", y, x); 869 covar->data.F32[y][x] = psMetadataLookupF32(&status, row, name); 870 } 871 } 872 model->covar = covar; 873 874 psArrayAdd(source->modelFits, 1, model); 875 psFree(model); 876 877 psFree(row); 878 } 879 686 880 return true; 687 881 } … … 831 1025 return true; 832 1026 } 1027 1028 bool pmSourcesRead_CMF_PS1_SV1_XRAD(psFits *fits, psMetadata *hduHeader, psArray *sources, long *sourceIndex) 1029 { 1030 PS_ASSERT_PTR_NON_NULL(fits, false); 1031 PS_ASSERT_PTR_NON_NULL(sources, false); 1032 1033 bool status; 1034 long numSources = psFitsTableSize(fits); // Number of sources in table 1035 if (numSources == 0) { 1036 psError(psErrorCodeLast(), false, "XRAD Table contains no entries\n"); 1037 return false; 1038 } 1039 1040 for (long i = 0; i < numSources; i++) { 1041 psMetadata *row = psFitsReadTableRow(fits, i); // Table row 1042 if (!row) { 1043 psError(psErrorCodeLast(), false, "Unable to read row %ld of sources", i); 1044 psFree(row); 1045 return false; 1046 } 1047 // Find the source with this sequence number. 1048 // XXX: I am assuming that sources is sorted in order of seq. 1049 long seq = psMetadataLookupU32 (&status, row, "IPP_IDET"); 1050 long j = seq < sources->n ? seq : sources->n - 1; 1051 pmSource *source = NULL; 1052 for (; j >= 0; j--) { 1053 source = sources->data[j]; 1054 if (source->seq == seq) { 1055 break; 1056 } 1057 } 1058 if (!source) { 1059 psError(PS_ERR_UNKNOWN, false, "Failed to find source for row %ld sequence number %ld\n", i, seq); 1060 psFree(row); 1061 return false; 1062 } 1063 if (!source->radialAper) { 1064 // XXX: where to find the number of models to expect? 1065 source->radialAper = psArrayAllocEmpty(5); 1066 } 1067 pmSourceRadialApertures *radialAper = pmSourceRadialAperturesAlloc(); 1068 1069 radialAper->flux = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX")); 1070 radialAper->fluxStdev = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX_STDEV")); 1071 radialAper->fluxErr = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FLUX_ERR")); 1072 radialAper->fill = psMemIncrRefCounter(psMetadataLookupVector(&status, row, "APER_FILL")); 1073 1074 psArrayAdd(source->radialAper, 1, radialAper); 1075 1076 psFree(radialAper); 1077 psFree(row); 1078 } 1079 1080 return true; 1081 }
Note:
See TracChangeset
for help on using the changeset viewer.
