IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4386


Ignore:
Timestamp:
Jun 24, 2005, 3:05:59 PM (21 years ago)
Author:
Paul Price
Message:

Retrieval of concepts seems to be working.

Location:
trunk/archive/scripts/src
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/concepts.txt

    r4281 r4386  
    2727FPA.RADECSYS            System of RA,Dec (e.g., J2000 or ICRS)
    2828FPA.NAME                An identifier (e.g., observation number) for the FPA instance
     29FPA.DATE                UT date (YYYY-MM-DD)
     30FPA.TIME                UT time (HH:MM:SS.sss)
     31FPA.DATETIME            UT date and time (YYYY-MM-DDTHH:MM:SS.ss)
     32FPA.MJD                 Modified Julian Date
    2933
    3034Chip-level:
     
    4347CELL.GAIN               CCD gain (e/ADU)
    4448CELL.READNOISE          CCD read noise (e)
     49CELL.SATURATION         CCD saturation point (ADU)
     50CELL.BAD                CCD bad pixel point (ADU)
    4551
    46 CELL.XOFFSET            Offset on the CCD of window start in x
    47 CELL.YOFFSET            Offset on the CCD of window start in y
    4852CELL.XBIN               Binning in x
    4953CELL.YBIN               Binning in y
     
    5559value to become out of sync).  And there is no reason why (most)
    5660concepts lower down can't be specified higher up, and simply be
    57 inherited.  The exception to this is the OBSNUM (observation number),
    58 which allows an FPA to be identified given a cell, etc.
     61inherited.  The exception to this is the FPA.NAME (observation
     62number), which allows an FPA to be identified given a cell, etc.
     63
     64There are so many ways of specifying dates and times.  We probably
     65want a high-level function, psCellGetTimeObs() to sort through all of the
     66possibilities.
     67
     68Similarly with binning: CCDSUM is a common header, or the bin factors
     69might be in separate headers.
    5970
    6071
    61 These are optional:
     72Retrieval
     73=========
    6274
    63 DB.HOST         Database host name (for psDBInit)
    64 DB.NAME         Database name (for psDBInit)
    65 DB.USER         Database user name (for psDBInit)
    66 DB.PASSWORD     Database password (for psDBInit)
     75Each of the concepts can be retrieved in the following ways:
    6776
     771. FITS header translation: the camera configuration contains a
     78   "TRANSLATION" entry, which gives the concept along with the FITS
     79   header equivalent.
     80
     812. Database: the camera configuration "DATABASE" entry contains
     82   information on how to poll the database for the required concept.
     83   The DATABASE entry contains metadatas specified using the TYPE:
     84
     85        TYPE            dbEntry         TABLE           COLUMN          GIVENDBCOL      GIVENPS
     86
     87   An example DATABASE entry is:
     88
     89        CELL.GAIN       dbEntry         Camera          gain            chipId,cellId   CHIP.NAME,CELL.NAME
     90
     91   This says, in the database, you basically do: "SELECT gain IN
     92   Camera where chipId == CHIP.NAME and cellId == CELL.NAME" (where I
     93   have, no doubt, taken liberty with the SQL query).  In this case,
     94   CHIP.NAME and CELL.NAME are looked up before the query is executed,
     95   using means other than a DB query (otherwise we could get stuck in
     96   an infinite loop).
     97
     983. Defaults: the camera configuration "DEFAULTS" entry contains
     99   default values.  These default values may simply be specified, or
     100   they may be dependent upon another value.  In the latter case, an
     101   additional keyword, "CONCEPT_DEPEND", where "CONCEPT" is the
     102   concept of interest, and "DEPEND" is literal, is specified with the
     103   value being the concept on which it is dependent.  Then, the
     104   concept is a METADATA type, with the elements being values of the
     105   other concept on which it is dependent.  An example is helpful:
     106
     107        CELL.YPARITY_DEPEND     STR     CHIP.NAME
     108        CELL.YPARITY    METADATA
     109                ccd00   S32     -1
     110                ccd35   S32     1
     111        END
     112
     113   This says that the CELL.YPARITY is dependent upon the CHIP.NAME:
     114   ccd00 has negative parity, and ccd35 has positive parity.
     115
  • trunk/archive/scripts/src/gpc1_raw.config

    r4309 r4386  
    1111PHU             STR     CHIP    # The FITS file represents a single chip
    1212EXTENSIONS      STR     CELL    # The extensions represent cells
    13 EXTENSION_KEY   STR     EXTNAME # You get the extensions by looking at the EXTNAME header
    14 IDENTIFIER      STR     OBSID   # We identify the observation by the observation Id in the header
    1513
    1614# What's in the FITS file?
     
    104102# How to translate PS concepts into FITS headers
    105103TRANSLATION     METADATA
    106         FPA.AIRMASS     STR     AIRMASS
    107         FPA.FILTER      STR     FILTER
    108         FPA.POSANGLE    STR     POSANG
    109         FPA.RA          STR     OBJ-RA
    110         FPA.DEC         STR     OBJ-DEC
    111         CELL.EXPOSURE   STR     EXPTIME
    112         CELL.DARKTIME   STR     DARKTIME
    113         CELL.DATE       STR     DATE-OBS
    114         CELL.TIME       STR     TIME-OBS
     104        CELL.BIN        STR     CCDSUM
     105        CELL.SATURATION STR     SATURATE
    115106END
    116107
    117108# Default PS concepts that may be specified by value
    118109DEFAULTS        METADATA
     110        FPA.AIRMASS     F32     0.0
     111        FPA.FILTER      STR     NONE
     112        FPA.POSANGLE    F32     0.0
     113        FPA.RA          STR     0:0:0
     114        FPA.DEC         STR     0:0:0
    119115        FPA.RADECSYS    STR     ICRS
     116        FPA.NAME        S32     0
     117        FPA.MJD         F32     12345.6789
     118        CELL.EXPOSURE   F32     0.0
     119        CELL.DARKTIME   F32     0.0
     120        CELL.GAIN       F32     1.0
     121        CELL.READNOISE  F32     0.0
     122        CELL.BAD        S32     0
     123        CELL.BIN        S32     1
     124        CELL.XPARITY    S32     1
     125        CELL.YPARITY    S32     1
     126        CELL.TEST_DEPEND        STR     CELL.NAME
     127        CELL.TEST       METADATA
     128                xy00    S32     00
     129                xy01    S32     01
     130                xy02    S32     02
     131                xy03    S32     03
     132                xy04    S32     04
     133                xy05    S32     05
     134                xy06    S32     06
     135                xy07    S32     07
     136                xy10    S32     10
     137                xy11    S32     11
     138                xy12    S32     12
     139                xy13    S32     13
     140                xy14    S32     14
     141                xy15    S32     15
     142                xy16    S32     16
     143                xy17    S32     17
     144                xy20    S32     20
     145                xy21    S32     21
     146                xy22    S32     22
     147                xy23    S32     23
     148                xy24    S32     24
     149                xy25    S32     25
     150                xy26    S32     26
     151                xy27    S32     27
     152                xy30    S32     30
     153                xy31    S32     31
     154                xy32    S32     32
     155                xy33    S32     33
     156                xy34    S32     34
     157                xy35    S32     35
     158                xy36    S32     36
     159                xy37    S32     37
     160                xy40    S32     40
     161                xy41    S32     41
     162                xy42    S32     42
     163                xy43    S32     43
     164                xy44    S32     44
     165                xy45    S32     45
     166                xy46    S32     46
     167                xy47    S32     47
     168                xy50    S32     50
     169                xy51    S32     51
     170                xy52    S32     52
     171                xy53    S32     53
     172                xy54    S32     54
     173                xy55    S32     55
     174                xy56    S32     56
     175                xy57    S32     57
     176                xy60    S32     60
     177                xy61    S32     61
     178                xy62    S32     62
     179                xy63    S32     63
     180                xy64    S32     64
     181                xy65    S32     65
     182                xy66    S32     66
     183                xy67    S32     67
     184                xy70    S32     70
     185                xy71    S32     71
     186                xy72    S32     72
     187                xy73    S32     73
     188                xy74    S32     74
     189                xy75    S32     75
     190                xy76    S32     76
     191                xy77    S32     77
     192        END
    120193END
    121194
  • trunk/archive/scripts/src/ipprc.config

    r4092 r4386  
    33
    44### Database configuration
    5 DBSERVER        STR     ippdb.ifa.hawaii.edu
    6 DBUSER          STR     ipp
    7 DBPASSWORD      STR     password
     5DBSERVER        STR     ippdb.ifa.hawaii.edu    # Database host name (for psDBInit)
     6DBUSER          STR     ipp                     # Database user name (for psDBInit)
     7DBPASSWORD      STR     password                # Database password (for psDBInit)
    88
    99### Setups for each camera system
  • trunk/archive/scripts/src/lris_blue.config

    r4275 r4386  
    3232PHU             STR     FPA     # The FITS file represents an entire FPA
    3333EXTENSIONS      STR     NONE    # There are no extensions
    34 EXTENSION_KEY   STR     EXTNAME # This is actually irrelevant since there are no extensions
    35 IDENTIFIER      STR     EXPNUM  # We identify the observation by the exposure number in the header
    3634
    3735# What's in the FITS file?
  • trunk/archive/scripts/src/megacam_raw.config

    r4092 r4386  
    1212PHU             STR     FPA     # The FITS file represents an entire FPA
    1313EXTENSIONS      STR     CELL    # The extensions represent cells
    14 EXTENSION_KEY   STR     EXTNAME # You get the extensions by looking at the EXTNAME header
    15 IDENTIFIER      STR     OBSID   # We identify the observation by the observation Id in the header
    1614
    1715# What's in the FITS file?
    1816CONTENTS        METADATA
    1917        # Extension name, chip name:type
    20         amp00   STR     ccd00:science
    21         amp01   STR     ccd00:science
    22         amp02   STR     ccd01:science
    23         amp03   STR     ccd01:science
    24         guide   STR     guide:guide             # A guide CCD thrown in, just for fun
     18        amp00   STR     ccd00:left
     19        amp01   STR     ccd00:right
     20        amp02   STR     ccd01:left
     21        amp03   STR     ccd01:right
     22        amp04   STR     ccd02:left
     23        amp05   STR     ccd02:right
     24        amp06   STR     ccd03:left
     25        amp07   STR     ccd03:right
     26        amp08   STR     ccd04:left
     27        amp09   STR     ccd04:right
     28        amp10   STR     ccd05:left
     29        amp11   STR     ccd05:right
     30        amp12   STR     ccd06:left
     31        amp13   STR     ccd06:right
     32        amp14   STR     ccd07:left
     33        amp15   STR     ccd07:right
     34        amp16   STR     ccd08:left
     35        amp17   STR     ccd08:right
     36        amp18   STR     ccd09:left
     37        amp19   STR     ccd09:right
     38        amp20   STR     ccd10:left
     39        amp21   STR     ccd10:right
     40        amp22   STR     ccd11:left
     41        amp23   STR     ccd11:right
     42        amp24   STR     ccd12:left
     43        amp25   STR     ccd12:right
     44        amp26   STR     ccd13:left
     45        amp27   STR     ccd13:right
     46        amp28   STR     ccd14:left
     47        amp29   STR     ccd14:right
     48        amp30   STR     ccd15:left
     49        amp31   STR     ccd15:right
     50        amp32   STR     ccd16:left
     51        amp33   STR     ccd16:right
     52        amp34   STR     ccd17:left
     53        amp35   STR     ccd17:right
     54        amp36   STR     ccd18:left
     55        amp37   STR     ccd18:right
     56        amp38   STR     ccd19:left
     57        amp39   STR     ccd19:right
     58        amp40   STR     ccd20:left
     59        amp41   STR     ccd20:right
     60        amp42   STR     ccd21:left
     61        amp43   STR     ccd21:right
     62        amp44   STR     ccd22:left
     63        amp45   STR     ccd22:right
     64        amp46   STR     ccd23:left
     65        amp47   STR     ccd23:right
     66        amp48   STR     ccd24:left
     67        amp49   STR     ccd24:right
     68        amp50   STR     ccd25:left
     69        amp51   STR     ccd25:right
     70        amp52   STR     ccd26:left
     71        amp53   STR     ccd26:right
     72        amp54   STR     ccd27:left
     73        amp55   STR     ccd27:right
     74        amp56   STR     ccd28:left
     75        amp57   STR     ccd28:right
     76        amp58   STR     ccd29:left
     77        amp59   STR     ccd29:right
     78        amp60   STR     ccd30:left
     79        amp61   STR     ccd30:right
     80        amp62   STR     ccd31:left
     81        amp63   STR     ccd31:right
     82        amp64   STR     ccd32:left
     83        amp65   STR     ccd32:right
     84        amp66   STR     ccd33:left
     85        amp67   STR     ccd33:right
     86        amp68   STR     ccd34:left
     87        amp69   STR     ccd34:right
     88        amp70   STR     ccd35:left
     89        amp71   STR     ccd35:right
    2590END
    2691
    2792# Specify the cell data
    2893CELLS   METADATA
    29         science METADATA        # A science CCD
    30                 CELL.BIASSEC    STR     VALUE:[1:10,1:4096];[1035:1084,1:4096]
    31                 CELL.TRIMSEC    STR     VALUE:[11:1034,1:4096]
    32         #       CELL.BIASSEC    STR     HEADER:BIASSEC
    33         #       CELL.TRIMSEC    STR     HEADER:TRIMSEC
     94        left    METADATA        # Left amplifier
     95                CELL.BIASSEC    STR     HEADER:BIASSEC
     96                CELL.TRIMSEC    STR     HEADER:DATASEC
     97                CELL.XPARITY    S32     1       # We could have specified this as a DEFAULT, but this works
    3498        END
    35 
    36         guide   METADATA        # A guide CCD
    37                 CELL.BIASSEC    STR     VALUE:[1:10,1:1024];[1035:1084,1:1024]
    38                 CELL.TRIMSEC    STR     VALUE:[11:1034,1:1024]
    39         #       CELL.BIASSEC    STR     HEADER:BIASSEC
    40         #       CELL.TRIMSEC    STR     HEADER:TRIMSEC
     99        right   METADATA        # Right amplifier
     100                CELL.BIASSEC    STR     HEADER:BIASSEC
     101                CELL.TRIMSEC    STR     HEADER:DATASEC
     102                CELL.XPARITY    S32     -1      # This cell is read out in the opposite direction
    41103        END
    42                
    43104END
    44105
    45106# How to translate PS concepts into FITS headers
    46107TRANSLATION     METADATA
     108        FPA.NAME        STR     EXPNUM
    47109        FPA.AIRMASS     STR     AIRMASS
    48110        FPA.FILTER      STR     FILTER
    49         FPA.POSANGLE    STR     POSANG
    50         FPA.RA          STR     OBJ-RA
    51         FPA.DEC         STR     OBJ-DEC
    52         CELL.EXPOSURE   STR     EXPOSURE
    53         CELL.DARKTIME   STR     EXPOSURE        # No specific darktime header; use exposure time
    54         CELL.DATE       STR     DATE-OBS
    55         CELL.TIME       STR     TIME-OBS
     111        FPA.POSANGLE    STR     ROTANGLE
     112        FPA.RA          STR     RA
     113        FPA.DEC         STR     DEC
     114        FPA.RADECSYS    STR     RADECSYS
     115        FPA.MJD         STR     MJD-OBS
     116        CELL.EXPOSURE   STR     EXPTIME
     117        CELL.DARKTIME   STR     DARKTIME
     118        CELL.XBIN       STR     CCDBIN1
     119        CELL.YBIN       STR     CCDBIN2
     120        CELL.GAIN       STR     GAIN
     121        CELL.READNOISE  STR     RDNOISE
     122        CELL.SATURATION STR     SATURATE
    56123END
    57124
    58125# Default PS concepts that may be specified by value
    59126DEFAULTS        METADATA
    60         FPA.RADECSYS    STR     ICRS
     127        CELL.BAD                S32     0
     128        CELL.YPARITY_DEPEND     STR     CHIP.NAME
     129        CELL.YPARITY    METADATA
     130                ccd00   S32     -1
     131                ccd01   S32     -1
     132                ccd02   S32     -1
     133                ccd03   S32     -1
     134                ccd04   S32     -1
     135                ccd05   S32     -1
     136                ccd06   S32     -1
     137                ccd07   S32     -1
     138                ccd08   S32     -1
     139                ccd09   S32     -1
     140                ccd10   S32     -1
     141                ccd11   S32     -1
     142                ccd12   S32     -1
     143                ccd13   S32     -1
     144                ccd14   S32     -1
     145                ccd15   S32     -1
     146                ccd16   S32     -1
     147                ccd17   S32     -1
     148                ccd18   S32     1
     149                ccd19   S32     1
     150                ccd20   S32     1
     151                ccd21   S32     1
     152                ccd22   S32     1
     153                ccd23   S32     1
     154                ccd24   S32     1
     155                ccd25   S32     1
     156                ccd26   S32     1
     157                ccd27   S32     1
     158                ccd28   S32     1
     159                ccd29   S32     1
     160                ccd20   S32     1
     161                ccd31   S32     1
     162                ccd32   S32     1
     163                ccd33   S32     1
     164                ccd34   S32     1
     165                ccd35   S32     1
     166        END
    61167END
    62168
     
    64170DATABASE        METADATA
    65171        TYPE            dbEntry         TABLE           COLUMN          GIVENDBCOL      GIVENPS
    66         CELL.GAIN       dbEntry         Camera          gain            chipId,cellId   CHIP.NAME,CELL.NAME
    67         CELL.READNOISE  dbEntry         Camera          readNoise       chipId,cellId   CHIP.NAME,CELL.NAME
     172#       CELL.GAIN       dbEntry         Camera          gain            chipId,cellId   CHIP.NAME,CELL.NAME
     173#       CELL.READNOISE  dbEntry         Camera          readNoise       chipId,cellId   CHIP.NAME,CELL.NAME
    68174
    69175# A database entry refers to a particular column (COLUMN) in a
     
    72178
    73179END
     180
  • trunk/archive/scripts/src/megacam_splice.config

    r4092 r4386  
    1111PHU             STR     FPA     # The FITS file represents an entire FPA
    1212EXTENSIONS      STR     CHIP    # The extensions represent chips
    13 EXTENSION_KEY   STR     EXTNAME # You get the extensions by looking at the EXTNAME header
    14 IDENTIFIER      STR     OBSID   # We identify the observation by the observation Id in the header
    1513
    1614# What's in the FITS file?
    1715CONTENTS        METADATA
    1816        # Extension name, components
    19         ccd00           STR     LeftAmp RightAmp
    20         ccd01           STR     LeftAmp RightAmp
     17        ccd00           STR     left right
     18        ccd01           STR     left right
     19        ccd02           STR     left right
     20        ccd03           STR     left right
     21        ccd04           STR     left right
     22        ccd05           STR     left right
     23        ccd06           STR     left right
     24        ccd07           STR     left right
     25        ccd08           STR     left right
     26        ccd09           STR     left right
     27        ccd10           STR     left right
     28        ccd11           STR     left right
     29        ccd12           STR     left right
     30        ccd13           STR     left right
     31        ccd14           STR     left right
     32        ccd15           STR     left right
     33        ccd16           STR     left right
     34        ccd17           STR     left right
     35        ccd18           STR     left right
     36        ccd19           STR     left right
     37        ccd20           STR     left right
     38        ccd21           STR     left right
     39        ccd22           STR     left right
     40        ccd23           STR     left right
     41        ccd24           STR     left right
     42        ccd25           STR     left right
     43        ccd26           STR     left right
     44        ccd27           STR     left right
     45        ccd28           STR     left right
     46        ccd29           STR     left right
     47        ccd30           STR     left right
     48        ccd31           STR     left right
     49        ccd32           STR     left right
     50        ccd33           STR     left right
     51        ccd34           STR     left right
     52        ccd35           STR     left right
    2153END
    2254
    2355# Specify the cells
    2456CELLS           METADATA
    25         LeftAmp         METADATA
    26                 CELL.BIASSEC    STR     VALUE:[1:10,1:2048];[2069:2118,1:2048]
    27                 CELL.TRIMSEC    STR     VALUE:[21:1044,1:2048]
    28         #       CELL.BIASSEC    STR     HEADER:BIASSECA
    29         #       CELL.TRIMSEC    STR     HEADER:TRIMSECA
     57        left            METADATA
     58                CELL.BIASSEC    STR     HEADER:BSECA
     59                CELL.TRIMSEC    STR     HEADER:TSECA
    3060        END
    3161
    32         RightAmp        METADATA
    33                 CELL.BIASSEC    STR     VALUE:[11:20,1:2048];[2119:2168,1:2048]
    34                 CELL.TRIMSEC    STR     VALUE:[1045:2068,1:2048]
    35         #       CELL.BIASSEC    STR     HEADER:BIASSECB
    36         #       CELL.TRIMSEC    STR     HEADER:TRIMSECB
     62        right           METADATA
     63                CELL.BIASSEC    STR     HEADER:BSECB
     64                CELL.TRIMSEC    STR     HEADER:TSECB
    3765        END
    3866END
     
    4068# How to translate PS concepts into FITS headers
    4169TRANSLATION     METADATA
    42         FPA.AIRMASS     STR     AIRMASS
    43         FPA.FILTER      STR     FILTER
    44         FPA.POSANGLE    STR     POSANG
    45         FPA.RA          STR     OBJ-RA
    46         FPA.DEC         STR     OBJ-DEC
    47         CELL.EXPOSURE   STR     EXPTIME
    48         CELL.DARKTIME   STR     DARKTIME
    49         CELL.DATE       STR     DATE-OBS
    50         CELL.TIME       STR     TIME-OBS
     70        FPA.NAME        STR     EXPNUM
     71        FPA.AIRMASS     STR     AIRMASS
     72        FPA.FILTER      STR     FILTER
     73        FPA.POSANGLE    STR     ROTANGLE
     74        FPA.RA          STR     RA
     75        FPA.DEC         STR     DEC
     76        FPA.RADECSYS    STR     RADECSYS
     77        FPA.MJD         STR     MJD-OBS
     78        CELL.EXPOSURE   STR     EXPTIME
     79        CELL.DARKTIME   STR     DARKTIME
     80        CELL.XBIN       STR     CCDBIN1
     81        CELL.YBIN       STR     CCDBIN2
     82        CELL.GAIN       STR     GAIN
     83        CELL.READNOISE  STR     RDNOISE
     84        CELL.SATURATION STR     SATURATE
    5185END
     86
     87# Default PS concepts that may be specified by value
     88DEFAULTS        METADATA
     89        CELL.BAD                S32     0
     90        CELL.XPARITY            S32     1
     91        CELL.YPARITY            S32     1
     92END
     93
    5294
    5395# How to translation PS concepts into database lookups
    5496DATABASE        METADATA
    5597        TYPE            dbEntry         TABLE           COLUMN          GIVENDBCOL      GIVENPS
    56         CELL.GAIN       dbEntry         Camera          gain            chipId,cellId   CHIP.NAME,CELL.NAME
    57         CELL.READNOISE  dbEntry         Camera          readNoise       chipId,cellId   CHIP.NAME,CELL.NAME
     98#       CELL.GAIN       dbEntry         Camera          gain            chipId,cellId   CHIP.NAME,CELL.NAME
     99#       CELL.READNOISE  dbEntry         Camera          readNoise       chipId,cellId   CHIP.NAME,CELL.NAME
    58100
    59101# A database entry refers to a particular column (COLUMN) in a
  • trunk/archive/scripts/src/papFocalPlane.c

    r4309 r4386  
    4444    psMetadataItem *newItem = psMetadataItemAlloc(valueName, value->type, value->comment, value->data.V);
    4545
    46     if (fpa) {
     46    if (fpa && strncmp(valueName, "FPA", 3) == 0) {
    4747        psMetadataAddItem(fpa->values, newItem, PS_LIST_TAIL, PS_META_REPLACE);
    4848    }
    49     if (chip) {
     49    if (chip && strncmp(valueName, "CHIP", 4) == 0) {
    5050        psMetadataAddItem(chip->values, newItem, PS_LIST_TAIL, PS_META_REPLACE);
    5151    }
    52     if (cell) {
     52    if (cell && strncmp(valueName, "CELL", 4) == 0) {
    5353        psMetadataAddItem(cell->values, newItem, PS_LIST_TAIL, PS_META_REPLACE);
    5454    }
    5555
    56     psFree(newItem);
    5756}
    5857
     
    6564{
    6665    bool mdStatus = true;               // Status of MD lookup
     66    psMetadata *translation = psMetadataLookupMD(&mdStatus, fpa->camera, "TRANSLATION"); // FITS translation
     67    if (! mdStatus) {
     68        psError(PS_ERR_IO, false, "Unable to find TRANSLATION in camera configuration.\n");
     69        return NULL;
     70    }
    6771
    6872    // Look for how to translate the concept into a FITS header name
    69     const char *header = psMetadataLookupString(&mdStatus, fpa->fits, valueName);
    70     if (strlen(header) > 0) {
     73    const char *header = psMetadataLookupString(&mdStatus, translation, valueName);
     74    if (mdStatus && strlen(header) > 0) {
    7175        // We have a FITS header to look up --- search each level
    7276        if (cell->header) {
     
    110114    )
    111115{
    112     psMetadataItem *defItem = psMetadataLookup((psMetadata*)fpa->defaults, valueName);
     116    bool mdOK = true;                   // Status of MD lookup
     117    psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS");
     118    if (! mdOK) {
     119        psError(PS_ERR_IO, false, "Unable to find DEFAULTS in camera configuration.\n");
     120        return NULL;
     121    }
     122
     123    psMetadataItem *defItem = psMetadataLookup(defaults, valueName);
    113124    if (defItem) {
     125        if (defItem->type == PS_META_META) {
     126            // A dependent default
     127            psTrace(__func__, 7, "Evaluating dependent default....\n");
     128            psMetadata *dependents = defItem->data.V; // The list of dependents
     129            // Find out what it depends on
     130            psString dependName = psStringCopy(valueName);
     131            psStringAppend(&dependName, "_DEPEND");
     132            psString dependsOn = psMetadataLookupString(&mdOK, defaults, dependName);
     133            if (! mdOK) {
     134                psError(PS_ERR_IO, false, "Unable to find %s in camera configuration for dependent default"
     135                        " --- ignored\n", dependName);
     136                // XXX: Need to clean up before returning
     137                return NULL;
     138            }
     139            psFree(dependName);
     140            // Find the value of the dependent concept
     141            psMetadataItem *depItem = getValueFromCache(fpa, chip, cell, dependsOn);
     142            if (! depItem) {
     143                depItem = getValueFromHeader(fpa, chip, cell, dependsOn);
     144            }
     145            if (! depItem) {
     146                psError(PS_ERR_IO, true, "Unable to find value for %s (required for %s)\n", dependsOn,
     147                        valueName);
     148                return NULL;
     149            }
     150            if (depItem->type != PS_META_STR) {
     151                psError(PS_ERR_IO, true, "Value of %s is not of type string, as required for dependency"
     152                        " --- ignored.\n", dependsOn);
     153            }
     154
     155            defItem = psMetadataLookup(dependents, depItem->data.V);    // This is now what we were after
     156        }
    114157        setValueInCache(fpa, chip, cell, valueName, defItem);
    115158    }
     159
     160    // XXX: Need to clean up before returning
    116161    return defItem;                     // defItem is either NULL or points to what was desired
    117162}
     
    125170    )
    126171{
    127     if (fpa->db) {
    128         // The database has been initialised
    129         bool mdStatus = true;           // Status of MD lookup
    130         psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, fpa->database, valueName);
    131         if (dbLookup) {
    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
    136            
    137             // Now, need to get the "given"s
    138             if (strlen(givenCols) || strlen(givenPS)) {
    139                 psList *cols = papSplit(givenCols, ",;"); // List of column names
    140                 psList *values = papSplit(givenPS, ",;"); // List of value names for the columns
    141                 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
    142                 if (cols->size != values->size) {
    143                     psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
    144                              "the same number of entries --- ignored.\n", valueName);
     172    if (! fpa->db) {
     173        // No database initialised
     174        return NULL;
     175    }
     176
     177    bool mdStatus = true;               // Status of MD lookup
     178    psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE");
     179    if (! mdStatus) {
     180        // No error, because not everyone needs to use the DB
     181        return NULL;
     182    }
     183
     184    psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, database, valueName);
     185    if (dbLookup) {
     186        const char *tableName = psMetadataLookupString(&mdStatus, dbLookup, "TABLE"); // Name of the table
     187        const char *colName = psMetadataLookupString(&mdStatus, dbLookup, "COLUMN"); // Name of the column
     188        const char *givenCols = psMetadataLookupString(&mdStatus, dbLookup, "GIVENDBCOL");      // Name of "where" columns
     189        const char *givenPS = psMetadataLookupString(&mdStatus, dbLookup, "GIVENPS"); // Values for "where" columns
     190       
     191        // Now, need to get the "given"s
     192        if (strlen(givenCols) || strlen(givenPS)) {
     193            psList *cols = papSplit(givenCols, ",;"); // List of column names
     194            psList *values = papSplit(givenPS, ",;"); // List of value names for the columns
     195            psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
     196            if (cols->size != values->size) {
     197                psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
     198                         "the same number of entries --- ignored.\n", valueName);
     199            } else {
     200                // Iterators for the lists
     201                psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
     202                psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
     203                char *column = NULL;    // Name of the column
     204                while (column = psListGetAndIncrement(colsIter)) {
     205                    const char *name = psListGetAndIncrement(valuesIter); // Name for the value
     206                    if (!strlen(column) || !strlen(name)) {
     207                        psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
     208                                 " empty --- ignored.\n", valueName);
     209                    } else {
     210                        // Search for the value name
     211                        psMetadataItem *item = getValueFromCache(fpa, chip, cell, name);
     212                        if (! item) {
     213                            item = getValueFromHeader(fpa, chip, cell, name);
     214                        }
     215                        if (! item) {
     216                            item = getValueFromDefault(fpa, chip, cell, name);
     217                        }
     218                        if (! item) {
     219                            psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
     220                                     " lookup on %s --- ignored.\n", name, valueName);
     221                        } else {
     222                            // We need to create a new psMetadataItem.  I don't think we can't simply hack
     223                            // the existing one, since that could conceivably cause memory leaks
     224                            psMetadataItem *newItem = psMetadataItemAlloc(valueName, item->type,
     225                                                                          item->comment, item->data.V);
     226                            psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
     227                            psFree(newItem);
     228                        }
     229                    }
     230                } // Iterating through the columns
     231               
     232                psArray *dbResult = psDBSelectRows(fpa->db, tableName, selection, 2); // Lookup result
     233                // Note that we use limit=2 in order to test if there are multiple rows returned
     234               
     235                psMetadataItem *result = NULL; // The final result of the DB lookup
     236                if (dbResult->n == 0) {
     237                    psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",
     238                             valueName);
    145239                } else {
    146                     // Iterators for the lists
    147                     psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);
    148                     psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);
    149                     char *column = NULL;        // Name of the column
    150                     while (column = psListGetAndIncrement(colsIter)) {
    151                         const char *name = psListGetAndIncrement(valuesIter); // Name for the value
    152                         if (!strlen(column) || !strlen(name)) {
    153                             psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "
    154                                      " empty --- ignored.\n", valueName);
    155                         } else {
    156                             // Search for the value name
    157                             psMetadataItem *item = getValueFromCache(fpa, chip, cell, name);
    158                             if (! item) {
    159                                 item = getValueFromHeader(fpa, chip, cell, name);
    160                             }
    161                             if (! item) {
    162                                 item = getValueFromDefault(fpa, chip, cell, name);
    163                             }
    164                             if (! item) {
    165                                 psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
    166                                          " lookup on %s --- ignored.\n", name, valueName);
    167                             } else {
    168                                 // We need to create a new psMetadataItem.  I don't think we can't simply hack
    169                                 // the existing one, since that could conceivably cause memory leaks
    170                                 psMetadataItem *newItem = psMetadataItemAlloc(valueName, item->type,
    171                                                                               item->comment, item->data.V);
    172                                 psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);
    173                                 psFree(newItem);
    174                             }
    175                         }
    176                     } // Iterating through the columns
    177                    
    178                     psArray *dbResult = psDBSelectRows(fpa->db, tableName, selection, 2); // Result of lookup
    179                     // Note that we use limit=2 in order to test if there are multiple rows returned
    180 
    181                     psMetadataItem *result = NULL; // The final result of the DB lookup
    182                     if (dbResult->n == 0) {
    183                         psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",
    184                                  valueName);
    185                     } else {
    186                         if (dbResult-> n > 1) {
    187                             psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "
    188                                      " using the first one only.\n", valueName);
    189                         }
    190                         result = (psMetadataItem*)dbResult->data[0];
     240                    if (dbResult-> n > 1) {
     241                        psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "
     242                                 " using the first one only.\n", valueName);
    191243                    }
    192                     // XXX: Need to clean up before returning
    193                     return result;
     244                    result = (psMetadataItem*)dbResult->data[0];
    194245                }
    195             }
    196         } // Doing the "given"s.
    197     }
    198 
    199     // XXX: Need to clean up before returning
    200 
    201     // If we've fallen through somehow, we didn't get anything.
     246                // XXX: Need to clean up before returning
     247                return result;
     248            }
     249        }
     250    } // Doing the "given"s.
     251
     252    // Shouldn't get here
    202253    return NULL;
    203254}
     
    209260                               )
    210261{
     262    psTrace(__func__, 3, "Trying to retrieve %s for %s:%s...\n", valueName, chipName, cellName);
     263
    211264    bool mdStatus = true;               // Status of MD lookup
    212265    papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
     266    if (!mdStatus) {
     267        psError(PS_ERR_IO, false, "Unable to find chip named %s\n", chipName);
     268        return NULL;
     269    }
    213270    papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell
     271    if (!mdStatus) {
     272        psError(PS_ERR_IO, false, "Unable to find cell named %s in chip %s\n", cellName, chipName);
     273        return NULL;
     274    }
    214275
    215276    // Try cache, headers, database, defaults in order
     277    psTrace(__func__, 5, "Trying caches....\n");
    216278    psMetadataItem *item = getValueFromCache(fpa, chip, cell, valueName);
    217279    if (! item) {
     280        psTrace(__func__, 5, "Trying headers....\n");
    218281        item = getValueFromHeader(fpa, chip, cell, valueName);
    219282    }
    220283    if (! item) {
     284        psTrace(__func__, 5, "Trying database....\n");
    221285        item = getValueFromDB(fpa, chip, cell, valueName);
    222286    }
    223287    if (! item) {
     288        psTrace(__func__, 5, "Trying defaults....\n");
    224289        item = getValueFromDefault(fpa, chip, cell, valueName);
    225290    }
     
    245310    }
    246311
    247     psFree(item);
    248312    return value;
    249313}
     
    266330    }
    267331
    268     psFree(item);
    269332    return value;
    270333}
     
    288351    }
    289352
    290     psFree(item);
    291353    return value;
    292354}
     
    310372    }
    311373
    312     psFree(item);
    313374    return value;
    314375}
     
    318379//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    319380
    320 papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info
    321                     psMetadata *database, // Database lookup info
    322                     psMetadata *defaults, // Defaults info
    323                     psDB *db            // Database handle
     381papFPA *papFPAAlloc(const psMetadata *camera, // Camera configuration
     382                    psDB *db            // Database
    324383    )
    325384{
     
    327386    psMemSetDeallocator(fpa, (psFreeFcn)p_papFPAFree);
    328387
    329     // Fill in the various components
    330     fpa->fits = psMemIncrRefCounter(fits);
    331     fpa->database = psMemIncrRefCounter(database);
    332     fpa->defaults = psMemIncrRefCounter(defaults);
     388    // Fill in the components
     389    fpa->fromTangentPlane = NULL;
     390    fpa->toTangentPlane = NULL;
     391    fpa->projection = NULL;
    333392
    334393    fpa->values = psMetadataAlloc();
     394    fpa->camera = psMemIncrRefCounter((psPtr)camera);
     395    fpa->db = db;
     396    fpa->chips = psMetadataAlloc();
     397
     398    fpa->pixels = NULL;
    335399    fpa->header = NULL;
    336     fpa->db = psMemIncrRefCounter(db);
    337 
    338     fpa->chips = psMetadataAlloc();
    339     fpa->images = NULL;
    340400
    341401    return fpa;
     
    344404void p_papFPAFree(papFPA *fpa)
    345405{
    346     psFree((psPtr)fpa->fits);
    347     psFree((psPtr)fpa->database);
    348     psFree((psPtr)fpa->defaults);
     406    psFree(fpa->fromTangentPlane);
     407    psFree(fpa->toTangentPlane);
     408    psFree(fpa->projection);
    349409
    350410    psFree(fpa->values);
     411    psFree((psPtr)fpa->camera);
     412    psFree(fpa->db);
     413    psFree(fpa->chips);
     414
     415    psFree(fpa->pixels);
    351416    psFree(fpa->header);
    352     if (fpa->db) {
    353         psDBCleanup((psDB*)fpa->db);
    354     }
    355 
    356     psFree(fpa->chips);
    357     psFree(fpa->images);
    358 }
    359 
    360 papChip *papChipAlloc(papFPA *fpa,              // FPA to which the chip belongs
    361                     const char *name    // Name of the chip
     417}
     418
     419papChip *papChipAlloc(papFPA *fpa,      // FPA to which the chip belongs
     420                      const char *name  // Name of the chip
    362421    )
    363422{
    364423    papChip *chip = psAlloc(sizeof(papChip)); // The chip
    365424    psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree);
    366     psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Added on allocation of chip", chip);
     425
     426    // Push onto the FPA
     427    psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Chip added on allocation", chip);
     428
     429    // Fill in the components
     430    *(int*)&chip->col0 = 0;             // Good enough for now
     431    *(int*)&chip->row0 = 0;             // Good enough for now
     432
     433    chip->toFPA = NULL;
     434    chip->fromFPA = NULL;
    367435
    368436    chip->values = psMetadataAlloc();
     437    chip->cells = psMetadataAlloc();
     438
     439    chip->pixels = NULL;
    369440    chip->header = NULL;
    370441
    371     chip->cells = psMetadataAlloc();
    372     chip->images = NULL;
     442    psMetadataAdd(chip->values, PS_LIST_TAIL, "CHIP.NAME", PS_META_STR, "Name of the chip",
     443                  psStringCopy(name));
    373444
    374445    return chip;
     
    377448void p_papChipFree(papChip *chip)
    378449{
     450    psFree(chip->toFPA);
     451    psFree(chip->fromFPA);
     452
    379453    psFree(chip->values);
     454    psFree(chip->cells);
     455
     456    psFree(chip->pixels);
    380457    psFree(chip->header);
    381     psFree(chip->cells);
    382     psFree(chip->images);
    383458}
    384459
    385460papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
    386                     const char *name,   // Name of the cell
    387                     int nReadouts       // Number of readouts contained
     461                      const char *name, // Name of the cell
     462                      int nReadouts     // Number of readouts contained
    388463    )
    389464{
    390465    papCell *cell = psAlloc(sizeof(papCell)); // The cell
    391466    psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree);
    392     psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Added on allocation of cell", cell);
     467
     468    // Push onto the chip
     469    psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Cell added on allocation", cell);
     470
     471    // Fill in components
     472    *(int*)&cell->col0 = 0;             // Good enough for now
     473    *(int*)&cell->row0 = 0;             // Good enough for now
     474
     475    cell->toChip = NULL;
     476    cell->fromChip = NULL;
     477    cell->toFPA = NULL;
     478    cell->toTP = NULL;
     479    cell->toSky = NULL;
    393480
    394481    cell->values = psMetadataAlloc();
     482    cell->readouts = psArrayAlloc(nReadouts);
     483
     484    cell->pixels = NULL;
    395485    cell->header = NULL;
    396486
    397     cell->readouts = psArrayAlloc(nReadouts);
    398     cell->images = NULL;
     487    psMetadataAdd(cell->values, PS_LIST_TAIL, "CELL.NAME", PS_META_STR, "Name of the cell",
     488                  psStringCopy(name));
    399489
    400490    return cell;
     
    403493void p_papCellFree(papCell *cell)
    404494{
     495    psFree(cell->toChip);
     496    psFree(cell->fromChip);
     497    psFree(cell->toFPA);
     498    psFree(cell->toTP);
     499    psFree(cell->toSky);
     500
    405501    psFree(cell->values);
     502    psFree(cell->readouts);
     503
     504    psFree(cell->pixels);
    406505    psFree(cell->header);
    407     psFree(cell->readouts);
    408     psFree(cell->images);
    409506}
    410507
  • trunk/archive/scripts/src/papFocalPlane.h

    r4309 r4386  
    99#define PS_META_CELL PS_META_UNKNOWN
    1010
    11 
    1211typedef struct {
    13     // How to get information
    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    
    18     // A source of information
     12    // Astrometric transformations
     13    psPlaneDistort* fromTangentPlane;   // Transformation from tangent plane to focal plane
     14    psPlaneDistort* toTangentPlane;     // Transformation from focal plane to tangent plane
     15    psProjection *projection;           // Projection from tangent plane to sky
     16    // Information
    1917    psMetadata *values;                 // Important values (cached)
    20     psMetadata *header;                 // The FITS header
    21     psDB *db;                           // The database handle
    22 
    23     // Lower levels
     18    const psMetadata *camera;           // Camera configuration
     19    psDB *db;                           // Database
    2420    psMetadata *chips;                  // The chips (referred to by name)
    25 
    26     psArray *images;                    // The pixel data, if it corresponds to this level
     21    // FITS data
     22    psArray *pixels;                    // The pixel data, if it corresponds to this level
     23    psMetadata *header;                 // The FITS header, if it corresponds to this level
    2724} papFPA;
    2825
    2926typedef struct {
    30     // Sources of information
     27    // Offset specifying position on focal plane
     28    const int col0;                     // Offset from the left of FPA
     29    const int row0;                     // Offset from the bottom of FPA
     30    // Astrometric transformations
     31    psPlaneTransform* toFPA;            // Transformation from chip to FPA coordinates
     32    psPlaneTransform* fromFPA;          // Transformation from FPA to chip coordinates
     33    // Information
    3134    psMetadata *values;                 // Important values (cached)
    32     psMetadata *header;                 // The FITS header
    33 
    34     // Lower levels
    3535    psMetadata *cells;                  // The cells (referred to by name)
    36 
    37     psArray *images;                    // The pixel data, if it corresponds to this level
     36    // FITS data
     37    psArray *pixels;                    // The pixel data, if it corresponds to this level
     38    psMetadata *header;                 // The FITS header, if it corresponds to this level
    3839} papChip;
    3940
    4041typedef struct {
    41     // Sources of information
     42    // Offset specifying position on chip
     43    const int col0;                     // Offset from the left of chip
     44    const int row0;                     // Offset from the bottom of chip
     45    // Astrometric transformations
     46    psPlaneTransform* toChip;           // Transformations from cell to chip coordinates
     47    psPlaneTransform* fromChip;         // Transformations from cell to chip coordinates
     48    psPlaneTransform* toFPA;            // Transformations from cell to FPA coordinates
     49    psPlaneTransform* toTP;             // Transformations from cell to FPA coordinates
     50    psPlaneTransform* toSky;            // Transformations from cell to tangent plane coordinates
     51    // Information
    4252    psMetadata *values;                 // Important values (cached)
    43     psMetadata *header;                 // The FITS header
    44 
    45     // Lower levels
    4653    psArray *readouts;                  // The readouts (referred to by number)
    47 
    48     psArray *images;                    // The pixel data, if it corresponds to this level
     54    // FITS data
     55    psArray *pixels;                    // The pixel data, if it corresponds to this level
     56    psMetadata *header;                 // The FITS header, if it corresponds to this level
    4957} papCell;
    5058
    5159
    5260typedef struct {
     61    // Details for position on the cell
    5362    const int col0;                     // Offset from the left of cell.
    5463    const int row0;                     // Offset from the bottom of cell.
     
    5766    const unsigned int colBins;         // Amount of binning in x-dimension
    5867    const unsigned int rowBins;         // Amount of binning in y-dimension
    59     psImage* image;                     // The pixels
     68    // Information
     69    psImage *image;                     // The pixels
    6070    psList *overscans;                  // Array of subimages containing the overscan region(s)
    61     psMetadata* values;                 // readout-level metadata
     71    psMetadata *values;                 // readout-level metadata
    6272} papReadout;
    6373
     
    6878                               const char *cellName, // The name of the cell
    6979                               const char *valueName // Name of value
    70                                );
     80    );
    7181
    7282// Type-specific functions provided as a convenience to the user
     
    94104
    95105// Allocators and deallocators
    96 papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info
    97                     psMetadata *database, // Database lookup info
    98                     psMetadata *defaults, // Defaults info
    99                     psDB *db            // Database handle
     106papFPA *papFPAAlloc(const psMetadata *camera, // Camera configuration
     107                    psDB *db            // Database
    100108    );
    101109void p_papFPAFree(papFPA *fpa);
    102110
    103 papChip *papChipAlloc(papFPA *fpa,              // FPA to which the chip belongs
     111papChip *papChipAlloc(papFPA *fpa,      // FPA to which the chip belongs
    104112                    const char *name    // Name of the chip
    105113    );
     
    107115
    108116papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
    109                     const char *name,   // Name of the cell
    110                     int nReadouts       // Number of readouts contained
     117                      const char *name, // Name of the cell
     118                      int nReadouts     // Number of readouts contained
    111119    );
    112120void p_papCellFree(papCell *cell);
    113121
    114122papReadout *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
     123                            int readoutNum, // Number of the readout
     124                            psImage *image, // The pixels
     125                            psList *overscans, // The overscan images
     126                            int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
    119127    );
    120128void p_papReadoutFree(papReadout *readout);
  • trunk/archive/scripts/src/papmodule.h

    r4309 r4386  
    55#include "papStuff.h"
    66#include "psAdditionals.h"
     7#include "papFocalPlane.h"
  • trunk/archive/scripts/src/pmFPARead.c

    r4309 r4386  
    1212//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    1313
    14 // Copy a metadata
    15 static psMetadata *metadataCopy(psMetadata *md)
    16 {
    17     psMetadata *new = psMetadataAlloc();// The metadata to return
    18     psMetadataIterator *mdIter = psMetadataIteratorAlloc(md, PS_LIST_HEAD, NULL); // Iterator for the MD
     14// Copy metadata elements into another metadata
     15static void metadataCopy(psMetadata *to, // Metadata to which to copy
     16                         psMetadata *from // Metdata from which to copy
     17    )
     18{
     19    psMetadataIterator *mdIter = psMetadataIteratorAlloc(from, PS_LIST_HEAD, NULL); // Iterator for the MD
    1920    psMetadataItem *item = NULL;        // Item from the metadata
    2021    while (item = psMetadataGetAndIncrement(mdIter)) {
    21         if (! psMetadataAddItem(new, item, PS_LIST_TAIL, PS_META_REPLACE)) {
     22        psTrace(__func__, 9, "Adding %s to metadata...\n", item->name);
     23        if (! psMetadataAddItem(to, item, PS_LIST_TAIL, PS_META_REPLACE)) {
    2224            psLogMsg(__func__, PS_LOG_WARN, "Unable to add item (%s: %s) to metadata: ignored\n", item->name,
    2325                     item->comment);
     
    2527    }
    2628    psFree(mdIter);
    27 
    28     return new;
    2929}
    3030
     
    4646        return NULL;
    4747    } else {
    48 #if 0
    49         psMetadata *newCell = metadataCopy(cellData); // A copy of the cell, to be returned
    50         return newCell;
    51 #else
    52         return psMemIncrRefCounter(cellData);
    53 #endif
     48        return cellData;
    5449    }
    5550}
     
    6257    )
    6358{
    64     if (! psFitsMoveExtName(fits, extName)) {
     59    if (strncmp(extName, "PHU", 3) == 0) {
     60        if (!psFitsMoveExtNum(fits, 0, false)) {
     61            psError(PS_ERR_IO, false, "Unable to find PHU in FITS file!\n");
     62            return false;
     63        }
     64    } else if (! psFitsMoveExtName(fits, extName)) {
    6565        psError(PS_ERR_IO, false, "Unable to find extension %s in FITS file!\n", extName);
    6666        return false;
     
    7979
    8080    int numPlanes = 1;                  // Number of planes
    81     if (nAxis > 3) {
     81    if (nAxis == 3) {
    8282        numPlanes = psMetadataLookupS32(&mdStatus, *header, "NAXIS3");
    8383        if (!mdStatus) {
     
    251251//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    252252
    253 papFPA *pmFPARead(const psMetadata *camera, // The camera configuration
    254                   psFits *fits // A FITS file
    255     )
    256 {
     253papFPA *pmFPARead(psFits *fits, // A FITS file
     254                  const psMetadata *camera, // The camera configuration
     255                  psDB *db              // Database
     256    )
     257{
     258    papFPA *fpa = papFPAAlloc(camera, db); // The FPA to fill out
    257259    bool mdStatus = true;               // Status from metadata lookups
    258     // Get the configuration information out of the camera config
    259     psMetadata *translation = psMetadataLookupMD(&mdStatus, camera, "TRANSLATION");
    260     psMetadata *database = psMetadataLookupMD(&mdStatus, camera, "DATABASE");
    261     psMetadata *defaults = psMetadataLookupMD(&mdStatus, camera, "DEFAULTS");
    262     psDB *dbh = NULL;
    263 
    264     // Generate a build tree
    265     papFPA *fpa = papFPAAlloc(translation, database, defaults, dbh); // The FPA to fill out
    266 
    267260    const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU?
    268261    const char *extType = psMetadataLookupString(&mdStatus, camera, "EXTENSIONS"); // What's in the extensions?
     
    286279                const char *extName = contentItem->name; // The name of the extension
    287280                papChip *chip = papChipAlloc(fpa, extName); // The chip
    288                 readExtension(&(chip->images), &(chip->header), fits, extName);
    289 
     281                readExtension(&(chip->pixels), &(chip->header), fits, extName);
    290282                if (contentItem->type != PS_META_STR) {
    291283                    psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n",
     
    293285                } else {
    294286                    const char *content = contentItem->data.V; // The content of the extension
     287                    psTrace(__func__, 7, "Content of %s is: %s\n", extName, content);
    295288                    psList *cellNames = papSplit(content, " ,"); // A list of the component cells
    296289                    psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, NULL);
     
    298291                    while (cellName = psListGetAndIncrement(cellNamesIter)) {
    299292                        // Get the cell data
    300                         papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->images)->n); // The cell
    301                         cell->values = getCellData(camera, cellName);
    302                         portionCell(cell, chip->images, chip->header);
     293                        papCell *cell = papCellAlloc(chip, cellName, ((psArray*)chip->pixels)->n); // The cell
     294                        psMetadata *cellData = getCellData(camera, cellName);
     295                        metadataCopy(cell->values, cellData);
     296                        portionCell(cell, chip->pixels, chip->header);
    303297                    }
    304298                    psFree(cellNamesIter);
     
    309303        } else if (strncmp(extType, "CELL", 4) == 0) {
    310304            // Extensions are cells; Content contains a chip name and cell type
     305            psMetadata *chipNumbers = psMetadataAlloc(); // Given a chip name, holds the chip number
    311306            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    312307                const char *extName = contentItem->name; // The name of the extension
     
    324319                        const char *chipName = psListGet(contents, 0); // The name of the chip
    325320                        const char *cellType = psListGet(contents, 1); // The type of cell
     321                        psTrace(__func__, 7, "Extension is cell of type %s, from chip %s\n", cellType,
     322                                chipName);
    326323
    327324                        papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
    328325                        if (! mdStatus && ! chip) {
    329                             papChip *chip = papChipAlloc(fpa, "CHIP");
     326                            chip = papChipAlloc(fpa, chipName);
    330327                        }
    331328                        // The cell
    332329                        psArray *images = NULL;
    333330                        psMetadata *header = NULL;
     331                        psTrace(__func__, 7, "Reading extension %s\n", extName);
    334332                        readExtension(&images, &header, fits, extName);
    335                         papCell *cell = papCellAlloc(chip, extName, images->n); // The cell
    336                         cell->images = images;
     333                        psTrace(__func__, 7, "Allocating cell %s\n", cellType);
     334                        papCell *cell = papCellAlloc(chip, cellType, images->n); // The cell
     335                        cell->pixels = images;
    337336                        cell->header = header;
    338                         cell->values = getCellData(camera, extName);
    339                         portionCell(cell, cell->images, cell->header);
     337                        psMetadata *cellData = getCellData(camera, cellType);
     338                        metadataCopy(cell->values, cellData);
     339                        psTrace(__func__, 7, "Portioning cell....\n");
     340                        portionCell(cell, cell->pixels, cell->header);
     341                        psTrace(__func__, 7, "Done.\n");
    340342                    }
    341343                }
     
    344346        } else if (strncmp(extType, "NONE", 4) == 0) {
    345347            // No extensions; Content contains metadata, each entry is a chip with its component cells
    346             readExtension(&(fpa->images), &(fpa->header), fits, "PHU");
     348            readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    347349            while (contentItem = psMetadataGetAndIncrement(contentsIter)) {
    348350                const char *chipName = contentItem->name; // The name of the chip
     
    353355                } else {
    354356                    const char *content = contentItem->data.V; // The content of the extension
    355                     papChip *chip = papChipAlloc(fpa, "CHIP"); // The chip
     357                    papChip *chip = papChipAlloc(fpa, content); // The chip
    356358                    psList *cellNames = papSplit(content, ", "); // Split the list of cells
    357359                    psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false);
    358360                    char *cellName = NULL; // Name of the cell
    359361                    while (cellName = psListGetAndIncrement(cellNamesIter)) {
    360                         papCell *cell = papCellAlloc(chip, "CELL", ((psArray*)fpa->images)->n); // The cell
    361                         cell->values = getCellData(camera, cellName);
    362                         portionCell(cell, fpa->images, fpa->header);
     362                        papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
     363                        psMetadata *cellData = getCellData(camera, cellName);
     364                        metadataCopy(cell->values, cellData);
     365                        portionCell(cell, fpa->pixels, fpa->header);
    363366                    }
    364367                    psFree(cellNamesIter);
     
    380383        if (strncmp(extType, "NONE", 4) == 0) {
    381384            // There are no extensions --- only the PHU
    382             readExtension(&(fpa->images), &(fpa->header), fits, "PHU");
     385            readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU");
    383386
    384387            const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS");
     
    392395            const char *cellName = NULL;
    393396            while (cellName = psListGetAndIncrement(cellIter)) {
    394                 papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->images)->n); // The cell
    395                 cell->values = getCellData(camera, cellName);
    396                 portionCell(cell, fpa->images, fpa->header);
     397                papCell *cell = papCellAlloc(chip, cellName, ((psArray*)fpa->pixels)->n); // The cell
     398                psMetadata *cellData = getCellData(camera, cellName);
     399                metadataCopy(cell->values, cellData);
     400                portionCell(cell, fpa->pixels, fpa->header);
    397401            }
    398402            psFree(cellIter);
     
    433437                    readExtension(&images, &header, fits, extName);
    434438                    papCell *cell = papCellAlloc(chip, extName, images->n); // The cell
    435                     cell->images = images;
     439                    cell->pixels = images;
    436440                    cell->header = header;
    437                     cell->values = getCellData(camera, cellType);
    438                     portionCell(cell, cell->images, cell->header);
     441                    psMetadata *cellData = getCellData(camera, cellType);
     442                    metadataCopy(cell->values, cellData);
     443                    portionCell(cell, cell->pixels, cell->header);
    439444                }
    440445            } // Iterating through contents
     
    455460    }
    456461
    457    
    458     // Print out the build tree
     462    return fpa;
     463}
     464
     465void pmFPAPrint(papFPA *fpa             // FPA to print
     466    )
     467{
     468    // Print out the focal plane
    459469    psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa->chips, PS_LIST_HEAD, NULL); // Iterator for FPA
    460470    psMetadataItem *fpaItem = NULL;     // Item from metadata
    461471    psTrace("pmFPARead", 0, "FPA:\n");
    462     if (fpa->images) {
     472    if (fpa->pixels) {
    463473        psTrace("pmFPARead", 1, "---> FPA contains pixels.\n");
    464474    }
     
    469479            psTrace("pmFPARead", 1, "Chip: %s\n", fpaItem->name);
    470480            papChip *chip = fpaItem->data.V; // The chip
    471             if (chip->images) {
     481            if (chip->pixels) {
    472482                psTrace("pmFPARead", 2, "---> Chip contains pixels.\n");
    473483            }
     
    481491                    psTrace("pmFPARead", 2, "Cell: %s\n", chipItem->name);
    482492                    papCell *cell = chipItem->data.V; // The cell
    483                     if (cell->images) {
     493                    if (cell->pixels) {
    484494                        psTrace("pmFPARead", 3, "---> Cell contains pixels.\n");
    485495                    }
     
    494504                          case PS_META_F32:
    495505                            psTrace("pmFPARead", 3, "%s: %f\n", cellItem->name, cellItem->data.F32);
     506                            break;
     507                          case PS_META_S32:
     508                            psTrace("pmFPARead", 3, "%s: %d\n", cellItem->name, cellItem->data.S32);
    496509                            break;
    497510                          case PS_META_META:
     
    527540    } // Iterating through FPA
    528541    psFree(fpaIter);
    529 
    530     return fpa;
    531 
    532 }
     542}
  • trunk/archive/scripts/src/pmFPARead.h

    r4309 r4386  
    55
    66// Read the contents of a FITS file (format specified by the camera configuration) into memory
    7 papFPA *pmFPARead(const psMetadata *camera, // The camera configuration
    8                   psFits *fits // A FITS file
     7papFPA *pmFPARead(psFits *fits, // A FITS file
     8                  const psMetadata *camera, // The camera configuration
     9                  psDB *db              // Database handle
    910    );
    1011
     12// Print out the FPA
     13void pmFPAPrint(papFPA *fpa             // FPA to print
     14    );
    1115
    1216#endif
  • trunk/archive/scripts/src/psAdditionals.c

    r4309 r4386  
    4747        }
    4848    } else if (item->type != PS_META_STR) {
    49         // The value at the key isn't metadata
     49        // The value at the key isn't of the desired type
    5050        if (status) {
    5151            *status = false;
     
    7676        }
    7777    } else if (item->type != PS_META_CHIP) {
    78         // The value at the key isn't metadata
     78        // The value at the key isn't of the desired type
    7979        if (status) {
    8080            *status = false;
     
    105105        }
    106106    } else if (item->type != PS_META_CELL) {
    107         // The value at the key isn't metadata
     107        // The value at the key isn't of the desired type
    108108        if (status) {
    109109            *status = false;
  • trunk/archive/scripts/src/test_pmFPARead.c

    r4309 r4386  
    2525#endif
    2626
    27     psTraceSetLevel("readMultipleRegions", 0);
    28     psTraceSetLevel("portions", 0);
    29     psTraceSetLevel("pmFPARead", 10);
    30    
     27    (void)psTraceSetLevel(".", 10);
     28    (void)psTraceSetLevel("readMultipleRegions", 0);
     29    (void)psTraceSetLevel("portions", 0);
     30    (void)psTraceSetLevel("pmFPARead", 10);
     31    (void)psTraceSetLevel("pmFPAfromHeader", 10);
    3132
    3233    if (argc != 3) {
     
    3435        exit(EXIT_FAILURE);
    3536    }
    36     const char *configName = argv[1];
     37    const char *cameraName = argv[1];
    3738    const char *imageName = argv[2];
    38        
     39
    3940    int badLines = 0;                   // Number of bad lines in camera configuration
    40 
    41     (void)psTraceSetLevel("pmFPAfromHeader", 10);
    42 
    43     psMetadata *camera = psMetadataConfigParse(NULL, &badLines, configName, true); // Camera config
    44 
     41    psMetadata *camera = psMetadataConfigParse(NULL, &badLines, cameraName, true); // Read camera config file
    4542    if (badLines > 0) {
    46         printf("%d bad lines encountered while reading %s\n", badLines, configName);
     43        psLogMsg(__func__, PS_LOG_WARN, "%d bad lines encountered while reading camera configuration %s\n",
     44                 badLines, cameraName);
    4745    }
    4846
    49     printf("Camera information:\n");
    50     psMetadataPrint(camera, 0);
    51    
    5247    psFits *fits = psFitsAlloc(imageName);
    53     papFPA *fpa = pmFPARead(camera, fits);
     48    papFPA *fpa = pmFPARead(fits, camera, NULL);
     49    (void)pmFPAPrint(fpa);
    5450
     51    printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.XPARITY"),
     52           psCellGetValueS32(fpa, "ccd15", "right", "CELL.XPARITY"));
     53    printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"),
     54           psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY"));
     55    printf("Test: %d %d\n", psCellGetValueS32(fpa, "ccd15", "left", "CELL.YPARITY"),
     56           psCellGetValueS32(fpa, "ccd15", "right", "CELL.YPARITY"));
     57
     58//    (void)pmFPAPrint(fpa);
     59
     60    // Tidy up
    5561    psMemCheckCorruption(true);
    5662
Note: See TracChangeset for help on using the changeset viewer.