Changeset 6552
- Timestamp:
- Mar 8, 2006, 5:08:08 PM (20 years ago)
- Location:
- branches/rel10_ifa/psModules/src/astrom
- Files:
-
- 15 edited
-
Makefile.am (modified) (2 diffs)
-
pmConcepts.c (modified) (4 diffs)
-
pmConcepts.h (modified) (3 diffs)
-
pmConceptsRead.c (modified) (2 diffs)
-
pmConceptsStandard.c (modified) (3 diffs)
-
pmConceptsWrite.c (modified) (2 diffs)
-
pmFPA.c (modified) (16 diffs)
-
pmFPA.h (modified) (8 diffs)
-
pmFPAConstruct.c (modified) (7 diffs)
-
pmFPAConstruct.h (modified) (1 diff)
-
pmFPARead.c (modified) (9 diffs)
-
pmFPARead.h (modified) (2 diffs)
-
pmFPAWrite.c (modified) (1 diff)
-
pmHDU.c (modified) (8 diffs)
-
pmHDU.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/Makefile.am
r6521 r6552 5 5 libpsmoduleastrom_la_SOURCES = \ 6 6 pmFPA.c \ 7 pmFPAAstrometry.c \8 pmAstrometryObjects.c \9 7 pmFPAConstruct.c \ 10 8 pmFPARead.c \ 11 pmFPAWrite.c \ 12 pmFPAfile.c \ 13 pmFPAview.c \ 9 pmHDU.c \ 14 10 pmReadout.c \ 15 psAdditionals.c \16 11 pmConcepts.c \ 17 12 pmConceptsRead.c \ 18 13 pmConceptsWrite.c \ 19 pmConceptsStandard.c \ 20 pmChipMosaic.c 14 pmConceptsStandard.c 15 # pmChipMosaic.c 16 # pmFPAfile.c 17 # pmFPAview.c 18 # pmFPAWrite.c 19 # pmFPAAstrometry.c 20 # pmAstrometryObjects.c 21 21 22 22 psmoduleincludedir = $(includedir) 23 23 psmoduleinclude_HEADERS = \ 24 24 pmFPA.h \ 25 pmFPAAstrometry.h \26 pmAstrometryObjects.h \27 25 pmFPAConstruct.h \ 28 26 pmFPARead.h \ 29 pmFPAWrite.h \ 30 pmFPAfile.c \ 31 pmFPAview.c \ 27 pmHDU.h \ 32 28 pmReadout.h \ 33 29 psAdditionals.h \ … … 35 31 pmConceptsRead.h \ 36 32 pmConceptsWrite.h \ 37 pmConceptsStandard.h \ 38 pmChipMosaic.h 33 pmConceptsStandard.h 34 # pmChipMosaic.h 35 # pmFPAfile.c 36 # pmFPAview.c 37 # pmFPAWrite.h 38 # pmFPAAstrometry.h 39 # pmAstrometryObjects.h -
branches/rel10_ifa/psModules/src/astrom/pmConcepts.c
r6448 r6552 154 154 } 155 155 } 156 psMetadataAddItem(target, conceptItem, PS_LIST_TAIL, PS_META_REPLACE); 157 psFree(conceptItem); // Drop reference 156 if (conceptItem) { 157 psMetadataAddItem(target, conceptItem, PS_LIST_TAIL, PS_META_REPLACE); 158 psFree(conceptItem); // Drop reference 159 } 160 // No error if conceptItem is NULL, since that may only mean that the required information isn't 161 // present yet. 158 162 } 159 163 psFree(specsIter); … … 537 541 { 538 542 // Copy FPA concepts 539 target->concepts = p ap_psMetadataCopy(target->concepts, source->concepts);543 target->concepts = psMetadataCopy(target->concepts, source->concepts); 540 544 541 545 // Copy chip concepts … … 553 557 continue; 554 558 } 555 targetChip->concepts = p ap_psMetadataCopy(targetChip->concepts, sourceChip->concepts);559 targetChip->concepts = psMetadataCopy(targetChip->concepts, sourceChip->concepts); 556 560 557 561 // Copy cell concepts … … 569 573 continue; 570 574 } 571 targetCell->concepts = p ap_psMetadataCopy(targetCell->concepts, sourceCell->concepts);575 targetCell->concepts = psMetadataCopy(targetCell->concepts, sourceCell->concepts); 572 576 } 573 577 } -
branches/rel10_ifa/psModules/src/astrom/pmConcepts.h
r6448 r6552 40 40 ); 41 41 42 #if 0 43 // Some specificity to reading and writing concepts 44 typedef enum { 45 PM_CONCEPT_SOURCE_ALL = 0x00, // Do all sources 46 PM_CONCEPT_SOURCE_CAMERA = 0x01, // Do concepts that come from the camera information 47 PM_CONCEPT_SOURCE_DEFAULTS = 0x02, // Do concepts that come from defaults 48 PM_CONCEPT_SOURCE_HEADER = 0x04, // Do concepts that come from FITS header 49 PM_CONCEPT_SOURCE_DATABASE = 0x08 // Do concepts that come from database 50 } pmConceptSource; 51 #endif 52 42 53 // Set blanks, read or write concepts at the appropriate level 43 bool pmConceptsBlankFPA(pmFPA *fpa // FPA for which to set blank concepts54 bool pmConceptsBlankFPA(pmFPA *fpa // FPA for which to set blank concepts 44 55 ); 45 56 bool pmConceptsReadFPA(pmFPA *fpa, // FPA for which to read concepts … … 49 60 psDB *db // Database handle 50 61 ); 51 bool pmConceptsBlankChip(pmChip *chip // FPA for which to set blank concepts62 bool pmConceptsBlankChip(pmChip *chip // FPA for which to set blank concepts 52 63 ); 53 64 bool pmConceptsReadChip(pmChip *chip, // Chip for which to read concepts … … 55 66 ); 56 67 bool pmConceptsWriteChip(pmChip *chip, // Chip for which to write concepts 57 psDB *db // Database handle68 psDB *db // Database handle 58 69 ); 59 bool pmConceptsBlankCell(pmCell *cell // Cell for which to set blank concepts70 bool pmConceptsBlankCell(pmCell *cell // Cell for which to set blank concepts 60 71 ); 61 72 bool pmConceptsReadCell(pmCell *cell, // Cell for which to read concepts -
branches/rel10_ifa/psModules/src/astrom/pmConceptsRead.c
r6448 r6552 13 13 { 14 14 if (cell) { 15 psMetadata *camera = cell->c amera; // Camera data15 psMetadata *camera = cell->config; // Camera configuration 16 16 psMetadataItem *item = psMetadataLookup(camera, concept); 17 17 return item; … … 55 55 if (fpa->hdu) { 56 56 psMetadataItem *fpaItem = psMetadataLookup(fpa->hdu->header, keyword); 57 if (fpaItem) {58 // XXX: Need to clean up before returning59 return fpaItem;60 }61 }62 63 if (fpa->phu) {64 psMetadataItem *fpaItem = psMetadataLookup(fpa->phu, keyword);65 57 if (fpaItem) { 66 58 // XXX: Need to clean up before returning -
branches/rel10_ifa/psModules/src/astrom/pmConceptsStandard.c
r6448 r6552 663 663 if (strcasecmp(source, "VALUE") == 0) { 664 664 // Check that it's the same value as stored in the camera 665 psString checkString = psMetadataLookupStr(NULL, cell->c amera, "CELL.TRIMSEC");665 psString checkString = psMetadataLookupStr(NULL, cell->config, "CELL.TRIMSEC"); 666 666 psRegion checkRegion = psRegionFromString(checkString); 667 667 if (! COMPARE_REGIONS(&checkRegion, trimsec)) { … … 709 709 if (strcasecmp(source, "VALUE") == 0) { 710 710 // Check that it's the same value as stored in the camera 711 psString checkString = psMetadataLookupStr(NULL, cell->c amera, "CELL.BIASSEC");711 psString checkString = psMetadataLookupStr(NULL, cell->config, "CELL.BIASSEC"); 712 712 psList *checkList = psStringSplit(checkString, " ;"); 713 713 if (biassecs->n != checkList->n) { … … 763 763 764 764 if (strcasecmp(source, "HEADER") == 0) { 765 psString keywordsString = psMetadataLookupStr(NULL, cell->c amera, "CELL.BIASSEC");765 psString keywordsString = psMetadataLookupStr(NULL, cell->config, "CELL.BIASSEC"); 766 766 psList *keywords = psStringSplit(keywordsString, " ,;"); 767 767 if (biassecs->n != keywords->n) { -
branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c
r6448 r6552 73 73 ) 74 74 { 75 if (! cell->c amera) {75 if (! cell->config) { 76 76 return false; 77 77 } 78 78 if (cell) { 79 psMetadataItem *item = psMetadataLookup(cell->c amera, concept->name); // Info we want79 psMetadataItem *item = psMetadataLookup(cell->config, concept->name); // Info we want 80 80 return compareConcepts(item, concept); 81 81 } … … 138 138 psTrace(__func__, 7, "Adding to the FPA level header...\n"); 139 139 psMetadataAddItem(fpa->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE); 140 status = true;141 } else {142 // In desperation, add to the PHU --- it HAS to be in the header somewhere!143 if (! fpa->phu) {144 fpa->phu = psMetadataAlloc();145 }146 psTrace(__func__, 7, "Adding to the PHU...\n");147 psMetadataAddItem(fpa->phu, headerItem, PS_LIST_TAIL, PS_META_REPLACE);148 140 status = true; 149 141 } -
branches/rel10_ifa/psModules/src/astrom/pmFPA.c
r6448 r6552 12 12 * XXX: Should we implement non-linear cell->chip transforms? 13 13 * 14 * @version $Revision: 1.1.4. 1$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-0 2-17 17:13:41$14 * @version $Revision: 1.1.4.2 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-03-09 03:08:08 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 26 26 #include "pslib.h" 27 27 28 #include "pmHDU.h" 28 29 #include "pmFPA.h" 29 30 #include "pmConcepts.h" … … 97 98 #endif 98 99 99 psFree(cell->toChip);100 psFree(cell->toFPA);101 psFree(cell->toSky);102 100 psFree(cell->concepts); 103 101 psFree(cell->analysis); 104 psFree(cell->c amera);102 psFree(cell->config); 105 103 psFree(cell->hdu); 106 104 } … … 135 133 #endif 136 134 135 #if 0 136 137 137 psFree(chip->toFPA); 138 138 psFree(chip->fromFPA); 139 #endif 140 139 141 psFree(chip->concepts); 140 142 psFree(chip->analysis); … … 148 150 if (fpa != NULL) { 149 151 psTrace(__func__, 9, "Freeing fpa %lx\n", (size_t)fpa); 152 #if 0 153 150 154 psFree(fpa->fromTangentPlane); 151 155 psFree(fpa->toTangentPlane); 152 156 psFree(fpa->projection); 157 #endif 158 153 159 psFree(fpa->concepts); 154 160 psFree(fpa->analysis); … … 172 178 psFree(fpa->chips); 173 179 psFree(fpa->hdu); 174 psFree(fpa->phu);175 180 } 176 181 } … … 230 235 231 236 232 233 void p_pmHDUFree(p_pmHDU *hdu)234 {235 if (hdu) {236 psFree(hdu->extname);237 psFree(hdu->header);238 psFree(hdu->images);239 psFree(hdu->masks);240 psFree(hdu->weights);241 }242 }243 244 // XXX: Verify these default values for row0, col0, rowBins, colBins245 // PAP: These values may disappear in the future in favour of values in parent->concepts?246 237 pmReadout *pmReadoutAlloc(pmCell *cell) 247 238 { 248 239 pmReadout *tmpReadout = (pmReadout *) psAlloc(sizeof(pmReadout)); 249 240 250 tmpReadout->col0 = 0;251 tmpReadout->row0 = 0;252 tmpReadout->colBins = 0;253 tmpReadout->rowBins = 0;254 241 tmpReadout->image = NULL; 255 242 tmpReadout->mask = NULL; … … 276 263 pmCell *pmCellAlloc( 277 264 pmChip *chip, 278 psMetadata *cameraData,279 265 const char *name) 280 266 { 281 267 pmCell *tmpCell = (pmCell *) psAlloc(sizeof(pmCell)); 282 268 283 tmpCell->col0 = 0;284 tmpCell->row0 = 0;285 tmpCell->toChip = NULL;286 tmpCell->toFPA = NULL;287 tmpCell->toSky = NULL;288 269 tmpCell->concepts = psMetadataAlloc(); 289 270 psBool rc = psMetadataAddStr(tmpCell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, NULL, name); … … 291 272 psLogMsg(__func__, PS_LOG_WARN, "WARNING: Could not add CELL.NAME to metadata.\n"); 292 273 } 293 tmpCell->c amera = psMemIncrRefCounter(cameraData);274 tmpCell->config = NULL; 294 275 tmpCell->analysis = psMetadataAlloc(); 295 276 tmpCell->readouts = psArrayAlloc(0); … … 323 304 pmChip *tmpChip = (pmChip *) psAlloc(sizeof(pmChip)); 324 305 306 #if 0 307 325 308 tmpChip->col0 = 0; 326 309 tmpChip->row0 = 0; 327 310 tmpChip->toFPA = NULL; 328 311 tmpChip->fromFPA = NULL; 312 #endif 313 329 314 tmpChip->concepts = psMetadataAlloc(); 330 315 psBool rc = psMetadataAddStr(tmpChip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, NULL, name); … … 359 344 pmFPA *tmpFPA = (pmFPA *) psAlloc(sizeof(pmFPA)); 360 345 346 #if 0 347 361 348 tmpFPA->fromTangentPlane = NULL; 362 349 tmpFPA->toTangentPlane = NULL; 363 350 tmpFPA->projection = NULL; 351 #endif 352 364 353 tmpFPA->concepts = psMetadataAlloc(); 365 354 tmpFPA->analysis = NULL; … … 367 356 tmpFPA->chips = psArrayAlloc(0); 368 357 tmpFPA->hdu = NULL; 369 tmpFPA->phu = NULL;370 358 371 359 pmConceptsBlankFPA(tmpFPA); … … 375 363 } 376 364 377 p_pmHDU *p_pmHDUAlloc(const char *extname) 378 { 379 p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU)); 380 psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree); 381 382 hdu->extname = psStringCopy(extname); 383 hdu->header = NULL; 384 hdu->images = NULL; 385 hdu->masks = NULL; 386 hdu->weights = NULL; 365 pmHDU *pmHDUFromFPA(pmFPA *fpa // FPA for which to find HDU 366 ) 367 { 368 return fpa->hdu; 369 } 370 371 pmHDU *pmHDUFromChip(pmChip *chip // Chip for which to find HDU 372 ) 373 { 374 pmHDU *hdu = chip->hdu; // The HDU information 375 if (!hdu) { 376 hdu = pmHDUFromFPA(chip->parent); // Grab HDU info from the FPA 377 } 378 379 return hdu; 380 } 381 382 pmHDU *pmHDUFromCell(pmCell *cell // Cell for which to find HDU 383 ) 384 { 385 pmHDU *hdu = cell->hdu; // The HDU information 386 if (!hdu) { 387 hdu = pmHDUFromChip(cell->parent); // Grab HDU info from the chip 388 } 387 389 388 390 return hdu; … … 599 601 } 600 602 601 603 #if 0 602 604 bool pmCellSetWeights(pmCell *cell // Cell for which to set weights 603 605 ) … … 609 611 float bad = psMetadataLookupF32(NULL, cell->concepts, "CELL.BAD"); // Bad level 610 612 611 p _pmHDU *hdu = cell->hdu;// The data unit, containing the weight and mask originals613 pmHDU *hdu = cell->hdu; // The data unit, containing the weight and mask originals 612 614 if (!hdu) { 613 615 pmChip *chip = cell->parent; // The parent chip … … 682 684 } 683 685 684 686 #endif -
branches/rel10_ifa/psModules/src/astrom/pmFPA.h
r6518 r6552 7 7 * @author GLG, MHPCC 8 8 * 9 * @version $Revision: 1.1.4. 2$ $Name: not supported by cvs2svn $10 * @date $Date: 2006-03-0 4 03:03:28 $9 * @version $Revision: 1.1.4.3 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2006-03-09 03:08:08 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 18 18 #include <config.h> 19 19 #endif 20 20 21 #include "pslib.h" 21 #include "p sDB.h"22 #include "pmHDU.h" 22 23 23 24 /// @addtogroup AstroImage 24 25 /// @{ 25 26 26 27 27 /** Focal plane data structure … … 43 43 typedef struct 44 44 { 45 #if 0 45 46 // Astrometric transformations 46 47 psPlaneDistort* fromTangentPlane; ///< Transformation from tangent plane to focal plane 47 48 psPlaneDistort* toTangentPlane; ///< Transformation from focal plane to tangent plane 48 49 psProjection *projection; ///< Projection from tangent plane to sky 50 #endif 49 51 // Information 50 52 psMetadata *concepts; ///< Cache for PS concepts … … 72 74 typedef struct 73 75 { 76 #if 0 74 77 // Offset specifying position on focal plane 75 78 int col0; ///< Offset from the left of FPA. … … 78 81 psPlaneTransform* toFPA; ///< Transformation from chip to FPA coordinates 79 82 psPlaneTransform* fromFPA; ///< Transformation from FPA to chip coordinates 83 #endif 80 84 // Information 81 85 psMetadata *concepts; ///< Cache for PS concepts … … 100 104 typedef struct 101 105 { 102 // Offset specifying position on chip103 int col0; ///< Offset from the left of chip.104 int row0; ///< Offset from the bottom of chip.105 // Astrometric transformations106 psPlaneTransform* toChip; ///< Transformations from cell to chip coordinates107 psPlaneTransform* toFPA; ///< Transformations from cell to FPA coordinates108 psPlaneTransform* toSky; ///< Transformations from cell to sky coordinates109 // Information110 106 psMetadata *concepts; ///< Cache for PS concepts 111 psMetadata *c amera; ///< Camera Info107 psMetadata *config; ///< Cell configuration info 112 108 psMetadata *analysis; ///< Cell-level analysis metadata 113 109 psArray *readouts; ///< The readouts (referred to by number) … … 168 164 pmCell *pmCellAlloc( 169 165 pmChip *chip, ///< Parent chip 170 psMetadata *cameraData, ///< Camera data171 166 const char *name ///< Name of cell 172 167 ); … … 199 194 ); 200 195 201 /** Allocates a p_pmHDU 202 * 203 * XXX: More detailed description 204 * 205 * @return p_pmHDU* newly allocated p_pmHDU 206 */ 207 p_pmHDU *p_pmHDUAlloc(const char *extname // Extension name 208 ); 209 196 // Find the HDU in the FPA hierarchy 197 pmHDU *pmHDUFromFPA(pmFPA *fpa // FPA for which to find HDU 198 ); 199 pmHDU *pmHDUFromChip(pmChip *chip // Chip for which to find HDU 200 ); 201 pmHDU *pmHDUFromCell(pmCell *cell // Cell for which to find HDU 202 ); 210 203 211 204 /** Verify parent links. -
branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.c
r6448 r6552 11 11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 12 13 // Read data for a particular cell from the camera configuration14 static psMetadata *getCellData(const psMetadata * camera, // The camera configuration13 // Read data for a particular cell from the camera format description 14 static psMetadata *getCellData(const psMetadata *format, // The camera format description 15 15 const char *cellName // The name of the cell 16 16 ) 17 17 { 18 18 bool status = true; // Result of MD lookup 19 psMetadata *cells = psMetadataLookupMD(&status, camera, "CELLS"); // The CELLS19 psMetadata *cells = psMetadataLookupMD(&status, format, "CELLS"); // The CELLS 20 20 if (! status) { 21 21 psError(PS_ERR_IO, false, "Unable to determine CELLS of camera.\n"); … … 28 28 } 29 29 30 #if 0 31 // Need to create a new instance, so that each cell can work with its own 32 psMetadata *copy = psMetadataAlloc(); 33 psMetadataIterator *iter = psMetadataIteratorAlloc(cellData, PS_LIST_HEAD, NULL); // Iterator 34 psMetadataItem *item = NULL; // Item from iteration 35 while (item = psMetadataGetAndIncrement(iter)) { 36 if (item->type == PS_DATA_METADATA_MULTI || item->type == PS_DATA_METADATA) { 37 psLogMsg(__func__, PS_LOG_WARN, "PS_DATA_METADATA_MULTI and PS_DATA_METADATA are not supported " 38 "in a cell definition --- %s ignored.\n", item->name); 30 return cellData; 31 } 32 33 // Find a chip by name 34 static pmChip *findChip(pmFPA *fpa, // FPA in which to find the chip 35 const char *name // Name of the chip 36 ) 37 { 38 psArray *chips = fpa->chips; // Array of chips 39 for (int i = 0; i < chips->n; i++) { 40 pmChip *chip = chips->data[i]; // The chip of interest 41 psString testName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of this chip 42 if (strcmp(name, testName) == 0) { 43 return chip; 44 } 45 } 46 47 psError(PS_ERR_IO, true, "Unable to find chip %s\n", name); 48 return NULL; 49 } 50 51 // Find a cell by name 52 static pmCell *findCell(pmChip *chip, // Chip in which to find the cell 53 const char *name // Name of the cell 54 ) 55 { 56 psArray *cells = chip->cells; // Array of cells 57 for (int i = 0; i < cells->n; i++) { 58 pmCell *cell = cells->data[i]; // The cell of interest 59 psString testName = psMetadataLookupStr(NULL, cell->concepts, "CELL.NAME"); // Name of this cell 60 if (strcmp(name, testName) == 0) { 61 return cell; 62 } 63 } 64 65 psError(PS_ERR_IO, true, "Unable to find cell %s\n", name); 66 return NULL; 67 } 68 69 // Parse a list of first:second pairs in a string 70 static bool parsePairs(psArray **first, // Array of the first values 71 psArray **second, // Array of the second values 72 const char *string // The string to parse 73 ) 74 { 75 bool allOK = true; // Everything was OK? 76 psList *pairs = psStringSplit(string, " ,;"); // List of the pairs 77 *first = psArrayAlloc(pairs->n); 78 *second = psArrayAlloc(pairs->n); 79 int num = 0; 80 psListIterator *pairsIter = psListIteratorAlloc(pairs, PS_LIST_HEAD, false); // Iterator for pairs 81 psString pair = NULL; // "first:second" pair string 82 while ((pair = psListGetAndIncrement(pairsIter))) { 83 psList *firstSecond = psStringSplit(pair, ":"); // List containing the first and second 84 if (firstSecond->n != 2) { 85 psLogMsg(__func__, PS_LOG_WARN, "Badly formated first:second pair: %s --- ignored.\n", pair); 86 allOK = false; 39 87 continue; 40 88 } 41 if (! psMetadataAdd(copy, PS_LIST_TAIL, item->name, item->type, item->comment, item->data.V)) { 42 psAbort(__func__, "Should never reach here!\n"); 43 } 44 } 45 psFree(iter); 46 47 return copy; 48 #else 49 50 return cellData; 51 #endif 52 53 } 54 89 psString firstBit = psListGet(firstSecond, PS_LIST_HEAD); // The first bit 90 psString secondBit = psListGet(firstSecond, PS_LIST_TAIL); // The second bit 91 psArraySet(*first, num, firstBit); 92 psArraySet(*second, num, secondBit); 93 num++; 94 psFree(firstSecond); 95 } 96 psFree(pairsIter); 97 psFree(pairs); 98 99 return allOK; 100 } 101 102 // Get the chip name from a primary header lookup 103 static psString chipNameFromHeader(const psMetadata *format, // FORMAT within the camera format description 104 const psMetadata *header // Primary header 105 ) 106 { 107 bool mdok = true; // Result of MD lookup 108 psString chipNameHeader = psMetadataLookupStr(&mdok, format, "CHIP.NAME"); 109 if (!mdok || strlen(chipNameHeader) == 0) { 110 psError(PS_ERR_IO, false, "Unable to find CHIP.NAME in the FORMAT.\n"); 111 return false; 112 } 113 psString chipName = psMetadataLookupStr(&mdok, header, chipNameHeader); 114 if (!chipName || strlen(chipName) == 0) { 115 psError(PS_ERR_IO, false, "Unable to find %s in primary header to identify chip name.\n", chipName); 116 return NULL; 117 } 118 119 return chipName; 120 } 55 121 56 122 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 58 124 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 59 125 126 // Construct an FPA instance on the basis of a camera configuration 127 pmFPA *pmFPAConstruct(const psMetadata *camera // The camera configuration 128 ) 129 { 130 pmFPA *fpa = pmFPAAlloc(camera); // The FPA to fill out 131 132 bool mdok = true; // Status from MD lookups 133 psMetadata *components = psMetadataLookupMD(&mdok, camera, "FPA"); // FPA components 134 psMetadataIterator *componentsIter = psMetadataIteratorAlloc(components, PS_LIST_HEAD, NULL); 135 psMetadataItem *componentsItem = NULL; // Item from components 136 while ((componentsItem = psMetadataGetAndIncrement(componentsIter))) { 137 const char *chipName = componentsItem->name; // Name of the chip 138 if (componentsItem->type != PS_DATA_STRING) { 139 psLogMsg(__func__, PS_LOG_WARN, "Element %s in FPA within the camera configuration is not of " 140 "type STR (type=%x) --- ignored.\n", chipName, componentsItem->type); 141 continue; 142 } 143 pmChip *chip = pmChipAlloc(fpa, chipName); // The chip 144 psList *cellNames = psStringSplit(componentsItem->data.V, " ,;"); // List of cell names 145 psListIterator *cellNamesIter = psListIteratorAlloc(cellNames, PS_LIST_HEAD, false); // Iterator 146 psString cellName = NULL; // Name of cell 147 while ((cellName = psListGetAndIncrement(cellNamesIter))) { 148 pmCell *cell = pmCellAlloc(chip, cellName); // New cell 149 psFree(cell); // Drop reference 150 } 151 psFree(chip); // Drop reference 152 psFree(cellNamesIter); 153 } 154 psFree(componentsIter); 155 156 return fpa; 157 } 158 159 160 // Add an input file to the FPA 161 bool pmFPAAddSource(pmFPA *fpa, // FPA to which to add 162 pmChip *chip, // Chip to which to add, or NULL 163 pmCell *cell, // Cell to which to add, or NULL 164 psMetadata *phu, // Primary header of file 165 const psMetadata *format // Format of file 166 ) 167 { 168 // Just in case someone's playing silly billy... 169 if (cell && !chip) { 170 chip = cell->parent; 171 } 172 if (chip && !fpa) { 173 fpa = chip->parent; 174 } 175 176 bool mdok = true; // Status from metadata lookups 177 psMetadata *formatSpec = psMetadataLookupMD(&mdok, format, "FORMAT"); // The format specification 178 if (!mdok || !formatSpec) { 179 psError(PS_ERR_IO, false, "Unable to find FORMAT in the camera format configuration.\n"); 180 return false; 181 } 182 183 // Where does the PHU go? 184 const char *phuType = psMetadataLookupStr(&mdok, formatSpec, "PHU"); // What is the PHU? 185 if (!mdok || strlen(phuType) == 0) { 186 psError(PS_ERR_IO, false, "Unable to find PHU in the format specification.\n"); 187 return false; 188 } 189 pmHDU *phdu = pmHDUAlloc("PHU"); // The primary header data unit 190 phdu->header = psMemIncrRefCounter(phu); 191 if (fpa && !fpa->hdu && strcasecmp(phuType, "FPA") == 0) { 192 fpa->hdu = phdu; 193 } else if (chip && !chip->hdu && strcasecmp(phuType, "CHIP") == 0) { 194 chip->hdu = phdu; 195 } else if (cell && !cell->hdu && strcasecmp(phuType, "CELL") == 0) { 196 // cell->hdu = phdu; 197 psError(PS_ERR_IO, true, "The case of PHU == CELL has not been written yet!\n"); 198 return false; 199 } 200 201 // And the individual extensions? 202 const char *extType = psMetadataLookupStr(&mdok, formatSpec, "EXTENSIONS"); // What's in the extns? 203 if (!mdok || strlen(extType) == 0) { 204 psError(PS_ERR_IO, false, "Unable to find EXTENSIONS in the format specification.\n"); 205 return false; 206 } 207 psMetadata *contents = psMetadataLookupMD(&mdok, format, "CONTENTS"); // The contents of the FITS file 208 if (!mdok || !contents) { 209 psError(PS_ERR_IO, false, "Unable to find CONTENTS in the camera format configuration.\n"); 210 return false; 211 } 212 213 if (strcasecmp(extType, "NONE") == 0) { 214 // No extensions --- it's all in the PHU 215 psString chipType = chipNameFromHeader(formatSpec, phu); // Type of chip 216 psString content = psMetadataLookupStr(&mdok, contents, chipType); // The content line 217 218 // Parse the list of first:second 219 psArray *names = NULL; // The first bits 220 psArray *values = NULL; // The second bits 221 parsePairs(&names, &values, content); 222 for (int i = 0; i < names->n; i++) { 223 psString chipName = names->data[i]; // The name of the chip 224 psString cellName = values->data[i]; // The name of the cell 225 pmChip *chip = findChip(fpa, chipName); // The chip we're looking for 226 pmCell *cell = findCell(chip, cellName); // The cell we're looking for 227 psMetadata *cellData = getCellData(format, cellName); // Data for this cell 228 if (! cellData) { 229 psLogMsg(__func__, PS_LOG_WARN, "Unable to find data for %s in CELLS --- ignored.\n", 230 cellName); 231 continue; 232 } 233 234 // Have already plugged in the PHU 235 236 // Put in the cell data 237 if (cell->config) { 238 psLogMsg(__func__, PS_LOG_WARN, "Overwriting cell data in chip %s, cell %s\n", chipName, 239 cellName); 240 psFree(cell->config); // Make way! 241 } 242 cell->config = psMemIncrRefCounter(cellData); 243 } 244 } 245 246 247 // Go through the contents 248 psMetadataIterator *contentsIter = psMetadataIteratorAlloc(contents, PS_LIST_HEAD, NULL); 249 psMetadataItem *contentsItem = NULL; // Item from contents 250 while ((contentsItem = psMetadataGetAndIncrement(contentsIter))) { 251 const char *extName = contentsItem->name; 252 if (contentsItem->type != PS_DATA_STRING) { 253 psLogMsg(__func__, PS_LOG_WARN, "CONTENTS item %s is not of type STR --- ignored.\n", extName); 254 continue; 255 } 256 257 pmHDU *hdu = pmHDUAlloc(extName); // The extension 258 259 // Parse the list of first:second 260 psArray *names = NULL; // The first bits 261 psArray *values = NULL; // The second bits 262 parsePairs(&names, &values, contentsItem->data.V); 263 264 // XXX Memory problems in here --> leaks and/or double frees??? 265 if (strcasecmp(extType, "CHIP") == 0) { 266 // Extensions are chips 267 for (int i = 0; i < names->n; i++) { 268 psString chipName = names->data[i]; // The name of the chip 269 psString cellName = values->data[i]; // The name of the cell 270 pmChip *chip = findChip(fpa, chipName); // The chip we're looking for 271 pmCell *cell = findCell(chip, cellName); // The cell we're looking for 272 psMetadata *cellData = getCellData(format, cellName); // Data for this cell 273 if (! cellData) { 274 psLogMsg(__func__, PS_LOG_WARN, "Unable to find data for %s in CELLS --- ignored.\n", 275 cellName); 276 continue; 277 } 278 279 // Put in the extension 280 if (chip->hdu) { 281 psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s\n", chipName); 282 psFree(chip->hdu); // Make way! 283 } 284 chip->hdu = psMemIncrRefCounter(hdu); 285 286 // Put in the cell data 287 if (cell->config) { 288 psLogMsg(__func__, PS_LOG_WARN, "Overwriting cell data in chip %s, cell %s\n", chipName, 289 cellName); 290 psFree(cell->config); // Make way! 291 } 292 cell->config = psMemIncrRefCounter(cellData); 293 } 294 295 } else if (strcasecmp(extType, "CELL") == 0) { 296 // Extensions are cells 297 psString chipName = NULL; // Name of chip under consideration 298 pmChip *chip = NULL; // The chip we're looking for 299 if (! fpa->hdu->phu) { 300 // Need to look up the name of the chip 301 chipName = chipNameFromHeader(formatSpec, phu); 302 chip = findChip(fpa, chipName); 303 } 304 for (int i = 0; i < names->n; i++) { 305 psString cellType = values->data[i]; // The type of the cell 306 psString cellName = NULL; // The name of the cell 307 if (fpa->hdu->phu) { 308 // We've got chipName:cellType with cellType == cellName 309 chipName = names->data[i]; 310 cellName = cellType; 311 chip = findChip(fpa, chipName); 312 } else { 313 // We've got cellName:cellType and the chipName comes from before 314 cellName = names->data[i]; 315 } 316 psMetadata *cellData = getCellData(format, cellType); // Data for this cell 317 pmCell *cell = findCell(chip, cellName); // The cell we're looking for 318 319 // Put in the extension 320 if (cell->hdu) { 321 psLogMsg(__func__, PS_LOG_WARN, "Overwriting HDU in chip %s, cell %s\n", chipName, 322 cellName); 323 psFree(cell->hdu); 324 } 325 cell->hdu = psMemIncrRefCounter(hdu); 326 327 // Put in the cell data 328 if (cell->config) { 329 psLogMsg(__func__, PS_LOG_WARN, "Overwriting cell data in chip %s, cell %s\n", chipName, 330 cellName); 331 psFree(cell->config); 332 } 333 cell->config = psMemIncrRefCounter(cellData); 334 } 335 336 } 337 psFree(hdu); 338 psFree(names); 339 psFree(values); 340 } 341 psFree(contentsIter); 342 343 return true; 344 } 345 346 347 348 349 #if 0 60 350 pmFPA *pmFPAConstruct(const psMetadata *camera // The camera configuration 61 351 ) … … 270 560 return fpa; 271 561 } 562 #endif 563 272 564 273 565 // Print out the focal plane structure 274 void pmFPAPrint(pmFPA *fpa // FPA to print 566 void pmFPAPrint(pmFPA *fpa, // FPA to print 567 bool concepts // Print concepts? 275 568 ) 276 569 { … … 279 572 psTrace(__func__, 2, "---> FPA is extension %s.\n", fpa->hdu->extname); 280 573 if (! fpa->hdu->images) { 281 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", fpa->hdu->extname); 282 } 283 } 284 psMetadataPrint(fpa->concepts, 2); 574 psTrace(__func__, 2, "---> NO PIXELS read in for extension %s\n", fpa->hdu->extname); 575 } 576 } 577 if (concepts) { 578 psMetadataPrint(fpa->concepts, 2); 579 } 285 580 286 581 psArray *chips = fpa->chips; // Array of chips … … 292 587 psTrace(__func__, 4, "---> Chip is extension %s.\n", chip->hdu->extname); 293 588 if (! chip->hdu->images) { 294 psTrace(__func__, 4, "---> NO PIXELS for extension %s\n", chip->hdu->extname); 295 } 296 } 297 psMetadataPrint(chip->concepts, 4); 589 psTrace(__func__, 4, "---> NO PIXELS read in for extension %s\n", chip->hdu->extname); 590 } 591 } 592 if (concepts) { 593 psMetadataPrint(chip->concepts, 4); 594 } 298 595 299 596 // Iterate over the chip … … 305 602 psTrace(__func__, 6, "---> Cell is extension %s.\n", cell->hdu->extname); 306 603 if (! cell->hdu->images) { 307 psTrace(__func__, 6, "---> NO PIXELS for extension %s\n", cell->hdu->extname); 308 } 309 } 310 psMetadataPrint(cell->concepts, 6); 604 psTrace(__func__, 6, "---> NO PIXELS read in for extension %s\n", cell->hdu->extname); 605 } 606 } 607 if (concepts) { 608 psMetadataPrint(cell->concepts, 6); 609 } 311 610 312 611 psTrace(__func__, 7, "Readouts:\n"); -
branches/rel10_ifa/psModules/src/astrom/pmFPAConstruct.h
r6448 r6552 5 5 #include "pmFPA.h" 6 6 7 // Read the contents of a FITS file (format specified by the camera configuration) into memory7 // Construct an FPA instance on the basis of a camera configuration 8 8 pmFPA *pmFPAConstruct(const psMetadata *camera // The camera configuration 9 9 ); 10 10 11 // Add an input file to the FPA 12 bool pmFPAAddSource(pmFPA *fpa, // FPA to which to add 13 pmChip *chip, // Chip to which to add, or NULL 14 pmCell *cell, // Cell to which to add, or NULL 15 psMetadata *phu, // Primary header of file 16 const psMetadata *format // Format of file 17 ); 18 11 19 // Print out the FPA 12 void pmFPAPrint(pmFPA *fpa // FPA to print 20 void pmFPAPrint(pmFPA *fpa, // FPA to print 21 bool concepts // Print concepts? 13 22 ); 14 23 -
branches/rel10_ifa/psModules/src/astrom/pmFPARead.c
r6520 r6552 12 12 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 13 13 14 14 #if 0 15 15 // Read a FITS extension into a chip 16 16 static bool readExtension(p_pmHDU *hdu, // Pixel data into which to read … … 135 135 return true; 136 136 } 137 138 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 139 // Public functions 140 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 141 142 143 bool pmReadoutRead(pmReadout *readout, // Readout to read into 144 psFits *fits // FITS file from which to read 145 ) 146 { 147 // 148 149 } 137 #endif 138 150 139 151 140 // Carve a readout from the image pixels … … 162 151 163 152 // Get the list of overscans 164 psListIterator *iter = psListIteratorAlloc( biassecs, PS_LIST_HEAD, false); // Iterator153 psListIterator *iter = psListIteratorAlloc((psList*)biassecs, PS_LIST_HEAD, false); // Iterator 165 154 psRegion *biassec = NULL; // A BIASSEC region from the list 166 155 while ((biassec = psListGetAndIncrement(iter))) { … … 174 163 } 175 164 176 165 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 166 // Public functions 167 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 168 169 170 #if 0 171 bool pmReadoutRead(pmReadout *readout, // Readout to read into 172 psFits *fits // FITS file from which to read 173 ) 174 { 175 // This is very very different 176 } 177 #endif 178 179 // Read in the cell, and allocate the readouts 177 180 bool pmCellRead(pmCell *cell, // Cell to read into 178 181 psFits *fits, // FITS file from which to read … … 185 188 return false; 186 189 } 187 188 // Read the "concepts"189 pmConceptsReadCell(cell, db);190 190 191 191 // Having read the cell, we now have to cut it up … … 205 205 } 206 206 207 207 // Read in the component cells 208 208 bool pmChipRead(pmChip *chip, // Chip to read into 209 209 psFits *fits, // FITS file from which to read … … 223 223 } 224 224 225 // Read in the component chips 225 226 bool pmFPARead(pmFPA *fpa, // FPA to read into 226 227 psFits *fits, // FITS file from which to read … … 228 229 ) 229 230 { 230 psArray *chips = fpa->c ells; // Array of cells231 psArray *chips = fpa->chips; // Array of chips 231 232 for (int i = 0; i < chips->n; i++) { 232 pmC ell*chip = chips->data[i]; // The cell of interest233 pmChip *chip = chips->data[i]; // The cell of interest 233 234 if (!pmChipRead(chip, fits, db)) { 234 235 psError(PS_ERR_IO, false, "Unable to read chip %d.\n", i); … … 239 240 return true; 240 241 } 242 243 // Read the PHU into the nominated HDU 244 static bool readPHU(pmHDU *hdu, // HDU to read into 245 psFits *fits // FITS file from which to read 246 ) 247 { 248 if (! hdu || ! hdu->phu) { 249 return false; // Nothing to see here, move along 250 } 251 if (hdu->header) { 252 return true; // Already something to see here, no need to gawk at it... (; 253 } 254 // Read the PHU 255 psFitsMoveExtNum(fits, 0, false); 256 hdu->header = psFitsReadHeader(hdu->header, fits); 257 return true; 258 } 259 260 // Read the PHU into a cell 261 bool pmCellReadPHU(pmCell *cell, // Cell to read into 262 psFits *fits // FITS file from which to read 263 ) 264 { 265 return readPHU(cell->hdu, fits) || readPHU(cell->parent->hdu, fits) || 266 readPHU(cell->parent->parent->hdu, fits); 267 268 } 269 270 // Read the PHU into a chip 271 bool pmChipReadPHU(pmChip *chip, // Chip to read into 272 psFits *fits // FITS file from which to read 273 ) 274 { 275 return readPHU(chip->hdu, fits) || readPHU(chip->parent->hdu, fits); 276 } 277 278 // Read the PHU into an FPA 279 bool pmFPAReadPHU(pmFPA *fpa, // FPA to read into 280 psFits *fits // FITS file from which to read 281 ) 282 { 283 return readPHU(fpa->hdu, fits); 284 } 285 286 287 241 288 242 289 #if 0 -
branches/rel10_ifa/psModules/src/astrom/pmFPARead.h
r6448 r6552 5 5 #include "pmFPA.h" 6 6 7 8 bool pmCellRead(pmCell *cell, // Cell to read into 9 psFits *fits, // FITS file from which to read 10 psDB *db // Database handle, for "concepts" ingest 11 ); 12 13 bool pmChipRead(pmChip *chip, // Chip to read into 14 psFits *fits, // FITS file from which to read 15 psDB *db // Database handle, for "concepts" ingest 16 ); 17 18 bool pmFPARead(pmFPA *fpa, // FPA to read into 19 psFits *fits, // FITS file from which to read 20 psDB *db // Database handle, for "concepts" ingest 21 ); 22 23 bool pmCellReadPHU(pmCell *cell, // Cell to read into 24 psFits *fits // FITS file from which to read 25 ); 26 27 bool pmChipReadPHU(pmChip *chip, // Chip to read into 28 psFits *fits // FITS file from which to read 29 ); 30 31 bool pmFPAReadPHU(pmFPA *fpa, // FPA to read into 32 psFits *fits // FITS file from which to read 33 ); 34 35 36 #if 0 7 37 bool pmFPARead(pmFPA *fpa, // FPA to read into 8 38 psFits *fits, // FITS file from which to read … … 27 57 psFits *source // Source FITS file (for the original data) 28 58 ); 29 59 #endif 30 60 31 61 #endif -
branches/rel10_ifa/psModules/src/astrom/pmFPAWrite.c
r6448 r6552 8 8 9 9 static bool writeHDU(psFits *fits, // FITS file to which to write 10 p _pmHDU *hdu// Pixel data to write10 pmHDU *hdu // Pixel data to write 11 11 ) 12 12 { -
branches/rel10_ifa/psModules/src/astrom/pmHDU.c
r6519 r6552 9 9 { 10 10 psFree(hdu->extname); 11 psFree(hdu->format); 11 12 psFree(hdu->header); 12 13 psFree(hdu->images); … … 32 33 hdu->extname = psStringCopy(extname); 33 34 } 35 hdu->format = NULL; 34 36 hdu->header = NULL; 35 37 hdu->images = NULL; 36 38 hdu->table = NULL; 37 39 38 return file;40 return hdu; 39 41 } 40 42 … … 54 56 return false; 55 57 } 56 } else if (! psFitsMoveExtName(fits, hdu->extname)) { 57 psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname); 58 hdu->phu = true; 59 } else { 60 if (! psFitsMoveExtName(fits, hdu->extname)) { 61 psError(PS_ERR_IO, false, "Unable to move to extension %s\n", hdu->extname); 62 } 63 // Now, just in case for some reason the PHU has an extension name that we've moved to.... 64 if (psFitsGetExtNum(fits) == 0) { 65 hdu->phu = true; 66 } else { 67 hdu->phu = false; 68 } 58 69 } 59 70 … … 63 74 } 64 75 76 #ifdef FITS_TABLES 65 77 // What type is it? 66 78 if (psFitsIsImage(hdu->header)) { 79 #endif 67 80 if (hdu->images) { 68 81 psFree(hdu->images); // Blow away anything existing … … 70 83 hdu->images = psFitsReadImageCube(fits, psRegionSet(0,0,0,0)); 71 84 return true; 85 #ifdef FITS_TABLES 86 72 87 } 73 88 if (psFitsIsTable(hdu->table)) { … … 82 97 psError(PS_ERR_UNKNOWN, true, "No idea what this HDU consists of!\n"); 83 98 return false; 99 #endif 84 100 } 85 101 … … 99 115 } 100 116 117 #ifdef FITS_TABLES 101 118 if (hdu->images && (!hdu->table || psFitsIsImage(hdu->header))) { 119 #endif 102 120 psFitsWriteImageCube(fits, hdu->header, hdu->images, hdu->extname); 103 121 return true; 122 #ifdef FITS_TABLES 123 104 124 } 105 125 … … 111 131 psError(PS_ERR_IO, true, "No idea what this HDU consists of!\n"); 112 132 return false; 113 } 114 115 116 pmHDU *pmHDUFromFPA(pmFPA *fpa // FPA for which to find HDU 117 ) 118 { 119 return fpa->hdu; 120 } 121 122 pmHDU *pmHDUFromChip(pmChip *chip // Chip for which to find HDU 123 ) 124 { 125 pmHDU *hdu = chip->hdu; // The HDU information 126 if (!hdu) { 127 hdu = pmHDUFromFPA(chip->parent); // Grab HDU info from the FPA 128 } 129 130 return hdu; 131 } 132 133 pmHDU *pmHDUFromCell(pmCell *cell // Cell for which to find HDU 134 ) 135 { 136 pmHDU *hdu = cell->hdu; // The HDU information 137 if (!hdu) { 138 hdu = pmHDUFromChip(cell->parent); // Grab HDU info from the chip 139 } 140 141 return hdu; 142 } 143 133 #endif 134 } 144 135 145 136 -
branches/rel10_ifa/psModules/src/astrom/pmHDU.h
r6517 r6552 1 1 #ifndef PM_HDU_H 2 2 #define PM_HDU_H 3 4 #include "pslib.h"5 #include "pmFPA.h"6 3 7 4 // An instance of the FITS Header Data Unit … … 10 7 psString extname; // The extension name 11 8 bool phu; // Is this the FITS Primary Header Unit 9 psMetadata *format; // The camera format 12 10 psMetadata *header; // The FITS header, or NULL if primary for FITS; or section info 13 11 psArray *images; // The pixel data … … 21 19 22 20 // Read the HDU 23 bool pmHDURead(pmHDU *hdu); 24 25 26 // Find the HDU in the FPA hierarchy 27 pmHDU *pmHDUFromFPA(pmFPA *fpa // FPA for which to find HDU 28 ); 29 pmHDU *pmHDUFromChip(pmChip *chip // Chip for which to find HDU 30 ); 31 pmHDU *pmHDUFromCell(pmCell *cell // Cell for which to find HDU 32 ); 21 bool pmHDURead(pmHDU *hdu, // HDU to read 22 psFits *fits // FITS file to read from 23 ); 33 24 34 25 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
