Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28593 Discussions

Reading Textfile format conventions problem

jaeger0
Beginner
439 Views
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



0 Kudos
5 Replies
mecej4
Honored Contributor III
440 Views
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
0 Kudos
Les_Neilson
Valued Contributor II
440 Views
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
0 Kudos
mecej4
Honored Contributor III
440 Views
Further clarification:

> the number of items in the list
^
comma-separated
0 Kudos
dboggs
New Contributor I
440 Views
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.
0 Kudos
mecej4
Honored Contributor III
440 Views
> 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.
0 Kudos
Reply