Changeset 4820
- Timestamp:
- Aug 18, 2005, 3:06:11 PM (21 years ago)
- Location:
- trunk/archive/scripts/src/phase2
- Files:
-
- 8 added
- 2 edited
-
Makefile (modified) (1 diff)
-
papPhase2.c (modified) (26 diffs)
-
papStuff.c (added)
-
papStuff.h (added)
-
pmConfig.c (added)
-
pmConfig.h (added)
-
pmFPA.c (added)
-
pmFPA.h (added)
-
pmFPAConstruct.c (added)
-
pmFPAConstruct.h (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/Makefile
r4793 r4820 1 1 SHELL = /bin/sh 2 2 CC = gcc 3 CFLAGS += -O0 -g -std=c99 -Werror -I/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/include/ -D_GNU_SOURCE 3 4 #DEVFLAGS += -DPRODUCTION # Produce binary as for production (don't use old APIs) 5 DEVFLAGS += -DTESTING # Testing version 6 7 CFLAGS += -O0 -g -std=c99 -Werror -I/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/include/ -D_GNU_SOURCE $(DEVFLAGS) 4 8 PSLIB += -L/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/lib/ -lpslib -lgsl -lgslcblas -lfftw3f -lsla -lcfitsio -lm -lxml2 -lmysqlclient 9 PSMODULE += -L/home/mithrandir/price/pan-starrs/jhroot/i686-pc-linux-gnu/lib/ -lpsmodule 5 10 LDFLAGS += $(PSLIB) 6 11 7 OBJS = papPhase2.o psAdditionals.o 12 OBJS = papPhase2.o psAdditionals.o pmConfig.o pmFPA.o pmFPAConstruct.o papStuff.o 8 13 TARGET = papPhase2 9 14 -
trunk/archive/scripts/src/phase2/papPhase2.c
r4793 r4820 1 1 #include <stdio.h> 2 #include <string.h> 3 2 4 #include "pslib.h" 3 5 #include "psAdditionals.h" 6 7 #include "pmSubtractBias.h" 8 9 #include "pmFPA.h" 10 #include "pmConfig.h" 11 #include "pmFPAConstruct.h" 4 12 5 13 // Phase 2 needs to: … … 25 33 // 26 34 // Most are self-explanatory. "-chip" says "only work on this particular chip". 35 36 37 #define RECIPE "PHASE2" // Name of the recipe to use 27 38 28 39 static psMemoryId memPrintAlloc(const psMemBlock *mb) … … 44 55 return 0; 45 56 } 57 static void memPrint(const psPtr ptr) 58 { 59 psMemBlock *mb = ((psMemBlock*)ptr) - 1; 60 printf("Memory block %lld (%lld):\n" 61 "\tFile %s, line %d, size %d\n" 62 "\tPosts: %x %x %x\n", 63 mb->id, mb->refCounter, mb->file, mb->lineno, mb->userMemorySize, mb->startblock, mb->endblock, 64 *(void**)((int8_t *)(mb + 1) + mb->userMemorySize)); 65 } 46 66 47 67 int main(int argc, char *argv[]) 48 68 { 49 psMemAllocateCallbackSetID(71); 50 psMemFreeCallbackSetID(71); 69 #if 0 70 // Hunting memory leaks 71 psMemAllocateCallbackSetID(3539); 72 psMemFreeCallbackSetID(3539); 51 73 psMemAllocateCallbackSet(memPrintAlloc); 52 74 psMemFreeCallbackSet(memPrintFree); 53 54 psTraceSetLevel("psArgumentParse", 10); 75 #endif 76 77 // psTraceSetLevel(".", 10); 55 78 56 79 // Parse the configurations … … 58 81 psMetadata *camera = NULL; // Camera configuration 59 82 psMetadata *recipe = NULL; // Recipe configuration 60 61 #if 0 62 if (! pmConfigRead(&site, &camera, &recipe, &argc, argv, "moduleName")) { 63 psErrorStackPrint("Can't find site configuration!\n"); 83 if (! pmConfigRead(&site, &camera, &recipe, &argc, argv, RECIPE)) { 84 psErrorStackPrint(stderr, "Can't find site configuration!\n"); 64 85 exit(EXIT_FAILURE); 65 86 } 66 #endif67 87 68 88 // Parse other command-line arguments … … 73 93 psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", "Name of the mask image", ""); 74 94 psMetadataAddS32(arguments, PS_LIST_TAIL, "-chip", "Chip number to process (if positive)", -1); 75 76 psMetadataAdd(arguments, PS_LIST_TAIL, "-string", PS_META_STR, "Test string", "SomeString");77 psMetadataAdd(arguments, PS_LIST_TAIL, "-bool", PS_META_BOOL, "Test bool", false);78 #if 179 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 1", 1);80 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 2", 2);81 psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 | PS_META_DUPLICATE_OK, "Test integer 3", 3);82 #endif83 psMetadataAdd(arguments, PS_LIST_TAIL, "-float", PS_META_F32, "Test float", 1.234567);84 85 95 if (! psArgumentParse(arguments, &argc, argv) || argc != 3) { 86 96 printf("\nPan-STARRS Phase 2 processing\n\n"); … … 92 102 const char *inputName = argv[1]; // Name of input image 93 103 const char *outputName = argv[2]; // Name of output image 94 95 printf("Success: %s %s\n", inputName, outputName);96 97 104 const char *biasName = psMetadataLookupString(NULL, arguments, "-bias"); // Name of bias image 98 105 const char *darkName = psMetadataLookupString(NULL, arguments, "-dark"); // Name of dark image … … 100 107 const char *maskName = psMetadataLookupString(NULL, arguments, "-mask"); // Name of mask image 101 108 const int chipNum = psMetadataLookupS32(NULL, arguments, "-chip"); // Chip number to work on 109 printf("Input: %s\nOutput: %s\n", inputName, outputName); 102 110 printf("Bias: %s\n", biasName); 103 111 printf("Dark: %s\n", darkName); … … 105 113 printf("Mask: %s\n", maskName); 106 114 printf("Chip: %d\n", chipNum); 107 108 // For testing 109 psString string = psMetadataLookupString(NULL, arguments, "-string"); 110 float floating = psMetadataLookupF32(NULL, arguments, "-float"); 111 bool mdok = false; 112 bool boolean = psMetadataLookupBool(&mdok, arguments, "-bool"); 113 if (!mdok) printf("Urgh!\n"); 114 printf("String: %s\n", string); 115 printf("Float: %f\n", floating); 116 printf("Boolean: %d\n", boolean); 115 psFree(arguments); 116 117 // Open the input 118 #ifdef PRODUCTION 119 psFits *inputFile = psFitsOpen(inputName, "r"); // File handle for FITS file 120 #else 121 psFits *inputFile = psFitsAlloc(inputName); // File handle for FITS file 122 #endif 123 if (! inputFile) { 124 psErrorStackPrint(stderr, "Can't open input image: %s\n", inputName); 125 exit(EXIT_FAILURE); 126 } 127 psMetadata *header = psFitsReadHeader(NULL, inputFile); // FITS header 128 #if PRODUCTION 129 psDB *database = pmConfigDB(site); // Database handle 130 #else 131 psDB *database = NULL; // Database handle 132 #endif 117 133 118 134 #if 0 119 psMetadataItem *intItem = psMetadataLookup(arguments, "-int");120 if (intItem->type == PS_META_MULTI) {121 psList *intMulti = intItem->data.V;122 psListIterator *intIter = psListIteratorAlloc(intMulti, PS_LIST_HEAD, false);123 psMetadataItem *intMultiItem = NULL;124 while (intMultiItem = psListGetAndIncrement(intIter)) {125 printf("Integer: %d\n", intMultiItem->data.S32);126 }127 psFree(intIter);128 }129 #endif130 131 132 133 134 135 #if 0136 // Open the input137 psFits *inputFile = psFitsOpen(inputName, "r"); // File handle for FITS file138 if (! inputFile) {139 psErrorStackPrint("Can't open input image: %s\n", inputName);140 exit(EXIT_FAILURE);141 }142 psMetadata *header = psFitsReadHeader(NULL, inputFile); // FITS header143 psDB *database = pmConfigDB(site); // Database handle144 145 135 // Open the output and output mask 146 136 // We do it here so that we don't process the whole lot and then find out we can't open the output file 137 #ifdef PRODUCTION 147 138 psFits *outputFile = psFitsOpen(outputName, "w"); 139 #else 140 psFits *outputFile = psFitsAlloc(outputName); 141 #endif 148 142 if (! outputFile) { 149 psErrorStackPrint( "Can't open output image: %s\n", outputName);143 psErrorStackPrint(stderr, "Can't open output image: %s\n", outputName); 150 144 exit(EXIT_FAILURE); 151 145 } 152 146 psString outputMaskName = psStringCopy(outputName); 153 (void)psStringAppend(outputMaskName, ".mask"); 154 psFits *outputMaskFile = psFits(outputMaskName, "w"); 147 (void)psStringAppend(&outputMaskName, ".mask"); 148 #ifdef PRODUCTION 149 psFits *outputMaskFile = psFitsOpen(outputMaskName, "w"); 150 #else 151 psFits *outputMaskFile = psFitsAlloc(outputMaskName); 152 #endif 155 153 if (! outputMaskFile) { 156 psErrorStackPrint( "Can't open output mask image: %s\n", outputMaskName);154 psErrorStackPrint(stderr, "Can't open output mask image: %s\n", outputMaskName); 157 155 exit(EXIT_FAILURE); 158 156 } 159 157 psFree(outputMaskName); 158 #endif 159 160 160 161 161 // Get camera configuration from header if not already defined … … 163 163 camera = pmConfigCameraFromHeader(site, header); 164 164 if (! camera) { 165 psErrorStackPrint( "Can't find camera configuration!\n");166 exit(EXIT_FAILURE); 167 } 168 } else if (! pmConfigValidateCamera(camera, inputHeader)) {169 psError( "phase2", true, "%s does not seem to be from the camera.\n", inputName);165 psErrorStackPrint(stderr, "Can't find camera configuration!\n"); 166 exit(EXIT_FAILURE); 167 } 168 } else if (! pmConfigValidateCamera(camera, header)) { 169 psError(PS_ERR_IO, true, "%s does not seem to be from the camera.\n", inputName); 170 170 exit(EXIT_FAILURE); 171 171 } 172 if (! recipe && !(recipe = pmConfigRecipeFromCamera(camera, "moduleName"))) {173 psErrorStackPrint( "Can't find recipe configuration!\n");172 if (! recipe && !(recipe = pmConfigRecipeFromCamera(camera, RECIPE))) { 173 psErrorStackPrint(stderr, "Can't find recipe configuration!\n"); 174 174 exit(EXIT_FAILURE); 175 175 } 176 176 177 177 // Construct camera in preparation for reading 178 pmFPA *input = pmFPAConstruct(camera, d b);179 pmFPA *mask = pmFPAConstruct(camera, d b);180 pmFPA *bias = pmFPAConstruct(camera, d b);181 pmFPA *dark = pmFPAConstruct(camera, d b);182 pmFPA *flat = pmFPAConstruct(camera, d b);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 183 184 184 // Set various tasks … … 236 236 " assuming NONE.\n", mode); 237 237 } 238 psFree(mode);239 238 psString fit = psMetadataLookupString(NULL, recipe, "OVERSCAN.FIT"); 240 239 if (strcasecmp(fit, "POLYNOMIAL") == 0) { … … 246 245 " assuming NONE.\n", fit); 247 246 } 248 psFree(fit);249 247 overscanBins = psMetadataLookupS32(NULL, recipe, "OVERSCAN.BIN"); 250 248 if (overscanBins <= 0) { 251 psErrorStackPrint( "OVERSCAN.BIN (%d) is non-positive --- assuming 1.\n", overscanBins);249 psErrorStackPrint(stderr, "OVERSCAN.BIN (%d) is non-positive --- assuming 1.\n", overscanBins); 252 250 overscanBins = 1; 253 251 } … … 258 256 overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN); 259 257 } else { 260 psErrorStackPrint( "OVERSCAN.STAT (%s) is not one of MEAN, MEDIAN: assuming MEAN\n", stat);258 psErrorStackPrint(stderr, "OVERSCAN.STAT (%s) is not one of MEAN, MEDIAN: assuming MEAN\n", stat); 261 259 overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); 262 260 } … … 270 268 } 271 269 } 272 270 271 #if 0 273 272 // Chip selection 274 273 if (chipNum >= 0) { … … 276 275 ! pmFPASelectChip(dark, chipNum) || ! pmFPASelectChip(flat, chipNum) || 277 276 ! pmFPASelectChip(mask, chipNum)) { 278 psErrorStackPrint( "Chip number %d doesn't exist in camera.\n", chipNum);277 psErrorStackPrint(stderr, "Chip number %d doesn't exist in camera.\n", chipNum); 279 278 exit(EXIT_FAILURE); 280 279 } … … 284 283 // Read in the input pixels 285 284 if (! pmFPARead(input, inputFile)) { 286 psErrorStackPrint( "Unable to populate camera from FITS file: %s\n", inputName);285 psErrorStackPrint(stderr, "Unable to populate camera from FITS file: %s\n", inputName); 287 286 exit(EXIT_FAILURE); 288 287 } 288 #ifdef PRODUCTION 289 289 psFitsClose(inputFile); 290 #else 291 psFree(inputFile); 292 #endif 293 290 294 291 295 // Load the calibration frames, if required … … 299 303 psFree(biasHeader); 300 304 if (! pmFPARead(bias, biasFile)) { 301 psErrorStackPrint( "Unable to populate bias camera from fits FITS: %s\n", biasName);305 psErrorStackPrint(stderr, "Unable to populate bias camera from fits FITS: %s\n", biasName); 302 306 exit(EXIT_FAILURE); 303 307 } … … 314 318 psFree(darkHeader); 315 319 if (! pmFPARead(dark, darkFile)) { 316 psErrorStackPrint( "Unable to populate dark camera from fits FITS: %s\n", darkName);320 psErrorStackPrint(stderr, "Unable to populate dark camera from fits FITS: %s\n", darkName); 317 321 exit(EXIT_FAILURE); 318 322 } … … 329 333 psFree(maskHeader); 330 334 if (! pmFPARead(mask, maskFile)) { 331 psErrorStackPrint( "Unable to populate mask camera from fits FITS: %s\n", maskName);335 psErrorStackPrint(stderr, "Unable to populate mask camera from fits FITS: %s\n", maskName); 332 336 exit(EXIT_FAILURE); 333 337 } … … 344 348 psFree(flatHeader); 345 349 if (! pmFPARead(flat, flatFile)) { 346 psErrorStackPrint( "Unable to populate flat camera from fits FITS: %s\n", flatName);350 psErrorStackPrint(stderr, "Unable to populate flat camera from fits FITS: %s\n", flatName); 347 351 exit(EXIT_FAILURE); 348 352 } … … 414 418 darkTime = pmReadoutGetDarkTime(darkReadout); 415 419 if (darkTime <= 0.0) { 416 psErrorStackPrint( "DARKTIME for dark image (%f) is non-positive.\n", darkTime);420 psErrorStackPrint(stderr, "DARKTIME for dark image (%f) is non-positive.\n", darkTime); 417 421 exit(EXIT_FAILURE); 418 422 } … … 469 473 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 470 474 if (psLookupTableRead(table) <= 0) { 471 psErrorStackPrint( "Unable to read non-linearity correction file %s ---"472 " ignored\n", tableName);475 psErrorStackPrint(stderr, "Unable to read non-linearity correction file %s " 476 "--- ignored\n", tableName); 473 477 } else { 474 478 (void)pmNonLinearityLookup(inputReadout, table); … … 523 527 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0); 524 528 if ((int numLines = psLookupTableRead(table)) <= 0) { 525 psErrorStackPrint( "Unable to read non-linearity correction"526 " file %s --- ignored\n", tableName);529 psErrorStackPrint(stderr, "Unable to read non-linearity " 530 "correction file %s --- ignored\n", tableName); 527 531 } else { 528 532 (void)pmNonLinearityLookup(inputReadout, table); … … 553 557 float inputTime = pmReadoutGetDarkTime(inputReadout); // Dark time for input image 554 558 if (inputTime <= 0) { 555 psErrorStackPrint("DARKTIME for input image (%f) is non-positive.\n", inputTime); 559 psErrorStackPrint(stderr, "DARKTIME for input image (%f) is non-positive.\n", 560 inputTime); 556 561 exit(EXIT_FAILURE); 557 562 } … … 583 588 overscanMode = PM_OVERSCAN_COLUMNS; 584 589 } else { 585 psErrorStackPrint("CELL.READDIR (%d) is not 1 or 2 --- assuming 1.\n", readdir); 590 psErrorStackPrint(stderr, "CELL.READDIR (%d) is not 1 or 2 --- assuming 1.\n", 591 readdir); 586 592 overscanMode = PM_OVERSCAN_ROWS; 587 593 } … … 655 661 pmFPAWrite(outputFile, input); 656 662 pmFPAWriteMask(outputMaskFile, input); 663 #ifdef PRODUCTION 657 664 psFitsClose(outputFile); 658 665 psFitsClose(outputMaskFile); 659 666 #else 667 psFree(outputFile); 668 psFree(outputMaskFile); 669 #endif 670 671 #endif 672 673 psFree(site); 674 psFree(header); 675 psFree(camera); 676 psFree(recipe); 660 677 psFree(input); 661 678 psFree(mask); … … 663 680 psFree(dark); 664 681 psFree(flat); 665 666 #endif 667 668 682 psFree(overscanStats); 683 psFree(inputFile); 684 685 #if 1 669 686 psMemCheckCorruption(true); 670 psFree(arguments);671 687 psMemBlock **leaks = NULL; // List of leaks 672 688 int nLeaks = psMemCheckLeaks(0, &leaks, NULL, false); // Number of leaks 673 689 printf("%d leaks found.\n", nLeaks); 690 #if 1 674 691 for (int i = 0; i < nLeaks; i++) { 675 printf("Memory leak detection: memBlock %lld \n"692 printf("Memory leak detection: memBlock %lld (%lld)\n" 676 693 "\tFile %s, line %d, size %d\n", 677 leaks[i]->id, leaks[i]->file, leaks[i]->lineno, leaks[i]->userMemorySize); 678 } 694 leaks[i]->id, leaks[i]->refCounter, leaks[i]->file, leaks[i]->lineno, 695 leaks[i]->userMemorySize); 696 } 697 #endif 698 #endif 679 699 680 700 }
Note:
See TracChangeset
for help on using the changeset viewer.
