home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4361 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  4.1 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!cis.ksu.edu!mac
  2. From: mac@cis.ksu.edu (Myron A. Calhoun)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: +*+*+*SYSTEM COMMANDS --FORTRAN +*+**+
  5. Date: 19 Nov 92 13:14:00 GMT
  6. Organization: Kansas State University
  7. Lines: 77
  8. Message-ID: <mac.722178966@depot.cis.ksu.edu.cis.ksu.edu>
  9. References: <1992Nov18.230140.1@vms.ucc.okstate.edu>
  10. NNTP-Posting-Host: depot.cis.ksu.edu
  11.  
  12. vpillai@vms.ucc.okstate.edu writes:
  13. >    I am a beginner in FORTRAN
  14. >    Can anybody tell me how to call system commands from a 
  15. >    FORTRAN program. like CLEAR SCREEN (cls)
  16.  
  17. Although the following (which I put together for one of my undergraduate
  18. classes) mentions Pascal, the same idea will work from any program,
  19. including FORTRAN, if the screen driver is ANSI.SYS compatible:
  20.  
  21. ------------ cut here ------------ cut here ------------ cut here ------------
  22. ********
  23. * ANSI *   is a character device driver that enables programs to use special
  24. ********   character sequences (escape codes) to control cursor positioning
  25. in screen displays and to redefine the function or meaning of any key in the
  26. keyboard.  ANSI.SYS is a TSR ("Terminate and Stay Resident") module which
  27. MUST be loaded at system boot time; include the line "DEVICE=pathinfo\ANSI.SYS"
  28. in your CONFIG.SYS file.  ANSI is similar to CON in that it drives the keyboard
  29. and monitor; the difference is that ANSI translates ANSI escape codes into
  30. special console functions.
  31.  
  32. In the descriptions given below, the symbol % represent the 1-byte code for ESC
  33. [that is, CONST ESC = CHAR(27); in Turbo Pascal notation].  Additionally, X and
  34. Y symbols are used to designate decimal numbers specified in ASCII [that is, the
  35. number 123 would have to be written '123'].
  36.  
  37.  CODE   CONTROLS                           DESCRIPTION
  38. ====== =============  ==========================================================
  39. %[X;YH Cursor X,Y     Move the cursor to [LINE,COLUMN] position specified by
  40.                       the X,Y parameters.  If X > 25 then 1 is used by default;
  41.                                            if Y > 80 then 80 is used.
  42.  
  43. %[XA   Cursor Up      Move cursor up/down in the same column; ignored if cursor
  44. %[XB   Cursor Down    is already on the top/bottom line of the screen.
  45.  
  46. %[XC   Cursor Right   Move cursor right/left in the same row; ignored if cursor
  47. %[XD   Cursor Left    is already in the right-/left-most column of the screen.
  48.  
  49. %[s    Save Position  Save current cursor position.
  50. %[u    Restore  "     Restore cursor position which was saved previously.
  51.  
  52. %[2J   Erase Screen   Erase entire screen.
  53. %[K    Erase to EOLn  Erase screen from current cursor position to end of line.
  54.  
  55. [There are other screen and keyboard functions which are not included here.]
  56.  
  57.  
  58. You may find it instructive to "play" with the following little test program
  59. I wrote while trying to determine just how this ANSI stuff actually works:
  60.  
  61. PROGRAM Test (INPUT, OUTPUT);
  62.   CONST ESC         = CHAR(27);     { ESCape character }
  63.         ClearScreen = ESC + '[2J';  { ANSI sequence to clear the entire string }
  64.  
  65.   VAR   Xint, Yint : INTEGER;   { Xint = integer value, Xstr = string value ...}
  66.         Xstr, Ystr : STRING[2]; { Two-digit values "cover" the range of 1..80  }
  67.  
  68. BEGIN
  69.   WHILE (1=1) DO BEGIN       { So-called "infinite" loop; terminate with ^C }
  70.  
  71. { Move cursor to near bottom left of screen and prompt user for coordinates }
  72.     Write (ESC + '[24;1f');
  73.     WriteLn ('Input two integers for Row and Column coordinates');
  74.  
  75. { Fetch ROW,COLUMN values from user, convert both into string form, and use them
  76.   to place a "#" symbol at the specified location on an otherwise blank screen }
  77.     ReadLn (Xint, Yint);  Str (Xint:1, Xstr);   Str (Yint:1, Ystr);
  78.     Write (ClearScreen, ESC + '[' + Xstr + ';' + Ystr + 'H', '# ')
  79.   END {WHILE}
  80. END.
  81. ------------ cut here ------------ cut here ------------ cut here ------------
  82.  
  83. --Myron.
  84. -- 
  85. # We preserve our freedoms using four boxes:  soap, ballot, jury, and cartridge.
  86. # Myron A. Calhoun, PhD EE; Assoc. Professor  (913) 539-4448 home
  87. # INTERNET: mac@cis.ksu.edu (129.130.10.5)          532-6350 work, 532-7353 fax
  88. #     UUCP: ...rutgers!depot!mac     Packet-BBS: W0PBV @ K0VAY.#NEKS.KS.USA.NAOM
  89.