- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a problem to read a text-file
The Textfile contains the Line "anonymouseID,7564"
The problem ist, that my read reads only "anonymouseID".
I know, that Fortran interpretes the , as a separator of data fields.
So what I want is to read the whole line, how can I manage this ?
I open a text-file with
character(256) line
OPEN(UNIT=file_id, FILE=filename, status='OLD', iostat=iErr)
read(file_id,*,err=10, end=20) line ! read one line
The Textfile contains the Line "anonymouseID,7564"
The problem ist, that my read reads only "anonymouseID".
I know, that Fortran interpretes the , as a separator of data fields.
So what I want is to read the whole line, how can I manage this ?
I open a text-file with
character(256) line
OPEN(UNIT=file_id, FILE=filename, status='OLD', iostat=iErr)
read(file_id,*,err=10, end=20) line ! read one line
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's what you get if you use list-directed input. Instead, do
read(file_id,'(A)',err=10, end=20) line ! read one line
read(file_id,'(A)',err=10, end=20) line ! read one line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just to clarify.
"List directed" (i.e. the * format),says that what is read from the file is determined by the the number of items in the list. You haveONE item in the list, your character variable "line". The record containsTWO items so the first one is read into "line" the second item is ignored.
Les
"List directed" (i.e. the * format),says that what is read from the file is determined by the the number of items in the list. You haveONE item in the list, your character variable "line". The record containsTWO items so the first one is read into "line" the second item is ignored.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Further clarification:
> the number of items in the list
^
comma-separated
> the number of items in the list
^
comma-separated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'd like to learn from this post but the classroom is clouded by an imperfect posit. The data file line is claimed to consist of
"anonymouseID,7564"
but are the quotes included or not? The explanation given seems to infer that they are not and so it consists of two items, anonymouseID and 7564.
If the quotes are included (which I would have inferred), then I think it consists of one item, a 17-character string, which should have been read in its entirety.
"anonymouseID,7564"
but are the quotes included or not? The explanation given seems to infer that they are not and so it consists of two items, anonymouseID and 7564.
If the quotes are included (which I would have inferred), then I think it consists of one item, a 17-character string, which should have been read in its entirety.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> If the quotes are included, then I think
it consists of one item, a 17-character string, which should have been
read in its entirety.
Yes, indeed. That is why, had the quotes been present in the input data file, the original poster would not have had any reason to start this thread.
Yes, indeed. That is why, had the quotes been present in the input data file, the original poster would not have had any reason to start this thread.
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