IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6834


Ignore:
Timestamp:
Apr 11, 2006, 4:12:24 PM (20 years ago)
Author:
Paul Price
Message:

Adding pmFPAAddSourceFromView; renaming pmFPAAddSource to pmFPAAddSourceFromHeader.

Location:
branches/rel10_ifa/psModules/src/astrom
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c

    r6815 r6834  
    324324}
    325325
     326static pmFPALevel hduLevel(psMetadata *format // The camera format configuration
     327                          )
     328{
     329    bool mdok = true;                   // Status of MD lookup
     330    psMetadata *file = psMetadataLookupMD(&mdok, format, "FILE"); // File information
     331    if (!mdok || !file) {
     332        psError(PS_ERR_IO, true, "Unable to find FILE information in camera format configuration.\n");
     333        return PM_FPA_LEVEL_NONE;
     334    }
     335    const char *extType = psMetadataLookupStr(&mdok, file, "EXTENSIONS");
     336    if (!mdok || !extType || strlen(extType) == 0) {
     337        psError(PS_ERR_IO, true, "Unable to find EXTENSIONS in the FILE information in the camera format"
     338                " configuration.\n");
     339        return PM_FPA_LEVEL_NONE;
     340    }
     341
     342    // Where do we stick in the HDUs?
     343    pmFPALevel level = PM_FPA_LEVEL_NONE; // Level for HDU insertion
     344    if (strcasecmp(extType, "CHIP") == 0) {
     345        level = PM_FPA_LEVEL_CHIP;
     346    } else if (strcasecmp(extType, "CELL") == 0) {
     347        level = PM_FPA_LEVEL_CELL;
     348    } else if (strcasecmp(extType, "NONE") != 0) {
     349        psError(PS_ERR_IO, true, "EXTENSIONS is not CHIP or CELL or NONE.\n");
     350    }
     351
     352    return level;
     353}
     354
    326355//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    327356// Public functions
     
    362391}
    363392
     393bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
     394                            pmFPAview *phuView, // The view, corresponding to the PHU
     395                            psMetadata *format // Format of file
     396                           )
     397{
     398    assert(fpa);
     399    assert(phuView);
     400    assert(format);
     401
     402    // Where does the PHU go?
     403    bool mdok = true;                   // Status of MD lookup
     404    psMetadata *fileInfo = psMetadataLookupMD(&mdok, format, "FILE"); // File information from the format
     405    if (!mdok || !fileInfo) {
     406        psError(PS_ERR_IO, false, "Unable to find FILE information in the camera format configuration.\n");
     407        return false;
     408    }
     409    const char *phuType = psMetadataLookupStr(&mdok, fileInfo, "PHU"); // What is the PHU?
     410    if (!mdok || strlen(phuType) == 0) {
     411        psError(PS_ERR_IO, false, "Unable to find PHU in the FILE information of the camera format.\n");
     412        return false;
     413    }
     414
     415    // Generate the PHU
     416    pmHDU *phdu = pmHDUAlloc("PHU");    // The primary header data unit
     417    phdu->format = psMemIncrRefCounter(format);
     418
     419    // Put in the PHU
     420    pmChip *chip = NULL;                // The chip that corresponds to the PHU
     421    pmCell *cell = NULL;                // The cell that corresponds to the PHU
     422    if (strcasecmp(phuType, "FPA") == 0) {
     423        fpa->hdu = phdu;
     424    } else {
     425        psArray *chips = fpa->chips;    // Array of chips
     426        if (phuView->chip < 0 || phuView->chip > chips->n) {
     427            psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a "
     428                    "particular chip, which cannot be determined from the view (%d).\n", phuView->chip);
     429            psFree(phdu);
     430            return false;
     431        }
     432        chip = chips->data[phuView->chip];
     433        if (strcasecmp(phuType, "CHIP") == 0) {
     434            chip->hdu = phdu;
     435        } else if (strcasecmp(phuType, "CELL") == 0) {
     436            psArray *cells = chip->cells; // Array of cells
     437            if (phuView->cell < 0 || phuView->cell > cells->n) {
     438                psError(PS_ERR_IO, true, "PHU specified by the camera format requires specification of a "
     439                        "particular cell, which cannot be determined from the view (%d).\n", phuView->cell);
     440                psFree(phdu);
     441                return false;
     442            }
     443            cell->hdu = phdu;
     444        } else {
     445            psError(PS_ERR_IO, true, "PHU in the camera configuration format is not FPA, CHIP or CELL.\n");
     446            psFree(phdu);
     447            return false;
     448        }
     449    }
     450
     451    // Put in the extensions
     452    pmFPALevel level = hduLevel(format);// The level for the HDUs to go
     453    if (level == PM_FPA_LEVEL_NONE) {
     454        // No extensions --- we're done
     455        return true;
     456    }
     457    psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file
     458    if (!mdok || !contents) {
     459        psError(PS_ERR_IO, false, "Unable to find CONTENTS in the camera format configuration.\n");
     460        return false;
     461    }
     462
     463    psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); // Iterator
     464    psMetadataItem *contentsItem = NULL;// Item from the contents iteration
     465    while ((contentsItem = psMetadataGetAndIncrement(contentsIter))) {
     466        if (contentsItem->type != PS_DATA_STRING) {
     467            psLogMsg(__func__, PS_LOG_WARN, "Content item %s is not of type STR --- ignored.\n",
     468                     contentsItem->name);
     469            continue;
     470        }
     471        pmHDU *hdu = pmHDUAlloc(contentsItem->name); // HDU to add
     472        hdu->format = psMemIncrRefCounter(format);
     473        const char *content = contentsItem->data.V; // The content data
     474        processContents(fpa, chip, cell, hdu, level, content, format);
     475        psFree(hdu);
     476    }
     477    psFree(contentsIter);
     478
     479    return true;
     480}
     481
     482
    364483
    365484// Add an input file to the FPA
    366 pmFPAview *pmFPAAddSource(pmFPA *fpa, // The FPA
    367                           psMetadata *phu, // Primary header of file
    368                           psMetadata *format // Format of file
    369                          )
     485pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA
     486                                    psMetadata *phu, // Primary header of file
     487                                    psMetadata *format // Format of file
     488                                   )
    370489{
    371490    assert(fpa);
     
    531650    psFree(phdu);
    532651
    533     // Where do we stick in the HDUs?
    534     pmFPALevel hduLevel = PM_FPA_LEVEL_NONE; // Level for HDU insertion
    535     if (strcasecmp(extType, "CHIP") == 0) {
    536         hduLevel = PM_FPA_LEVEL_CHIP;
    537     } else if (strcasecmp(extType, "CELL") == 0) {
    538         hduLevel = PM_FPA_LEVEL_CELL;
    539     } else {
    540         psError(PS_ERR_IO, true, "EXTENSIONS is not CHIP or CELL or NONE.\n");
    541         psFree(view);
    542         return NULL;
    543     }
     652    pmFPALevel level = hduLevel(format);// The level at which to plug in HDU
    544653
    545654    // Now go through the contents
     
    556665        hdu->format = psMemIncrRefCounter(format);
    557666
    558         processContents(fpa, chip, cell, hdu, hduLevel, contentsItem->data.V, format);
     667        processContents(fpa, chip, cell, hdu, level, contentsItem->data.V, format);
    559668        psFree(hdu);
    560669    }
     
    579688            psTrace(__func__, 2, "---> NO PIXELS read in for extension %s\n", fpa->hdu->extname);
    580689        }
    581         if (fpa->hdu->header && header) {
    582             psTrace(__func__, 2, "---> Header:\n");
    583             psMetadataPrint(fpa->hdu->header, 8);
     690        if (header) {
     691            if (fpa->hdu->header) {
     692                psTrace(__func__, 2, "---> Header:\n");
     693                psMetadataPrint(fpa->hdu->header, 8);
     694            } else {
     695                psTrace(__func__, 2, "---> NO HEADER read in for extension %s\n", fpa->hdu->extname);
     696            }
    584697        }
    585698    }
     
    595708        if (chip->hdu) {
    596709            psTrace(__func__, 4, "---> Chip is extension %s.\n", chip->hdu->extname);
    597             if (chip->hdu->header && header) {
    598                 psTrace(__func__, 4, "---> Header:\n");
    599                 psMetadataPrint(chip->hdu->header, 8);
     710            if (header) {
     711                if (chip->hdu->header) {
     712                    psTrace(__func__, 4, "---> Header:\n");
     713                    psMetadataPrint(chip->hdu->header, 8);
     714                } else {
     715                    psTrace(__func__, 4, "---> NO HEADER read in for extension %s\n", chip->hdu->extname);
     716                }
    600717            }
    601718            if (! chip->hdu->images) {
     
    614731            if (cell->hdu) {
    615732                psTrace(__func__, 6, "---> Cell is extension %s.\n", cell->hdu->extname);
    616                 if (cell->hdu->header && header) {
    617                     psTrace(__func__, 4, "---> Header:\n");
    618                     psMetadataPrint(cell->hdu->header, 8);
     733                if (header) {
     734                    if (cell->hdu->header) {
     735                        psTrace(__func__, 6, "---> Header:\n");
     736                        psMetadataPrint(cell->hdu->header, 8);
     737                    } else {
     738                        psTrace(__func__, 6, "---> NO HEADER read in for extension %s\n", cell->hdu->extname);
     739                    }
    619740                }
    620741                if (! cell->hdu->images) {
  • branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h

    r6734 r6834  
    1010                     );
    1111
    12 pmFPAview *pmFPAAddSource(pmFPA *fpa, // The FPA
    13                           psMetadata *phu, // Primary header of file
    14                           psMetadata *format // Format of file
    15                          );
     12bool pmFPAAddSourceFromView(pmFPA *fpa,   // The FPA
     13                            pmFPAview *phuView, // The view, corresponding to the PHU
     14                            psMetadata *format // Format of file
     15                           );
     16
     17pmFPAview *pmFPAAddSourceFromHeader(pmFPA *fpa, // The FPA
     18                                    psMetadata *phu, // Primary header of file
     19                                    psMetadata *format // Format of file
     20                                   );
    1621
    1722// Print out the FPA
  • branches/rel10_ifa/psModules/src/astrom/pmFPAfile.c

    r6827 r6834  
    698698
    699699        // set the view to the corresponding entry for this phu
    700         pmFPAview *view = pmFPAAddSource (fpa, phu, format);
     700        pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format);
    701701
    702702        // XXX is this the correct psMD to save the filename?
     
    786786
    787787        // set the view to the corresponding entry for this phu
    788         pmFPAview *view = pmFPAAddSource (fpa, phu, format);
     788        pmFPAview *view = pmFPAAddSourceFromHeader(fpa, phu, format);
    789789
    790790        // XXX is this the correct psMD to save the filename?
     
    879879
    880880        // set the view to the corresponding entry for this phu
    881         pmFPAview *view = pmFPAAddSource (file->fpa, phu, format);
     881        pmFPAview *view = pmFPAAddSourceFromHeader(file->fpa, phu, format);
    882882
    883883        // XXX is this the correct psMD to save the filename?
  • branches/rel10_ifa/psModules/src/astrom/pmHDU.c

    r6815 r6834  
    135135    }
    136136
     137    if (!hdu->images && !hdu->table && !hdu->header) {
     138        psLogMsg(__func__, PS_LOG_WARN, "Nothing to write for HDU %s\n", hdu->extname);
     139        return false;
     140    }
     141
    137142    // Preserve the extension name, if it's the PHU
    138143    char *extname = hdu->extname;       // The name of the extension
    139     if (strcasecmp(extname, "PHU") == 0) {
     144    if (strcasecmp(extname, "PHU") == 0 && hdu->header) {
    140145        bool mdok = true;               // Status of MD lookup
    141146        extname = psMetadataLookupStr(&mdok, hdu->header, "EXTNAME");
    142         if (!mdok || strlen(extname) == 0) {
     147        if (!mdok || !extname || strlen(extname) == 0) {
    143148            extname = "";
    144149        }
     
    149154        // Tell CFITSIO there's nothing there
    150155        psMetadataItem *naxis = psMetadataLookup(hdu->header, "NAXIS");
    151         naxis->data.S32 = 0;
     156        if (naxis) {
     157            naxis->data.S32 = 0;
     158        }
    152159
    153160        if (!psFitsWriteHeader(hdu->header, fits)) {
Note: See TracChangeset for help on using the changeset viewer.