      subroutine rang0(nat,ial)
c---------------------------------------------------------------------
c     nat = nb d'orb actives
c     ial = nb d'electrons alpha (ou beta)
c---------------------------------------------------------------------
      PARAMETER (maxorbcas=16)
      IMPLICIT INTEGER(A-H,O-x,z),logical*1(y)
      common /z/ iz(maxorbcas,maxorbcas,maxorbcas)
c     common/gen/nfr,natof(4),natom,matof(4),
c    *nalf(jrangmax),ndetf(nfrmax),ial0
      dimension C(0:maxorbcas,-1:maxorbcas-1)
      yw=.false.
      IF(ial.EQ.0) RETURN
C===CALCUL DE C
      DO I=0,maxorbcas
         DO J=-1,maxorbcas-1
            C(I,J)=-50
         ENDDO
      ENDDO
      DO 1 I=0,nat
c   C(I,J)=combinaison de J parmi I
      C(I,-1)=0
      C(I,0)=1
      C(I,1)=I
      DO 2 J=2,ial-1
      IF(J.GT.I) GOTO 2
      C(I,J)=(C(I,J-1)*(I-J+1))/(J)
      if(yw)write(6,*)'c(i,j),i,j',c(i,j),i,j
 2    CONTINUE
 1    CONTINUE
      if(yw)write(6,*)'c(i,j)'
      do i=0,nat
         if(yw)write(6,'(20i4)')(c(i,j),j=-1,ial-1)
      enddo
      DO 4 L=1,nat
      IFIN=MIN0(ial-1,L)
      DO 3 K=1,IFIN
      IZZ=0
      DO 5 M=nat-L+1,nat-K
      if(yw)write(6,*)'izz',izz
 5    IZZ=IZZ+C(M,ial-K)-C(M-1,ial-K-1)
      if(yw)write(6,*)'izz',izz
      iz(K,L,ial)=IZZ
 3    CONTINUE
      iz(ial,L,ial)=L-ial
 4    CONTINUE
      if(yw)write(6,*)'iz ial',ial
      do i=1,maxorbcas
         if(yw)write(6,'(20i4)')(iz(i,j,ial),j=1,maxorbcas)
      enddo
      RETURN
      END
