      integer function lenstr (str)
C     return length of STR not including trailing blanks
      character *(*) str
      do lenstr = len (str), 1, -1
        if (str (lenstr:lenstr).ne.' ') return
      end do
      end
