Pavol Namer
Pavol Namer

Reputation: 85

How to write a large amount of columns in a formatted file

I'm trying to write a code in fortran90 that allows me to create lets say 20 columns (f10.6) with one space between them in to the "output file". When I try to create file just with the 4 columns it works, but when I try to format a file with 5 or more columns it writes results wrong.

So my code for four columns looks like:

 do i=1, 200
     write(1,207) nq(i),plt_Dy1c4(i),plt_Dy3(i),plt_Dy4(i) 
       207   format(4(f10.6,x))
 end do

Similar for five columns looks like, but this doesn't works:

 do i=1, 200
 write(1,207) nq(i),plt_Dy1c4(i),plt_Dy3(i),plt_Dy4(i),plt_Dy5
   207   format(5(f10.6,x))
end do

The output files for five columns has 8200 rows instead of 200.

Is there any statement which should be used for creation of file which has many columns?

Upvotes: 1

Views: 310

Answers (1)

chw21
chw21

Reputation: 8140

What is plt_Dy5? I have the nagging feeling that it is an array with dimension(200), as your other plt_* vars seem to be.

If that is the case, then for every write() statement, it would write out the whole 200 values of plt_Dy5 in addition to the current index values of the other arrays, to a total of 204 values.

Since the format only allows for 5 values per row, this would mean 41 rows per write statement. Multiply this by 200 iterations of the loop, and you come to 8200 rows.

So simply replace plt_Dy5 by plt_D5(i) and you should be fine.

Upvotes: 1

Related Questions