      program example31b
      include 'mpif.h'
      integer bufsize, num, sum, status(MPI_STATUS_SIZE)
      integer fh, ierr
      parameter (bufsize=100)
      character buf(bufsize)
      call MPI_INIT(ierr)
      call MPI_FILE_OPEN(MPI_COMM_WORLD, "file.txt",
     &                   MPI_MODE_RDONLY, MPI_INFO_NULL, fh,
     &                   ierr)
      call MPI_FILE_SET_VIEW(fh, 0, MPI_CHARACTER,
     &                       MPI_CHARACTER, "native",
     &                       MPI_INFO_NULL, ierr)
      sum = 0
      do
         call MPI_FILE_READ(fh, buf, bufsize, MPI_CHARACTER,
     &                      status, ierr)
         call MPI_GET_COUNT(status, MPI_CHARACTER, num, ierr)
         print *, buf
         sum = sum + num
         if(num < bufsize) exit
      end do
      call MPI_FILE_CLOSE(fh, ierr)
      print *, sum, ' characters are readed'
      call MPI_FINALIZE(ierr)
      end
