IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18605


Ignore:
Timestamp:
Jul 17, 2008, 2:34:16 PM (18 years ago)
Author:
Paul Price
Message:

Adding some traps for when reading mask values from multiple sources
that don't match.

File:
1 edited

Legend:

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

    r18604 r18605  
    6464
    6565    bool status = false;
    66     char namekey[80];
    67     char valuekey[80];
    68 
    69     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
    70     if (!recipe) {
    71         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
    72         return false;
     66
     67    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
     68    if (!recipe) {
     69        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
     70        return false;
     71    }
     72
     73    // MASK.VALUE and MARK.VALUE aren't usually set in the recipe, but may be set in the header: create fake
     74    // versions so that it won't complain later
     75    if (!psMetadataLookup(recipe, "MASK.VALUE")) {
     76        psMetadataAddU8(recipe, PS_LIST_TAIL, "MASK.VALUE", 0, "Bits to mask", 0);
     77    }
     78    if (!psMetadataLookup(recipe, "MARK.VALUE")) {
     79        psMetadataAddU8(recipe, PS_LIST_TAIL, "MARK.VALUE", 0, "Bits for marking", 0);
    7380    }
    7481
     
    7986    }
    8087
     88    char namekey[80];                   // Keyword name for symbolic name of mask entry
     89    char valuekey[80];                  // Keyword name for value of mask entry
    8190    for (int i = 0; i < nMask; i++) {
    82 
    8391        snprintf(namekey,  64, "MSKNAM%02d", i);
    8492        snprintf(valuekey, 64, "MSKVAL%02d", i);
    8593
    8694        char *name = psMetadataLookupStr(&status, header, namekey);
     95        if (!status || !name) {
     96            psWarning("Unable to find header keyword %s when parsing mask", namekey);
     97            continue;
     98        }
    8799        psU8 bit = psMetadataLookupU8(&status, header, valuekey);
     100        if (!status) {
     101            psWarning("Unable to find header keyword %s when parsing mask", namekey);
     102            continue;
     103        }
    88104
    89105        // XXX validate that bit is a 2^n value?
    90106
    91         psMetadataItem *item = psMetadataLookup(recipe, name);
     107        psString nameAlready = NULL;    // Name of key with ".ALREADY" added
     108        psStringAppend(&nameAlready, "%s.ALREADY", name);
     109        bool already = psMetadataLookupBool(&status, recipe, nameAlready); // Already read this one?
     110
     111        psMetadataItem *item = psMetadataLookup(recipe, name); // Item in recipe with current value
     112        if (item->type != PS_TYPE_MASK) {
     113            psWarning("Mask recipe entry is not of a mask type (%x)", item->type);
     114            item->type = PS_TYPE_MASK;
     115        }
     116
     117        if (already) {
     118            if (item && item->data.U8 != bit) {
     119                psWarning("New mask recipe entry doesn't match previously loaded entry: %x vs %x",
     120                          bit, item->data.U8);
     121            }
     122        } else {
     123            psMetadataAddBool(recipe, PS_LIST_TAIL, nameAlready, 0, "Already read this mask value", true);
     124        }
     125
    92126        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);
     127            psWarning("Mask recipe entry %s not in recipe\n", name);
     128            psMetadataAddU8(recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit);
    95129        } else {
    96130            item->data.U8 = bit;
    97131        }
    98     }
     132
     133        psFree(nameAlready);
     134    }
     135
    99136
    100137    return true;
Note: See TracChangeset for help on using the changeset viewer.