Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29233 Discussões

Reading Textfile format conventions problem

jaeger0
Principiante
737 Visualizações
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 Respostas
mecej4
Colaborador honorário III
738 Visualizações
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
Les_Neilson
Contribuidor valorado II
738 Visualizações
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
mecej4
Colaborador honorário III
738 Visualizações
Further clarification:

> the number of items in the list
^
comma-separated
dboggs
Novo colaborador I
738 Visualizações
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.
mecej4
Colaborador honorário III
738 Visualizações
> 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.
Responder