      subroutine mr2sbis(iocc,mint,minp,maxt,maxp)
c      subroutine mr2sbis(nca,ncb,ica,icb,mint,minp,maxt,maxp)
      implicit real*8(a-h,o-x,z),logical*1 (y)
      parameter(maxorb=1024,nsymz=8)
      parameter(maxorbcas=16)
      parameter(maxref=15000)
      character*8 gener
      common/gene/gener,ygcas,ygmono,ygmr
      common/ocref/ iocref(maxorb,maxref),nref
      common/occ/noac,nelac,numac(maxorbcas),is0,ninac,nvirt
     *,numt(maxorb),nump(maxorb),ntac,nutac(maxorbcas),ms2
      common/mr/nmr,nel,yref(-maxorb:maxorb,maxref)
      common/f4/norb,noc,noca,nocb,nca0,ncb0,ydet,ydetv,ydetcl
     *,ydetsc,yf_act,ywcas,ynosym,ytp0
      dimension iocc(maxorb)
      yw=.false.
c
c--------------------------------------------------------------------
c     calcul de la distance maximale de iocc a tous les det de ref
c--------------------------------------------------------------------
c
c
c     distance aux determinants de reference
c
      idif=5
      if(gener(1:3).ne.'SEL') goto 20
      do kk=1,nref
         ii=0
         if(yw)print*,'iocc   ',(iocc(i),i=1,noac)
         if(yw)print*,'iocref ',(iocref(i,kk),i=1,noac)
         do i=1,noac
            ii=ii+abs(iocc(i)-iocref(i,kk))
            if(ii.gt.4) goto 10
         enddo
         if(yw)print*,'idif',idif
 10      continue
         idif=min(idif,ii)
         if(idif.eq.0) goto 20
      enddo
 20   continue
      if(yw)print*,'idif a la fin ',idif
c
c        nombre d'electrons en plus
c
      nn=0
      do i=1,noac
         nn=nn+iocc(i)
      enddo
      nn=nn-nelac
      if(yw)print*,'nn',nn
      if(gener(1:3).ne.'SEL') then
         idif=iabs(nn)
      endif
c
c        trous et part max
c
      call tpmms(nn,idif,mint,maxt,minp,maxp)
c
      if(yw)write(6,'(a33,6i5)')'mint,minp,maxt,maxp',
     *mint,minp,maxt,maxp
      if(yw)write(6,*)'nca,ncb',nca,ncb
      return
      end
