texas
texas

Reputation: 45

reading the Nth column of a .txt

I work in fortran

I know that you can read several columns by doing :

read (20,*) a,b,c

but I have a document with something like 25 columns but i would like to read the 19th without having to use trash variables like i do know.

I use :

read (20,*) trash1,trash2,[...],trash18,VariaWanted

I would like to know if there is a "cleaner" way to do so. Especially if I can use an integer to say where it is, so I can put it in "in variable" of function or subroutine.

Upvotes: 0

Views: 2336

Answers (2)

You do not show the actual format of your file. Often the tables use fixed column width. Then you can just use explicit format to read just that character columns in the row.

read (20,'(t42,f8.0)') a

Provided you want to read a real that uses 8 characters and starts on character column 42.

Upvotes: 4

M. S. B.
M. S. B.

Reputation: 29381

Perhaps:

real, dimension (25) :: temp
real :: keep
read (20,*) temp
keep = temp (19)

Upvotes: 2

Related Questions