IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 30, 2005, 7:05:28 AM (20 years ago)
Author:
eugene
Message:

cleanups, segfault fixes, etc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppImage/src/ppImageDetrendNonLinear.c

    r5857 r5858  
    11# include "ppImage.h"
    22
    3 bool ppDetrendNonLinear (pmCell *cell, pmReadout *readout, psMetadata *recipe) {
     3bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem) {
    44
    5     psString name;
    6     psVector *coeff;
    7     psMetadata *options;
     5    // These are the polynomial coefficients
     6    psVector *coeff = dataItem->data.V; // The coefficient vector
     7    if (coeff->type.type != PS_TYPE_F64) {
     8        psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
     9        psFree (coeff);
     10        coeff = temp;
     11    }
     12    psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, PS_POLYNOMIAL_ORD);
     13    psFree(correction->coeff);
     14    correction->coeff = psMemIncrRefCounter(coeff->data.F64);
     15    pmNonLinearityPolynomial(input, correction);
     16    psFree(coeff);
     17    psFree(correction);
     18    return true;
     19}   
    820
    9     psMetadataItem *dataItem = psMetadataLookup(recipe, "NONLIN.DATA");
    10     if (! dataItem) {
    11         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but unable to "
    12                  "find NONLIN.DATA in recipe --- ignored.\n");
     21bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem) {
     22
     23    // This is a filename: lookup table
     24    char *name = dataItem->data.V;       // Filename
     25    psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
     26    if (psLookupTableRead(table) <= 0) {
     27        psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
     28                          "%s --- ignored\n", name);
    1329        return false;
    1430    }
     31#ifdef PRODUCTION
     32    pmNonLinearityLookup(input, table);
     33#else
     34    psVector *influx = table->values->data[0];
     35    psVector *outflux = table->values->data[1];
     36    pmNonLinearityLookup(input, influx, outflux);
     37#endif
     38    psFree(table);
     39    return true;
     40}   
    1541
    16     switch (dataItem->type) {
     42bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options) {
     43
     44    psMetadataItem *concept;
     45
     46    switch (options->nonLinearType) {
    1747      case PS_DATA_VECTOR:
    18         // These are the polynomial coefficients
    19         coeff = dataItem->data.V; // The coefficient vector
    20         if (coeff->type.type != PS_TYPE_F64) {
    21             psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version
    22             coeff = temp;
    23         }
    24         psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1,
    25                                                          PS_POLYNOMIAL_ORD);
    26         psFree(correction->coeff);
    27         correction->coeff = psMemIncrRefCounter(coeff->data.F64);
    28         (void)pmNonLinearityPolynomial(inputReadout, correction);
    29         psFree(coeff);
    30         psFree(correction);
     48        ppDetrendNonLinearPolynomial (input, options->nonLinearData);
    3149        return true;
    3250
    3351      case PS_DATA_STRING:
    34         // This is a filename
    35         name = dataItem->data.V;       // Filename
    36         psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0);
    37         if (psLookupTableRead(table) <= 0) {
    38             psErrorStackPrint(stderr, "Unable to read non-linearity correction file "
    39                               "%s --- ignored\n", name);
    40             return false;
    41         }
    42 #ifdef PRODUCTION
    43         (void)pmNonLinearityLookup(inputReadout, table);
    44 #else
    45         psVector *influx = table->values->data[0];
    46         psVector *outflux = table->values->data[1];
    47         (void)pmNonLinearityLookup(inputReadout, table->values->data[0],
    48                                    table->values->data[1]);
    49 #endif
    50         psFree(table);
     52        ppDetrendNonLinearLookup (input, options->nonLinearData);
    5153        return true;
    5254
    5355      case PS_DATA_METADATA:
    54         // This is a menu
    55         options = dataItem->data.V; // Options with concept values as keys
    56         bool mdok = false; // Success of MD lookup
    57         psString concept = psMetadataLookupStr(&mdok, recipe, "NONLIN.SOURCE");
    58         if (! mdok || ! concept) {
    59             psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but "
    60                      "unable to find NONLIN.SOURCE in recipe --- ignored.\n");
     56        // XXX this is somewhat confusing : let's wrap in a function when i understand it
     57        concept = pmCellGetConcept(cell, options->nonLinearSource);
     58        if (! concept) {
     59            psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
     60                     "for non-linearity correction --- ignored.\n", options->nonLinearSource);
    6161            return false;
    6262        }
    63         psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept);
    64         if (! conceptValueItem) {
    65             psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s "
    66                      "for non-linearity correction --- ignored.\n", concept);
    67             return false;
    68         }
    69         if (conceptValueItem->type != PS_DATA_STRING) {
     63        if (concept->type != PS_DATA_STRING) {
    7064            psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as"
    7165                     " expected for non-linearity correction --- ignored.\n",
     
    7468        }
    7569
    76         psString conceptValue = conceptValueItem->data.V;
    7770        // Get the value of the concept
    78         psMetadataItem *optionItem = psMetadataLookup(options, conceptValue);
     71        psString conceptValue = concept->data.V;
     72        psMetadata *folder = (psMetadata *)options->nonLinearData->data.V;
     73        psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue);
    7974        if (!optionItem) {
    8075            psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA"
     
    8277            return false;
    8378        }
    84         if (optionItem->type == PS_DATA_VECTOR) {
    85             // These are the polynomial coefficients
    86             coeff = optionItem->data.V; // The coefficient vector
    87             if (coeff->type.type != PS_TYPE_F64) {
    88                 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64);
    89                 coeff = temp;
    90             }
    91             // Polynomial correction
    92             psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1,
    93                                                              PS_POLYNOMIAL_ORD);
    94             psFree(correction->coeff);
    95             correction->coeff = psMemIncrRefCounter(coeff->data.F64);
    96             (void)pmNonLinearityPolynomial(inputReadout, correction);
    97             psFree(coeff);
    98             psFree(correction);
     79
     80        switch (optionItem->type) {
     81          case PS_DATA_VECTOR:
     82            ppDetrendNonLinearPolynomial (input, optionItem);
    9983            return true;
    100         }
    101         if (optionItem->type == PS_DATA_STRING) {
    102             // This is a filename
    103             psString tableName = optionItem->data.V; // The filename
    104             psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0);
    105             int numLines = 0; // Number of lines read from table
    106             if ((numLines = psLookupTableRead(table)) <= 0) {
    107                 psErrorStackPrint(stderr, "Unable to read non-linearity "
    108                                   "correction file %s --- ignored\n",
    109                                   tableName);
    110                 return false;
    111             }
    112 #ifdef PRODUCTION
    113             (void)pmNonLinearityLookup(inputReadout, table);
    114 #else
    115             printf("XXX: Non-linearity correction from lookup table not "
    116                    "yet implemented.\n");
    117 #endif
    118             psFree(table);
     84          case PS_DATA_STRING:
     85            ppDetrendNonLinearLookup (input, optionItem);
    11986            return true;
     87          default:
     88            psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
     89                     "desired but unable to interpret NONLIN.DATA for %s"
     90                     " --- ignored\n", conceptValue);
     91            return false;
    12092        }
    121 
    122         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "
    123                  "desired but unable to interpret NONLIN.DATA for %s"
    124                  " --- ignored\n", conceptValue);
    125         return false;
    126  
    12793      default:
    128         psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but "
    129                  "NONLIN.DATA is of invalid type --- ignored.\n");
     94        psAbort("phase2", "Invalid options->nonLinearType");
    13095    }
    131     return false;
     96    return true;
    13297}
    13398
Note: See TracChangeset for help on using the changeset viewer.