% GUI2Dplot
% function for the MODIS GUI
% Copyright by Jasmine S Nahorniak, Oregon State University
% Feb 28 2000

function [Glineh]=GUI2Dplot(data,mins,maxs)

GUIbutton('Pushbutton7','PLOTTING','on');

% ******************************************************
% retrieve all of the user-selected options

GUIdefaults;

% figure number
tag='PopupMenu3';
choices=get(findobj('Tag',tag),'String');
val=get(findobj('Tag',tag),'Value');
fignum=choices{val};

% x data
tag='Listbox5';
choice=get(findobj('Tag',tag),'Value');
tdata=data{choice};
bad=find(tdata<mins(choice));
tdata(bad)=mins(choice);
bad=find(tdata>maxs(choice));
tdata(bad)=maxs(choice);
szdata=size(tdata);
xdata=reshape(tdata,szdata(1)*szdata(2),1);
clear tdata;

% y data
tag='Listbox6';
choice=get(findobj('Tag',tag),'Value');
tdata=data{1,choice};
bad=find(tdata<mins(choice));
tdata(bad)=mins(choice);
bad=find(tdata>maxs(choice));
tdata(bad)=maxs(choice);
szdata=size(tdata);
ydata=reshape(tdata,szdata(1)*szdata(2),1);
clear tdata;


% axis type
axistype=guiaxistype{1};   

% line type
linetype=guilinetype{1};   

% xlabel
tag='EditText3';
figxlabel=get(findobj('Tag',tag),'String');

% ylabel
tag='EditText7';
figylabel=get(findobj('Tag',tag),'String');

% title
tag='EditText12';
figtitle=get(findobj('Tag',tag),'String');


% *********************************************************
% colors

bgcol=GUIcol2num(guibackgroundcolors{1});
if guiaxiscolors{1}~='none' & guiaxiscolors{1}~=guibackgroundcolors{1},
    axiscol=GUIcol2num(guiaxiscolors{1});
else
    if guiaxiscolors{2}~=guibackgroundcolors{1},
        axiscol=GUIcol2num(guiaxiscolors{2});
    else
        axiscol=GUIcol2num(guiaxiscolors{3});
    end
end

% *********************************************************

% make new figure
if fignum(1)=='n',   % new figure
   GtwoDfig=figure;
   set(GtwoDfig,'Units','normalized','Position',[0.5 0 0.5 0.4])
   set(GtwoDfig,'Color',guibackgroundcolors{1})
   set(GtwoDfig,'Tag','twoDfigure')
   hold on;
   mapax=gca;
   set(mapax,'Color',bgcol,'XColor',axiscol,'YColor',axiscol);
   GUImake2Dmenu(GtwoDfig);
   % line color
   linecol=GUIcol2num(guilinecolor{1});   
else
   figure(str2num(fignum))
   hold on; 
   mapax=gca;  
   numcurves=length(findobj(gcf,'Tag','twoDcurve'));
   numcolors=length(guilinecolor);
   while numcurves>=numcolors,
        numcurves=numcurves-numcolors;
   end 
   % line color
   linecol=GUIcol2num(guilinecolor{numcurves+1}); 

   %set(mapax,'Color',guibackgroundcolors{1}, ...
    %         'XColor','guiaxiscolors{1},'YColor',guiaxiscolors{1});
end

% do plot    

set(mapax,'Box','on','YScale',axistype);
warning off     % don't tell me about linestyle error
Glineh=plot(xdata,ydata,'LineStyle',linetype,'Color',linecol);  
warning on
set(Glineh,'Tag','twoDcurve')

xlabel(figxlabel);
ylabel(figylabel);
title(figtitle,'Color',axiscol);

GUIfigurenum('PopupMenu3','twoDfigure');
   
GUIbutton('Pushbutton7','GO','off');
