2
! This file is part of the SIESTA package.
4
! Copyright (c) Fundacion General Universidad Autonoma de Madrid:
5
! E.Artacho, J.Gale, A.Garcia, J.Junquera, P.Ordejon, D.Sanchez-Portal
6
! and J.M.Soler, 1996-2006.
8
! Use of this software constitutes agreement with the full conditions
9
! given in the SIESTA license, as signed by all legitimate users.
12
c Copyright Alberto Garcia, 1996, 1997, 1998
14
c This module implements an interface to the FORTRAN logical unit
15
c system. Based on code by Richard Maine.
18
c Alberto Garcia, December 30, 1996
19
c Rewritten as a single subroutine
20
c with multiple entry points, March 7, 1998
21
c Now hybrid to comply with Siesta "die" interface.
22
c---------------------------------------------------------------
27
c Logical unit management. Units 0 to min_lun-1 are "reserved",
28
c since most of the "typical" files (output, etc) use them.
30
c Logical units min_lun to min_max are managed by this module.
34
c----------------------------------------------------------------
37
integer stdout, stderr
38
integer min_lun, max_lun, nunits
39
parameter (min_lun=10, max_lun=99, nunits=max_lun-min_lun+1)
40
logical lun_is_free(min_lun:max_lun)
42
save stdout, stderr, lun_is_free
43
c-----------------------------------------------------------------
45
c Internal and dummy variables
47
integer i, unit, lun, iostat
48
logical used, named, opened
49
character filename*50, form*11
51
c-----------------------------------------------------------------
52
c Initialization section
54
data lun_is_free /nunits*.true./
55
data stdout, stderr /6,0/
56
c-----------------------------------------------------------------
60
c Simple interfaces to modify standard units
76
c------------------------------------------------------------------
78
c Logical unit management
82
c Looks for a free unit and assigns it to lun
84
do lun= min_lun, max_lun
85
if (lun_is_free(lun)) then
86
inquire(unit=lun, opened=used, iostat=iostat)
87
if (iostat .ne. 0) used = .true.
88
lun_is_free(lun) = .false.
89
if (.not. used) return
92
call die('No luns available in io_assign')
98
c Useful to specify that one needs to use a particular unit number
100
c For example, assume some legacy code expects to work with unit 15:
102
c call io_reserve(15) ! this call at the beginning of the program
106
inquire(unit=lun, opened=used, iostat=iostat)
107
if (iostat .ne. 0) used = .true.
108
if (used) call die('Cannot reserve unit. Already connected')
109
if (lun .ge. min_lun .and. lun .le. max_lun)
110
$ lun_is_free(lun) = .false.
118
c Use this routine instead of a simple close!!
121
if (lun .ge. min_lun .and. lun .le. max_lun)
122
$ lun_is_free(lun) = .true.
129
c Prints a list of the connected logical units and the names of
130
c the associated files
133
write(stdout,'(a)') '******** io_status ********'
135
inquire(i,opened=opened,named=named,name=filename,
136
$ form=form,iostat=iostat)
137
if (iostat .eq. 0) then
140
write(stdout,9000) i, form, filename
142
write(stdout,9000) i, form, 'No name available'
146
write(stdout,9000) i, 'Iostat error'
149
write(stdout,'(a)') '******** ********'
151
9000 format(i4,5x,a,5x,a)