function BS_Albedo
%%  This m-file converts spectral MODIS white-sky and black-sky albedo
% (Product MCD43A3) into spectral blue sky albedo with a supplied matrix a
% of diffuse fraction of skylight

%-------------------------------------------------------------------------%
%% Program Display
display('************************************************************');
display(' ');
display('Blue Sky Albedo Calculator from MODIS data');
display(' Version 1.0 ');
display('Specify the variables for each of the Bands');
display(' ');

%-------------------------------------------------------------------------%
%% Import Black Sky Spectral Bands
prompt = {'Enter BSA Band 1 :', 'BSA Band 2:', 'BSA Band 3:', 'BSA Band 3:',...
    'BSA Band 4:', 'BSA Band 6:', 'BSA Band 7:', 'BSA Vis:', 'BSA NIR:', 'BSA Short:'};
title = 'Specify Spectral Variables';
lines = 1;
def = {'Albedo_BSA_Band1', 'Albedo_BSA_Band2', 'Albedo_BSA_Band3', ...
    'Albedo_BSA_Band4', 'Albedo_BSA_Band5', 'Albedo_BSA_Band6', 'Albedo_BSA_Band7',...
    'Albedo_BSA_vis', 'Albedo_BSA_nir', 'Albedo_BSA_shortwave'};
answer = inputdlg(prompt,title,lines,def);

BSA= cell(10,1);
for n = 1:1:10
    BSA{n}= evalin ('caller', answer{n});
end

%-------------------------------------------------------------------------%
%% Import White Sky Spectral Bands
prompt = {'Enter WSA Band 1 :', 'WSA Band 2:', 'WSA Band 3:', 'WSA Band 3:',...
    'WSA Band 4:', 'WSA Band 6:', 'WSA Band 7:', 'WSA Vis:', 'WSA NIR:', ...
    'WSA Short:', 'Diffuse Fraction of Sunlight'};
title = 'Specify Spectral Variables';
lines = 1;
def = {'Albedo_WSA_Band1', 'Albedo_WSA_Band2', 'Albedo_WSA_Band3', ...
    'Albedo_WSA_Band4', 'Albedo_WSA_Band5', 'Albedo_WSA_Band6', 'Albedo_WSA_Band7',...
    'Albedo_WSA_vis', 'Albedo_WSA_nir', 'Albedo_WSA_shortwave', 'Skyl'};
answer = inputdlg(prompt,title,lines,def);

WSA= cell(10,1);
for n = 1:1:10
    WSA{n}= evalin ('caller', answer{n});
end

Skyl = evalin('caller', answer{11});


%-------------------------------------------------------------------------%
%% Evaluate Spectral Blue sky albedo
BlueS_A = cell(10,1);
for n = 1:1:10
   BlueS_A{n} = WSA{1}*Skyl(n) +  (1-Skyl(n))* BSA{n};
end


%-------------------------------------------------------------------------%   
%% Export to workspace
assignin('base','BlueS_Albedo', BlueS_A);

%Notify user of completion
display('=> BLueSky albedo exported to workspace.');
display(' ');


%% %Take user input, assign to local variables
% BSA1 = evalin('caller', answer{1});
% BSA2 = evalin('caller',answer{2});
% BSA3 = evalin('caller', answer{3});
% BSA4 = evalin('caller', answer{4});
% BSA5 = evalin('caller', answer{5});
% BSA6 = evalin('caller', answer{6});
% BSA7 = evalin('caller', answer{7});
% BSAVis = evalin('caller', answer{8});
% BSANir = evalin('caller', answer{9});
% BSASh = evalin('caller', answer{10});
% 
% WSA1 = evalin('caller', answer{1});
% WSA2 = evalin('caller',answer{2});
% WSA3 = evalin('caller', answer{3});
% WSA4 = evalin('caller', answer{4});
% WSA5 = evalin('caller', answer{5});
% WSA6 = evalin('caller', answer{6});
% WSA7 = evalin('caller', answer{7});
% WSAVis = evalin('caller', answer{8});
% WSANir = evalin('caller', answer{9});
% WSASh = evalin('caller', answer{10});
