function fig = mmp_main(theCallback)
%
% this is the first figure that comes up as part of the moored Profiler
% processing stuff
%
% emontgomery@whoi.edu March 2002
%

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

popupStr = str2mat('  CTD ', ' ACM ', ' ENG ');
arch=computer;
  if (strcmp(arch,'PCWIN') | strcmp(arch,'MAC2'))
     win_dim=[125 125 410 300];
  else
     if (isunix)
        win_dim=[400 350 410 300];
     else
        win_dim=[125 125 410 300];
     end
  end

h0 = figure('Units','points', ...
	'Color',[0.2 0.7 0.7], ...
	'Colormap','default', ...
	'FileName','main_mmp.m', ...
	'PaperPosition',[18 180 576 432], ...
	'PaperUnits','points', ...
	'Position',win_dim, ...
        'Name','Main Window',...
	'Tag','setupWindow', ...
	'ToolBar','none');
  set(gcf,'NumberTitle','off')

% background frame and text
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.5 0.7 0.7], ...
	'ListboxTop',0, ...
	'Position',[0 0 440 300], ...
	'Style','frame', ...
	'Tag','bgFrame');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.5 0.7 0.7], ...
	'ListboxTop',0, ...
        'FontSize',14,...
	'FontWeight','bold',...
	'Position',[15.2 280 380.8 17.6], ...
	'String','MP processing', ...
	'Style','text', ...
	'Tag','hdrText');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.5 0.7 0.7], ...
	'ListboxTop',0, ...
        'FontSize',12,...
	'Position',[15.2 255 380.8 17.6], ...
	'String','Work down the left side for conversions, right side for display', ...
	'Style','text', ...
	'Tag','hdr2Text');
% pushbutton for conversion asc->.mat
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',0, ...
	'Position',[13 200 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Convert ascii data to .mat', ...
	'Style','Pushbutton', ...
	'Tag','SetupPush');
%  these three comprise the frame and popup window for plotting
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',100, ...
	'FontSize',12,...
	'Position',[215 200 180 30], ...
	'HorizontalAlignment','center',...
	'Callback',theCallback,...
	'String', 'Plot raw profile',...
	'Style','Pushbutton', ...
	'Tag','Rawplotpush');
% pushbutton for  viewing the summary of a .mat
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',0, ...
	'Position',[13 160 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Create summary file', ...
	'Style','Pushbutton', ...
	'Tag','SummPush');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',0, ...
	'Position',[215 160 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Plot summary data', ...
	'Style','Pushbutton', ...
	'Tag','PltSummPush');
% pushbutton for conversion asc->.mat
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',0, ...
	'Position',[13 120 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Derive pressure gridded .mat', ...
	'Style','Pushbutton', ...
	'Tag','pgridPush');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.3 0.6 0.7], ...
	'ListboxTop',0, ...
	'Position',[215 120 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Plot pressure gridded data', ...
	'Style','Pushbutton', ...
	'Tag','PlpgridPush');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.6 0.5 0.4], ...
	'ListboxTop',0, ...
	'Position',[215 80 180 30], ...
        'FontSize',12,...
        'Callback',theCallback, ...
	'String','Close Plot windows', ...
	'Style','Pushbutton', ...
	'Tag','CLWinPush');
h1 = uicontrol('Parent',h0, ...
        'Units','points', ...
        'BackgroundColor',[0.8 0.1 0.15], ...
        'ListboxTop',0, ...
	'FontSize',12,...
        'Position',[150 20 130 40], ...
        'Callback',theCallback,...
        'String','CLOSE - done', ...
        'Style','Pushbutton', ...
        'Tag','closePush');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% now we can deal with button clicks and stuff	                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
% keyboard

arch=computer;
if (strcmp(arch,'PCWIN')) 
   slsh='\';
else
   slsh='/';
end

switch(lower(theCallback))
     case 'callback'
        switch(lower(get(gcbo,'string')))
%        first do the 3 left hand computation actions
          case 'convert ascii data to .mat'
              cvt2mat;
          case 'create summary file'
	      summ_inp;
          case 'derive pressure gridded .mat'
	      pgrid_new;

%      then do the 3 right hand plot actions
          case 'plot raw profile'
             if exist('cvt_params.mat','file')
               load cvt_params;
               rawdir=char(params{2});
             else
               rawdir=pwd;
   	     end
               [fn,pathn]=uigetfile([rawdir slsh '*mat'],'choose a profile');
               eval(['raw_plots(''' [pathn fn] ''');'])

          case 'plot summary data'
             if exist('sm_params.mat','file')
               load sm_params;
               sumdir=char(params{4});
             else
               sumdir=pwd;
   	     end
              [fn,pathn]=uigetfile([sumdir slsh '*mat'],'choose a profile');
              eval(['plot_raw_summary(''' [pathn fn] ''');'])

          case 'plot pressure gridded data'
	      pl_win;

          case 'close plot windows'
                tsfigs=findobj('type','figure','tag','rawplot');
                close(tsfigs)
                tsfigs=findobj('type','figure','tag','sumplot');
                close(tsfigs)

%      and finally exit
          case 'close - done'
              main_fig=findobj('type','figure','name','Main Window');                          close(main_fig)
               return
          otherwise
            return
          end
   otherwise
end


