-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled by passing `access="direct"` and `recl` keyword options to the FortranFile constructor. read and write operations on such files must include the `rec` keyword to select which record to read/write. We assume that such files use no record markers at all, which is what gfortran and ifort seem to be doing. The ifort documentation mentions a "vms" option, which uses a single control byte at the start of each record, but this is currently not supported here. Closes #1.
- Loading branch information
Showing
15 changed files
with
366 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Base: close, unsafe_read, unsafe_write | ||
|
||
type FixedLengthRecord{T,C} <: Record | ||
io :: IO # underlying I/O stream | ||
reclen :: T # length of this record | ||
nleft :: T # bytes left in this record | ||
writable :: Bool # whether this record is writable | ||
convert :: C # convert method | ||
end | ||
|
||
function Record{C}( f::FortranFile{DirectAccess,C} ) | ||
## constructor for readable records | ||
conv = f.convert | ||
reclen = f.acctyp.reclen | ||
FixedLengthRecord(f.io, reclen, reclen, false, conv) | ||
end | ||
|
||
function Record{C}( f::FortranFile{DirectAccess,C}, towrite::Integer ) | ||
## constructor for writable records | ||
conv = f.convert | ||
reclen = f.acctyp.reclen | ||
if towrite > reclen | ||
error("attempting to write record of $(towrite) bytes into a file of record length $(reclen) bytes") | ||
end | ||
FixedLengthRecord(f.io, reclen, reclen, true, conv) | ||
end | ||
|
||
function gotorecord( f::FortranFile{DirectAccess}, recnum::Integer ) | ||
reclen = f.acctyp.reclen | ||
pos = (recnum-1) * reclen | ||
seek(f.io, pos) | ||
end | ||
|
||
function unsafe_read( rec::FixedLengthRecord, p::Ptr{UInt8}, n::UInt ) | ||
if (n > rec.nleft); error("attempting to read beyond record end"); end | ||
unsafe_read( rec.io, p, n ) | ||
rec.nleft -= n | ||
nothing | ||
end | ||
|
||
function unsafe_write( rec::FixedLengthRecord, p::Ptr{UInt8}, n::UInt ) | ||
if (n > rec.nleft); error("attempting to write beyond record end"); end | ||
nwritten = unsafe_write( rec.io, p, n ) | ||
rec.nleft -= n | ||
return nwritten | ||
end | ||
|
||
function close( rec::FixedLengthRecord ) | ||
if rec.nleft != 0 | ||
if rec.writable | ||
# Fortran standard 9.6.4.5.2 point 7: | ||
# "If the file is connected for direct access and the values specified by the | ||
# output list do not fill the record, the remainder of the record is undefined." | ||
# Following gfortran, we fill it with zeros. | ||
write(rec.io, zeros(UInt8, rec.nleft)) | ||
else | ||
skip(rec.io, rec.nleft) | ||
end | ||
end | ||
nothing | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.