Write in a same line of a file

I have a variable that is changing with each time step. I want to record the values for each time steps in a file.

WRITE (21,*) sim_time,x_c(2,2,2),x_al(2,2,2),phi_1(2,2,2), phi_2(2,2,2)
But the problem is I want these variables of each time step in a single line. But they are giving output in different line for each variable.
Also, what type of format do I need to use to see them in 0.xxx format?

When you care about formatting, don’t use list-directed (* format), as you lose all control. I might suggest:
WRITE (21,'(G0.2,3(1X,F5.3))') sim_time,x_c(2,2,2),x_al(2,2,2),phi_1(2,2,2), phi_2(2,2,2)
I’m guessing at the type of sim_time - G0.2 will accept any intrinsic type, write it in an appropriate format with two digits to the right of the decimal (if not integer). You may want to choose something else.

1 Like