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!

Fortran equivalent of the GotoXY in pascal 1

Status
Not open for further replies.

Stridx

Programmer
Sep 4, 2006
4
DK
Hello,

I've been doing programs in the Pascal and Qbasic and I've picked up doing alot of Fortran lately (been using it previously aswell). For output to the screen, I use the Print or Write commands normally. This is in a non-graphic enviroment, by the way. (Like DOS or Linux without X).
These methods generate a new line and pushes lines already written a line up.

If I wanted a certain string to be written a specific place on the screen (80 characters by 24 lines), how do I do that?

In, say, Pascal, I would do something like this:


Program XY;

Uses Crt;

Begin
GotoXY(10,10;
Write('This text begins at line 10, character 10');
end;

End Program XY


Or in, say Qbasic:

LOCATE 10, 10: PRINT "This text begins at line 10, character"

Is there an equivalent to this in FORTRAN or am I left with no hope? I've been searching alot both on this forum and via Google, but I couldn't come up with anything useful.

Any input is appreciated!

Thanks alot,
Anders Christensen
 
Does the terminal accept ANSI sequences?

Check if ESC[2J clears the screen
If it does look up the ANSI sequence for cursor positioning. There are two sequences that do the same thing and the coordinates have to be in ASCII strings.
 
How do I make it 'print' the ANSI sequence?

I've tried
Print*, ESC[2J and WRITE (*,*) ESC[2J[/B

Is there another way?

Thanks,
Anders
 
Code:
character*4 clearscreen
clearscreen = char(27) // '[2J'
print *, clearscreen
 
Great - that worked. Thank you!
I think I get it now, seems to work fine, I just can't figure out how to move the cursor up a number of lines, only backwards on the same line. I think I will look some more into that.
 
If that worked, then the sequence you are looking for is esc[Pl;PcH The only problem you'll hit is Pl and Pc must not have any spaces. It is a lot of messing about but the sequence for a left justified string is trim(adjustl(str)).

See if the following works on your system
Code:
      subroutine ClearScreen
      character*4 seq
      seq = char(27) // '[2J'
      print *, seq
      return
      end subroutine

      subroutine printat (x,y,str)
      integer x, y
      character*(*) str
      character*4 xstr, ystr
      write (xstr, '(I4)') x
      write (ystr, '(I4)') y
      print *, char(27), '[',
     &   trim(adjustl(ystr)),';',trim(adjustl(xstr)),'H',str
      return
      end

      program main
      call ClearScreen
      call printat (10, 20, 'botlft')
      call printat (60, 5, 'toprgt')
      call printat (10, 5, 'toplft')
      call printat (60, 20, 'botrgt')
      stop
      end
 
Wow, thanks, that code is exactly what I am looking for! Compiled right-out-of-the-box so to speak, just had to remove the "&" sign and make it one longer line.

I think I get the sequencing now, thanks once again.

Anders
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top