Changeset 4386
- Timestamp:
- Jun 24, 2005, 3:05:59 PM (21 years ago)
- Location:
- trunk/archive/scripts/src
- Files:
-
- 1 added
- 13 edited
-
concepts.txt (modified) (3 diffs)
-
gpc1_raw.config (modified) (2 diffs)
-
ipprc.config (modified) (1 diff)
-
lris_blue.config (modified) (1 diff)
-
lris_red.config (added)
-
megacam_raw.config (modified) (3 diffs)
-
megacam_splice.config (modified) (2 diffs)
-
papFocalPlane.c (modified) (14 diffs)
-
papFocalPlane.h (modified) (5 diffs)
-
papmodule.h (modified) (1 diff)
-
pmFPARead.c (modified) (21 diffs)
-
pmFPARead.h (modified) (1 diff)
-
psAdditionals.c (modified) (3 diffs)
-
test_pmFPARead.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/concepts.txt
r4281 r4386 27 27 FPA.RADECSYS System of RA,Dec (e.g., J2000 or ICRS) 28 28 FPA.NAME An identifier (e.g., observation number) for the FPA instance 29 FPA.DATE UT date (YYYY-MM-DD) 30 FPA.TIME UT time (HH:MM:SS.sss) 31 FPA.DATETIME UT date and time (YYYY-MM-DDTHH:MM:SS.ss) 32 FPA.MJD Modified Julian Date 29 33 30 34 Chip-level: … … 43 47 CELL.GAIN CCD gain (e/ADU) 44 48 CELL.READNOISE CCD read noise (e) 49 CELL.SATURATION CCD saturation point (ADU) 50 CELL.BAD CCD bad pixel point (ADU) 45 51 46 CELL.XOFFSET Offset on the CCD of window start in x47 CELL.YOFFSET Offset on the CCD of window start in y48 52 CELL.XBIN Binning in x 49 53 CELL.YBIN Binning in y … … 55 59 value to become out of sync). And there is no reason why (most) 56 60 concepts 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. 61 inherited. The exception to this is the FPA.NAME (observation 62 number), which allows an FPA to be identified given a cell, etc. 63 64 There are so many ways of specifying dates and times. We probably 65 want a high-level function, psCellGetTimeObs() to sort through all of the 66 possibilities. 67 68 Similarly with binning: CCDSUM is a common header, or the bin factors 69 might be in separate headers. 59 70 60 71 61 These are optional: 72 Retrieval 73 ========= 62 74 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) 75 Each of the concepts can be retrieved in the following ways: 67 76 77 1. FITS header translation: the camera configuration contains a 78 "TRANSLATION" entry, which gives the concept along with the FITS 79 header equivalent. 80 81 2. 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 98 3. 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 11 11 PHU STR CHIP # The FITS file represents a single chip 12 12 EXTENSIONS STR CELL # The extensions represent cells 13 EXTENSION_KEY STR EXTNAME # You get the extensions by looking at the EXTNAME header14 IDENTIFIER STR OBSID # We identify the observation by the observation Id in the header15 13 16 14 # What's in the FITS file? … … 104 102 # How to translate PS concepts into FITS headers 105 103 TRANSLATION 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 115 106 END 116 107 117 108 # Default PS concepts that may be specified by value 118 109 DEFAULTS 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 119 115 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 120 193 END 121 194 -
trunk/archive/scripts/src/ipprc.config
r4092 r4386 3 3 4 4 ### Database configuration 5 DBSERVER STR ippdb.ifa.hawaii.edu 6 DBUSER STR ipp 7 DBPASSWORD STR password 5 DBSERVER STR ippdb.ifa.hawaii.edu # Database host name (for psDBInit) 6 DBUSER STR ipp # Database user name (for psDBInit) 7 DBPASSWORD STR password # Database password (for psDBInit) 8 8 9 9 ### Setups for each camera system -
trunk/archive/scripts/src/lris_blue.config
r4275 r4386 32 32 PHU STR FPA # The FITS file represents an entire FPA 33 33 EXTENSIONS STR NONE # There are no extensions 34 EXTENSION_KEY STR EXTNAME # This is actually irrelevant since there are no extensions35 IDENTIFIER STR EXPNUM # We identify the observation by the exposure number in the header36 34 37 35 # What's in the FITS file? -
trunk/archive/scripts/src/megacam_raw.config
r4092 r4386 12 12 PHU STR FPA # The FITS file represents an entire FPA 13 13 EXTENSIONS STR CELL # The extensions represent cells 14 EXTENSION_KEY STR EXTNAME # You get the extensions by looking at the EXTNAME header15 IDENTIFIER STR OBSID # We identify the observation by the observation Id in the header16 14 17 15 # What's in the FITS file? 18 16 CONTENTS METADATA 19 17 # 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 25 90 END 26 91 27 92 # Specify the cell data 28 93 CELLS 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 34 98 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 41 103 END 42 43 104 END 44 105 45 106 # How to translate PS concepts into FITS headers 46 107 TRANSLATION METADATA 108 FPA.NAME STR EXPNUM 47 109 FPA.AIRMASS STR AIRMASS 48 110 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 56 123 END 57 124 58 125 # Default PS concepts that may be specified by value 59 126 DEFAULTS 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 61 167 END 62 168 … … 64 170 DATABASE METADATA 65 171 TYPE dbEntry TABLE COLUMN GIVENDBCOL GIVENPS 66 CELL.GAIN dbEntry Camera gain chipId,cellId CHIP.NAME,CELL.NAME67 CELL.READNOISE dbEntry Camera readNoise chipId,cellId CHIP.NAME,CELL.NAME172 # CELL.GAIN dbEntry Camera gain chipId,cellId CHIP.NAME,CELL.NAME 173 # CELL.READNOISE dbEntry Camera readNoise chipId,cellId CHIP.NAME,CELL.NAME 68 174 69 175 # A database entry refers to a particular column (COLUMN) in a … … 72 178 73 179 END 180 -
trunk/archive/scripts/src/megacam_splice.config
r4092 r4386 11 11 PHU STR FPA # The FITS file represents an entire FPA 12 12 EXTENSIONS STR CHIP # The extensions represent chips 13 EXTENSION_KEY STR EXTNAME # You get the extensions by looking at the EXTNAME header14 IDENTIFIER STR OBSID # We identify the observation by the observation Id in the header15 13 16 14 # What's in the FITS file? 17 15 CONTENTS METADATA 18 16 # 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 21 53 END 22 54 23 55 # Specify the cells 24 56 CELLS 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 30 60 END 31 61 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 37 65 END 38 66 END … … 40 68 # How to translate PS concepts into FITS headers 41 69 TRANSLATION 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 51 85 END 86 87 # Default PS concepts that may be specified by value 88 DEFAULTS METADATA 89 CELL.BAD S32 0 90 CELL.XPARITY S32 1 91 CELL.YPARITY S32 1 92 END 93 52 94 53 95 # How to translation PS concepts into database lookups 54 96 DATABASE METADATA 55 97 TYPE dbEntry TABLE COLUMN GIVENDBCOL GIVENPS 56 CELL.GAIN dbEntry Camera gain chipId,cellId CHIP.NAME,CELL.NAME57 CELL.READNOISE dbEntry Camera readNoise chipId,cellId CHIP.NAME,CELL.NAME98 # CELL.GAIN dbEntry Camera gain chipId,cellId CHIP.NAME,CELL.NAME 99 # CELL.READNOISE dbEntry Camera readNoise chipId,cellId CHIP.NAME,CELL.NAME 58 100 59 101 # A database entry refers to a particular column (COLUMN) in a -
trunk/archive/scripts/src/papFocalPlane.c
r4309 r4386 44 44 psMetadataItem *newItem = psMetadataItemAlloc(valueName, value->type, value->comment, value->data.V); 45 45 46 if (fpa ) {46 if (fpa && strncmp(valueName, "FPA", 3) == 0) { 47 47 psMetadataAddItem(fpa->values, newItem, PS_LIST_TAIL, PS_META_REPLACE); 48 48 } 49 if (chip ) {49 if (chip && strncmp(valueName, "CHIP", 4) == 0) { 50 50 psMetadataAddItem(chip->values, newItem, PS_LIST_TAIL, PS_META_REPLACE); 51 51 } 52 if (cell ) {52 if (cell && strncmp(valueName, "CELL", 4) == 0) { 53 53 psMetadataAddItem(cell->values, newItem, PS_LIST_TAIL, PS_META_REPLACE); 54 54 } 55 55 56 psFree(newItem);57 56 } 58 57 … … 65 64 { 66 65 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 } 67 71 68 72 // 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) { 71 75 // We have a FITS header to look up --- search each level 72 76 if (cell->header) { … … 110 114 ) 111 115 { 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); 113 124 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 } 114 157 setValueInCache(fpa, chip, cell, valueName, defItem); 115 158 } 159 160 // XXX: Need to clean up before returning 116 161 return defItem; // defItem is either NULL or points to what was desired 117 162 } … … 125 170 ) 126 171 { 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); 145 239 } 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); 191 243 } 192 // XXX: Need to clean up before returning 193 return result; 244 result = (psMetadataItem*)dbResult->data[0]; 194 245 } 195 }196 } // Doing the "given"s.197 }198 199 // XXX: Need to clean up before returning200 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 202 253 return NULL; 203 254 } … … 209 260 ) 210 261 { 262 psTrace(__func__, 3, "Trying to retrieve %s for %s:%s...\n", valueName, chipName, cellName); 263 211 264 bool mdStatus = true; // Status of MD lookup 212 265 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 } 213 270 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 } 214 275 215 276 // Try cache, headers, database, defaults in order 277 psTrace(__func__, 5, "Trying caches....\n"); 216 278 psMetadataItem *item = getValueFromCache(fpa, chip, cell, valueName); 217 279 if (! item) { 280 psTrace(__func__, 5, "Trying headers....\n"); 218 281 item = getValueFromHeader(fpa, chip, cell, valueName); 219 282 } 220 283 if (! item) { 284 psTrace(__func__, 5, "Trying database....\n"); 221 285 item = getValueFromDB(fpa, chip, cell, valueName); 222 286 } 223 287 if (! item) { 288 psTrace(__func__, 5, "Trying defaults....\n"); 224 289 item = getValueFromDefault(fpa, chip, cell, valueName); 225 290 } … … 245 310 } 246 311 247 psFree(item);248 312 return value; 249 313 } … … 266 330 } 267 331 268 psFree(item);269 332 return value; 270 333 } … … 288 351 } 289 352 290 psFree(item);291 353 return value; 292 354 } … … 310 372 } 311 373 312 psFree(item);313 374 return value; 314 375 } … … 318 379 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 319 380 320 papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info 321 psMetadata *database, // Database lookup info 322 psMetadata *defaults, // Defaults info 323 psDB *db // Database handle 381 papFPA *papFPAAlloc(const psMetadata *camera, // Camera configuration 382 psDB *db // Database 324 383 ) 325 384 { … … 327 386 psMemSetDeallocator(fpa, (psFreeFcn)p_papFPAFree); 328 387 329 // Fill in the variouscomponents330 fpa->f its = 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; 333 392 334 393 fpa->values = psMetadataAlloc(); 394 fpa->camera = psMemIncrRefCounter((psPtr)camera); 395 fpa->db = db; 396 fpa->chips = psMetadataAlloc(); 397 398 fpa->pixels = NULL; 335 399 fpa->header = NULL; 336 fpa->db = psMemIncrRefCounter(db);337 338 fpa->chips = psMetadataAlloc();339 fpa->images = NULL;340 400 341 401 return fpa; … … 344 404 void p_papFPAFree(papFPA *fpa) 345 405 { 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); 349 409 350 410 psFree(fpa->values); 411 psFree((psPtr)fpa->camera); 412 psFree(fpa->db); 413 psFree(fpa->chips); 414 415 psFree(fpa->pixels); 351 416 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 419 papChip *papChipAlloc(papFPA *fpa, // FPA to which the chip belongs 420 const char *name // Name of the chip 362 421 ) 363 422 { 364 423 papChip *chip = psAlloc(sizeof(papChip)); // The chip 365 424 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; 367 435 368 436 chip->values = psMetadataAlloc(); 437 chip->cells = psMetadataAlloc(); 438 439 chip->pixels = NULL; 369 440 chip->header = NULL; 370 441 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)); 373 444 374 445 return chip; … … 377 448 void p_papChipFree(papChip *chip) 378 449 { 450 psFree(chip->toFPA); 451 psFree(chip->fromFPA); 452 379 453 psFree(chip->values); 454 psFree(chip->cells); 455 456 psFree(chip->pixels); 380 457 psFree(chip->header); 381 psFree(chip->cells);382 psFree(chip->images);383 458 } 384 459 385 460 papCell *papCellAlloc(papChip *chip, // Chip to which the cell belongs 386 const char *name, // Name of the cell387 int nReadouts // Number of readouts contained461 const char *name, // Name of the cell 462 int nReadouts // Number of readouts contained 388 463 ) 389 464 { 390 465 papCell *cell = psAlloc(sizeof(papCell)); // The cell 391 466 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; 393 480 394 481 cell->values = psMetadataAlloc(); 482 cell->readouts = psArrayAlloc(nReadouts); 483 484 cell->pixels = NULL; 395 485 cell->header = NULL; 396 486 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)); 399 489 400 490 return cell; … … 403 493 void p_papCellFree(papCell *cell) 404 494 { 495 psFree(cell->toChip); 496 psFree(cell->fromChip); 497 psFree(cell->toFPA); 498 psFree(cell->toTP); 499 psFree(cell->toSky); 500 405 501 psFree(cell->values); 502 psFree(cell->readouts); 503 504 psFree(cell->pixels); 406 505 psFree(cell->header); 407 psFree(cell->readouts);408 psFree(cell->images);409 506 } 410 507 -
trunk/archive/scripts/src/papFocalPlane.h
r4309 r4386 9 9 #define PS_META_CELL PS_META_UNKNOWN 10 10 11 12 11 typedef 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 19 17 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 24 20 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 27 24 } papFPA; 28 25 29 26 typedef 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 31 34 psMetadata *values; // Important values (cached) 32 psMetadata *header; // The FITS header33 34 // Lower levels35 35 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 38 39 } papChip; 39 40 40 41 typedef 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 42 52 psMetadata *values; // Important values (cached) 43 psMetadata *header; // The FITS header44 45 // Lower levels46 53 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 49 57 } papCell; 50 58 51 59 52 60 typedef struct { 61 // Details for position on the cell 53 62 const int col0; // Offset from the left of cell. 54 63 const int row0; // Offset from the bottom of cell. … … 57 66 const unsigned int colBins; // Amount of binning in x-dimension 58 67 const unsigned int rowBins; // Amount of binning in y-dimension 59 psImage* image; // The pixels 68 // Information 69 psImage *image; // The pixels 60 70 psList *overscans; // Array of subimages containing the overscan region(s) 61 psMetadata *values; // readout-level metadata71 psMetadata *values; // readout-level metadata 62 72 } papReadout; 63 73 … … 68 78 const char *cellName, // The name of the cell 69 79 const char *valueName // Name of value 70 );80 ); 71 81 72 82 // Type-specific functions provided as a convenience to the user … … 94 104 95 105 // 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 106 papFPA *papFPAAlloc(const psMetadata *camera, // Camera configuration 107 psDB *db // Database 100 108 ); 101 109 void p_papFPAFree(papFPA *fpa); 102 110 103 papChip *papChipAlloc(papFPA *fpa, // FPA to which the chip belongs111 papChip *papChipAlloc(papFPA *fpa, // FPA to which the chip belongs 104 112 const char *name // Name of the chip 105 113 ); … … 107 115 108 116 papCell *papCellAlloc(papChip *chip, // Chip to which the cell belongs 109 const char *name, // Name of the cell110 int nReadouts // Number of readouts contained117 const char *name, // Name of the cell 118 int nReadouts // Number of readouts contained 111 119 ); 112 120 void p_papCellFree(papCell *cell); 113 121 114 122 papReadout *papReadoutAlloc(papCell *cell, // Cell to which the readout belongs 115 int readoutNum, // Number of the readout116 psImage *image, // The pixels117 psList *overscans, // The overscan images118 int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data123 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 119 127 ); 120 128 void p_papReadoutFree(papReadout *readout); -
trunk/archive/scripts/src/papmodule.h
r4309 r4386 5 5 #include "papStuff.h" 6 6 #include "psAdditionals.h" 7 #include "papFocalPlane.h" -
trunk/archive/scripts/src/pmFPARead.c
r4309 r4386 12 12 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 13 13 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 15 static 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 19 20 psMetadataItem *item = NULL; // Item from the metadata 20 21 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)) { 22 24 psLogMsg(__func__, PS_LOG_WARN, "Unable to add item (%s: %s) to metadata: ignored\n", item->name, 23 25 item->comment); … … 25 27 } 26 28 psFree(mdIter); 27 28 return new;29 29 } 30 30 … … 46 46 return NULL; 47 47 } 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; 54 49 } 55 50 } … … 62 57 ) 63 58 { 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)) { 65 65 psError(PS_ERR_IO, false, "Unable to find extension %s in FITS file!\n", extName); 66 66 return false; … … 79 79 80 80 int numPlanes = 1; // Number of planes 81 if (nAxis >3) {81 if (nAxis == 3) { 82 82 numPlanes = psMetadataLookupS32(&mdStatus, *header, "NAXIS3"); 83 83 if (!mdStatus) { … … 251 251 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 252 252 253 papFPA *pmFPARead(const psMetadata *camera, // The camera configuration 254 psFits *fits // A FITS file 255 ) 256 { 253 papFPA *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 257 259 bool mdStatus = true; // Status from metadata lookups 258 // Get the configuration information out of the camera config259 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 tree265 papFPA *fpa = papFPAAlloc(translation, database, defaults, dbh); // The FPA to fill out266 267 260 const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU? 268 261 const char *extType = psMetadataLookupString(&mdStatus, camera, "EXTENSIONS"); // What's in the extensions? … … 286 279 const char *extName = contentItem->name; // The name of the extension 287 280 papChip *chip = papChipAlloc(fpa, extName); // The chip 288 readExtension(&(chip->images), &(chip->header), fits, extName); 289 281 readExtension(&(chip->pixels), &(chip->header), fits, extName); 290 282 if (contentItem->type != PS_META_STR) { 291 283 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", … … 293 285 } else { 294 286 const char *content = contentItem->data.V; // The content of the extension 287 psTrace(__func__, 7, "Content of %s is: %s\n", extName, content); 295 288 psList *cellNames = papSplit(content, " ,"); // A list of the component cells 296 289 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, NULL); … … 298 291 while (cellName = psListGetAndIncrement(cellNamesIter)) { 299 292 // 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); 303 297 } 304 298 psFree(cellNamesIter); … … 309 303 } else if (strncmp(extType, "CELL", 4) == 0) { 310 304 // Extensions are cells; Content contains a chip name and cell type 305 psMetadata *chipNumbers = psMetadataAlloc(); // Given a chip name, holds the chip number 311 306 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 312 307 const char *extName = contentItem->name; // The name of the extension … … 324 319 const char *chipName = psListGet(contents, 0); // The name of the chip 325 320 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); 326 323 327 324 papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip 328 325 if (! mdStatus && ! chip) { 329 papChip *chip = papChipAlloc(fpa, "CHIP");326 chip = papChipAlloc(fpa, chipName); 330 327 } 331 328 // The cell 332 329 psArray *images = NULL; 333 330 psMetadata *header = NULL; 331 psTrace(__func__, 7, "Reading extension %s\n", extName); 334 332 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; 337 336 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"); 340 342 } 341 343 } … … 344 346 } else if (strncmp(extType, "NONE", 4) == 0) { 345 347 // 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"); 347 349 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 348 350 const char *chipName = contentItem->name; // The name of the chip … … 353 355 } else { 354 356 const char *content = contentItem->data.V; // The content of the extension 355 papChip *chip = papChipAlloc(fpa, "CHIP"); // The chip357 papChip *chip = papChipAlloc(fpa, content); // The chip 356 358 psList *cellNames = papSplit(content, ", "); // Split the list of cells 357 359 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); 358 360 char *cellName = NULL; // Name of the cell 359 361 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); 363 366 } 364 367 psFree(cellNamesIter); … … 380 383 if (strncmp(extType, "NONE", 4) == 0) { 381 384 // There are no extensions --- only the PHU 382 readExtension(&(fpa-> images), &(fpa->header), fits, "PHU");385 readExtension(&(fpa->pixels), &(fpa->header), fits, "PHU"); 383 386 384 387 const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS"); … … 392 395 const char *cellName = NULL; 393 396 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); 397 401 } 398 402 psFree(cellIter); … … 433 437 readExtension(&images, &header, fits, extName); 434 438 papCell *cell = papCellAlloc(chip, extName, images->n); // The cell 435 cell-> images = images;439 cell->pixels = images; 436 440 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); 439 444 } 440 445 } // Iterating through contents … … 455 460 } 456 461 457 458 // Print out the build tree 462 return fpa; 463 } 464 465 void pmFPAPrint(papFPA *fpa // FPA to print 466 ) 467 { 468 // Print out the focal plane 459 469 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa->chips, PS_LIST_HEAD, NULL); // Iterator for FPA 460 470 psMetadataItem *fpaItem = NULL; // Item from metadata 461 471 psTrace("pmFPARead", 0, "FPA:\n"); 462 if (fpa-> images) {472 if (fpa->pixels) { 463 473 psTrace("pmFPARead", 1, "---> FPA contains pixels.\n"); 464 474 } … … 469 479 psTrace("pmFPARead", 1, "Chip: %s\n", fpaItem->name); 470 480 papChip *chip = fpaItem->data.V; // The chip 471 if (chip-> images) {481 if (chip->pixels) { 472 482 psTrace("pmFPARead", 2, "---> Chip contains pixels.\n"); 473 483 } … … 481 491 psTrace("pmFPARead", 2, "Cell: %s\n", chipItem->name); 482 492 papCell *cell = chipItem->data.V; // The cell 483 if (cell-> images) {493 if (cell->pixels) { 484 494 psTrace("pmFPARead", 3, "---> Cell contains pixels.\n"); 485 495 } … … 494 504 case PS_META_F32: 495 505 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); 496 509 break; 497 510 case PS_META_META: … … 527 540 } // Iterating through FPA 528 541 psFree(fpaIter); 529 530 return fpa; 531 532 } 542 } -
trunk/archive/scripts/src/pmFPARead.h
r4309 r4386 5 5 6 6 // 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 7 papFPA *pmFPARead(psFits *fits, // A FITS file 8 const psMetadata *camera, // The camera configuration 9 psDB *db // Database handle 9 10 ); 10 11 12 // Print out the FPA 13 void pmFPAPrint(papFPA *fpa // FPA to print 14 ); 11 15 12 16 #endif -
trunk/archive/scripts/src/psAdditionals.c
r4309 r4386 47 47 } 48 48 } else if (item->type != PS_META_STR) { 49 // The value at the key isn't metadata49 // The value at the key isn't of the desired type 50 50 if (status) { 51 51 *status = false; … … 76 76 } 77 77 } else if (item->type != PS_META_CHIP) { 78 // The value at the key isn't metadata78 // The value at the key isn't of the desired type 79 79 if (status) { 80 80 *status = false; … … 105 105 } 106 106 } else if (item->type != PS_META_CELL) { 107 // The value at the key isn't metadata107 // The value at the key isn't of the desired type 108 108 if (status) { 109 109 *status = false; -
trunk/archive/scripts/src/test_pmFPARead.c
r4309 r4386 25 25 #endif 26 26 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); 31 32 32 33 if (argc != 3) { … … 34 35 exit(EXIT_FAILURE); 35 36 } 36 const char *c onfigName = argv[1];37 const char *cameraName = argv[1]; 37 38 const char *imageName = argv[2]; 38 39 39 40 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 45 42 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); 47 45 } 48 46 49 printf("Camera information:\n");50 psMetadataPrint(camera, 0);51 52 47 psFits *fits = psFitsAlloc(imageName); 53 papFPA *fpa = pmFPARead(camera, fits); 48 papFPA *fpa = pmFPARead(fits, camera, NULL); 49 (void)pmFPAPrint(fpa); 54 50 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 55 61 psMemCheckCorruption(true); 56 62
Note:
See TracChangeset
for help on using the changeset viewer.
