- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
During my output flow, I was wondering if there is a way to put the cursor at the top left of the screen
(rather than scrolling the output)
If I reinitialize the screen BEFORE it reaches the bottom, it wont scroll, right ?
The reason for doing that is to get a dynamic readable flow of the output, which I will NOT
get if I scroll it.
Actually I dont HAVE to clear the remainder of the screen, I might just be able to place the cursor at the top left every 20 lines or so.
If you could refer me to a relevant article, that would be GREAT.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this a QuickWin application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not currently - do I have to convert it to a Quickwin app to do this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If it is a console window you can use https://docs.microsoft.com/en-us/windows/console/setconsolecursorposition if I understand what you are trying to do correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
use kernel32 type(T_COORD) :: coord integer(HANDLE) :: hConsole ... hConsole = GetStdHandle(STD_OUTPUT_HANDLE) coord%X = 0 coord%Y = 0 if(SetConsoleCursorPosition(hConsole, coord) .eq. .false.) stop "error"
The above is untested code.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Recent versions of Windows 10 also support ansi escape sequences in the console - see https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cut and pasted that from Mr. Dempsey, but it does not do anything to the cursor position.
No error, either. Its a No OP.
apparently these articles are all in C++, so is there any way to do that with fortran?
Or maybe I have to go to QUickwin instead?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A trivial variiation of Jim's code works for me.
PROGRAM MoveTheCursor USE KERNEL32 IMPLICIT NONE TYPE(T_COORD) :: coord INTEGER(HANDLE) :: hConsole PRINT "('This is where text appears before')" hConsole = GetStdHandle(STD_OUTPUT_HANDLE) coord = T_COORD(0, 0) IF (SetConsoleCursorPosition(hConsole, coord) == 0_BOOL) STOP "error" PRINT "('This is where text appears after')" END PROGRAM MoveTheCursor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>During my output flow, I was wondering if there is a way to put the cursor at the top left of the screen
Note, you did not ask to clear the screen too. While you can open kernel32.f90 and ifwinty.f90 (compiler\include folder) and examine the interfaces that sound somewhat like you need, you may find it easiest to perform a Google search:
windows console clear
The first hit: https://support.microsoft.com/en-us/help/99261/how-to-performing-clear-screen-cls-in-a-console-application
While that example is in C++, you will likely find all the system call interfaces listed in kernel32.f90 or ifwinty.f90, then using them write a Fortran analog. (I do not think you will need to muck with the text attribute)
What we are trying to do is to show you how to research a problem and solve it yourself.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I still dont know how to reference these C++ routines from a Fortran program.
I noticed there were many others with that same issue - maybe an experienced C++ user would know better.
No articles about that topic?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note that the MSDN link provided by Jim Dempsey has C calls. You don't need to know, how to call C++ code, in order to use that MSDN example.
Doesn't the sample code provided by IanH do what you need?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>I still dont know how to reference these C++ routines from a Fortran program.
The Fortran interfaces to the Windows routines are located in kernel32.f90 and ifwinty.f90 (compiler\include folder).
A complete description of the Microsoft Windows routines are listed on the Microsoft websites:
support.microsoft.com
msdn.microsoft.com
The examples on the Microsoft website are generally C/C++ and some in C#. The Fortran modules use the same interface declarations as are available in the C/C++ examples. Fortran uses
structName%memberVariable ! Intel Fortran also supports . (but is non-standard/non-portable)
whereas C/C++/C# uses
structName.memberVariable
You may run across some exceptions, some due to the fact that Fortran does not have unsigned integers.
IanH made some very useful suggestions, in particular the substitution for 0_BOOL due to C/C++ considering int(0) as a bool false, and anything else as a bool true. Fortran is quite different, Fortran looks at only the least significant bit. lsb=0=.false., lsb=1=.true. IOW C int(2) would be read as true in C, and .false. in Fortran. Note, reading the Microsoft example, return value, said a return of 0/false indicated error. IOW in Fortran you would use 0_BOOL to indicate failure (anything else is assumed to be true).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I too had the need for things like this, so I experimented and developed the attached code which does some of the things you asked for. It turns out that the API console routines--as referred to by several posters above--can do a lot of useful things and are simple to use if you just have some examples (in Fortran!) to get started.
The attached demo program (although not pretty) will set the cursor at a prescribed location, clear a block on the screen, clear the entire screen, and set the text color. I hope you find it helpful.

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