function plotmasterweb(fctn, varargin)
% Initial switchyard file derived from plotmaster.m

global XYDATA
global UVDATA
global VECFIG
global CONTFIG
global ALLFIG
evalin('base','global UVDATA')
evalin('base','global XYDATA')
evalin('base','global VECFIG')
evalin('base','global CONTFIG')
evalin('base','global ALLFIG')

ALLFIG.outpath =  pwd;

switch(fctn)       
	case 'firstwindow'
		 msg = sprintf('\n\n     WEB PLOTS:    IMPORTANT\n\nExcept for the cruise database, \nAll file inputs and outputs\ntake place in the current directory.\n\nCurrently in:\n%s', pwd);
		 noticeOK(msg)
       pause(2.5)
		 call_gplotwebdb
       
	case 'okcallbackweb'         %  >> from gplotwebdb - btnOK
       tp = findobj(gcbf,'tag','txtboxinpath');
       ALLFIG.dbpath = get(tp,'string');   
       if isempty(ALLFIG.dbpath) | ~exist(ALLFIG.dbpath,'file')
          msg = sprintf('\nInput data path/file incomplete \nor incorrect.');
          noticeOK(msg)
          return
       else
          close(gcf)
       end

       webmaster('setup') 
       
   case 'getcfgfile'       % from [...] on gplotwebdb
       getfile
end  
   
%%%%%%%%%%%%
   
function call_gplotwebdb
global ALLFIG

gplotwebdb

%curd = pwd;
%slashes = findstr(curd, filesep);
%ship_cruiseID = curd(slashes(end-1)+1:end);
%basestr = '/home/moli4/datasets';
%basestr = '.';
%endstr = ['a', ship_cruiseID(end-3:end), 'dir.blk'];
%dbguess = fullfile(basestr, ship_cruiseID, 'adcpdb', endstr);
%
%
%tp = findobj(gcf,'tag','txtboxinpath');
%if ~isfield(ALLFIG, 'dbpath')  % fresh start
%   if exist( basestr,'dir') 
%      set(tp,'string','/home/moli4/datasets/*dir.blk');
%      if exist(dbguess, 'file'), set(tp,'string',dbguess); end;
%   else
%      set(tp,'string','');
%   end
%else % return from ongoing session (outpath established)
%   set(tp,'string', ALLFIG.dbpath);
%end



%JH try this 2003/07/07
tp = findobj(gcf,'tag','txtboxinpath');
curd = pwd;
if ~isfield(ALLFIG, 'dbpath')  % fresh start
   if exist('../adcpdb','dir') %we're in a processing directory
      [basedir, ship_cruiseID] = fileparts(fileparts(curd));
      endstr = ['a', ship_cruiseID(end-3:end), 'dir.blk'];   
      dbguess =  fullfile('../adcpdb/', endstr);
      if (exist(dbguess,'file'))
         tp = findobj(gcf,'tag','txtboxinpath');
         set(tp,'string', dbguess);
      end
   else %assume we're in the directory with all the web stuff, named by cruise
      [pp, ship_cruiseID] = fileparts(curd);
      basedir = '.';
      clear pp
      endstr = ['a', ship_cruiseID(end-3:end), 'dir.blk'];   
      dbguess =  ['/home/moli4/datasets/.../*dir.blk'];
      tp = findobj(gcf,'tag','txtboxinpath');
      set(tp,'string', dbguess);
   end
else % return from ongoing session (outpath established)
   set(tp,'string', ALLFIG.dbpath);
   [pp, ship_cruiseID] = fileparts(curd);
   basedir = '.';
end
   


%%%%%%%%%%%%%

function getfile
global ALLFIG

cph = findobj(gcf,'tag','txtboxinpath');
cpstr = get(cph,'string');      

[uifile, uipath] = uigetfile(sprintf('%s', cpstr), 'Select a file of the form *dir.blk', 200, 100);
if uipath ~= 0   % not cancelled 
   fullname = strcat(uipath, uifile);
   set(cph,'string', fullname);
else
   set(cph, 'enable', 'on');  % keep avail. if cancelled & reset
   set(cph, 'string', cpstr);
end

%%%%%%%%%%% EOF
