Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write without a newline in Fortran?

Tags:

io

fortran

I'm writing a piece of code by which I plan to write a .txt file that's a 10x10001 matrix:

do i = 1, 10
    read(1,10) seed !Read a number from file 1
    write(2,20) seed !Write that number in file 2
    do k = 1, 10000 
        seed = mod((a*seed),m)
        R = seed/m
        write(2,20) R !I want all these numbers to be next to the seed, not on new lines
    end do
end do

But all the R's are written on new lines.

Is there a way to separate every number with a space instead of a new line, or should I implement this same code using C++ and pipelines?

like image 416
Miguelgondu Avatar asked Sep 07 '14 20:09

Miguelgondu


1 Answers

You can make write not add a newline at the end with the following code:

write(2, 20, advance="no") R
like image 67
Arnon Zilca Avatar answered Sep 29 '22 03:09

Arnon Zilca