

      integer function trmlen( source )
c     ******************************************************************
c     *                           trmlen                               *
c     *----------------------------------------------------------------*
c     * this function returns the length of a character string, source,*
c     * excluding any trailing blanks.                                 *
c     *                                                                *
c     *                         written by                             *
c     *                       roger e haylett                          *
c     *                         june  1988                             *
c     *                                                                *
c     ******************************************************************

      integer         curpos    ! l current character position in source
      logical         finish    ! l set .true. when processing is over
      character*(*)   source    ! i source string to be scanned

c     *** scan string, one character at a time, from the right,     ***
c     *** stopping only when the first non-blank character is found ***

      finish = .false.
      curpos = len( source )

   10 if( .not. finish )then

        if( source( curpos: curpos ) .eq. ' ' )then
          curpos = curpos - 1
        else
          finish = .true.
        endif

      goto 10
      endif

      trmlen = curpos

      return
      end
