IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6663


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.

Location:
branches/rel10_ifa/psModules/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/Makefile.am

    r6618 r6663  
    88        pmFPAMaskWeight.c \
    99        pmFPARead.c \
     10        pmFPAWrite.c \
    1011        pmHDU.c \
    1112        pmHDUGetLowest.c \
     
    2122#       pmAstrometryObjects.c
    2223#       pmChipMosaic.c
    23 #       pmFPAWrite.c
    2424
    2525psmoduleincludedir = $(includedir)
     
    2929        pmFPAMaskWeight.h \
    3030        pmFPARead.h \
     31        pmFPAWrite.h \
    3132        pmHDU.h \
    3233        pmHDUGetLowest.h \
     
    4445#
    4546#       pmChipMosaic.h
    46 #       pmFPAWrite.h
  • branches/rel10_ifa/psModules/src/astrom/pmConceptsStandard.c

    r6581 r6663  
    413413        psString format = psMetadataLookupStr(&mdok, formats, name);
    414414        if (mdok && strlen(format) > 0 && strcasecmp(format, "FORTRAN") == 0) {
    415             return -1;
     415            return 1;
    416416        }
    417417    }
     
    429429    }
    430430    int offset = concept->data.S32;
    431     offset += fortranCorr(cameraFormat, pattern->name);
     431    offset -= fortranCorr(cameraFormat, pattern->name);
    432432    return psMetadataItemAllocS32(pattern->name, pattern->comment, offset);
    433433}
     
    486486        psMetadataItem *yBinItem = psMetadataLookup(cell->concepts, "CELL.YBIN"); // Binning factor in y
    487487        psString binString = psStringCopy("");
    488         psStringAppend(&binString, "%d,%d", concept->data.S32, yBinItem->data.S32);
     488        psStringAppend(&binString, "%d %d", concept->data.S32, yBinItem->data.S32);
    489489        psMetadataItem *binItem = psMetadataItemAllocStr(concept->name, concept->comment, binString);
    490490        psFree(binString);
     
    611611    }
    612612    int offset = concept->data.S32;
    613     offset -= fortranCorr(cameraFormat, concept->name);
     613    offset += fortranCorr(cameraFormat, concept->name);
    614614    return psMetadataItemAllocS32(concept->name, concept->comment, offset);
    615615}
  • branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c

    r6575 r6663  
    132132    if (cell) {
    133133        pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     134        if (!hdu) {
     135            return false;
     136        }
    134137        psMetadata *cameraFormat = hdu->format; // The camera format
    135138        psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator
     
    145148                // Formatted version
    146149                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell);
     150                if (!formatted) {
     151                    continue;
     152                }
    147153                psString nameSource = NULL; // String with the concept name and ".SOURCE" added
    148154                psStringAppend(&nameSource, "%s.SOURCE", name);
     
    193199{
    194200    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     201    if (!hdu) {
     202        return false;
     203    }
    195204    psMetadata *cameraFormat = hdu->format; // The camera format
    196205    bool mdok = true;                   // Status of MD lookup
     
    208217                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    209218                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
     219                if (!formatted) {
     220                    continue;
     221                }
    210222                if (! compareConcepts(defaultItem, formatted)) {
    211223                    psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera "
     
    229241{
    230242    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     243    if (!hdu) {
     244        return false;
     245    }
    231246    psMetadata *cameraFormat = hdu->format; // The camera format
    232247    bool mdok = true;                   // Status of MD lookup
     
    249264                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    250265                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
     266                if (!formatted) {
     267                    continue;
     268                }
    251269                psList *keywords = psStringSplit(headerItem->data.V, " ,;"); // List of header keywords
    252270                if (formatted->type == PS_DATA_LIST) {
     
    289307{
    290308    pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level
     309    if (!hdu) {
     310        return false;
     311    }
    291312    psMetadata *cameraFormat = hdu->format; // The camera format
    292313    bool mdok = true;                   // Status of MD lookup
     
    311332                psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts
    312333                psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell);
     334                if (!formatted) {
     335                    continue;
     336                }
    313337
    314338                psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest
  • branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c

    r6618 r6663  
    115115        return false;
    116116    }
    117     psString result = psMetadataLookupStr(&mdok, header, keyword);
    118     if (!mdok || strlen(result) == 0) {
     117    psMetadataItem *resultItem = psMetadataLookup(header, keyword);
     118    if (! resultItem) {
    119119        psError(PS_ERR_IO, false, "Unable to find %s in primary header to identify %s.\n", keyword, name);
    120120        return NULL;
    121121    }
    122 
    123     return result;
     122    return psMetadataItemParseString(resultItem);
    124123}
    125124
     
    190189    }
    191190    psMetadataItem *fpaNameItem = psMetadataLookup(phu, nameKeyword); // Name of the FPA
     191    if (!fpaNameItem) {
     192        psError(PS_ERR_IO, false, "Unable to find keyword %s with the name of the FPA.\n", nameKeyword);
     193        return NULL;
     194    }
    192195    const char *newFPAname = psMetadataItemParseString(fpaNameItem); // FPA.NAME for new source
    193196    fpaNameItem = psMetadataLookup(fpa->concepts, "FPA.NAME"); // Current name of FPA
     
    421424            psString chipName = NULL;   // Name of chip under consideration
    422425            pmChip *chip = NULL;        // The chip we're looking for
    423             if (! fpa->hdu->phu) {
     426            #if 1
     427            // Think I'm doing this at the start now
     428            if (!fpa->hdu || !fpa->hdu->phu) {
    424429                // Need to look up the name of the chip
    425430                chipName = phuNameFromHeader("CHIP.NAME", formatSpec, phu);
     
    431436                chip = fpa->chips->data[chipNum];
    432437            }
     438            #endif
    433439            for (int i = 0; i < names->n; i++) {
    434440                psString cellType = values->data[i]; // The type of the cell
    435441                psString cellName = NULL; // The name of the cell
    436                 if (fpa->hdu->phu) {
     442                if (fpa->hdu && fpa->hdu->phu) {
    437443                    // We've got chipName:cellType with cellType == cellName
    438444                    chipName = names->data[i];
  • branches/rel10_ifa/psModules/src/astrom/pmFPARead.c

    r6622 r6663  
    5959#if 0
    6060bool pmReadoutRead(pmReadout *readout,  // Readout to read into
    61                    psFits *fits         // FITS file from which to read
     61                   psFits *fits,        // FITS file from which to read
     62                   int numSections      // Total number of sections
     63                   int section          // The section of interest
    6264                  )
    6365{
  • branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.c

    r6552 r6663  
    44
    55#include "pmFPA.h"
    6 #include "pmFPARead.h"
     6#include "pmHDU.h"
    77#include "pmConcepts.h"
    88
     9
     10bool pmCellWrite(pmCell *cell,          // Cell to write
     11                 psFits *fits,          // FITS file to which to write
     12                 psDB *db               // Database handle for "concepts" update
     13                )
     14{
     15    pmConceptsWriteCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL);
     16
     17    pmHDU *hdu = cell->hdu;             // The HDU
     18    if (hdu && !pmHDUWrite(hdu, fits)) {
     19        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
     20        return false;
     21    }
     22
     23    return true;
     24}
     25
     26
     27bool pmChipWrite(pmChip *chip,          // Chip to write
     28                 psFits *fits,          // FITS file to which to write
     29                 psDB *db               // Database handle for "concepts" update
     30                )
     31{
     32    pmConceptsWriteChip(chip, PM_CONCEPT_SOURCE_HEADER, false, NULL);
     33
     34    pmHDU *hdu = chip->hdu;             // The HDU
     35    if (hdu && !pmHDUWrite(hdu, fits)) {
     36        psError(PS_ERR_IO, false, "Unable to write HDU for Chip.\n");
     37        return false;
     38    }
     39
     40    bool success = true;                // Success of writing
     41    psArray *cells = chip->cells;       // Array of cells
     42    for (int i = 0; i < cells->n; i++) {
     43        pmCell *cell = cells->data[i];  // The cell of interest
     44        success |= pmCellWrite(cell, fits, db);
     45    }
     46
     47    return success;
     48}
     49
     50
     51
     52
     53bool pmFPAWrite(pmFPA *fpa,             // FPA to write
     54                psFits *fits,           // FITS file to which to write
     55                psDB *db                // Database handle for "concepts" update
     56               )
     57{
     58    pmConceptsWriteFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL);
     59
     60    pmHDU *hdu = fpa->hdu;              // The HDU
     61    if (hdu && !pmHDUWrite(hdu, fits)) {
     62        psError(PS_ERR_IO, false, "Unable to write HDU for FPA.\n");
     63        return false;
     64    }
     65
     66    bool success = true;                // Success of writing
     67    psArray *chips = fpa->chips;        // Array of chips
     68    for (int i = 0; i < chips->n; i++) {
     69        pmChip *chip = chips->data[i];  // The chip of interest
     70        success |= pmChipWrite(chip, fits, db);
     71    }
     72
     73    return success;
     74}
     75
     76
     77
     78
     79#if 0
    980static bool writeHDU(psFits *fits,      // FITS file to which to write
    1081                     pmHDU *hdu         // Pixel data to write
     
    258329    return true;
    259330}
     331#endif
  • branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.h

    r6448 r6663  
    55#include "pmFPA.h"
    66
    7 bool pmFPAWrite(psFits *fits,           // FITS file to which to write
    8                 pmFPA *fpa,             // FPA to write
    9                 psDB *db                // Database to update
     7
     8bool pmCellWrite(pmCell *cell,          // Cell to write
     9                 psFits *fits,          // FITS file to which to write
     10                 psDB *db               // Database handle for "concepts" update
     11                );
     12bool pmChipWrite(pmChip *chip,          // Chip to write
     13                 psFits *fits,          // FITS file to which to write
     14                 psDB *db               // Database handle for "concepts" update
     15                );
     16bool pmFPAWrite(pmFPA *fpa,             // FPA to write
     17                psFits *fits,           // FITS file to which to write
     18                psDB *db                // Database handle for "concepts" update
    1019               );
    1120
    12 bool pmFPAWriteMask(pmFPA *fpa,         // FPA containing mask to write
    13                     psFits *fits        // FITS file for image
    14                    );
    15 
    16 bool pmFPAWriteWeight(pmFPA *fpa,       // FPA containing mask to write
    17                       psFits *fits      // FITS file for image
    18                      );
    19 
    20 
    2121#endif
  • 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
  • branches/rel10_ifa/psModules/src/astrom/pmHDU.h

    r6575 r6663  
    2323              );
    2424
     25// Write the HDU
     26bool pmHDUWrite(pmHDU *hdu,             // HDU to write
     27                psFits *fits            // FITS file to write to
     28               );
     29
    2530#endif
  • branches/rel10_ifa/psModules/src/pslib/psMetadataItemParse.c

    r6635 r6663  
    4848    case PS_TYPE_F32:
    4949        psLogMsg(__func__, PS_LOG_WARN, "Item %s (%s) should be S32, but is F32 --- converting.\n",
    50                  item->name, comment);
     50                 item->name, item->comment);
    5151        return (int)item->data.F32;
    5252    case PS_TYPE_F64:
    5353        psLogMsg(__func__, PS_LOG_WARN, "Item %s (%s) should be S32, but is F64 --- converting.\n",
    54                  item->name, comment);
     54                 item->name, item->comment);
    5555        return (int)item->data.F64;
    5656    default:
  • branches/rel10_ifa/psModules/src/psmodules.h

    r6577 r6663  
    1919#include "pmFPAConstruct.h"
    2020#include "pmFPARead.h"
    21 //#include "pmFPAWrite.h"
     21#include "pmFPAWrite.h"
    2222#include "pmReadout.h"
    2323#include "pmFPAfile.h"
Note: See TracChangeset for help on using the changeset viewer.