      PROGRAM GRIBTRACE
      implicit none

      integer iargc
      integer, parameter :: info_offset = 255
      integer info(info_offset + 1024)
      character(len=80) file
      integer fp, j, k, iret, idebug
      integer numargs
      integer kfield
      integer, parameter :: n = 38
      character*70 fmt(n)
c234567890c234567890c234567890c234567890c234567890c234567890c234567890--
      data fmt(1:10)/
     1'("( 1) GRIB-file length in bytes                    : ",i15)',
     2'("( 2) GRIB-edition                                 : ",i15)',
     3'("( 3) Grid type code                               : ",13x,a4)',
     4'("( 4) 0 = Regular, 1 = Quasi-regular grid          : ",i15)',
     5'("( 5) No. of vertical coordinates                  : ",i15)',
     6'("( 6) No. of LATs or J pent. resol. param.         : ",i15)',
     7'("( 7) No. of LONs or K pent. resol. param.         : ",i15)',
     8'("( 8)                M pent. resol. param.         : ",i15)',
     9'("( 9) Estim. no. of fields in the GRIB-file        : ",i15)',
     $'("(10) Version no. of the code table 2              : ",i15)'/
      data fmt(11:20)/   
     1'("(11) Date (YYYYMMDD)                              : ",i15.8)',
     2'("(12) Time (HHMM)                                  : ",i15.4)',
     3'("(13) Latitude of the first grid point             : ",i15)',
     4'("(14) Longitude of the first grid point            : ",i15)',
     5'("(15) Latitude of the last grid point              : ",i15)',
     6'("(16) Longitude of the last grid point             : ",i15)',
     7'("(17) Direction increment i                        : ",i15)',
     8'("(18) Direction increment j                        : ",i15)',
     9'("(19) No. of latitudes between pole and equator    : ",i15)',
     $'("(20) MARS class (1=od, 2=rd, 3=er)                : ",i15)'/
      data fmt(21:30)/   
     1'("(21) MARS type (1=fg,2=an,3=ia,5=3v,6=4v-an,9=fc) : ",i15)',
     2'("(22) Experiment id or version number              : ",11x,a4)',
     3'("(23) No. of data values coded/encoded             : ",i15)',
     4'("(24) No. of bits used for packing                 : ",i15)',
     5'("(25) 0 = Grid point, 128 = Spherical harmonics    : ",i15)',
     6'("(26) 0 = Simple packing, 64 = Complex packing     : ",i15)',
     7'("(27) 0 = Floating point data, 32 = Integer data   : ",i15)',
     8'("(28) Start offset to the complex packed data      : ",i15)',
     9'("(29) Scaling factor (power P) for complex packing : ",i15)',
     $'("(30) Time unit indicator                          : ",i15)'/
      data fmt(31:38)/   
     1'("(31) Time period P1                               : ",i15)',
     2'("(32) Time period P2                               : ",i15)',
     3'("(33) Time range indicator                         : ",i15)',
     4'("(34) Field code                                   : ",i15)',
     5'("(35) GRIB-product length in bytes                 : ",i15)',
     6'("(36) Type of level indicator                      : ",i15)',
     7'("(37) Top level value                              : ",i15)',
     8'("(38) Bottom level value                           : ",i15)'/

c234567890c234567890c234567890c234567890c234567890c234567890c234567890--

      numargs = iargc()
      
      if (numargs < 1) then
         print *,'Usage: gribtrace file_1 file_2 .. file_n'
         stop '*Error*'
      endif

      idebug = 0
      call GRSDBG(idebug)

      do j=1,numargs
         call GETARG(j, file)

         print '(a)',
     $        ' Opening GRIB-file "'//trim(file)//'" ...'
      
         call GRIB_OPEN(fp, trim(file), 'r',
     $        info, 0, iret)

         if (iret /= 0) then
            write(0,*) '** Error: Problems in file opening'
            cycle
         endif

         kfield = 0

         FOREVER: do
            kfield = kfield + 1
            
            call GRIB_INFO(fp, info, size(info), iret)
            if (iret /= 0) exit FOREVER
            
            write(*,*)'Field no. ',kfield
            do k=1,n
               write(*,fmt(k)) info(k)
            enddo
            write(*,*)'End field.'
         enddo FOREVER

         call GRIB_CLOSE(fp, iret)
      enddo

      END PROGRAM GRIBTRACE
