function orca_ram_run
%
%
% COPYRIGHT (c) 2008
% 
% Applied Research Laboratories, The University of Texas at Austin
% (ARL:UT)
% All rights reserved.
% 
% This material may be reproduced by or for the U.S. Government
% only. This notice must appear in all copies of this file and its
% derivatives. Further distribution outside the U.S. Government is
% prohibited without the explicit written authorization from the
% Director of the Environmental Sciences Laboratory, ARL:UT.
% 
% THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
% EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE
% IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
% PURPOSE, OR NONINFRINGEMENT.
% 
% IN NO EVENT WILL ARL:UT BE LIABLE FOR ANY DAMAGES WHATSOEVER ARISING
% OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN IF ARL:UT HAS
% BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
orca_global
%
SVP=adi_svp_read([ORC.adi_dir,ORC.svp_root]);
GAP=adi_svp_interpret(SVP);
iiparm=[1,1,1,4,1]; safety_fac=1, iires=1;
zs=adi_lim_eval(ORC.zs_lims); nzs=length(zs);
freq=adi_lim_eval(ORC.cw_freqs); nfreq=length(freq); nrun=0; suf=[];
freq0=mean(freq);
depths=adi_lim_eval(ORC.zr_lims);
if length(depths)>1, delz=diff(depths(1:2)); else, delz=0; end
ranges=adi_lim_eval(ORC.rng_lims);
if length(ranges)>1, delr=1000*diff(ranges(1:2)); else, delr=0; end
%
ram_root=['ramPE_runs'];
for jf=1:nfreq,
	for jzs=1:nzs,
		PE_convert_ri(ram_root,SVP,GAP,zs(jzs),ORC.rng_lims(2),freq(jf), ...
			safety_fac,iires,freq0,delr,delz);
% Run RAM PE if available:
		ramp([ram_root,'.in'],ram_root);
%        
		SD=hdfsd_open([ram_root,'.hdf']);
		[TL,status]=hdfsd_read(SD,[],1);
        disp(TL.dims);
		[PHASE,status]=hdfsd_read(SD,[],2);
        if jf==1 & jzs==1,
            nzr=TL.dims(1); nrng=TL.dims(2);
            TL_dB=zeros(nzr,nrng,nzs,nfreq); TL_phase=TL_dB;
            zr_ax=TL.scales{1}; rng_ax=TL.scales{2};
        end
        TL_dB(:,:,jzs,jf)=TL.data;
        TL_phase(:,:,jzs,jf)=PHASE.data;
	end
end
%
% eval(['!del ',ram_root,'*']);
%     
hdf_root=[ORC.out_root]; SDw=[]; jset=1; dlab='PE TL - dB';
dims=[nzr,nrng,nzs,nfreq]; scales={zr_ax rng_ax zs(:)' freq(:)'};
labels={'Depth - m', 'Range - km', 'Source Depth - m','Frequency - Hz'};
[SDw,stat]=hdfsd_write_open(hdf_root,SDw,1,dlab,dims,scales,labels);
[stat]=hdfsd_write(SDw,1,[],TL_dB);
%
dlab='PE TL Phase - deg';
[SDw,stat]=hdfsd_write_open(hdf_root,SDw,2,dlab,dims,scales,labels);
[stat]=hdfsd_write(SDw,2,[],TL_phase);
stat=hdfsd_write_close(SDw);
%
disp(['Finished writing PE TL file ',hdf_root,'.hdf']);
