function varargout = cloudMask(varargin)
% CLOUDMASK M-file for cloudMask.fig
%      CLOUDMASK, by itself, creates a new CLOUDMASK or raises the existing
%      singleton*.
%
%      H = CLOUDMASK returns the handle to a new CLOUDMASK or the handle to
%      the existing singleton*.
%
%      CLOUDMASK('Property','Value',...) creates a new CLOUDMASK using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to cloudMask_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      CLOUDMASK('CALLBACK') and CLOUDMASK('CALLBACK',hObject,...) call the
%      local function named CALLBACK in CLOUDMASK.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help cloudMask

% Last Modified by GUIDE v2.5 28-Jan-2003 12:08:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @cloudMask_OpeningFcn, ...
                   'gui_OutputFcn',  @cloudMask_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before cloudMask is made visible.
function cloudMask_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for cloudMask
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes cloudMask wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = cloudMask_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --------------------------------------------------------------------
function plot_menu_Callback(hObject, eventdata, handles)
% hObject    handle to bit_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function load_menu_Callback(hObject, eventdata, handles)
% hObject    handle to load_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

pathName = '/home/fsun/data/06Sept2002/';
[fileName, pathName]=uigetfile('../Data/*35*.hdf','Cloud Mask File', pathName);

[temp,rem]=strtok(fileName,'.');
[yearday,rem]=strtok(rem,'.');
yr=yearday(length(yearday)-6:length(yearday)-3);
dy=yearday(length(yearday)-2:length(yearday));
hr=strtok(rem,'.');
plotString = sprintf('MODIS %s %s %s UTC',yr,dy,hr);
plotString
		
%% READ IN CLOUD MASK, ONLY BYTE 1 
disp('Reading in byte 1 of the cloud mask data...');
cloudmask = readModisCloudMask([pathName fileName], 1);

%% DISPLAY CLOUD MASK (BYTE 1, BITS 1 & 2) AS X,Y IMAGE 
plotCloudMaskSingleBit(cloudmask, [1 1], plotString, gcf)
