!Subroutine for read parameters files:
!READPAR
!ReadItem
!CommentHandler


      subroutine READPAR!(timer, timed, effref, refper, effrefl, &
!                         flref, a, b, c, d)

      use comvar, only: timer, &
                        timed, &
                        effref, &
                        refper, &
                        effrefl, &
                        flref, &
                        a, &
                        b, &
                        c, &
                        d

      implicit none

      integer, parameter :: parm_unit=9  ! file unit assignment for input
      character*20 parm_file

! ******************************************************************************
! open the parameter file 'params.hyd' ; read in parameters...

      parm_file = 'params.hyd'
      open(UNIT=parm_unit, FILE=parm_file, STATUS='OLD')

      call readitem(parm_unit, parm_file, timer)
      call readitem(parm_unit, parm_file, timed)
      call readitem(parm_unit, parm_file, effref)
      call readitem(parm_unit, parm_file, refper)

      call readitem(parm_unit, parm_file, effrefl)
      call readitem(parm_unit, parm_file, flref)


      call readitem(parm_unit, parm_file, a)
      call readitem(parm_unit, parm_file, b)
      call readitem(parm_unit, parm_file, c)
      call readitem(parm_unit, parm_file, d)
      
      WRITE(*,*) 
      WRITE(*,*) '*********************************************'
      WRITE(*,*) 'ALL PARAMETERS READED'
      WRITE(*,*) '*********************************************'
      WRITE(*,*) ' timer  = ', timer
      WRITE(*,*) ' timed  = ', timed
      WRITE(*,*) ' effref = ', effref
      WRITE(*,*) ' refper = ', refper
      WRITE(*,*) 'effrefl = ', effrefl
      WRITE(*,*) '  flref = ', flref
      WRITE(*,*) '       a = ', a
      WRITE(*,*) '       b = ', b
      WRITE(*,*) '       c = ', c
      WRITE(*,*) '       d = ', d
      WRITE(*,*) '*********************************************'
      WRITE(*,*)
      
      close (parm_unit)
!      stop 0

      end !program

!*******************************************************************************

      subroutine ReadItem (funit, fname, item)

! Simple routine to read data in free format, with a built-in error handler 
! designed to locate and skip over comment strings buried in the data stream.

      include 'netcdf.inc'

      integer*4    funit, &
                   iocode     ! dummy variable required by system for error handling?
      real*4       item
      character*20 fname

 101  read (funit, *, end=999, err=911, iostat=iocode) item
      return

 911  call CommentHandler (funit, fname)
      goto 101

 999  write (*,*) fname, funit
   2  format ('RD_PARAM: Unexpected EOF encountered in file ', &
              A20, ' on unit ', I2)
      stop

      end subroutine ReadItem


!*******************************************************************************

      subroutine CommentHandler (parm_unit, parm_file)
      
! #, *, c, C, !, // and /* denote comments in the parameter file. Therefore the 
! input reading routine must ignore these symbols and any text to their right. 
! This subroutine checks for the occurrence of these symbols, whenever RD_PARAM
! detects an error reading numeric data. If the error was caused by text starting
! with one of these symbols, the text is skipped over and the routine returns
! so that the next line of data can be read in.

! If an error is detected, the line containing the offending characters is 
! echoed to the screen and execution stops. But if someone were so-inclined,
! they could write some extra code to analyse the problem and possibly recover
! from it.

      integer*4     parm_unit, &
                    iocode    ! dummy variable required by system for error handling?
      integer*2     is_comment
      character*12  parm_file ! name of file from which input is being read in
      character*255 inputline ! arbitrary string. Input lines cannot exceed 255 chars!

      backspace(parm_unit)    ! back up to start of field that caused this error
 
      read (parm_unit, 1002, end=800, err=801, iostat=iocode) inputline
 1002 format (A255)

      is_comment = 0          ! must initialize this correctly

      if ((index (inputline, 'C') .eq. 1) .or. &
          (index (inputline, 'c') .eq. 1) .or. &
          (index (inputline, '*') .eq. 1) .or. &
          (index (inputline, '#') .eq. 1) .or. &
          (index (inputline, '!') .eq. 1) .or. &
          (index (inputline, '/') .eq. 1)) is_comment = 1


      if (is_comment .NE. 1) goto 801 ! we have a problem....
 
      return  ! But if we get to here, all's well and we can move on.

  800 write (*, 1000) parm_file, inputline ! For now, just echo the line and stop
 1000 format ('CommentHandler: Unexpected EOF encountered in ', &
              A12, '\nLast input was:', A255)

      stop

  801 write (*, 1001) parm_file, inputline ! For now, just echo the line and stop.
 1001 format ('CommentHandler: Error encountered reading data ', &
              'from ', A12, '\nLast input was:', A255)

      stop

      end subroutine CommentHandler
