      module modlirin
      integer,save ::  nint,l_ijcl,nrec_ijcl,ifint
      integer(2),save,dimension(4096) :: iint,jnt,knt,lnt
      double precision,save,dimension(4096) :: aaint
      contains
       subroutine liri00(val)
      use module
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      logical,optional,intent(in) :: val
      logical yval
      yw=.false.
      yval=.true.
      if(present(val)) yval=val
      !yval=.not.(present(val).and..not.val)
      close(ifint)
      if(yw)print'(''ycl'',l2)', ycl
      if(ycl) then
              open(ifint,file=ijcl1,form='formatted',status='old')
      else
              open(ifint,file=ijcl1,form='unformatted',status='old')
      endif
      if(ycl) return
      if(yval) then
              read(ifint) iint,jnt,knt,lnt,aaint
      else
              read(ifint) iint,jnt,knt,lnt
      endif
      nint=0
      l_ijcl=1
      nrec_ijcl=0
      return
      end subroutine
       subroutine lirin(i,j,k,l,a,val)
      use module
      IMPLICIT REAL(8)(A-H,O-X,Z),logical(1)(y)
      character(3) c
      character(80) ijcl2
      logical,optional,intent(in) :: val
      logical yval
      yval=.true.
      if(present(val)) yval=val
      !yval=.not.(present(val).and..not.val)
      c='_  '
 1    if(ycl) then
         if(.not.yval) then
                 read(ifint,*)i,j,k,l
         else
                 read(ifint,*)i,j,k,l,a
         endif
      else
         nint=nint+1
         if(nint.gt.4096) then
            l_ijcl=l_ijcl+1
            if(l_ijcl.gt.nb_ijcl) then
               l_ijcl=1
               nrec_ijcl=nrec_ijcl+1
               if(nrec_ijcl.le.9) then
                  write(c(2:2),'(i1)') nrec_ijcl
               else
                  write(c(2:3),'(i2)') nrec_ijcl
               endif
               close(ifint)
               ijcl2=trim(ijcl1)//c
               open(ifint,file=ijcl2,form='unformatted',status='old')
            endif
            if(.not.yval) then
                    read(ifint) iint,jnt,knt,lnt
            else
                    read(ifint) iint,jnt,knt,lnt,aaint
                    !print*,'lect',iint(1),jnt(1),knt(1),lnt(1),aaint(1)
            endif
            nint=1
         endif
         i=iint(nint)
         j=jnt(nint)
         k=knt(nint)
         l=lnt(nint)
         if(yval) a=aaint(nint)
      endif
      if(yval.and.dabs(a).lt.sint) then
         if(k.ne.0) then
            ilimi=ilimi+1
            a=0.d0
         endif
      endif
      return
      end subroutine
      end module
