Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

READ until end-of-line

intelgg
Beginner
1,857 Views
I have a user-defined type like

type MY_TYPE
real(8) :: mber1
real(8) :: mber2
real(8) :: mber3
end type MY_TYPE

and a variable

type(MY_TYPE) myTypeVar

and finally a read statement like

READ(10, *, IOSTAT = myIOStat) myTypeVar

When the READ statement reads a line that
happens to have only two real numbers,
the first real number of the next line is
read into myTypeVar%mber3.

I instead want READ to not read pass the
end of line, and instead give me an error
in myIOStat.

Thanks
Gilles G
0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,857 Views
Don't use list-directed input. It will keep reading records until the I/O list is full.

Steve
0 Kudos
nijhuis
Beginner
1,857 Views
You can perform list directed IO on a one line basis by first reading the line with the A-format in a character string (which is large enough to hold the longest line) and then do the list directed read on the character string.

character(MAX_LINE_LENGTH) line

READ(10, "(A)", IOSTAT=myIOStat) line

READ(line, *, IOSTAT=myIOStat1) myTypeVar

When myIOStat1 equals -1 less than 3 numbers are read. Because you don't know how many numbers are read, preset them; unread members remain unchanged by the read.

Guus Nijhuis
0 Kudos
Reply