C Program converts RSC-11-6 data records; header info goes to unpack.hdr and
C  data samples go to unpack.dat

C Usage
C           unpack pathname
C where
C                           pathname      is path to RSC-11-6 file

C Exits
C           0   normal
C           1   wrong number of arguments



      integer*4       dunit /17/      ! logical unit for output samples
      character*128   filename        ! path to input file
      integer*4       hunit /16/      ! logical unit for output headers
      integer*4       iarray(1264)    ! input data record
      integer*4       irec /0/        ! record number
      integer*4       iunit /31/      ! logical unit for input data
      integer*4       narg            ! number of arguments
      integer*4       oarray(42)      ! output record of header data
      integer*4       odata(1250)     ! output record of 16-bit sample data

      integer*4       iargc           ! function

      equivalence   ( iarray(15), odata(1) )


C Get and process argument

      narg = iargc()
      if (narg .ne. 1) then
        write(*,'("USAGE:  unpk  pathname")')
        call exit (1)
      end if

      call getarg(1,filename)

      open ( unit = iunit,
     *       file = filename,
     *       access = 'direct',
     *       recl = 5056,
     *       form = 'unformatted',
     *       status = 'old')

      open ( unit = hunit,
     *       file = 'unpk.hdr',
     *       status = 'unknown')

      open ( unit = dunit,
     *       file = 'unpk.dat',
     *       access = 'direct',
     *       recl = 5000,
     *       form = 'unformatted',
     *       status = 'unknown')

 10   continue

      irec = irec + 1
      read(iunit,rec=irec,end=90) iarray


C Unpack header, send it to hunit; send 8-bit data samples to dunit

      call get_hdr(iarray,oarray)
      call prt_hdr1(hunit,oarray)

      write(dunit,rec=irec) odata

      go to 10


C Exits

 90   continue
      irec = irec - 1
      write(*,'("EOF after record ",i10)') irec

 99   continue
      stop
      end
