Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing on screen

Status
Not open for further replies.

fanta2

Technical User
Apr 10, 2005
78
CA
I was printing on the screen like:

Do i=1, 100
print *, 'values are ', i
Enddo
This prints rows of values like:
values are 1
values are 2
values are 3
.
.
I want the values to change in one place like

values are 1 (for the next i the value of 1 would change to 2 .... not another line)
Any idea how this can be done in fortran 90 thanks!
 
I have typo above:
...
instead of advance='no' try to use +
...
 
Thanks guys! The $ sign seems to work for me. Is it not a standard feature.

Gummibaer:
The bsp variable seems to return the position of the cursor to the beginning.
Your second alternative is awsome although it uses dfwin. It is not standard right?

mikrom and gullipe:
I will check the plus + if it works. I have F77 with + that works but I haven't checked it with F90 thoroughly. Is + a standard?
 
fanta2

To my knowledge, all my code is standard, only exception is the 'use dfwin' statement. The module with the API routine definitions will sure bear a different name with other compilers.

The calls to the API-functions (GetStdHandle, GetConsoleScreenBufferInfo, SetConsoleCursorPosition) are standard win32 API calls.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Thanks gummibaer for the explanation.

'+' doesn't seem to work in F90.
 
It does work - after some preparations.

From the links mikrom gave I came up with this prog, that does the job as well:

Code:
	program pp   

	use dfwin						! win 32 API routine definitions
	implicit none					! allways !
	integer i						! loop counter 

	open (unit = 6, file = 'CON', carriagecontrol = 'fortran')

	do i = 1, 99 
		write(6,'(a1, a10, i3)')'+','values are ', i						! write to console      
		call sleep (100)								! wait some time to see the output
  	end do            

	stop
	end

As far as I understand it, you have to specify that the console handles the first character of an output record as in the days of old, taking it for a carriage control character. That is what apparently happens in the open-statement.

The 'use dfwin' - statement is present only for the sleep function to work, you would not need both in real life.

But I am quite happy that this carriage control does not work any more unless you express your wish to do so explicitly. In the days of old I was one of those that occasionally created a lot of nearly empty printout...

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
I forgot to mention:

Once you are through with the nonadvancing output, you should turn off this carriagecontrol-mode and return to the previous output behaviour by simply closing unit 6 again

Code:
close (unit = 6)

Otherwise you would have to make sure that all your output to console starts with a blank as first character to advance to the next line.

And, this carriagecontrol = 'fortran' option of the open seems to be a special Compaq feature and no standard fortran.

Norbert


The optimist believes we live in the best of all possible worlds - the pessimist fears this might be true.
 
Thanks again gummibaer but it really needed a lot of preparation compared to the old usage.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top