To use the tests first decide which tests are relevant to the analysis and are to be used for masking data from the analysis. For this example, all tests with an assessment of "Bad" are chosen, except for test 4 which is not in use. The tests used are [1, 2, 3, 5]. Test 6 is described as "Indeterminate" and will not be part of the mask applied to the data.
For this example, assume the data and companion QC fields are ten element arrays and equal to the values
Create an array of tests numbers to use in the mask to exclude values
tests = [1, 2, 3, 5]
Create a single mask value summarizing all the tests from the 'tests' array.
mask = TOTAL(ISHFT(1L,tests-1), /PRESERVE_TYPE) ;
Search the companion QC field for at least one of the tests to be tripped. The result of the search is an array of indexes where at leat one of the 'tests' has been set as true. If none of the tests were tripped a single !NULL value is returned.
index = WHERE(qc_direct_normal_broadband AND mask, /NULL)print, index 0 1 2 3 8
Replace direct normal broadband data values where the companion QC field indicated a test was tripped to the IEEE Not A Number value to exclude from further analysis. If index is equal !NULL the data array is unchanged.
direct_normal_broadband[index] = !Values.F_NANprint, direct_normal_broadband NaN NaN NaN NaN 11.0 20.0 50.0 110.0 NaN 134.0
There you go, four lines of code and you're done. If a different set of tests were desired the only part that needs to change is the 'tests' array, the rest of the code is independent of datastream or analysis. This also works with multi-dimensional data variables.
If you're interested in a description using the bits directly you can find a description here