by tomk80 » Mon Jul 09, 2018 10:53 am
I contacted Bryan Stiles (JPL engineer who works on QuikSCAT processing) and he sent me the following Matlab script for loading the various flags. Note that flags are stored in the variables "flags" and "eflags." The version 4.0 dataset features two new flags:
"flags" bit 6, which marks wind vector cells that are likely corrupted (roughly 3% of total pts)
"eflags" bit 12, which marks wind vector cells that are possibly corrupted (roughly 15% of total pts)
Utilizing the new bit 6 flag will include many wind observations in coastal areas that utilize the new coastal processing, and will also include more wind vector cells in rainy areas, so long as the rain impact is not too large.
By contrast, the new eflags bit 12 takes a more conservative approach in coastal areas and in rainy areas, i.e., flags many more observations.
Here is the script from Dr. Stiles:
function [meaning, data]=read_qs_bit(filename,varname,bit_number);
%% routine for reading QuikSCAT version 4 L2B wind vector product file
%% This documents how to read wind vector quality bits from a QuikSCAT version 4 netcdf file
%% with full checking to make sure you read the right bit
%% without the checking all you need is three lines
%%
%% mask = 2^bit_number;
%% var=ncread(filename,varname);
%% data=bitand(var,mask)/mask;
%%%
%%%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%%% function l2b=read_qs_bit(filename,varname,bit_number);
%%% INPUTS
%%%% filename = the name of the QuikSCAT version 4 netcdf file
%%%% varname = the short name ('flags' or 'eflags') of the desired wind vector quality flag variable
%%%% bit_number = the number bewten 0 and 15 inclusive or the desired bit from the flag
%%% OUTPUTS
%%%% meaning = the string from the file metadata that describes the requested bit
%%%% data = the data from the desired bit, an array of ones and zeros for each wind vector cell
%%%% Example
%%%% [meaning,data]=read_qs_bit('qs_l2b_23715_v4.0_200401080705.nc','flags',6) yields
%%%!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
%%% Check to make sure varname is 'flags' or 'eflags'
if(~strcmp(varname,'flags') & ~strcmp(varname,'eflags'))
meaning='Bad varname input to read_qs_bit';
data=[];
return;
end
%%% Check to make sure bit_number is between an integer 0 and 15
if( bit_number<0 | bit_number>15 | round(bit_number)~=bit_number)
meaning='Bad bit_number input to read_qs_bit';
data=[];
return;
end
%%% Check to make sure filename exists
if(~exist(filename,'file'))
meaning='Bad filename input to read_qs_bit';
data=[];
return;
end
%%% read desired flag variable
var=ncread(filename,varname);
%%% determine desired bit mask
mask=2^bit_number;
%%% read and parse flag meanings and flag masks attributes from variable
meaning_str=ncreadatt(filename,varname,'flag_meanings');
mask_str=ncreadatt(filename,varname,'flag_masks');
remain=meaning_str;
meanings={};
masks=[];
while(~isempty(remain))
[token,remain] = strtok(remain, ' ');
meanings{end+1}=token;
end
remain=mask_str;
while(~isempty(remain))
[token,remain] = strtok(remain, 's, ');
masks = [masks , str2num(token)];
end
%%% find mask in list of assigned masks
i=find(mask==masks);
%%% if desired bit mask is not in the list return meaning='undefined_bit' and data=[];
if (isempty(i))
meaning='undefined_bit';
data=[];
return;
%%% otherwise select the right meaning for the desired bit mask
else
meaning=char(meanings{i});
end
%%% get data from bit
data=bitand(var,mask)/mask;
%%% end of function
return;