IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18598


Ignore:
Timestamp:
Jul 17, 2008, 10:37:20 AM (18 years ago)
Author:
Paul Price
Message:

Adding const, assertions, cleaning up.

Location:
trunk/psModules/src/config
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfigMask.c

    r18554 r18598  
    1111psMaskType pmConfigMaskGet(const char *masks, const pmConfig *config)
    1212{
    13     assert (config);
     13    psAssert(config, "Require configuration");
    1414    PS_ASSERT_STRING_NON_EMPTY(masks, 0);
    1515
     
    4242bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue)
    4343{
    44     assert (config);
     44    psAssert(config, "Require configuration");
    4545    PS_ASSERT_STRING_NON_EMPTY(maskName, false);
    4646
     
    5858// replace the named masks in the recipe with values in the header:
    5959// replace only the names in the header in the recipe
    60 bool pmConfigMaskReadHeader (pmConfig *config, psMetadata *header) {
     60bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header)
     61{
     62    PS_ASSERT_PTR_NON_NULL(config, false);
     63    PS_ASSERT_METADATA_NON_NULL(header, false);
    6164
    6265    bool status = false;
     
    7881    for (int i = 0; i < nMask; i++) {
    7982
    80         snprintf (namekey,  64, "MSKNAM%02d", i);
    81         snprintf (valuekey, 64, "MSKVAL%02d", i);
    82 
    83         char *name = psMetadataLookupStr (&status, header, namekey);
    84         psU8 bit = psMetadataLookupU8 (&status, header, valuekey);
    85 
    86         // XXX validate that bit is a 2^n value?
    87 
    88         psMetadataItem *item = psMetadataLookup (header, name);
    89         if (!item) {
    90             psWarning("mask recipe entry %s not in recipe\n", name);
    91             psMetadataAddU8 (recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit);
    92         } else {
    93             item->data.U8 = bit;
    94         }
    95     }
    96    
     83        snprintf (namekey,  64, "MSKNAM%02d", i);
     84        snprintf (valuekey, 64, "MSKVAL%02d", i);
     85
     86        char *name = psMetadataLookupStr (&status, header, namekey);
     87        psU8 bit = psMetadataLookupU8 (&status, header, valuekey);
     88
     89        // XXX validate that bit is a 2^n value?
     90
     91        psMetadataItem *item = psMetadataLookup (header, name);
     92        if (!item) {
     93            psWarning("mask recipe entry %s not in recipe\n", name);
     94            psMetadataAddU8 (recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit);
     95        } else {
     96            item->data.U8 = bit;
     97        }
     98    }
     99
    97100    return true;
    98101}
    99102
    100103// write the named mask bits to the header
    101 bool pmConfigMaskWriteHeader (pmConfig *config, psMetadata *header) {
     104bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header)
     105{
     106    PS_ASSERT_PTR_NON_NULL(config, false);
     107    PS_ASSERT_METADATA_NON_NULL(header, false);
    102108
    103109    char namekey[80];
     
    117123    while ((item = psMetadataGetAndIncrement(iter))) {
    118124
    119         if (item->type != PS_DATA_U8) {
    120             psWarning("mask recipe entry %s is not a bit value\n", item->name);
    121             continue;
    122         }
    123 
    124         snprintf (namekey,  64, "MSKNAM%02d", nMask);
    125         snprintf (valuekey, 64, "MSKVAL%02d", nMask);
    126 
    127         psMetadataAddStr (header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
    128         psMetadataAddU8 (header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.U8);
    129         nMask ++;
    130     }
    131    
     125        if (item->type != PS_DATA_U8) {
     126            psWarning("mask recipe entry %s is not a bit value\n", item->name);
     127            continue;
     128        }
     129
     130        snprintf (namekey,  64, "MSKNAM%02d", nMask);
     131        snprintf (valuekey, 64, "MSKVAL%02d", nMask);
     132
     133        psMetadataAddStr (header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);
     134        psMetadataAddU8 (header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.U8);
     135        nMask ++;
     136    }
     137
    132138    psMetadataAddS32 (header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask);
    133139    return true;
     
    135141
    136142// examine named mask values in mask recipe and set the bits for maskValue and markValue
    137 // this function sets an appropriate value for the following required named mask concepts: 
     143// this function sets an appropriate value for the following required named mask concepts:
    138144// FLAT (used to mark out-of-range corrections in the flat-fielding)
    139145// BLANK (used to mark non-existent pixels)
     
    143149// If these latter do not exist, the value 0x01 is used.
    144150// The values actually used for these names are written back to the config file
    145 bool pmConfigMaskSetBits (psMaskType *outMaskValue, psMaskType *outMarkValue, pmConfig *config) {
     151bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config)
     152{
     153    PS_ASSERT_PTR_NON_NULL(config, false);
    146154
    147155    psMaskType maskValue = 0;
    148156
    149157    // mask for generic detector defect
    150     psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config); 
     158    psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config);
    151159    maskValue |= detectorMask;
    152160
     
    156164
    157165    // mask for non-linear flat regions (default to DETECTOR if not defined)
    158     psMaskType flatMask = pmConfigMaskGet("FLAT", config); 
     166    psMaskType flatMask = pmConfigMaskGet("FLAT", config);
    159167    if (!flatMask) {
    160         flatMask = detectorMask;
    161         pmConfigMaskSet (config, "FLAT", flatMask);
     168        flatMask = detectorMask;
     169        pmConfigMaskSet (config, "FLAT", flatMask);
    162170    }
    163171    if (!flatMask) {
    164         flatMask = 0x01;
    165         pmConfigMaskSet (config, "FLAT", flatMask);
     172        flatMask = 0x01;
     173        pmConfigMaskSet (config, "FLAT", flatMask);
    166174    }
    167175    maskValue |= flatMask;
    168176
    169177    // mask for non-existent data  (default to DETECTOR if not defined)
    170     psMaskType blankMask = pmConfigMaskGet("BLANK", config); 
     178    psMaskType blankMask = pmConfigMaskGet("BLANK", config);
    171179    if (!blankMask) {
    172         blankMask = detectorMask;
    173         pmConfigMaskSet (config, "BLANK", blankMask);
     180        blankMask = detectorMask;
     181        pmConfigMaskSet (config, "BLANK", blankMask);
    174182    }
    175183    if (!blankMask) {
    176         blankMask = 0x01;
    177         pmConfigMaskSet (config, "BLANK", blankMask);
     184        blankMask = 0x01;
     185        pmConfigMaskSet (config, "BLANK", blankMask);
    178186    }
    179187    maskValue |= blankMask;
     
    186194    psMaskType satMask = pmConfigMaskGet("SAT", config);
    187195    if (!satMask) {
    188         satMask = rangeMask;
    189         pmConfigMaskSet (config, "SAT", satMask);
     196        satMask = rangeMask;
     197        pmConfigMaskSet (config, "SAT", satMask);
    190198    }
    191199    if (!satMask) {
    192         satMask = 0x01;
    193         pmConfigMaskSet (config, "SAT", satMask);
     200        satMask = 0x01;
     201        pmConfigMaskSet (config, "SAT", satMask);
    194202    }
    195203    maskValue |= satMask;
    196    
     204
    197205    // mask for below-range data  (default to RANGE if not defined)
    198206    psMaskType badMask = pmConfigMaskGet("BAD", config);
    199207    if (!badMask) {
    200         badMask = rangeMask;
    201         pmConfigMaskSet (config, "BAD", badMask);
     208        badMask = rangeMask;
     209        pmConfigMaskSet (config, "BAD", badMask);
    202210    }
    203211    if (!badMask) {
    204         badMask = 0x01;
    205         pmConfigMaskSet (config, "BAD", badMask);
     212        badMask = 0x01;
     213        pmConfigMaskSet (config, "BAD", badMask);
    206214    }
    207215    maskValue |= badMask;
     
    219227    int nBits = sizeof(psMaskType) * 8;
    220228    for (int i = 0; !markValue && (i < nBits); i++) {
    221         if (maskValue & markValue) {
    222             markValue >>= 1;
    223         } else {
    224             markValue = markValue;
    225         }
     229        if (maskValue & markValue) {
     230            markValue >>= 1;
     231        } else {
     232            markValue = markValue;
     233        }
    226234    }
    227235    if (!markValue) {
    228         psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
    229         return false;
    230     }
     236        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
     237        return false;
     238    }
     239
    231240
    232241    // update the config table
    233     pmConfigMaskSet (config, "MASK.VALUE", maskValue);
    234     pmConfigMaskSet (config, "MARK.VALUE", markValue);
    235 
    236     *outMaskValue = maskValue;
    237     *outMarkValue = markValue;
    238 
    239     return true;
    240 }
     242    pmConfigMaskSet(config, "MASK.VALUE", maskValue);
     243    pmConfigMaskSet(config, "MARK.VALUE", markValue);
     244
     245    if (outMaskValue) {
     246        *outMaskValue = maskValue;
     247    }
     248    if (outMarkValue) {
     249        *outMarkValue = markValue;
     250    }
     251
     252    return true;
     253}
  • trunk/psModules/src/config/pmConfigMask.h

    r18554 r18598  
    44 *  @author Paul Price, IfA
    55 *
    6  *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2008-07-15 20:25:00 $
     6 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2008-07-17 20:37:20 $
    88 *  Copyright 2007 Institute for Astronomy, University of Hawaii
    99 */
     
    2424/// The mask values are derived from the MASKS recipe
    2525psMaskType pmConfigMaskGet(const char *masks, ///< List of symbolic names, space/comma delimited
    26                         const pmConfig *config ///< Configuration
    27                         );
     26                           const pmConfig *config ///< Configuration
     27    );
    2828
    2929bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue);
     
    3131// replace the named masks in the recipe with values in the header:
    3232// replace only the names in the header in the recipe
    33 bool pmConfigMaskReadHeader (pmConfig *config, psMetadata *header);
     33bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header);
    3434
    3535// write the named mask bits to the header
    36 bool pmConfigMaskWriteHeader (pmConfig *config, psMetadata *header);
     36bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header);
    3737
    38 bool pmConfigMaskSetBits (psMaskType *outMaskValue, psMaskType *outMarkValue, pmConfig *config);
     38bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config);
    3939
    4040#endif
Note: See TracChangeset for help on using the changeset viewer.