10 SUBROUTINE safe_open(iunit, istat, filename, filestat, &
11 & fileform, record_in, access_in, delim_in)
49 INTEGER,
INTENT(inout) :: iunit
50 INTEGER,
INTENT(out) :: istat
51 CHARACTER(LEN=*),
INTENT(in) :: filename, filestat, fileform
52 INTEGER,
INTENT(in),
OPTIONAL :: record_in
53 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: access_in
54 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: delim_in
58 CHARACTER(LEN=*),
PARAMETER :: cdelim =
"apostrophe", &
59 cform=
"formatted", cunform=
"unformatted",
60 cscratch=
"scratch", cseq=
"sequential"
61 CHARACTER(LEN=10) :: acc_type
62 CHARACTER(LEN=10) :: delim_type
63 LOGICAL :: lopen, lexist, linvalid
75 WRITE (6, *)
'In safe_open, requested unit was uninitialized: IUNIT='
79 INQUIRE(iunit, exist=lexist, opened=lopen, iostat=istat)
80 linvalid = (istat.ne.0 .or. .not.lexist) .or. lopen
81 IF (.not.linvalid)
EXIT
88 IF (
PRESENT(access_in))
THEN
89 acc_type = trim(access_in)
95 lexist = (filestat(1:1).eq.
's') .or. (filestat(1:1).eq.
'S')
100 IF (
PRESENT(access_in))
THEN
101 acc_type = trim(access_in)
103 acc_type =
'SEQUENTIAL'
107 IF (
PRESENT(delim_in))
THEN
108 SELECT CASE (delim_in(1:1))
121 SELECT CASE (fileform(1:1))
123 IF (
PRESENT(record_in))
THEN
125 OPEN(unit=iunit, form=cunform, status=cscratch,
126 & recl=record_in, access=acc_type, iostat=istat)
128 OPEN(unit=iunit, file=trim(filename), form=cunform,
129 & status=trim(filestat), recl=record_in,
130 & access=acc_type, iostat=istat)
134 OPEN(unit=iunit, form=cunform, status=cscratch,
135 & access=acc_type, iostat=istat)
137 OPEN(unit=iunit, file=trim(filename), form=cunform,
138 & status=trim(filestat), access=acc_type,iostat=istat)
143 IF (
PRESENT(record_in))
THEN
145 OPEN(unit=iunit, form=cform, status=cscratch,
146 delim=trim(delim_type), recl=record_in,
147 access=acc_type, iostat=istat)
149 OPEN(unit=iunit, file=trim(filename), form=cform,
150 status=trim(filestat), delim=trim(delim_type),
151 recl=record_in, access=acc_type, iostat=istat)
155 OPEN(unit=iunit, form=cform, status=cscratch,
156 delim=trim(delim_type), access=acc_type,
159 OPEN(unit=iunit, file=trim(filename), form=cform,
160 status=trim(filestat), delim=trim(delim_type),
161 access=acc_type, iostat=istat)
167 END SUBROUTINE safe_open
169 END MODULE safe_open_mod