function z=get_depths(fname,gname,tindex,type);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  Get the depths of the sigma levels
%
%  Further Information:  
%  http://www.brest.ird.fr/Roms_tools/
%  
%  This file is part of ROMSTOOLS
%
%  ROMSTOOLS is free software; you can redistribute it and/or modify
%  it under the terms of the GNU General Public License as published
%  by the Free Software Foundation; either version 2 of the License,
%  or (at your option) any later version.
%
%  ROMSTOOLS is distributed in the hope that it will be useful, but
%  WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%  GNU General Public License for more details.
%
%  You should have received a copy of the GNU General Public License
%  along with this program; if not, write to the Free Software
%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
%  MA  02111-1307  USA
%
%  Copyright (c) 2002-2006 by Pierrick Penven 
%  e-mail:Pierrick.Penven@ird.fr  
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  ncload(gname,'h');

  %
  % open history file
  %
  nc=netcdf(fname);
  
  zeta=squeeze(nc{'zeta'}(tindex,:,:));
%%  zeta=([]);
  
  theta_s=nc.theta_s(:);
  
  if (isempty(theta_s))
    %  disp('Rutgers version')
    theta_s=nc{'theta_s'}(:);
    theta_b=nc{'theta_b'}(:);
    Tcline=nc{'Tcline'}(:);
  else 
    %  disp('UCLA version');
    theta_b=nc.theta_b(:);
    Tcline=nc.Tcline(:);
  end

  if (isempty(Tcline))
    %  disp('UCLA version 2');
    hc=nc.hc(:);
  else
    hmin=min(min(h));
    hc=min(hmin,Tcline);
  end 
  
  N=length(nc('s_rho'));
  
  close(nc);
  
  %
  %
  %
  if isempty(zeta)
    zeta=zeros(size(h));
  end

  vtype=type;
  if (type=='u')|(type=='v')
    vtype='r';
  end
  z=roms_zlevs(h,zeta,theta_s,theta_b,hc,N,vtype);
  if type=='u'
    z=rho2u_3d(z);
  end
  if type=='v'
    z=rho2v_3d(z);
  end
  
  return
