IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 24, 2005, 3:05:59 PM (21 years ago)
Author:
Paul Price
Message:

Retrieval of concepts seems to be working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/pmFPARead.c

    r4309 r4386  
    1212//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1313
    14 // Copy a metadata
    15 static psMetadata *metadataCopy(psMetadata *md)
    16 {
    17     psMetadata *new = psMetadataAlloc();// The metadata to return
    18     psMetadataIterator *mdIter = psMetadataIteratorAlloc(md, PS_LIST_HEAD, NULL); // Iterator for the MD
     14// Copy metadata elements into another metadata
     15static void metadataCopy(psMetadata *to, // Metadata to which to copy
     16                         psMetadata *from // Metdata from which to copy
     17    )
     18{
     19    psMetadataIterator *mdIter = psMetadataIteratorAlloc(from, PS_LIST_HEAD, NULL); // Iterator for the MD
    1920    psMetadataItem *item = NULL;        // Item from the metadata
    2021    while (item = psMetadataGetAndIncrement(mdIter)) {
    21         if (! psMetadataAddItem(new, item, PS_LIST_TAIL, PS_META_REPLACE)) {
     22        psTrace(__func__, 9, "Adding %s to metadata...\n", item->name);
     23        if (! psMetadataAddItem(to, item, PS_LIST_TAIL, PS_META_REPLACE)) {
    2224            psLogMsg(__func__, PS_LOG_WARN, "Unable to add item (%s: %s) to metadata: ignored\n", item->name,
    2325                     item->comment);
     
    2527    }
    2628    psFree(mdIter);
    27 
    28     return new;
    2929}
    3030
     
    4646        return NULL;
    4747    } else {
    48 #if 0
    49         psMetadata *newCell = metadataCopy(cellData); // A copy of the cell, to be returned
    50         return newCell;
    51 #else
    52         return psMemIncrRefCounter(cellData);
    53 #endif
     48        return cellData;
    5449    }
    5550}
     
    6257    )
    6358{
    64     if (! psFitsMoveExtName(fits, extName)) {
     59    if (strncmp(extName, "PHU", 3) == 0) {
     60        if (!psFitsMoveExtNum(fits, 0, false)) {
     61            psError(PS_ERR_IO, false, "Unable to find PHU in FITS file!\n");
     62            return false;
     63        }
     64    } else if (! psFitsMoveExtName(fits, extName)) {
    6565        psError(PS_ERR_IO, false, "Unable to find extension %s in FITS file!\n", extName);
    6666        return false;
     
    7979
    8080    int numPlanes = 1;                  // Number of planes
    81     if (nAxis > 3) {
     81    if (nAxis == 3) {
    8282        numPlanes = psMetadataLookupS32(&mdStatus, *header, "NAXIS3");
    8383        if (!mdStatus) {
     
    251251//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    252252
    253 papFPA *pmFPARead(const psMetadata *camera, // The camera configuration
    254                   psFits *fits // A FITS file
    255     )
    256 {
     253papFPA *pmFPARead(psFits *fits, // A FITS file
     254                  const psMetadata *camera, // The camera configuration
     255                  psDB *db              // Database
     256    )
     257{
     258    papFPA *fpa = papFPAAlloc(camera, db); // The FPA to fill out
    257259    bool mdStatus = true;               // Status from metadata lookups
    258     // Get the configuration information out of the camera config
    259     psMetadata *translation = psMetadataLookupMD(&mdStatus, camera, "TRANSLATION");
    260     psMetadata *database = psMetadataLookupMD(&mdStatus, camera, "DATABASE");
    261     psMetadata *defaults = psMetadataLookupMD(&mdStatus, camera, "DEFAULTS");
    262     psDB *dbh = NULL;
    263 
    264     // Generate a build tree
    265     papFPA *fpa = papFPAAlloc(translation, database, defaults, dbh); // The FPA to fill out
    266 
    267260    const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU?
    268261    const char *extType = psMetadataLookupString(&mdStatus, camera, "EXTENSIONS"); // What's in the extensions?
     
    286279                const char *extName = contentItem->name; // The name of the extension
    287280                papChip *chip = papChipAlloc(fpa, extName); // The chip
    288                 readExtension(&(chip->images), &(chip->header), fits, extName);
    289 
     281                readExtension(&(chip->pixels), &(chip->header), fits, extName);
    290282                if (contentItem->type != PS_META_STR) {
    291283                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     
    293285                } else {
    294286                    const char *content = contentItem->data.V; // The content of the extension
     287                    psTrace(__func__, 7, "Content of %s is: %s\n", extName, content);
    295288                    psList *cellNames = papSplit(content, " ,"); // A list of the component cells
    296289                    psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, NULL);
     
    298291                    while (cellName = psListGetAndIncrement(cellNamesIter)) {
    299292                        // Get the cell data
    300                         papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->images)->n); // The cell
    301                         cell->values = getCellData(camera, cellName);
    302                         portionCell(cell, chip->images, chip->header);
     293                        papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->pixels)->n); // The cell
     294                        psMetadata *cellData = getCellData(camera, cellName);
     295                        metadataCopy(cell->values, cellData);
     296                        portionCell(cell, chip->pixels, chip->header);
    303297                    }
    304298                    psFree(cellNamesIter);
     
    309303        } else if (strncmp(extType, "CELL", 4) == 0) {
    310304            // Extensions are cells; Content contains a chip name and cell type
     305            psMetadata *chipNumbers = psMetadataAlloc(); // Given a chip name, holds the chip number
    311306            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    312307                const char *extName = contentItem->name; // The name of the extension
     
    324319                        const char *chipName = psListGet(contents, 0); // The name of the chip
    325320                        const char *cellType = psListGet(contents, 1); // The type of cell
     321                        psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType,
     322                                chipName);
    326323
    327324                        papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
    328325                        if (! mdStatus && ! chip) {
    329                             papChip *chip = papChipAlloc(fpa, "CHIP");
     326                            chip = papChipAlloc(fpa, chipName);
    330327                        }
    331328                        // The cell
    332329                        psArray *images = NULL;
    333330                        psMetadata *header = NULL;
     331                        psTrace(__func__, 7, "Reading extension %s\n", extName);
    334332                        readExtension(&images, &header, fits, extName);
    335                         papCell *cell = papCellAlloc(chip, extName, images->n); // The cell
    336                         cell->images = images;
     333                        psTrace(__func__, 7, "Allocating cell %s\n", cellType);
     334                        papCell *cell = papCellAlloc(chip, cellType, images->n); // The cell
     335                        cell->pixels = images;
    337336                        cell->header = header;
    338                         cell->values = getCellData(camera, extName);
    339                         portionCell(cell, cell->images, cell->header);
     337                        psMetadata *cellData = getCellData(camera, cellType);
     338                        metadataCopy(cell->values, cellData);
     339                        psTrace(__func__, 7, "Portioning cell....\n");
     340                        portionCell(cell, cell->pixels, cell->header);
     341                        psTrace(__func__, 7, "Done.\n");
    340342                    }
    341343                }
     
    344346        } else if (strncmp(extType, "NONE", 4) == 0) {
    345347            // No extensions; Content contains metadata, each entry is a chip with its component cells
    346             readExtension(&(fpa->images), &(fpa->header), fits, "PHU");
     348            readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    347349            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    348350                const char *chipName = contentItem->name; // The name of the chip
     
    353355                } else {
    354356                    const char *content = contentItem->data.V; // The content of the extension
    355                     papChip *chip = papChipAlloc(fpa, "CHIP"); // The chip
     357                    papChip *chip = papChipAlloc(fpa, content); // The chip
    356358                    psList *cellNames = papSplit(content, ", "); // Split the list of cells
    357359                    psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false);
    358360                    char *cellName = NULL; // Name of the cell
    359361                    while (cellName = psListGetAndIncrement(cellNamesIter)) {
    360                         papCell *cell = papCellAlloc(chip, "CELL", ((psArray*)fpa->images)->n); // The cell
    361                         cell->values = getCellData(camera, cellName);
    362                         portionCell(cell, fpa->images, fpa->header);
     362                        papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
     363                        psMetadata *cellData = getCellData(camera, cellName);
     364                        metadataCopy(cell->values, cellData);
     365                        portionCell(cell, fpa->pixels, fpa->header);
    363366                    }
    364367                    psFree(cellNamesIter);
     
    380383        if (strncmp(extType, "NONE", 4) == 0) {
    381384            // There are no extensions --- only the PHU
    382             readExtension(&(fpa->images), &(fpa->header), fits, "PHU");
     385            readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    383386
    384387            const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS");
     
    392395            const char *cellName = NULL;
    393396            while (cellName = psListGetAndIncrement(cellIter)) {
    394                 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->images)->n); // The cell
    395                 cell->values = getCellData(camera, cellName);
    396                 portionCell(cell, fpa->images, fpa->header);
     397                papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
     398                psMetadata *cellData = getCellData(camera, cellName);
     399                metadataCopy(cell->values, cellData);
     400                portionCell(cell, fpa->pixels, fpa->header);
    397401            }
    398402            psFree(cellIter);
     
    433437                    readExtension(&images, &header, fits, extName);
    434438                    papCell *cell = papCellAlloc(chip, extName, images->n); // The cell
    435                     cell->images = images;
     439                    cell->pixels = images;
    436440                    cell->header = header;
    437                     cell->values = getCellData(camera, cellType);
    438                     portionCell(cell, cell->images, cell->header);
     441                    psMetadata *cellData = getCellData(camera, cellType);
     442                    metadataCopy(cell->values, cellData);
     443                    portionCell(cell, cell->pixels, cell->header);
    439444                }
    440445            } // Iterating through contents
     
    455460    }
    456461
    457    
    458     // Print out the build tree
     462    return fpa;
     463}
     464
     465void pmFPAPrint(papFPA *fpa             // FPA to print
     466    )
     467{
     468    // Print out the focal plane
    459469    psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa->chips, PS_LIST_HEAD, NULL); // Iterator for FPA
    460470    psMetadataItem *fpaItem = NULL;     // Item from metadata
    461471    psTrace("pmFPARead", 0, "FPA:\n");
    462     if (fpa->images) {
     472    if (fpa->pixels) {
    463473        psTrace("pmFPARead", 1, "---> FPA contains pixels.\n");
    464474    }
     
    469479            psTrace("pmFPARead", 1, "Chip: %s\n", fpaItem->name);
    470480            papChip *chip = fpaItem->data.V; // The chip
    471             if (chip->images) {
     481            if (chip->pixels) {
    472482                psTrace("pmFPARead", 2, "---> Chip contains pixels.\n");
    473483            }
     
    481491                    psTrace("pmFPARead", 2, "Cell: %s\n", chipItem->name);
    482492                    papCell *cell = chipItem->data.V; // The cell
    483                     if (cell->images) {
     493                    if (cell->pixels) {
    484494                        psTrace("pmFPARead", 3, "---> Cell contains pixels.\n");
    485495                    }
     
    494504                          case PS_META_F32:
    495505                            psTrace("pmFPARead", 3, "%s: %f\n", cellItem->name, cellItem->data.F32);
     506                            break;
     507                          case PS_META_S32:
     508                            psTrace("pmFPARead", 3, "%s: %d\n", cellItem->name, cellItem->data.S32);
    496509                            break;
    497510                          case PS_META_META:
     
    527540    } // Iterating through FPA
    528541    psFree(fpaIter);
    529 
    530     return fpa;
    531 
    532 }
     542}
Note: See TracChangeset for help on using the changeset viewer.