-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecodeCTMmodels.m
More file actions
73 lines (68 loc) · 2.25 KB
/
decodeCTMmodels.m
File metadata and controls
73 lines (68 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [models, modelIndices] = decodeCTMmodels(bitmask_hex)
% decodeCTMmodels - Decode CTM model bitmask to list of model names
%
% Decodes a hexadecimal bitmask into the list of CTM models it represents.
% This is the inverse operation of the bitmask encoding in generateBMEcode.
%
% SYNTAX:
% [models, modelIndices] = decodeCTMmodels(bitmask_hex)
%
% INPUT:
% bitmask_hex - String, hexadecimal representation of bitmask (e.g., '01', '23', '3F')
% OR numeric bitmask value (e.g., 1, 35, 63)
%
% OUTPUT:
% models - Cell array of model names included in the bitmask
% modelIndices - Numeric array of model bit positions (0-5)
%
% MODEL ENCODING:
% Bit Position Value (hex) Model Name
% 0 01 MERRA2-GMI
% 1 02 M3fusion
% 2 04 OMI-MLS
% 3 08 IASI-GOME2
% 4 10 UKML
% 5 20 NJML
% 6 40 CrIS
%
% EXAMPLES:
% models = decodeCTMmodels('01')
% % → {'MERRA2-GMI'}
%
% models = decodeCTMmodels('03')
% % → {'MERRA2-GMI', 'M3fusion'}
%
% models = decodeCTMmodels('23')
% % → {'MERRA2-GMI', 'M3fusion', 'IASI-GOME2'}
%
% models = decodeCTMmodels('3F')
% % → {'MERRA2-GMI', 'M3fusion', 'OMI-MLS', 'IASI-GOME2', 'UKML', 'NJML'}
%
% [models, indices] = decodeCTMmodels(35) % 35 = 0x23
% % → models = {'MERRA2-GMI', 'M3fusion', 'IASI-GOME2'}
% % → indices = [0, 1, 3]
% Convert hex string to numeric if needed
if ischar(bitmask_hex) || isstring(bitmask_hex)
bitmask = hex2dec(bitmask_hex);
else
bitmask = bitmask_hex;
end
% Model names and their bit positions (must match generateBMEcode)
modelNames = {'MERRA2-GMI', 'M3fusion', 'OMI-MLS', 'IASI-GOME2', 'UKML', 'NJML', 'CrIS'};
modelBits = [1, 2, 4, 8, 16, 32, 64]; % 2^0, 2^1, 2^2, 2^3, 2^4, 2^5, 2^6
% Decode bitmask
models = {};
modelIndices = [];
for i = 1:length(modelNames)
if bitand(bitmask, modelBits(i)) ~= 0
models{end+1} = modelNames{i};
modelIndices(end+1) = i-1; % 0-indexed bit position
end
end
% Convert to column cell array if needed for consistency
if ~isempty(models) && size(models, 1) == 1
models = models';
else
models = {'obs. only'};
end
end