io - How to skip over an array in a Fortran unformatted file? -
my programme reads “unformatted” file in fortran. among other things, file contains array programme not need, can quite large. skip array.
if programme writing data:
program write real :: useless(10), useful=42 open(123, file='foo', form='unformatted') write(123) size(useless) write(123) useless write(123) useful end programme write
then works reading:
program read integer :: n real, allocatable :: useless(:) real :: useful open(123, file='foo', form='unformatted') read(123) n allocate(useless(n)) read(123) useless read(123) useful print*, useful end programme read
but avoid allocating “useless” array. discovered this
program read2 integer :: n, real :: useless real :: useful open(123, file='foo', form='unformatted') read(123) n i=1,n read(123) useless end read(123) useful print*, useful end programme read2
does not work (because of record lengths beingness written file [edit, see francescalus' answer]).
it not alternative alter format of file.
it isn't sin read fewer file storage units in record.
program read real :: useful open(123, file='foo', form='unformatted') read(123) read(123) read(123) useful print*, useful end programme read
each "empty" read still advances record file connected sequential access.
as farther comment: sec effort doesn't fail "because of record lengths". fails because of effort read separate records. examples of significance of difference can found in many posts.
io fortran binaryfiles
No comments:
Post a Comment