IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4309


Ignore:
Timestamp:
Jun 17, 2005, 2:48:18 PM (21 years ago)
Author:
Paul Price
Message:

Reading in an FPA seems to be working!

Location:
trunk/archive/scripts/src
Files:
4 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/Makefile

    r4092 r4309  
    11SHELL = /bin/sh
    22CC = gcc
    3 CFLAGS += -O2 -g -std=c99 -I/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/include/ -D_GNU_SOURCE
     3CFLAGS += -O0 -g -std=c99 -Werror -I/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/include/ -D_GNU_SOURCE
    44PSLIB += -L/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm -lxml2 -lmysqlclient
    55LDFLAGS += $(PSLIB)
    66
    7 OBJS = test_pmFPAfromHeader.o pmCameraFromHeader.o pmFPAFromHeader.o psAdditionals.o papStuff.o
     7BUILD_OBJS = test_pmFPAfromHeader.o pmCameraFromHeader.o pmFPAFromHeader.o psAdditionals.o papStuff.o
     8BUILD_TARGET = test_pmFPAfromHeader
    89
    9 TARGET = test_pmFPAfromHeader
     10READ_OBJS = test_pmFPARead.o pmCameraFromHeader.o pmFPARead.o papFocalPlane.o psAdditionals.o papStuff.o
     11READ_TARGET = test_pmFPARead
    1012
    1113.PHONY: tags clean empty
     
    1416                $(CC) -c $(CFLAGS) $(OPTFLAGS) $<
    1517
    16 $(TARGET):      $(OBJS)
    17                 $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(OPTFLAGS)
     18$(READ_TARGET): $(READ_OBJS)
     19                $(CC) $(CFLAGS) -o $@ $(READ_OBJS) $(LDFLAGS) $(OPTFLAGS)
    1820
    1921clean:
  • trunk/archive/scripts/src/gpc1_raw.config

    r4092 r4309  
    1717CONTENTS        METADATA
    1818        # Extension name, type
    19         cell00  STR     pitch10u
    20         cell01  STR     pitch10u
    21         cell10  STR     pitch10u
    22         cell11  STR     pitch12u
     19        xy00    STR     pitch10u
     20        xy01    STR     pitch10u
     21        xy02    STR     pitch10u
     22        xy03    STR     pitch10u
     23        xy04    STR     pitch10u
     24        xy05    STR     pitch10u
     25        xy06    STR     pitch10u
     26        xy07    STR     pitch10u
     27        xy10    STR     pitch10u
     28        xy11    STR     pitch10u
     29        xy12    STR     pitch10u
     30        xy13    STR     pitch10u
     31        xy14    STR     pitch10u
     32        xy15    STR     pitch10u
     33        xy16    STR     pitch10u
     34        xy17    STR     pitch10u
     35        xy20    STR     pitch10u
     36        xy21    STR     pitch10u
     37        xy22    STR     pitch10u
     38        xy23    STR     pitch10u
     39        xy24    STR     pitch10u
     40        xy25    STR     pitch10u
     41        xy26    STR     pitch10u
     42        xy27    STR     pitch10u
     43        xy30    STR     pitch10u
     44        xy31    STR     pitch10u
     45        xy32    STR     pitch10u
     46        xy33    STR     pitch10u
     47        xy34    STR     pitch10u
     48        xy35    STR     pitch10u
     49        xy36    STR     pitch10u
     50        xy37    STR     pitch10u
     51        xy40    STR     pitch10u
     52        xy41    STR     pitch10u
     53        xy42    STR     pitch10u
     54        xy43    STR     pitch10u
     55        xy44    STR     pitch10u
     56        xy45    STR     pitch10u
     57        xy46    STR     pitch10u
     58        xy47    STR     pitch10u
     59        xy50    STR     pitch10u
     60        xy51    STR     pitch10u
     61        xy52    STR     pitch10u
     62        xy53    STR     pitch10u
     63        xy54    STR     pitch10u
     64        xy55    STR     pitch10u
     65        xy56    STR     pitch10u
     66        xy57    STR     pitch10u
     67        xy60    STR     pitch10u
     68        xy61    STR     pitch10u
     69        xy62    STR     pitch10u
     70        xy63    STR     pitch10u
     71        xy64    STR     pitch10u
     72        xy65    STR     pitch10u
     73        xy66    STR     pitch10u
     74        xy67    STR     pitch10u
     75        xy70    STR     pitch10u
     76        xy71    STR     pitch10u
     77        xy72    STR     pitch10u
     78        xy73    STR     pitch10u
     79        xy74    STR     pitch10u
     80        xy75    STR     pitch10u
     81        xy76    STR     pitch10u
     82        xy77    STR     pitch10u
    2383END
    2484
     
    2686CELLS   METADATA
    2787        pitch10u        METADATA
    28                 CELL.BIASSEC    STR     VALUE:[1:10,1:614];[625:674,1:614]
    29                 CELL.TRIMSEC    STR     VALUE:[11:624,1:614]
     88                CELL.BIASSEC    STR     VALUE:[575:606,1:594]
     89                CELL.TRIMSEC    STR     VALUE:[1:574,1:594]
    3090        #       CELL.BIASSEC    STR     HEADER:BIASSEC
    31         #       CELL.TRIMSEC    STR     HEADER:TRIMSEC
     91        #       CELL.TRIMSEC    STR     HEADER:DATASEC
    3292        END
    3393
     94        # This is just in here for fun
    3495        pitch12u        METADATA
    3596                CELL.BIASSEC    STR     VALUE:[1:10,1:512];[523:574,1:512]
  • trunk/archive/scripts/src/papFocalPlane.c

    r4092 r4309  
    11#include <stdio.h>
     2#include <string.h>
    23#include "pslib.h"
    34#include "papFocalPlane.h"
    4 #include "pmRead.h"
     5#include "psAdditionals.h"
     6#include "pmFPARead.h"
    57
    68// I'm sure this code, especially the DB lookup, leaks memory something chronic....
     
    810
    911// Look for a value already cached
    10 static psMetadataItem *getValueFromCache(const psFPA *fpa, // The FPA that contains the chip
    11                                          const psChip *chip, // The chip that contains the cell
    12                                          const psCell *cell, // The cell
     12static psMetadataItem *getValueFromCache(const papFPA *fpa, // The FPA that contains the chip
     13                                         const papChip *chip, // The chip that contains the cell
     14                                         const papCell *cell, // The cell
    1315                                         const char *valueName // Name of value
    1416    )
     
    3133
    3234// Put a value that we've found into the cache
    33 static void setValueInCache(psFPA *fpa, // The FPA that contains the chip
    34                             psChip *chip, // The chip that contains the cell
    35                             psCell *cell, // The cell
     35static void setValueInCache(papFPA *fpa, // The FPA that contains the chip
     36                            papChip *chip, // The chip that contains the cell
     37                            papCell *cell, // The cell
    3638                            const char *valueName, // Name of value
    3739                            const psMetadataItem *value // Item containing the value
     
    5658
    5759
    58 static psMetadataItem *getValueFromHeader(const psFPA *fpa, // The FPA that contains the chip
    59                                           const psChip *chip, // The chip that contains the cell
    60                                           const psCell *cell, // The cell
     60static psMetadataItem *getValueFromHeader(papFPA *fpa, // The FPA that contains the chip
     61                                          papChip *chip, // The chip that contains the cell
     62                                          papCell *cell, // The cell
    6163                                          const char *valueName // Name of value
    6264    )
    6365{
     66    bool mdStatus = true;               // Status of MD lookup
     67
    6468    // Look for how to translate the concept into a FITS header name
    65     const char *header = psMetadataLookupString(fpa->fits, valueName);
     69    const char *header = psMetadataLookupString(&mdStatus, fpa->fits, valueName);
    6670    if (strlen(header) > 0) {
    6771        // We have a FITS header to look up --- search each level
     
    7074            if (cellItem) {
    7175                // XXX: Need to clean up before returning
    72                 setValueInCache(NULL, NULL, cell, cellItem);
     76                setValueInCache(NULL, NULL, cell, valueName, cellItem);
    7377                return cellItem;
    7478            }
     
    7983            if (chipItem) {
    8084                // XXX: Need to clean up before returning
    81                 setValueInCache(NULL, chip, cell, chipItem);
     85                setValueInCache(NULL, chip, cell, valueName, chipItem);
    8286                return chipItem;
    8387            }
     
    8892            if (fpaItem) {
    8993                // XXX: Need to clean up before returning
    90                 setValueInCache(fpa, chip, cell, fpaItem);
     94                setValueInCache(fpa, chip, cell, valueName, fpaItem);
    9195                return fpaItem;
    9296            }
     
    100104
    101105// Look for a default
    102 static psMetadataItem *getValueFromDefault(const psFPA *fpa, // The FPA that contains the chip
    103                                            const psChip *chip, // The chip that contains the cell
    104                                            const psCell *cell, // The cell
     106static psMetadataItem *getValueFromDefault(papFPA *fpa, // The FPA that contains the chip
     107                                           papChip *chip, // The chip that contains the cell
     108                                           papCell *cell, // The cell
    105109                                           const char *valueName // Name of value
    106110    )
    107111{
    108     psMetadataItem *defItem = psMetadataLookup(fpa->defaults, valueName);
     112    psMetadataItem *defItem = psMetadataLookup((psMetadata*)fpa->defaults, valueName);
    109113    if (defItem) {
    110         setValueInCache(fpa, chip, cell, defItem);
     114        setValueInCache(fpa, chip, cell, valueName, defItem);
    111115    }
    112116    return defItem;                     // defItem is either NULL or points to what was desired
     
    115119
    116120// Look for a database lookup
    117 static psMetadataItem *getValueFromDB(const psFPA *fpa, // The FPA that contains the chip
    118                                       const psChip *chip, // The chip that contains the cell
    119                                       const psCell *cell, // The cell
     121static psMetadataItem *getValueFromDB(papFPA *fpa, // The FPA that contains the chip
     122                                      papChip *chip, // The chip that contains the cell
     123                                      papCell *cell, // The cell
    120124                                      const char *valueName // Name of value
    121125    )
     
    123127    if (fpa->db) {
    124128        // The database has been initialised
    125 
    126         psMetadata *dbLookup = psMetadataLookupMD(fpa->database, valueName);
     129        bool mdStatus = true;           // Status of MD lookup
     130        psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, fpa->database, valueName);
    127131        if (dbLookup) {
    128             const char *tableName = psMetadataLookupString(dbLookup, "TABLE"); // Name of the table
    129             const char *colName = psMetadataLookupString(dbLookup, "COLUMN"); // Name of the column
    130             const char *givenCols = psMetadataLookupString(dbLookup, "GIVENDBCOL");     // Name of "where" columns
    131             const char *givenPS = psMetadataLookupString(dbLookup, "GIVENPS"); // Values for "where" columns
     132            const char *tableName = psMetadataLookupString(&mdStatus, dbLookup, "TABLE"); // Name of the table
     133            const char *colName = psMetadataLookupString(&mdStatus, dbLookup, "COLUMN"); // Name of the column
     134            const char *givenCols = psMetadataLookupString(&mdStatus, dbLookup, "GIVENDBCOL");  // Name of "where" columns
     135            const char *givenPS = psMetadataLookupString(&mdStatus, dbLookup, "GIVENPS"); // Values for "where" columns
    132136           
    133137            // Now, need to get the "given"s
     
    135139                psList *cols = papSplit(givenCols, ",;"); // List of column names
    136140                psList *values = papSplit(givenPS, ",;"); // List of value names for the columns
    137                 psMetadata *selection = psMetadataAlloc(NULL); // The stuff to select in the DB
     141                psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
    138142                if (cols->size != values->size) {
    139143                    psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
     
    159163                            }
    160164                            if (! item) {
    161                                 psLogMsg(__func__, PS_LOG_ERR, "Unable to find the value name %s for DB "
     165                                psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
    162166                                         " lookup on %s --- ignored.\n", name, valueName);
    163167                            } else {
     
    199203}
    200204
    201 psMetadataItem *psCellGetValue(const psFPA *fpa, // The FPA that contains the cell
     205psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
    202206                               const char *chipName, // The name of the chip
    203207                               const char *cellName, // The name of the cell
     
    205209                               )
    206210{
    207     psChip *chip = psMetadataLookupChip(fpa, chipName); // The chip
    208     psCell *cell = psMetadataLookupCell(chip, cellName); // The cell
     211    bool mdStatus = true;               // Status of MD lookup
     212    papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
     213    papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell
    209214
    210215    // Try cache, headers, database, defaults in order
     
    223228}
    224229
    225 float psCellGetValueF32(const psFPA *fpa, // The FPA that contains the cell
     230float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
    226231                        const char *chipName, // The name of the chip
    227232                        const char *cellName, // The name of the cell
     
    244249}
    245250
    246 int psCellGetValueS32(const psFPA *fpa, // The FPA that contains the cell
     251int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
    247252                      const char *chipName, // The name of the chip
    248253                      const char *cellName, // The name of the cell
     
    250255    )
    251256{
    252     int value = NAN;                    // Result
     257    int value = 0;                      // Result
    253258    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    254259    if (! item) {
     
    266271
    267272
    268 double psCellGetValueF64(const psFPA *fpa, // The FPA that contains the cell
     273double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
    269274                         const char *chipName, // The name of the chip
    270275                         const char *cellName, // The name of the cell
     
    288293
    289294
    290 psString psCellGetValueString(const psFPA *fpa, // The FPA that contains the cell
     295psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
    291296                              const char *chipName, // The name of the chip
    292297                              const char *cellName, // The name of the cell
     
    308313    return value;
    309314}
     315
     316//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     317// Allocators
     318//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     319
     320papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info
     321                    psMetadata *database, // Database lookup info
     322                    psMetadata *defaults, // Defaults info
     323                    psDB *db            // Database handle
     324    )
     325{
     326    papFPA *fpa = psAlloc(sizeof(papFPA));// The FPA
     327    psMemSetDeallocator(fpa, (psFreeFcn)p_papFPAFree);
     328
     329    // Fill in the various components
     330    fpa->fits = psMemIncrRefCounter(fits);
     331    fpa->database = psMemIncrRefCounter(database);
     332    fpa->defaults = psMemIncrRefCounter(defaults);
     333
     334    fpa->values = psMetadataAlloc();
     335    fpa->header = NULL;
     336    fpa->db = psMemIncrRefCounter(db);
     337
     338    fpa->chips = psMetadataAlloc();
     339    fpa->images = NULL;
     340
     341    return fpa;
     342}
     343
     344void p_papFPAFree(papFPA *fpa)
     345{
     346    psFree((psPtr)fpa->fits);
     347    psFree((psPtr)fpa->database);
     348    psFree((psPtr)fpa->defaults);
     349
     350    psFree(fpa->values);
     351    psFree(fpa->header);
     352    if (fpa->db) {
     353        psDBCleanup((psDB*)fpa->db);
     354    }
     355
     356    psFree(fpa->chips);
     357    psFree(fpa->images);
     358}
     359
     360papChip *papChipAlloc(papFPA *fpa,              // FPA to which the chip belongs
     361                    const char *name    // Name of the chip
     362    )
     363{
     364    papChip *chip = psAlloc(sizeof(papChip)); // The chip
     365    psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree);
     366    psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Added on allocation of chip", chip);
     367
     368    chip->values = psMetadataAlloc();
     369    chip->header = NULL;
     370
     371    chip->cells = psMetadataAlloc();
     372    chip->images = NULL;
     373
     374    return chip;
     375}
     376
     377void p_papChipFree(papChip *chip)
     378{
     379    psFree(chip->values);
     380    psFree(chip->header);
     381    psFree(chip->cells);
     382    psFree(chip->images);
     383}
     384
     385papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
     386                    const char *name,   // Name of the cell
     387                    int nReadouts       // Number of readouts contained
     388    )
     389{
     390    papCell *cell = psAlloc(sizeof(papCell)); // The cell
     391    psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree);
     392    psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Added on allocation of cell", cell);
     393
     394    cell->values = psMetadataAlloc();
     395    cell->header = NULL;
     396
     397    cell->readouts = psArrayAlloc(nReadouts);
     398    cell->images = NULL;
     399
     400    return cell;
     401}
     402
     403void p_papCellFree(papCell *cell)
     404{
     405    psFree(cell->values);
     406    psFree(cell->header);
     407    psFree(cell->readouts);
     408    psFree(cell->images);
     409}
     410
     411papReadout *papReadoutAlloc(papCell *cell, // Cell to which the readout belongs
     412                            int readoutNum, // Number of the readout
     413                            psImage *image, // The pixels
     414                            psList *overscans, // The overscan images
     415                            int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
     416    )
     417{
     418    papReadout *readout = psAlloc(sizeof(papReadout));
     419    psMemSetDeallocator(readout, (psFreeFcn)p_papReadoutFree);
     420    psArray *readouts = cell->readouts;
     421    if (readoutNum >= readouts->nalloc) {
     422        readouts = psArrayRealloc(readouts, readoutNum);
     423        cell->readouts = readouts;
     424    }
     425    readouts->data[readoutNum] = readout;
     426   
     427    // Set the components
     428    readout->image = image;
     429    readout->overscans = overscans;
     430   
     431    readout->values = psMetadataAlloc();
     432   
     433    *(int*)&readout->col0 = col0;
     434    *(int*)&readout->row0 = row0;
     435    *(int*)&readout->colParity = colParity;
     436    *(int*)&readout->rowParity = rowParity;
     437    *(int*)&readout->colBins = colBin;
     438    *(int*)&readout->rowBins = rowBin;
     439
     440    return readout;
     441}
     442
     443void p_papReadoutFree(papReadout *readout)
     444{
     445    psFree(readout->image);
     446    psFree(readout->overscans);
     447    psFree(readout->values);
     448}
  • trunk/archive/scripts/src/papFocalPlane.h

    r4092 r4309  
    33
    44#include "pslib.h"
     5#include "papStuff.h"
     6
     7// Temporary metadata types
     8#define PS_META_CHIP PS_META_UNKNOWN
     9#define PS_META_CELL PS_META_UNKNOWN
     10
    511
    612typedef struct {
    713    // How to get information
    8     psMetadata *defaults;               // IPP concepts supplied with defaults
    9     psMetadata *database;               // IPP concepts supplied from database lookup
    10     psMetadata *fits;                   // IPP concepts supplied from FITS headers
    11 
     14    const psMetadata *defaults;         // IPP concepts supplied with defaults
     15    const psMetadata *database;         // IPP concepts supplied from database lookup
     16    const psMetadata *fits;             // IPP concepts supplied from FITS headers
     17   
    1218    // A source of information
     19    psMetadata *values;                 // Important values (cached)
    1320    psMetadata *header;                 // The FITS header
    1421    psDB *db;                           // The database handle
     
    1724    psMetadata *chips;                  // The chips (referred to by name)
    1825
    19     psImage *image;                     // The pixel data, if it corresponds to this level
    20 } psFPA;
     26    psArray *images;                    // The pixel data, if it corresponds to this level
     27} papFPA;
    2128
    2229typedef struct {
     
    2835    psMetadata *cells;                  // The cells (referred to by name)
    2936
    30     psImage *image;                     // The pixel data, if it corresponds to this level
    31 } psChip;
     37    psArray *images;                    // The pixel data, if it corresponds to this level
     38} papChip;
    3239
    3340typedef struct {
     
    3946    psArray *readouts;                  // The readouts (referred to by number)
    4047
    41     psImage *image;                     // The pixel data, if it corresponds to this level
    42 } psCell;
     48    psArray *images;                    // The pixel data, if it corresponds to this level
     49} papCell;
    4350
    4451
     
    5360    psList *overscans;                  // Array of subimages containing the overscan region(s)
    5461    psMetadata* values;                 // readout-level metadata
    55 } psReadout;
     62} papReadout;
    5663
    5764
    5865// Look for a particular value for a given cell (referred to by FPA+chip+cell)
    59 psMetadataItem *psCellGetValue(const psFPA *fpa, // The FPA that contains the cell
     66psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
    6067                               const char *chipName, // The name of the chip
    6168                               const char *cellName, // The name of the cell
     
    6471
    6572// Type-specific functions provided as a convenience to the user
    66 float psCellGetValueF32(const psFPA *fpa, // The FPA that contains the cell
     73float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
    6774                        const char *chipName, // The name of the chip
    6875                        const char *cellName, // The name of the cell
    6976                        const char *valueName // Name of value
    7077                        );
    71 int psCellGetValueS32(const psFPA *fpa, // The FPA that contains the cell
     78int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
    7279                      const char *chipName, // The name of the chip
    7380                      const char *cellName, // The name of the cell
    7481                      const char *valueName // Name of value
    7582                      );
    76 double psCellGetValueF64(const psFPA *fpa, // The FPA that contains the cell
     83double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
    7784                         const char *chipName, // The name of the chip
    7885                         const char *cellName, // The name of the cell
    7986                         const char *valueName // Name of value
    8087                         );
    81 psString psCellGetValueString(const psFPA *fpa, // The FPA that contains the cell
     88psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
    8289                              const char *chipName, // The name of the chip
    8390                              const char *cellName, // The name of the cell
     
    8693
    8794
     95// Allocators and deallocators
     96papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info
     97                    psMetadata *database, // Database lookup info
     98                    psMetadata *defaults, // Defaults info
     99                    psDB *db            // Database handle
     100    );
     101void p_papFPAFree(papFPA *fpa);
     102
     103papChip *papChipAlloc(papFPA *fpa,              // FPA to which the chip belongs
     104                    const char *name    // Name of the chip
     105    );
     106void p_papChipFree(papChip *chip);
     107
     108papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
     109                    const char *name,   // Name of the cell
     110                    int nReadouts       // Number of readouts contained
     111    );
     112void p_papCellFree(papCell *cell);
     113
     114papReadout *papReadoutAlloc(papCell *cell,      // Cell to which the readout belongs
     115                          int readoutNum, // Number of the readout
     116                          psImage *image, // The pixels
     117                          psList *overscans, // The overscan images
     118                          int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
     119    );
     120void p_papReadoutFree(papReadout *readout);
     121
    88122#endif
  • trunk/archive/scripts/src/papStuff.c

    r4092 r4309  
    22#include <string.h>
    33#include "pslib.h"
     4#include "papStuff.h"
    45
    56// Split string on given characters
     
    2324            } else {
    2425                // We're at the end of the word
    25                 char *word = psStringNCopy(&string[start], i - start);
     26                psString word = psStringNCopy(&string[start], i - start);
    2627                (void)psListAdd(values, PS_LIST_TAIL, word);
    2728                start = i + 1;
     
    3132    if (start < length) {
    3233        // Copy the last word
    33         char *word = psStringNCopy(&string[start], length - start);
     34        psString word = psStringNCopy(&string[start], length - start);
    3435        (void)psListAdd(values, PS_LIST_TAIL, word);
    3536    }
  • trunk/archive/scripts/src/papStuff.h

    r4092 r4309  
    44#include "pslib.h"
    55
     6// psString is a psLib version of a char*
     7typedef char* psString;
     8
    69// Split string on given characters
    710psList *papSplit(const char *string, const char *splitters);
  • trunk/archive/scripts/src/pmCameraFromHeader.c

    r4092 r4309  
    22#include <string.h>
    33#include "pslib.h"
    4 #include "psmodule.h"
     4#include "papmodule.h"
    55
    66// Work out what camera we have, based on the FITS header and a set of rules specified in the IPP
     
    3131        } else if (instrumentItem->type == PS_META_STR) {
    3232            psTrace(__func__, 5, "Reading instrument configuration for %s...\n", instrumentItem->name);
    33             instrument = psMetadataParseConfig(NULL, NULL, instrumentItem->data.V, true);
     33            instrument = psMetadataConfigParse(NULL, NULL, instrumentItem->data.V, true);
    3434        }
    3535
  • trunk/archive/scripts/src/pmFPAFromHeader.c

    r4092 r4309  
    8080        }
    8181
    82         bool extIsChips;                // Are the extensions chips (true) or cells (false)?
    8382        if (strcmp(extType, "CHIP") == 0) {
    84             extIsChips = true;  // Extensions are chips
    85         } else if (strcmp(extType, "CELL") == 0) {
    86             extIsChips = false; // Extensions are cells
    87         } else {
    88             psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is neither CHIP or CELL.\n");
    89             psFree(fpa);
    90             return NULL;
    91         }
    92 
    93         // Iterate through the contents
    94         psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
    95         psMetadataItem *contentItem = NULL; // Item from the metadata
    96         while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    97             const char *extName = contentItem->name; // The name of the extension
    98                
    99             if (extIsChips) {
    100                 // Content contains a list of cells
     83            // Extensions are chips; Content contains a list of cells
     84            psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
     85            psMetadataItem *contentItem = NULL; // Item from the metadata
     86            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
     87                const char *extName = contentItem->name; // The name of the extension
     88
    10189                if (contentItem->type != PS_META_STR) {
    10290                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     
    120108                    psMetadataAdd(fpa, PS_LIST_TAIL, extName, PS_META_META, "", chip);
    121109                }
    122             } else {
    123                 // Content contains a chip name and cell type
     110            }
     111            psFree(contentsIter);
     112
     113        } else if (strcmp(extType, "CELL") == 0) {
     114            // Extensions are cells; Content contains a chip name and cell type
     115            psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
     116            psMetadataItem *contentItem = NULL; // Item from the metadata
     117            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
     118                const char *extName = contentItem->name; // The name of the extension
     119
    124120                if (contentItem->type != PS_META_STR) {
    125121                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     
    148144                    }
    149145                }
    150 
    151             } // Type of extension
    152         } // Iterating through contents
    153         psFree(contentsIter);
     146            }
     147            psFree(contentsIter);
     148        } else if (strcmp(extType, "NONE") == 0) {
     149            // No extensions; Content contains metadata, each entry is a chip with its component cells
     150            psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL);
     151            psMetadataItem *contentItem = NULL; // Item from the metadata
     152            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
     153                const char *chipName = contentItem->name; // The name of the chip
     154
     155                if (contentItem->type != PS_META_STR) {
     156                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     157                             contentItem->type);
     158                } else {
     159                    const char *content = contentItem->data.V; // The content of the extension
     160                    psMetadata *chip = psMetadataAlloc(); // The chip
     161                    psList *cellNames = papSplit(content, ", "); // Split the list of cells
     162                    psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false);
     163                    char *cellName = NULL; // Name of the cell
     164                    while (cellName = psListGetAndIncrement(cellNamesIter)) {
     165                        psMetadata *cell = getCellData(camera, cellName);
     166                        psMetadataAdd(cell, PS_LIST_HEAD, "EXTENSION", PS_META_STR, "", "PHU");
     167                        psMetadataAdd(chip, PS_LIST_TAIL, cellName, PS_META_META, "", cell);
     168                    }
     169                    psFree(cellNamesIter);
     170                    // Add the chip onto the FPA
     171                    psMetadataAdd(fpa, PS_LIST_TAIL, chipName, PS_META_META, "", chip);
     172                }
     173            }
     174            psFree(contentsIter);
     175        } else {
     176            psError(PS_ERR_IO, false, "EXTENSIONS in camera definition is not CHIP, CELL or NONE.\n");
     177            psFree(fpa);
     178            return NULL;
     179        } // Type of extension
    154180
    155181    } else if (strcmp(phuType, "CHIP") == 0) {
  • trunk/archive/scripts/src/psAdditionals.c

    r4093 r4309  
    22#include <string.h>
    33#include "pslib.h"
    4 #include "psmodule.h"
     4#include "papmodule.h"
    55
    66
     
    3535
    3636
    37 const char *psMetadataLookupString(bool *status, const psMetadata *md, const char *key)
     37char *psMetadataLookupString(bool *status, const psMetadata *md, const char *key)
    3838{
    3939    psMetadataItem *item = psMetadataLookup((psMetadata*)md, key); // The metadata with instruments
    40     const char *value = NULL;           // The value to return
     40    char *value = NULL;                 // The value to return
    4141    if (!item) {
    4242        // The given key isn't in the metadata
     
    6464}
    6565
     66papChip *psMetadataLookupChip(bool *status, const psMetadata *md, const char *key)
     67{
     68    psMetadataItem *item = psMetadataLookup((psMetadata*)md, key); // The metadata with instruments
     69    papChip *value = NULL;              // The value to return
     70    if (!item) {
     71        // The given key isn't in the metadata
     72        if (status) {
     73            *status = false;
     74        } else {
     75            psError(PS_ERR_IO, true, "Couldn't find %s in the metadata.\n");
     76        }
     77    } else if (item->type != PS_META_CHIP) {
     78        // The value at the key isn't metadata
     79        if (status) {
     80            *status = false;
     81        } else {
     82            psLogMsg(__func__, PS_LOG_WARN, "%s isn't of type PS_META_CHIP, as expected.\n");
     83        }
     84        value = NULL;
     85    } else {
     86        // We have the requested metadata
     87        if (status) {
     88            *status = true;
     89        }
     90        value = item->data.V; // The requested metadata
     91    }
     92    return value;
     93}
     94
     95papCell *psMetadataLookupCell(bool *status, const psMetadata *md, const char *key)
     96{
     97    psMetadataItem *item = psMetadataLookup((psMetadata*)md, key); // The metadata with instruments
     98    papCell *value = NULL;              // The value to return
     99    if (!item) {
     100        // The given key isn't in the metadata
     101        if (status) {
     102            *status = false;
     103        } else {
     104            psError(PS_ERR_IO, true, "Couldn't find %s in the metadata.\n");
     105        }
     106    } else if (item->type != PS_META_CELL) {
     107        // The value at the key isn't metadata
     108        if (status) {
     109            *status = false;
     110        } else {
     111            psLogMsg(__func__, PS_LOG_WARN, "%s isn't of type PS_META_CHIP, as expected.\n");
     112        }
     113        value = NULL;
     114    } else {
     115        // We have the requested metadata
     116        if (status) {
     117            *status = true;
     118        }
     119        value = item->data.V; // The requested metadata
     120    }
     121    return value;
     122}
    66123
    67124void psMetadataPrint(psMetadata *md, int level)
  • trunk/archive/scripts/src/psAdditionals.h

    r4093 r4309  
    88
    99// Get a value from the metadata that we believe should be a string
    10 const char *psMetadataLookupString(bool *status, const psMetadata *md, const char *key);
     10char *psMetadataLookupString(bool *status, const psMetadata *md, const char *key);
     11
     12papChip *psMetadataLookupChip(bool *status, const psMetadata *md, const char *key);
     13papCell *psMetadataLookupCell(bool *status, const psMetadata *md, const char *key);
     14
    1115
    1216// Print out the metadata
Note: See TracChangeset for help on using the changeset viewer.