function [X,Y,LOK]=buildBigXY21(il,nodes,n,isto,iAll)
% function [X,Y,LOK]=buildBigXY21(il,nodes,n,isto,iAll)
%
% to build LUT input/output (LOG-RADIANCES,Q,U) for bigRun25
% built from buildBigXY20.m
%
% INPUT:
% il:       channel number [1, ..8]
% nodes:    altitude node indices [f.i. 1:2:61]
% n:        number of samplings
% isto:     1: I 2: Q 3: U
% iAll:     if ==1, no screening on LOK (to be performed outside)
%
% OUTPUT:
% if "m" = number of valid samples
% X(m,35)   NN inputs
% Y(m,35)   NN outputs
% LOK(n,8)  logical array of valid samples
%
% DiF / v1.0 / 04-Oct-2021
%---------------------------------------------------------------------

sq=@(x) squeeze(x);

ozDataFile='ozSet12.mat'; % source of ozone profiles
airDataFile='airSet1.mat'; % source of air profiles

load(ozDataFile,'A'); % load PCA coef of ozone profiles
load(airDataFile,'Aair'); % load PCA coef of air profiles

load('bigRun25.mat'); % output of bigRun24
load('br25Ana2.mat','LOKI','LOKQ','LOKU'); % just to get the inliers screened by br24Ana2

lz=1:61;

switch isto
    case 1
        LOK=LOKI;
    case 2
        LOK=LOKQ;
    case 3
        LOK=LOKU;
end

if iAll==0
    lok1=find(LOK(:,il));
    if n>length(lok1)
        n=length(lok1);
    end
    loks=lok1(1:n); % lok1 subset
else
    loks=1:n; 
end

npcOz=20;

X=[A(loks,1:npcOz) CAE(loks,:) Aair(loks,:) REF(loks) SIG(loks) SZA(loks) SAA(loks) ALB(loks)];
switch isto
    case 1
        Y=log(sq(BIGI(loks,nodes,il)));
    case 2
        Y=sq(BIGQ(loks,nodes,il));
    case 3
        Y=sq(BIGU(loks,nodes,il));
end

