- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Don't use list-directed input. It will keep reading records until the I/O list is full.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page