Write output data file with more than 3 columns

Hi,
How can I write an output datafile “file.dat” with more than 3 coluns?

When I use:

open(1,file=“file.dat”,status=“unknown”)
do j=1,nj
do i=1,ni
write(1,*) x,x,x,x,x
end do
end do

The data in the file becames:
x x x
x x

Instead of
x x x x x

Can you help me?

Thanks in advanced

Hi mathe1s,

You’ll need to use an explicit format in your write statement. Something like:

% cat test.f90

program foo

integer,parameter :: ni=5
integer,parameter :: nj=5
integer,parameter :: nk=5
real :: a(ni,nj,5)
integer :: i,j,k

do j=1,nj
do i=1,ni
do k=1,nk
   a(i,j,k) = real(k) / (real(i)*real(j))
end do
end do
end do

open(1,file="file.dat",status="unknown")
do j=1,nj
do i=1,ni
write(1,'(5f15.10)'), a(i,j,1), a(i,j,2), a(i,j,3), a(i,j,4), a(i,j,5)
end do
end do
close(1)
end program foo
% pgfortran test.f90; ./a.out
% cat file.dat
   1.0000000000   2.0000000000   3.0000000000   4.0000000000   5.0000000000
   0.5000000000   1.0000000000   1.5000000000   2.0000000000   2.5000000000
   0.3333333433   0.6666666865   1.0000000000   1.3333333731   1.6666666269
   0.2500000000   0.5000000000   0.7500000000   1.0000000000   1.2500000000
   0.2000000030   0.4000000060   0.6000000238   0.8000000119   1.0000000000
   0.5000000000   1.0000000000   1.5000000000   2.0000000000   2.5000000000
   0.2500000000   0.5000000000   0.7500000000   1.0000000000   1.2500000000
   0.1666666716   0.3333333433   0.5000000000   0.6666666865   0.8333333135
   0.1250000000   0.2500000000   0.3750000000   0.5000000000   0.6250000000
   0.1000000015   0.2000000030   0.3000000119   0.4000000060   0.5000000000
   0.3333333433   0.6666666865   1.0000000000   1.3333333731   1.6666666269
   0.1666666716   0.3333333433   0.5000000000   0.6666666865   0.8333333135
   0.1111111119   0.2222222239   0.3333333433   0.4444444478   0.5555555820
   0.0833333358   0.1666666716   0.2500000000   0.3333333433   0.4166666567
   0.0666666701   0.1333333403   0.2000000030   0.2666666806   0.3333333433
   0.2500000000   0.5000000000   0.7500000000   1.0000000000   1.2500000000
   0.1250000000   0.2500000000   0.3750000000   0.5000000000   0.6250000000
   0.0833333358   0.1666666716   0.2500000000   0.3333333433   0.4166666567
   0.0625000000   0.1250000000   0.1875000000   0.2500000000   0.3125000000
   0.0500000007   0.1000000015   0.1500000060   0.2000000030   0.2500000000
   0.2000000030   0.4000000060   0.6000000238   0.8000000119   1.0000000000
   0.1000000015   0.2000000030   0.3000000119   0.4000000060   0.5000000000
   0.0666666701   0.1333333403   0.2000000030   0.2666666806   0.3333333433
   0.0500000007   0.1000000015   0.1500000060   0.2000000030   0.2500000000
   0.0399999991   0.0799999982   0.1199999973   0.1599999964   0.2000000030

Hope this helps,
Mat