
clear 
clc

addpath('/ships19/hercules/mino/6SLUT/ABI_6sV2.1.2/6SV2.1_AHI_core/output/')
load Apparent_Refl_B6_abi_Dv212.mat
load Aer_OD_total_B6_abi_Dv212.mat

% filename='AHI_Ocean_Aerosol_LUT_v01.hdf';
%10    15    21     4     8     9
%*********************************************************************
SZA=[0:12:48,54:6:78];
VZA=0:6:84;
RAZ=[0:12:168,170:2:180];
AOT=[0,0.1,0.3,0.5,1.0,2.0,3.0,5.0];
WS=[2,6,10,14];
% AOT_total=hdfread(filename,'Aer_AOT_total_ocean');
Refl=Apparent_Refl_B6_abi_Dv212;
%*********************************************************************
Apparent_Refl0(8,1)=9999;



szaa=0:2:78;

%LUT_data.Solar_Zenith_Angles.data		= ones(40,1,'uint8')*99; % max 90 degree
%LUT_data.Solar_Zenith_Angles.type		= 'uint8';
%LUT_data.Solar_Zenith_Angles.attribute	= 'Solar Zenith Angles (deg)';
%LUT_data.Solar_Zenith_Angles.scale_factor	= 1;
%LUT_data.Solar_Zenith_Angles.data=uint8(szaa');

vzaa=0:2:80;
%LUT_data.View_Zenith_Angles.data		= ones(41,1,'uint8')*99;
%LUT_data.View_Zenith_Angles.type		= 'uint8';
%LUT_data.View_Zenith_Angles.attribute	= 'View Zenith Angles (deg)';
%LUT_data.View_Zenith_Angles.scale_factor	= 1;
%LUT_data.View_Zenith_Angles.data=uint8(vzaa');

raza=[0:5:170,171,172,173,174,175,176,177,178,179,180];
%LUT_data.Relative_Azimuth_Angles.data		= ones(45,1,'uint8')*99;
%LUT_data.Relative_Azimuth_Angles.type		= 'uint8';
%LUT_data.Relative_Azimuth_Angles.attribute	= 'Relative Azimuth Angles (deg)';
%LUT_data.Relative_Azimuth_Angles.scale_factor	= 1;
%LUT_data.Relative_Azimuth_Angles.data=uint8(raza'); % relative azimuth angles

wsa=2:4:14;
%LUT_data.Wind_Speed.data		= ones(4,1,'uint8')*99;
%LUT_data.Wind_Speed.type		= 'uint8';
%LUT_data.Wind_Speed.attribute	= 'Wind Speed m/s';
%LUT_data.Wind_Speed.scale_factor	= 1;
%LUT_data.Wind_Speed.data=uint8(wsa'); % wind speed


AOT_uint16=uint16(AOT*100);
%LUT_data.AOT_at_550nm.data		= ones(8,1,'uint16')*99;
%LUT_data.AOT_at_550nm.type		= 'uint16';
%LUT_data.AOT_at_550nm.attribute	= 'AOT at 550nm';
%LUT_data.AOT_at_550nm.scale_factor= 0.01;
%LUT_data.AOT_at_550nm.data=uint16(AOT_uint16); % aot

AOT_band=uint16(squeeze(Aer_OD_total_B6_abi_Dv212(1,1,1,1,:,:)*10000));

LUT_Ocean_dust_data.AOT_at_xxnm.data		= ones(1,8,'uint16')*9999;
LUT_Ocean_dust_data.AOT_at_xxnm.type		= 'uint16';
LUT_Ocean_dust_data.AOT_at_xxnm.attribute	= 'AOT at xxnm for ocean dust aerosol models and 8 AOTs';
LUT_Ocean_dust_data.AOT_at_xxnm.scale_factor= 0.0001;
LUT_Ocean_dust_data.AOT_at_xxnm.data=uint16(AOT_band);


LUT_Ocean_dust_data.Apparent_Reflectance_ocean.data		= ones(40,41,45,8,4,'uint16')*9999;
LUT_Ocean_dust_data.Apparent_Reflectance_ocean.type		= 'uint16';
LUT_Ocean_dust_data.Apparent_Reflectance_ocean.attribute	= 'Apparent_Reflectance_ocean';
LUT_Ocean_dust_data.Apparent_Reflectance_ocean.scale_factor= 0.0001;% important change from version v04v to v05 


for sol=1:40
    for view=1:41
        dataview=[sol view] 
        for relazi=1:45
            
                for wsi=1:4

%Refl size 9     3     6     8    19    16    10
% %        10    15    21     4     8     9

Delta_azi_in=raza(relazi);
SenZen_in=vzaa(view);
SolZen_in=szaa(sol);
ws_in=wsa(wsi);


for model=1
    for opt=1:8
    
       
 Apparent_Refl_sq=squeeze(Refl(:,:,:,:,opt));

Apparent_Refl0(opt,model)=interpn(SZA,VZA,RAZ,WS,Apparent_Refl_sq,...
                              SolZen_in,SenZen_in,Delta_azi_in,ws_in);
    end
       

end

Apparent_Refl_1=Apparent_Refl0*10000;

LUT_Ocean_dust_data.Apparent_Reflectance_ocean.data(sol,view,relazi,:,wsi)=reshape(uint16(Apparent_Refl_1),[8,1]); % 
                end
            end
        end
    end

save LUT_data_OB6_abi_Dv212 LUT_Ocean_dust_data


