function SSP=hep_ssp_convert(ssp_suf,out_root,BATHY,lats,longs,jdays,hours)
%
% Call SSP=hep_ssp_convert(ssp_suf,out_root,BATHY,lats,longs,jdays,hours);
%
%
% 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.
if nargin<3, out_root=[]; end
if nargin<4, lats=[]; longs=[]; end
if nargin<6, jdays=[]; hours=[]; end
%
ssp_files=dir(['*',ssp_suf]);
nfile=length(ssp_files);
SSP.out_root=out_root;
SSP.ssp_files=ssp_files;
SSP.nssp=nfile; SSP.bathy_root=BATHY.bathy_root;
for jfile=1:nfile,
    ssp=load(ssp_files(jfile).name); npt=size(ssp,1);
    if abs(ssp(1,2))>5, 
        disp(['Warning: First SSP depth not so close to zero: ',num2str(ssp(1,2))]);
    end
    if ssp(1,2)~=0, disp('Setting first SSP depth to zero...'); ssp(1,2)=0; end
    ii=find(diff(ssp(:,2))>0); 
    if length(ii)<npt-1, 
        disp(ssp); disp('Deleting mis-ordered points: '); 
        ssp=ssp([1;ii+1],1:2); disp(ssp); 
    end
    done=0;
    while ~done,
        if isempty(lats),
            disp(['Need info for file name ',ssp_files(jfile).name,':']);
            str=input('Enter lat as decimal or [deg,hour,min]: ','s');
            lat=str2num(str);
            str=input('Enter long as decimal or [deg,hour,min]: ','s');
            long=str2num(str);
        else
            lat=lats{jfile}; long=longs{jfile};
        end
        if length(lat)==3, 
            sg=sign(lat(1)); lat=lat(1) + sg*lat(2)/60 + sg*lat(3)/3600;
        end
        if length(long)==3, 
            sg=sign(long(1)); long=long(1) + sg*long(2)/60 + sg*long(3)/3600;
        end
        hw=interp2(BATHY.lat,BATHY.long,BATHY.hw',lat,long);
        if isnan(hw), disp('Entered Lat,Long outside those in BATHY'); else; done=1; end
    end
    if isempty(jdays),
        disp(['Need info for file name ',ssp_files(jfile).name,':']);
        str=input('Enter Julian day or [jmo,day]: ','s');
        jday=str2num(str);
        str=input('Enter hour of day as decimal or [hour,min,sec]: ','s');
        hour=str2num(str);
    else
        jday=jdays{jfile}; hour=hours{jfile};
    end
    if length(jday)==2, jday=date_to_Jday(jday(1),jday(2)); end
    if length(hour)==3, hour=hour(1) + hour(2)/60 + hour(3)/3600; end
%
    ii=find(ssp(:,2)<=hw);
    zax=ssp(ii,2); cax=ssp(ii,1);
    if zax(end)<hw, 
        zax=[zax; hw]; 
        cax=[cax; interp1(ssp(:,2),ssp(:,1),hw)]; 
    end
    SSP.ssp{jfile}=[zax,cax];
    SSP.npt(jfile)=length(zax);
    SSP.hw(jfile)=hw;
    SSP.lat(jfile)=lat;
    SSP.long(jfile)=long;
    SSP.jday(jfile)=jday;
    SSP.hour(jfile)=hour;
end
%
if ~isempty(out_root),
    str=['save ',out_root,'_SSP SSP']; disp(str); eval(str);
else
    disp('Empty output file root specified - will not save in _SSP.mat file.');
end
