Changeset 4386 for trunk/archive/scripts/src/pmFPARead.c
- Timestamp:
- Jun 24, 2005, 3:05:59 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/pmFPARead.c (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.
