% Execute the SimCARPE3D code.
% td 28 May 2009
% td 20 July 2023

clear
format compact

! rm diary.txt
diary diary.txt

disp(' host:')
eval('! hostname');
disp(' ')
! cat /etc/os-release
disp(' ')
! lscpu
disp(' ')
[ 'script executed : ' date]
disp (' ')

%%    specify parameters

rng=   20000;  % max x propagation distance
f0=200; % Hz   %  single frequency to compute, or initial frequuency for broadband
           % code rev11 needs modification to do broadband
zs= 20;  % source depth
depP= 95 ;  % water depth  % used for plotting only, when Enfile='Wedge002' or Wedge003
steplamb=1;  % x step length in wavelength units
ny=2^11  % number of y points
aspect=4;   % ascpect ratio, delta y over delta z of compute grid
 % numericalaspect=2;
nz= 2*ny/aspect   % number of z points, including image ocean

nout=4;  % number of outputs as it steps along, final one is at final range.
c0=1500; % benchmark sound speed


% filen='test267.mat';  % input file for environmental data, this one has sound speed
 % made from enviromental data
% Envfile='testmoordataZvar' ;  % variable bottom depth
  % uses filen, alternative would be to have this synthesize fields

  
% April 2023 wedge case. Uniform in x,y SVP from test301.mat, via make_test302.m .

rangedep=1;

params.range_update_in_meters = 22.5;

switch rangedep
    
    case 1
        rdcw_flag=1; % zero for range independent
        runcode='layered302RangeDep_Wedge003';
        filen='layered302rd' ; %  file with watercolumn sound speed
        Envfile='Wedge003'  % file that reads filen and makes bathymetry
        
    case 0
        rdcw_flag=0; % zero for range independent
        runcode='layered302RangeIndep_Wedge003';
        filen='layered302ri' ; %    % file with watercolumn sound speed
        Envfile='Wedge003'  % file that reads filen and makes bathymetry
        
end

params.rng=rng;
params.f0       =f0 ;
params.zs       =zs; 
params.depP     =depP ; 
params.steplamb =steplamb;  
params.ny       =ny; 
params.aspect   =aspect;  
params.nz       =nz;
params.nout     =nout;
params.c0       =c0;   
params.rdcw_flag=rdcw_flag;
params.filen    =filen;
params.Envfile  =Envfile;


%% end parameters. Now run 3DPE. Save output and two plots. ........................
      
      
for ys= [ 500 ] % source y position, meters, can loop on this, for example, as written.
              % or modify to loop on another parameter.

  params.ys=ys;
  
  close all
  
  outfile=[runcode num2str(round(ys)) ]
      
  simulata= CARPE3D(params);
  
  % save(outfile,'psifinal','xgg','ygg','rgg','zgg','Ez', 'Af')
  save (outfile, 'simulata');
  
  figure(3)
  hold on
  text(0,0,runcode,'interpreter','none');
  print('-dpng','-r200',[runcode 'Figure3_ys' num2str(round(ys))])
  pause(2)
  figure(4)
  hold on
  text(500,-zs,runcode,'interpreter','none');
  print('-dpng','-r200',[runcode 'Figure4_ys' num2str(round(ys))])
end


diary off

