Changeset 5104
- Timestamp:
- Sep 22, 2005, 4:54:52 PM (21 years ago)
- Location:
- trunk/archive/scripts/src/phase2
- Files:
-
- 10 edited
-
Makefile (modified) (1 diff)
-
papPhase2.c (modified) (30 diffs)
-
papStuff.c (modified) (3 diffs)
-
pmConfig.c (modified) (2 diffs)
-
pmFPA.c (modified) (11 diffs)
-
pmFPA.h (modified) (8 diffs)
-
pmFPAConstruct.c (modified) (14 diffs)
-
pmFPAConstruct.h (modified) (1 diff)
-
psAdditionals.c (modified) (2 diffs)
-
psAdditionals.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/Makefile
r4820 r5104 5 5 DEVFLAGS += -DTESTING # Testing version 6 6 7 CFLAGS += -O0 -g -std=c99 -Werror -I /home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/include/-D_GNU_SOURCE $(DEVFLAGS)8 PSLIB += -L /home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm-lxml2 -lmysqlclient9 PSMODULE += -L /home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/lib/ -lpsmodule7 CFLAGS += -O0 -g -std=c99 -Werror -I$(JHBUILD)/include/ -I$(JHBUILD)/include/libxml2/ -DPS_NO_TRACE -D_GNU_SOURCE $(DEVFLAGS) 8 PSLIB += -L$(JHBUILD)/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm -L$(JHBUILD)/lib/libxml2/ -L$(JHBUILD)/lib/mysql/ -lxml2 -lmysqlclient 9 PSMODULE += -L$(JHBUILD)/lib/ -lpsmodule 10 10 LDFLAGS += $(PSLIB) 11 11 12 OBJS = papPhase2.o psAdditionals.o pmConfig.o pmFPA.o pmFPAConstruct.o papStuff.o 12 OBJS = papPhase2.o psAdditionals.o pmConfig.o pmFPA.o pmFPAConstruct.o papStuff.o pmFPARead.o \ 13 pmFPAConceptsGet.o pmFPAConceptsSet.o pmFPAWrite.o \ 14 pmFlatField.o pmMaskBadPixels.o pmNonLinear.o pmSubtractBias.o 13 15 TARGET = papPhase2 14 16 -
trunk/archive/scripts/src/phase2/papPhase2.c
r4820 r5104 4 4 #include "pslib.h" 5 5 #include "psAdditionals.h" 6 7 #include "pmSubtractBias.h"8 6 9 7 #include "pmFPA.h" 10 8 #include "pmConfig.h" 11 9 #include "pmFPAConstruct.h" 10 #include "pmFPARead.h" 11 #include "pmFPAConceptsGet.h" 12 #include "pmFPAWrite.h" 13 14 #include "pmFlatField.h" 15 #include "pmMaskBadPixels.h" 16 #include "pmNonLinear.h" 17 #include "pmSubtractBias.h" 12 18 13 19 // Phase 2 needs to: … … 37 43 #define RECIPE "PHASE2" // Name of the recipe to use 38 44 39 static psMem oryId memPrintAlloc(const psMemBlock *mb)45 static psMemId memPrintAlloc(const psMemBlock *mb) 40 46 { 41 47 printf("Allocated memory block %lld (%lld):\n" … … 46 52 return 0; 47 53 } 48 static psMem oryId memPrintFree(const psMemBlock *mb)54 static psMemId memPrintFree(const psMemBlock *mb) 49 55 { 50 56 printf("Freed memory block %lld (%lld):\n" … … 69 75 #if 0 70 76 // Hunting memory leaks 71 psMemAllocateCallbackSetID( 3539);72 psMemFreeCallbackSetID( 3539);77 psMemAllocateCallbackSetID(23289); 78 psMemFreeCallbackSetID(23289); 73 79 psMemAllocateCallbackSet(memPrintAlloc); 74 80 psMemFreeCallbackSet(memPrintFree); 75 81 #endif 76 82 77 // psTraceSetLevel(".", 10);83 psTraceSetLevel("pmConfigCameraFromHeader", 10); 78 84 79 85 // Parse the configurations … … 88 94 // Parse other command-line arguments 89 95 psMetadata *arguments = psMetadataAlloc(); // The arguments, with default values 90 psMetadataAddStr(arguments, PS_LIST_TAIL, "-bias", "Name of the bias image", "");91 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dark", "Name of the dark image", "");92 psMetadataAddStr(arguments, PS_LIST_TAIL, "-flat", "Name of the flat-field image", "");93 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", "Name of the mask image", "");94 psMetadataAddS32(arguments, PS_LIST_TAIL, "-chip", "Chip number to process (if positive)", -1);96 psMetadataAddStr(arguments, PS_LIST_TAIL, "-bias", 0, "Name of the bias image", ""); 97 psMetadataAddStr(arguments, PS_LIST_TAIL, "-dark", 0, "Name of the dark image", ""); 98 psMetadataAddStr(arguments, PS_LIST_TAIL, "-flat", 0, "Name of the flat-field image", ""); 99 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", 0, "Name of the mask image", ""); 100 psMetadataAddS32(arguments, PS_LIST_TAIL, "-chip", 0, "Chip number to process (if positive)", -1); 95 101 if (! psArgumentParse(arguments, &argc, argv) || argc != 3) { 96 102 printf("\nPan-STARRS Phase 2 processing\n\n"); … … 113 119 printf("Mask: %s\n", maskName); 114 120 printf("Chip: %d\n", chipNum); 115 psFree(arguments);116 121 117 122 // Open the input … … 132 137 #endif 133 138 134 #if 0135 139 // Open the output and output mask 136 140 // We do it here so that we don't process the whole lot and then find out we can't open the output file … … 144 148 exit(EXIT_FAILURE); 145 149 } 150 151 #if 0 146 152 psString outputMaskName = psStringCopy(outputName); 147 153 (void)psStringAppend(&outputMaskName, ".mask"); … … 158 164 #endif 159 165 160 161 166 // Get camera configuration from header if not already defined 162 167 if (! camera) { … … 176 181 177 182 // Construct camera in preparation for reading 178 pmFPA *input = pmFPAConstruct(camera , database);179 pmFPA *mask = pmFPAConstruct(camera , database);180 pmFPA *bias = pmFPAConstruct(camera , database);181 pmFPA *dark = pmFPAConstruct(camera , database);182 pmFPA *flat = pmFPAConstruct(camera , database);183 pmFPA *input = pmFPAConstruct(camera); 184 pmFPA *mask = pmFPAConstruct(camera); 185 pmFPA *bias = pmFPAConstruct(camera); 186 pmFPA *dark = pmFPAConstruct(camera); 187 pmFPA *flat = pmFPAConstruct(camera); 183 188 184 189 // Set various tasks … … 198 203 199 204 if (psMetadataLookupBool(NULL, recipe, "MASK")) { 200 if ( maskName) {205 if (strlen(maskName) > 0) { 201 206 doMask = true; 202 207 } else { … … 209 214 } 210 215 if (psMetadataLookupBool(NULL, recipe, "BIAS")) { 211 if ( biasName) {216 if (strlen(biasName) > 0) { 212 217 doBias = true; 213 218 } else { … … 217 222 } 218 223 if (psMetadataLookupBool(NULL, recipe, "DARK")) { 219 if ( darkName) {224 if (strlen(darkName) > 0) { 220 225 doDark = true; 221 226 } else { … … 260 265 } 261 266 } 267 262 268 if (psMetadataLookupBool(NULL, recipe, "FLAT")) { 263 if ( flatName) {269 if (strlen(flatName) > 0) { 264 270 doFlat = true; 265 271 } else { … … 269 275 } 270 276 271 #if 0272 277 // Chip selection 273 278 if (chipNum >= 0) { … … 282 287 283 288 // Read in the input pixels 284 if (! pmFPARead(input, inputFile )) {289 if (! pmFPARead(input, inputFile, header, database)) { 285 290 psErrorStackPrint(stderr, "Unable to populate camera from FITS file: %s\n", inputName); 286 291 exit(EXIT_FAILURE); … … 292 297 #endif 293 298 299 pmFPAPrint(input); 294 300 295 301 // Load the calibration frames, if required 296 if (biasName) { 302 if (doBias) { 303 #ifdef PRODUCTION 297 304 psFits *biasFile = psFitsOpen(biasName, "r"); // File handle for bias 305 #else 306 psFits *biasFile = psFitsAlloc(biasName); 307 #endif 298 308 psMetadata *biasHeader = psFitsReadHeader(NULL, biasFile); // FITS header for bias 299 309 if (! pmConfigValidateCamera(camera, biasHeader)) { 300 psError( "phase2", true, "Bias (%s) does not seem to be from the same camera.\n", biasName);310 psError(PS_ERR_IO, true, "Bias (%s) does not seem to be from the same camera.\n", biasName); 301 311 exit(EXIT_FAILURE); 302 312 } 303 313 psFree(biasHeader); 304 if (! pmFPARead(bias, biasFile )) {314 if (! pmFPARead(bias, biasFile, NULL, database)) { 305 315 psErrorStackPrint(stderr, "Unable to populate bias camera from fits FITS: %s\n", biasName); 306 316 exit(EXIT_FAILURE); 307 317 } 318 #ifdef PRODUCTION 308 319 psFitsClose(biasFile); 309 } 310 311 if (darkName) { 320 #else 321 psFree(biasFile); 322 #endif 323 } 324 325 if (doDark) { 326 #ifdef PRODUCTION 312 327 psFits *darkFile = psFitsOpen(darkName, "r"); // File handle for dark 328 #else 329 psFits *darkFile = psFitsAlloc(darkName); 330 #endif 313 331 psMetadata *darkHeader = psFitsReadHeader(NULL, darkFile); // FITS header for dark 314 332 if (! pmConfigValidateCamera(camera, darkHeader)) { 315 psError( "phase2", true, "Dark (%s) does not seem to be from the same camera.\n", darkName);333 psError(PS_ERR_IO, true, "Dark (%s) does not seem to be from the same camera.\n", darkName); 316 334 exit(EXIT_FAILURE); 317 335 } 318 336 psFree(darkHeader); 319 if (! pmFPARead(dark, darkFile )) {337 if (! pmFPARead(dark, darkFile, NULL, database)) { 320 338 psErrorStackPrint(stderr, "Unable to populate dark camera from fits FITS: %s\n", darkName); 321 339 exit(EXIT_FAILURE); 322 340 } 341 #ifdef PRODUCTION 323 342 psFitsClose(darkFile); 324 } 325 326 if (maskName) { 343 #else 344 psFree(darkFile); 345 #endif 346 } 347 348 if (doMask) { 349 #ifdef PRODUCTION 327 350 psFits *maskFile = psFitsOpen(maskName, "r"); // File handle for mask 351 #else 352 psFits *maskFile = psFitsAlloc(maskName); 353 #endif 328 354 psMetadata *maskHeader = psFitsReadHeader(NULL, maskFile); // FITS header for mask 329 355 if (! pmConfigValidateCamera(camera, maskHeader)) { 330 psError( "phase2", true, "Mask (%s) does not seem to be from the same camera.\n", maskName);356 psError(PS_ERR_IO, true, "Mask (%s) does not seem to be from the same camera.\n", maskName); 331 357 exit(EXIT_FAILURE); 332 358 } 333 359 psFree(maskHeader); 334 if (! pmFPARead(mask, maskFile )) {360 if (! pmFPARead(mask, maskFile, NULL, database)) { 335 361 psErrorStackPrint(stderr, "Unable to populate mask camera from fits FITS: %s\n", maskName); 336 362 exit(EXIT_FAILURE); 337 363 } 364 #ifdef PRODUCTION 338 365 psFitsClose(maskFile); 366 #else 367 psFree(maskFile); 368 #endif 339 369 } 340 370 341 if (flatName) { 371 if (doFlat) { 372 #ifdef PRODUCTION 342 373 psFits *flatFile = psFitsOpen(flatName, "r"); // File handle for flat 374 #else 375 psFits *flatFile = psFitsAlloc(flatName); 376 #endif 343 377 psMetadata *flatHeader = psFitsReadHeader(NULL, flatFile); // FITS header for flat 344 378 if (! pmConfigValidateCamera(camera, flatHeader)) { 345 psError( "phase2", true, "Flat (%s) does not seem to be from the same camera.\n", flatName);379 psError(PS_ERR_IO, true, "Flat (%s) does not seem to be from the same camera.\n", flatName); 346 380 exit(EXIT_FAILURE); 347 381 } 348 382 psFree(flatHeader); 349 if (! pmFPARead(flat, flatFile )) {383 if (! pmFPARead(flat, flatFile, NULL, database)) { 350 384 psErrorStackPrint(stderr, "Unable to populate flat camera from fits FITS: %s\n", flatName); 351 385 exit(EXIT_FAILURE); 352 386 } 387 #ifdef PRODUCTION 353 388 psFitsClose(flatFile); 389 #else 390 psFree(flatFile); 391 #endif 354 392 } 355 393 356 psArray *inputChips = input s->chips; // Array of chips in input image394 psArray *inputChips = input->chips; // Array of chips in input image 357 395 psArray *biasChips = bias->chips; // Array of chips in bias image 358 396 psArray *darkChips = dark->chips; // Array of chips in dark image … … 377 415 378 416 for (int j = 0; j < inputCells->n; j++) { 379 pmCell *inputCell = inputCells->data[ i]; // Cell of interest in input image380 pmCell *biasCell = biasCells->data[ i]; // Cell of interest in bias image381 pmCell *darkCell = darkCells->data[ i]; // Cell of interest in dark imag382 pmCell *maskCell = maskCells->data[ i]; // Cell of interest in mask image383 pmCell *flatCell = flatCells->data[ i]; // Cell of interest in flat image417 pmCell *inputCell = inputCells->data[j]; // Cell of interest in input image 418 pmCell *biasCell = biasCells->data[j]; // Cell of interest in bias image 419 pmCell *darkCell = darkCells->data[j]; // Cell of interest in dark imag 420 pmCell *maskCell = maskCells->data[j]; // Cell of interest in mask image 421 pmCell *flatCell = flatCells->data[j]; // Cell of interest in flat image 384 422 385 423 if (! inputCell->valid) { … … 388 426 389 427 psArray *inputReadouts = inputCell->readouts; // Array of readouts in input image 390 if ( biasCell->readouts->n !=1) {428 if (doBias && biasCell->readouts->n > 1) { 391 429 psLogMsg("phase2", PS_LOG_WARN, "Bias contains multiple readouts: only the first will be" 392 430 " used."); 393 431 } 394 if (d arkCell->readouts->n !=1) {432 if (doDark && darkCell->readouts->n > 1) { 395 433 psLogMsg("phase2", PS_LOG_WARN, "Dark contains multiple readouts: only the first will be" 396 434 " used."); 397 435 } 398 if ( maskCell->readouts->n !=1) {436 if (doMask && maskCell->readouts->n > 1) { 399 437 psLogMsg("phase2", PS_LOG_WARN, "Mask contains multiple readouts: only the first will be" 400 438 " used."); 401 439 } 402 if ( flatCell->readouts->n !=1) {440 if (doFlat && flatCell->readouts->n > 1) { 403 441 psLogMsg("phase2", PS_LOG_WARN, "Flat contains multiple readouts: only the first will be" 404 442 " used."); 405 443 } 406 444 445 pmReadout *biasReadout = NULL; // Bias readout 446 pmReadout *maskReadout = NULL; // Mask readout 447 pmReadout *flatReadout = NULL; // Flat readout 407 448 psImage *biasImage = NULL; // Bias pixels 408 449 psImage *darkImage = NULL; // Dark pixels 409 450 float darkTime = 1.0; // Dark time for dark image 410 411 if (biasName) { 412 pmReadout *biasReadout = biasCell->readouts->data[0]; // Readout of interest in bias image 451 psImage *maskImage = NULL; // Mask pixels 452 453 if (doBias) { 454 biasReadout = biasCell->readouts->data[0]; // Readout of interest in bias image 413 455 biasImage = biasReadout->image; 414 456 } 415 if (d arkName) {457 if (doDark) { 416 458 pmReadout *darkReadout = darkCell->readouts->data[0]; // Readout of interest in dark image 417 459 darkImage = darkReadout->image; 418 darkTime = p mReadoutGetDarkTime(darkReadout);460 darkTime = psMetadataLookupF32(NULL, darkCell->concepts, "CELL.DARKTIME"); 419 461 if (darkTime <= 0.0) { 420 462 psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime); … … 422 464 } 423 465 } 424 if (maskName) { 425 pmReadout *maskReadout = maskCell->readouts->data[0]; // Readout of interest in mask image 426 } 427 if (flatName) { 428 pmReadout *flatReadout = flatCell->readouts->data[0]; // Readout of interest in mask image 466 if (doMask) { 467 maskReadout = maskCell->readouts->data[0]; // Readout of interest in mask image 468 maskImage = maskReadout->image; 469 } 470 if (doFlat) { 471 flatReadout = flatCell->readouts->data[0]; // Readout of interest in mask image 429 472 } 430 473 … … 432 475 pmReadout *inputReadout = inputReadouts->data[k]; // Readout of interest in input image 433 476 psImage *inputImage = inputReadout->image; // The actual image 434 psList *input Bias = inputReadout->bias; // List of overscan bias regions477 psList *inputOverscans = inputReadout->overscans; // List of overscan bias regions 435 478 436 479 // Mask bad pixels 437 480 if (doMask) { 481 float saturation = psMetadataLookupF32(NULL, inputCell->concepts, "CELL.SATURATION"); 482 438 483 // Need to change this later to grow the mask by the size of the convolution kernel 439 (void)pmMaskBadPixels(inputReadout, mask Readout,440 P S_MASK_TRAP | PS_MASK_BADCOL | PS_MASK_SAT, saturation,441 P S_MASK_TRAP, 0);484 (void)pmMaskBadPixels(inputReadout, maskImage, 485 PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT, saturation, 486 PM_MASK_TRAP, 0); 442 487 } 443 488 … … 450 495 } else { 451 496 switch (dataItem->type) { 452 case PS_META_VECTOR: 453 // These are the polynomial coefficients 454 psVector *coeff = dataItem->data.V; // The coefficient vector 455 if (coeff->type.type != PS_TYPE_F64) { 456 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 497 case PS_META_VEC: 498 { 499 // These are the polynomial coefficients 500 psVector *coeff = dataItem->data.V; // The coefficient vector 501 if (coeff->type.type != PS_TYPE_F64) { 502 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 503 psFree(coeff); 504 coeff = temp; 505 } 506 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 507 coeff->n + 1); 508 for (int i = 0; i < coeff->n; i++) { 509 correction->coeff[i] = coeff->data.F64[i]; 510 } 511 (void)pmNonLinearityPolynomial(inputReadout, correction); 457 512 psFree(coeff); 458 coeff = temp;513 psFree(correction); 459 514 } 460 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD,461 coeff->n + 1);462 for (int i = 0; i < coeff->n; i++) {463 correction->coeff[i] = coeff->data.F64[i];464 }465 (void)pmNonLinearityPolynomial(inputReadout, correction);466 psFree(coeffCopy);467 psFree(coeff);468 psFree(correction);469 515 break; 470 516 case PS_META_STR: 471 // This is a filename 472 psString name = dataItem->data.V; // Filename 473 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 474 if (psLookupTableRead(table) <= 0) { 475 psErrorStackPrint(stderr, "Unable to read non-linearity correction file %s " 476 "--- ignored\n", tableName); 477 } else { 478 (void)pmNonLinearityLookup(inputReadout, table); 517 { 518 // This is a filename 519 psString name = dataItem->data.V; // Filename 520 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 521 if (psLookupTableRead(table) <= 0) { 522 psErrorStackPrint(stderr, "Unable to read non-linearity correction file " 523 "%s --- ignored\n", name); 524 } else { 525 #ifdef PRODUCTION 526 (void)pmNonLinearityLookup(inputReadout, table); 527 #else 528 printf("XXX: Non-linearity with lookup table not yet implemented.\n"); 529 #endif 530 } 531 psFree(table); 479 532 } 480 psFree(table);481 533 break; 482 534 case PS_META_META: 483 // This is a menu 484 psMetadata *options = dataItem->data.V; // Options with concept values as keys 485 bool mdok = false; // Success of MD lookup 486 psString concept = psMetadataLookupStr(&mdok, recipe, "NONLIN.SOURCE"); 487 if (! mdok || ! concept) { 488 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 489 "unable to find NONLIN.SOURCE in recipe --- ignored.\n"); 490 } else { 491 psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept); 492 if (! conceptValueItem) { 493 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 494 "for non-linearity correction --- ignored.\n", concept); 495 } else if (conceptValueItem->type != PS_META_STR) { 496 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 497 " expected for non-linearity correction --- ignored.\n", 498 concept); 535 { 536 // This is a menu 537 psMetadata *options = dataItem->data.V; // Options with concept values as keys 538 bool mdok = false; // Success of MD lookup 539 psString concept = psMetadataLookupString(&mdok, recipe, "NONLIN.SOURCE"); 540 if (! mdok || ! concept) { 541 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 542 "unable to find NONLIN.SOURCE in recipe --- ignored.\n"); 499 543 } else { 500 psString conceptValue = conceptValueItem->data.V; 501 // Get the value of the concept 502 psMetadataItem *optionItem = psMetadataLookup(options, conceptValue); 503 if (!optionItem) { 504 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 505 " --- ignored.\n", conceptValue); 506 } else if (optionItem->type == PS_META_VECTOR) { 507 // These are the polynomial coefficients 508 psVector *coeff = optionItem->data.V; // The coefficient vector 509 if (coeff->type.type != PS_TYPE_F64) { 510 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); 544 psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept); 545 if (! conceptValueItem) { 546 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 547 "for non-linearity correction --- ignored.\n", concept); 548 } else if (conceptValueItem->type != PS_META_STR) { 549 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 550 " expected for non-linearity correction --- ignored.\n", 551 concept); 552 } else { 553 psString conceptValue = conceptValueItem->data.V; 554 // Get the value of the concept 555 psMetadataItem *optionItem = psMetadataLookup(options, conceptValue); 556 if (!optionItem) { 557 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" 558 " --- ignored.\n", conceptValue); 559 } else if (optionItem->type == PS_META_VEC) { 560 // These are the polynomial coefficients 561 psVector *coeff = optionItem->data.V; // The coefficient vector 562 if (coeff->type.type != PS_TYPE_F64) { 563 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); 564 psFree(coeff); 565 coeff = temp; 566 } 567 // Polynomial correction 568 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, 569 coeff->n + 1); 570 for (int i = 0; i < coeff->n; i++) { 571 correction->coeff[i] = coeff->data.F64[i]; 572 } 573 (void)pmNonLinearityPolynomial(inputReadout, correction); 511 574 psFree(coeff); 512 coeff = temp; 575 psFree(correction); 576 } else if (optionItem->type == PS_META_STR) { 577 // This is a filename 578 psString tableName = optionItem->data.V; // The filename 579 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0); 580 int numLines = 0; // Number of lines read from table 581 if ((numLines = psLookupTableRead(table)) <= 0) { 582 psErrorStackPrint(stderr, "Unable to read non-linearity " 583 "correction file %s --- ignored\n", 584 tableName); 585 } else { 586 #ifdef PRODUCTION 587 (void)pmNonLinearityLookup(inputReadout, table); 588 #else 589 printf("XXX: Non-linearity correction from lookup table not " 590 "yet implemented.\n"); 591 #endif 592 } 593 psFree(table); 594 } else { 595 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " 596 "desired but unable to interpret NONLIN.DATA for %s" 597 " --- ignored\n", conceptValue); 513 598 } 514 // Polynomial correction515 psPolynomial1D *correction = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD,516 coeff->n + 1);517 for (int i = 0; i < coeff->n; i++) {518 correction->coeff[i] = coeff->data.F64[i];519 }520 (void)pmNonLinearityPolynomial(inputReadout, correction);521 psFree(coeffCopy);522 psFree(coeff);523 psFree(correction);524 } else if (optionItem->type == PS_META_STR) {525 // This is a filename526 psString tableName = optionItem->data.V; // The filename527 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0);528 if ((int numLines = psLookupTableRead(table)) <= 0) {529 psErrorStackPrint(stderr, "Unable to read non-linearity "530 "correction file %s --- ignored\n", tableName);531 } else {532 (void)pmNonLinearityLookup(inputReadout, table);533 }534 psFree(table);535 } else {536 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "537 "desired but unable to interpret NONLIN.DATA for %s"538 " --- ignored\n", conceptValue);539 599 } 540 600 } … … 553 613 // it's not in there yet. Once it is, we can get rid of "pedestal". 554 614 615 #ifdef PRODUCTION 555 616 psImage *pedestal = NULL; // Pedestal image (bias + scaled dark) 556 617 if (doDark) { 557 float inputTime = pmReadoutGetDarkTime(inputReadout); // Dark time for input image 618 // Dark time for input image 619 float inputTime = psMetadataLookupF32(NULL, inputCell->concepts, "CELL.DARKTIME"); 558 620 if (inputTime <= 0) { 559 621 psErrorStackPrint(stderr, "DARKTIME for input image (%f) is non-positive.\n", … … 562 624 } 563 625 564 pedestal = psBinaryOp(NULL, darkImage, "*",565 psScalarAlloc(inputTime * darkTime, PS_TYPE_F32));626 pedestal = (psImage*)psBinaryOp(NULL, darkImage, "*", 627 psScalarAlloc(inputTime * darkTime, PS_TYPE_F32)); 566 628 } 567 629 if (doBias) { … … 569 631 if (biasImage->numRows != darkImage->numRows || 570 632 biasImage->numCols != darkImage->numCols) { 571 psError( "phase2", true, "Bias and dark images have different dimensions: "633 psError(PS_ERR_IO, true, "Bias and dark images have different dimensions: " 572 634 "%dx%d vs %dx%d\n", biasImage->numCols, biasImage->numRows, 573 635 darkImage->numCols, darkImage->numRows); … … 579 641 } 580 642 } 581 643 #endif 582 644 if (overscanMode == PM_OVERSCAN_ROWS || overscanMode == PM_OVERSCAN_COLUMNS) { 583 645 // Need to get the read direction 584 int readdir = p mCellGetReaddir(inputCell); // Read direction646 int readdir = psMetadataLookupS32(NULL, inputCell->concepts, "CELL.READDIR"); 585 647 if (readdir == 1) { 586 648 overscanMode = PM_OVERSCAN_ROWS; … … 594 656 } 595 657 596 void *overscanResult = NULL; // Result of overscan fit 597 (void)pmSubtractBias(inputImage, overscanResult, inputBias, overscanMode, overscanStat, 598 overscanBin, overscanFit, pedestal); 599 600 // Output overscan fit results, if required 601 if (doOverscan) { 602 switch (overscanFit) { 603 case PM_FIT_POLYNOMIAL: 604 psPolynomial1D *poly = (psPolynomial1D*)overscanResult; // The polynomial 605 psString coeffs = NULL; // String containing the coefficients 606 for (int i = 0; i < poly->n; i++) { 607 psStringAppend(&coeffs, "%.2f ", poly->coeffs[i]); 658 printf("mode: %d\n", overscanMode); 659 660 if (doBias || doOverscan || doDark) { 661 void *overscanResult = NULL; // Result of overscan fit 662 #ifdef PRODUCTION 663 (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode, 664 overscanStats, overscanBins, overscanFit, pedestal); 665 #else 666 (void)pmSubtractBias(inputReadout, overscanResult, inputOverscans, overscanMode, 667 overscanStats, overscanBins, overscanFit, biasReadout); 668 #endif 669 670 // Output overscan fit results, if required 671 if (doOverscan) { 672 switch (overscanFit) { 673 case PM_FIT_POLYNOMIAL: 674 { 675 psPolynomial1D *poly = (psPolynomial1D*)overscanResult; // The polynomial 676 psString coeffs = NULL; // String containing the coefficients 677 for (int i = 0; i < poly->n; i++) { 678 psStringAppend(&coeffs, "%.2f ", poly->coeff[i]); 679 } 680 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n", 681 coeffs); 682 psFree(coeffs); 683 } 684 break; 685 case PM_FIT_SPLINE: 686 { 687 psSpline1D *spline = (psSpline1D*)overscanResult; // The spline 688 psString coeffs = NULL; // String containing the coefficients 689 for (int i = 0; i < spline->n; i++) { 690 psPolynomial1D *poly = spline->spline[i]; // i-th polynomial 691 psStringAppend(&coeffs, "%d: ", i); 692 for (int j = 0; j < poly->n; j++) { 693 psStringAppend(&coeffs, "%.2f ", poly->coeff[i]); 694 } 695 psStringAppend(&coeffs, "\n"); 696 } 697 psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n", 698 coeffs); 699 psFree(coeffs); 700 } 701 break; 702 case PM_FIT_NONE: 703 break; 704 default: 705 psAbort(__func__, "Should never get here!!!\n"); 608 706 } 609 psLogMsg("phase2", PS_LOG_INFO, "Overscan polynomial coefficients:\n%s\n",610 coeffs);611 psFree(coeffs);612 break;613 case PM_FIT_SPLINE:614 psSpline1D *spline = (psSpline1D*)overscanResult; // The spline615 psString coeffs = NULL; // String containing the coefficients616 for (int i = 0; i < spline->n; i++) {617 psPolynomial1D *poly = spline->spline[i]; // i-th polynomial618 psStringAppend(&coeffs, "%d: ", i);619 for (int j = 0; j < poly->n; j++) {620 psStringAppend(&coeffs, "%.2f ", poly->coeffs[i]);621 }622 psStringAppend(&coeffs, "\n");623 }624 psLogMsg("phase2", PS_LOG_INFO, "Overscan spline coefficients:\n%s\n", coeffs);625 psFree(coeffs);626 break;627 case PM_FIT_NONE:628 break;629 default:630 psAbort("Should never get here!!!\n");631 707 } 632 708 } … … 634 710 // Flat-field correction 635 711 if (doFlat) { 636 (void)pmFlatField(inputReadout, maskReadout,flatReadout);712 (void)pmFlatField(inputReadout, flatReadout); 637 713 } 638 714 … … 659 735 660 736 // Write the output 661 pmFPAWrite(outputFile, input );662 pmFPAWriteMask(outputMaskFile, input);737 pmFPAWrite(outputFile, input, database); 738 // pmFPAWriteMask(outputMaskFile, input); 663 739 #ifdef PRODUCTION 664 740 psFitsClose(outputFile); 665 psFitsClose(outputMaskFile);741 // psFitsClose(outputMaskFile); 666 742 #else 667 743 psFree(outputFile); 668 psFree(outputMaskFile); 669 #endif 670 671 #endif 672 744 // psFree(outputMaskFile); 745 #endif 746 747 psFree(arguments); 673 748 psFree(site); 674 749 psFree(header); … … 681 756 psFree(flat); 682 757 psFree(overscanStats); 683 psFree(inputFile);684 758 685 759 #if 1 -
trunk/archive/scripts/src/phase2/papStuff.c
r4820 r5104 6 6 7 7 #include "papStuff.h" 8 9 10 static void memPrint(const psPtr ptr) 11 { 12 psMemBlock *mb = ((psMemBlock*)ptr) - 1; 13 printf("Memory block %lld (%lld):\n" 14 "\tFile %s, line %d, size %d\n" 15 "\tPosts: %x %x %x\n", 16 mb->id, mb->refCounter, mb->file, mb->lineno, mb->userMemorySize, mb->startblock, mb->endblock, 17 *(void**)((int8_t *)(mb + 1) + mb->userMemorySize)); 18 } 8 19 9 20 // Split string on given characters … … 30 41 (void)psListAdd(values, PS_LIST_TAIL, word); 31 42 start = i + 1; 43 psFree(word); 32 44 } 33 45 } … … 37 49 psString word = psStringNCopy(&string[start], length - start); 38 50 (void)psListAdd(values, PS_LIST_TAIL, word); 51 psFree(word); 39 52 } 40 53 -
trunk/archive/scripts/src/phase2/pmConfig.c
r4820 r5104 133 133 } 134 134 psTrace(__func__, 7, "Setting log destination to STDOUT.\n"); 135 psLogSetDestination( 0);135 psLogSetDestination(PS_LOG_TO_STDOUT); 136 136 } 137 137 … … 147 147 } 148 148 psTrace(__func__, 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32); 149 (void)psTraceSetLevel(traceItem->name, traceItem->data.S32);149 psTraceSetLevel(traceItem->name, traceItem->data.S32); 150 150 } 151 151 psFree(traceIter); -
trunk/archive/scripts/src/phase2/pmFPA.c
r4820 r5104 1 1 #include <stdio.h> 2 2 #include <string.h> 3 #include <assert.h> 3 4 #include "pslib.h" 4 5 #include "psAdditionals.h" … … 6 7 #include "pmFPA.h" 7 8 8 9 9 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 10 10 // Allocators 11 11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 12 13 pmFPA *pmFPAAlloc(const psMetadata *camera, // Camera configuration 14 psDB *db // Database 13 p_pmHDU *p_pmHDUAlloc(const char *extname) 14 { 15 p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU)); 16 psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree); 17 18 hdu->extname = extname; 19 hdu->pixels = NULL; 20 hdu->header = NULL; 21 22 return hdu; 23 } 24 25 void p_pmHDUFree(p_pmHDU *hdu) 26 { 27 psFree(hdu->pixels); 28 psFree(hdu->header); 29 } 30 31 pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration 15 32 ) 16 33 { 17 34 pmFPA *fpa = psAlloc(sizeof(pmFPA));// The FPA 18 psMemSetDeallocator(fpa, (psFreeF cn)p_pmFPAFree);35 psMemSetDeallocator(fpa, (psFreeFunc)p_pmFPAFree); 19 36 20 37 // Fill in the components … … 23 40 fpa->projection = NULL; 24 41 25 fpa->values = psMetadataAlloc(); 26 // fpa->camera = psMemIncrRefCounter((psPtr)camera); 27 fpa->db = db; 42 fpa->concepts = psMetadataAlloc(); 43 fpa->camera = psMemIncrRefCounter((psPtr)camera); 28 44 fpa->chips = psArrayAlloc(0); 29 45 30 fpa->extname = NULL; 31 fpa->pixels = NULL; 32 fpa->header = NULL; 46 fpa->private = NULL; 33 47 34 48 return fpa; … … 41 55 psFree(fpa->projection); 42 56 43 psFree(fpa-> values);57 psFree(fpa->concepts); 44 58 psFree((psPtr)fpa->camera); 45 psFree(fpa->db);46 59 psFree(fpa->chips); 47 60 48 psFree(fpa->pixels); 49 psFree(fpa->header); 61 psFree(fpa->private); 50 62 } 51 63 … … 55 67 { 56 68 pmChip *chip = psAlloc(sizeof(pmChip)); // The chip 57 psMemSetDeallocator(chip, (psFreeF cn)p_pmChipFree);69 psMemSetDeallocator(chip, (psFreeFunc)p_pmChipFree); 58 70 59 71 // Push onto the array of chips … … 67 79 chip->fromFPA = NULL; 68 80 69 chip->values = psMetadataAlloc(); 70 // chip->parent = psMemIncrRefCounter(fpa); 81 chip->concepts = psMetadataAlloc(); 71 82 chip->cells = psArrayAlloc(0); 72 73 chip->extname = NULL; 74 chip->pixels = NULL; 75 chip->header = NULL; 76 77 psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at pmChipAlloc", name); 83 chip->parent = fpa; // We don't increment the reference counter on this --- it's a 84 // "hidden" link. If we increment the reference counter, we get stuck 85 // in a circle. 86 chip->valid = true; 87 88 chip->private = NULL; 89 90 psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name); 78 91 79 92 return chip; … … 85 98 psFree(chip->fromFPA); 86 99 87 psFree(chip-> values);100 psFree(chip->concepts); 88 101 psFree(chip->cells); 89 // psFree(chip->parent); 90 91 psFree(chip->pixels); 92 psFree(chip->header); 102 103 psFree(chip->private); 104 105 // We don't free the parent member, since that would generate a circular call. We don't increment the 106 // reference counter when we add it, anyway, so that's OK. 93 107 } 94 108 95 109 pmCell *pmCellAlloc(pmChip *chip, // Chip to which the cell belongs 96 psMetadata * values, // Initial values for concepts110 psMetadata *cameraData, // Camera data 97 111 psString name // Name of cell 98 112 ) 99 113 { 100 114 pmCell *cell = psAlloc(sizeof(pmCell)); // The cell 101 psMemSetDeallocator(cell, (psFreeF cn)p_pmCellFree);115 psMemSetDeallocator(cell, (psFreeFunc)p_pmCellFree); 102 116 103 117 // Push onto the array of chips … … 114 128 cell->toSky = NULL; 115 129 116 cell->values = psMemIncrRefCounter(values); 130 cell->concepts = psMetadataAlloc(); 131 psMetadataAddStr(cell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, "Cell name added at pmCellAlloc", name); 132 cell->camera = psMemIncrRefCounter(cameraData); 133 117 134 cell->readouts = psArrayAlloc(0); 118 // cell->parent = psMemIncrRefCounter(chip); 119 120 cell->extname = NULL; 121 cell->pixels = NULL; 122 cell->header = NULL; 123 124 psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at pmCellAlloc", name); 135 cell->parent = chip; // We don't increment the reference counter on this --- it's a 136 // "hidden" link. If we increment the reference counter, we get stuck 137 // in a circle. 138 cell->valid = true; 139 140 cell->private = NULL; 125 141 126 142 return cell; … … 135 151 psFree(cell->toSky); 136 152 137 psFree(cell->values); 153 psFree(cell->concepts); 154 psFree(cell->camera); 138 155 psFree(cell->readouts); 139 // psFree(cell->parent); 140 141 psFree(cell->pixels); 142 psFree(cell->header); 156 157 psFree(cell->private); 158 159 // We don't free the parent member, since that would generate a circular call. We don't increment the 160 // reference counter when we add it, anyway, so that's OK. 143 161 } 144 162 145 163 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs 146 int readoutNum, // Number of the readout147 164 psImage *image, // The pixels 148 165 psList *overscans, // The overscan images … … 151 168 { 152 169 pmReadout *readout = psAlloc(sizeof(pmReadout)); 153 psMemSetDeallocator(readout, (psFreeFcn)p_pmReadoutFree); 154 psArray *readouts = cell->readouts; 155 if (readoutNum >= readouts->nalloc) { 156 readouts = psArrayRealloc(readouts, readoutNum); 157 cell->readouts = readouts; 158 } 159 readouts->data[readoutNum] = readout; 170 psMemSetDeallocator(readout, (psFreeFunc)p_pmReadoutFree); 171 cell->readouts = psArrayAdd(cell->readouts, 0, readout); 160 172 161 173 // Set the components 162 readout->image = image; 163 readout->overscans = overscans; 174 readout->image = psMemIncrRefCounter(image); 175 readout->mask = NULL; 176 readout->overscans = psMemIncrRefCounter(overscans); 164 177 165 readout->values = psMetadataAlloc();178 //readout->concepts = psMetadataAlloc(); 166 179 167 180 *(int*)&readout->col0 = col0; … … 178 191 { 179 192 psFree(readout->image); 193 psFree(readout->mask); 180 194 psFree(readout->overscans); 181 psFree(readout->values); 182 } 195 //psFree(readout->concepts); 196 } 197 198 199 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 200 // Select and Exclude chips 201 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 202 203 bool pmFPASelectChip(pmFPA *fpa, int chipNum) 204 { 205 assert(fpa); 206 207 if (chipNum < 0 || chipNum > fpa->chips->n) { 208 return false; 209 } 210 psArray *chips = fpa->chips; // Component chips 211 for (int i = 0; i < chips->n; i++) { 212 pmChip *chip = chips->data[i]; // The chip of interest 213 if (i == chipNum) { 214 psTrace(__func__, 5, "Marking chip %d valid.\n", i); 215 chip->valid = true; 216 psArray *cells = chip->cells; // Component cells 217 for (int j = 0; j < cells->n; j++) { 218 pmCell *cell = cells->data[j]; // Cell of interest 219 cell->valid = true; 220 } 221 } else { 222 psTrace(__func__, 5, "Marking chip %d invalid.\n", i); 223 chip->valid = false; 224 psArray *cells = chip->cells; // Component cells 225 for (int j = 0; j < cells->n; j++) { 226 pmCell *cell = cells->data[j]; // Cell of interest 227 cell->valid = false; 228 } 229 } 230 } 231 return true; 232 } 233 234 int pmFPAExcludeChip(pmFPA *fpa, int chipNum) 235 { 236 assert(fpa); 237 238 if (chipNum < 0 || chipNum > fpa->chips->n) { 239 psLogMsg(__func__, PS_LOG_WARN, "Invalid chip number: %d\n", chipNum); 240 } 241 int numValid = 0; // Number of valid chips 242 psArray *chips = fpa->chips; // Component chips 243 for (int i = 0; i < chips->n; i++) { 244 pmChip *chip = chips->data[i]; // The chip of interest 245 if (i == chipNum) { 246 psTrace(__func__, 5, "Marking chip %d invalid.\n", i); 247 chip->valid = false; 248 psArray *cells = chip->cells; // Component cells 249 for (int j = 0; j < cells->n; j++) { 250 pmCell *cell = cells->data[j]; // Cell of interest 251 cell->valid = false; 252 } 253 } else if (chip->valid) { 254 numValid++; 255 } 256 } 257 258 psTrace(__func__, 5, "%d valid chips in fpa.\n", numValid); 259 return numValid; 260 } -
trunk/archive/scripts/src/phase2/pmFPA.h
r4820 r5104 10 10 11 11 typedef struct { 12 const char *extname; // Extension name, if it corresponds to this level 13 psArray *pixels; // The pixel data, if it corresponds to this level 14 psMetadata *header; // The FITS header, if it corresponds to this level 15 } p_pmHDU; 16 17 typedef struct { 12 18 // Astrometric transformations 13 19 psPlaneDistort* fromTangentPlane; // Transformation from tangent plane to focal plane … … 15 21 psProjection *projection; // Projection from tangent plane to sky 16 22 // Information 17 psMetadata * values; // Important values (cached)18 const psMetadata *camera; // Camera configuration19 ps DB *db; // Database23 psMetadata *camera; // Camera configuration 24 psMetadata *concepts; // Values for concepts 25 psMetadata *phu; // Primary Header 20 26 psArray *chips; // The chips 21 // FITS data 22 const char *extname; // Extension name, if it corresponds to this level 23 psArray *pixels; // The pixel data, if it corresponds to this level 24 psMetadata *header; // The FITS header, if it corresponds to this level 27 p_pmHDU *private; // FITS data 25 28 } pmFPA; 26 29 … … 33 36 psPlaneTransform* fromFPA; // Transformation from FPA to chip coordinates 34 37 // Information 35 psMetadata * values; // Important values (cached)38 psMetadata *concepts; // Values for concepts 36 39 psArray *cells; // The cells (referred to by name) 37 40 pmFPA *parent; // Parent FPA 38 // FITS data 39 const char *extname; // Extension name, if it corresponds to this level 40 psArray *pixels; // The pixel data, if it corresponds to this level 41 psMetadata *header; // The FITS header, if it corresponds to this level 41 bool valid; // Valid for reading in? 42 p_pmHDU *private; // FITS data 42 43 } pmChip; 43 44 … … 53 54 psPlaneTransform* toSky; // Transformations from cell to tangent plane coordinates 54 55 // Information 55 psMetadata *values; // Important values (cached) 56 psMetadata *concepts; // Values for concepts 57 psMetadata *camera; // Camera information 56 58 psArray *readouts; // The readouts (referred to by number) 57 59 pmChip *parent; // Parent chip 58 // FITS data 59 const char *extname; // Extension name, if it corresponds to this level 60 psArray *pixels; // The pixel data, if it corresponds to this level 61 psMetadata *header; // The FITS header, if it corresponds to this level 60 bool valid; // Valid for operating on? 61 p_pmHDU *private; // FITS data 62 62 } pmCell; 63 63 … … 73 73 // Information 74 74 psImage *image; // The pixels 75 psList *overscans; // Array of subimages containing the overscan region(s) 76 psMetadata *values; // readout-level metadata 75 psImage *mask; // Mask image 76 psList *overscans; // List of subimages containing the overscan regions 77 psMetadata *concepts; // Concepts for readouts 77 78 } pmReadout; 78 79 79 80 // Allocators and deallocators 80 pmFPA *pmFPAAlloc(const psMetadata *camera, // Camera configuration 81 psDB *db // Database 81 p_pmHDU *p_pmHDUAlloc(const char *extname); 82 void p_pmHDUFree(p_pmHDU *hdu); 83 pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration 82 84 ); 83 85 void p_pmFPAFree(pmFPA *fpa); … … 89 91 90 92 pmCell *pmCellAlloc(pmChip *chip, // Chip to which the cell belongs 91 psMetadata * values, // Initial values for concepts93 psMetadata *cameraData, // Camera data 92 94 psString name // Name of cell 93 95 ); … … 95 97 96 98 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs 97 int readoutNum, // Number of the readout98 99 psImage *image, // The pixels 99 100 psList *overscans, // The overscan images … … 102 103 void p_pmReadoutFree(pmReadout *readout); 103 104 105 // Select and exclude chips 106 bool pmFPASelectChip(pmFPA *fpa, int chipNum); 107 int pmFPAExcludeChip(pmFPA *fpa, int chipNum); 108 104 109 #endif -
trunk/archive/scripts/src/phase2/pmFPAConstruct.c
r4820 r5104 30 30 psError(PS_ERR_IO, false, "Unable to find specs for cell %s: ignored\n", cellName); 31 31 } 32 33 #if 0 34 // Need to create a new instance, so that each cell can work with its own 35 psMetadata *copy = psMetadataAlloc(); 36 psMetadataIterator *iter = psMetadataIteratorAlloc(cellData, PS_LIST_HEAD, NULL); // Iterator 37 psMetadataItem *item = NULL; // Item from iteration 38 while (item = psMetadataGetAndIncrement(iter)) { 39 if (item->type == PS_META_MULTI || item->type == PS_META_META) { 40 psLogMsg(__func__, PS_LOG_WARN, "PS_META_MULTI and PS_META_META are not supported in a cell " 41 "definition --- %s ignored.\n", item->name); 42 continue; 43 } 44 if (! psMetadataAdd(copy, PS_LIST_TAIL, item->name, item->type, item->comment, item->data.V)) { 45 psAbort(__func__, "Should never reach here!\n"); 46 } 47 } 48 psFree(iter); 49 50 return copy; 51 #else 32 52 return cellData; 53 #endif 54 33 55 } 34 56 … … 38 60 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 39 61 40 pmFPA *pmFPAConstruct(const psMetadata *camera, // The camera configuration 41 psDB *db // Database handle 62 pmFPA *pmFPAConstruct(const psMetadata *camera // The camera configuration 42 63 ) 43 64 { 44 pmFPA *fpa = pmFPAAlloc(camera , db); // The FPA to fill out65 pmFPA *fpa = pmFPAAlloc(camera); // The FPA to fill out 45 66 bool mdStatus = true; // Status from metadata lookups 46 67 const char *phuType = psMetadataLookupString(&mdStatus, camera, "PHU"); // What is the PHU? … … 67 88 psString extName = contentItem->name; // The name of the extension 68 89 pmChip *chip = pmChipAlloc(fpa, extName); // The chip 69 chip-> extname = extName;// Markchip to receive FITS data90 chip->private = p_pmHDUAlloc(extName); // Prepare chip to receive FITS data 70 91 if (contentItem->type != PS_META_STR) { 71 92 psLogMsg(__func__, PS_LOG_WARN, "Type of content item (%x) is not string: ignored\n", … … 83 104 psMetadata *cellData = getCellData(camera, cellName); 84 105 pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell 106 // psFree(cellData); 85 107 } 86 108 psFree(cellNamesIter); … … 102 124 const char *content = contentItem->data.V; // The content of the extension 103 125 psList *contents = papSplit(content, ": "); // Split the name from the type 104 if (contents-> size!= 2) {126 if (contents->n != 2) { 105 127 psLogMsg(__func__, PS_LOG_WARN, "Unable to read contents of %s: ignored.\n", extName); 106 128 } else { … … 123 145 psMetadata *cellData = getCellData(camera, cellType); 124 146 pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell 125 cell->extname = extName; // Mark cell to receive FITS data 147 // psFree(cellData); 148 cell->private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data 126 149 127 150 psFree(chip); 128 151 psFree(cell); 129 psFree(chipName);130 psFree(cellType);131 152 } 132 153 psFree(contents); … … 136 157 } else if (strcasecmp(extType, "NONE") == 0) { 137 158 // No extensions; Content contains metadata, each entry is a chip with its component cells 138 fpa-> extname = "PHU";159 fpa->private = p_pmHDUAlloc("PHU"); // Prepare FPA to receive FITS data 139 160 while (contentItem = psMetadataGetAndIncrement(contentsIter)) { 140 161 psString chipName = contentItem->name; // The name of the chip … … 155 176 psMetadata *cellData = getCellData(camera, cellName); 156 177 pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell 178 // psFree(cellData); 157 179 } 158 180 psFree(cellNamesIter); … … 174 196 if (strcasecmp(extType, "NONE") == 0) { 175 197 // There are no extensions --- only the PHU 176 chip-> extname = "PHU";198 chip->private = p_pmHDUAlloc("PHU"); 177 199 178 200 const char *contents = psMetadataLookupString(&mdStatus, camera, "CONTENTS"); … … 188 210 psMetadata *cellData = getCellData(camera, cellName); 189 211 pmCell *cell = pmCellAlloc(chip, cellData, cellName); // The cell 212 // psFree(cellData); 190 213 } 191 214 psFree(cellIter); … … 223 246 psMetadata *cellData = getCellData(camera, cellType); 224 247 pmCell *cell = pmCellAlloc(chip, cellData, extName); // The cell 225 cell->extname = extName; // Mark cell to receive FITS data 248 // psFree(cellData); 249 cell->private = p_pmHDUAlloc(extName); // Prepare cell to receive FITS data 226 250 } // Iterating through contents 227 251 psFree(contentsIter); … … 249 273 { 250 274 psTrace(__func__, 0, "FPA:\n"); 251 if (fpa-> extname) {252 psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa-> extname);253 if (! fpa->p ixels) {254 psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa-> extname);275 if (fpa->private) { 276 psTrace(__func__, 1, "---> FPA is extension %s.\n", fpa->private->extname); 277 if (! fpa->private->pixels) { 278 psTrace(__func__, 1, "---> NO PIXELS for extension %s\n", fpa->private->extname); 255 279 } 256 280 } … … 261 285 psTrace(__func__, 1, "Chip: %d\n", i); 262 286 pmChip *chip = chips->data[i]; // The chip 263 if (chip-> extname) {264 psTrace(__func__, 2, "---> Chip is extension %s.\n", chip-> extname);265 if (! chip->p ixels) {266 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip-> extname);287 if (chip->private) { 288 psTrace(__func__, 2, "---> Chip is extension %s.\n", chip->private->extname); 289 if (! chip->private->pixels) { 290 psTrace(__func__, 2, "---> NO PIXELS for extension %s\n", chip->private->extname); 267 291 } 268 292 } … … 272 296 psTrace(__func__, 2, "Cell: %d\n", j); 273 297 pmCell *cell = cells->data[j]; // The cell 274 if (cell-> extname) {275 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell-> extname);276 if (! cell->p ixels) {277 psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell-> extname);278 } 279 } 280 psMetadataPrint(cell-> values, 3);298 if (cell->private) { 299 psTrace(__func__, 3, "---> Cell is extension %s.\n", cell->private->extname); 300 if (! cell->private->pixels) { 301 psTrace(__func__, 3, "---> NO PIXELS for extension %s\n", cell->private->extname); 302 } 303 } 304 psMetadataPrint(cell->concepts, 3); 281 305 psTrace(__func__, 3, "Readouts:\n"); 282 306 psArray *readouts = cell->readouts; // Array of readouts -
trunk/archive/scripts/src/phase2/pmFPAConstruct.h
r4820 r5104 6 6 7 7 // Read the contents of a FITS file (format specified by the camera configuration) into memory 8 pmFPA *pmFPAConstruct(const psMetadata *camera, // The camera configuration 9 psDB *db // Database handle 8 pmFPA *pmFPAConstruct(const psMetadata *camera // The camera configuration 10 9 ); 11 10 -
trunk/archive/scripts/src/phase2/psAdditionals.c
r4793 r5104 103 103 break; 104 104 default: 105 printf("\n"); 105 106 psError(PS_ERR_IO, false, "Non-printable metadata type: %x\n", item->type); 106 107 } … … 262 263 // Go through the MULTI 263 264 psList *multi = argItem->data.V; // The list of MULTI psMetadataItems 264 if (*argc < i + multi-> size) {265 if (*argc < i + multi->n) { 265 266 psError(PS_ERR_IO, true, "Not enough arguments for %s.\n", argItem->name); 266 267 // Remove the arguments --- they will be ignored -
trunk/archive/scripts/src/phase2/psAdditionals.h
r4793 r5104 3 3 4 4 #include "pslib.h" 5 6 typedef char* psString;7 5 8 6 // Get a value from the metadata that we believe should be metadata.
Note:
See TracChangeset
for help on using the changeset viewer.
