function wraminfil( thetitle, source_info, ssp_info, bathymetry_info, pe_info, output_info )

% Writes RAM input file. 
%
% SYNTAX: wraminfil( title, source, ssp, bottom, pe, output )
%

%*******************************************************************************
% Gambelas, 24/10/2008 at 15:30
% Written by Tordar 
%*******************************************************************************
% Get source data: 

freq     = source_info.f;
zs       = source_info.zs;

%*******************************************************************************
% Get sound speed data: 

c    = ssp_info.c;
z    = ssp_info.z; 
r    = ssp_info.r;

%*******************************************************************************
% Get bathymetry data:

    rbty = bathymetry_info.x(1,:) ;
    zbty = bathymetry_info.x(2,:) ;
    cbty = bathymetry_info.c      ;
  rhobty = bathymetry_info.rho    ;
alphabty = bathymetry_info.alpha  ; 

    nbty = length( rbty ) ; 
 
%*******************************************************************************
% Get pe data:

    np = pe_info.np ;
    ns = pe_info.ns ;
    c0 = pe_info.c0 ;
    rs = pe_info.rs ;
    
%*******************************************************************************  
% Get output data: 

zr      = output_info.zr    ;
rmax    = output_info.Rmax  ;
zmax    = output_info.Dmax  ;
dr      = output_info.dr    ;
dz      = output_info.dz    ;
ndr     = output_info.ndr   ;
ndz     = output_info.ndz   ;
zmplt   = output_info.zmplt ;

%*******************************************************************************  
% Write the INFIL: 
 
fid = fopen('ram.in','w');
fprintf(fid,'%s\n',thetitle);
fprintf(fid,'%f %f %f\n',freq,zs,zr );
fprintf(fid,'%f %f %d\n',rmax,dr,ndr);       
fprintf(fid,'%f %f %d %f\n',zmax,dz,ndz,zmplt);
fprintf(fid,'%f %d %d %f\n',c0,np,ns,rs); data = [rbty;zbty];
fprintf(fid,'%f %f\n',data);
fprintf(fid,'-1 -1\n');

for i = 1:1

    data = [z(:,i) c(:,i)]';
    
    fprintf(fid,'%f %f\n',data);
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),cbty(i));
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),rhobty(i));
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),alphabty(1,i));
    fprintf(fid,'%f %f\n',   zmax,alphabty(2,i));
    fprintf(fid,'-1 -1\n');

end 

for i = 2:nbty

    data = [z(:,i) c(:,i)]';
    
    fprintf(fid,'%f\n',rbty(i));
    fprintf(fid,'%f %f\n',data);
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),cbty(i));
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),rhobty(i));
    fprintf(fid,'-1 -1\n');
    fprintf(fid,'%f %f\n',zbty(i),alphabty(1,i));
    fprintf(fid,'%f %f\n',   zmax,alphabty(2,i));
    fprintf(fid,'-1 -1\n');

end

fclose( fid );
