%--------------------------------------------------------------------------
%
% PURPOSE: Simulate 21" AUV dynamics with the Qnx simulator. Plot the results.
% AUTHOR:  Rob McEwen
% DATE:    2015/4/14
%
%--------------------------------------------------------------------------
%
% Note:  Any mission name that you want to run variations on has to be at
% least 8 characters.  So, Diamond.cfg will need another character before
% the strncmp ignores the rest.
%
missionList = {'SimWCakeSimple.cfg',
               'SimVIsland.cfg',
               'SimVIsland0.cfg',
               'Flat4c.cfg',
               'PortOALow2.cfg',
               'PortOAHigh.cfg',
               'PortOA30.cfg',
	       'PortAllRob.cfg',
	       'PortAllNoReturn.cfg',
	       'PortSteveGood.cfg',      %N/S/E dogleg const depth 50 for Krukowski
	       'PortSarah.cfg',
	       'PortDavid.cfg',
	       'PortTest.cfg',
               'SimMC1850.cfg',
               '20150827_IcebergTesting_m1v4_rob.cfg',
               'SimMC2800.cfg',
               'Transect.cfg',
               'SingleTransect.cfg',
	       'PlateauWest.cfg',
	       'PlateauTest.cfg',
	       'Wall2014.cfg',
	       'Wall2014Escape.cfg',
	       '2013_WallTest_12v1_withresonR1.cfg.pp',
	       '2013_WallTest_11v1R2pp.cfg',
	       '2016_WallTest_15v1.cfg.pp',
	       '2017_WallTest',
	       '2017_TrnTest',
	       'TrnTestSouth',
	       'Iceberg.cfg',
	       'Iceberg2.cfg',           %Multi-level original MB location IcebergInTheBay.
	       'Iceberg3.cfg',           %Multi-level new MB location. "theBerg" series.
	       'Iceberg4.cfg',           %Single-level, new location, "theBerg", in&out.
	       'Triangle.cfg',
	       'Diamond2.cfg',           %Duane's & Yanwu's Gulper mission.
	       'EarlyDiamondLaunch.cfg',    %Duane's early launch point.
	       'InshoreDock.cfg.pp',
	       'PetersensCleanBerg',
	       'Cubes.cfg'};
	       
[status cname]=system('hostname');
fprintf('Starting a simulation on %s',cname);

if( exist('missionFileName')==0 )
    fprintf('Please set missionFileName. Supported missions are:\n');
    %missionList = textread('missionList.txt','%s');
    for( i=1:length(missionList) )
        fprintf('   %s\n',char(missionList(i)));
    end
    return
else
  %
  % This logic assumes the user starts with Matlab in the correct directory.
    pwdstr = pwd;
    if(strncmp(computer,'PCWIN',5))
        hostPathToOnboard = char(regexp(pwdstr,'\\.*onboard','match'));
	location = 'network';
	linDirPath = hostPathToOnboard;
            %
            % First swap the slash \ for /:
            for( i=1:length(linDirPath) )
                if(linDirPath(i) == '\')
                    linDirPath(i) = '/';
                end
            end
    elseif(strncmp(computer,'MAC',3))
      if( strfind(pwdstr, '/Volumes/'))
	location = 'network';
        hostPathToOnboard = char(regexp(pwdstr,'/Volumes/.*onboard','match'));
      elseif( strfind(pwdstr, '/Users/rob'))
	location = 'local';
        hostPathToOnboard = char(regexp(pwdstr,'/Users/rob/.*onboard','match'));
      else
	fprintf(['Can''t find either the local or network directory on the' ...
		 ' Mac.\n']);
      end
    else
	fprintf('Unrecognized computer type %s.\n',computer);
    end
        
    if( ~isempty(hostPathToOnboard) )
        cd(hostPathToOnboard)
        fprintf('Running out of %s directory %s.\n',location, pwd);
    else
        fprintf(['%s is an unrecognized directory.  Please cd to ' ...
                 '"onboard".\n'],pwdstr);
        return
    end

    if( strcmp(computer,'PCWIN64'))
        guestname = 'mvc-bi.shore.mbari.org';
        guestname = 'sandpiper-qnx.shore.mbari.org';
        fprintf('Telnetting to %s.\n',guestname);
    elseif( strcmp(computer,'MACI64'))
        %guestname = 'whitebird-qnx';
        %guestname = 'sandpiper-qnx.shore.mbari.org';
       	%guestname =  '134.89.33.87';
       	guestname =  '134.89.32.72';
       	%guestname =  '192.168.63.129';
    else
        fprintf('Unrecognized host.  Exit.\n');
        return
    end
    cpStr = sprintf('ping -c 1 %s', guestname);
    [error result] = system( cpStr );
    if( error ) 
      fprintf('Error: Could not ping VM %s.\n',guestname);
      return
    end
    fprintf('Telnetting to %s.\n',guestname);
    worked = 0;
    recognized = 0;
    cpError = 0;
    missionListStr='';
    useTrn = '';
    len = length(missionList);
    for(i=1:len-1)
        %
        % strcat plays nasty tricks with trailing spaces.
        missionListStr = [missionListStr,char(missionList(i)),' '];
    end
    missionListStr = [missionListStr,char(missionList(len))];
    %missionList = textread('missionList.txt','%s');
    configDir = 'imaging';
    for( i=1:length(missionList) )
        %if( strncmp(missionList(i), missionFileName, 13 ))
        if( strncmp(missionList(i), missionFileName, 8 ))
            recognized = 1;
            fprintf(['Running supported mission %s out of %s with ',... 
		     'configuration files in %s.\n'],...
                    missionFileName, hostPathToOnboard, configDir);
        end
    end
    if(~recognized) 
        fprintf('Running mission %s out of %s\n', ...
                missionFileName, hostPathToOnboard);
    end
    %
    % If missionFileName is "recognized", that is, in the list above,
    % determine which configuration files to use, and copy them into place.
    % If the VM didn't mount Atlas, ftp them over.
    %
    configNames = {'vehicle', 'simulator', 'workSite', 'terrainAid'};
    eval(['cd config/', configDir]);
    nExistingConfigs=3;
    if( exist('terrainAid.cfg') ) nExistingConfigs = nExistingConfigs + 1;end
    if( recognized )
      %
      % Save aside the existing configuration files:
      for( i=1:nExistingConfigs )
	cpStr = sprintf('cp %s.cfg %sSave.cfg',...
		configNames{i}, configNames{i} );
	[error result] = system( cpStr );
	if( error ) 
	  fprintf('Error: %s, occured while copying %s.\n',result, ...
		  configName);
	  cpError=1;
	end
      end
      %
      % Move the corresponding configuration files into place.  
      %
      nConfigs = 3;
      if( exist('trn') == 1 ) 
	nConfigs = nConfigs + 1; 
	useTrn = '-trn';
      end
      % Each of the missions below have a unique set of corresponding
      % configuration files. 
      if( strcmp(missionFileName,'SimWCakeSimple.cfg') || ...
          strcmp(missionFileName,'Flat4c.cfg')  || ...
          strcmp(missionFileName,'SimMC1850.cfg') || ...
	  strcmp(missionFileName,'SimMC2800.cfg') || ...
          strcmp(missionFileName,'PlateauWest.cfg') || ...
          strcmp(missionFileName,'PlateauTest.cfg') || ...
	  strcmp(missionFileName,'Iceberg.cfg') || ...
	  strcmp(missionFileName,'Diamond2.cfg') || ...
	  strcmp(missionFileName,'EarlyDiamondLaunch.cfg') || ...
	  strcmp(missionFileName,'Triangle.cfg') || ...
	  strcmp(missionFileName,'Cubes.cfg') )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
			  configNames{i}, missionFileName, configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, missionfileName);
	    cpError=1;
	  end
	end
	%
	% Each of the following families of missions run from a single set of
        % configuration files.
      elseif( strncmp(missionFileName,'Iceberg2',8) )
	%
	% This is the priority 0, multi-depth encirclement.  The berg is
        % in the first Monterey Bay location.
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'Iceberg2.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'Iceberg2.cfg');
	    cpError=1;
	  end
	end
	%
	% Changed the 8 to 7 below, so Iceberg3 and above will use the
        % Iceberg3 configuration files.  Making Iceberg4.cfg which has
        % drop-in and drop-out angles in berg coordinates.
	%
      elseif( strncmp(missionFileName,'Iceberg3',7) )
	%
	% This is priority 0.  They moved the berg to a new location in the
        % bay.
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'Iceberg3.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'Iceberg3.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'PetersensCleanBerg',7) )
	%
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'Petersens.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'Petersens.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'Transect',7) || ...
	      strncmp(missionFileName,'SingleTransect',12) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'Transect.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'Transect.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'PortDavid',9) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'PortDavid.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'PortDavid.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'Port',4) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'PortOA30.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'PortOA30.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'InshoreDock',7) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'InshoreDock.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'InshoreDock.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'SimVIsland',10) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'SimVIsland.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'SimVIsland.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'2017_TrnTestNear', 16) || ...
              strncmp(missionFileName,'2017_WallTestNear', 17) || ...
              strncmp(missionFileName,'TrnTestSouthLocalNear', 17) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'WallNear.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'WallNear.cfg');
	    cpError=1;
	  end
	end
      elseif( strncmp(missionFileName,'2016_WallTestSide', 17) )
	%
	% This has to come before the older series of wall tests below.
        % Those had the old map Topo_Wall_2m_Small, and down-looking Trn.
	% These have Steve's new map and side-looking Trn.
	%
	% Need to figure out how to deal with the trn configs when running
        % out of the local directory.
	%
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'WallSide.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'WallSide.cfg');
	    cpError=1;
	  end
	end
      elseif( strcmp(missionFileName,'Wall2014.cfg') || ...
              strcmp(missionFileName,'Wall2014Escape.cfg') || ...
	      strcmp(missionFileName,'2013_WallTest_12v1_withresonR1.cfg.pp')|| ...
	      strcmp(missionFileName,'2013_WallTest_11v1R2pp.cfg') || ...
	      strncmp(missionFileName,'2016_WallTest_15v1.cfg.pp', 13) || ...
	      strncmp(missionFileName,'2017_WallTest', 13) || ...
	      strncmp(missionFileName,'2017_TrnTest', 12) || ...
	      strncmp(missionFileName,'TrnTestSouth', 12) )
	for( i=1:nConfigs )
	  cpStr = sprintf('cp %s%s %s.cfg',...
		  configNames{i}, 'Wall2014.cfg', configNames{i} );
	  [error result] = system( cpStr );
	  if( error ) 
	    fprintf('Error: %s, occured while copying %s%s.\n',result, ...
		    configNames{i}, 'Wall2014.cfg');
	    cpError=1;
	  end
	end
	%
	% If missionFileName is not in the list
      else
	fprintf(['Error: The mission %s is in the list but not ',...
		'in the "if-elseif".\n'], missionFileName)
	cpError=1;
      end
    end %if( recognized )

    if(cpError) return; end
    %
    % Tranfer the mission and configuration files to whitebird-qnx.  
    %
    if( strcmp(computer,'MACI64'))
      switch( location )
       case{'network'}
       case{'local'}
	fprintf('Matlab: Transfer mission file to the guest:\n');
	guestPathToMissions = 'auv-qnx/auv/altex/onboard/missions';
	eval(['cd ', hostPathToOnboard, '/missions'])
	putString = sprintf(['/usr/local/bin/ncftpput '...
		    '-R -u rob -p rob %s %s %s'], ...
			    guestname, guestPathToMissions, missionFileName);
	[error result] = system(putString);
	if( error )
	  fprintf('Matlab: Error transferring mission to guest: %s\n',result);
	  return
	else
	  fprintf('Matlab: mission ncftpput suceeded.\n')
	end
	fprintf('Matlab: Transfer configuration files to the guest:\n');
	guestPathToConfigs = 'auv-qnx/auv/altex/onboard/config/imaging';
	eval(['cd ', hostPathToOnboard, '/config/imaging'])
	if(useTrn) 
	  trnStr = 'terrainAid.cfg'; 
	else
	  trnStr = '';
	end
	putString = sprintf(['/usr/local/bin/ncftpput '...
		    '-R -u rob -p rob %s %s %s %s %s %s'], ...
			    guestname, guestPathToConfigs, ...
			    'vehicle.cfg', 'simulator.cfg', ...
			    'workSite.cfg', trnStr);
	[error result] = system(putString);
	if( error )
	  fprintf(['Matlab: Error %s transferring a configuration file to the' ...
		   ' guest.\n'],result);
	  return
	else
	  fprintf('Matlab: Main configuration ncftpput succeeded.\n')
	end
	if( strcmp(useTrn,'-trn') )
	  %
	  % Now copy over the Trn config files:
	  %
	  putString = sprintf(['/usr/local/bin/ncftpput '...
		    '-R -u rob -p rob %s %s %s %s %s'], ...
			      guestname, guestPathToConfigs, ...
			      'mappingAUV_specs.cfg', 'rdiDVL_specs.cfg', ...
			      'resonSeabat8101_specs.cfg');
	  [error result] = system(putString);
	  if( error )
	    fprintf(['Matlab: Error %s transferring a TRN configuration file to the' ...
		     ' guest.\n'],result);
	    return
	  else
	    fprintf('Matlab: TRN configuration ncftpput succeeded.\n')
	  end
	end
      end
    end
    
    i=5;
    while( i > 0 )
      fprintf('\rMatlab: Starting the qnx sim in %d seconds.',i);
      pause(1);
      i = i-1;
    end
    fprintf('\n');
    %    runString = sprintf(['rsh %s "../../offboard/sim ' ...
    %                        '%s > /dev/null >& /dev/null"'], guestname,...
    %                        missionFileName);
    %
    % The qnx .profile cd's to onboard/bin.
    %
    runString = sprintf('rsh %s ../../offboard/sim %s %s',...
                        guestname, missionFileName, useTrn);
    tic
    %[error  result]= system(runString);
    error = system(runString);
    telapsed=toc;

    if( error )
      fprintf('Qnx sim failed with error = %d. Exit.\n', error );
%      fprintf('Qnx sim failed with status = %d, result = %s. Exit.\n',...
%	      error, result);
      return
    end

    %
    % Restore the previously existing configuration files:
    if( recognized )
      fprintf('Now restoring previously existing configuration files.\n');
      for( i=1:nExistingConfigs )
	cpStr = sprintf('cp %sSave.cfg %s.cfg',...
		configNames{i}, configNames{i} );
	[error result] = system( cpStr );
	if( error ) 
	  fprintf('Error: %s, occured while restoring %s.\n',result, ...
		  configName);
	end
      end
    end

    lsString = sprintf('rsh %s ls -l ../logs/latest',guestname);
    [error result] = system(lsString);
    
    if( ~error )
      guestPathToLatest = ...
	  char(regexp(result, '[\w/-]*\d\d\d\d\.\d\d\d\.\d\d','match'));
      guestPathToLogs = ...
	  char(regexp(result, '[\w/-]*/logs/','match'));
      latestdir = char(regexp(result, '\d\d\d\d\.\d\d\d\.\d\d','match'));
      fprintf('Matlab:  Guest path to latest = %s\n',guestPathToLatest);
      fprintf('Matlab:  latestdir = %s\n',latestdir);
    else
      fprintf('Matlab:  Can''t find "latest" in %s\n',result);
      return
    end        

    if( strcmp(computer,'PCWIN64'))
      eval(['cd //atlas', guestPathToLatest(10:end)])
    elseif( strcmp(computer,'MACI64'))
      switch( location )
       case{'network'}
	%eval(['cd /Volumes', guestPathToLatest(10:end)])   For Atlas, when it worked.
	eval(['cd /Volumes/qnx_partition', guestPathToLatest(10:end)])
       case{'local'}
	eval(['cd ', hostPathToOnboard, '/logs'])
	getString = sprintf(['/usr/local/bin/ncftpget '...
		    '-R -u rob -p rob %s . %s'], ...
			    guestname, guestPathToLatest);
	[status result] = system(getString);
	if( ~status )
	  fprintf('Matlab: %s\n',result);
	else
	  fprintf('Matlab: ncftpget suceeded.\n')
	end
	eval(['cd ', latestdir])
      end
    else
      fprintf('Unrecognized host.  Exit.\n');
      return
    end
    %
    % Had to boot the "switch" here because I couldn't figure out how control the searching
    % as well. Here I can use strncmp().
    if(recognized)
      if( strcmp(missionFileName,'SimWCakeSimple.cfg') || ...
	  strncmp(missionFileName,'SimVIsland.cfg',10) || ...
	  strcmp(missionFileName,'Triangle.cfg'))
	npbeams=119; idt.vertMt=0; plotSwFlags=1;
	loadData; review; dvl; deltaT; wallPlot
      elseif( strncmp(missionFileName,'Iceberg.cfg',7))
	npbeams=119; idt.vertMt=0; plotSwFlags=1;
	loadData; review; dvl; deltaT; wallPlot; plotDvlSide; terrainPlotPsi;
	bergPlot2;
      elseif( strncmp(missionFileName,'Petersens',7))
	[status,result] = ...
	    system('egrep ''^[ ]*map.*\_v2'' terrainAid.cfg');
	if(isempty(result))
	  loc = 'CleanBerg00';
	else
	  loc = 'CleanBerg_v2R2';
	end
	%npbeams=119; idt.vertMt=0; plotSwFlags=1; loc = 'CleanBerg_v2R2';
	%npbeams=119; idt.vertMt=0; plotSwFlags=1; loc = 'CleanBerg00';
	npbeams=119; idt.vertMt=0; plotSwFlags=1;
	loadData; loadGrd; review; 
	dvl; deltaT; wallPlot; plotDvlSide; 
	terrainPlotPsi;	
	% Translate wpw to local to make Matlab 3D fast.  SermN&E are in
        % terrainPlotPsi.  Hand copy SermN&E to plot the original data.
	wpw.data(:,wpw.eastings) = wpw.data(:,wpw.eastings)-SermEasting;
	wpw.data(:,wpw.northings) = wpw.data(:,wpw.northings)-SermNorthing;
	bergPlot4;
      elseif( strncmp(missionFileName,'Cubes.cfg',7))
	npbeams=119; idt.vertMt=0; plotSwFlags=1;
	loadData; review; dvl; deltaT; wallPlot; plotDvlSide; bergPlot2;
      elseif( strcmp(missionFileName,'Flat4c.cfg') )
	npbeams=119; idt.vertMt=1; loc= 'portu';
	loadData; loadGrd; review; dvl; deltaT
      elseif( strncmp(missionFileName,'Port',4) )
	% if(strncmp(missionFileName,'PortAllNo',9)) 
	%   deci = 5;
	% else
	%   deci=2; 
	% end
	deci = 5;
	npbeams=119; idt.vertMt=1; loc= 'portu';
	loadData; 
	loadGrd; review; dvl; deltaT; terrainPlotPsi; 
	plotThetaB; plotSurf
      elseif( strcmp(missionFileName,'SimMC1850.cfg') || ...
	      strcmp(missionFileName,'20150827_IcebergTesting_m1v4_rob.cfg'))
	npbeams=119; idt.vertMt=1; loc= 'MC1850';
	loadData; loadGrd; review; dvl; deltaT; terrainPlot; plotSurf
      elseif( strcmp(missionFileName,'SimMC2800.cfg') )
	npbeams=119; idt.vertMt=1; loc= 'MC2800';
	loadData; loadGrd; review; dvl; deltaT; terrainPlot; plotSurf
      elseif( strncmp(missionFileName,'Plateau',7) )
	npbeams=119; idt.vertMt=1; loc='plateau';
	loadData; loadGrd; review; dvl; deltaT; plotThetaB; plotSurf
      elseif( strncmp(missionFileName,'Transect.cfg',7) || ...
	      strncmp(missionFileName,'Diamond.cfg',7) || ...
	      strncmp(missionFileName,'EarlyDiamondLaunch.cfg',7) || ...
	      strncmp(missionFileName,'SingleTransect.cfg',12) )
	loc='upper';loadData; loadGrd; review; dvl; plotSurf
      elseif( strncmp(missionFileName,'InshoreDock.cfg.pp',7) )
	loadData; review; miss
      elseif( strncmp(missionFileName,'2016_WallTestSide',17) )
	%
	% Must come before the one below, which checks a shorter
        % sub-string. 
	%
	%loc='wallside';
	npbeams=119; idt.vertMt=0; plotSwFlags=1; loc = 'wall'; 
	loadData; loadGrd; review; dvl; deltaT; plotSurf; wallPlot;
	plotDvlSide; terrainPlotSide
      elseif( strcmp(missionFileName,'Wall2014.cfg') || ...
              strcmp(missionFileName,'Wall2014Escape.cfg') || ...
	      strcmp(missionFileName,'2013_WallTest_12v1_withresonR1.cfg.pp') || ...
	      strcmp(missionFileName,'2013_WallTest_11v1R2pp.cfg') || ... 
	      strncmp(missionFileName,'2016_WallTest_15v1.cfg.pp',13) || ...
	      strncmp(missionFileName,'2017_WallTest',13) || ...
	      strncmp(missionFileName,'2017_TrnTest',12) || ...
	      strncmp(missionFileName,'TrnTestSouth',12) )
	npbeams=119; idt.vertMt=0; plotSwFlags=1; loc='wall';
	loadData; loadGrd; review; dvl; deltaT; plotSurf; wallPlot;
	if( exist('dvlSide') ) terrainPlotSide; end
      else
	fprintf('Unrecognized scenario.\n')
      end
    else
      %loadData; review; dvl
      npbeams=119; idt.vertMt=1; loc= 'portu';
      loadData; loadGrd; review; dvl; deltaT; plotThetaB; deci=2; plotSurf
    end
    if( telapsed > 0 )
      diary('syslog')
      fprintf('\n\n');
      fprintf(['Simulated time = %.1f; Elapsed time = %.1f; '...
	       'speed increase of x%.2f.\n'],...
	      dataNav(end,1), telapsed, dataNav(end,1)/telapsed);
      diary off
    end   
    return
end
