IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 17, 2008, 12:38:15 PM (18 years ago)
Author:
Paul Price
Message:

The FPA format in psastroDataSave was bad: the GPC1 inputs (which is used for the output) had HDUs in the chips, but the output format is supposed to have an HDU in the FPA. It comes down to a pmFPAfileSuitableFPA not being called at the right place. To fix this, I've sprinkled calls to pmFPAfileSuitableFPA in all the FITS writing functions. This provides the HDU in the right place to these functions. pmFPAfileSuitableFPA should now automatically take care of header conformity, updating concepts, etc. Now, if adding a function to write FITS data, you should make sure that you call pmFPAfileSuitableFPA to get the right format, HDU, header keywords, etc.

File:
1 edited

Legend:

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

    r18599 r18601  
    33 *  @author EAM, IfA
    44 *
    5  *  @version $Revision: 1.62 $ $Name: not supported by cvs2svn $
    6  *  @date $Date: 2008-07-17 20:43:23 $
     5 *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
     6 *  @date $Date: 2008-07-17 22:38:15 $
    77 *
    88 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2828#include "pmFPAview.h"
    2929#include "pmFPAfile.h"
     30#include "pmFPAfileFitsIO.h"
    3031#include "pmConcepts.h"
    3132
     
    108109
    109110// Given a FITS file pointer, write the table of object data
    110 bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     111bool pmFPAviewWriteObjects (const pmFPAview *view, pmFPAfile *file, pmConfig *config)
    111112{
    112113    PS_ASSERT_PTR_NON_NULL(view, false);
     
    114115    PS_ASSERT_PTR_NON_NULL(file->fpa, false);
    115116
    116     pmFPA *fpa = file->fpa;
     117    pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing
    117118
    118119    if (view->chip == -1) {
    119120        if (!pmFPAWriteObjects (fpa, view, file, config)) {
    120121            psError(PS_ERR_IO, false, "Failed to write objects from fpa");
    121             return false;
    122         }
     122            psFree(fpa);
     123            return false;
     124        }
     125        psFree(fpa);
    123126        return true;
    124127    }
     
    126129    if (view->chip >= fpa->chips->n) {
    127130        psError(PS_ERR_UNKNOWN, false, "Writing chip == %d (>= chips->n == %ld)", view->chip, fpa->chips->n);
     131        psFree(fpa);
    128132        return false;
    129133    }
     
    133137        if (!pmChipWriteObjects (chip, view, file, config)) {
    134138            psError(PS_ERR_IO, false, "Failed to write objects from chip");
    135             return false;
    136         }
     139            psFree(fpa);
     140            return false;
     141        }
     142        psFree(fpa);
    137143        return true;
    138144    }
     
    141147        psError(PS_ERR_UNKNOWN, false, "Writing cell == %d (>= cells->n == %ld)",
    142148                view->cell, chip->cells->n);
     149        psFree(fpa);
    143150        return false;
    144151    }
     
    148155        if (!pmCellWriteObjects (cell, view, file, config)) {
    149156            psError(PS_ERR_IO, false, "Failed to write objects from cell");
    150             return false;
    151         }
    152 
     157            psFree(fpa);
     158            return false;
     159        }
     160        psFree(fpa);
    153161        return true;
    154162    }
     
    157165        psError(PS_ERR_UNKNOWN, false, "Writing readout == %d (>= readouts->n == %ld)",
    158166                view->readout, cell->readouts->n);
     167        psFree(fpa);
    159168        return false;
    160169    }
     
    163172    if (!pmReadoutWriteObjects (readout, view, file, config)) {
    164173        psError(PS_ERR_IO, false, "Failed to write objects from readout %d", view->readout);
    165         return false;
    166     }
    167 
     174        psFree(fpa);
     175        return false;
     176    }
     177
     178    psFree(fpa);
    168179    return true;
    169180}
     
    244255    PS_ASSERT_PTR_NON_NULL(view, false);
    245256    PS_ASSERT_PTR_NON_NULL(file, false);
    246     PS_ASSERT_PTR_NON_NULL(file->fpa, false);
     257
     258    pmCell *cell = readout->parent;
     259    PS_ASSERT_PTR_NON_NULL(cell, false);
     260    pmChip *chip = cell->parent;
     261    PS_ASSERT_PTR_NON_NULL(chip, false);
     262    pmFPA *fpa = chip->parent;
     263    PS_ASSERT_PTR_NON_NULL(fpa, false);
    247264
    248265    bool status;
     
    281298      case PM_FPA_FILE_CMP:
    282299        // a SPLIT format : only one header and object table per file
    283         hdu = pmFPAviewThisHDU (view, file->fpa);
     300        hdu = pmFPAviewThisHDU (view, fpa);
    284301        if (!hdu) {
    285302            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
     
    317334
    318335        // get the current header
    319         hdu = pmFPAviewThisHDU (view, file->fpa);
     336        hdu = pmFPAviewThisHDU (view, fpa);
    320337        if (!hdu) {
    321338            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
     
    486503
    487504// if this file needs to have a PHU written out, write one
    488 bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
     505bool pmSource_CMF_WritePHU (const pmFPAview *view, pmFPAfile *file, pmConfig *config)
    489506{
    490507    PS_ASSERT_PTR_NON_NULL(view, false);
     
    503520    if (file->fpa->chips->n == 1) return true;
    504521
     522
    505523    // find the FPA phu
    506     pmHDU *phu = pmFPAviewThisPHU (view, file->fpa);
     524    pmFPA *fpa = pmFPAfileSuitableFPA(file, view, config, false); // Suitable FPA for writing
     525    pmHDU *phu = psMemIncrRefCounter(pmFPAviewThisPHU(view, fpa));
    507526
    508527    // if there is no PHU, this is a single header+image (extension-less) file. This could be
     
    513532        psMetadataCopy (outhead, phu->header);
    514533    }
     534    psFree(phu);
    515535
    516536    pmConfigConformHeader (outhead, file->format);
     
    521541    // XXX why are these not correctly inserted by pmConfigConformHeader??
    522542
    523     psMetadata *headers = psMetadataLookupMetadata(NULL, file->fpa->camera, BLANK_HEADERS); // Header names
     543    // Because these concepts are not part of the "RULE" in the camera format, pmConfigConformHeader only adds
     544    // what is required by the "RULE".
     545    // Though we can configure Ohana to look at particular header keywords, it doesn't like having the
     546    // important values in "HIERARCH FPA.TIME", etc, as is done for skycells, so we stoop to its level,
     547    // putting in additional header keywords that it can understand.
     548
     549    psMetadata *headers = psMetadataLookupMetadata(NULL, fpa->camera, BLANK_HEADERS); // Header names
    524550    if (!headers) {
    525551        psError(PS_ERR_UNEXPECTED_NULL, false,
    526552                "Unable to find %s metadata within camera configuration", BLANK_HEADERS);
    527553        psFree(outhead);
     554        psFree(fpa);
    528555        return false;
    529556    }
     
    535562                    "Unable to find FPA.TIME in %s within camera configuration.", BLANK_HEADERS);
    536563            psFree(outhead);
    537             return false;
    538         }
    539         psTime *time = psMetadataLookupTime(NULL, file->fpa->concepts, "FPA.TIME"); // Time of observation
     564            psFree(fpa);
     565            return false;
     566        }
     567        psTime *time = psMetadataLookupTime(NULL, fpa->concepts, "FPA.TIME"); // Time of observation
    540568        double mjd = psTimeToMJD(time); // The MJD of observation
    541569        psMetadataAddF64(outhead, PS_LIST_TAIL, mjdName, PS_META_REPLACE,
     
    550578                    BLANK_HEADERS);
    551579            psFree(outhead);
    552             return false;
    553         }
    554         float exptime = psMetadataLookupF32(NULL, file->fpa->concepts,
    555                                             "FPA.EXPOSURE"); // Exposure time
     580            psFree(fpa);
     581            return false;
     582        }
     583        float exptime = psMetadataLookupF32(NULL, fpa->concepts, "FPA.EXPOSURE"); // Exposure time
    556584        psMetadataAddF32(outhead, PS_LIST_TAIL, expName, PS_META_REPLACE,
    557585                         "Exposure time (sec)", exptime);
     
    565593                    BLANK_HEADERS);
    566594            psFree(outhead);
    567             return false;
    568         }
    569         float airmass = psMetadataLookupF32(NULL, file->fpa->concepts, "FPA.AIRMASS"); // Airmass
     595            psFree(fpa);
     596            return false;
     597        }
     598        float airmass = psMetadataLookupF32(NULL, fpa->concepts, "FPA.AIRMASS"); // Airmass
    570599        psMetadataAddF32(outhead, PS_LIST_TAIL, amName, PS_META_REPLACE,
    571600                         "Observation airmass", airmass);
     
    575604    const char *fpaNameHdr = psMetadataLookupStr(NULL, fileData, "FPA.OBS");
    576605    if (fpaNameHdr && strlen(fpaNameHdr) > 0) {
    577         const char *fpaName = psMetadataLookupStr(NULL, file->fpa->concepts, "FPA.OBS");
     606        const char *fpaName = psMetadataLookupStr(NULL, fpa->concepts, "FPA.OBS");
    578607        psMetadataAddStr(outhead, PS_LIST_TAIL, fpaNameHdr, PS_META_REPLACE,
    579608                         "FPA observation identifier", fpaName);
     
    581610
    582611    // if we have mosaic-level astrometry information, add it here:
    583     psMetadata *updates = psMetadataLookupPtr (&status, file->fpa->analysis, "PSASTRO.HEADER");
     612    psMetadata *updates = psMetadataLookupPtr (&status, fpa->analysis, "PSASTRO.HEADER");
    584613    if (updates) {
    585614        psMetadataCopy (outhead, updates);
    586615    }
     616    psFree(fpa);
    587617
    588618    psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
Note: See TracChangeset for help on using the changeset viewer.