- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to show progress of the program on the screen (standard output). I would like to refresh the current line it is writing to. For example, I want it to simply print the current index to the screen, but I don't want it to print the index each time on a new, seperate line.
I think the rewrite command would work for a regular file, but get an error on the following line of code:
rewrite(*,*)'Progress: ',i,' of 100'
What I want:
Progress:3 of 100
What I don't want:
Progress 1 of 100
Progress: 2 of 100
Progress: 3 of 100 etc...
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try something like this
write (*,'(a,i0,a,$)') 'Progress: ',i,' of 100'
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
write (*,"(t1,a,i0,a,advance='no')") 'Progress: ',i,' of 100'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why is it I can neverremember the "Advance=NO" option ?
To do my reply I justhad a quick look at some codeweuse for doing exactly this sort of "progress" thing andmerely copied thewrite statementas is. One day I shall ask permission to change the code.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the ideas, however, it's still not working...
write
(*,'(t1,a,i0,a,advance=no)') 'Progress: ',i,' of 100' didn't work - compiler complained that 'A constant or general expression must appear in a format list in this context. [,a,advance=no]It also complained that characters =, c, n and v are not valid in a format list.
I tried pulling the advance='no' out of the format list, but then it doesn't write anything to the screen
write(*,'(t1,a,i0,a)',advance='no') 'Progress: ',i,' of 100'
I also tried Les's line of code write (*,'(a,i0,a,$)') 'Progress: ',i,' of 100'
But only get a continuous stream of output. I'll admit, I have no idea what the $ does.
Progress: 1 of 100Progress: 2 of 100Progress:3 of 100Progress: 4 of 100Progress:5 of 100 etc....
Any other suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
use ifcore
write (*,*)
do i=1,10
write (*,'("Testing ",I2,A,$)') i,char(13)
call sleepqq(1000)
end do
write (*,'(A)') char(10)
end
The $ suppresses the newline at the end of the line. ADVANCE='NO' (which is a separate WRITE keyword and not part of the format) does not work for this as it does not move the cursor back to the beginning of the line. I found it also necessary to write CR and LF characters to get things positioned right. The call to sleepqq was just for the purpose of the test.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry my mistake. Looking closer atour actual code that does a progress count in fact it writes a number ofbackspaces ( using bs = char(8) ) before writing the string.
The code I showed before isusedtodisplay a prompt andget a user response on the same line.
The $ is an old extension before advance='no' came about.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
The only limitation is the line of text cannot be longer than 1 line. I added text that inadvertantly split across two lines of the standard output and it doesn't work in that case. If the length is less than the standard output record length it works.
I'm not clear how the char(13) and char(10) actually make this work, but thanks
Matt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
CHAR(13) is CR - it moves the cursor to the beginning of the current line. CHAR(10) is LF - it moves the cursor to the next line.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page