GETCHAR() IN FORTRAN 
Author Message
 GETCHAR() IN FORTRAN

Recently I posted:

Quote:
>I am a novice at programming in fortran however, I have done extensive
>programming in C.  One of the funtions in C which I found useful was the
>getchar() function.  This function waits for the user to input a single
>character (the answer to a yes/no question) without waiting for the enter
>key.  Is this possible to do in Fortran?

>Also, is there a way that I could let the user use the function keys and the
>arrow keys?

In this posting, I neglected to mention the type of machine I was using, the
operating system, and the version of FORTRAN I was using.

I am using a PC, DOS-based machine, FORTRAN 90 and the program has no need
for portability.  I hope that this information will get more positive
responses.  Thank you to those who have responded.


------------------------------------------------------------------------------
Paul Belfry
Village II North E
Room 119
725-9681



Sun, 21 Jul 1996 06:46:58 GMT  
 GETCHAR() IN FORTRAN

Quote:
>Recently I posted:

>>This function waits for the user to input a single
>>character (the answer to a yes/no question) without waiting for the enter
>>key.  Is this possible to do in Fortran?

I'd like an answer to the same question, only for a Unix system,
specifically a Sun SparcStation.

Kathy Rages



Mon, 22 Jul 1996 05:29:37 GMT  
 GETCHAR() IN FORTRAN

Quote:
>Recently I posted:

>>I am a novice at programming in Fortran however, I have done extensive
>>programming in C.  One of the funtions in C which I found useful was the
>>getchar() function.  This function waits for the user to input a single
>>character (the answer to a yes/no question) without waiting for the enter
>>key.  Is this possible to do in Fortran?

>>Also, is there a way that I could let the user use the function keys and the
>>arrow keys?

>In this posting, I neglected to mention the type of machine I was using, the
>operating system, and the version of FORTRAN I was using.

>I am using a PC, DOS-based machine, FORTRAN 90 and the program has no need
>for portability.  I hope that this information will get more positive
>responses.  Thank you to those who have responded.

Paul,

  you are wrong is assuming that getchar() works as you are claiming.
Had this been true, no need would be for getche() in Borland C languages.
In fact the ANSI C standard does not explicitly state WHEN THE GETCHAR()
will return. You are only guaranteed that you will get the first char
"waiting" in stdin, but not when. So your claim about getchar() functionality
is incorrect to my knowledge. As an example try the following:
----
#include <stdio.h>

main()
{
  int c;

  while ((c=getchar()) != '0')
    printf("\t<%d>\n", c);

Quote:
}

-----
and it won't work as you claim. (Yes I tried it on VAX, AXP and HP-RISC).

  Now regarding your question: there is *no* portable way of doing this
in FORTRAN either; both FORTRAN 77 and 90 for that matter. However, the
recommended solution in these cases is to write routines of the form:
SYS_GETCHAR_ECHO() that you rewrite every time you move to another
platform. Now for PCs you will need to have a gateway routine to
the system/BIOS interrupt services. Usually such a routine has a
format:
        SUBROUTINE INT86( INT_NO, REGS_IN, REGS_OUT )
Where INT_NO is the interrupt number, and REGS_IN, REGS_OUT are integer
arrays containing the values of registers at input/output. Once you
have this routine at your service you will need to find the correct
interrupt. For your needs you will need INT21h function 07h and read
the AL register on return. The register will contain the character,
or for extended key-code like the arrow keys a zero (0) in which
case you need to execute the interrupt again to get the "truly" hit
key/character. For more on this send me e-mail or get yourself a
good book on MS-DOS interrupts, or download the Ralf Brown's list
of interrupt services (available in Win HELP format and text format)
from garbo.uwasa.fi at pc/programming; I think the files start with
intxxxx or something like that.

  Hope this helps a bit.

Petros Dafniotis



Mon, 22 Jul 1996 13:11:56 GMT  
 GETCHAR() IN FORTRAN

Quote:
Kathy Rages writes:
>>> This function waits for the user to input a single
>>> character (the answer to a yes/no question) without waiting for the enter
>>> key.  Is this possible to do in Fortran?
> I'd like an answer to the same question, only for a Unix system,
> specifically a Sun SparcStation.

Such a function is not an intrinsic function in ANSI standard FORTRAN 77
(anybody know if it has been added to Fortran 90?), so whatever you use
will be nonportable.  Your best bet might be the corresponding C function,
because many FORTRAN compiler vendors also offer C compilers with support
for calling one from the other.

I use the KbdCharIn API in OS/2.  It has the nice feature of offering
both blocking and nonblocking modes.  I've used it to program what is
essentially an infinite loop, but you can get out of the loop with the
Esc key; all other keystrokes are ignored.  Lots of wonderful uses for
nonblocking I/O.



Mon, 22 Jul 1996 19:55:00 GMT  
 GETCHAR() IN FORTRAN

Quote:
>Kathy Rages writes:

>>>> This function waits for the user to input a single
>>>> character (the answer to a yes/no question) without waiting for the enter
>>>> key.  Is this possible to do in Fortran?

>> I'd like an answer to the same question, only for a Unix system,
>> specifically a Sun SparcStation.

>Such a function is not an intrinsic function in ANSI standard FORTRAN 77
>(anybody know if it has been added to Fortran 90?), so whatever you use

It hasn't, as far as I know.

Quote:
>will be nonportable.  Your best bet might be the corresponding C function,

There is no corresponding ANSI C function.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Thu, 25 Jul 1996 22:00:50 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. GETCHAR IN FORTRAN

2. gets() and getchar

3. HELP Assignment due in!! GetChar Problems

4. getchar and get()

5. getchar/kbhit in TCL

6. A GetChar (C) or ReadKey (Pascal) type function in FORTRAN????

7. fortran.i - SWIG library module for FORTRAN code wrapping

8. VC++ calling fortran function and fortran function calling a c++ function

9. DEC Fortran 90 -> SGI Fortran 90

10. (newbie) new (future) fortran functions, fortran standard committee

11. c++ calling fortran and fortran calling C++

12. Intel fortran and fortran 77 standard!

 

 
Powered by phpBB® Forum Software