% GUIdeletedata
% Copyright by Jasmine S Nahorniak, Oregon State University. 
% Mar 2 2000

function [data,files,names,sizes,matrices,mins,maxs,region,filetype]= ...
          GUIdeletedata(olddata, oldfiles, oldnames, oldsizes, ...
                        oldmatrices, oldmins, oldmaxs,oldregion,oldfiletype);

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

% get the selected file 
choice=get(findobj('Tag','Listbox1'),'Value'); 

 
% get files to keep
numfiles=length(olddata);
goodfiles=[1:choice-1 choice+1:numfiles];

 % remove from existing arrays
   if length(olddata)>1,
     data=olddata(goodfiles);
     files=oldfiles(goodfiles);
     names=oldnames(goodfiles);
     matrices=oldmatrices(1,[1:end-1]);
     mins=oldmins(goodfiles);
     maxs=oldmaxs(goodfiles);
     region=oldregion(goodfiles);
     filetype=oldfiletype(goodfiles);
     sizes=oldsizes(goodfiles,:);
     for i=1:length(sizes(:,1)),
        sizescell{i}=['[' num2str(sizes(i,1)) ' x ' num2str(sizes(i,2)) ']'];
     end
     if choice>1,
       if choice==numfiles,
         newchoice=choice-1;
       else
         newchoice=choice;
       end
     else
       newchoice=1;
     end 
   else    
     data={};
     files={};
     names={};
     mins=[];
     maxs=[];
     matrices={};
     region={};
     filetype={};
     sizescell={};
     sizes=[];
     newchoice=1;
    
   % disable all appropriate buttons
   set(findobj('Tag','Pushbutton9'),'Enable','off');
   set(findobj('Tag','Pushbutton10'),'Enable','off');
   set(findobj('Tag','Pushbutton4'),'Enable','off');
   set(findobj('Tag','Pushbutton6'),'Enable','off');
   set(findobj('Tag','Pushbutton15'),'Enable','off');
   set(findobj('Tag','Pushbutton5'),'Enable','off');
   set(findobj('Tag','Pushbutton3'),'Enable','off');
   %set(findobj('Tag','Pushbutton12'),'Enable','off');
   set(findobj('Tag','Pushbutton7'),'Enable','off');
   set(findobj('Tag','Pushbutton14'),'Enable','off');
   set(findobj('Tag','Pushbutton16'),'Enable','off');

     
   end
   
   
   
    % put in data list box and x/y data boxes 
     set(findobj('Tag','Listbox1'),'String',files,'Value',newchoice);
     set(findobj('Tag','Listbox3'),'String',sizescell,'Value',newchoice);
     set(findobj('Tag','Listbox4'),'String',matrices,'Value',newchoice);
     set(findobj('Tag','Listbox5'),'String',files,'Value',newchoice);
     set(findobj('Tag','Listbox6'),'String',files,'Value',newchoice);
    if numfiles>1,
         GUIselectdata(mins,maxs,region);
    else
     set(findobj('Tag','EditText1'),'String','');
     set(findobj('Tag','EditText6'),'String','');
    end

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

