c
c
c
      character datafl*80,outfl*80
      
      write(*,*)
      write(*,*)  ' Enter the name of the input file:'
      read(*,'(a)') datafl
      write(*,*)  ' Enter the grid size nx,ny,nz:'
      read(*,*)     nx,ny,nz
      write(*,*)  ' Enter the name of the output file:'
      read(*,'(a)') outfl
      
      open(1,file=datafl)
      read(1,*)
      read(1,*) nvari
      do i=1,nvari
            read(1,*)
      end do
      
      open(2,file=outfl)
      write(2,100)
 100  format('Average values',/,'2',/,'Real. Num',/,'Average')
 
      do isim=1,1000
            n = 0
            a = 0.0
            do i=1,nx*ny*nz
                  read(1,*,end=1) val
                  if(val.ge.0.0) then
                        n = n + 1
                        a = a + val
                  end if     
            end do
            a = a / real(max(n,1))
            write(2,'(i4,x,g14.8)') isim,a
      end do
 1    continue
 
      stop
      end