IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 19, 2011, 1:22:04 PM (14 years ago)
Author:
bills
Message:

Add and call functions to read the extended source extensions for the PS1_SV1
cmf format

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/objects/pmSourceIO.c

    r32633 r32971  
    5757#define BLANK_HEADERS "BLANK.HEADERS"   // Name of metadata in camera configuration containing header names
    5858                                        // for putting values into a blank PHU
     59static bool pmReadoutReadXSRC(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xsrcname, psArray *sources, long *sourceIndex);
     60static bool pmReadoutReadXFIT(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
     61static bool pmReadoutReadXRAD(pmFPAfile *file, char * exttype, psMetadata *hduHeader, psString xfitname, psArray *sources, long *sourceIndex);
    5962
    6063// lookup the EXTNAME values used for table data and image header segments
     
    961964        psString dataname = NULL;
    962965        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)) {
    964989            return false;
    965990        }
     
    10391064            }
    10401065
     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
    10411107            if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) {
    10421108#if 0
     
    11651231}
    11661232
    1167 
     1233// XXX: We might be able to macroize this and reuse for the other types
     1234
     1235static 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
     1294static 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}
     1352static 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}
Note: See TracChangeset for help on using the changeset viewer.