      SUBROUTINE FSINN(iprox,iproy,prog,iopt,icoul)
c
      save
      INCLUDE 'Parametres.f'
      integer ich(4)
      character*512 string
      character*64 prog,progbid
      character*80 device_name,kinfo
      character*12 heure
      character*15 cterm(6)
      integer xmm,ymm
      parameter(maxcolo=256)
      external kinfo
c
      data cterm /'"monochrom"    ','"gray levels"  ','"unknown"      '
     &           ,'"8 bits color"','"true colors"  ','"direct colors"'/
c
      sauve_graphic = .false.
      accentsok = .false.
      lebrowser = .false.
      igarde_taille_fen = 0
      imix_courant = 0
      iptbuf = 1
      icoul_questions = 0
      ilarstrfen = 65
      iaunlogo = 0
      if (iopt.eq.-99) then
        progbid = prog
        call enleve_tous_blancs(progbid,lprog,64)
        nomprogramme(1:lprog) = prog(1:lprog)
        nomprogramme(lprog+1:lprog+1) = char(0)
        lapremierefois = 1
        icount = 1
        gardefou = .true.
        call gslw(1)
      elseif(iopt.ne.0) then
        call selgraphix11
        call x11changecurseur(1)
      else
        ibordx = 0
        ibordy = 0
        if ((iprox*iproy).eq.0) then
          ich(1) = 85
          ich(2) = 85
        else
          ich(1) = min(100,max(iprox,20))
          ich(2) = min(100,max(iproy,20))
        endif
        xloosetime = 54632721.
        call init_temps()
        call calibremenu
        call papercolor(0)
        iprox0 = ich(1)
        iproy0 = ich(2)
        progbid = prog
        iprogre = 0
        call enleve_tous_blancs(progbid,lprog,64)
        nomprogramme(1:lprog) = progbid(1:lprog)
        nomprogramme(lprog+1:lprog+1) = char(0)
        if (albion) then
          print*,'Welcome on '//nomprogramme(1:lprog)//'!'
        else
          print*,'Bienvenue sur '//nomprogramme(1:lprog)//' !'
        endif
        call getenvc('DISPLAY'//CHAR(0),string,512,ich(3))
        if (ich(3).ge.1.and.ich(3).le.512) then
Cfj          if (albion) then
Cfj            print*,'Graphics sent on ',string(1:ich(3))
Cfj          else
Cfj            print*,'On envoie le graphique sur ',string(1:ich(3))
Cfj          endif
        else
          string = ' '
          ich(3) = 1
        endif
        ich(4) = maxcolo
        if (icount.gt.1) return
        icount = icount+1
        device_name(1:ich(3)) = string(1:ich(3))
        call x11opendisplay(device_name(1:ich(3))//char(0))
        call x11ecran(xmm,ymm,nbpixx,nbpixy,nbpixx2,nbpixy2)
cc        print*,' taille de l''ecran en mm.   :',xmm,ymm
cc        print*,' taille de l''ecran en pixels:',nbpixx,nbpixy
        coef = real(10*nbpixx)/real(xmm)
        if (nbpixx.ne.1280.or.nbpixy.ne.1024) then
          cccc = real(nbpixx)*1024./(real(nbpixy)*1280.)
          if (cccc.gt.1.) then
            idx = nint(real(nbpixx*ich(1))*.01/cccc)
            idy = nint(real(nbpixy*ich(2))*.01)
          else
            idx = nint(real(nbpixx*ich(1))*.01)
            idy = nint(cccc*real(nbpixy*ich(2))*.01)
          endif
        else
          idx = (nbpixx*ich(1))/100
          idy = (nbpixy*ich(2))/100
        endif
        nbcolo = ich(4)
        call x11device(inbc,idx,idy,nbcolo,nomprogramme)
c
c ibacking = 0 -> serveur sans backing store. Se debrouiller a la main !
c
        call x11askbacking(ibacking)
        if (ibacking.eq.0) then
          if (albion) then
            print*,'No backing-store on this X server !'
          else
            print*,'Pas de backing-store sur ce serveur X !'
          endif
        endif
c
c home dir
c
        lhomedir = 0
        call getenvc('HOME'//CHAR(0),CHOMEDIR,32,LHOMEDIR)
c
c fontes
c
        ipostscript = 1
        do i=1,nfontes_de_base
          lapremierefois = 0
          call gslss(i-1)
        enddo
        lapremierefois = 1
        call gslss(0)
        string='a'//char(0)
        call x11textextendall(string,1,isizecar0,ihautcar0,ibasecar0)
        ibordpop = nint(real(isizecar0)*1.8)
        idyliste = nint(real(ihautcar0)*2.2)
        ibordbrow = 2
        zero = 0.
c
        string(1:80) = kinfo('UTILISATEUR')
        call enleve_tous_blancs(string,l,80)
        heure = kinfo('HEURE')
        fichtmp = '/tmp/scratch.'
     &       //string(1:l)//'.'//heure(1:2)//heure(4:5)//heure(7:8)
        call enleve_tous_blancs(fichtmp,lftmp,80)
        fichtmp(lftmp+1:lftmp+1) = char(0)
        call quicestceluila('gifsicle',8,ilestlagifsicle,0)
c        
        call gslss(2)
c
        if (inbc.eq.3) then
          ipseudo = 0
Cfj          if (albion) then
Cfj            print*,'Color display with',nbcolo,' colors'
Cfj          else
Cfj            print*,'Terminal couleur à',nbcolo,' couleurs'
Cfj          endif
        elseif(inbc.eq.1) then
          ipseudo = 0
Cfj          if (albion) then
Cfj            print*,'Black and white display with',nbcolo,' gray levels'
Cfj          else
Cfj            print*,'Terminal noir et blanc à',nbcolo,' niveaux de gris'
Cfj          endif
        elseif(inbc.eq.0) then
          ipseudo = 0
Cfj          if (albion) then
Cfj            print*,'Monochrom display'
Cfj          else
Cfj            print*,'Terminal monochrome'
Cfj          endif
        elseif(inbc.eq.4) then
          ipseudo = 1
Cfj          if (albion) then
Cfj            print*,'True Color display'
Cfj          else
Cfj            print*,'Terminal "True Color"'
Cfj          endif
        elseif(inbc.eq.5) then
          ipseudo = 1
Cfj          if (albion) then
Cfj            print*,'Direct Color display'
Cfj          else
Cfj            print*,'Terminal "Direct Color"'
Cfj          endif
        else
          inbc = 2
          ipseudo = 1
Cfj          if (albion) then
Cfj            print*,'Display type =',inbc,' unknown...'
Cfj          else
Cfj            print*,'Type de terminal =',inbc,' inconnu...'
Cfj          endif
        endif
        icoul = inbc
        itypterm = inbc
        call x11szscrn(idx,idy)
        if (ipseudo.ne.0) then
          call x11loadcolor(7)
          ix = idx/2
          iy = idy/2
          if (albion) then
            call x11txtsrnrot3(
     &        'Loading colors (TrueColor mode)...'//char(0)
     &        ,34,ix,iy,bidon,0.,5,-1)
          else
            call x11txtsrnrot3(
     &        'Chargement des couleurs (mode TrueColor)...'//char(0)
     &        ,43,ix,iy,bidon,0.,5,-1)
          endif
          is = 1
          ss = .1
          CALL PARAMSOMBRE(is,is,ss)
        endif
        if (albion) then
          print*,'Window',idx,' x',idy,', display ',cterm(inbc+1)
        else
          print*,'Fenêtre',idx,' x',idy,', terminal ',cterm(inbc+1)
        endif
Cfj        xmin = 0.
Cfj        xmax = idx/coef
Cfj        ymin = 0.
Cfj        ymax = idy/coef
        display_characteristics(1) = idx
        display_characteristics(2) = idy
        if (nbcolo.eq.2) then
          hi_plane = 0
        elseif(ipseudo.eq.0) then
          if (nbcolo.le.16) then
            hi_plane = 4
          else
            hi_plane = 8
          endif
        else
          hi_plane = 8
        endif
c
        i2box = 5
        j2box = 5  
        icoulfond = 0
        colfond(1) = 1.
        colfond(2) = 1.
        colfond(3) = 1.
        i2dfond = 0
        do i=1,256
          bufferout(i:i) = ' '
        enddo
        ii = 0
        do i=1,lprog
          if (nomprogramme(i:i).eq.' ') then
            ii = i-1
            goto 3131
          endif
        enddo
 3131   if (ii.ne.0) then
          lprogcourt = ii
        else
          lprogcourt = lprog
        endif
        call x11nomicone(nomprogramme(1:lprogcourt)//char(0),lprogcourt)
      endif
      end
c-----------------------------------------------------------------------
      integer function mybogovitesse()
      INCLUDE 'Parametres.f'
      mybogovitesse = nloosetime
      end
c-----------------------------------------------------------------------
      subroutine papercolor(iopt)
      INCLUDE 'Parametres.f'
      ipapercolor = iopt
      end
c-----------------------------------------------------------------------
      subroutine maxpixsize(maxpixx,maxpixy)
      INCLUDE 'Parametres.f'
      maxpixx = nbpixx2
      maxpixy = nbpixy2
      end
      
