View previous topic :: View next topic |
Author |
Message |
eric_carwardine
Joined: 13 Jun 2009 Posts: 70 Location: Perth, Western Australia
|
Posted: Sun Aug 09, 2015 7:09 pm Post subject: Trapping control characters entered from keyboard |
|
|
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 |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Mon Aug 10, 2015 12:36 am Post subject: |
|
|
Plz clarify what do you specifically need. To interrupt loading of some large files ? |
|
Back to top |
|
|
eric_carwardine
Joined: 13 Jun 2009 Posts: 70 Location: Perth, Western Australia
|
Posted: Mon Aug 10, 2015 1:57 am Post subject: |
|
|
To make effective the 'end=' option in a READ statement, such as:
Code: |
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 |
|
Back to top |
|
|
DanRRight
Joined: 10 Mar 2008 Posts: 2816 Location: South Pole, Antarctica
|
Posted: Mon Aug 10, 2015 10:04 am Post subject: |
|
|
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 |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Aug 10, 2015 12:18 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
IanLambley
Joined: 17 Dec 2006 Posts: 490 Location: Sunderland
|
Posted: Mon Aug 10, 2015 5:18 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
eric_carwardine
Joined: 13 Jun 2009 Posts: 70 Location: Perth, Western Australia
|
Posted: Sat Aug 15, 2015 1:45 am Post subject: Re: |
|
|
IanLambley wrote: |
{start snip}So what are you actually trying to achieve.{end snip}
|
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 |
|
Back to top |
|
|
|