c-----------------------------------------------------------------------
c
c  Name:
c      FUNCTION GETLUN
c
c  Purpose:
c      Get a logical unit number that is not in use.
c
c  Usage:
c      RESULT = GETLUN()
c 
c  Input:
c      Nothing
c
c  Output:
c      RESULT  Logical unit number (use in OPEN statement for example)
c
c  Revised:
c      Liam.Gumley@ssec.wisc.edu
c      $Id: getlun.f,v 1.3 1999/11/11 20:04:44 gumley Exp $
c
c-----------------------------------------------------------------------

      integer function getlun()
      
      implicit none

c ... local variables
      
      integer i
      logical od

      getlun = -1
      
c ... search unit numbers from 20 onwards for one that is not in use
      
      i = 20
10    od = .false.
      inquire( i, opened = od )
      if( od ) then
        i = i + 1
        goto 10
      endif

      getlun = i
      
      end
