%==================================================================
%  
%  TRACEO: Pekeris upslope example.
%  Gambelas, Sat Jun 14 16:30:47 WEST 2014
%  Written by Tordar 
%  
%==================================================================

system('rm -rf cpr.mat');

clear all, close all 

case_title = '''Pekeris waveguide & coherent pressure''';

%==================================================================
%  
%  Define source data:
%  
%==================================================================

freq   =  125;
Rmaxkm =    5; Rmax = Rmaxkm*1000;
Dmax   =  100; 

ray_step = 5; 

zs = 50; rs = 0; thetamax = 45; nthetas = 101; thetas = linspace(-thetamax,thetamax,nthetas);

source_data.ds       = ray_step;
source_data.position = [rs zs];
source_data.rbox     = [rs-1 Rmax+1];
source_data.f        = freq;
source_data.thetas   = thetas;

%==================================================================
%  
%  Define altimetry data:
%  
%==================================================================

altimetry = [rs-2 Rmax+2;0 0];

surface_data.type  =   '''V'''; 
surface_data.ptype =   '''H'''; % Homogeneous
surface_data.units =   '''W'''; % (Attenuation Units) dB/Wavelenght
surface_data.itype =  '''FL'''; % Sea surface interpolation type
surface_data.x     = altimetry; % Surface coordinates
surface_data.properties = [0 0 0 0 0]; % Dummy values

%==================================================================
%  
%  Define sound speed data:
%  
%==================================================================

c0 = 1500;

ssp_data.cdist = '''c(z,z)'''; % Sound speed profile

ssp_data.cclass = '''ISOV'''; % Isovelocity profile

ssp_data.z   = [0 Dmax]';
ssp_data.r   = [];
ssp_data.c   = [c0 c0]';

%==================================================================
%  
%  Define object data:
%  
%==================================================================

object_data.nobjects = 0; % Number of objects

%==================================================================
%  
%  Define bathymetry data:
%  
%==================================================================

bathymetry = [rs-2 rs Rmax Rmax+2;Dmax Dmax Dmax*0.5 Dmax*0.5];

bottom_data.type   = '''E''' ;
bottom_data.ptype  = '''H''' ; % Homogeneous bottom
bottom_data.units  = '''W''' ; % Bottom attenuation units
bottom_data.itype  = '''2P'''; % Bottom interpolation type 
bottom_data.x      = bathymetry; % Bottom coordinates 
bottom_data.properties = [1700 0 1.7 0.7 0]; % [cp cs rho ap as]

%==================================================================
%  
%  Define output data:
%  
%==================================================================

nra = 201; rarray = linspace(0,Rmax,nra);
nza = 201; zarray = linspace(0,Dmax,nza);

output_data.ctype       = '''CPR'''; 
output_data.array_shape = '''RRY''';
output_data.r           = rarray;
output_data.z           = zarray;
output_data.miss        = 0.5;

%==================================================================
%  
%  Call the function:
%  
%==================================================================

disp('Writing TRACEO waveguide input file...')

wtraceoinfil('pekeris.in',case_title,source_data,surface_data,ssp_data,object_data,bottom_data,output_data);

disp('Calling TRACEO...')

system('runtraceo pekeris');

load cpr

tl = 20*log10( abs( pressure ) );

figure(1), hold on
plot(rs,zs,'ko',rs,zs,'m*','MarkerSize',16)
plot(bathymetry(1,:),bathymetry(2,:),'k','LineWidth',2)
pcolor(rarray,zarray,tl), shading interp, colorbar
axis([0 Rmax 0 Dmax])
view(0,-90)
hold off 
xlabel('Range (m)')
ylabel('Depth (m)')
title('TRACEO - Pekeris waveguide, acoustic pressure')

disp('done.')
