ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/nano_mpi/src/file_units.F90
Revision: 4
Committed: Mon Jun 10 17:18:36 2002 UTC (22 years, 1 month ago) by chuckv
File size: 1353 byte(s)
Log Message:
Import Root

File Contents

# User Rev Content
1 chuckv 4 !------------------------------------------------------------------------
2     ! Files Module
3     !-----------------------------------------------------------------------
4     ! Functions:
5     !
6     ! NEXT_UNIT Returns the next available fortran unit number.
7     !
8     ! Uses the fortran 90 inquire statement to find next unit.
9     !
10     !-----------------------------------------------------------------------
11     module file_units
12    
13     use definitions, ONLY : max_units
14     use io_units, ONLY : INPUT_UNIT,OUTPUT_UNIT
15    
16    
17     contains
18    
19     function next_unit() result(unit_number)
20    
21     ! result variable
22     integer :: unit_number
23    
24     ! local scalar variables
25     integer :: i, unit
26     logical :: is_opened
27    
28     !. initialize unit number to return -1
29     ! we can use this to error check
30     unit = -1
31    
32     is_opened = .true.
33    
34     ! do while unit is opened
35    
36     find_unit: do i = 10, max_units
37    
38     ! check to make sure that we don't assign input or
39     ! output streams
40    
41     if ( ( i /= input_unit) .and. (i /= output_unit) ) then
42    
43     inquire (i, opened = is_opened)
44    
45     if ( .not. is_opened ) then
46     unit = i
47     exit find_unit
48     end if
49     end if
50     end do find_unit
51    
52     unit_number = unit
53    
54     end function next_unit
55    
56     end module file_units