      subroutine reoriav(u,occup,tipo,cas,nd,nd1,nd2,nd3,ndims,noacs)
      double precision u(nd,nd1),occup(nd1)
      character(12) tipo(nd1)
      character(3) cas
      integer,allocatable :: iac(:),inac(:)
      double precision,allocatable :: u1(:,:),occuptmp(:)
      character(12),allocatable :: tiptmp(:)
      allocate (iac(ndims),inac(ndims))
      allocate(u1(nd,nd1),occuptmp(nd1),tiptmp(nd1))
      !print*,'nd1,nd2,nd3',nd1,nd2,nd3
      if(nd1/=nd2) then
          print*,'nd1.ne.nd2'
          print*,'nd1,nd2',nd1,nd2
          stop
      endif
      if(nd1/=nd3) then
          print*,'nd1.ne.nd3'
          print*,'nd1,nd3',nd1,nd3
          stop
      endif
      if(nd1/=nd3) stop'nd1.ne.nd3'
      ! Place des actives
      kka=0
      kki=0
      do k=1,nd1
         if(tipo(k)(1:2)=='A_') then
            kka=kka+1
            iac(kka)=k
            noacs=noacs+1
         else
            kki=kki+1
            inac(kki)=k
         endif
      enddo
      if(cas=='occ') then
         u1(:,1:kki)=u(:,inac(1:kki))
         occuptmp(1:kki)=occup(inac(1:kki))
         tiptmp(1:kki)=tipo(inac(1:kki))
         u1(:,1+kki:nd1)=u(:,iac(1:kka))
         occuptmp(1+kki:nd1)=occup(iac(1:kka))
         tiptmp(1+kki:nd1)=tipo(iac(1:kka))
      else
         u1(:,1:kka)=u(:,iac(1:kka))
         occuptmp(1:kka)=occup(iac(1:kka))
         tiptmp(1:kka)=tipo(iac(1:kka))
         u1(:,1+kka:nd1)=u(:,inac(1:kki))
         occuptmp(1+kka:nd1)=occup(inac(1:kki))
         tiptmp(1+kka:nd1)=tipo(inac(1:kki))
      endif
      u=u1
      tipo=tiptmp
      occup=occuptmp
      deallocate (iac,inac,u1,occuptmp,tiptmp)
      return
      end


