Technical Support for Environmental Data Collection Software
Email This Article
Your Name: *  
Your Email: *
Friend's Email: *
  *Required Field
Verification Code: *

Setting CWMS Quality Flags in Output Values

  • Author: Michael Maloney
  • Create Time: 02/21/2013 10:38:27
  • Last Update Time: 02/21/2013 10:38:53
The CCP infrastructure uses a similar mechanism as CWMS to store various flags about every value in the database. A 32 bit integer is divided into several bit-fields. Each bit has meaning.

Note that the flag values (bit positions within the 32-bit integer) are not the same in CCP as they are when stored in the CWMS 'quality' value in the database. Some of the bits that are reserved for use by the infrastructure.The CCP internally uses some of these bits to control its own behavior. You must be careful to not change these reserved flags.

In your algorithm code you can set CWMS Quality Flags with the following methods:

   setFlagBits(outputParm, flags2set);
   clearFlagBits(outputParm, flags2clear);

In both cases you supply an integer mask specifying which bits are to be affected. "set" means to change the bit to a 1. "clear" means to change it to a zero.

Attached to this article is the source code for the class Please use the masks and bit values in this file when calling the set/clear methods.

In the imports section of your algorithm:
   import decodes.cwms.CwmsFlags;

Now, suppose you want to set the SCREENED and VALIDITY_OKAY bits for an output parameter called "result". You would do this:

    inf flags2set = CwmsFlags.SCREENED | CwmsFlags.VALIDITY_OKAY;
    setFlagBits(result, flags2set);

Suppose you want to set the output flags to the same values as the validity results from input flags. First you need to clear the output flags using a mask, retrieve the input flags, apply the mask to the input flags, and then set the output:

if you want to copy just the results of validation, you could do this:

    int flagMask = CwmsFlags.SCREENED_MASK | CwmsFlags.VALIDITY_MASK;
    clearFlagBits(result, flagMask);
    int flags2set = getInputFlagBits("input") & flagMask;
    setFlagBits(result, flags2set);

Or to copy all flags not reserved by the infrastructure:

    int flagMask = ~(CwmsFlags.RESERVED_4_COMP | CwmsFlags.RESERVED_4_VAR);
    clearFlagBits(result, flagMask);
    int flags2set = getInputFlagBits("input") & flagMask;
    setFlagBits(result, flags2set);