function [bdf]=basic_depth_fct(z,HW,HB,NL,enl,fnl,gnl,hnl,M)
% This script evaluates the test functions in the combined Legendre 
% polynomial spanning set, at the depth z. These functions are used in 
% the expansion that approximates the acoustic normal modes.
% It calls the legpoly function.
%
      NLM1=NL-1;
      hwo2=HW/2.0d0;
      hbmhwo2=(HB-HW)/2.0d0;
      hbphwo2=(HB+HW)/2.0d0;
%
      bdf=zeros(M,1);
   for I=1:M % Loop over index in combined polynomial spanning set
%
      if z <= HW
      xw=(z-hwo2)/hwo2;
      [p,d]=legpoly(NL,xw);
         if I <= NLM1 % I=1:NL-1
         ik=I-1;
         pw=p(1,ik+1)+(enl(ik+1)+(-1)^(ik+NL))*p(1,NL)+ ...
                                       enl(ik+1)*p(1,NL+1);
         else % I=NL:2*N-2
         ik=I-NL;
         pw=fnl(ik+1)*(p(1,NL)+p(1,NL+1));
         end
      bdf(I)=pw;
      else % z > HW
      xb=(z-hbphwo2)/hbmhwo2;
      [p,d]=legpoly(NL,xb);
         if I <= NLM1
         ik=I-1;
         pb=gnl(ik+1)*(-p(1,NL)+p(1,NL+1));
         else
         ik=I-NL;
         pb=p(1,ik+1)-(hnl(ik+1)+1.0d0)*p(1,NL)+hnl(ik+1)*p(1,NL+1);
         end
      bdf(I)=pb;
      end
 %
   end % End loop over index in combined polynomial spanning set