Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing on the same line in FORTRAN

Tags:

fortran

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.

like image 850
user2712002 Avatar asked Aug 23 '13 18:08

user2712002


People also ask

How do I print to the next line in Fortran?

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.

What is write statement in Fortran?

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.

What does print * mean in Fortran?

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.

How do I open a Fortran file?

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.


1 Answers

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.

like image 106
Kyle Kanos Avatar answered Sep 18 '22 17:09

Kyle Kanos