Changeset 7278
- Timestamp:
- Jun 1, 2006, 2:55:23 PM (20 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 27 edited
-
camera/pmChipMosaic.c (modified) (6 diffs)
-
camera/pmFPA.c (modified) (2 diffs)
-
camera/pmFPAConstruct.c (modified) (10 diffs)
-
camera/pmFPACopy.c (modified) (6 diffs)
-
camera/pmFPACopy.h (modified) (1 diff)
-
camera/pmFPAHeader.c (modified) (2 diffs)
-
camera/pmFPARead.c (modified) (6 diffs)
-
camera/pmFPAUtils.c (modified) (2 diffs)
-
camera/pmFPAWrite.c (modified) (4 diffs)
-
camera/pmFPA_JPEG.c (modified) (6 diffs)
-
camera/pmFPAfile.c (modified) (28 diffs)
-
camera/pmFPAview.c (modified) (13 diffs)
-
camera/pmHDU.c (modified) (4 diffs)
-
camera/pmHDUGenerate.c (modified) (3 diffs)
-
camera/pmHDUUtils.c (modified) (5 diffs)
-
concepts/pmConcepts.c (modified) (24 diffs)
-
concepts/pmConceptsRead.c (modified) (10 diffs)
-
concepts/pmConceptsStandard.c (modified) (19 diffs)
-
concepts/pmConceptsStandard.h (modified) (1 diff)
-
concepts/pmConceptsWrite.c (modified) (11 diffs)
-
config/pmConfig.c (modified) (10 diffs)
-
detrend/pmFlatField.c (modified) (4 diffs)
-
detrend/pmFlatField.h (modified) (2 diffs)
-
detrend/pmFlatNormalize.c (modified) (1 diff)
-
detrend/pmFringeStats.c (modified) (6 diffs)
-
detrend/pmSubtractBias.c (modified) (6 diffs)
-
imcombine/pmReadoutCombine.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmChipMosaic.c
r7017 r7278 41 41 ) 42 42 { 43 assert(bounds); 44 assert(chip); 45 43 46 if (primary) { 44 47 *bounds = psRegionSet(INFINITY, 0, INFINITY, 0); … … 104 107 ) 105 108 { 109 assert(xBinChip); 110 assert(yBinChip); 111 assert(chip); 112 106 113 // Check that we've got the HDU in the chip or the FPA 107 114 if ((!chip->hdu || !chip->hdu->images) && (!chip->parent->hdu || !chip->parent->hdu->images)) { … … 358 365 ) 359 366 { 367 assert(target); 368 assert(sources); 369 assert(xBin > 0 && yBin > 0); 370 assert(trimsec); 371 360 372 bool success = true; // Result of setting everything 361 373 float gain = 0.0; // Gain … … 433 445 } 434 446 435 436 447 return success; 437 448 } … … 446 457 ) 447 458 { 459 assert(mosaicImage); 460 assert(mosaicMask); 461 assert(mosaicWeights); 462 assert(chip); 463 448 464 psArray *cells = chip->cells; // The array of cells 449 465 int numCells = cells->n; // Number of cells … … 587 603 ) 588 604 { 605 PS_ASSERT_PTR_NON_NULL(chip, false); 606 589 607 psImage *mosaicImage = NULL; // The mosaic image 590 608 psImage *mosaicMask = NULL; // The mosaic mask -
trunk/psModules/src/camera/pmFPA.c
r7274 r7278 12 12 * XXX: Should we implement non-linear cell->chip transforms? 13 13 * 14 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $15 * @date $Date: 2006-06-0 1 22:43:26$14 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-06-02 00:55:22 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 399 399 } 400 400 401 bool pmChipSetFileStatus pmChip *chip, bool status)401 bool pmChipSetFileStatus(pmChip *chip, bool status) 402 402 { 403 403 PS_ASSERT_PTR_NON_NULL(chip, false); -
trunk/psModules/src/camera/pmFPAConstruct.c
r7168 r7278 21 21 ) 22 22 { 23 assert(format); 24 assert(cellName && strlen(cellName) > 0); 25 23 26 bool status = true; // Result of MD lookup 24 27 psMetadata *cells = psMetadataLookupMD(&status, format, "CELLS"); // The CELLS … … 43 46 ) 44 47 { 48 assert(first); 49 assert(second); 50 assert(third); 51 assert(string && strlen(string) > 0); 52 45 53 bool allOK = true; // Everything was OK? 46 54 psList *values = psStringSplit(string, " ,;", true); // List of the parts … … 96 104 ) 97 105 { 106 assert(name && strlen(name) > 0); 107 assert(fileInfo); 108 assert(header); 109 98 110 bool mdok = true; // Result of MD lookup 99 111 psString keyword = psMetadataLookupStr(&mdok, fileInfo, name); … … 188 200 ) 189 201 { 202 assert(fileInfo); 203 assert(contents); 204 assert(header); 205 190 206 bool mdok = true; // Status of MD lookup 191 207 const char *contentHeaders = psMetadataLookupStr(&mdok, fileInfo, "CONTENT"); // Headers for content … … 237 253 assert(contents && strlen(contents) > 0); 238 254 assert(!cell || (cell && chip)); // Need both chip and cell if given a cell 255 assert(format); 239 256 240 257 if (hdu && level == PM_FPA_LEVEL_FPA) { … … 329 346 ) 330 347 { 348 assert(format); 349 331 350 bool mdok = true; // Status of MD lookup 332 351 psMetadata *file = psMetadataLookupMD(&mdok, format, "FILE"); // File information … … 363 382 ) 364 383 { 384 PS_ASSERT_PTR_NON_NULL(camera, NULL); 385 365 386 pmFPA *fpa = pmFPAAlloc(camera); // The FPA to fill out 366 387 … … 400 421 ) 401 422 { 402 assert(fpa);403 assert(phuView);404 assert(format);423 PS_ASSERT_PTR_NON_NULL(fpa, false); 424 PS_ASSERT_PTR_NON_NULL(phuView, false); 425 PS_ASSERT_PTR_NON_NULL(format, false); 405 426 406 427 // Where does the PHU go? … … 495 516 ) 496 517 { 497 assert(fpa);498 assert(phu);499 assert(format);518 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 519 PS_ASSERT_PTR_NON_NULL(phu, NULL); 520 PS_ASSERT_PTR_NON_NULL(format, NULL); 500 521 501 522 bool mdok = true; // Status from metadata lookups … … 689 710 ) 690 711 { 712 PS_ASSERT_PTR_NON_NULL(fpa,); 713 691 714 psTrace(__func__, 1, "FPA:\n"); 692 715 if (fpa->hdu) { -
trunk/psModules/src/camera/pmFPACopy.c
r7168 r7278 24 24 ) 25 25 { 26 assert(source); 27 26 28 psImage *copy = psMemIncrRefCounter(source); 27 29 bool copied = false; // Have the pixels been copied? … … 51 53 ) 52 54 { 55 assert(region); 56 assert(xBin > 0); 57 assert(yBin > 0); 58 53 59 // Want to include the lower bound: 1 binned by 4 --> 0; 3 binned by 4 --> 0; 4 binned by 4 --> 1 54 60 region->x0 = (int)(region->x0 / xBin); … … 62 68 ) 63 69 { 70 assert(cell); 71 64 72 if (cell->hdu && cell->hdu->phu) { 65 73 return cell->hdu; … … 274 282 assert(target); 275 283 assert(source); 284 assert(xBin > 0); 285 assert(yBin > 0); 276 286 277 287 psArray *targetCells = target->cells; // The target cells … … 300 310 } 301 311 302 static intfpaCopy(pmFPA *target, // The target FPA303 pmFPA *source, // The source FPA, to be copied304 bool pixels, // Copy the pixels?305 int xBin, int yBin // (Relative) binning factors in x and y306 )312 static bool fpaCopy(pmFPA *target, // The target FPA 313 pmFPA *source, // The source FPA, to be copied 314 bool pixels, // Copy the pixels? 315 int xBin, int yBin // (Relative) binning factors in x and y 316 ) 307 317 { 308 318 assert(target); 309 319 assert(source); 320 assert(xBin > 0); 321 assert(yBin > 0); 310 322 311 323 psArray *targetChips = target->chips; // The target chips … … 338 350 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 339 351 340 int pmFPACopy(pmFPA *target, // The target FPA 341 pmFPA *source // The source FPA, to be copied 342 ) 343 { 352 bool pmFPACopy(pmFPA *target, // The target FPA 353 pmFPA *source // The source FPA, to be copied 354 ) 355 { 356 PS_ASSERT_PTR_NON_NULL(target, false); 357 PS_ASSERT_PTR_NON_NULL(source, false); 344 358 return fpaCopy(target, source, true, 1, 1); 345 359 } 346 360 347 int pmChipCopy(pmChip *target, // The target chip 348 pmChip *source // The source chip, to be copied 349 ) 350 { 361 bool pmChipCopy(pmChip *target, // The target chip 362 pmChip *source // The source chip, to be copied 363 ) 364 { 365 PS_ASSERT_PTR_NON_NULL(target, false); 366 PS_ASSERT_PTR_NON_NULL(source, false); 351 367 return chipCopy(target, source, true, 1, 1); 352 368 } 353 369 354 int pmCellCopy(pmCell *target, // The target cell 355 pmCell *source // The source cell, to be copied 356 ) 357 { 370 bool pmCellCopy(pmCell *target, // The target cell 371 pmCell *source // The source cell, to be copied 372 ) 373 { 374 PS_ASSERT_PTR_NON_NULL(target, false); 375 PS_ASSERT_PTR_NON_NULL(source, false); 358 376 return cellCopy(target, source, true, 1, 1); 359 377 } 360 378 361 379 362 int pmFPACopyStructure(pmFPA *target, // The target FPA 363 pmFPA *source, // The source FPA, to be copied 364 int xBin, int yBin // Binning factors in x and y 365 ) 366 { 367 return fpaCopy(target, source, false, xBin, yBin); 368 } 369 370 int pmChipCopyStructure(pmChip *target, // The target chip 371 pmChip *source, // The source chip, to be copied 380 bool pmFPACopyStructure(pmFPA *target, // The target FPA 381 pmFPA *source, // The source FPA, to be copied 372 382 int xBin, int yBin // Binning factors in x and y 373 383 ) 374 384 { 385 PS_ASSERT_PTR_NON_NULL(target, false); 386 PS_ASSERT_PTR_NON_NULL(source, false); 387 PS_ASSERT_INT_POSITIVE(xBin, false); 388 PS_ASSERT_INT_POSITIVE(yBin, false); 389 return fpaCopy(target, source, false, xBin, yBin); 390 } 391 392 bool pmChipCopyStructure(pmChip *target, // The target chip 393 pmChip *source, // The source chip, to be copied 394 int xBin, int yBin // Binning factors in x and y 395 ) 396 { 397 PS_ASSERT_PTR_NON_NULL(target, false); 398 PS_ASSERT_PTR_NON_NULL(source, false); 399 PS_ASSERT_INT_POSITIVE(xBin, false); 400 PS_ASSERT_INT_POSITIVE(yBin, false); 375 401 return chipCopy(target, source, false, xBin, yBin); 376 402 } 377 403 378 int pmCellCopyStructure(pmCell *target, // The target cell 379 pmCell *source, // The source cell, to be copied 380 int xBin, int yBin // Binning factors in x and y 381 ) 382 { 404 bool pmCellCopyStructure(pmCell *target, // The target cell 405 pmCell *source, // The source cell, to be copied 406 int xBin, int yBin // Binning factors in x and y 407 ) 408 { 409 PS_ASSERT_PTR_NON_NULL(target, false); 410 PS_ASSERT_PTR_NON_NULL(source, false); 411 PS_ASSERT_INT_POSITIVE(xBin, false); 412 PS_ASSERT_INT_POSITIVE(yBin, false); 383 413 return cellCopy(target, source, false, xBin, yBin); 384 414 } -
trunk/psModules/src/camera/pmFPACopy.h
r7017 r7278 3 3 4 4 // Copy the FPA components, including the pixels 5 int pmFPACopy(pmFPA *target, // The target FPA 6 pmFPA *source // The source FPA, to be copied 7 ); 8 int pmChipCopy(pmChip *target, // The target chip 9 pmChip *source // The source chip, to be copied 5 bool pmFPACopy(pmFPA *target, // The target FPA 6 pmFPA *source // The source FPA, to be copied 10 7 ); 11 int pmCellCopy(pmCell *target, // The target cell 12 pmCell *source // The source cell, to be copied 13 ); 8 bool pmChipCopy(pmChip *target, // The target chip 9 pmChip *source // The source chip, to be copied 10 ); 11 bool pmCellCopy(pmCell *target, // The target cell 12 pmCell *source // The source cell, to be copied 13 ); 14 14 15 15 // Versions that copy the structure and not the pixels; they also allow binning 16 int pmFPACopyStructure(pmFPA *target, // The target FPA 17 pmFPA *source, // The source FPA, to be copied 18 int xBin, int yBin // Binning factors in x and y 19 ); 20 int pmChipCopyStructure(pmChip *target, // The target chip 21 pmChip *source, // The source chip, to be copied 22 int xBin, int yBin // Binning factors in x and y 16 bool pmFPACopyStructure(pmFPA *target, // The target FPA 17 pmFPA *source, // The source FPA, to be copied 18 int xBin, int yBin // Binning factors in x and y 23 19 ); 24 int pmCellCopyStructure(pmCell *target, // The target cell 25 pmCell *source, // The source cell, to be copied 26 int xBin, int yBin // Binning factors in x and y 27 ); 20 bool pmChipCopyStructure(pmChip *target, // The target chip 21 pmChip *source, // The source chip, to be copied 22 int xBin, int yBin // Binning factors in x and y 23 ); 24 bool pmCellCopyStructure(pmCell *target, // The target cell 25 pmCell *source, // The source cell, to be copied 26 int xBin, int yBin // Binning factors in x and y 27 ); 28 28 29 29 -
trunk/psModules/src/camera/pmFPAHeader.c
r7274 r7278 15 15 ) 16 16 { 17 assert(chip); 18 17 19 bool status = true; // Status of concept reading 18 20 status |= pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_HEADER, false, NULL); … … 33 35 ) 34 36 { 37 assert(fpa); 38 35 39 bool status = true; // Status of concept reading 36 40 status |= pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_HEADER, NULL); -
trunk/psModules/src/camera/pmFPARead.c
r7274 r7278 27 27 ) 28 28 { 29 assert(readout); 30 assert(image); 31 assert(trimsec); 32 assert(biassecs); 33 29 34 // The image corresponding to the trim region 30 35 if (psRegionIsBad(*trimsec)) { … … 85 90 ) 86 91 { 92 assert(fits); 93 assert(region); 94 87 95 bool resize = false; // Do we need to resize the image once read? 88 96 psRegion toRead = psRegionSet(region->x0, region->x1, region->y0, region->y1); // Region to read … … 158 166 ) 159 167 { 168 PS_ASSERT_PTR_NON_NULL(readout, false); 169 PS_ASSERT_PTR_NON_NULL(fits, false); 170 PS_ASSERT_INT_NONNEGATIVE(z, false); 171 PS_ASSERT_INT_NONNEGATIVE(numScans, false); 172 160 173 // Get the HDU and read the header 161 174 pmCell *cell = readout->parent; // The parent cell … … 298 311 ) 299 312 { 313 PS_ASSERT_PTR_NON_NULL(cell, false); 314 PS_ASSERT_PTR_NON_NULL(fits, false); 315 300 316 pmHDU *hdu = pmHDUFromCell(cell); // The HDU 301 317 if (!hdu) { … … 345 361 ) 346 362 { 363 PS_ASSERT_PTR_NON_NULL(chip, false); 364 PS_ASSERT_PTR_NON_NULL(fits, false); 365 347 366 bool success = false; // Were we able to read at least one HDU? 348 367 psArray *cells = chip->cells; // Array of cells … … 366 385 ) 367 386 { 387 PS_ASSERT_PTR_NON_NULL(fpa, false); 388 PS_ASSERT_PTR_NON_NULL(fits, false); 389 368 390 bool success = false; // Were we able to read at least one HDU? 369 391 psArray *chips = fpa->chips; // Array of chips -
trunk/psModules/src/camera/pmFPAUtils.c
r7017 r7278 9 9 ) 10 10 { 11 psArray *chips = fpa->chips; // Array of chips 11 PS_ASSERT_PTR_NON_NULL(fpa, -1); 12 PS_ASSERT_PTR_NON_NULL(name, -1); 13 if (strlen(name) == 0) { 14 return -1; 15 } 16 17 psArray *chips = fpa->chips; // Array of chips 12 18 for (int i = 0; i < chips->n; i++) { 13 19 pmChip *chip = chips->data[i]; // The chip of interest … … 27 33 ) 28 34 { 35 PS_ASSERT_PTR_NON_NULL(chip, -1); 36 PS_ASSERT_PTR_NON_NULL(name, -1); 37 if (strlen(name) == 0) { 38 return -1; 39 } 40 29 41 psArray *cells = chip->cells; // Array of cells 30 42 for (int i = 0; i < cells->n; i++) { -
trunk/psModules/src/camera/pmFPAWrite.c
r7249 r7278 16 16 ) 17 17 { 18 PS_ASSERT_PTR_NON_NULL(readout, false); 19 PS_ASSERT_PTR_NON_NULL(fits, false); 20 18 21 pmHDU *hdu = pmHDUFromReadout(readout); // The HDU to which to write 19 22 if (!hdu) { … … 87 90 ) 88 91 { 92 PS_ASSERT_PTR_NON_NULL(cell, false); 93 PS_ASSERT_PTR_NON_NULL(fits, false); 94 89 95 pmHDU *hdu = cell->hdu; // The HDU 90 96 if (!hdu) { … … 118 124 ) 119 125 { 126 PS_ASSERT_PTR_NON_NULL(chip, false); 127 PS_ASSERT_PTR_NON_NULL(fits, false); 128 120 129 pmHDU *hdu = chip->hdu; // The HDU 121 130 if (!hdu) { … … 156 165 ) 157 166 { 167 PS_ASSERT_PTR_NON_NULL(fpa, false); 168 PS_ASSERT_PTR_NON_NULL(fits, false); 169 158 170 pmHDU *hdu = fpa->hdu; // The HDU 159 171 if (!hdu) { -
trunk/psModules/src/camera/pmFPA_JPEG.c
r7017 r7278 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-0 5-01 01:55:43$7 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-06-02 00:55:22 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 28 29 29 30 bool pmFPAviewWriteJPEG (const pmFPAview *view, pmFPAfile *file)30 bool pmFPAviewWriteJPEG(const pmFPAview *view, pmFPAfile *file) 31 31 { 32 PS_ASSERT_PTR_NON_NULL(view, false); 33 PS_ASSERT_PTR_NON_NULL(file, false); 32 34 33 35 pmFPA *fpa = file->fpa; … … 70 72 bool pmFPAWriteJPEG (pmFPA *fpa, const pmFPAview *view, pmFPAfile *file) 71 73 { 74 PS_ASSERT_PTR_NON_NULL(fpa, false); 75 PS_ASSERT_PTR_NON_NULL(view, false); 76 PS_ASSERT_PTR_NON_NULL(file, false); 72 77 73 78 for (int i = 0; i < fpa->chips->n; i++) { … … 82 87 bool pmChipWriteJPEG (pmChip *chip, const pmFPAview *view, pmFPAfile *file) 83 88 { 89 PS_ASSERT_PTR_NON_NULL(chip, false); 90 PS_ASSERT_PTR_NON_NULL(view, false); 91 PS_ASSERT_PTR_NON_NULL(file, false); 84 92 85 93 for (int i = 0; i < chip->cells->n; i++) { … … 94 102 bool pmCellWriteJPEG (pmCell *cell, const pmFPAview *view, pmFPAfile *file) 95 103 { 104 PS_ASSERT_PTR_NON_NULL(cell, false); 105 PS_ASSERT_PTR_NON_NULL(view, false); 106 PS_ASSERT_PTR_NON_NULL(file, false); 96 107 97 108 for (int i = 0; i < cell->readouts->n; i++) { … … 106 117 bool pmReadoutWriteJPEG (pmReadout *readout, const pmFPAview *view, pmFPAfile *file) 107 118 { 119 PS_ASSERT_PTR_NON_NULL(readout, false); 120 PS_ASSERT_PTR_NON_NULL(view, false); 121 PS_ASSERT_PTR_NON_NULL(file, false); 122 108 123 char *name, *mode, *word, *mapname; 109 124 psArray *range; -
trunk/psModules/src/camera/pmFPAfile.c
r7249 r7278 22 22 #include "pmFPA_JPEG.h" 23 23 24 static void pmFPAfileFree (pmFPAfile *file) 25 { 26 27 if (file == NULL) 24 static void pmFPAfileFree(pmFPAfile *file) 25 { 26 if (!file) { 28 27 return; 28 } 29 29 30 30 psFree (file->fpa); … … 54 54 } 55 55 56 pmFPAfile *pmFPAfileAlloc () 57 { 58 59 pmFPAfile *file = psAlloc (sizeof(pmFPAfile)); 60 psMemSetDeallocator (file, (psFreeFunc) pmFPAfileFree); 56 pmFPAfile *pmFPAfileAlloc() 57 { 58 pmFPAfile *file = psAlloc(sizeof(pmFPAfile)); 59 psMemSetDeallocator(file, (psFreeFunc) pmFPAfileFree); 61 60 62 61 file->phu = NULL; … … 83 82 file->state = PM_FPA_STATE_CLOSED; 84 83 85 return (file); 86 } 87 88 pmFPAfile *pmFPAfileDefine (psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name) 89 { 84 return file; 85 } 86 87 pmFPAfile *pmFPAfileDefine(psMetadata *files, psMetadata *camera, pmFPA *fpa, char *name) 88 { 89 PS_ASSERT_PTR_NON_NULL(files, NULL); 90 PS_ASSERT_PTR_NON_NULL(camera, NULL); 91 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 92 PS_ASSERT_PTR_NON_NULL(name, NULL); 93 PS_ASSERT_INT_POSITIVE(strlen(name), NULL); 90 94 91 95 bool status; … … 243 247 bool pmFPAfileOpen (pmFPAfile *file, const pmFPAview *view) 244 248 { 249 PS_ASSERT_PTR_NON_NULL(file, false); 250 PS_ASSERT_PTR_NON_NULL(view, false); 245 251 246 252 bool status; … … 325 331 } 326 332 327 bool pmFPAfileRead (pmFPAfile *file, const pmFPAview *view) 328 { 333 bool pmFPAfileRead(pmFPAfile *file, const pmFPAview *view) 334 { 335 PS_ASSERT_PTR_NON_NULL(file, false); 336 PS_ASSERT_PTR_NON_NULL(view, false); 337 329 338 if (file->state & PM_FPA_STATE_INACTIVE) 330 339 return false; … … 378 387 } 379 388 380 bool pmFPAfileWrite (pmFPAfile *file, const pmFPAview *view) 381 { 389 bool pmFPAfileWrite(pmFPAfile *file, const pmFPAview *view) 390 { 391 PS_ASSERT_PTR_NON_NULL(file, false); 392 PS_ASSERT_PTR_NON_NULL(view, false); 382 393 383 394 if (file->state & PM_FPA_STATE_INACTIVE) { … … 436 447 bool pmFPAfileCreate (pmFPAfile *file, const pmFPAview *view) 437 448 { 449 PS_ASSERT_PTR_NON_NULL(file, false); 450 PS_ASSERT_PTR_NON_NULL(view, false); 451 438 452 if (file->state & PM_FPA_STATE_INACTIVE) { 439 453 return false; … … 478 492 bool pmFPAfileClose (pmFPAfile *file, const pmFPAview *view) 479 493 { 494 PS_ASSERT_PTR_NON_NULL(file, false); 495 PS_ASSERT_PTR_NON_NULL(view, false); 496 480 497 if (file->state & PM_FPA_STATE_INACTIVE) { 481 498 return false; … … 524 541 bool pmFPAfileActivate (psMetadata *files, bool state, char *name) 525 542 { 526 if (name == NULL) { 543 PS_ASSERT_PTR_NON_NULL(files, false); 544 545 if (!name) { 527 546 psMetadataItem *item = NULL; 528 547 psMetadataIterator *iter = psMetadataIteratorAlloc (files, PS_LIST_HEAD, NULL); … … 555 574 bool pmFPAfileIOChecks (psMetadata *files, const pmFPAview *view, pmFPAfilePlace place) 556 575 { 576 PS_ASSERT_PTR_NON_NULL(files, false); 577 PS_ASSERT_PTR_NON_NULL(view, false); 578 557 579 // recipe override values (command-line options): 558 580 psMetadataItem *item = NULL; … … 577 599 pmReadout *pmFPAfileCreateInternal (psMetadata *files, char *name, int Nx, int Ny, int type) 578 600 { 579 pmReadout *readout = pmReadoutAlloc (NULL); 580 readout->image = psImageAlloc (Nx, Ny, type); 601 PS_ASSERT_PTR_NON_NULL(files, false); 602 PS_ASSERT_PTR_NON_NULL(name, false); 603 PS_ASSERT_INT_POSITIVE(strlen(name), false); 604 605 pmReadout *readout = pmReadoutAlloc(NULL); 606 readout->image = psImageAlloc(Nx, Ny, type); 581 607 582 608 // I want an image from the … … 585 611 586 612 file->readout = readout; 587 psMetadataAddPtr (files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file);588 psFree (file);613 psMetadataAddPtr(files, PS_LIST_TAIL, name, PS_DATA_UNKNOWN, "", file); 614 psFree(file); 589 615 // we free this copy of file, but 'files' still has a copy 590 616 591 return (readout); 592 } 593 594 bool pmFPAfileDropInternal (psMetadata *files, char *name) 595 { 617 return readout; 618 } 619 620 bool pmFPAfileDropInternal(psMetadata *files, char *name) 621 { 622 PS_ASSERT_PTR_NON_NULL(files, false); 623 PS_ASSERT_PTR_NON_NULL(name, false); 624 PS_ASSERT_INT_POSITIVE(strlen(name), false); 625 596 626 bool status; 597 627 … … 610 640 pmReadout *pmFPAfileThisReadout (psMetadata *files, const pmFPAview *view, const char *name) 611 641 { 642 PS_ASSERT_PTR_NON_NULL(files, false); 643 PS_ASSERT_PTR_NON_NULL(view, false); 644 PS_ASSERT_PTR_NON_NULL(name, false); 645 PS_ASSERT_INT_POSITIVE(strlen(name), false); 646 612 647 bool status; 613 648 … … 629 664 bool pmFPAviewReadFitsImage (const pmFPAview *view, pmFPAfile *file) 630 665 { 666 PS_ASSERT_PTR_NON_NULL(view, false); 667 PS_ASSERT_PTR_NON_NULL(file, false); 668 631 669 bool status; 632 670 pmFPA *fpa = file->fpa; … … 680 718 bool pmFPAviewWriteFitsImage (const pmFPAview *view, pmFPAfile *file) 681 719 { 720 PS_ASSERT_PTR_NON_NULL(view, false); 721 PS_ASSERT_PTR_NON_NULL(file, false); 682 722 683 723 pmFPA *fpa = file->fpa; … … 748 788 pmFPAfile *pmFPAfileFromArgs (bool *found, pmConfig *config, char *filename, char *argname) 749 789 { 790 PS_ASSERT_PTR_NON_NULL(config, false); 791 PS_ASSERT_PTR_NON_NULL(filename, false); 792 PS_ASSERT_INT_POSITIVE(strlen(filename), false); 793 PS_ASSERT_PTR_NON_NULL(argname, false); 794 PS_ASSERT_INT_POSITIVE(strlen(argname), false); 795 750 796 bool status; 751 797 pmFPA *fpa = NULL; … … 755 801 psMetadata *format = NULL; 756 802 757 if (*found) 758 return NULL; 803 if (*found) { 804 return NULL; 805 } 759 806 760 807 // we search the argument data for the named fileset (argname) 761 808 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname); 762 if (!status) 763 return NULL; 764 if (infiles->n < 1) 765 return NULL; 809 if (!status) { 810 return NULL; 811 } 812 if (infiles->n < 1) { 813 return NULL; 814 } 766 815 767 816 // determine the current format from the header … … 836 885 pmFPAfile *pmFPAfileSetFromArgs (bool *found, pmConfig *config, char *filename, char *argname) 837 886 { 887 PS_ASSERT_PTR_NON_NULL(config, false); 888 PS_ASSERT_PTR_NON_NULL(filename, false); 889 PS_ASSERT_INT_POSITIVE(strlen(filename), false); 890 PS_ASSERT_PTR_NON_NULL(argname, false); 891 PS_ASSERT_INT_POSITIVE(strlen(argname), false); 892 838 893 bool status; 839 894 pmFPA *fpa = NULL; … … 848 903 // we search the argument data for the named fileset (argname) 849 904 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname); 850 if (!status) 851 return NULL; 852 if (infiles->n < 1) 853 return NULL; 905 if (!status) { 906 return NULL; 907 } 908 if (infiles->n < 1) { 909 return NULL; 910 } 854 911 855 912 // determine the current format from the header … … 914 971 pmFPAfile *pmFPAfileFromFPA (pmConfig *config, pmFPA *src, int xBin, int yBin, char *filename) 915 972 { 973 PS_ASSERT_PTR_NON_NULL(config, false); 974 PS_ASSERT_PTR_NON_NULL(src, false); 975 PS_ASSERT_PTR_NON_NULL(filename, false); 976 PS_ASSERT_INT_POSITIVE(strlen(filename), false); 977 916 978 // XXX pmFPAConstruct has many leaks (6919) 917 979 pmFPA *fpa = pmFPAConstruct (config->camera); … … 928 990 pmFPAfile *pmFPAfileFromConf (bool *found, pmConfig *config, char *filename, pmFPA *input) 929 991 { 992 PS_ASSERT_PTR_NON_NULL(config, false); 993 PS_ASSERT_PTR_NON_NULL(filename, false); 994 PS_ASSERT_INT_POSITIVE(strlen(filename), false); 995 PS_ASSERT_PTR_NON_NULL(input, false); 996 930 997 psFits *fits = NULL; 931 998 pmFPAfile *file = NULL; … … 934 1001 psArray *infiles = NULL; 935 1002 936 if (*found) 937 return NULL; 1003 if (*found) { 1004 return NULL; 1005 } 938 1006 939 1007 // a camera config is needed (as source of file rule) … … 951 1019 952 1020 // image names come from the file->name list? 953 if (!strcasecmp (file->filerule, "@FILES")) 1021 if (!strcasecmp (file->filerule, "@FILES")) { 954 1022 psAbort ("pmFPAfileFromConfig", "programming error"); 1023 } 955 1024 956 1025 // image needs to come from the detrend database … … 964 1033 infiles->data[0] = psStringCopy (file->filerule); 965 1034 } 966 if (infiles == NULL) 967 return NULL; 1035 if (infiles == NULL) { 1036 return NULL; 1037 } 968 1038 if (infiles->n < 1) { 969 1039 psFree (infiles); … … 1018 1088 bool pmFPAfileAddFileNames (psMetadata *files, char *name, char *value, int mode) 1019 1089 { 1090 PS_ASSERT_PTR_NON_NULL(files, false); 1091 PS_ASSERT_PTR_NON_NULL(name, false); 1092 PS_ASSERT_INT_POSITIVE(strlen(name), false); 1093 PS_ASSERT_PTR_NON_NULL(value, false); 1094 PS_ASSERT_INT_POSITIVE(strlen(value), false); 1020 1095 1021 1096 // add the output names to the output-type files … … 1036 1111 char *pmFPAfileNameFromRule (char *rule, pmFPAfile *file, const pmFPAview *view) 1037 1112 { 1113 PS_ASSERT_PTR_NON_NULL(rule, NULL); 1114 PS_ASSERT_INT_POSITIVE(strlen(rule), NULL); 1115 PS_ASSERT_PTR_NON_NULL(file, NULL); 1116 PS_ASSERT_PTR_NON_NULL(view, NULL); 1038 1117 1039 1118 char *newName = NULL; // destination for resulting name … … 1078 1157 bool pmFPAfileCopyView (pmFPA *out, pmFPA *in, const pmFPAview *view) 1079 1158 { 1159 PS_ASSERT_PTR_NON_NULL(out, false); 1160 PS_ASSERT_PTR_NON_NULL(in, false); 1161 PS_ASSERT_PTR_NON_NULL(view, false); 1162 1080 1163 // pmFPAWrite takes care of all PHUs as needed 1081 1164 if (view->chip == -1) { … … 1112 1195 bool pmFPAfileCopyStructureView (pmFPA *out, pmFPA *in, psMetadata *format, int xBin, int yBin, const pmFPAview *view) 1113 1196 { 1197 PS_ASSERT_PTR_NON_NULL(out, false); 1198 PS_ASSERT_PTR_NON_NULL(in, false); 1199 PS_ASSERT_PTR_NON_NULL(format, false); 1200 PS_ASSERT_PTR_NON_NULL(view, false); 1201 1114 1202 // pmFPAWrite takes care of all PHUs as needed 1115 1203 if (view->chip == -1) { -
trunk/psModules/src/camera/pmFPAview.c
r7017 r7278 3 3 * @author EAM, IfA 4 4 * 5 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 5-01 01:55:43$5 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-06-02 00:55:22 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 19 19 #include "pmFPAview.h" 20 20 21 static void pmFPAviewFree (pmFPAview *view) 22 { 23 if (view == NULL) 24 return; 21 static void pmFPAviewFree(pmFPAview *view) 22 { 23 // No reason to keep this function, apart from the fact that it allows us to type the memBlock 25 24 return; 26 25 } 27 26 28 pmFPAview *pmFPAviewAlloc (int nRows)29 { 30 pmFPAview *view = psAlloc (sizeof(pmFPAview));31 psMemSetDeallocator (view, (psFreeFunc) pmFPAviewFree);27 pmFPAview *pmFPAviewAlloc(int nRows) 28 { 29 pmFPAview *view = psAlloc(sizeof(pmFPAview)); 30 psMemSetDeallocator(view, (psFreeFunc) pmFPAviewFree); 32 31 33 32 view->chip = -1; … … 36 35 view->iRows = 0; 37 36 view->nRows = nRows; 38 return (view); 39 } 40 41 pmFPAdepth pmFPAviewDepth (const pmFPAview *view) 42 { 37 return view; 38 } 39 40 pmFPAdepth pmFPAviewDepth(const pmFPAview *view) 41 { 42 PS_ASSERT_PTR_NON_NULL(view, PM_FPA_DEPTH_NONE); 43 43 44 44 if (view->chip < 0) { … … 54 54 } 55 55 56 pmChip *pmFPAviewThisChip (const pmFPAview *view, pmFPA *fpa) 57 { 56 pmChip *pmFPAviewThisChip(const pmFPAview *view, pmFPA *fpa) 57 { 58 PS_ASSERT_PTR_NON_NULL(view, NULL); 59 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 58 60 59 61 if (view->chip < 0) { … … 69 71 } 70 72 71 pmChip *pmFPAviewNextChip (pmFPAview *view, pmFPA *fpa, int nStep) 72 { 73 pmChip *pmFPAviewNextChip(pmFPAview *view, pmFPA *fpa, int nStep) 74 { 75 PS_ASSERT_PTR_NON_NULL(view, NULL); 76 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 77 73 78 view->cell = -1; 74 79 view->readout = -1; … … 100 105 } 101 106 102 pmCell *pmFPAviewThisCell (const pmFPAview *view, pmFPA *fpa) 103 { 107 pmCell *pmFPAviewThisCell(const pmFPAview *view, pmFPA *fpa) 108 { 109 PS_ASSERT_PTR_NON_NULL(view, NULL); 110 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 104 111 105 112 if (view->cell < 0) { … … 108 115 109 116 pmChip *chip = pmFPAviewThisChip (view, fpa); 110 if (chip == NULL) { 111 return NULL; 112 } 117 PS_ASSERT_PTR_NON_NULL(chip, NULL); 113 118 114 119 if (view->cell >= chip->cells->n) { … … 122 127 pmCell *pmFPAviewNextCell (pmFPAview *view, pmFPA *fpa, int nStep) 123 128 { 129 PS_ASSERT_PTR_NON_NULL(view, NULL); 130 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 124 131 125 132 pmChip *chip = pmFPAviewThisChip (view, fpa); 126 if (chip == NULL) { 127 return NULL; 128 } 133 PS_ASSERT_PTR_NON_NULL(chip, NULL); 129 134 130 135 view->readout = -1; … … 158 163 pmReadout *pmFPAviewThisReadout (const pmFPAview *view, pmFPA *fpa) 159 164 { 165 PS_ASSERT_PTR_NON_NULL(view, NULL); 166 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 160 167 161 168 if (view->readout < 0) { … … 164 171 165 172 pmCell *cell = pmFPAviewThisCell (view, fpa); 166 if (cell == NULL) { 167 return NULL; 168 } 173 PS_ASSERT_PTR_NON_NULL(cell, NULL); 169 174 170 175 if (view->readout >= cell->readouts->n) { … … 178 183 pmReadout *pmFPAviewNextReadout (pmFPAview *view, pmFPA *fpa, int nStep) 179 184 { 185 PS_ASSERT_PTR_NON_NULL(view, NULL); 186 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 180 187 181 188 pmCell *cell = pmFPAviewThisCell (view, fpa); 182 if (cell == NULL) { 183 return NULL; 184 } 189 PS_ASSERT_PTR_NON_NULL(cell, NULL); 185 190 186 191 view->iRows = 0; … … 211 216 } 212 217 213 pmHDU *pmFPAviewThisHDU (const pmFPAview *view, pmFPA *fpa) 214 { 218 pmHDU *pmFPAviewThisHDU(const pmFPAview *view, pmFPA *fpa) 219 { 220 PS_ASSERT_PTR_NON_NULL(view, NULL); 221 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 222 215 223 // the HDU is attached to a cell, chip or fpa 216 224 // if this view has a -1 for the level which contains the hdu, … … 229 237 } 230 238 231 pmHDU *pmFPAviewThisPHU (const pmFPAview *view, pmFPA *fpa) 232 { 239 pmHDU *pmFPAviewThisPHU(const pmFPAview *view, pmFPA *fpa) 240 { 241 PS_ASSERT_PTR_NON_NULL(view, NULL); 242 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 243 233 244 // select the HDU which corresponds to the PHU containing this view 234 245 -
trunk/psModules/src/camera/pmHDU.c
r7241 r7278 61 61 psMemSetDeallocator(hdu, (psFreeFunc)hduFree); 62 62 63 if (! extname || strlen(extname) == 0) {63 if (!extname || strlen(extname) == 0) { 64 64 hdu->phu = true; 65 65 hdu->extname = psStringCopy("PHU"); … … 86 86 ) 87 87 { 88 assert(hdu);89 assert(fits);88 PS_ASSERT_PTR_NON_NULL(hdu, false); 89 PS_ASSERT_PTR_NON_NULL(fits, false); 90 90 91 91 // Move to the appropriate extension … … 113 113 ) 114 114 { 115 assert(hdu);116 assert(fits);115 PS_ASSERT_PTR_NON_NULL(hdu, false); 116 PS_ASSERT_PTR_NON_NULL(fits, false); 117 117 118 118 // Read the header; includes the move … … 159 159 ) 160 160 { 161 assert(hdu);162 assert(fits);161 PS_ASSERT_PTR_NON_NULL(hdu, false); 162 PS_ASSERT_PTR_NON_NULL(fits, false); 163 163 164 164 psTrace(__func__, 7, "Writing HDU %s\n", hdu->extname); -
trunk/psModules/src/camera/pmHDUGenerate.c
r7257 r7278 437 437 ) 438 438 { 439 PS_ASSERT_PTR_NON_NULL(cell, false); 440 439 441 // Get the HDU and a list of cells below it 440 442 pmHDU *hdu = pmHDUFromCell(cell); // The HDU in the cell … … 487 489 ) 488 490 { 491 PS_ASSERT_PTR_NON_NULL(chip, false); 492 489 493 // Get the HDU and a list of cells below it 490 494 pmHDU *hdu = pmHDUFromChip(chip); // The HDU in the chip … … 536 540 ) 537 541 { 542 PS_ASSERT_PTR_NON_NULL(fpa, false); 543 538 544 // Get the HDU and a list of cells below it 539 545 pmHDU *hdu = pmHDUFromFPA(fpa); // The HDU in the FPA -
trunk/psModules/src/camera/pmHDUUtils.c
r7168 r7278 8 8 ) 9 9 { 10 PS_ASSERT_PTR_NON_NULL(fpa, NULL); 10 11 return fpa->hdu; 11 12 } … … 14 15 ) 15 16 { 17 PS_ASSERT_PTR_NON_NULL(chip, NULL); 18 16 19 pmHDU *hdu = chip->hdu; // The HDU information 17 20 if (!hdu) { … … 25 28 ) 26 29 { 30 PS_ASSERT_PTR_NON_NULL(cell, NULL); 31 27 32 pmHDU *hdu = cell->hdu; // The HDU information 28 33 if (!hdu) { … … 33 38 } 34 39 35 pmHDU *pmHDUFromReadout (pmReadout *readout)40 pmHDU *pmHDUFromReadout(pmReadout *readout) 36 41 { 42 PS_ASSERT_PTR_NON_NULL(readout, NULL); 37 43 38 44 pmCell *cell = readout->parent; // cell containing this readout; 39 pmHDU *hdu = pmHDUFromCell (cell);45 pmHDU *hdu = pmHDUFromCell(cell); 40 46 return hdu; 41 47 } … … 64 70 ) 65 71 { 72 PS_ASSERT_PTR_NON_NULL(hdu,); 73 66 74 if (hdu->phu) { 67 75 psTrace(__func__, level, "HDU: %s (PHU)\n", hdu->extname); -
trunk/psModules/src/concepts/pmConcepts.c
r7017 r7278 44 44 ) 45 45 { 46 assert(blank); 46 PS_ASSERT_PTR_NON_NULL(blank, false); 47 47 48 if (!conceptsInitialised) { 48 49 pmConceptsInit(); … … 80 81 ) 81 82 { 83 assert(specs); 84 assert(target); 85 82 86 if (!conceptsInitialised) { 83 87 pmConceptsInit(); … … 119 123 ) 120 124 { 125 assert(specs); 126 assert(read); 127 assert(target); 128 121 129 if (!conceptsInitialised) { 122 130 pmConceptsInit(); … … 156 164 ) 157 165 { 166 assert(specs); 167 assert(concepts); 168 158 169 if (!conceptsInitialised) { 159 170 pmConceptsInit(); … … 180 191 ) 181 192 { 193 PS_ASSERT_PTR_NON_NULL(fpa, false); 182 194 psTrace("psModule.concepts", 5, "Blanking FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 183 195 return conceptsBlank(&conceptsFPA, fpa->concepts); … … 191 203 ) 192 204 { 205 PS_ASSERT_PTR_NON_NULL(fpa, false); 193 206 psTrace("psModule.concepts", 5, "Reading FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 194 207 return conceptsRead(&conceptsFPA, fpa, NULL, NULL, &fpa->conceptsRead, source, db, fpa->concepts); … … 201 214 ) 202 215 { 216 PS_ASSERT_PTR_NON_NULL(fpa, false); 203 217 psTrace("psModule.concepts", 5, "Writing FPA concepts: %x %x\n", conceptsFPA, fpa->concepts); 204 218 return conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source, db, fpa->concepts); … … 209 223 ) 210 224 { 225 PS_ASSERT_PTR_NON_NULL(chip, false); 211 226 psTrace("psModule.concepts", 5, "Blanking chip concepts: %x %x\n", conceptsChip, chip->concepts); 212 227 return conceptsBlank(&conceptsChip, chip->concepts); … … 220 235 ) 221 236 { 237 PS_ASSERT_PTR_NON_NULL(chip, false); 222 238 psTrace("psModule.concepts", 5, "Reading chip concepts: %x %x\n", conceptsChip, chip->concepts); 223 239 pmFPA *fpa = chip->parent; // FPA to which the chip belongs … … 235 251 ) 236 252 { 253 PS_ASSERT_PTR_NON_NULL(chip, false); 237 254 psTrace("psModule.concepts", 5, "Writing chip concepts: %x %x\n", conceptsChip, chip->concepts); 238 255 pmFPA *fpa = chip->parent; // FPA to which the chip belongs … … 246 263 ) 247 264 { 265 PS_ASSERT_PTR_NON_NULL(cell, false); 248 266 psTrace("psModule.concepts", 5, "Blanking cell concepts: %x %x\n", conceptsCell, cell->concepts); 249 267 return conceptsBlank(&conceptsCell, cell->concepts); … … 257 275 ) 258 276 { 277 PS_ASSERT_PTR_NON_NULL(cell, false); 259 278 psTrace("psModule.concepts", 5, "Reading cell concepts: %x %x\n", conceptsCell, cell->concepts); 260 279 pmChip *chip = cell->parent; // Chip to which the cell belongs … … 274 293 ) 275 294 { 295 PS_ASSERT_PTR_NON_NULL(cell, false); 276 296 psTrace("psModule.concepts", 5, "Writing cell concepts: %x %x\n", conceptsCell, cell->concepts); 277 297 pmChip *chip = cell->parent; // Chip to which the cell belongs … … 336 356 { 337 357 psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN); 338 pmConceptRegister(fpaRa, (pmConceptParseFunc)p mConceptParse_FPA_Coords,339 (pmConceptFormatFunc)p mConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);358 pmConceptRegister(fpaRa, (pmConceptParseFunc)p_pmConceptParse_FPA_Coords, 359 (pmConceptFormatFunc)p_pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA); 340 360 psFree(fpaRa); 341 361 } … … 344 364 { 345 365 psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN); 346 pmConceptRegister(fpaDec, (pmConceptParseFunc)p mConceptParse_FPA_Coords,347 (pmConceptFormatFunc)p mConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA);366 pmConceptRegister(fpaDec, (pmConceptParseFunc)p_pmConceptParse_FPA_Coords, 367 (pmConceptFormatFunc)p_pmConceptFormat_FPA_Coords, PM_FPA_LEVEL_FPA); 348 368 psFree(fpaDec); 349 369 } … … 446 466 "Trim section", trimsec); 447 467 psFree(trimsec); 448 pmConceptRegister(cellTrimsec, (pmConceptParseFunc)p mConceptParse_CELL_TRIMSEC,449 (pmConceptFormatFunc)p mConceptFormat_CELL_TRIMSEC, PM_FPA_LEVEL_CELL);468 pmConceptRegister(cellTrimsec, (pmConceptParseFunc)p_pmConceptParse_CELL_TRIMSEC, 469 (pmConceptFormatFunc)p_pmConceptFormat_CELL_TRIMSEC, PM_FPA_LEVEL_CELL); 450 470 psFree(cellTrimsec); 451 471 } … … 457 477 "Bias sections", biassecs); 458 478 psFree(biassecs); 459 pmConceptRegister(cellBiassec, (pmConceptParseFunc)p mConceptParse_CELL_BIASSEC,460 (pmConceptFormatFunc)p mConceptFormat_CELL_BIASSEC, PM_FPA_LEVEL_CELL);479 pmConceptRegister(cellBiassec, (pmConceptParseFunc)p_pmConceptParse_CELL_BIASSEC, 480 (pmConceptFormatFunc)p_pmConceptFormat_CELL_BIASSEC, PM_FPA_LEVEL_CELL); 461 481 psFree(cellBiassec); 462 482 } … … 465 485 { 466 486 psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0); 467 pmConceptRegister(cellXbin, (pmConceptParseFunc)p mConceptParse_CELL_Binning,468 (pmConceptFormatFunc)p mConceptFormat_CELL_XBIN, PM_FPA_LEVEL_CELL);487 pmConceptRegister(cellXbin, (pmConceptParseFunc)p_pmConceptParse_CELL_Binning, 488 (pmConceptFormatFunc)p_pmConceptFormat_CELL_XBIN, PM_FPA_LEVEL_CELL); 469 489 psFree(cellXbin); 470 490 } … … 473 493 { 474 494 psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0); 475 pmConceptRegister(cellYbin, (pmConceptParseFunc)p mConceptParse_CELL_Binning,476 (pmConceptFormatFunc)p mConceptFormat_CELL_YBIN, PM_FPA_LEVEL_CELL);495 pmConceptRegister(cellYbin, (pmConceptParseFunc)p_pmConceptParse_CELL_Binning, 496 (pmConceptFormatFunc)p_pmConceptFormat_CELL_YBIN, PM_FPA_LEVEL_CELL); 477 497 psFree(cellYbin); 478 498 } … … 481 501 { 482 502 psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1); 483 pmConceptRegister(cellTimesys, (pmConceptParseFunc)p mConceptParse_CELL_TIMESYS,484 (pmConceptFormatFunc)p mConceptFormat_CELL_TIMESYS, PM_FPA_LEVEL_CELL);503 pmConceptRegister(cellTimesys, (pmConceptParseFunc)p_pmConceptParse_CELL_TIMESYS, 504 (pmConceptFormatFunc)p_pmConceptFormat_CELL_TIMESYS, PM_FPA_LEVEL_CELL); 485 505 psFree(cellTimesys); 486 506 } … … 495 515 "Time of exposure", time); 496 516 psFree(time); 497 pmConceptRegister(cellTime, (pmConceptParseFunc)p mConceptParse_CELL_TIME,498 (pmConceptFormatFunc)p mConceptFormat_CELL_TIME, PM_FPA_LEVEL_CELL);517 pmConceptRegister(cellTime, (pmConceptParseFunc)p_pmConceptParse_CELL_TIME, 518 (pmConceptFormatFunc)p_pmConceptFormat_CELL_TIME, PM_FPA_LEVEL_CELL); 499 519 psFree(cellTime); 500 520 } … … 503 523 { 504 524 psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0); 505 pmConceptRegister(cellX0, (pmConceptParseFunc)p mConceptParse_CELL_Positions,506 (pmConceptFormatFunc)p mConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);525 pmConceptRegister(cellX0, (pmConceptParseFunc)p_pmConceptParse_CELL_Positions, 526 (pmConceptFormatFunc)p_pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL); 507 527 psFree(cellX0); 508 528 } … … 511 531 { 512 532 psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0); 513 pmConceptRegister(cellY0, (pmConceptParseFunc)p mConceptParse_CELL_Positions,514 (pmConceptFormatFunc)p mConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL);533 pmConceptRegister(cellY0, (pmConceptParseFunc)p_pmConceptParse_CELL_Positions, 534 (pmConceptFormatFunc)p_pmConceptFormat_CELL_Positions, PM_FPA_LEVEL_CELL); 515 535 psFree(cellY0); 516 536 } … … 534 554 ) 535 555 { 556 PS_ASSERT_PTR_NON_NULL(target, false); 557 PS_ASSERT_PTR_NON_NULL(source, false); 558 536 559 // Copy FPA concepts 537 560 target->concepts = psMetadataCopy(target->concepts, source->concepts); -
trunk/psModules/src/concepts/pmConceptsRead.c
r7017 r7278 1 1 #include <stdio.h> 2 #include <assert.h> 2 3 3 4 #include "pslib.h" … … 21 22 ) 22 23 { 24 assert(concept); 25 assert(pattern); 26 23 27 switch (pattern->type) { 24 28 case PS_DATA_STRING: { … … 53 57 ) 54 58 { 55 if (concept) { 56 psMetadataItem *parsed = NULL; // The parsed concept 57 if (spec->parse) { 58 parsed = spec->parse(concept, spec->blank, cameraFormat, fpa, chip, cell); 59 } else { 60 parsed = parsePlain(concept, spec->blank); 61 } 62 63 // Plug the parsed concept into a new psMetadataItem, so each "concept" has its own version that can 64 // be altered without affecting the others. Also, so that we maintain the template name and comment. 65 psMetadataItem *cleaned = NULL; // Item that's been cleaned up --- correct name and comment 66 switch (spec->blank->type) { 67 case PS_DATA_STRING: 68 cleaned = psMetadataItemAllocStr(spec->blank->name, spec->blank->comment, parsed->data.V); 69 break; 70 case PS_DATA_S32: 71 cleaned = psMetadataItemAllocS32(spec->blank->name, spec->blank->comment, parsed->data.S32); 72 break; 73 case PS_DATA_F32: 74 cleaned = psMetadataItemAllocF32(spec->blank->name, spec->blank->comment, parsed->data.F32); 75 break; 76 case PS_DATA_F64: 77 cleaned = psMetadataItemAllocF64(spec->blank->name, spec->blank->comment, parsed->data.F64); 78 break; 79 default: 80 cleaned = psMetadataItemAlloc(spec->blank->name, parsed->type, spec->blank->comment, 81 parsed->data.V); 82 } 83 psFree(parsed); 84 psMetadataAddItem(target, cleaned, PS_LIST_TAIL, PS_META_REPLACE); 85 psFree(cleaned); // Drop reference 86 return true; 87 } 88 89 return false; 59 assert(spec); 60 assert(cameraFormat); 61 assert(target); 62 63 if (!concept) { 64 return false; 65 } 66 67 psMetadataItem *parsed = NULL; // The parsed concept 68 if (spec->parse) { 69 parsed = spec->parse(concept, spec->blank, cameraFormat, fpa, chip, cell); 70 } else { 71 parsed = parsePlain(concept, spec->blank); 72 } 73 74 // Plug the parsed concept into a new psMetadataItem, so each "concept" has its own version that can 75 // be altered without affecting the others. Also, so that we maintain the template name and comment. 76 psMetadataItem *cleaned = NULL; // Item that's been cleaned up --- correct name and comment 77 switch (spec->blank->type) { 78 case PS_DATA_STRING: 79 cleaned = psMetadataItemAllocStr(spec->blank->name, spec->blank->comment, parsed->data.V); 80 break; 81 case PS_DATA_S32: 82 cleaned = psMetadataItemAllocS32(spec->blank->name, spec->blank->comment, parsed->data.S32); 83 break; 84 case PS_DATA_F32: 85 cleaned = psMetadataItemAllocF32(spec->blank->name, spec->blank->comment, parsed->data.F32); 86 break; 87 case PS_DATA_F64: 88 cleaned = psMetadataItemAllocF64(spec->blank->name, spec->blank->comment, parsed->data.F64); 89 break; 90 default: 91 cleaned = psMetadataItemAlloc(spec->blank->name, parsed->type, spec->blank->comment, 92 parsed->data.V); 93 } 94 psFree(parsed); 95 psMetadataAddItem(target, cleaned, PS_LIST_TAIL, PS_META_REPLACE); 96 psFree(cleaned); // Drop reference 97 return true; 90 98 } 91 99 … … 100 108 ) 101 109 { 102 if (cell) { 103 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 104 if (! hdu) { 105 return false; 106 } 107 psMetadata *cameraFormat = hdu->format; // The camera format 108 psMetadata *cellConfig = cell->config; // The camera configuration for this cell 109 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 110 psMetadataItem *specItem = NULL; // Item from the specs metadata 111 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 112 pmConceptSpec *spec = specItem->data.V; // The specification 113 psString name = specItem->name; // The concept name 114 psMetadataItem *conceptItem = psMetadataLookup(cellConfig, name); // The concept, or NULL 115 psMetadataItem *value = NULL; // The value of the concept 116 if (conceptItem) { 117 if (conceptItem->type == PS_DATA_STRING) { 118 // Check the SOURCE 119 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 120 psStringAppend(&nameSource, "%s.SOURCE", name); 121 bool mdok = true; // Status of MD lookup 122 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 123 psFree(nameSource); 124 if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) { 125 value = conceptItem; 126 conceptParse(spec, value, cameraFormat, target, NULL, NULL, cell); 127 } else if (source && (strlen(source) == 0 || strcasecmp(source, "HEADER") != 0)) { 128 // We leave "HEADER" to pmConceptsReadFromHeader 129 psError(PS_ERR_IO, true, "%s isn't HEADER or VALUE --- can't read %s\n", source, 130 name); 131 continue; 132 } 133 } else { 134 // Another type --- should be OK 135 conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell); 110 PS_ASSERT_PTR_NON_NULL(specs, false); 111 PS_ASSERT_PTR_NON_NULL(target, false); 112 if (!cell) { 113 return false; 114 } 115 116 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 117 if (! hdu) { 118 return false; 119 } 120 psMetadata *cameraFormat = hdu->format; // The camera format 121 psMetadata *cellConfig = cell->config; // The camera configuration for this cell 122 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 123 psMetadataItem *specItem = NULL; // Item from the specs metadata 124 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 125 pmConceptSpec *spec = specItem->data.V; // The specification 126 psString name = specItem->name; // The concept name 127 psMetadataItem *conceptItem = psMetadataLookup(cellConfig, name); // The concept, or NULL 128 psMetadataItem *value = NULL; // The value of the concept 129 if (conceptItem) { 130 if (conceptItem->type == PS_DATA_STRING) { 131 // Check the SOURCE 132 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 133 psStringAppend(&nameSource, "%s.SOURCE", name); 134 bool mdok = true; // Status of MD lookup 135 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 136 psFree(nameSource); 137 if (mdok && strlen(source) > 0 && strcasecmp(source, "VALUE") == 0) { 138 value = conceptItem; 139 conceptParse(spec, value, cameraFormat, target, NULL, NULL, cell); 140 } else if (source && (strlen(source) == 0 || strcasecmp(source, "HEADER") != 0)) { 141 // We leave "HEADER" to pmConceptsReadFromHeader 142 psError(PS_ERR_IO, true, "%s isn't HEADER or VALUE --- can't read %s\n", source, 143 name); 144 continue; 136 145 } 146 } else { 147 // Another type --- should be OK 148 conceptParse(spec, conceptItem, cameraFormat, target, NULL, NULL, cell); 137 149 } 138 150 } 139 psFree(specsIter); 140 return true; 141 } 142 return false; 151 } 152 psFree(specsIter); 153 return true; 143 154 } 144 155 … … 151 162 ) 152 163 { 164 PS_ASSERT_PTR_NON_NULL(specs, false); 165 PS_ASSERT_PTR_NON_NULL(target, false); 166 153 167 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 154 168 if (!hdu) { … … 158 172 bool mdok = true; // Status of MD lookup 159 173 psMetadata *defaults = psMetadataLookupMD(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec 160 if (mdok && defaults) { 161 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 162 psMetadata *cameraFormat = hdu->format; // The camera format 163 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 164 psMetadataItem *specItem = NULL; // Item from the specs metadata 165 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 166 pmConceptSpec *spec = specItem->data.V; // The specification 167 psString name = specItem->name; // The concept name 168 psMetadataItem *conceptItem = psMetadataLookup(defaults, name); // The concept, or NULL 169 conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell); 170 } 171 psFree(specsIter); 172 return true; 173 } 174 return false; 174 if (!mdok || !defaults) { 175 return false; 176 } 177 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 178 psMetadataItem *specItem = NULL; // Item from the specs metadata 179 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 180 pmConceptSpec *spec = specItem->data.V; // The specification 181 psString name = specItem->name; // The concept name 182 psMetadataItem *conceptItem = psMetadataLookup(defaults, name); // The concept, or NULL 183 conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell); 184 } 185 psFree(specsIter); 186 return true; 175 187 } 176 188 … … 183 195 ) 184 196 { 197 PS_ASSERT_PTR_NON_NULL(specs, false); 198 PS_ASSERT_PTR_NON_NULL(target, false); 199 185 200 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 186 201 if (!hdu) { … … 190 205 bool mdok = true; // Status of MD lookup 191 206 psMetadata *transSpec = psMetadataLookupMD(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec 192 if (mdok && transSpec) { 193 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 194 psMetadataItem *specItem = NULL; // Item from the specs metadata 195 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 196 pmConceptSpec *spec = specItem->data.V; // The specification 197 psString name = specItem->name; // The concept name 198 psMetadataItem *headerItem = NULL; // The value of the concept from the header 199 // First check the cell configuration 200 if (cell && cell->config) { 201 psMetadataItem *conceptItem = psMetadataLookup(cell->config, name); // The concept, or NULL 202 if (conceptItem) { 203 // Check the SOURCE 204 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 205 psStringAppend(&nameSource, "%s.SOURCE", name); 206 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 207 psFree(nameSource); 208 if (mdok && strlen(source) && strcasecmp(source, "HEADER") == 0) { 209 headerItem = psMetadataLookup(hdu->header, conceptItem->data.V); 207 if (!mdok || !transSpec) { 208 return false; 209 } 210 211 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 212 psMetadataItem *specItem = NULL; // Item from the specs metadata 213 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 214 pmConceptSpec *spec = specItem->data.V; // The specification 215 psString name = specItem->name; // The concept name 216 psMetadataItem *headerItem = NULL; // The value of the concept from the header 217 // First check the cell configuration 218 if (cell && cell->config) { 219 psMetadataItem *conceptItem = psMetadataLookup(cell->config, name); // The concept, or NULL 220 if (conceptItem) { 221 // Check the SOURCE 222 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 223 psStringAppend(&nameSource, "%s.SOURCE", name); 224 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 225 psFree(nameSource); 226 if (mdok && strlen(source) && strcasecmp(source, "HEADER") == 0) { 227 headerItem = psMetadataLookup(hdu->header, conceptItem->data.V); 228 } 229 // Leave the error handling to pmConceptsFromCamera, which should already have been called 230 } 231 } 232 if (! headerItem) { 233 psString keywords = psMetadataLookupStr(&mdok, transSpec, name); // The FITS keywords 234 if (mdok && strlen(keywords) > 0) { 235 // In case there are multiple headers 236 psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords 237 if (keys->n == 1) { 238 // Only one key --- proceed as usual 239 headerItem = psMetadataLookup(hdu->header, keywords); 240 } else { 241 psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator 242 psString key = NULL; // Item from iteration 243 psList *values = psListAlloc(NULL); // List containing the values 244 while ((key = psListGetAndIncrement(keysIter))) { 245 psMetadataItem *value = psMetadataLookup(hdu->header, key); 246 psListAdd(values, PS_LIST_TAIL, value); 210 247 } 211 // Leave the error handling to pmConceptsFromCamera, which should already have been called 248 psFree(keysIter); 249 headerItem = psMetadataItemAlloc(name, PS_DATA_LIST, specItem->comment, values); 250 psFree(values); 212 251 } 252 psFree(keys); 213 253 } 214 if (! headerItem) {215 psString keywords = psMetadataLookupStr(&mdok, transSpec, name); // The FITS keywords216 if (mdok && strlen(keywords) > 0) {217 // In case there are multiple headers218 psList *keys = psStringSplit(keywords, " ,;", true); // List of keywords219 if (keys->n == 1) {220 // Only one key --- proceed as usual221 headerItem = psMetadataLookup(hdu->header, keywords);222 } else {223 psListIterator *keysIter = psListIteratorAlloc(keys, PS_LIST_HEAD, false); // Iterator224 psString key = NULL; // Item from iteration225 psList *values = psListAlloc(NULL); // List containing the values226 while ((key = psListGetAndIncrement(keysIter))) {227 psMetadataItem *value = psMetadataLookup(hdu->header, key);228 psListAdd(values, PS_LIST_TAIL, value);229 }230 psFree(keysIter);231 headerItem = psMetadataItemAlloc(name, PS_DATA_LIST, specItem->comment, values);232 psFree(values);233 }234 psFree(keys);235 }236 }237 238 // This will also clean up the name239 conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell);240 254 } 241 psFree(specsIter); 242 return true; 243 } 244 return false; 255 256 // This will also clean up the name 257 conceptParse(spec, headerItem, cameraFormat, target, fpa, chip, cell); 258 } 259 psFree(specsIter); 260 return true; 245 261 } 246 262 … … 255 271 ) 256 272 { 273 PS_ASSERT_PTR_NON_NULL(specs, false); 274 PS_ASSERT_PTR_NON_NULL(target, false); 275 257 276 #ifdef OMIT_PSDB 277 258 278 return false; 259 279 #else … … 266 286 bool mdok = true; // Status of MD lookup 267 287 psMetadata *dbSpec = psMetadataLookupMD(&mdok, cameraFormat, "DATABSE"); // The DATABASE spec 268 if (mdok && dbSpec) { 269 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 270 psMetadata *cameraFormat = hdu->format; // The camera format 271 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 272 psMetadataItem *specItem = NULL; // Item from the specs metadata 273 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 274 pmConceptSpec *spec = specItem->data.V; // The specification 275 psString name = specItem->name; // The concept name 276 277 psMetadata *dbLookup = psMetadataLookupMD(&mdok, dbSpec, name); 278 if (mdok && dbLookup) { 279 const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); // Table name 280 // Names of the "where" columns 281 const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL"); 282 // Values of the "where" columns 283 const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS"); 284 285 // Now, need to get the "given"s 286 if (strlen(givenCols) > 0 || strlen(givenPS) > 0) { 287 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names 288 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns 289 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB 290 if (cols->n != values->n) { 288 if (!mdok || !dbSpec) { 289 return false; 290 } 291 292 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 293 psMetadataItem *specItem = NULL; // Item from the specs metadata 294 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 295 pmConceptSpec *spec = specItem->data.V; // The specification 296 psString name = specItem->name; // The concept name 297 298 psMetadata *dbLookup = psMetadataLookupMD(&mdok, dbSpec, name); 299 if (mdok && dbLookup) { 300 const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); // Table name 301 // Names of the "where" columns 302 const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL"); 303 // Values of the "where" columns 304 const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS"); 305 306 // Now, need to get the "given"s 307 if (strlen(givenCols) > 0 || strlen(givenPS) > 0) { 308 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names 309 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns 310 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB 311 if (cols->n != values->n) { 312 psLogMsg(__func__, PS_LOG_WARN, 313 "The GIVENDBCOL and GIVENPS entries for %s do not have " 314 "the same number of entries --- ignored.\n", name); 315 } else { 316 // Iterators for the lists 317 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false); 318 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); 319 char *column = NULL; // Name of the column 320 while ((column = psListGetAndIncrement(colsIter))) { 321 char *dependName = psListGetAndIncrement(valuesIter); // Name for the value 322 if (!strlen(column) || !strlen(name)) { 323 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is " 324 " empty --- ignored.\n", name); 325 } else { 326 // Search for the value name 327 psMetadataItem *item = NULL; // The value 328 if (!item && cell) { 329 item = psMetadataLookup(cell->concepts, dependName); 330 } 331 if (!item && chip) { 332 item = psMetadataLookup(chip->concepts, dependName); 333 } 334 if (!item && fpa) { 335 item = psMetadataLookup(fpa->concepts, dependName); 336 } 337 if (! item) { 338 psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB" 339 " lookup on %s --- ignored.\n", dependName, name); 340 } else { 341 // We need to create a new psMetadataItem. I don't think we can't 342 // simply hack the existing one, since that could conceivably cause 343 // memory leaks 344 psMetadataItem *newItem = psMetadataItemAlloc(name, item->type, 345 item->comment, 346 item->data.V); 347 psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE); 348 psFree(newItem); 349 } 350 } 351 psFree(dependName); 352 psFree(column); 353 } // Iterating through the columns 354 psFree(colsIter); 355 psFree(valuesIter); 356 357 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result 358 // Note that we use limit=2 in order to test if there are multiple rows returned 359 360 psMetadataItem *conceptItem = NULL; // The final result of the DB lookup 361 if (dbResult->n == 0) { 291 362 psLogMsg(__func__, PS_LOG_WARN, 292 "The GIVENDBCOL and GIVENPS entries for %s do not have " 293 "the same number of entries --- ignored.\n", name); 363 "Unable to find any rows in DB for %s --- ignored\n", name); 294 364 } else { 295 // Iterators for the lists 296 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false); 297 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); 298 char *column = NULL; // Name of the column 299 while ((column = psListGetAndIncrement(colsIter))) { 300 char *dependName = psListGetAndIncrement(valuesIter); // Name for the value 301 if (!strlen(column) || !strlen(name)) { 302 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is " 303 " empty --- ignored.\n", name); 304 } else { 305 // Search for the value name 306 psMetadataItem *item = NULL; // The value 307 if (!item && cell) { 308 item = psMetadataLookup(cell->concepts, dependName); 309 } 310 if (!item && chip) { 311 item = psMetadataLookup(chip->concepts, dependName); 312 } 313 if (!item && fpa) { 314 item = psMetadataLookup(fpa->concepts, dependName); 315 } 316 if (! item) { 317 psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB" 318 " lookup on %s --- ignored.\n", dependName, name); 319 } else { 320 // We need to create a new psMetadataItem. I don't think we can't 321 // simply hack the existing one, since that could conceivably cause 322 // memory leaks 323 psMetadataItem *newItem = psMetadataItemAlloc(name, item->type, 324 item->comment, 325 item->data.V); 326 psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE); 327 psFree(newItem); 328 } 329 } 330 psFree(dependName); 331 psFree(column); 332 } // Iterating through the columns 333 psFree(colsIter); 334 psFree(valuesIter); 335 336 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result 337 // Note that we use limit=2 in order to test if there are multiple rows returned 338 339 psMetadataItem *conceptItem = NULL; // The final result of the DB lookup 340 if (dbResult->n == 0) { 365 if (dbResult-> n > 1) { 341 366 psLogMsg(__func__, PS_LOG_WARN, 342 "Unable to find any rows in DB for %s --- ignored\n", name); 343 } else { 344 if (dbResult-> n > 1) { 345 psLogMsg(__func__, PS_LOG_WARN, 346 "Multiple rows returned in DB lookup for %s --- " 347 " using the first one only.\n", name); 348 } 349 conceptItem = (psMetadataItem*)dbResult->data[0]; 367 "Multiple rows returned in DB lookup for %s --- " 368 " using the first one only.\n", name); 350 369 } 351 352 // Now we have the result 353 conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell); 354 370 conceptItem = (psMetadataItem*)dbResult->data[0]; 355 371 } 356 psFree(cols); 357 psFree(values); 372 373 // Now we have the result 374 conceptParse(spec, conceptItem, cameraFormat, target, fpa, chip, cell); 375 358 376 } 359 } // Doing the "given"s. 360 361 } // Iterating through the concept specifications 362 psFree(specsIter); 363 364 return true; 365 } 366 return false; 377 psFree(cols); 378 psFree(values); 379 } 380 } // Doing the "given"s. 381 382 } // Iterating through the concept specifications 383 psFree(specsIter); 384 385 return true; 367 386 #endif 368 387 } 369 388 370 389 371 372 373 #ifdef OLD374 375 psMetadataItem *pmConceptReadFromCamera(pmCell *cell, // The cell376 const char *concept // Name of concept377 )378 {379 if (cell) {380 psMetadata *camera = cell->config; // Camera configuration381 psMetadataItem *item = psMetadataLookup(camera, concept);382 return item;383 }384 return NULL;385 }386 387 psMetadataItem *pmConceptReadFromHeader(pmFPA *fpa, // The FPA that contains the chip388 pmChip *chip, // The chip that contains the cell389 pmCell *cell, // The cell390 const char *concept // Name of concept391 )392 {393 bool mdStatus = true; // Status of MD lookup394 psMetadata *translation = psMetadataLookupMD(&mdStatus, fpa->camera, "TRANSLATION"); // FITS translation395 if (! mdStatus) {396 psError(PS_ERR_IO, false, "Unable to find TRANSLATION in camera configuration.\n");397 return NULL;398 }399 400 // Look for how to translate the concept into a FITS header name401 const char *keyword = psMetadataLookupStr(&mdStatus, translation, concept);402 if (mdStatus && strlen(keyword) > 0) {403 // We have a FITS header to look up --- search each level404 if (cell && cell->hdu) {405 psMetadataItem *cellItem = psMetadataLookup(cell->hdu->header, keyword);406 if (cellItem) {407 // XXX: Need to clean up before returning408 return cellItem;409 }410 }411 412 if (chip && chip->hdu) {413 psMetadataItem *chipItem = psMetadataLookup(chip->hdu->header, keyword);414 if (chipItem) {415 // XXX: Need to clean up before returning416 return chipItem;417 }418 }419 420 if (fpa->hdu) {421 psMetadataItem *fpaItem = psMetadataLookup(fpa->hdu->header, keyword);422 if (fpaItem) {423 // XXX: Need to clean up before returning424 return fpaItem;425 }426 }427 }428 429 // No header value430 return NULL;431 }432 433 434 // Look for a default435 psMetadataItem *pmConceptReadFromDefault(pmFPA *fpa, // The FPA that contains the chip436 pmChip *chip, // The chip that contains the cell437 pmCell *cell, // The cell438 const char *concept // Name of concept439 )440 {441 bool mdOK = true; // Status of MD lookup442 psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS");443 if (! mdOK) {444 psError(PS_ERR_IO, false, "Unable to find DEFAULTS in camera configuration.\n");445 return NULL;446 }447 448 psMetadataItem *defItem = psMetadataLookup(defaults, concept);449 if (defItem) {450 if (defItem->type == PS_DATA_METADATA) {451 // A dependent default452 psTrace(__func__, 7, "Evaluating dependent default....\n");453 psMetadata *dependents = defItem->data.V; // The list of dependents454 // Find out what it depends on455 psString dependName = psStringCopy(concept);456 psStringAppend(&dependName, ".DEPEND");457 psString dependsOn = psMetadataLookupStr(&mdOK, defaults, dependName);458 if (! mdOK) {459 psError(PS_ERR_IO, false, "Unable to find %s in camera configuration for dependent default"460 " --- ignored\n", dependName);461 // XXX: Need to clean up before returning462 return NULL;463 }464 psFree(dependName);465 // Find the value of the dependent concept466 psMetadataItem *depItem = pmConceptReadFromHeader(fpa, chip, cell, dependsOn);467 if (! depItem) {468 psError(PS_ERR_IO, true, "Unable to find value for %s (required for %s)\n", dependsOn,469 concept);470 return NULL;471 }472 if (depItem->type != PS_DATA_STRING) {473 psError(PS_ERR_IO, true, "Value of %s is not of type string, as required for dependency"474 " --- ignored.\n", dependsOn);475 }476 477 defItem = psMetadataLookup(dependents, depItem->data.V); // This is now what we were after478 }479 }480 481 // XXX: Need to clean up before returning482 return defItem; // defItem is either NULL or points to what was desired483 }484 485 486 // Look for a database lookup487 // XXX: Not tested488 psMetadataItem *pmConceptReadFromDB(pmFPA *fpa, // The FPA that contains the chip489 pmChip *chip, // The chip that contains the cell490 pmCell *cell, // The cell491 psDB *db, // DB handle492 const char *concept // Name of concept493 )494 {495 if (! db) {496 // No database initialised497 return NULL;498 }499 500 bool mdStatus = true; // Status of MD lookup501 psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE");502 if (! mdStatus) {503 // No error, because not everyone needs to use the DB504 return NULL;505 }506 507 psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, database, concept);508 if (dbLookup) {509 const char *tableName = psMetadataLookupStr(&mdStatus, dbLookup, "TABLE"); // Name of the table510 // const char *colName = psMetadataLookupStr(&mdStatus, dbLookup, "COLUMN"); // Name of the column511 const char *givenCols = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENDBCOL"); // Name of "where"512 // columns513 const char *givenPS = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENPS"); // Values for "where"514 // columns515 516 // Now, need to get the "given"s517 if (strlen(givenCols) || strlen(givenPS)) {518 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names519 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns520 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB521 if (cols->n != values->n) {522 psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "523 "the same number of entries --- ignored.\n", concept);524 } else {525 // Iterators for the lists526 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);527 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);528 char *column = NULL; // Name of the column529 while ((column = psListGetAndIncrement(colsIter))) {530 char *name = psListGetAndIncrement(valuesIter); // Name for the value531 if (!strlen(column) || !strlen(name)) {532 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "533 " empty --- ignored.\n", concept);534 } else {535 // Search for the value name536 psMetadataItem *item = pmConceptReadFromHeader(fpa, chip, cell, name);537 if (! item) {538 item = pmConceptReadFromDefault(fpa, chip, cell, name);539 }540 if (! item) {541 psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "542 " lookup on %s --- ignored.\n", name, concept);543 } else {544 // We need to create a new psMetadataItem. I don't think we can't simply hack545 // the existing one, since that could conceivably cause memory leaks546 psMetadataItem *newItem = psMetadataItemAlloc(concept, item->type,547 item->comment, item->data.V);548 psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);549 psFree(newItem);550 }551 }552 psFree(name);553 psFree(column);554 } // Iterating through the columns555 psFree(colsIter);556 psFree(valuesIter);557 558 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result559 // Note that we use limit=2 in order to test if there are multiple rows returned560 561 psMetadataItem *result = NULL; // The final result of the DB lookup562 if (dbResult->n == 0) {563 psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",564 concept);565 } else {566 if (dbResult-> n > 1) {567 psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "568 " using the first one only.\n", concept);569 }570 result = (psMetadataItem*)dbResult->data[0];571 }572 // XXX: Need to clean up before returning573 return result;574 }575 psFree(cols);576 psFree(values);577 }578 } // Doing the "given"s.579 580 psAbort(__func__, "Shouldn't ever get here.\n");581 return NULL;582 }583 584 585 // Concept lookup586 psMetadataItem *pmConceptRead(pmFPA *fpa, // The FPA587 pmChip *chip,// The chip588 pmCell *cell, // The cell589 psDB *db, // DB handle590 const char *name // Concept name591 )592 {593 // Try headers, database, defaults in order594 psMetadataItem *item = pmConceptReadFromCamera(cell, name);595 if (! item) {596 item = pmConceptReadFromHeader(fpa, chip, cell, name);597 }598 if (! item) {599 item = pmConceptReadFromDB(fpa, chip, cell, db, name);600 }601 if (! item) {602 item = pmConceptReadFromDefault(fpa, chip, cell, name);603 }604 return item; // item is either NULL, or points to what was desired605 }606 607 608 #endif -
trunk/psModules/src/concepts/pmConceptsStandard.c
r7253 r7278 9 9 #include "pmConceptsStandard.h" 10 10 11 // The functions in this file are intended to be called solely within the psModules concepts code. For this 12 // reason, they use "assert" instead of the PS_ASSERT_WHATEVER functions --- if there's a problem, then 13 // there's a BIG problem that affects all of the code. 11 14 12 15 #define COMPARE_REGIONS(a,b) (((a)->x0 == (b)->x0 && \ … … 38 41 39 42 // FPA.RA and FPA.DEC 40 psMetadataItem *pmConceptParse_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 43 psMetadataItem *p_pmConceptParse_FPA_Coords(psMetadataItem *concept, 44 psMetadataItem *pattern, 45 psMetadata *cameraFormat, 46 pmFPA *fpa, 47 pmChip *chip, 48 pmCell *cell) 41 49 { 42 50 assert(concept); … … 102 110 103 111 // FPA.RA and FPA.DEC 104 psMetadataItem *pmConceptFormat_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat) 105 { 106 assert(concept); 107 assert(pattern); 112 psMetadataItem *p_pmConceptFormat_FPA_Coords(psMetadataItem *concept, 113 psMetadata *cameraFormat, 114 pmFPA *fpa, 115 pmChip *chip, 116 pmCell *cell) 117 { 118 assert(concept); 108 119 assert(cameraFormat); 109 120 … … 112 123 // How to interpret the coordinates 113 124 bool mdok = true; // Status of MD lookup 114 psMetadata *formats = psMetadataLookupMD(&mdok, cameraFormat, "FORMATS"); 125 psMetadata *formats = psMetadataLookupMD(&mdok, 126 cameraFormat, 127 "FORMATS"); 115 128 if (mdok && formats) { 116 psString format = psMetadataLookupStr(&mdok, formats, pattern->name);129 psString format = psMetadataLookupStr(&mdok,formats, concept->name); 117 130 if (mdok && strlen(format) > 0) { 118 131 if (strcasecmp(format, "HOURS") == 0) { … … 123 136 // No action required 124 137 } else { 125 coords /= defaultCoordScaling( pattern);138 coords /= defaultCoordScaling(concept); 126 139 } 127 140 } else { 128 coords /= defaultCoordScaling( pattern);141 coords /= defaultCoordScaling(concept); 129 142 } 130 143 } else { 131 coords /= defaultCoordScaling( pattern);144 coords /= defaultCoordScaling(concept); 132 145 } 133 146 … … 140 153 psString coordString = NULL; // String with the coordinates in sexagesimal format 141 154 psStringAppend(&coordString, "%d:%d:%.2f", big, medium, small); 142 psMetadataItem *coordItem = psMetadataItemAllocStr( pattern->name, pattern->comment, coordString);155 psMetadataItem *coordItem = psMetadataItemAllocStr(concept->name, concept->comment, coordString); 143 156 psFree(coordString); 144 157 … … 147 160 148 161 149 psMetadataItem *pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 162 psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, 163 psMetadataItem *pattern, 164 psMetadata *cameraFormat, 165 pmFPA *fpa, 166 pmChip *chip, 167 pmCell *cell) 150 168 { 151 169 assert(concept); … … 167 185 } 168 186 169 psMetadataItem *pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 187 psMetadataItem *p_pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, 188 psMetadataItem *pattern, 189 psMetadata *cameraFormat, 190 pmFPA *fpa, 191 pmChip *chip, 192 pmCell *cell) 170 193 { 171 194 assert(concept); … … 218 241 219 242 // CELL.XBIN and CELL.YBIN 220 psMetadataItem *pmConceptParse_CELL_Binning(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 243 psMetadataItem *p_pmConceptParse_CELL_Binning(psMetadataItem *concept, 244 psMetadataItem *pattern, 245 psMetadata *cameraFormat, 246 pmFPA *fpa, 247 pmChip *chip, 248 pmCell *cell) 221 249 { 222 250 assert(concept); … … 249 277 250 278 251 psMetadataItem *pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 279 psMetadataItem *p_pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, 280 psMetadataItem *pattern, 281 psMetadata *cameraFormat, 282 pmFPA *fpa, 283 pmChip *chip, 284 pmCell *cell) 252 285 { 253 286 assert(concept); … … 274 307 275 308 276 psMetadataItem *pmConceptParse_CELL_TIME(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 309 psMetadataItem *p_pmConceptParse_CELL_TIME(psMetadataItem *concept, 310 psMetadataItem *pattern, 311 psMetadata *cameraFormat, 312 pmFPA *fpa, 313 pmChip *chip, 314 pmCell *cell) 277 315 { 278 316 assert(concept); … … 466 504 } 467 505 468 psMetadataItem *pmConceptParse_CELL_Positions(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 506 psMetadataItem *p_pmConceptParse_CELL_Positions(psMetadataItem *concept, 507 psMetadataItem *pattern, 508 psMetadata *cameraFormat, 509 pmFPA *fpa, 510 pmChip *chip, 511 pmCell *cell) 469 512 { 470 513 assert(concept); … … 489 532 490 533 491 psMetadataItem *pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 534 psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, 535 psMetadata *cameraFormat, 536 pmFPA *fpa, 537 pmChip *chip, 538 pmCell *cell) 492 539 { 493 540 assert(concept); … … 501 548 } 502 549 503 psMetadataItem *pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 550 psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, 551 psMetadata *cameraFormat, 552 pmFPA *fpa, 553 pmChip *chip, 554 pmCell *cell) 504 555 { 505 556 // Return a metadata item containing a list of metadata items of region strings … … 523 574 // This function actually does both CELL.XBIN and CELL.YBIN if CELL.XBIN and CELL.YBIN are specified by the 524 575 // same header. 525 psMetadataItem *pmConceptFormat_CELL_XBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 576 psMetadataItem *p_pmConceptFormat_CELL_XBIN(psMetadataItem *concept, 577 psMetadata *cameraFormat, 578 pmFPA *fpa, 579 pmChip *chip, 580 pmCell *cell) 526 581 { 527 582 assert(concept); … … 546 601 547 602 // Only need to format if both if CELL.XBIN and CELL.YBIN are not specified by the same header. 548 psMetadataItem *pmConceptFormat_CELL_YBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 603 psMetadataItem *p_pmConceptFormat_CELL_YBIN(psMetadataItem *concept, 604 psMetadata *cameraFormat, 605 pmFPA *fpa, 606 pmChip *chip, 607 pmCell *cell) 549 608 { 550 609 assert(concept); … … 565 624 566 625 567 psMetadataItem *pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 626 psMetadataItem *p_pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, 627 psMetadata *cameraFormat, 628 pmFPA *fpa, 629 pmChip *chip, 630 pmCell *cell) 568 631 { 569 632 psString sys = NULL; // String to store … … 590 653 } 591 654 592 psMetadataItem *pmConceptFormat_CELL_TIME(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 655 psMetadataItem *p_pmConceptFormat_CELL_TIME(psMetadataItem *concept, 656 psMetadata *cameraFormat, 657 pmFPA *fpa, 658 pmChip *chip, 659 pmCell *cell) 593 660 { 594 661 psTime *time = concept->data.V; // The time … … 699 766 } 700 767 701 psMetadataItem *pmConceptFormat_CELL_Positions(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell) 768 psMetadataItem *p_pmConceptFormat_CELL_Positions(psMetadataItem *concept, 769 psMetadata *cameraFormat, 770 pmFPA *fpa, 771 pmChip *chip, 772 pmCell *cell) 702 773 { 703 774 assert(concept); -
trunk/psModules/src/concepts/pmConceptsStandard.h
r7017 r7278 5 5 #include "pmFPA.h" 6 6 7 // Functions to parse and format the standard concepts 7 8 8 psMetadataItem *pmConceptParse_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 9 psMetadataItem *pmConceptFormat_FPA_Coords(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat); 10 psMetadataItem *pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 11 psMetadataItem *pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 12 psMetadataItem *pmConceptParse_CELL_Binning(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 13 psMetadataItem *pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 14 psMetadataItem *pmConceptParse_CELL_TIME(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 15 psMetadataItem *pmConceptParse_CELL_Positions(psMetadataItem *concept, psMetadataItem *pattern, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 16 psMetadataItem *pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 17 psMetadataItem *pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 18 psMetadataItem *pmConceptFormat_CELL_XBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 19 psMetadataItem *pmConceptFormat_CELL_YBIN(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 20 psMetadataItem *pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 21 psMetadataItem *pmConceptFormat_CELL_TIME(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 22 psMetadataItem *pmConceptFormat_CELL_Positions(psMetadataItem *concept, psMetadata *cameraFormat, pmFPA *fpa, pmChip *chip, pmCell *cell); 9 psMetadataItem *p_pmConceptParse_FPA_Coords(psMetadataItem *concept, 10 psMetadataItem *pattern, 11 psMetadata *cameraFormat, 12 pmFPA *fpa, 13 pmChip *chip, 14 pmCell *cell); 15 psMetadataItem *p_pmConceptFormat_FPA_Coords(psMetadataItem *concept, 16 psMetadata *cameraFormat, 17 pmFPA *fpa, 18 pmChip *chip, 19 pmCell *cell); 20 psMetadataItem *p_pmConceptParse_CELL_TRIMSEC(psMetadataItem *concept, 21 psMetadataItem *pattern, 22 psMetadata *cameraFormat, 23 pmFPA *fpa, 24 pmChip *chip, 25 pmCell *cell); 26 psMetadataItem *p_pmConceptParse_CELL_BIASSEC(psMetadataItem *concept, 27 psMetadataItem *pattern, 28 psMetadata *cameraFormat, 29 pmFPA *fpa, 30 pmChip *chip, 31 pmCell *cell); 32 psMetadataItem *p_pmConceptParse_CELL_Binning(psMetadataItem *concept, 33 psMetadataItem *pattern, 34 psMetadata *cameraFormat, 35 pmFPA *fpa, 36 pmChip *chip, 37 pmCell *cell); 38 psMetadataItem *p_pmConceptParse_CELL_TIMESYS(psMetadataItem *concept, 39 psMetadataItem *pattern, 40 psMetadata *cameraFormat, 41 pmFPA *fpa, 42 pmChip *chip, 43 pmCell *cell); 44 psMetadataItem *p_pmConceptParse_CELL_TIME(psMetadataItem *concept, 45 psMetadataItem *pattern, 46 psMetadata *cameraFormat, 47 pmFPA *fpa, 48 pmChip *chip, 49 pmCell *cell); 50 psMetadataItem *p_pmConceptParse_CELL_Positions(psMetadataItem *concept, 51 psMetadataItem *pattern, 52 psMetadata *cameraFormat, 53 pmFPA *fpa, 54 pmChip *chip, 55 pmCell *cell); 56 psMetadataItem *p_pmConceptFormat_CELL_TRIMSEC(psMetadataItem *concept, 57 psMetadata *cameraFormat, 58 pmFPA *fpa, 59 pmChip *chip, 60 pmCell *cell); 61 psMetadataItem *p_pmConceptFormat_CELL_BIASSEC(psMetadataItem *concept, 62 psMetadata *cameraFormat, 63 pmFPA *fpa, 64 pmChip *chip, 65 pmCell *cell); 66 psMetadataItem *p_pmConceptFormat_CELL_XBIN(psMetadataItem *concept, 67 psMetadata *cameraFormat, 68 pmFPA *fpa, 69 pmChip *chip, 70 pmCell *cell); 71 psMetadataItem *p_pmConceptFormat_CELL_YBIN(psMetadataItem *concept, 72 psMetadata *cameraFormat, 73 pmFPA *fpa, 74 pmChip *chip, 75 pmCell *cell); 76 psMetadataItem *p_pmConceptFormat_CELL_TIMESYS(psMetadataItem *concept, 77 psMetadata *cameraFormat, 78 pmFPA *fpa, 79 pmChip *chip, 80 pmCell *cell); 81 psMetadataItem *p_pmConceptFormat_CELL_TIME(psMetadataItem *concept, 82 psMetadata *cameraFormat, 83 pmFPA *fpa, 84 pmChip *chip, 85 pmCell *cell); 86 psMetadataItem *p_pmConceptFormat_CELL_Positions(psMetadataItem *concept, 87 psMetadata *cameraFormat, 88 pmFPA *fpa, 89 pmChip *chip, 90 pmCell *cell); 23 91 24 92 #endif -
trunk/psModules/src/concepts/pmConceptsWrite.c
r7017 r7278 1 1 #include <stdio.h> 2 #include <assert.h> 2 3 #include <strings.h> 3 4 #include "pslib.h" … … 110 111 ) 111 112 { 113 assert(spec); 114 assert(cameraFormat); 115 112 116 if (concept) { 113 117 psMetadataItem *formatted = NULL; // The formatted concept … … 129 133 ) 130 134 { 135 assert(hdu); 136 assert(keyword && strlen(keyword) > 0); 137 assert(item); 138 131 139 if (!hdu->header) { 132 140 return false; … … 166 174 ) 167 175 { 176 assert(hdu); 177 assert(keywords); 178 assert(item); 179 168 180 bool status = true; // Status of writing headers, to be returned 169 181 if (item->type == PS_DATA_LIST) { … … 204 216 ) 205 217 { 206 if (cell) { 207 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 208 if (!hdu) { 209 return false; 210 } 211 psMetadata *cameraFormat = hdu->format; // The camera format 212 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 213 psMetadataItem *specItem = NULL; // Item from the specs metadata 214 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 215 pmConceptSpec *spec = specItem->data.V; // The specification 216 psString name = specItem->name; // The concept name 217 psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera, 218 // or NULL 219 if (cameraItem) { 220 // Grab the concept 221 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept 222 // Formatted version 223 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell); 224 if (!formatted) { 225 continue; 226 } 227 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 228 psStringAppend(&nameSource, "%s.SOURCE", name); 229 bool mdok = true; // Status of MD lookup 230 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 231 if (mdok && strlen(source) > 0) { 232 psTrace(__func__, 8, "%s is %s\n", nameSource, source); 233 if (strcasecmp(source, "HEADER") == 0) { 234 if (cameraItem->type != PS_DATA_STRING) { 235 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by header, but is not " 236 "of type STR --- ignored.\n", conceptItem->name); 237 continue; 238 } 239 psTrace(__func__, 8, "Writing %s to header %s\n", name, cameraItem->data.V); 240 writeHeader(hdu, cameraItem->data.V, formatted); 241 } else if (strcasecmp(source, "VALUE") == 0) { 242 psTrace(__func__, 8, "Checking %s against camera format.\n", name); 243 if (! compareConcepts(formatted, cameraItem)) { 244 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " 245 "format, but the values don't match.\n", name); 246 } 247 } else { 248 psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't " 249 "write\n", nameSource); 218 PS_ASSERT_PTR_NON_NULL(specs, false); 219 PS_ASSERT_PTR_NON_NULL(concepts, false); 220 if (!cell) { 221 return false; 222 } 223 224 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 225 if (!hdu) { 226 return false; 227 } 228 psMetadata *cameraFormat = hdu->format; // The camera format 229 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 230 psMetadataItem *specItem = NULL; // Item from the specs metadata 231 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 232 pmConceptSpec *spec = specItem->data.V; // The specification 233 psString name = specItem->name; // The concept name 234 psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera, 235 // or NULL 236 if (cameraItem) { 237 // Grab the concept 238 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept 239 // Formatted version 240 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell); 241 if (!formatted) { 242 continue; 243 } 244 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 245 psStringAppend(&nameSource, "%s.SOURCE", name); 246 bool mdok = true; // Status of MD lookup 247 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 248 if (mdok && strlen(source) > 0) { 249 psTrace(__func__, 8, "%s is %s\n", nameSource, source); 250 if (strcasecmp(source, "HEADER") == 0) { 251 if (cameraItem->type != PS_DATA_STRING) { 252 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by header, but is not " 253 "of type STR --- ignored.\n", conceptItem->name); 254 continue; 250 255 } 251 } else if (! compareConcepts(formatted, cameraItem)) { 252 // Assume it's specified by value 253 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " 254 "format, but the values don't match.\n", name); 255 } 256 psFree(formatted); 257 psFree(nameSource); 258 } 259 260 } 261 psFree(specsIter); 262 return true; 263 } 264 return false; 256 psTrace(__func__, 8, "Writing %s to header %s\n", name, cameraItem->data.V); 257 writeHeader(hdu, cameraItem->data.V, formatted); 258 } else if (strcasecmp(source, "VALUE") == 0) { 259 psTrace(__func__, 8, "Checking %s against camera format.\n", name); 260 if (! compareConcepts(formatted, cameraItem)) { 261 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " 262 "format, but the values don't match.\n", name); 263 } 264 } else { 265 psLogMsg(__func__, PS_LOG_WARN, "Concept source %s isn't HEADER or VALUE --- can't " 266 "write\n", nameSource); 267 } 268 } else if (! compareConcepts(formatted, cameraItem)) { 269 // Assume it's specified by value 270 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by value in the camera " 271 "format, but the values don't match.\n", name); 272 } 273 psFree(formatted); 274 psFree(nameSource); 275 } 276 277 } 278 psFree(specsIter); 279 return true; 265 280 } 266 281 … … 272 287 ) 273 288 { 289 PS_ASSERT_PTR_NON_NULL(specs, false); 290 PS_ASSERT_PTR_NON_NULL(concepts, false); 291 274 292 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 275 293 if (!hdu) { … … 279 297 bool mdok = true; // Status of MD lookup 280 298 psMetadata *defaults = psMetadataLookupMD(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec 281 if (mdok && defaults) { 282 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 283 psMetadata *cameraFormat = hdu->format; // The camera format 284 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 285 psMetadataItem *specItem = NULL; // Item from the specs metadata 286 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 287 pmConceptSpec *spec = specItem->data.V; // The specification 288 psString name = specItem->name; // The concept name 289 psMetadataItem *defaultItem = psMetadataLookup(defaults, name); // The item from the DEFAULTS 290 if (defaultItem) { 291 psMetadataItem *conceptItem = NULL; // The item from the concepts 292 if (defaultItem->type == PS_DATA_METADATA) { 293 // It's a menu --- need to look up the .DEPEND 294 psString dependName = NULL; // The concept name with ".DEPEND" on the end 295 psStringAppend(&dependName, ".DEPEND"); 296 psString dependKey = psMetadataLookupStr(&mdok, defaults, dependName); // The keyword 297 psFree(dependName); 298 if (!mdok || !dependKey || strlen(dependKey) == 0) { 299 psLogMsg(__func__, PS_LOG_WARN, "Can't find %s in the DEFAULTS for %s --- ignored.\n", 300 dependName, name); 301 continue; 302 } 303 psString dependValue = psMetadataLookupStr(&mdok, concepts, dependName); // The value 304 if (!mdok || !dependKey || strlen(dependKey) == 0) { 305 psLogMsg(__func__, PS_LOG_WARN, "Concept %s specified by %s isn't of type STR -- " 306 "ignored.\n", name, dependName); 307 continue; 308 } 309 conceptItem = psMetadataLookup(defaultItem->data.V, dependValue); 310 } else { 311 conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 312 } 313 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 314 if (!formatted) { 299 if (!mdok || !defaults) { 300 return false; 301 } 302 303 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 304 psMetadataItem *specItem = NULL; // Item from the specs metadata 305 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 306 pmConceptSpec *spec = specItem->data.V; // The specification 307 psString name = specItem->name; // The concept name 308 psMetadataItem *defaultItem = psMetadataLookup(defaults, name); // The item from the DEFAULTS 309 if (defaultItem) { 310 psMetadataItem *conceptItem = NULL; // The item from the concepts 311 if (defaultItem->type == PS_DATA_METADATA) { 312 // It's a menu --- need to look up the .DEPEND 313 psString dependName = NULL; // The concept name with ".DEPEND" on the end 314 psStringAppend(&dependName, ".DEPEND"); 315 psString dependKey = psMetadataLookupStr(&mdok, defaults, dependName); // The keyword 316 psFree(dependName); 317 if (!mdok || !dependKey || strlen(dependKey) == 0) { 318 psLogMsg(__func__, PS_LOG_WARN, "Can't find %s in the DEFAULTS for %s --- ignored.\n", 319 dependName, name); 315 320 continue; 316 321 } 317 if (! compareConcepts(formatted, defaultItem)) { 318 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera " 319 "format, but the values don't match.\n", name); 320 } 321 psFree(formatted); 322 } 323 } 324 psFree(specsIter); 325 return true; 326 } 327 return false; 322 psString dependValue = psMetadataLookupStr(&mdok, concepts, dependName); // The value 323 if (!mdok || !dependKey || strlen(dependKey) == 0) { 324 psLogMsg(__func__, PS_LOG_WARN, "Concept %s specified by %s isn't of type STR -- " 325 "ignored.\n", name, dependName); 326 continue; 327 } 328 conceptItem = psMetadataLookup(defaultItem->data.V, dependValue); 329 } else { 330 conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 331 } 332 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 333 if (!formatted) { 334 continue; 335 } 336 if (! compareConcepts(formatted, defaultItem)) { 337 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera " 338 "format, but the values don't match.\n", name); 339 } 340 psFree(formatted); 341 } 342 } 343 psFree(specsIter); 344 return true; 328 345 } 329 346 … … 336 353 ) 337 354 { 355 PS_ASSERT_PTR_NON_NULL(specs, false); 356 PS_ASSERT_PTR_NON_NULL(concepts, false); 357 338 358 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 339 359 if (!hdu) { … … 343 363 bool mdok = true; // Status of MD lookup 344 364 psMetadata *translation = psMetadataLookupMD(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec 345 if (mdok && translation) { 346 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 347 psMetadata *cameraFormat = hdu->format; // The camera format 348 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 349 psMetadataItem *specItem = NULL; // Item from the specs metadata 350 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 351 pmConceptSpec *spec = specItem->data.V; // The specification 352 psString name = specItem->name; // The concept name 353 psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION 354 if (headerItem) { 355 if (headerItem->type != PS_DATA_STRING) { 356 psLogMsg(__func__, PS_LOG_WARN, "TRANSLATION keyword for concept %s isn't of type STR ---" 357 " ignored.", name); 358 continue; 359 } 360 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 361 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 362 if (!formatted) { 363 continue; 364 } 365 psList *keywords = psStringSplit(headerItem->data.V, " ,;", true); // List of header keywords 366 if (formatted->type == PS_DATA_LIST) { 367 psList *values = formatted->data.V; // The values for the headers 368 if (values->n != keywords->n) { 369 psLogMsg(__func__, PS_LOG_WARN, "Number of headers specified does not match number " 370 "of values for concept %s.\n", name); 365 if (!mdok || !translation) { 366 return false; 367 } 368 369 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 370 psMetadataItem *specItem = NULL; // Item from the specs metadata 371 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 372 pmConceptSpec *spec = specItem->data.V; // The specification 373 psString name = specItem->name; // The concept name 374 psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION 375 if (headerItem) { 376 if (headerItem->type != PS_DATA_STRING) { 377 psLogMsg(__func__, PS_LOG_WARN, "TRANSLATION keyword for concept %s isn't of type STR ---" 378 " ignored.", name); 379 continue; 380 } 381 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 382 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 383 if (!formatted) { 384 continue; 385 } 386 psList *keywords = psStringSplit(headerItem->data.V, " ,;", true); // List of header keywords 387 if (formatted->type == PS_DATA_LIST) { 388 psList *values = formatted->data.V; // The values for the headers 389 if (values->n != keywords->n) { 390 psLogMsg(__func__, PS_LOG_WARN, "Number of headers specified does not match number " 391 "of values for concept %s.\n", name); 392 } 393 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator 394 psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false); 395 psMetadataItem *valuesItem = NULL; // Item from list 396 while ((valuesItem = psListGetAndIncrement(valuesIter))) { 397 psString keyword = psListGetAndIncrement(keywordsIter); // Keyword from the list 398 if (strlen(keyword) > 0) { 399 writeHeader(hdu, keyword, formatted); 371 400 } 372 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); // Iterator 373 psListIterator *keywordsIter = psListIteratorAlloc(keywords, PS_LIST_HEAD, false); 374 psMetadataItem *valuesItem = NULL; // Item from list 375 while ((valuesItem = psListGetAndIncrement(valuesIter))) { 376 psString keyword = psListGetAndIncrement(keywordsIter); // Keyword from the list 377 if (strlen(keyword) > 0) { 378 writeHeader(hdu, keyword, formatted); 379 } 380 } 381 psFree(valuesIter); 382 psFree(keywordsIter); 383 } else { 384 psString keyword = psListGet(keywords, PS_LIST_HEAD); // The keyword 385 writeHeader(hdu, keyword, formatted); 386 } 387 psFree(formatted); 388 psFree(keywords); 389 } 390 } 391 psFree(specsIter); 392 return true; 393 } 394 return false; 401 } 402 psFree(valuesIter); 403 psFree(keywordsIter); 404 } else { 405 psString keyword = psListGet(keywords, PS_LIST_HEAD); // The keyword 406 writeHeader(hdu, keyword, formatted); 407 } 408 psFree(formatted); 409 psFree(keywords); 410 } 411 } 412 psFree(specsIter); 413 return true; 395 414 } 396 415 … … 404 423 ) 405 424 { 425 PS_ASSERT_PTR_NON_NULL(specs, false); 426 PS_ASSERT_PTR_NON_NULL(concepts, false); 427 428 if (!db) { 429 return false; 430 } 431 406 432 #ifdef OMIT_PSDB 407 433 return false; … … 415 441 bool mdok = true; // Status of MD lookup 416 442 psMetadata *database = psMetadataLookupMD(&mdok, cameraFormat, "DATABASE"); // The DATABASE spec 417 if (mdok && database) { 418 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 419 psMetadata *cameraFormat = hdu->format; // The camera format 420 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 421 psMetadataItem *specItem = NULL; // Item from the specs metadata 422 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 423 pmConceptSpec *spec = specItem->data.V; // The specification 424 psString name = specItem->name; // The concept name 425 426 psMetadataItem *dbItem = psMetadataLookup(database, name); // The item from the DATABASE 427 if (dbItem) { 428 if (dbItem->type != PS_DATA_METADATA) { 429 psLogMsg(__func__, PS_LOG_WARN, "DATABASE keyword for concept %s isn't of type METADATA " 430 "--- ignored.\n", name); 431 continue; 432 } 433 434 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 435 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 436 if (!formatted) { 437 continue; 438 } 439 440 psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest 441 // Name of the table 442 const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); 443 // Name of "where" columns 444 const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL"); 445 // Values for "where" columns 446 const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS"); 447 448 // Now, need to get the "given"s 449 if (strlen(givenCols) || strlen(givenPS)) { 450 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names 451 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns 452 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB 453 if (cols->n != values->n) { 454 psLogMsg(__func__, PS_LOG_WARN, 455 "The GIVENDBCOL and GIVENPS entries for %s do not have " 456 "the same number of entries --- ignored.\n", name); 443 if (!mdok || !database) { 444 return false; 445 } 446 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 447 psMetadataItem *specItem = NULL; // Item from the specs metadata 448 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 449 pmConceptSpec *spec = specItem->data.V; // The specification 450 psString name = specItem->name; // The concept name 451 452 psMetadataItem *dbItem = psMetadataLookup(database, name); // The item from the DATABASE 453 if (dbItem) { 454 if (dbItem->type != PS_DATA_METADATA) { 455 psLogMsg(__func__, PS_LOG_WARN, "DATABASE keyword for concept %s isn't of type METADATA " 456 "--- ignored.\n", name); 457 continue; 458 } 459 460 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 461 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 462 if (!formatted) { 463 continue; 464 } 465 466 psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest 467 // Name of the table 468 const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); 469 // Name of "where" columns 470 const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL"); 471 // Values for "where" columns 472 const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS"); 473 474 // Now, need to get the "given"s 475 if (strlen(givenCols) || strlen(givenPS)) { 476 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names 477 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns 478 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB 479 if (cols->n != values->n) { 480 psLogMsg(__func__, PS_LOG_WARN, 481 "The GIVENDBCOL and GIVENPS entries for %s do not have " 482 "the same number of entries --- ignored.\n", name); 483 } else { 484 // Iterators for the lists 485 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false); 486 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); 487 char *column = NULL; // Name of the column 488 while ((column = psListGetAndIncrement(colsIter))) { 489 char *dependName = psListGetAndIncrement(valuesIter); // Name for the value 490 if (!strlen(column) || !strlen(name)) { 491 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is " 492 " empty --- ignored.\n", name); 493 } else { 494 // Search for the value name 495 psMetadataItem *item = NULL; // The value 496 if (!item && cell) { 497 item = psMetadataLookup(cell->concepts, dependName); 498 } 499 if (!item && chip) { 500 item = psMetadataLookup(chip->concepts, dependName); 501 } 502 if (!item && fpa) { 503 item = psMetadataLookup(fpa->concepts, dependName); 504 } 505 if (! item) { 506 psLogMsg(__func__, PS_LOG_ERROR, 507 "Unable to find the value name %s for DB " 508 " lookup on %s --- ignored.\n", dependName, name); 509 } else { 510 // We need to create a new psMetadataItem. I don't think we can't simply 511 // hack the existing one, since that could conceivably cause memory leaks 512 psMetadataAddItem(selection, formatted, PS_LIST_TAIL, PS_META_REPLACE); 513 psFree(formatted); 514 } 515 } 516 psFree(dependName); 517 psFree(column); 518 } // Iterating through the columns 519 psFree(colsIter); 520 psFree(valuesIter); 521 522 // Check first to make sure we're only going to touch one row 523 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result 524 // Note that we use limit=2 in order to test if there are multiple rows returned 525 if (! dbResult || dbResult->n == 0) { 526 psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- " 527 "ignored\n", name); 528 return false; 457 529 } else { 458 // Iterators for the lists 459 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false); 460 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false); 461 char *column = NULL; // Name of the column 462 while ((column = psListGetAndIncrement(colsIter))) { 463 char *dependName = psListGetAndIncrement(valuesIter); // Name for the value 464 if (!strlen(column) || !strlen(name)) { 465 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is " 466 " empty --- ignored.\n", name); 467 } else { 468 // Search for the value name 469 psMetadataItem *item = NULL; // The value 470 if (!item && cell) { 471 item = psMetadataLookup(cell->concepts, dependName); 472 } 473 if (!item && chip) { 474 item = psMetadataLookup(chip->concepts, dependName); 475 } 476 if (!item && fpa) { 477 item = psMetadataLookup(fpa->concepts, dependName); 478 } 479 if (! item) { 480 psLogMsg(__func__, PS_LOG_ERROR, 481 "Unable to find the value name %s for DB " 482 " lookup on %s --- ignored.\n", dependName, name); 483 } else { 484 // We need to create a new psMetadataItem. I don't think we can't simply 485 // hack the existing one, since that could conceivably cause memory leaks 486 psMetadataAddItem(selection, formatted, PS_LIST_TAIL, PS_META_REPLACE); 487 psFree(formatted); 488 } 489 } 490 psFree(dependName); 491 psFree(column); 492 } // Iterating through the columns 493 psFree(colsIter); 494 psFree(valuesIter); 495 496 // Check first to make sure we're only going to touch one row 497 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result 498 // Note that we use limit=2 in order to test if there are multiple rows returned 499 if (! dbResult || dbResult->n == 0) { 500 psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- " 501 "ignored\n", name); 502 return false; 503 } else { 504 if (dbResult->n > 1) { 505 psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s " 506 "--- ignored.\n", name); 507 } 508 // Update the DB 509 psMetadata *update = psMetadataAlloc(); 510 psMetadataAddItem(update, conceptItem, PS_LIST_HEAD, 0); 511 psDBUpdateRows(db, tableName, selection, update); 512 psFree(update); 513 return true; 530 if (dbResult->n > 1) { 531 psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s " 532 "--- ignored.\n", name); 514 533 } 534 // Update the DB 535 psMetadata *update = psMetadataAlloc(); 536 psMetadataAddItem(update, conceptItem, PS_LIST_HEAD, 0); 537 psDBUpdateRows(db, tableName, selection, update); 538 psFree(update); 539 return true; 515 540 } 516 psFree(cols); 517 psFree(values); 518 } // Doing the "given"s. 519 } 520 } 521 psFree(specsIter); 522 return true; 523 } 524 return false; 541 } 542 psFree(cols); 543 psFree(values); 544 } // Doing the "given"s. 545 } 546 } 547 psFree(specsIter); 548 return true; 525 549 #endif 526 550 } 527 551 528 529 530 531 #if 0532 533 // Well, not really "write", but check to make sure it's there and matches534 bool pmConceptWriteToCamera(pmCell *cell, // The cell535 psMetadataItem *concept // Concept536 )537 {538 if (! cell->config) {539 return false;540 }541 if (cell) {542 psMetadataItem *item = psMetadataLookup(cell->config, concept->name); // Info we want543 return compareConcepts(item, concept);544 }545 546 return false;547 }548 549 // Write the concept to the header in the appropriate location550 bool pmConceptWriteToHeader(pmFPA *fpa, // The FPA that contains the chip551 pmChip *chip, // The chip that contains the cell552 pmCell *cell, // The cell553 psMetadataItem *concept // Concept554 )555 {556 bool mdok = true; // Status of MD lookup557 bool status = false; // Status of setting header558 if (! fpa->camera) {559 return false;560 }561 psMetadata *translation = psMetadataLookupMD(&mdok, fpa->camera, "TRANSLATION"); // FITS translation562 if (! mdok) {563 psError(PS_ERR_IO, false, "Unable to find TRANSLATION in camera configuration.\n");564 return false;565 }566 567 // Look for how to translate the concept into a FITS header name568 const char *keyword = psMetadataLookupStr(&mdok, translation, concept->name);569 if (mdok && strlen(keyword) > 0) {570 psTrace(__func__, 6, "It's in keyword %s\n", keyword);571 psMetadataItem *headerItem = NULL; // Item to add to header572 // XXX: Need to expand range of types573 switch (concept->type) {574 case PS_DATA_STRING:575 headerItem = psMetadataItemAllocStr(keyword, concept->comment, concept->data.V);576 break;577 case PS_DATA_S32:578 headerItem = psMetadataItemAllocS32(keyword, concept->comment, concept->data.S32);579 break;580 case PS_DATA_F32:581 headerItem = psMetadataItemAllocF32(keyword, concept->comment, concept->data.F32);582 break;583 case PS_DATA_F64:584 headerItem = psMetadataItemAllocF64(keyword, concept->comment, concept->data.F64);585 break;586 default:587 headerItem = psMetadataItemAlloc(keyword, concept->type, concept->comment,588 concept->data.V); // Item for the header589 }590 591 // We have a FITS header to look up --- search each level592 if (cell && cell->hdu) {593 psTrace(__func__, 7, "Adding to the cell level header...\n");594 psMetadataAddItem(cell->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);595 status = true;596 } else if (chip && chip->hdu) {597 psTrace(__func__, 7, "Adding to the chip level header...\n");598 psMetadataAddItem(chip->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);599 status = true;600 } else if (fpa->hdu) {601 psTrace(__func__, 7, "Adding to the FPA level header...\n");602 psMetadataAddItem(fpa->hdu->header, headerItem, PS_LIST_TAIL, PS_META_REPLACE);603 status = true;604 }605 psFree(headerItem);606 }607 608 // No header value609 return status;610 }611 612 613 // Well, not really "write", but check to see if it's there, and matches614 bool pmConceptWriteToDefault(pmFPA *fpa, // The FPA that contains the chip615 pmChip *chip, // The chip that contains the cell616 pmCell *cell, // The cell617 psMetadataItem *concept // Concept618 )619 {620 bool mdOK = true; // Status of MD lookup621 if (! fpa->camera) {622 return false;623 }624 psMetadata *defaults = psMetadataLookupMD(&mdOK, fpa->camera, "DEFAULTS");625 if (! mdOK || ! defaults) {626 psError(PS_ERR_IO, false, "Unable to find DEFAULTS in camera configuration.\n");627 return false;628 }629 630 psMetadataItem *defItem = psMetadataLookup(defaults, concept->name);631 bool status = false; // Result of checking the database632 if (defItem) {633 if (defItem->type == PS_DATA_METADATA) {634 // A dependent default635 psTrace(__func__, 7, "Evaluating dependent default....\n");636 psMetadata *dependents = defItem->data.V; // The list of dependents637 // Find out what it depends on638 psString dependName = psStringCopy(concept->name);639 psStringAppend(&dependName, ".DEPEND");640 psString dependsOn = psMetadataLookupStr(&mdOK, defaults, dependName);641 if (! mdOK) {642 psError(PS_ERR_IO, false, "Unable to find %s in camera configuration for dependent default"643 " --- ignored\n", dependName);644 // XXX: Need to clean up before returning645 return false;646 }647 psFree(dependName);648 // Find the value of the dependent concept649 psMetadataItem *depItem = pmConceptReadFromHeader(fpa, chip, cell, dependsOn);650 if (! depItem) {651 psError(PS_ERR_IO, true, "Unable to find value for %s (required for %s)\n", dependsOn,652 concept->name);653 return false;654 }655 if (depItem->type != PS_DATA_STRING) {656 psError(PS_ERR_IO, true, "Value of %s is not of type string, as required for dependency"657 " --- ignored.\n", dependsOn);658 }659 660 defItem = psMetadataLookup(dependents, depItem->data.V); // This is now what we were after661 }662 663 status = compareConcepts(defItem, concept);664 if (! status) {665 psError(PS_ERR_IO, true, "Concept %s is specified by default in the camera configuration, "666 "but doesn't match the actual value.\n", concept->name);667 }668 }669 670 // XXX: Need to clean up before returning671 return status;672 }673 674 675 // XXX: Not tested at all676 // XXX I WOULD NOT TRUST THIS FUNCTION IN THE SLIGHTEST YET! --- PAP677 bool pmConceptWriteToDB(pmFPA *fpa, // The FPA that contains the chip678 pmChip *chip, // The chip that contains the cell679 pmCell *cell, // The cell680 psDB *db, // DB handle681 psMetadataItem *concept // Concept682 )683 {684 if (! db) {685 // No database initialised686 return false;687 }688 689 bool mdStatus = true; // Status of MD lookup690 if (! fpa->camera) {691 return false;692 }693 psMetadata *database = psMetadataLookupMD(&mdStatus, fpa->camera, "DATABASE");694 if (! mdStatus) {695 // No error, because not everyone needs to use the DB696 return NULL;697 }698 699 psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, database, concept->name);700 if (dbLookup) {701 const char *tableName = psMetadataLookupStr(&mdStatus, dbLookup, "TABLE"); // Name of the table702 // const char *colName = psMetadataLookupStr(&mdStatus, dbLookup, "COLUMN"); // Name of the column703 const char *givenCols = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENDBCOL"); // Name of "where"704 // columns705 const char *givenPS = psMetadataLookupStr(&mdStatus, dbLookup, "GIVENPS"); // Values for "where"706 // columns707 708 // Now, need to get the "given"s709 if (strlen(givenCols) || strlen(givenPS)) {710 psList *cols = psStringSplit(givenCols, ",;", true); // List of column names711 psList *values = psStringSplit(givenPS, ",;", true); // List of value names for the columns712 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB713 if (cols->n != values->n) {714 psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "715 "the same number of entries --- ignored.\n", concept);716 } else {717 // Iterators for the lists718 psListIterator *colsIter = psListIteratorAlloc(cols, PS_LIST_HEAD, false);719 psListIterator *valuesIter = psListIteratorAlloc(values, PS_LIST_HEAD, false);720 char *column = NULL; // Name of the column721 while ((column = psListGetAndIncrement(colsIter))) {722 char *name = psListGetAndIncrement(valuesIter); // Name for the value723 if (!strlen(column) || !strlen(name)) {724 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is "725 " empty --- ignored.\n", concept);726 } else {727 // Search for the value name728 psMetadataItem *item = pmConceptReadFromHeader(fpa, chip, cell, name);729 if (! item) {730 item = pmConceptReadFromDefault(fpa, chip, cell, name);731 }732 if (! item) {733 psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "734 " lookup on %s --- ignored.\n", name, concept);735 } else {736 // We need to create a new psMetadataItem. I don't think we can't simply hack737 // the existing one, since that could conceivably cause memory leaks738 psMetadataItem *newItem = psMetadataItemAlloc(concept->name, item->type,739 item->comment, item->data.V);740 psMetadataAddItem(selection, newItem, PS_LIST_TAIL, PS_META_REPLACE);741 psFree(newItem);742 }743 }744 psFree(name);745 psFree(column);746 } // Iterating through the columns747 psFree(colsIter);748 psFree(valuesIter);749 750 // Check first to make sure we're only going to touch one row751 psArray *dbResult = psDBSelectRows(db, tableName, selection, 2); // Lookup result752 // Note that we use limit=2 in order to test if there are multiple rows returned753 if (! dbResult || dbResult->n == 0) {754 psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- ignored\n",755 concept->name);756 return false;757 } else {758 if (dbResult->n > 1) {759 psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s --- "760 " ignored.\n", concept->name);761 }762 // Update the DB763 psMetadata *update = psMetadataAlloc();764 psMetadataAddItem(update, concept, PS_LIST_HEAD, 0);765 psDBUpdateRows(db, tableName, selection, update);766 psFree(update);767 return true;768 }769 }770 psFree(cols);771 psFree(values);772 }773 } // Doing the "given"s.774 775 psAbort(__func__, "Shouldn't ever get here?\n");776 return false;777 }778 779 780 // Concept write from item781 bool pmConceptWriteItem(pmFPA *fpa, // The FPA782 pmChip *chip, // The chip783 pmCell *cell, // The cell784 psDB *db, // DB handle785 psMetadataItem *concept // Concept item786 )787 {788 if (! fpa->camera) {789 return false;790 }791 792 // Try headers, database, defaults in order793 psTrace(__func__, 3, "Trying to set concept %s...\n", concept->name);794 bool status = pmConceptWriteToCamera(cell, concept); // Status for return795 if (! status) {796 psTrace(__func__, 5, "Trying header....\n");797 status = pmConceptWriteToHeader(fpa, chip, cell, concept);798 }799 if (! status) {800 psTrace(__func__, 5, "Trying database....\n");801 status = pmConceptWriteToDB(fpa, chip, cell, db, concept);802 }803 if (! status) {804 psTrace(__func__, 5, "Checking defaults....\n");805 status = pmConceptWriteToDefault(fpa, chip, cell, concept);806 }807 808 if (! status) {809 psError(PS_ERR_IO, true, "Unable to set %s (%s).\n", concept->name, concept->comment);810 }811 812 return status;813 }814 815 816 // Concept write817 bool pmConceptWrite(pmFPA *fpa, // The FPA818 pmChip *chip,// The chip819 pmCell *cell, // The cell820 psDB *db, // DB handle821 psMetadata *concepts, // Concepts MD from which to set822 const char *name // Name of the concept823 )824 {825 psMetadataItem *concept = psMetadataLookup(concepts, name);826 if (! concept) {827 psError(PS_ERR_IO, true, "No such concept as %s\n", name);828 return false;829 }830 return pmConceptWriteItem(fpa, chip, cell, db, concept);831 }832 833 #endif -
trunk/psModules/src/config/pmConfig.c
r7187 r7278 3 3 * @author PAP, IfA 4 4 * 5 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 5-23 23:37:23$5 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-06-02 00:55:22 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 69 69 const char *description) // Description of file 70 70 { 71 assert(config); 72 assert(name && strlen(name) > 0); 73 assert(description && strlen(description) > 0); 74 71 75 char *realName = NULL; 72 76 unsigned int numBadLines = 0; … … 303 307 } 304 308 if (logFD == STDIN_FILENO) { 305 psLogMsg(__func__, PS_LOG_WARN, "Only STDERR and STDOUT currently supported as a log destination.\n"); 309 psLogMsg(__func__, PS_LOG_WARN, "Only STDERR and STDOUT currently supported as a log " 310 "destination.\n"); 306 311 logFD = STDERR_FILENO; 307 312 } … … 352 357 const psMetadata *header) 353 358 { 359 PS_ASSERT_PTR_NON_NULL(cameraFormat, false); 360 PS_ASSERT_PTR_NON_NULL(header, false); 361 354 362 // Read the rule for that camera format 355 363 bool mdStatus = true; … … 395 403 assert(camera); 396 404 assert(header); 405 assert(cameraName && strlen(cameraName) > 0); 397 406 398 407 bool result = false; // Did we find the first match? … … 449 458 ) 450 459 { 460 PS_ASSERT_PTR_NON_NULL(config, NULL); 461 PS_ASSERT_PTR_NON_NULL(header, NULL); 462 451 463 psMetadata *format = NULL; // The winning format 452 464 bool mdok = false; // Metadata lookup status … … 562 574 ) 563 575 { 576 PS_ASSERT_PTR_NON_NULL(config, NULL); 577 PS_ASSERT_PTR_NON_NULL(config->site, NULL); 578 564 579 #ifdef OMIT_PSDB 580 565 581 return NULL; 566 582 #else 567 583 568 PS_ASSERT_PTR_NON_NULL(config->site, NULL);569 584 psBool mdStatus01 = false; 570 585 psBool mdStatus02 = false; … … 590 605 ) 591 606 { 607 PS_ASSERT_PTR_NON_NULL(header, false); 608 PS_ASSERT_PTR_NON_NULL(format, false); 609 592 610 bool mdok = true; // Status of MD lookup 593 611 psMetadata *rules = psMetadataLookupMD(&mdok, format, "RULE"); // How to identify this format … … 613 631 psArray *pmConfigFileSets (int *argc, char **argv, char *file, char *list) 614 632 { 633 PS_ASSERT_PTR_NON_NULL(argc, NULL); 634 PS_ASSERT_INT_NONNEGATIVE(*argc, NULL); 635 PS_ASSERT_PTR_NON_NULL(argv, NULL); 636 PS_ASSERT_PTR_NON_NULL(file, NULL); 637 PS_ASSERT_INT_POSITIVE(strlen(file), NULL); 638 PS_ASSERT_PTR_NON_NULL(list, NULL); 639 PS_ASSERT_INT_POSITIVE(strlen(list), NULL); 615 640 616 641 int Narg; … … 670 695 bool pmConfigFileSetsMD (psMetadata *metadata, int *argc, char **argv, char *name, char *file, char *list) 671 696 { 697 PS_ASSERT_PTR_NON_NULL(metadata, false); 698 PS_ASSERT_PTR_NON_NULL(argc, false); 699 PS_ASSERT_INT_NONNEGATIVE(*argc, NULL); 700 PS_ASSERT_PTR_NON_NULL(argv, false); 701 PS_ASSERT_PTR_NON_NULL(name, false); 702 PS_ASSERT_INT_POSITIVE(strlen(name), NULL); 703 PS_ASSERT_PTR_NON_NULL(file, false); 704 PS_ASSERT_INT_POSITIVE(strlen(file), NULL); 705 PS_ASSERT_PTR_NON_NULL(list, false); 706 PS_ASSERT_INT_POSITIVE(strlen(list), NULL); 672 707 673 708 psArray *files = pmConfigFileSets (argc, argv, file, list); -
trunk/psModules/src/detrend/pmFlatField.c
r6873 r7278 1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the3 // one that was being worked on.4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////5 6 7 1 /** @file pmFlatField.c 8 2 * … … 24 18 * @author Ross Harman, MHPCC 25 19 * 26 * @version $Revision: 1. 6$ $Name: not supported by cvs2svn $27 * @date $Date: 2006-0 4-17 18:10:08$20 * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $ 21 * @date $Date: 2006-06-02 00:55:23 $ 28 22 * 29 23 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 46 40 bool pmFlatField(pmReadout *in, const pmReadout *flat) 47 41 { 48 int i = 0; 49 int j = 0; 42 PS_ASSERT_PTR_NON_NULL(in, false); 43 PS_ASSERT_PTR_NON_NULL(in->image, false); 44 PS_ASSERT_IMAGE_NON_EMPTY(in->image, false); 45 PS_ASSERT_PTR_NON_NULL(flat, false); 46 PS_ASSERT_PTR_NON_NULL(flat->image, false); 47 PS_ASSERT_IMAGE_NON_EMPTY(flat->image, false); 48 if (in->mask) { 49 PS_ASSERT_IMAGE_TYPE(in->mask, PS_TYPE_U8, false); 50 } 51 PS_ASSERT_IMAGE_TYPE(flat->image, in->image->type.type, false); 52 50 53 int totOffCol = 0; 51 54 int totOffRow = 0; … … 147 150 148 151 // Macro for all PS types 149 #define PM_FLAT_DIVISION(TYPE) \ 150 case PS_TYPE_##TYPE: \ 151 /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */ \ 152 for(j = totOffRow; j < inImage->numRows; j++) { \ 153 for(i = totOffCol; i < inImage->numCols; i++) { \ 154 if(flatImage->data.TYPE[j][i] <= 0.0) { \ 155 /* Negative or zero flat pixels shall be masked in input image as PM_MASK_FLAT */ \ 156 if (inMask) { \ 157 inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_FLAT; \ 158 } \ 159 flatImage->data.TYPE[j][i] = 0.0; \ 160 } \ 161 } \ 162 } \ 163 for(j = totOffRow; j < inImage->numRows; j++) { \ 164 for(i = totOffCol; i < inImage->numCols; i++) { \ 165 if(inMask && !inMask->data.PS_TYPE_MASK_DATA[j][i]) { \ 166 /* Module shall divide the input image by the flat-fielded image */ \ 167 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ 168 } \ 169 } \ 170 } \ 152 #define FLAT_DIVISION_CASE(TYPE) \ 153 case PS_TYPE_##TYPE: \ 154 for (long j = totOffRow; j < inImage->numRows; j++) { \ 155 for (long i = totOffCol; i < inImage->numCols; i++) { \ 156 if (flatImage->data.TYPE[j][i] <= 0.0) { \ 157 if (inMask) { \ 158 inMask->data.U8[j][i] |= PM_MASK_FLAT; \ 159 } \ 160 flatImage->data.TYPE[j][i] = 0.0; \ 161 } else { \ 162 if (!inMask || !inMask->data.U8[j][i]) { \ 163 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i]; \ 164 } \ 165 } \ 166 } \ 167 } \ 171 168 break; 172 169 173 170 switch(inType) { 174 PM_FLAT_DIVISION(U8);175 PM_FLAT_DIVISION(U16);176 PM_FLAT_DIVISION(U32);177 PM_FLAT_DIVISION(U64);178 PM_FLAT_DIVISION(S8);179 PM_FLAT_DIVISION(S16);180 PM_FLAT_DIVISION(S32);181 PM_FLAT_DIVISION(S64);182 PM_FLAT_DIVISION(F32);183 PM_FLAT_DIVISION(F64);171 FLAT_DIVISION_CASE(U8); 172 FLAT_DIVISION_CASE(U16); 173 FLAT_DIVISION_CASE(U32); 174 FLAT_DIVISION_CASE(U64); 175 FLAT_DIVISION_CASE(S8); 176 FLAT_DIVISION_CASE(S16); 177 FLAT_DIVISION_CASE(S32); 178 FLAT_DIVISION_CASE(S64); 179 FLAT_DIVISION_CASE(F32); 180 FLAT_DIVISION_CASE(F64); 184 181 default: 185 182 psError( PS_ERR_BAD_PARAMETER_TYPE, true, -
trunk/psModules/src/detrend/pmFlatField.h
r6872 r7278 1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////2 // XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the3 // one that was being worked on.4 //////////////////////////////////////////////////////////////////////////////////////////////////////////////5 6 7 1 /** @file pmFlatField.h 8 2 * … … 24 18 * @author Ross Harman, MHPCC 25 19 * 26 * @version $Revision: 1. 3$ $Name: not supported by cvs2svn $27 * @date $Date: 2006-0 4-17 18:01:05$20 * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $ 21 * @date $Date: 2006-06-02 00:55:23 $ 28 22 * 29 23 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii -
trunk/psModules/src/detrend/pmFlatNormalize.c
r7179 r7278 15 15 ) 16 16 { 17 PS_ASSERT_PTR_NON_NULL(chipGains, NULL); 18 PS_ASSERT_PTR_NON_NULL(fluxLevels, NULL); 19 17 20 int numSources = fluxLevels->numRows; // Number of integrations 18 21 int numChips = fluxLevels->numCols; // Number of chips with which each integration is made -
trunk/psModules/src/detrend/pmFringeStats.c
r7126 r7278 3 3 * @author Eugene Magnier, IfA 4 4 * 5 * @version $Revision: 1. 5$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-0 5-17 00:55:35$5 * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-06-02 00:55:23 $ 7 7 * 8 8 * Copyright 2004 IfA … … 61 61 bool pmFringeRegionsCreatePoints(pmFringeRegions *fringe, const psImage *image) 62 62 { 63 PS_ASSERT_PTR_NON_NULL(fringe, false); 64 PS_ASSERT_PTR_NON_NULL(image, false); 65 PS_ASSERT_IMAGE_NON_EMPTY(image, false); 63 66 64 67 double frnd; … … 106 109 pmFringeStats *pmFringeStatsAlloc(pmFringeRegions *regions) 107 110 { 111 PS_ASSERT_PTR_NON_NULL(regions, false); 112 108 113 pmFringeStats *stats = psAlloc(sizeof(pmFringeStats)); 109 114 (void)psMemSetDeallocator(stats, (psFreeFunc)fringeStatsFree); … … 120 125 pmFringeStats *pmFringeStatsMeasure(pmFringeRegions *fringe, pmReadout *readout, psMaskType maskVal) 121 126 { 127 PS_ASSERT_PTR_NON_NULL(fringe, NULL); 128 PS_ASSERT_PTR_NON_NULL(readout, NULL); 129 PS_ASSERT_PTR_NON_NULL(readout->image, NULL); 130 PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL); 131 122 132 if (!fringe->x || !fringe->y) { 123 133 // create the fringe vectors for this image … … 364 374 unsigned int nIter, float keepFrac) 365 375 { 376 PS_ASSERT_PTR_NON_NULL(science, NULL); 377 PS_ASSERT_PTR_NON_NULL(fringes, NULL); 378 PS_ASSERT_INT_POSITIVE(fringes->n, NULL); 379 PS_ASSERT_INT_POSITIVE(nIter, NULL); 380 366 381 pmFringeRegions *regions = science->regions; // The fringe regions 367 382 int numRegions = regions->nRequested; // Number of regions … … 439 454 unsigned int nIter, float keepFrac) 440 455 { 456 PS_ASSERT_PTR_NON_NULL(readout, NULL); 457 PS_ASSERT_PTR_NON_NULL(readout->image, NULL); 458 PS_ASSERT_IMAGE_NON_EMPTY(readout->image, NULL); 459 PS_ASSERT_PTR_NON_NULL(fringes, NULL); 460 PS_ASSERT_PTR_NON_NULL(fringeImages, NULL); 461 PS_ASSERT_PTR_NON_NULL(fringeStats, NULL); 462 PS_ASSERT_INT_EQUAL(fringeImages->n, fringeStats->n, NULL); 463 PS_ASSERT_INT_POSITIVE(nIter, NULL); 464 441 465 // measure the fringe stats for the science frame and solve for the scales 442 466 pmFringeStats *scienceStats = pmFringeStatsMeasure(fringes, readout, maskVal); -
trunk/psModules/src/detrend/pmSubtractBias.c
r7018 r7278 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1. 1$ $Name: not supported by cvs2svn $14 * @date $Date: 2006-0 5-01 01:56:29$13 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-06-02 00:55:23 $ 15 15 * 16 16 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 146 146 147 147 148 #if 0149 /******************************************************************************150 ImageSubtractScalar(): subtract a scalar from the input image.151 152 XXX: Use a psLib function for this.153 154 XXX: This should155 *****************************************************************************/156 static psImage *ImageSubtractScalar(psImage *image,157 psF32 scalar)158 {159 for (psS32 i=0;i<image->numRows;i++) {160 for (psS32 j=0;j<image->numCols;j++) {161 image->data.F32[i][j]-= scalar;162 }163 }164 return(image);165 }166 #endif167 168 148 /****************************************************************************** 169 149 GenNewStatOptions(): this routine will take as input the options member of the … … 175 155 static psStatsOptions GenNewStatOptions(const psStats *stat) 176 156 { 157 assert(stat); 158 177 159 psS32 numOptions = 0; 178 160 psStatsOptions opt = 0; … … 210 192 if (numOptions != 1) { 211 193 psLogMsg(__func__, PS_LOG_WARN, 212 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options have been specified\n"); 213 } 214 return(opt); 215 } 216 217 218 219 #if 0 220 /****************************************************************************** 221 ScaleOverscanVector(): this routine takes as input an arbitrary vector, 222 creates a new vector of length n, and fills the new vector with the 223 interpolated values of the old vector. The type of interpolation is: 224 PM_FIT_POLYNOMIAL: fit a polynomial to the entire input vector data. 225 PM_FIT_SPLINE: fit splines to the input vector data. 226 XXX: Doesn't it make more sense to do polynomial interpolation on a few 227 elements of the input vector, rather than fit a polynomial to the entire 228 vector? 229 *****************************************************************************/ 230 static psVector *ScaleOverscanVector(psVector *overscanVector, 231 psS32 n, 232 void *fitSpec, 233 pmFit fit) 234 { 235 psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4, 236 "---- ScaleOverscanVector() begin (%d -> %d) ----\n", overscanVector->n, n); 237 // PS_VECTOR_PRINT_F32(overscanVector); 238 239 if (NULL == overscanVector) { 240 return(overscanVector); 241 } 242 243 // Allocate the new vector. 244 psVector *newVec = psVectorAlloc(n, PS_TYPE_F32); 245 246 // 247 // If the new vector is the same size as the old, simply copy the data. 248 // 249 if (n == overscanVector->n) { 250 for (psS32 i = 0 ; i < n ; i++) { 251 newVec->data.F32[i] = overscanVector->data.F32[i]; 252 } 253 return(newVec); 254 } 255 psPolynomial1D *myPoly; 256 psSpline1D *mySpline; 257 psF32 x; 258 psS32 i; 259 if (fit == PM_FIT_POLYNOMIAL) { 260 // Fit a polynomial to the old overscan vector. 261 myPoly = (psPolynomial1D *) fitSpec; 262 PS_ASSERT_POLY_NON_NULL(myPoly, NULL); 263 myPoly = psVectorFitPolynomial1D(myPoly, NULL, 0, overscanVector, NULL, NULL); 264 if (myPoly == NULL) { 265 psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(1): Could not fit a polynomial to the psVector.\n"); 266 return(NULL); 267 } 268 269 // For each element of the new vector, convert the x-ordinate to that 270 // of the old vector, use the fitted polynomial to determine the 271 // interpolated value at that point, and set the new vector. 272 for (i=0;i<n;i++) { 273 x = ((psF32) i) * ((psF32) overscanVector->n) / ((psF32) n); 274 newVec->data.F32[i] = psPolynomial1DEval(myPoly, x); 275 } 276 } else if (fit == PM_FIT_SPLINE) { 277 psS32 mustFreeSpline = 0; 278 // Fit a spline to the old overscan vector. 279 mySpline = (psSpline1D *) fitSpec; 280 // XXX: Does it make any sense to have a psSpline argument? 281 if (mySpline == NULL) { 282 mustFreeSpline = 1; 283 } 284 285 // 286 // NOTE: Since the X arg in the psVectorFitSpline1D() function is NULL, 287 // splines endpoints will be from 0.0 to overscanVector->n-1. Must scale 288 // properly when doing the spline eval. 289 // 290 // mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL); 291 mySpline = psVectorFitSpline1D(NULL, overscanVector); 292 if (mySpline == NULL) { 293 psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector()(2): Could not fit a spline to the psVector.\n"); 294 return(NULL); 295 } 296 // PS_PRINT_SPLINE(mySpline); 297 298 // For each element of the new vector, convert the x-ordinate to that 299 // of the old vector, use the fitted polynomial to determine the 300 // interpolated value at that point, and set the new vector. 301 for (i=0;i<n;i++) { 302 // Scale to [0 : overscanVector->n - 1] 303 x = ((psF32) i) * ((psF32) (overscanVector->n-1)) / ((psF32) n); 304 newVec->data.F32[i] = psSpline1DEval(mySpline, x); 305 } 306 if (mustFreeSpline ==1) { 307 psFree(mySpline); 308 } 309 // PS_VECTOR_PRINT_F32(newVec); 310 311 312 } else { 313 psError(PS_ERR_UNKNOWN, true, "unknown fit type. Returning NULL.\n"); 314 psFree(newVec); 315 return(NULL); 316 } 317 318 psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4, 319 "---- ScaleOverscanVector() exit ----\n"); 320 return(newVec); 321 } 322 323 #endif 194 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options " 195 "have been specified\n"); 196 } 197 return opt; 198 } 199 324 200 325 201 // Produce an overscan vector from an array of pixels … … 329 205 ) 330 206 { 207 assert(overscanOpts); 208 assert(pixels); 209 assert(myStats); 210 331 211 // Reduce the overscans 332 212 psVector *reduced = psVectorAlloc(pixels->n, PS_TYPE_F32); // Overscan for each row … … 416 296 psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4, 417 297 "---- pmSubtractBias() begin ----\n"); 418 PS_ASSERT_READOUT_NON_NULL(in, NULL); 419 PS_ASSERT_READOUT_NON_EMPTY(in, NULL); 420 PS_ASSERT_READOUT_TYPE(in, PS_TYPE_F32, NULL); 298 PS_ASSERT_PTR_NON_NULL(in, NULL); 299 PS_ASSERT_IMAGE_NON_NULL(in->image, NULL); 300 PS_ASSERT_IMAGE_TYPE(in->image, PS_TYPE_F32, NULL); 301 PS_ASSERT_PTR_NON_NULL(overscanOpts, NULL); 302 if (bias) { 303 PS_ASSERT_IMAGE_NON_NULL(bias->image, NULL); 304 PS_ASSERT_IMAGE_TYPE(bias->image, PS_TYPE_F32, NULL); 305 } 306 if (dark) { 307 PS_ASSERT_IMAGE_NON_NULL(dark->image, NULL); 308 PS_ASSERT_IMAGE_TYPE(dark->image, PS_TYPE_F32, NULL); 309 } 421 310 422 311 psImage *image = in->image; // The input image -
trunk/psModules/src/imcombine/pmReadoutCombine.c
r7259 r7278 5 5 * @author GLG, MHPCC 6 6 * 7 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $8 * @date $Date: 2006-06-0 1 03:39:15$7 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2006-06-02 00:55:23 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 30 30 ) 31 31 { 32 assert(stats); 33 32 34 switch (option) { 33 35 case PS_STAT_SAMPLE_MEAN: … … 96 98 if (zero) { 97 99 PS_ASSERT_VECTOR_TYPE(zero, PS_TYPE_F32, false); 98 if (zero->n != inputs->n) { 99 psError(PS_ERR_UNKNOWN, true, "Zero vector has incorrect size (%d vs %d).\n", 100 zero->n, inputs->n); 101 return false; 102 } 100 PS_ASSERT_VECTOR_SIZE(zero, inputs->n, false); 103 101 } 104 102 if (scale) { 105 103 PS_ASSERT_VECTOR_TYPE(scale, PS_TYPE_F32, false); 106 if (scale->n != inputs->n) { 107 psError(PS_ERR_UNKNOWN, true, "Scale vector has incorrect size (%d vs %d).\n", 108 scale->n, inputs->n); 109 return false; 110 } 111 } 112 assert(params->fracLow >= 0.0 && params->fracLow < 1.0); 113 assert(params->fracHigh >= 0.0 && params->fracHigh < 1.0); 114 assert(params->combine == PS_STAT_SAMPLE_MEAN || 115 params->combine == PS_STAT_SAMPLE_MEDIAN || 116 params->combine == PS_STAT_ROBUST_MEDIAN || 117 params->combine == PS_STAT_FITTED_MEAN || 118 params->combine == PS_STAT_CLIPPED_MEAN); 104 PS_ASSERT_VECTOR_SIZE(scale, inputs->n, false); 105 } 106 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracLow, 0.0, 1.0, false); 107 PS_ASSERT_FLOAT_WITHIN_RANGE(params->fracHigh, 0.0, 1.0, false); 108 if (params->combine != PS_STAT_SAMPLE_MEAN && params->combine != PS_STAT_SAMPLE_MEDIAN && 109 params->combine != PS_STAT_ROBUST_MEDIAN && params->combine != PS_STAT_FITTED_MEAN && 110 params->combine != PS_STAT_CLIPPED_MEAN) { 111 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Combination method is not SAMPLE_MEAN, SAMPLE_MEDIAN, " 112 "ROBUST_MEDIAN, FITTED_MEAN or CLIPPED_MEAN.\n"); 113 return false; 114 } 119 115 120 116 psStats *stats = psStatsAlloc(params->combine); // The statistics to use in the combination
Note:
See TracChangeset
for help on using the changeset viewer.
