IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 21, 2006, 1:52:54 PM (20 years ago)
Author:
Paul Price
Message:

Now works with GPC1 dummy OTA FITS file from Sidik; some other changes to organise things.

File:
1 edited

Legend:

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

    r6590 r6663  
    114114    assert(fits);
    115115
     116    psTrace(__func__, 7, "Writing HDU %s\n", hdu->extname);
     117
    116118    if (hdu->images && hdu->table && !hdu->header) {
    117119        psError(PS_ERR_IO, true, "Both image and table data provided in HDU, but no header --- "
     
    120122    }
    121123
     124    // Preserve the extension name, if it's the PHU
     125    char *extname = hdu->extname;       // The name of the extension
     126    if (strcasecmp(extname, "PHU") == 0) {
     127        bool mdok = true;               // Status of MD lookup
     128        extname = psMetadataLookupStr(&mdok, hdu->header, "EXTNAME");
     129        if (!mdok || strlen(extname) == 0) {
     130            extname = "";
     131        }
     132    }
     133
     134    if (!hdu->images && !psFitsWriteHeader(hdu->header, fits)) {
     135        psError(PS_ERR_IO, false, "Unable to write header for extension %s\n", extname);
     136    }
     137
    122138    #ifdef FITS_TABLES
    123139    if (hdu->images && (!hdu->table || psFitsIsImage(hdu->header))) {
    124         #endif
    125         psFitsWriteImageCube(fits, hdu->header, hdu->images, hdu->extname);
     140        psFitsWriteImageCube(fits, hdu->header, hdu->images, extname);
    126141        return true;
    127         #ifdef FITS_TABLES
    128 
    129142    }
    130143
     
    136149    psError(PS_ERR_IO, true, "No idea what this HDU consists of!\n");
    137150    return false;
     151    #else
     152
     153    if (hdu->images) {
     154        psTrace(__func__, 9, "Writing pixels for %s\n", hdu->extname);
     155        if (!psFitsWriteImageCube(fits, hdu->header, hdu->images, extname)) {
     156            psError(PS_ERR_IO, false, "Unable to write image to extension %s\n", hdu->extname);
     157            return false;
     158        }
     159    }
     160    return true;
    138161    #endif
    139162}
    140163
    141 
    142 
    143 #if 0
    144 
    145 
    146 
    147 
    148 // Read the PHU of a file
    149 static bool readPHU(pmCameraFile *file  // File for which to read the PHU
    150                    )
    151 {
    152     if (! file->phu) {
    153         if (! file->fits) {
    154             file->fits = psFitsOpen(file->name, "r");
    155         }
    156         (void)psFitsMoveExtNum(file->fits, 0, false);
    157         file->phu = psFitsReadHeader(NULL, file->fits);
    158 
    159         return true;
    160     }
    161 
    162     return false;
    163 }
    164 
    165 bool pmCameraFileFormat(pmCameraFile *file, // File to inspect
    166                         psMetadata *camera // Camera description
    167                        )
    168 {
    169     if (! camera) {
    170         return false;
    171     }
    172 
    173     readPHU(file);
    174 
    175     bool mdok = true;                   // Result of MD lookup
    176     psMetadata *formats = psMetadataLookupMD(&mdok, camera, "FORMATS"); // List of known formats
    177     if (! mdok || ! formats) {
    178         psLogMsg(__func__, PS_LOG_WARN, "Unable to find list of FORMATS in camera configuration!\n");
    179         return false;
    180     }
    181 
    182     bool result = false;                // Result of search
    183     psMetadataIterator *formatsIter = psMetadataIteratorAlloc(formats, NULL); // Iterator for formats
    184     psMetadataItem *formatsItem = NULL; // Item from formats
    185     while ((formatsItem = psMetadataGetAndIncrement(formatsIter))) {
    186         if (formatsItem->type != PS_DATA_STRING) {
    187             psLogMsg(__func__, PS_LOG_WARN, "Entry not of type STR found in camera FORMATS list.\n");
    188             continue;
    189         }
    190         psTrace(__func__, 7, "Trying format file: %s\n", formatsItem->name);
    191         int numBadLines = 0;            // Number of bad lines in file
    192         psMetadata *format = psMetadataConfigParse(NULL, &numBadLines, formatsItem->data.V, true);
    193         if (numBadLines > 0) {
    194             psLogMsg(__func__, PS_LOG_WARN, "%d bad lines found in %s.\n", formatsItem->name);
    195         }
    196         if (pmConfigValidateCamera(format, file->phu)) {
    197             file->format = format;
    198             result = true;
    199             psLogMsg(__func__, PS_LOG_INFO + 2, "File %s matches camera format file %s\n", file->name,
    200                      formatsItem->data.V);
    201             break;
    202         }
    203         psFree(format);
    204     }
    205     psFree(formatsIter);
    206 
    207     return result;
    208 }
    209 
    210 
    211 bool pmConfigValidateCamera(const psMetadata *camera, const psMetadata *header);
    212 
    213 pmFPA *pmFPASourceFile(pmFPA *fpa,      // FPA to which to add
    214                        pmFile *file,    // File to add
    215                        const char *name, // Symbolic name for file, e.g., "INPUT", "OUTPUT", "TESTFILE"
    216                        pmConfig *config // Configuration set
    217                       )
    218 {
    219     assert(file);
    220     assert(name);
    221 
    222     if (! file->fits) {
    223         file->fits = psFitsOpen(file->name, "r");
    224     }
    225     if (! file->phu) {
    226         (void)psFitsMoveExtNum(file->fits, 0, false);
    227         file->phu = psFitsReadHeader(NULL, file->fits);
    228     }
    229 
    230     psMetadata *fileConfig = NULL;      // The file configuration
    231     if (fpa && fpa->camera) {
    232         fpa
    233 
    234         bool pmConfigValidateCamera(const psMetadata *camera, const psMetadata *header);
    235         #endif
Note: See TracChangeset for help on using the changeset viewer.