      subroutine ecr(b,l,n,ifil)
      parameter (ngru3=2048)
      IMPLICIT REAL(8)(A-H,O-Z)
      dimension b(n)
!      print*,'n',n
!      write(6,*)'ecr l,n,ifil',l,n,ifil
      nn=(n-1)/ngru3
      ll=(l-1)*(nn+1)
      do k=1,n,ngru3
         ll=ll+1
c          write(ifil,rec=l) b
         long=min0(ngru3,n-k+1)
         call ecric(b(k),ll,long,ifil)
      enddo
      return
      end
       subroutine ecric(b,ll,long,ifil)
      IMPLICIT REAL(8)(A-H,O-Z)
      dimension b(long)
      irec=ll
      if(ifil==22.or.ifil==21) then
c         print*,'ecric ll',ll,ifil,long
         inquire(ifil,RECL=long2)
c         print*,'ecr.f',ifil,ll,long,long2
         call filesplit('WRITE',ifil,long2,ichange,irec)
!         if(ichange==1)
!     *   print*,'****CLOSE/OPEN en ecriture  sur file',ifil
         call flush(6)
      endif
      !if(ifil==22) print*,'ECRITURE 22',ll
      write(ifil,rec=irec) b
      return
      end
