Friday 3 July 2009

Formatted Read Statements yet again.

Further to my last post, I want to add a code snippet for reading in large arrays with many columns. It has some nice implicit do-loops. "myfile.ans" contains 1 column of integers, followed by Ncols of data that I want to read into "Blam" and Ncols that I want to read into "Dlam".

integer :: i, Nrows, Ncols
real :: Blam(Nrows, Ncols), Dlam(Nrows, Ncols)
integer :: pixies(Nrows)
character(1) :: tmp

open(unit=2,file='myfile.ans',status='OLD',action='READ')
do i = 1,Nrows,
read(2,20) pixies(i), (tmp,Blam(i,j), j=1,Ncols), (tmp,Dlam(i,j), j=1,Ncols)
enddo
close(2)
20 format(I3, 36(A1,F6.4))

Annoyingly, I can't seem to replace 36 (=2*Ncols) with a variable name or my compiler shouts. A mystery for another time I think.

No comments: