Changeset 6570 for branches/rel10_ifa/psModules/src/astrom/pmConcepts.c
- Timestamp:
- Mar 10, 2006, 5:20:10 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmConcepts.c
r6552 r6570 23 23 24 24 pmConceptSpec *pmConceptSpecAlloc(psMetadataItem *blank, // Blank value; contains the name 25 pmConcept ReadFunc read, // Function to call to readthe concept26 pmConcept WriteFunc write // Function to call to writethe concept25 pmConceptParseFunc parse, // Function to call to parse the concept 26 pmConceptFormatFunc format // Function to call to format the concept 27 27 ) 28 28 { … … 31 31 32 32 spec->blank = psMemIncrRefCounter(blank); 33 spec-> read = read;34 spec-> write = write;33 spec->parse = parse; 34 spec->format = format; 35 35 36 36 return spec; … … 39 39 40 40 bool pmConceptRegister(psMetadataItem *blank, // Blank value; contains the name 41 pmConcept ReadFunc read, // Function to call to readthe concept42 pmConcept WriteFunc write, // Function to call to writethe concept41 pmConceptParseFunc parse, // Function to call to parse the concept 42 pmConceptFormatFunc format, // Function to call to format the concept 43 43 pmConceptLevel level // Level at which to store concept in the FPA hierarchy 44 44 ) … … 49 49 } 50 50 51 pmConceptSpec *spec = pmConceptSpecAlloc(blank, read, write); // The concept specification51 pmConceptSpec *spec = pmConceptSpecAlloc(blank, parse, format); // The concept specification 52 52 psMetadata **target = NULL; // The metadata of known concepts to write to 53 53 switch (level) { … … 74 74 } 75 75 76 // This function gets called for the really boring concepts --- where all you have to do is read from a header77 // or database and you don't need to muck around with conversions.78 // There is no similar "writePlain", since the type is already known.79 static psMetadataItem *readPlain(psMetadataItem *blank, // The blank value with name, comment, type80 pmFPA *fpa, // The FPA of interest81 pmChip *chip, // The Chip of interest82 pmCell *cell, // The cell of interest83 psDB *db // Database handle84 )85 {86 switch (blank->type) {87 case PS_DATA_STRING: {88 psString string = pmConceptReadString(fpa, chip, cell, db, blank->name);89 psMetadataItem *item = psMetadataItemAllocStr(blank->name, blank->comment, string);90 psFree(string);91 return item;92 }93 case PS_DATA_S32:94 return psMetadataItemAllocS32(blank->name, blank->comment,95 pmConceptReadS32(fpa, chip, cell, db, blank->name));96 case PS_DATA_F32:97 return psMetadataItemAllocF32(blank->name, blank->comment,98 pmConceptReadF32(fpa, chip, cell, db, blank->name));99 case PS_DATA_F64:100 return psMetadataItemAllocF64(blank->name, blank->comment,101 pmConceptReadF64(fpa, chip, cell, db, blank->name));102 default:103 psLogMsg(__func__, PS_LOG_WARN, "Concept %s (%s) is not of a standard type (%x)\n",104 blank->name, blank->comment, blank->type);105 }106 return NULL;107 }108 76 109 77 // Set all registered concepts to blank value for the specified level 110 static bool conceptsBlank(psMetadata * *specs, // One of the concepts specifications78 static bool conceptsBlank(psMetadata *specs, // One of the concepts specifications 111 79 psMetadata *target // Place to install the concepts 112 80 ) … … 128 96 } 129 97 98 99 130 100 // Read all registered concepts for the specified level 131 static bool conceptsRead(psMetadata * *specs, // One of the concepts specifications101 static bool conceptsRead(psMetadata *specs, // One of the concepts specifications 132 102 pmFPA *fpa, // The FPA 133 103 pmChip *chip, // The chip 134 104 pmCell *cell, // The cell 105 pmConceptSource source, // The source of the concepts to read 135 106 psDB *db, // Database handle 136 107 psMetadata *target // Place into which to read the concepts … … 140 111 pmConceptsInit(); 141 112 } 142 psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs 143 psMetadataItem *specItem = NULL; // Item from the specs metadata 144 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 145 pmConceptSpec *spec = specItem->data.V; // The specification 146 psMetadataItem *conceptItem = NULL; // The item to add to the concepts 147 if (spec->read) { 148 conceptItem = spec->read(fpa, chip, cell, db); 149 } else { 150 conceptItem = readPlain(spec->blank, fpa, chip, cell, db); 151 if (conceptItem->type != spec->blank->type) { 152 psLogMsg(__func__, PS_LOG_ERROR, "Type of concept %s following read (%x) does not match " 153 "blank type (%x).\n", spec->blank->name, conceptItem->type, spec->blank->type); 154 } 155 } 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. 162 } 163 psFree(specsIter); 113 114 if (source & PM_CONCEPT_SOURCE_CAMERA || source == PM_CONCEPT_SOURCE_ALL) { 115 pmConceptsReadFromCamera(specs, cell, target); 116 } 117 if (source & PM_CONCEPT_SOURCE_DEFAULTS || source == PM_CONCEPT_SOURCE_ALL) { 118 pmConceptsReadFromDefaults(specs, fpa, chip, cell, target); 119 } 120 if (source & PM_CONCEPT_SOURCE_HEADER || source == PM_CONCEPT_SOURCE_ALL) { 121 pmConceptsReadFromHeader(specs, fpa, chip, cell, target); 122 } 123 if (source & PM_CONCEPT_SOURCE_DATABASE || source == PM_CONCEPT_SOURCE_ALL) { 124 pmConceptsReadFromHeader(specs, fpa, chip, cell, db, target); 125 } 126 164 127 return true; 165 128 } 166 129 167 130 // Write all registered concepts for the specified level 168 static bool conceptsWrite(psMetadata * *specs, // One of the concepts specifications131 static bool conceptsWrite(psMetadata *specs, // One of the concepts specifications 169 132 pmFPA *fpa, // The FPA 170 133 pmChip *chip, // The chip 171 134 pmCell *cell, // The cell 135 pmConceptSource source, // The source of the concepts to write 172 136 psDB *db, // Database handle 173 psMetadata * source// The concepts to write out137 psMetadata *concepts // The concepts to write out 174 138 ) 175 139 { … … 177 141 pmConceptsInit(); 178 142 } 179 if (! fpa->camera) { 180 return false; 181 } 182 psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL); // Iterator on concepts 183 psMetadataItem *item = NULL; // Item from the concepts 184 while ((item = psMetadataGetAndIncrement(iter))) { 185 const char *name = item->name; // Name of the concept 186 if (!strcmp(name, "CELL.NAME") || !strcmp(name, "CHIP.NAME")) { 187 // These concepts are not written out; they are set from things like the FITS extname 188 continue; 189 } 190 psMetadataItem *specItem = psMetadataLookup(*specs, name); // Specification for the concept 191 if (specItem) { 192 pmConceptSpec *spec = specItem->data.V; // The specification 193 if (spec->write) { 194 spec->write(fpa, chip, cell, db); // The concept 195 } else { 196 pmConceptWrite(fpa, chip, cell, db, source, spec->blank->name); 197 } 198 } else { 199 psLogMsg(__func__, PS_LOG_WARN, "Unable to find specification to write concept %s in FPA\n", 200 name); 201 } 202 } 203 psFree(iter); 143 144 if (source & PM_CONCEPT_SOURCE_CAMERA || source == PM_CONCEPT_SOURCE_ALL) { 145 pmConceptsWriteToCamera(specs, cell, concepts); 146 } 147 if (source & PM_CONCEPT_SOURCE_DEFAULTS || source == PM_CONCEPT_SOURCE_ALL) { 148 pmConceptsWriteToDefaults(specs, fpa, chip, cell, concepts); 149 } 150 if (source & PM_CONCEPT_SOURCE_HEADER || source == PM_CONCEPT_SOURCE_ALL) { 151 pmConceptsWriteToHeader(specs, fpa, chip, cell, concepts); 152 } 153 if (source & PM_CONCEPT_SOURCE_DATABASE || source == PM_CONCEPT_SOURCE_ALL) { 154 pmConceptsWriteToHeader(specs, fpa, chip, cell, db, concepts); 155 } 204 156 205 157 return true; 206 158 } 159 207 160 208 161 // Set the concepts for a given FPA to blanks … … 211 164 { 212 165 psTrace("psModule.concepts", 5, "Blanking FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 213 return conceptsBlank( &conceptsFPA, fpa->concepts);166 return conceptsBlank(conceptsFPA, fpa->concepts); 214 167 } 215 168 216 169 // Read the concepts for a given FPA 217 170 bool pmConceptsReadFPA(pmFPA *fpa, // FPA for which to read concepts 171 pmConceptSource source, // The source of the concepts to read 218 172 psDB *db // Database handle 219 173 ) 220 174 { 221 175 psTrace("psModule.concepts", 5, "Reading FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 222 return conceptsRead( &conceptsFPA, fpa, NULL, NULL, db, fpa->concepts);176 return conceptsRead(conceptsFPA, fpa, NULL, NULL, source, db, fpa->concepts); 223 177 } 224 178 … … 229 183 { 230 184 psTrace("psModule.concepts", 5, "Writing FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 231 return conceptsWrite( &conceptsFPA, fpa, NULL, NULL, db, fpa->concepts);185 return conceptsWrite(conceptsFPA, fpa, NULL, NULL, db, fpa->concepts); 232 186 } 233 187 … … 237 191 { 238 192 psTrace("psModule.concepts", 5, "Blanking chip concepts: %x %x\n", conceptsChip, chip->concepts); 239 return conceptsBlank( &conceptsChip, chip->concepts);193 return conceptsBlank(conceptsChip, chip->concepts); 240 194 } 241 195 242 196 // Read the concepts for a given FPA 243 197 bool pmConceptsReadChip(pmChip *chip, // Chip for which to read concepts 198 pmConceptSource source, // The source of the concepts to read 244 199 psDB *db // Database handle 245 200 ) … … 247 202 psTrace("psModule.concepts", 5, "Reading chip concepts: %x %x\n", conceptsChip, chip->concepts); 248 203 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 249 return conceptsRead( &conceptsChip, fpa, chip, NULL, db, chip->concepts);204 return conceptsRead(conceptsChip, fpa, chip, NULL, source, db, chip->concepts); 250 205 } 251 206 … … 257 212 psTrace("psModule.concepts", 5, "Writing chip concepts: %x %x\n", conceptsChip, chip->concepts); 258 213 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 259 return conceptsWrite( &conceptsChip, fpa, chip, NULL, db, chip->concepts);214 return conceptsWrite(conceptsChip, fpa, chip, NULL, db, chip->concepts); 260 215 } 261 216 … … 265 220 { 266 221 psTrace("psModule.concepts", 5, "Blanking cell concepts: %x %x\n", conceptsCell, cell->concepts); 267 return conceptsBlank( &conceptsCell, cell->concepts);222 return conceptsBlank(conceptsCell, cell->concepts); 268 223 } 269 224 270 225 // Read the concepts for a given FPA 271 226 bool pmConceptsReadCell(pmCell *cell, // Cell for which to read concepts 227 pmConceptSource source, // The source of the concepts to read 272 228 psDB *db // Database handle 273 229 ) … … 276 232 pmChip *chip = cell->parent; // Chip to which the cell belongs 277 233 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 278 return conceptsRead( &conceptsCell, fpa, chip, cell, db, cell->concepts);234 return conceptsRead(conceptsCell, fpa, chip, cell, source, db, cell->concepts); 279 235 } 280 236 … … 287 243 pmChip *chip = cell->parent; // Chip to which the cell belongs 288 244 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 289 return conceptsWrite( &conceptsCell, fpa, chip, cell, db, cell->concepts);245 return conceptsWrite(conceptsCell, fpa, chip, cell, db, cell->concepts); 290 246 } 291 247 … … 300 256 // Install the standard concepts 301 257 258 #if 0 302 259 // FPA.NAME 303 260 { … … 306 263 psFree(fpaName); 307 264 } 265 #endif 308 266 309 267 // FPA.AIRMASS … … 340 298 { 341 299 psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN); 342 pmConceptRegister(fpaRa, (pmConcept ReadFunc)pmConceptRead_FPA_RA,343 (pmConcept WriteFunc)pmConceptWrite_FPA_RA, PM_CONCEPT_LEVEL_FPA);300 pmConceptRegister(fpaRa, (pmConceptParseFunc)pmConceptParse_FPA_Coords, 301 (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_CONCEPT_LEVEL_FPA); 344 302 psFree(fpaRa); 345 303 } … … 348 306 { 349 307 psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN); 350 pmConceptRegister(fpaDec, (pmConcept ReadFunc)pmConceptRead_FPA_DEC,351 (pmConcept WriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);308 pmConceptRegister(fpaDec, (pmConceptParseFunc)pmConceptParse_FPA_Coords, 309 (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_CONCEPT_LEVEL_FPA); 352 310 psFree(fpaDec); 353 311 } … … 436 394 437 395 // CELL.DARKTIME 438 { 396 {Read 439 397 psMetadataItem *cellDarktime = psMetadataItemAllocF32("CELL.DARKTIME", 440 398 "Time since flush (sec)", NAN); … … 450 408 "Trim section", trimsec); 451 409 psFree(trimsec); 452 pmConceptRegister(cellTrimsec, (pmConcept ReadFunc)pmConceptRead_CELL_TRIMSEC,453 (pmConcept WriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);410 pmConceptRegister(cellTrimsec, (pmConceptParseFunc)pmConceptParse_CELL_TRIMSEC, 411 (pmConceptFormatFunc)pmConceptFormat_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL); 454 412 psFree(cellTrimsec); 455 413 } … … 461 419 "Bias sections", biassecs); 462 420 psFree(biassecs); 463 pmConceptRegister(cellBiassec, (pmConcept ReadFunc)pmConceptRead_CELL_BIASSEC,464 (pmConcept WriteFunc)pmConceptWrite_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL);421 pmConceptRegister(cellBiassec, (pmConceptParseFunc)pmConceptParse_CELL_BIASSEC, 422 (pmConceptFormatFunc)pmConceptFormat_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL); 465 423 psFree(cellBiassec); 466 424 } … … 469 427 { 470 428 psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0); 471 pmConceptRegister(cellXbin, (pmConcept ReadFunc)pmConceptRead_CELL_XBIN,472 (pmConcept WriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);429 pmConceptRegister(cellXbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning, 430 (pmConceptFormatFunc)pmConceptFormat_CELL_Binning, PM_CONCEPT_LEVEL_CELL); 473 431 psFree(cellXbin); 474 432 } … … 477 435 { 478 436 psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0); 479 pmConceptRegister(cellYbin, (pmConcept ReadFunc)pmConceptRead_CELL_YBIN,480 (pmConcept WriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);437 pmConceptRegister(cellYbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning, 438 (pmConceptFormatFunc)pmConceptFormat_CELL_Binning, PM_CONCEPT_LEVEL_CELL); 481 439 psFree(cellYbin); 482 440 } … … 485 443 { 486 444 psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1); 487 pmConceptRegister(cellTimesys, (pmConcept ReadFunc)pmConceptRead_CELL_TIMESYS,488 (pmConcept WriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);445 pmConceptRegister(cellTimesys, (pmConceptParseFunc)pmConceptParse_CELL_TIMESYS, 446 (pmConceptFormatFunc)pmConceptFormat_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL); 489 447 psFree(cellTimesys); 490 448 } … … 499 457 "Time of exposure", time); 500 458 psFree(time); 501 pmConceptRegister(cellTime, (pmConcept ReadFunc)pmConceptRead_CELL_TIME,502 (pmConcept WriteFunc)pmConceptWrite_CELL_TIME, PM_CONCEPT_LEVEL_CELL);459 pmConceptRegister(cellTime, (pmConceptParseFunc)pmConceptParse_CELL_TIME, 460 (pmConceptFormatFunc)pmConceptFormat_CELL_TIME, PM_CONCEPT_LEVEL_CELL); 503 461 psFree(cellTime); 504 462 } … … 507 465 { 508 466 psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0); 509 pmConceptRegister(cellX0, (pmConcept ReadFunc)pmConceptRead_CELL_X0,510 (pmConcept WriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);467 pmConceptRegister(cellX0, (pmConceptParseFunc)pmConceptParse_CELL_Positions, 468 (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_CONCEPT_LEVEL_CELL); 511 469 psFree(cellX0); 512 470 } … … 515 473 { 516 474 psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0); 517 pmConceptRegister(cellY0, (pmConcept ReadFunc)pmConceptRead_CELL_Y0,518 (pmConcept WriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);475 pmConceptRegister(cellY0, (pmConceptParseFunc)pmConceptParse_CELL_Positions, 476 (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_CONCEPT_LEVEL_CELL); 519 477 psFree(cellY0); 520 478 }
Note:
See TracChangeset
for help on using the changeset viewer.
