From: mac@cis.ksu.edu (Myron A. Calhoun)
Newsgroups: comp.lang.fortran
Subject: Re: +*+*+*SYSTEM COMMANDS --FORTRAN +*+**+
Date: 19 Nov 92 13:14:00 GMT
Organization: Kansas State University
NNTP-Posting-Host: depot.cis.ksu.edu

vpillai@vms.ucc.okstate.edu writes:
>	I am a beginner in FORTRAN
>	Can anybody tell me how to call system commands from a 
>	FORTRAN program. like CLEAR SCREEN (cls)

Although the following (which I put together for one of my undergraduate
classes) mentions Pascal, the same idea will work from any program,
including FORTRAN, if the screen driver is ANSI.SYS compatible:

------------ cut here ------------ cut here ------------ cut here ------------
********
* ANSI *   is a character device driver that enables programs to use special
********   character sequences (escape codes) to control cursor positioning
in screen displays and to redefine the function or meaning of any key in the
keyboard.  ANSI.SYS is a TSR ("Terminate and Stay Resident") module which
MUST be loaded at system boot time; include the line "DEVICE=pathinfo\ANSI.SYS"
in your CONFIG.SYS file.  ANSI is similar to CON in that it drives the keyboard
and monitor; the difference is that ANSI translates ANSI escape codes into
special console functions.

In the descriptions given below, the symbol % represent the 1-byte code for ESC
[that is, CONST ESC = CHAR(27); in Turbo Pascal notation].  Additionally, X and
Y symbols are used to designate decimal numbers specified in ASCII [that is, the
number 123 would have to be written '123'].

 CODE   CONTROLS                           DESCRIPTION
====== =============  ==========================================================
%[X;YH Cursor X,Y     Move the cursor to [LINE,COLUMN] position specified by
                      the X,Y parameters.  If X > 25 then 1 is used by default;
                                           if Y > 80 then 80 is used.

%[XA   Cursor Up      Move cursor up/down in the same column; ignored if cursor
%[XB   Cursor Down    is already on the top/bottom line of the screen.

%[XC   Cursor Right   Move cursor right/left in the same row; ignored if cursor
%[XD   Cursor Left    is already in the right-/left-most column of the screen.

%[s    Save Position  Save current cursor position.
%[u    Restore  "     Restore cursor position which was saved previously.

%[2J   Erase Screen   Erase entire screen.
%[K    Erase to EOLn  Erase screen from current cursor position to end of line.

[There are other screen and keyboard functions which are not included here.]


You may find it instructive to "play" with the following little test program
I wrote while trying to determine just how this ANSI stuff actually works:

PROGRAM Test (INPUT, OUTPUT);
  CONST ESC         = CHAR(27);     { ESCape character }
        ClearScreen = ESC + '[2J';  { ANSI sequence to clear the entire string }

  VAR   Xint, Yint : INTEGER;   { Xint = integer value, Xstr = string value ...}
        Xstr, Ystr : STRING[2]; { Two-digit values "cover" the range of 1..80  }

BEGIN
  WHILE (1=1) DO BEGIN       { So-called "infinite" loop; terminate with ^C }

{ Move cursor to near bottom left of screen and prompt user for coordinates }
    Write (ESC + '[24;1f');
    WriteLn ('Input two integers for Row and Column coordinates');

{ Fetch ROW,COLUMN values from user, convert both into string form, and use them
  to place a "#" symbol at the specified location on an otherwise blank screen }
    ReadLn (Xint, Yint);  Str (Xint:1, Xstr);   Str (Yint:1, Ystr);
    Write (ClearScreen, ESC + '[' + Xstr + ';' + Ystr + 'H', '# ')
  END {WHILE}
END.
------------ cut here ------------ cut here ------------ cut here ------------

--Myron.
-- 
# We preserve our freedoms using four boxes:  soap, ballot, jury, and cartridge.
# Myron A. Calhoun, PhD EE; Assoc. Professor  (913) 539-4448 home
# INTERNET: mac@cis.ksu.edu (129.130.10.5)          532-6350 work, 532-7353 fax
#     UUCP: ...rutgers!depot!mac     Packet-BBS: W0PBV @ K0VAY.#NEKS.KS.USA.NAOM
Newsgroups: comp.lang.fortran