kjm100@csc.anu.oz (08/01/90)
31 July 1990 *** Attention: SUN FORTRAN/C/OS gurus *** I would be very grateful if anyone could tell me how to read keyboard characters --- one at a time without echoing those characters to the terminal --- within a SUN FORTRAN program. One would think that using the integer function GETC would do the trick but no ... Specific application: I have written a CCD stellar photometry package (see Mighell 1989, Mon. Not. R. astr. Soc. 238:807-833) which currently runs on VAX VMS systems. Since the big VAX at Mount Stromlo will be removed in November I am currently trying to port the package over to SUN machines. My program reads the coordinates from a Tektronix 4010 crosshairs (GIN mode) without echoing the cryptic Tektronix 4010 codes back to the graphics terminal. This is easy to do within VAX FORTRAN but is apparently very difficult within SUN FORTRAN. Plea for help: Surely this problem was solved a long time ago in SUNland but the terse SUN documentation makes a lone scientist long for the rather verbose VAX user manuals. Apparently it is possible to overide the standard terminal definitions of the SUN operating system within a SUN C program but how can this be done within SUN FORTRAN? *** ANY help would be greatly appreciated!!! *** Thank you, Ken Mighell -- +-----------------------------------------------------------------------------+ | Kenneth John Mighell | | Mount Stromlo and Siding Spring Observatories | | Private Bag, Post Office Weston Creek, ACT 2611, AUSTRALIA | | email: mighell@mso.anu.oz.au (INTERNET) phone: 06-249-0234 fax: 06-249-0233 | +-----------------------------------------------------------------------------+
khb@chiba.Eng.Sun.COM (Keith Bierman - SPD Advanced Languages) (08/02/90)
In article <2587.26b69a29@csc.anu.oz> kjm100@csc.anu.oz writes: I would be very grateful if anyone could tell me how to read keyboard characters --- one at a time without echoing those characters to the terminal --- within a SUN FORTRAN program. One would think that using the integer function GETC would do the trick but no ... It isn't hard, but perhaps we do need another example or two ;> (note that the f77v1.3 docset is already about 2x the size of previous editions...) First a f77 driver: program bork c c Example of how a program like login works: c integer getc_noecho character*1 char/" "/ write(6,'("enter password ",$)') call flush(6) ! make sure we see the prompt istat=getc_noecho(char) do while (istat .gt. 0) write(6,*) "char = ",char istat=getc_noecho(char) end do print*," look ma, no hands " end This will print out "enter password " and wait for input. We'll read the buffer one byte at a time until an end of file (^D) is input. We will be tacky and print out each character, one to a line, to prove the characters are, indeed being read. Here is the C code for getc_noecho /* emulate getc, but don't echo */ #include <termios.h> getc_noecho_(buf) char buf[]; { struct termios old, new; int rv; /* return value */ int size; /* this is quite tacky; one might prefer a buffer */ int fd; /* at a time ... or to use any file .... */ size=1; fd=0; /* then size, fd would be arguments */ if (ioctl(fd, TCGETS, &old) == -1) return -1; new = old; new.c_lflag &= ~ECHO; /* ioctl is the magickey */ if (ioctl(fd, TCSETS, &new) == -1) return -1; rv = read (fd, buf, size); if (ioctl(fd, TCSETS, &old) == -1) return -1; return rv; } More elegant (or more suited to your application) implementations are left as an exercise to the reader. -- ---------------------------------------------------------------- Keith H. Bierman kbierman@Eng.Sun.COM | khb@chiba.Eng.Sun.COM SMI 2550 Garcia 12-33 | (415 336 2648) Mountain View, CA 94043