14 SUBROUTINE safe_open(iunit, istat, filename, filestat, &
15 & fileform, record_in, access_in, delim_in)
56 INTEGER,
INTENT(inout) :: iunit
57 INTEGER,
INTENT(out) :: istat
58 CHARACTER(LEN=*),
INTENT(in) :: filename, filestat, fileform
59 INTEGER,
INTENT(in),
OPTIONAL :: record_in
60 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: access_in
61 CHARACTER(LEN=*),
INTENT(in),
OPTIONAL :: delim_in
65 CHARACTER(LEN=*),
PARAMETER :: cdelim =
"apostrophe",
66 1 cform=
"formatted", cunform=
"unformatted",
67 2 cscratch=
"scratch", cseq=
"sequential"
68 CHARACTER(LEN=10) :: acc_type
69 CHARACTER(LEN=10) :: delim_type
70 LOGICAL :: lopen, lexist, linvalid
83 INQUIRE(iunit, exist=lexist, opened=lopen, iostat=istat)
84 linvalid = (istat.ne.0 .or. .not.lexist) .or. lopen
85 IF (.not.linvalid)
EXIT
93 IF (
PRESENT(access_in))
THEN
94 acc_type = trim(access_in)
100 lexist = (filestat(1:1).eq.
's') .or. (filestat(1:1).eq.
'S')
105 IF (
PRESENT(access_in))
THEN
106 acc_type = trim(access_in)
108 acc_type =
'SEQUENTIAL'
112 IF (
PRESENT(delim_in))
THEN
113 SELECT CASE (delim_in(1:1))
126 SELECT CASE (fileform(1:1))
128 IF (
PRESENT(record_in))
THEN
130 OPEN(unit=iunit, form=cunform, status=cscratch,
131 & recl=record_in, access=acc_type, iostat=istat)
133 OPEN(unit=iunit, file=trim(filename), form=cunform,
134 & status=trim(filestat), recl=record_in,
135 & access=acc_type, iostat=istat)
139 OPEN(unit=iunit, form=cunform, status=cscratch,
140 & access=acc_type, iostat=istat)
142 OPEN(unit=iunit, file=trim(filename), form=cunform,
143 & status=trim(filestat), access=acc_type,iostat=istat)
148 IF (
PRESENT(record_in))
THEN
150 OPEN(unit=iunit, form=cform, status=cscratch,
151 & delim=trim(delim_type), recl=record_in,
152 & access=acc_type, iostat=istat)
154 OPEN(unit=iunit, file=trim(filename), form=cform,
155 & status=trim(filestat), delim=trim(delim_type),
156 & recl=record_in, access=acc_type, iostat=istat)
160 OPEN(unit=iunit, form=cform, status=cscratch,
161 & delim=trim(delim_type), access=acc_type,
164 OPEN(unit=iunit, file=trim(filename), form=cform,
165 & status=trim(filestat), delim=trim(delim_type),
166 & access=acc_type, iostat=istat)