In Fortran, each time one uses WRITE
a new line is produced. In order to control the working of a program that is being executed, I would like to write on screen the current value of a variable, but always on the same line (erasing the previous value and starting at the beginning of the line). That is, something like
1 CONTINUE
"update the value of a"
WRITE(*,*) a
BACKSPACE "screen"
GOTO 1
Something like WRITE(*,*,ADVANCE='NO')
(incorrect anyway) is not quite what I
need: this would write all the values of a
one after another on a very long
line.
In Fortran, a statement must start on a new line. If a statement is too long to fit on a line, it can be continued with the following methods: If a line is ended with an ampersand, &, it will be continued on the next line. Continuation is normally to the first character of the next non-comment line.
The WRITE statement writes data from the list to a file. For tape I/O, use the TOPEN() routines. The options can be specified in any order.
PRINT *, "The output values are ", var1, var2, var3 The * indicates list-directed output, output printed according to FORTRAN's built-in rules. Formatted output allows the programmer to control the appearance or format of the output.
open (unit = number, file = "name") . open (unit = 24, file = "c:\\fortran\\data\\divisors. dat") . Fortran uses the unit number to access the file with later read and write statements.
A trick that I was shown for what you want is as follows
do l=1,lmax
...update a...
write(*,'(1a1,<type>,$)') char(13), a
enddo
where <type>
is your format specifier for a
(i.e., i0
for integer).
The key is the char(13)
, which is the carriage return, and the $
in the format descriptor. I really don't know if there is a name for $
, I just know that it works for displaying on the screen--for output to file you get an a
on each line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With