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

reading data files

forall
Beginner
753 Views
Hi,

I am trying to read a data file with the following line (the quotes denote the start and end of the line) " 0: 56 56 120 /".

I want to ignore the first 3 characters and read the 3 integers (56,56,120) into 3 integer variables i, j, k. However the numbers of blanks between them can vary depending on the input file, eg, some file may have " 0: 56 56 120 /". Is here a simple syntax for doing this?

I tried "read (unt,'(a3,i0,i0,i0)') str, i, j, k" (where str is a character string) and similar variants, but either end up with i=5656120 and j=k=0, or with a read error...

any pointers would be appreciated!
dmitri
0 Kudos
1 Reply
Steven_L_Intel1
Employee
753 Views

You could do it this way:

character(100) record
...
READ (unit,'(A)') record
READ (record(4:),*) i,j,k

Note that if the input data is bad (for example, letters or punctuation), you may not get an error from the list-directed read.

0 Kudos
Reply