Skip to content

stdlib_experimental_io(open): support for unformatted sequential files #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/stdlib_experimental_io.f90
Original file line number Diff line number Diff line change
@@ -337,6 +337,9 @@ integer function open(filename, mode, iostat) result(u)
case('b', 's')
access_='stream'
form_='unformatted'
case('u')
access_='sequential'
form_='unformatted'
case default
call error_stop("Unsupported mode: "//mode_(3:3))
end select
@@ -376,7 +379,10 @@ integer function open(filename, mode, iostat) result(u)
else if (lfirst(2) .and. a(i:i) == '+') then
mode_(2:2) = a(i:i)
lfirst(2)=.false.
else if (lfirst(3) .and. (a(i:i) == 't' .or. a(i:i) == 'b')) then
else if (lfirst(3) &
.and. (a(i:i) == 't' &
.or. a(i:i) == 'b' .or. a(i:i) == 's'&
.or. a(i:i) == 'u')) then
mode_(3:3) = a(i:i)
lfirst(3)=.false.
else if (a(i:i) == ' ') then
@@ -385,7 +391,7 @@ integer function open(filename, mode, iostat) result(u)
call error_stop("Wrong mode: "//trim(a))
else
call error_stop("Wrong character: "//a(i:i))
endif
end if
end do

end function
2 changes: 1 addition & 1 deletion src/tests/io/Makefile.manual
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ PROGS_SRC = test_loadtxt.f90 \
test_parse_mode.f90 \
test_open.f90

CLEAN_FILES = tmp.dat tmp_qp.dat io_open.dat io_open.stream
CLEAN_FILES = tmp.dat tmp_qp.dat io_open.dat io_open.stream io_open.bin


include ../Makefile.manual.test.mk
25 changes: 25 additions & 0 deletions src/tests/io/test_open.f90
Original file line number Diff line number Diff line change
@@ -59,6 +59,31 @@ program test_open
close(u)


! Unformatted sequential file
filename = get_outpath() // "/io_open.bin"

! Test mode "w"
u = open(filename, "wu")
write(u) 1, 2, 3
close(u)

! Test mode "r"
u = open(filename, "ru")
read(u) a
call assert(all(a == [1, 2, 3]))
close(u)

! Test mode "a"
u = open(filename, "au")
write(u) 4, 5, 6
close(u)
u = open(filename, "ru")
read(u) a
call assert(all(a == [1, 2, 3]))
read(u) a
call assert(all(a == [4, 5, 6]))
close(u)


!0 and non-0 open
filename = get_outpath() // "/io_open.stream"