IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 18, 2005, 3:06:11 PM (21 years ago)
Author:
Paul Price
Message:

Constructing FPAs OK.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/phase2/papPhase2.c

    r4793 r4820  
    11#include <stdio.h>
     2#include <string.h>
     3
    24#include "pslib.h"
    35#include "psAdditionals.h"
     6
     7#include "pmSubtractBias.h"
     8
     9#include "pmFPA.h"
     10#include "pmConfig.h"
     11#include "pmFPAConstruct.h"
    412
    513// Phase 2 needs to:
     
    2533//
    2634// Most are self-explanatory.  "-chip" says "only work on this particular chip".
     35
     36
     37#define RECIPE "PHASE2"                 // Name of the recipe to use
    2738
    2839static psMemoryId memPrintAlloc(const psMemBlock *mb)
     
    4455    return 0;
    4556}
     57static 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}
    4666
    4767int main(int argc, char *argv[])
    4868{
    49     psMemAllocateCallbackSetID(71);
    50     psMemFreeCallbackSetID(71);
     69#if 0
     70    // Hunting memory leaks
     71    psMemAllocateCallbackSetID(3539);
     72    psMemFreeCallbackSetID(3539);
    5173    psMemAllocateCallbackSet(memPrintAlloc);
    5274    psMemFreeCallbackSet(memPrintFree);
    53 
    54     psTraceSetLevel("psArgumentParse", 10);
     75#endif
     76
     77//    psTraceSetLevel(".", 10);
    5578
    5679    // Parse the configurations
     
    5881    psMetadata *camera = NULL;          // Camera configuration
    5982    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");
    6485        exit(EXIT_FAILURE);
    6586    }
    66 #endif
    6787
    6888    // Parse other command-line arguments
     
    7393    psMetadataAddStr(arguments, PS_LIST_TAIL, "-mask", "Name of the mask image", "");
    7494    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 1
    79     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 #endif
    83     psMetadataAdd(arguments, PS_LIST_TAIL, "-float", PS_META_F32, "Test float", 1.234567);
    84 
    8595    if (! psArgumentParse(arguments, &argc, argv) || argc != 3) {
    8696        printf("\nPan-STARRS Phase 2 processing\n\n");
     
    92102    const char *inputName = argv[1];    // Name of input image
    93103    const char *outputName = argv[2];   // Name of output image
    94 
    95     printf("Success: %s %s\n", inputName, outputName);
    96 
    97104    const char *biasName = psMetadataLookupString(NULL, arguments, "-bias"); // Name of bias image
    98105    const char *darkName = psMetadataLookupString(NULL, arguments, "-dark"); // Name of dark image
     
    100107    const char *maskName = psMetadataLookupString(NULL, arguments, "-mask"); // Name of mask image
    101108    const int chipNum = psMetadataLookupS32(NULL, arguments, "-chip"); // Chip number to work on
     109    printf("Input: %s\nOutput: %s\n", inputName, outputName);
    102110    printf("Bias: %s\n", biasName);
    103111    printf("Dark: %s\n", darkName);
     
    105113    printf("Mask: %s\n", maskName);
    106114    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
    117133
    118134#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 #endif
    130 
    131 
    132 
    133 
    134 
    135 #if 0
    136     // Open the input
    137     psFits *inputFile = psFitsOpen(inputName, "r"); // File handle for FITS file
    138     if (! inputFile) {
    139         psErrorStackPrint("Can't open input image: %s\n", inputName);
    140         exit(EXIT_FAILURE);
    141     }
    142     psMetadata *header = psFitsReadHeader(NULL, inputFile); // FITS header
    143     psDB *database = pmConfigDB(site);  // Database handle
    144 
    145135    // Open the output and output mask
    146136    // 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
    147138    psFits *outputFile = psFitsOpen(outputName, "w");
     139#else
     140    psFits *outputFile = psFitsAlloc(outputName);
     141#endif
    148142    if (! outputFile) {
    149         psErrorStackPrint("Can't open output image: %s\n", outputName);
     143        psErrorStackPrint(stderr, "Can't open output image: %s\n", outputName);
    150144        exit(EXIT_FAILURE);
    151145    }
    152146    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
    155153    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);
    157155        exit(EXIT_FAILURE);
    158156    }
    159157    psFree(outputMaskName);
     158#endif
     159
    160160       
    161161    // Get camera configuration from header if not already defined
     
    163163        camera = pmConfigCameraFromHeader(site, header);
    164164        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);
    170170        exit(EXIT_FAILURE);
    171171    }
    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");
    174174        exit(EXIT_FAILURE);
    175175    }
    176176
    177177    // Construct camera in preparation for reading
    178     pmFPA *input = pmFPAConstruct(camera, db);
    179     pmFPA *mask = pmFPAConstruct(camera, db);
    180     pmFPA *bias = pmFPAConstruct(camera, db);
    181     pmFPA *dark = pmFPAConstruct(camera, db);
    182     pmFPA *flat = pmFPAConstruct(camera, db);
     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);
    183183
    184184    // Set various tasks
     
    236236                     " assuming NONE.\n", mode);
    237237        }
    238         psFree(mode);
    239238        psString fit = psMetadataLookupString(NULL, recipe, "OVERSCAN.FIT");
    240239        if (strcasecmp(fit, "POLYNOMIAL") == 0) {
     
    246245                     " assuming NONE.\n", fit);
    247246        }
    248         psFree(fit);
    249247        overscanBins = psMetadataLookupS32(NULL, recipe, "OVERSCAN.BIN");
    250248        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);
    252250            overscanBins = 1;
    253251        }
     
    258256            overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    259257        } 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);
    261259            overscanStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);     
    262260        }
     
    270268        }
    271269    }
    272          
     270
     271#if 0
    273272    // Chip selection
    274273    if (chipNum >= 0) {
     
    276275            ! pmFPASelectChip(dark, chipNum) || ! pmFPASelectChip(flat, chipNum) ||
    277276            ! 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);
    279278            exit(EXIT_FAILURE);
    280279        }
     
    284283    // Read in the input pixels
    285284    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);
    287286        exit(EXIT_FAILURE);
    288287    }
     288#ifdef PRODUCTION
    289289    psFitsClose(inputFile);
     290#else
     291    psFree(inputFile);
     292#endif
     293
    290294
    291295    // Load the calibration frames, if required
     
    299303        psFree(biasHeader);
    300304        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);
    302306            exit(EXIT_FAILURE);
    303307        }
     
    314318        psFree(darkHeader);
    315319        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);
    317321            exit(EXIT_FAILURE);
    318322        }
     
    329333        psFree(maskHeader);
    330334        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);
    332336            exit(EXIT_FAILURE);
    333337        }
     
    344348        psFree(flatHeader);
    345349        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);
    347351            exit(EXIT_FAILURE);
    348352        }
     
    414418                darkTime = pmReadoutGetDarkTime(darkReadout);
    415419                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);
    417421                    exit(EXIT_FAILURE);
    418422                }
     
    469473                            psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
    470474                            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);
    473477                            } else {
    474478                                (void)pmNonLinearityLookup(inputReadout, table);
     
    523527                                        psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0);
    524528                                        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);
    527531                                        } else {
    528532                                            (void)pmNonLinearityLookup(inputReadout, table);
     
    553557                    float inputTime = pmReadoutGetDarkTime(inputReadout); // Dark time for input image
    554558                    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);
    556561                        exit(EXIT_FAILURE);
    557562                    }
     
    583588                        overscanMode = PM_OVERSCAN_COLUMNS;
    584589                    } 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);
    586592                        overscanMode = PM_OVERSCAN_ROWS;
    587593                    }
     
    655661    pmFPAWrite(outputFile, input);
    656662    pmFPAWriteMask(outputMaskFile, input);
     663#ifdef PRODUCTION
    657664    psFitsClose(outputFile);
    658665    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);
    660677    psFree(input);
    661678    psFree(mask);
     
    663680    psFree(dark);
    664681    psFree(flat);
    665 
    666 #endif
    667 
    668    
     682    psFree(overscanStats);
     683    psFree(inputFile);
     684
     685#if 1
    669686    psMemCheckCorruption(true);
    670     psFree(arguments);
    671687    psMemBlock **leaks = NULL;          // List of leaks
    672688    int nLeaks = psMemCheckLeaks(0, &leaks, NULL, false); // Number of leaks
    673689    printf("%d leaks found.\n", nLeaks);
     690#if 1
    674691    for (int i = 0; i < nLeaks; i++) {
    675         printf("Memory leak detection: memBlock %lld\n"
     692        printf("Memory leak detection: memBlock %lld (%lld)\n"
    676693               "\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
    679699
    680700}
Note: See TracChangeset for help on using the changeset viewer.