      !call titre(' abcdefghijklmnopqr#1234567890#azertyui#ABCDEFGH# ')
      !end
      subroutine titre(t,larg_in)
      character(*) t
      character(2000) t1
      character,dimension(:,:),allocatable :: tt
      integer option
      n=0
      l=len_trim(t)
      !print*,'titre ',trim(t),l
      lmax=0
      ideb=1
      larg=larg_in
      option=larg/100
      larg=mod(larg,100)

      ! Eventuellement, redecoupage de t
      l=len_trim(t)
      !print*,'l',l
      if(l<1900) then
         t1=t
         ideb=1
         !print*,trim(t1)
         do k=1,10
            !print*,trim(t1)
            !print*,trim(t1(ideb:))
            i=index(t1(ideb:),'#')
            !print*,'ideb,i',ideb,i
            if(i==0) exit
            if(i>larg_in) then
               ipos=-1+larg_in+6
               !print*,'i,larg_in',i,larg_in-6,ipos
               t1(ipos+1:)=t1(ipos:)
               t1(ipos:ipos)='#'
               l=l+1
               ideb=ipos+1
            else
               ideb=ideb+i+1
            endif
         enddo
      endif
      ! Fin redecoupage t
      
      ! Calculs: n=nb de lignes ; lmax=longueur max d'une ligne
      ideb=1
      do k=1,l
         !if(option==3)print*,'t1(k:k)',k,'   ',t1(k:k),ideb
         if(k.eq.l+1.or.t1(k:k)=='#') then
            long=k-ideb
            n=n+1
            lmax=max(lmax,long)
            ideb=k+1
         endif
      enddo
      lmax=max(larg,lmax)
      n=n+1
      !

      marge=(80-lmax)/2-2
      if(marge>=80.or.marge<=0) then
         print*,'marge',marge
         print*,'lmax',lmax
         print*,'erreur dans titre'
         print*,t
         return
      endif
      allocate (tt(n+3,80-marge))
      !print*,'lmax',lmax
      !print*,'marge',marge

      ! Fabrication du cadre
      tt=' '
      if(option<=1) then
         tt(1,marge+1:80-marge)='*'
         tt(n+2,:)=tt(1,:)
         tt(:,marge)='*'
         tt(:,80-marge)='*'
      else if(option==2) then
         tt(1,2:lmax+4)='_'
         tt(n+2,:)=tt(1,:)
         tt(2:,1)='|'
      else if(option==3) then
         tt(1,2:lmax+2)='='
         tt(n+1,:)=tt(1,:)
      endif
      ideb=1
      ll=1
      mm=marge+lmax/2+2
      !print*,'l',l
      do k=1,l
         !print*,'t1(k:k)',t1(k:k)
         if(t1(k:k)=='#') then
            long=k-ideb
            long2=long/2-1+mod(long,2)
            ll=ll+1
            !print*,'long',k,long,mm-long/2,mm+long/2
            if(option==1) then
               tt(ll,marge+3:marge+3+long2+long/2)
     *         =(/(t1(kk:kk),kk=ideb,k-1)/)
            elseif(option==2) then
               tt(ll+1,3:3+long2+long/2)
     *         =(/(t1(kk:kk),kk=ideb,k-1)/)
            elseif(option==3) then
               tt(ll,3:3+long2+long/2)
     *         =(/(t1(kk:kk),kk=ideb,k-1)/)
            else
               tt(ll,mm-long/2:mm+long2)=(/(t1(kk:kk),kk=ideb,k-1)/)
               !print*,'T ',(/(t1(kk:kk),kk=ideb,k-1)/)
            endif
            ideb=k+1
         endif
      enddo
      !do k=1,n+2
      !print'(100a1)','tt ',tt(k,:)
      !enddo
      print*,' '
      if(option==3) then
         do k=1,n+1
            print'(80a)',(tt(k,ll),ll=1,80-marge)
         enddo
      else
         do k=1,n+2
            print'(80a)',(tt(k,ll),ll=1,80-marge)
         enddo
      endif
      print*,' '

      deallocate(tt)
      return
      end
      function tchar(i)
      character(20) :: tchar
      character(10) :: format1
      character(20) :: c
      tchar=' '
      format1='(i)'
      write(c,*) i
      c=adjustl(c)
      l=len_trim(c)
      write(c,*) l
      c=adjustl(c)
      format1='(i'//trim(c)//')'
      !print*,'format1 ',format1
      write(tchar,format1) i
      end
