C
C    Copyright (C) 2009 Anders Aspegren Søndergaard <andersas@gmail.com>
C    -------------------------------------------------------------------

C    This file is part of Wavlib.

C    Wavlib is free software: you can redistribute it and/or modify
C    it under the terms of the GNU General Public License as published by
C    the Free Software Foundation, either version 3 of the License, or
C    (at your option) any later version.

C    Wavlib is distributed in the hope that it will be useful,
C    but WITHOUT ANY WARRANTY; without even the implied warranty of
C    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
C    GNU General Public License for more details.

C    You should have received a copy of the GNU General Public License
C    along with Wavlib. If not, see <http://www.gnu.org/licenses/>.


C     This function sets U to an unused file unit, or -1 on failure to
C     do so (eg. no free file units)
      SUBROUTINE GTUNIT(U)
        INTEGER U
        LOGICAL OPNED

C       Loop through file units 10-99 (to avoid messing with stdout etc)
        DO 10 U = 10, 99
C         See if file is opened, if not return the unit:
          INQUIRE(UNIT=U,OPENED=OPNED)
          IF (.NOT. OPNED) THEN
                RETURN
          ENDIF
  10    CONTINUE

C       No available unit found, return -1:
        U = -1
        RETURN
      END


