PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

READ Skips First Three Bytes of Files

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
BPalmer



Joined: 15 Dec 2009
Posts: 3

PostPosted: Tue Dec 15, 2009 3:10 pm    Post subject: READ Skips First Three Bytes of Files Reply with quote

I'm having problems running the following program (read.for):

PROGRAM READ_ERROR
CHARACTER BUF*1000
INTEGER IO, NSTART, NEND, NCHAR
DIMENSION ISTAT(12)

OPEN(10, FILE='./test.run', FORM='UNFORMATTED', IOSTAT=IO,
1 ACCESS='SEQUENTIAL', ACTION='READ')

IO = FSTAT(10, ISTAT)
NCHAR = ISTAT(8)
NSTART = 1
NEND = NSTART+NCHAR-1

READ(10, IOSTAT=IO) BUF(NSTART:NEND)
CLOSE(10)
STOP
END

on a test.run file containing:
012345678910

and compiled with
pgf95 -g read.for -o read

After the READ statement, IO is -1 and BUF(NSTART:NSTART) is '3'. In other words the first three bytes '012' are skipped.

Any ideas why the program would skip the first three bytes of the read?

Thanks,

Brian
Back to top
View user's profile
BPalmer



Joined: 15 Dec 2009
Posts: 3

PostPosted: Tue Dec 15, 2009 3:33 pm    Post subject: It actually skips the first 4 bytes Reply with quote

I included an error in the previous explanation. The test.run file had a newline before the numbers started. Removing the newline causes buf(1:1) to contain '4', which means that the read is skipping the first 4 bytes.

My apologies,

Brian
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6208
Location: The Portland Group Inc.

PostPosted: Tue Dec 15, 2009 4:08 pm    Post subject: Reply with quote

Hi Brain,

You need to use formatted I/O since "test.run" is a text file. Unformatted I/O is record based and the first 4 bytes of the line tells the record size.

For example:
Code:
% cat read.f90
PROGRAM READ_ERROR
CHARACTER BUF*1000
INTEGER IO, NSTART, NEND, NCHAR
DIMENSION ISTAT(12)

OPEN(10, FILE='./test.run', FORM='FORMATTED', IOSTAT=IO, &
 ACCESS='SEQUENTIAL', ACTION='READ')

IO = FSTAT(10, ISTAT)
NCHAR = ISTAT(8)
NSTART = 1
NEND = NSTART+NCHAR-1

READ(10,IOSTAT=IO,*) BUF(NSTART:NEND)
CLOSE(10)
write(*,*) BUF(NSTART:NEND)
STOP
END

% pgf90 read.f90
% a.out
 012345678910
FORTRAN STOP



Hope this helps,
Mat
Back to top
View user's profile
BPalmer



Joined: 15 Dec 2009
Posts: 3

PostPosted: Tue Dec 15, 2009 4:17 pm    Post subject: I think that I found the answer Reply with quote

When I change the ACCESS to 'STREAM' it starts reading at the first byte. I apologize to anyone whose time I've taken up with this question. I clearly could have read some documentation from somewhere.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group