      subroutine getchr(iunit,chr,*,*)

c     Copyright 2012 Leon van Dommelen.  This software is made available
c     under the GNU Public License version 3.

c     Gets the next character from the input file open on unit iunit.
c     If iunit is zero, gets it from subroutine iioget instead.

c     Takes exit 1 on end of file and 2 on other error.

c     This version for g77.  Unit iunit must have been opened using
c     "form='unformatted'".

c     avoid typos
      implicit none

c input:

c     I/O unit to read from
      integer iunit

c output:

c     read character
      character*1 chr

c local:

c     error status
      integer stat

c executable:

c     read a character from the file
      call fgetc(iunit,chr,stat)

c     check for problems
      if(stat.eq.-1)then
c        end of file
         return 1
      else if(stat.ne.0)then
c        other error
         return 2
      endif

c     all OK
      return

      end
