Could this code be simply translatable to FTN?

void locate(short x, short y)
{
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

subroutine locate (x,y)
    use :: kernel32
    implicit none
    
    integer(SHORT), intent(IN) :: x,y
    integer(BOOL) :: ret
    
    ret = SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), T_COORD(X,Y))
    end subroutine locate

This assumes Intel Fortran for the kernel32 module. As shown here, x and y are not passed by value as they would be in C; that could be changed.

You assume intel Fortran, but I have Gfortran and cannot use the intel Fortran compiler because I absolutely do not want to the Microsoft visual environment which, as I understand, it requires,

Intel Fortran requires the installation of Visual C++, but you can do everything from the command line. Nevertheless, I believe that gfortran includes its own set of Windows API declarations and you should be able to adapt the code I showed to use it. You asked how to convert that C code to Fortran (at least I assumed that’s what you meant by “FTN”), so I showed that.

It is possible to run the Intel compilers, ifort and ifx, from the command line in Windows, just as you do with gfortran. I have done so.

1 Like

Thank you for you response!
Sorry if I am not communicating in an effective way. I am a rooky at Fortran. My compiler is: gcc\x86_64-w64-mingw32. When I compile, I do so from the command line,

I am wanting to locate x,y, just as I do when using C language, like so:

void locate(short x, short y)
{
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

I do not have the knowledge to translate what you wrote for use with a different compiler than Intel.

So I will have to download the intel compiler to be able to profit from your post?

Thank you for the information about the Intel compiler. I will need to travel the maze to find it on the Net and download it.

Patrick, consider this an opportunity to learn more about Fortran and about how to call functions that are outside of the Fortran language. The defeatist attitude that comes across in your posts does not encourage others to help you. If you are expecting others to write your code for you, you will end up disappointed.

Yes, if you want to use the code I gave exactly as written, then you need to use the Intel compiler. It is hardly difficult to find, but if you would like a pointer, this is useful.

I used Intel Fortran here because that’s the compiler I know and use. It can be used completely from the command line if you desire. (I think it can be used from Cygwin too, but I have not tried that.) Maybe you can convince someone else to modify the code for gfortran if you’re unwilling to put in any effort.

1 Like

Hi @Patrick here another advise, while my main compiler is also Intel (ifort) I also use a lot gfortran. And whenever I just want to understand the behaviour a small code snipet I do not want to create a big project just for 3 lines of code… So, a fantastic solution is this site: https://godbolt.org/

Here an example of what you can do:

You write your code on one windows, click on “Add new>Execution only” and you will have a new window in which you can chose you compiler, there are several version of ifort / ifx / gfortran to chose from. You can also check the ASM code to see which compiler is optimizing better and how… etc etc.

This is my default go to online compiler to play around before going to doing my actual implementations. And being able to see the result from different compilers is also useful to know if you are just using a compiler-specific tool or something more standard.

Hope it helps

1 Like

How can you simply confront a person, having tried to the best of his ability to clearly state his case, and having done so with utter respect for the addressee in question, with such hard, depreciative, and abrasive comment? It makes me very miserable to read such a confrontational narrative. Please have some respect for someone who is totally new in the domain of knowledge that you profess to be yours.

@Patrick, I think that you fail to recognize that your chosen basic task (writing text to a specific screen position) has no support in standard Fortran. The only way is to call a library routine, or a non-standard routine provided by the compiler vendor, to perform the task. Different compilers may use different ways of doing this, or not implement it at all. Some may require that you go through a C routine as an intermediary to an OS-provided shared library (DLL). In fact, the five lines of “C code” that you showed in the original post are not supported by standard C, either!

One possible solution to screen positioning that you should probably study: ANSI escape sequences .

As a self-styled “rookie”, you are creating an obstacle course for yourself by choosing tasks that Fortran was not designed to do and that a Fortran compiler is not required to support. My suggestion is that you gain experience with character mode Fortran programs before attempting some of the things that you have done so far.

2 Likes

Thank you for posting to me. In comparison to what I still need to learn, my current knowledge of Fortran is deplorably zero. So for very bit of help I am grateful. It isn’t that I am too lazy to sort things out for myself, as your colleague poster implied. I have an ad summos honores degree in my own domain of knowledge, and an honours degree in another.