      subroutine sauvebit(nom,l,nomfen,lf,iformat,ilarg,ihaut)
      character*128 nom,nom2,nomfen
      character*24 coptlogo
      character*11 cgravity(9)
      INCLUDE 'Parametres.f'
      CHARACTER*12 RM
      data cgravity / ' NorthWest ',' North     ',' NorthEast '
     &              , ' West      ',' Center    ',' East      '
     &              , ' SouthWest ',' South     ',' SouthEast ' /
c
c formats:
c   0 : xpm (pas de traduction. Sortie directe de x11sauvexpm)
c   1 : gif (traduction par convert)
c   2 : png (traduction par convert)
c
c pour les images xd3d, table de 75 couleurs, 512x512, 
c l'ordre empirique de tailles, du plus petit au plus gros est :
c   gif entrelace  (40k)
c   gif            (40k)
c   pict           (70k)
c   tiff packbits  (90k)
c   tiff lzw, et tiff  (120k)
c   xwd            (280k)
c   rgb            (3*270k)
c   ppm            (820k)
c
c
ccc      CALL selgraphix11
      RM = ';/bin/rm -f '
      l2 = l+4
      if (iformat.eq.0) then
        nom2(1:l2) = nom(1:l)//'.xpm'
      elseif(iformat.eq.1) then
        nom2(1:l2) = nom(1:l)//'.gif'
      elseif(iformat.eq.2) then
        nom2(1:l2) = nom(1:l)//'.png'
      else
        nom2(1:l2) = nom(1:l)//'.eps'
      endif
      if (albion) then
        print*,
     &'Dump of window: "'//nomfen(1:lf)//'" --> '//nom2(1:l2)
      else
        print*,
     &'Dump de la fenêtre : "'//nomfen(1:lf)//'" --> '//nom2(1:l2)
      endif
      call x11sauvexpm(nom(1:l)//'.xpm'//char(0),ilarg,ihaut)
c
c ajout du logo
c
      if (iaunlogo.gt.0) then
        if (itranslogo.gt.0) then
          write(coptlogo,1000) itranslogo
        else
          coptlogo = ' -compose Over -gravity '
        endif
      endif
 1000 format('    -blend',i4,' -gravity ')
c
      if (iformat.ne.0) then
        if (iformat.eq.3) then
c
c bug de convert ? si on traduit directement de xpm a eps, il manque un
c bout pour les grandes images...
c et des fois ca donne un eps verole.
c
          if (iaunlogo.le.0) then
            call exec('convert '//nom(1:l)//'.xpm /tmp/bidonbidon.png')
          else
            call exec('combine'//coptlogo//cgravity(iaunlogo)
     &       //nom(1:l)//'.xpm '//nomdulogo(1:lnomdulogo)
     &       //' /tmp/bidonbidon.png')
          endif
          call exec('convert /tmp/bidonbidon.png '//nom2(1:l2)
     &         //RM//nom(1:l)//'.xpm /tmp/bidonbidon.png')
        elseif(iformat.eq.1.and.ilestlagifsicle) then
          if (iaunlogo.le.0) then
            call exec('convert '//nom(1:l)//'.xpm '//nom2(1:l2)
     &         //';gifsicle --careful -O2 -b '//nom2(1:l2)
     &         //RM//nom(1:l)//'.xpm')
          else
            call exec('combine'//coptlogo//cgravity(iaunlogo)
     &       //nom(1:l)//'.xpm '//nomdulogo(1:lnomdulogo)
     &           //' '//nom2(1:l2)
     &         //';gifsicle --careful -O2 -b '//nom2(1:l2)
     &         //RM//nom(1:l)//'.xpm')
          endif
        else
          if (iaunlogo.le.0) then
            call exec('convert '//nom(1:l)//'.xpm '//nom2(1:l2)
     &         //RM//nom(1:l)//'.xpm')
          else
            call exec('combine'//coptlogo//cgravity(iaunlogo)
     &       //nom(1:l)//'.xpm '//nomdulogo(1:lnomdulogo)
     &           //' '//nom2(1:l2)
     &         //RM//nom(1:l)//'.xpm')
          endif
        endif
      elseif(iaunlogo.gt.0) then
        call exec('combine'//coptlogo//cgravity(iaunlogo)
     &       //nom(1:l)//'.xpm '//nomdulogo(1:lnomdulogo)
     &       //' /tmp/bidonbidon.xpm; mv -f /tmp/bidonbidon.xpm '
     &       //nom(1:l)//'.xpm')
      endif
      end
c-----------------------------------------------------------------------
      subroutine formats_bit(iformat,ilang)
      logical*4 trouve,trouve2
c
      INCLUDE 'Parametres.f'
c
      if (ibacking.eq.0) then
        print*,' '
        if (ilang.eq.0) then
          print*,
     &         '*** Attention de ne pas cacher la fenêtre de sauvegarde'
          print*,
     &         '*** pendant l''exécution. Pas de "backing store"'
        else
          print*,'*** Be careful: obscured windows during bitmap saving'
          print*,
     &         '*** may cause unpredictable results (no backing store)'
        endif
      endif
      print*,' '
      if (ilang.eq.0) then
        PRINT*,'Sauvegarde d''images(s) bitmap'
        PRINT*,'-----------------------------'
        PRINT*,'Formats disponibles :'
        PRINT*,'  -1 : test (pas de sauvegarde sur disque)'
      else
        PRINT*,'Bitmap files export'
        PRINT*,'-------------------'
        PRINT*,'Available formats:'
        PRINT*,'  -1 : test (no files saved)'
      endif
      PRINT*,'   0 : xpm'
      call quicestceluila('convert',7,trouve,0)
      if (trouve) then
        print*,'   1 : gif'
        print*,'   2 : png'
        print*,'   3 : eps (Bitmap PostScript)'
      endif
      if (ilang.eq.0) then
        PRINT*,'autre: cancel'
        if (trouve)
     &    print*,'(Les formats 1, 2 et 3 sont traduits par "convert")'
        print*,' '
        CALL LIENTIER('Format d''image bitmap choisi ?',0,IFORMAT)
      else
        print*,' else: cancel bitmap export'
        if (trouve)
     &    print*,'(Formats 1, 2 and 3 are translated through "convert")'
        print*,' '
        CALL LIENTIER('Image format chosen?',0,IFORMAT)
      endif
c
c logo
c
      if (trouve.and.iformat.ge.10.and.iformat.le.13) then
        iformat = iformat-10
        call quicestceluila('combine',7,trouve2,0)
        if (trouve2) then
          if (ilang.eq.0) then
            print*,'Vous voulez mettre un logo sur l''image ?'
            print*,'Les positions suivantes sont disponibles :'
            print*,'  0: pas de logo'
            print*,'  1: NorthWest '
            print*,'  2: North     '
            print*,'  3: NorthEast '
            print*,'  4: West      '
            print*,'  5: Center    '
            print*,'  6: East      '
            print*,'  7: SouthWest '
            print*,'  8: South     '
            print*,'  9: SouthEast '
            call lientier('Position du logo ?',0,iaunlogo)
            if (iaunlogo.lt.0.or.iaunlogo.gt.9) iaunlogo = 0
            if (iaunlogo.gt.0) then
              call lifich('Nom du fichier contenant le logo à insérer ?'
     &             ,0,nomdulogo,lnomdulogo)
              call lientier(
     &          'Transparence du logo (0-> opaque, 100-> transparent) ?'
     &             ,0,itranslogo)
              itranslogo = max(0,itranslogo)
              if (itranslogo.ge.100) then
                print*,'*** complètement transparent <=> pas de logo !'
                iaunlogo = 0
              endif
            endif
          else
            print*,'Do you want to put a logo on the picture ?'
            print*,'Possible positions for the logo :'
            print*,'  0: no logo'
            print*,'  1: NorthWest '
            print*,'  2: North     '
            print*,'  3: NorthEast '
            print*,'  4: West      '
            print*,'  5: Center    '
            print*,'  6: East      '
            print*,'  7: SouthWest '
            print*,'  8: South     '
            print*,'  9: SouthEast '
            call lientier('Logo''s position ?',0,iaunlogo)
            if (iaunlogo.lt.0.or.iaunlogo.gt.9) iaunlogo = 0
            if (iaunlogo.gt.0) then
              call lifich('Name of the logo''s file ?'
     &             ,0,nomdulogo,lnomdulogo)
              call lientier(
     &     'Transparency of the logo (0-> opaque, 100-> transparent) ?'
     &             ,0,itranslogo)
              itranslogo = max(0,itranslogo)
              if (itranslogo.ge.100) then
                print*,'*** fully transparent <=> no logo !'
                iaunlogo = 0
              endif
            endif
          endif
        endif
      else
        iaunlogo = 0
      endif
      if (iformat.lt.-1.or.
     &(trouve.and.iformat.gt.3).or.(.not.trouve.and.iformat.gt.0)) then
        iformat = -2
      endif
      end
c-----------------------------------------------------------------------
      subroutine quicestceluila(commande,lc,cestla,iefface)
      character*132 commande,lu
      logical*4 cestla
c
      INCLUDE 'Parametres.f'
c
      call exec(
     &'which '//CHAR(92)//commande(1:lc)//' > '//fichtmp(1:lftmp)
     &//' 2> /dev/null')
      call premier_libre(ifich)
      open(ifich,file=fichtmp(1:lftmp))
      read(ifich,'(a132)',err=1000,end=1000) lu
      goto 1001
 1000 do i=1,132
        lu(i:i) = ' '
      enddo
 1001 close(ifich)
      call enleve_tous_blancs(lu,llu,132)
      if (lu(llu-lc+1:llu).eq.commande(1:lc)) then
        cestla = .true.
      else
        cestla = .false.
      endif
      if (iefface.eq.0) call exec('/bin/rm -f '//fichtmp(1:lftmp))
      end
