 function fig = pl_win(theCallback)
% This is the machine-generated representation of a Handle Graphics object
% and its children.  Note that handle values may change when these objects
% are re-created. This may cause problems with any callbacks written to
% depend on the value of the handle at the time the object was saved.
% This problem is solved by saving the output as a FIG-file.
%
% To reopen this object, just type the name of the M-file at the MATLAB
% prompt. The M-file and its associated MAT-file must be on your path.
% 
% NOTE: certain newer features in MATLAB may not have been saved in this
% M-file due to limitations of this format, which has been superseded by
% FIG-files.  Figures which have been annotated using the plot editor tools
% are incompatible with the M-file/MAT-file format, and should be saved as
% FIG-files.

if (nargin<1)
%set theCallback for the buttons
  theCallback=[mfilename ' callback'];
  popupStr = str2mat(' blank ');

arch=computer;
  if (strcmp(arch,'PCWIN') | strcmp(arch,'MAC2'))
     win_dim=[140 100 560 420];
  else
     if (isunix)
        win_dim=[445 120 560 420];
     else
        win_dim=[140 100 560 420];
     end
  end

h0 = figure('Color',[0.5 0.7 0.7], ...
	'Colormap','default', ...
	'FileName','pl_win.m', ...
	'NumberTitle','off', ...
	'PaperPosition',[18 180 576 432], ...
	'PaperUnits','points', ...
	'Position',[554 497 560 420], ...
	'Tag','plot window', ...
	'ToolBar','none',...
        'Name','plot window');
h1 = axes('Parent',h0, ...
	'Units','pixels', ...
	'CameraUpVector',[0 1 0], ...
	'Color',[1 1 1], ...
	'Position',[60 145 310 240], ...
	'Tag','Axes1', ...
	'XColor',[0 0 0], ...
	'YColor',[0 0 0], ...
	'ZColor',[0 0 0]);
h2 = text('Parent',h1, ...
	'Color',[0 0 0], ...
	'HandleVisibility','off', ...
	'HorizontalAlignment','center', ...
	'Position',[0.496987951807229 -0.08778625954198471 9.160254037844386], ...
	'Tag','Axes1Text4', ...
	'VerticalAlignment','cap');

set(get(h2,'Parent'),'XLabel',h2);
h2 = text('Parent',h1, ...
	'Color',[0 0 0], ...
	'HandleVisibility','off', ...
	'HorizontalAlignment','center', ...
	'Position',[-0.08433734939759037 0.4961832061068703 9.160254037844386], ...
	'Rotation',90, ...
	'Tag','Axes1Text3', ...
	'VerticalAlignment','baseline');

set(get(h2,'Parent'),'YLabel',h2);
h2 = text('Parent',h1, ...
	'Color',[0 0 0], ...
	'HandleVisibility','off', ...
	'HorizontalAlignment','right', ...
	'Position',[-0.1174698795180723 1.068702290076336 9.160254037844386], ...
	'Tag','Axes1Text2', ...
	'Visible','off');

set(get(h2,'Parent'),'ZLabel',h2);
h2 = text('Parent',h1, ...
	'Color',[0 0 0], ...
	'HandleVisibility','off', ...
	'HorizontalAlignment','center', ...
	'Position',[0.496987951807229 1.022900763358779 9.160254037844386], ...
	'Tag','Axes1Text1', ...
	'VerticalAlignment','bottom');

set(get(h2,'Parent'),'Title',h2);

%  adds title bar on the figure
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 .3 .8], ...
	'ListboxTop',0, ...
	'Position',[45 312 248 20], ...
        'FontSize',14,...
	'FontWeight','bold',...
	'Style','text',...
	'String','MMP plotting tool',...
	'Tag','HdrText');

% these are for the buttons on the right
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.2 0.7 0.5], ...
	'ListboxTop',0, ...
	'Position',[308 6 124 320], ... 
        'Callback',theCallback, ...
        'Style','Frame',...
	'String','', ...
	'Tag','optFrame');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.7 0.7 0.7], ...
	'ListboxTop',0, ...
	'Position',[320 282.4 103 35.2], ...
        'Callback',theCallback, ...
	'String','load data', ...
        'Style','pushbutton',...
	'Tag','Loadbutton');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[320 66.72 103 35.2], ...
	'String','modify plot', ...
        'Callback',theCallback, ...
        'Style','pushbutton',...
	'Tag','modbutton');

h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.7 0.7 0.7], ...
	'ListboxTop',0, ...
	'Position',[320 120.64 103 35.2], ... 
        'Callback',theCallback, ...
        'Style','pushbutton',...
	'String','plot', ...
	'Tag','plotbutton');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[320 12.8 103 35.2], ...
        'Callback',theCallback, ...
	'String','quit', ...
        'Style','pushbutton',...
	'Tag','quitbutton');

h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[320 228.48 103 35.2], ...
        'Style','Frame',...
	'Tag','Xframe');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[325 232.48 35 20], ...
        'String','X var',...
        'Style','Text',...
	'Tag','Xtext');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Min',1, ...
	'Position',[358 238.5 60 20], ...
	'String',popupStr, ...
        'Callback',theCallback, ...
	'HorizontalAlignment','left',...
	'Style','popupmenu', ...
	'Tag','XaxMenu', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[320 174.56 103 35.2], ...
        'Style','Frame',...
	'Tag','Yframe');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[325 178.56 35 20], ...
        'String','Y var',...
        'Style','Text',...
	'Tag','Ytext');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Min',1, ...
	'Position',[358 183.5 60 20], ...
	'String',popupStr, ...
	'HorizontalAlignment','left',...
        'Callback',theCallback, ...
	'Style','popupmenu', ...
	'Tag','YaxMenu', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[.7 .7 .7], ...
	'ListboxTop',0, ...
	'Position',[28 65 264 16], ...
	'Style','text', ...
	'String','Enter plot commands below, then click modify plot',...
	'Tag','Text1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'ListboxTop',0, ...
	'Position',[28 24 264 42], ...
	'String','',...
	'HorizontalAlignment','left',...
	'Style','edit', ...
	'Tag','EditText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[.7 .7 .7], ...
	'ListboxTop',0, ...
	'Position',[28 8 264 16], ...
	'Style','text', ...
	'String','',...
	'Tag','open_fileTxt');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%    Now deal with the effects of actions on the buttons
%         all actions based on the callback object's 'String'

  switch(lower(theCallback))
     case 'callback'
	switch(lower(get(gcbo,'string')))

           case 'load data'
%            if there's a path saved, use it
  		h=findobj('tag','Loadbutton');
	        inpath=get(h,'Userdata');
               eval(['[prof,pth]=uigetfile(''' inpath '*.mat'', ''select a profile'');']);
               eval(['load ' pth prof])
               vars=who;
               popupStr=char(vars);
		x1=findobj('tag','XaxMenu');
		set(x1,'String',popupStr)  
                set(x1,'HorizontalAlignment','left') 
		y1=findobj('tag','YaxMenu');
		set(y1,'String',popupStr)
                set(y1,'HorizontalAlignment','left')
%              save the data in a structure then to gcbf for others to access
		  for ik=1:length(vars)
		    eval(['grds.' char(vars{ik}) '= ' vars{ik} ';']);
		  end
		    grds.varname=vars;
%              save the path 
		  h=findobj('tag','Loadbutton');             
		  set(h,'UserData',pth);
		set(gcbf,'UserData', grds);  
%              write out which file was opened
		  h=findobj('tag','open_fileTxt');
		  set(h,'String',prof);

   	   case 'plot'
		ty=get(findobj(gcf,'Style','popupmenu','Tag','YaxMenu'),'value');
		tx=get(findobj(gcf,'Style','popupmenu','Tag','XaxMenu'),'value');
		grds=get(gcbf,'UserData');
		  xvar=grds.varname{tx};
		  yvar=grds.varname{ty};
		if eval(['(length(grds.' xvar ') == length(grds.' yvar '))'])   		  	   eval(['plot(grds.' xvar ', grds.' yvar ')']);  
	         else
		    msg='the variables selected are different lengths, try chosing others';
		    msg_window(msg);
        		 while (findobj('type','figure','tag','msgwin'))
          		   pause(2)
         		 end
        		  break;
		 end

            case 'modify plot'
	      eh=findobj(gcbf,'Tag','EditText1');
	      pl_cmd=get(eh,'String');
	      eval(pl_cmd);
	      set(eh,'String',' ');

           case 'quit'
             plot_fig=findobj('type','figure','name','plot window');
             close(plot_fig);
             return
        otherwise
           return
      end
   
     otherwise
   end
