Silverfrost Forums

Welcome to our forums

Trapping control characters entered from keyboard

9 Aug 2015 6:09 #16712

G'day, folks 😄

Is there a way of intercepting control characters, such as Control-Z, entered from the keyboard so that the 'end=' option in a READ statement is effective?

Eric Carwardine, in Perth, Western Australia

9 Aug 2015 11:36 #16713

Plz clarify what do you specifically need. To interrupt loading of some large files ?

10 Aug 2015 12:57 #16715

To make effective the 'end=' option in a READ statement, such as:

160   write(6,161)
161   format(' Enter device name ',
     1'(Control-Z to quit) > ',$)
      read(5, 171, err=100, end=100) device
171   format(a8)

where '5' is the logical unit number for input at the terminal via the keyboard, '6' is the screen, and 'device' is a variable.

Eric

10 Aug 2015 9:04 #16716

There a a lot of options to get keyboard input for controlling the code flow but your respond demonstrating your goals puzzled me even more. Can anyone here ask the right question (sorry i have to leave for a week for business trip and will be here just sporadically)?

General ways to get keyboard input is via

  1. get_key@(key) in DOS-like style programming
  2. %ac accelerators in Clearwin+ in Windows-like style
  3. There also exist one more complex case using Clearwin+ %mg

All have great examples of usage in Search of this forum and in the Help for FTN95

10 Aug 2015 11:18 #16717

Eric,

Ctrl-Z works as you want, provided that you follow it with the Enter key. Ctrl-C doesn't need the Enter key but aborts the whole program.

Dan is correct that there are numerous ways of skinning this particular cat, but using simply Fortran input/output you could ask the user to type something to denote the end of input - 'END' or 'QUIT' being my suggestions. As the user might use upper or lower or mixed case, then the FTN77 functions UCASE@ and LCASE@ simplify getting the response all in the same case before doing a test.

I disliked the question and answer format for interacting with a program when it was all there was, and I'm much happier with a Windows interface via Clearwin+.

Eddie

10 Aug 2015 4:18 #16718

In the olden (Halcyon) days on Digital computers and others, Ctrl-Z ended an input to a file such as:

copy tt: myfile.dat

Then you typed the data and closed the file with a CTRL-Z

If you open a command prompt for DOS commands on a PC and type

copy con: myfile.txt

it works almost identically except that a <return> is needed to action the line containing CTRL-Z... Try it

In Fortran, you can open TT: or CON: for read and loop for input statements using do READ(5,1000,end=999)LineOfData 1000 format(a) enddo

999 continue

CTRL-Z will exit the loop.

So what are you actually trying to achieve. You could equally well put the data into a file via Notepad and then open the file and read with an END=

Regards Ian Note on VAXes etc. 'TT:' is the current terminal and refers to both the keyboard for input and screen (or roll of paper in my day!) for output. just like 'CON:' in DOS

15 Aug 2015 12:45 #16735

Quoted from IanLambley

So what are you actually trying to achieve.

First, my thanks to DanRRight, Eddie, and Ian 😄

I was on a nostalgia trip, back to when I learned Fortran and Assembler on five different systems, from DEC-10 and VAX mainframes up (or down, depending on how you regard the hierarchy of computers) to PC's. Remembering when I programmed keyboard interrupts, polled the keyboard, and intercepted everything entered at the keyboard.

Mind you, it wasn't easy learning mainframe assembler back in the 1970's There are certain things which university computing centres definitely deter students from learning.

Anyway, back to the future - and Clearwin 😄 I'll try getting ADD_KEYBOARD_MONITOR@ and GET_WKEY@ to work.

Eric

Please login to reply.