
function spectral2broadband
%%  This m-file converts spectral MODIS albedo data, converts it into 
%Broad Band albedo, and exports the resulting matrix back into the work
%place.  It is assumed that the input variables are already in the
%workspace.
%Version 1.0
%Author: Bruce Corliss

%% Algorithm ----------------------------------------------------------
%     Liang et al weighted corefficients visible to broadband
%
% Band ----------------  Wavelength  ----------------------------------
% Blue = 0.4364       % 0.459- 0.479
% Green = 0.5366      % 0.545- 0.565
% Red = 0.3265        % 0.620- 0.670
% NIR = 0             % 1.230- 1.250
% LW1 = 0             % 1.230- 1.250
% LW2 = 0             % 1.628- 1.652
% LW3 = 0             % 2.105- 2.115


display('************************************************************');
display(' ');
display('Spectral Albedo (Visible) to Broadband Converter for MODIS data');
display(' Version 1.0 ');
display('Specify the variables for each of the Bands');
display(' ');

% Produce prompt for user input
prompt = {'Enter Band 1   (Red, 0.620- 0.670):',...
 'Enter Band 2   (NIR, 0.841- 0.876):', 'Enter Band 3   (Blue, 0.459- 0.479):',...
 'Enter Band 4   (Green, 0.545- 0.565):', 'Enter Band 5   (1.2, 1.230- 1.250);',...
 'Enter Band 6   (1.6, 1.628- 1.652):', 'Enter Band 7   (2.1, 2.105- 2.155):'};
title = 'Specify Spectral Variables';
lines = 1;
def = {'Red','NIR', 'Blue', 'Green', 'LW1', 'LW2', 'LW3'};
answer = inputdlg(prompt,title,lines,def);

%Take user input, assign to local variables
Red = evalin('caller', answer{1});
NIR = evalin('caller',answer{2});
Blue = evalin('caller', answer{3});
Green = evalin('caller', answer{4});
LW1 = evalin('caller', answer{5});
LW2 = evalin('caller', answer{6});
LW3 = evalin('caller', answer{7});

%Evaluate Broadband albedo
BroadBand_a = 0.4364.*Blue + 0.2366.*Green + 0.3265.*Red +...
               0.*NIR + 0.*LW1 + 0.*LW2 + 0.*LW3;
     
%Export to workspace
assignin('base','BroadBand_a',BroadBand_a);

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