C        1         2         3         4         5         6         7
C234567890123456789012345678901234567890123456789012345678901234567890123456789
C    ===================================================================
C     Eclatement d'une table de compilation de resultats sur differents
C     champs en sous catalogues independants.
C    ===================================================================

      parameter (
     1   NCMax     =      15 )          ! nombre maximum de champs

      character
     1   Nom1*40,
     1   Nom2(NCMax)*40,                ! nom des catalogues extraits
     1   Field*3,                       ! identification des champs
     1   Racine*10,                     ! racine de leur nom
     1   Extension*2,                   ! racine de leur extension
     1   Name(NCMax)*1,                 ! identification des spots
     1   Ligne*80

      integer*4
     1   Lu2(NCMax),NOC(NCMax)

C    -------------------------------------------------------------------
      Nom1      = 'final.98.awk3'
      Field     = '507'
      Racine    = 'e'//Field//'.lco98'
      Extension = '.s' 
C    ------------------------------------------------------------------
100   format ( a77 )
C    ------------------------------------------------------------------

      NC = 13                           ! A --> M
      DO IC = 1,NC
          Name(IC) = char(64+IC)
      ENDDO

      Lu1 = 1
      open (
     1    file   = Nom1,
     1    unit   = Lu1,
     1    status = 'old')

      DO IC = 1,NC
          Lu2(IC)  = 20 + IC
          Nom2(IC) = Racine//Extension//Name(IC)
          open (
     1       file   = Nom2(IC),
     1       unit   = Lu2(IC),
     1       status = 'new' )
          NOC(IC) = 0
      ENDDO

      NSaut = 0
      DO ISaut = 1,NSaut
          read (Lu1,*) Ligne
      ENDDO
      NObj = 0
1000  CONTINUE
          read (Lu1,100,end=1100) Ligne
          NObj = NObj + 1

          if ( Ligne(2:4).eq.Field ) then
              DO IC = 1,NC
                  if ( Ligne(7:7).eq.Name(IC) ) then
                      NOC(IC) = NOC(IC) + 1
                      write (Lu2(IC),*) Ligne
                  endif
              ENDDO
          endif

          goto 1000
1100  CONTINUE
      close (Lu1)
      DO IC = 1,NC
          close (Lu2(IC))
      ENDDO

      print *,' '
      print *,' Nb d''objets lus .... : ',NObj
      DO IC = 1,NC
          print *,' '
          print *,'Champ : ',Name(IC),' nb d''objets : ',NOC(IC)
      ENDDO
      
C    ===================================================================
      end
