Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Beginner
19 Views

How to output a matrix without changing to a new line?

For example

program main
integer m
complex cjj
complex matrix(3, 5)

cjj=(0.0, 1.0)
matrix(1, :)=2*cjj
matrix(2, :)=2+1*cjj
matrix(3, :)=5*cjj+6

open(16, file='data.txt')
do m=1, 3
write(16, *)matrix(m, :)
enddo
close(16)
end

The above code does not work well. What I want is that the data in the output file is the same as the dimension of the matrix.

For this case, the size of the matrix is 3*5. What I want is also there are 3 lines ,and each line has 5 values.

0 Kudos
2 Replies
Black Belt
19 Views

Do not use list-directed WRITE when you require the output to be formatted in a certain way. The following will work with IFort for your program above:

     write(16, '(*(F5.1,2x,F6.2))')matrix(m, :)

 

0 Kudos
Beginner
19 Views

mecej4 wrote:

Do not use list-directed WRITE when you require the output to be formatted in a certain way. The following will work with IFort for your program above:

     write(16, '(*(F5.1,2x,F6.2))')matrix(m, :)

 

Thanks so much,

Even though I have been using Fortran for many years. I still do not familiar with the Fortran output/input format. Could you please tell me, how to make the output of a complex number like:

(1.69E-004,4.06E-007)

 

Thanks,

Best regards,

Tai

0 Kudos