% GUIlistfiles
% List MODIS HDF files
% function for the MODIS GUI
% Copyright by Jasmine S Nahorniak, Oregon State University. 
% Feb 23 2000

% GUIlistfiles
% Function for the MODIS GUI
% Jasmine S Bartlett
% Mar 3 2000


function GUIlistfiles

GUIbutton('Pushbutton1','WORKING','on');

% get the path (input by user)
pathh=findobj('Tag','EditText4');
path=get(pathh,'String');

% find the files in that directory
direc=dir(path);
dircell=struct2cell(direc);
files=dircell(1,3:end);
charfiles=char(files);
sortchar=sortrows(charfiles);
sortfiles=cellstr(sortchar);


% list the files in the filelist box
filesh=findobj('Tag','Listbox2');
set(filesh,'Value',1);
set(filesh,'String',sortfiles);
newfile=char(sortfiles{1});

% turn off load button if first file is a directory
sizedirec=size(dircell);
if sizedirec(2)>2,
   isdirec=cat(1,dircell{4,3});
else
   isdirec=1;  % empty directory so don't turn load button on
end
if isdirec==1, 
  set(findobj('Tag','Pushbutton1'),'Enable','off');
else
  set(findobj('Tag','Pushbutton1'),'Enable','on');
  % set file type based on filename
 if length(newfile)>4,  % has a long enough filename
  if newfile(3)~='D',  % is a level 3 mapped file
     if (newfile(5)=='M' | newfile(5)=='N' | newfile(5)=='S'),
        set(findobj('Tag','PopupMenu2'),'Value',1);
     elseif (newfile(5)=='Q')
        set(findobj('Tag','PopupMenu2'),'Value',3);
     else
        set(findobj('Tag','PopupMenu2'),'Value',2);
     end
  elseif (newfile(1:5)=='MODOC' | newfile(1:5)=='MOD28' | newfile(1:5)=='MOD03'), % is a level 2 or 1 file
     set(findobj('Tag','PopupMenu2'),'Value',4);     
  end
 end
end

GUIbutton('Pushbutton1','GO','off');
