I'm doing project Euler ID11 (http://projecteuler.net/index.php?section=problems&id=11), and I thought I'd try this one in FORTRAN 95. The first problem in the project is finding a suitable way of reading in a 20x20 matrix of integers.(adsbygoogle = window.adsbygoogle || []).push({});

I'm doing it by put the 20x20 matrix into a separate file called data1.txt and thought I could have FORTRAN read in each data point like this:

The problem I have is that it READ only reads the first column before reaching end of file and skips the space delimited data on the same row. I got around this by writing:Code (Text):

integer :: m(20,20), i, j

open(1001,file='data1.txt')

do i = 1, 20

do j = 1, 20

read(1001,*) m(i,j)

end do

end do

But this is a really cumbersome and ugly solution! Surely there must be a better way?Code (Text):

integer :: m(20,20), i

open(1001,file='data1.txt')

do i = 1, 20

read(1001,*) m(i,1), m(i,2), m(i,3), m(i,4), m(i,5), m(i,6), m(i,7), &

m(i,8), m(i,9), m(i,10), m(i,11), m(i,12), m(i,13), m(i,14), m(i,15), &

m(i,16), m(i,17), m(i,18), m(i,19), m(i,20)

end do

rewind(1001); close(1001);

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# FORTRAN95 dealing with space delimited data files

**Physics Forums | Science Articles, Homework Help, Discussion**