home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.whtech.com
/
ftp.whtech.com.tar
/
ftp.whtech.com
/
Geneve
/
9640news
/
CAT39
/
FRTRNTT.ARK
< prev
next >
Wrap
Text File
|
2006-10-19
|
18KB
|
477 lines
?
Understanding 99 FORTRAN, for your TI-99/4A and MYARC Geneve
------------------------------------------------------------
The following is the start of a tuturial on 99 FORTRAN. In this section,
I give a little history of FORTRAN, and take the user through editing,
compiling, linking, and running a small FORTRAN program.
Part 1 - The basics
-------------------
99 FORTRAN offers unique capabilities for your TI-99 and GENEVE, a syntax
similar to BASIC with the execution speed of a true compiler! FORTRAN is
more like BASIC than C or FORTH.
FORTRAN is the oldest "higher level language" developed in the 1950's. It
is best known for numerical analysis (and is still probably the best suited
language for such applications) but can easily handle other types of programs,
such as games or database programs or just about anything. As a matter of
fact, the original granddaddy adventure game "ADVENTURE" was written in
FORTRAN on a PDP-11.
As FORTRAN evolved from a very simple numerical language, to a very rich
and powerful language, various standards emerged. FORTRAN II, FORTRAN III,
and finally FORTRAN IV was standardized in 1966, with the ANSI standard
FORTRAN 66. During the 1970's, a new and very important style of pro-
gramming emerged, structured programming. What is it? Well, look at
the following pieces of FORTRAN code and see which is easier to understand:
IF ( ICODE - 10 ) 100, 110, 100
100 J = 2
GOTO 120
110 J = 3
120 CONTINUE
or
IF ( ICODE .EQ. 10 ) THEN
J = 3
ELSE
J = 2
ENDIF
The first example shows a FORTRAN arithmetic IF statement, whereas the
second a structured block IF statement. Both code segments do the exact
same function, if the variable ICODE is equal to 10, then the variable
J is set equal to 3, otherwise the variable J is set equal to 2. The
second example is MUCH easier to understand, especially later when you
go looking for statement labels.
99 FORTRAN has some FORTRAN 66 and some FORTRAN 77 features. Most important
with FORTRAN 77 is the structured IF statement, as shown above.
Equipment Needed
----------------
To run 99 FORTRAN, you need a TI-99/4A with 32k memory, disk drive, console,
monitor, and one of the modules Editor Assembler, MINI-Memory, Extended
BASIC or TI-Writer. If you have the MINI-Memory, then use it, 99 FORTRAN
makes use of the extra 4k of memory to speed compilation and for the symbolic
debugger.
You also need a copy of 99 FORTRAN. This is available from TENEX Computer
Express, Disk Only Software, or Quality 99 Software, suggested retail of
$49.95.
99 FORTRAN can also be run on a GENEVE in GPL mode (sorry, MDOS version is
not available, yet). It can be run at the highest speed (5) available.
It can also access RAM disks.
Note that the released versions of 99 FORTRAN include 2.1, 2.1.1, 2.1.2,
2.1.3, 2.1.4, 2.1.5, 2.1.6, 2.1.7, 3.1, 3.1.1, 3.1.2, 3.1.3. If you
currently have a version 2 (see the label on the boot or library disk,
or read the VERSION file on the boot or library disk) then you should
send in your warranty registration to LGMA Products. You will then
receive a letter explaining how to upgrade your system to the latest
version 3 release.
If you make copies of the boot disk, then make sure the name of the disk
is kept the same, e.g. FORTCOMP for the boot disk, and FORTLIBR for the
two library disks. If you copy the boot disk to a RAM disk (e.g. DSK5),
then make sure the name of the RAM disk is FORTCOMP also. This can be
changed with the preferences program, see the FORTRAN manual for a
description.
Booting in FORTRAN
------------------
Booting in FORTRAN is easy, just put the BOOT disk in any drive (suggest
drive one to cut down on searches), and enter BASIC, and type:
OLD "DSK.FORTCOMP.LOAD"
RUN
There are several other ways of booting in FORTRAN. A quick way with the
editor/assembler module is to use option 5 (load and run), and type:
DSK.FORTCOMP.UTIL1
If the boot process went ok, you will see a menu on the screen:
99 FORTRAN
1 Edit 6 Save
2 Compile 7 Load
3 Link 8 USER
4 Run 9 Utilities
5 Run/Debug
a blinking underscore will also be at the bottom of the screen, this is
the cursor.
To perform a function, type the number associated with the function (e.g.
1 to edit a program) followed by ENTER (or return). The boot disk will
be read for that function, the appropriate program(s) related to that
function will be read, and the function initiated. If you don't have the
boot disk plugged into a drive, then you will get a cryptic "I/O Error"
message. Just put the boot disk in and try again.
Editing a program
-----------------
Now that FORTRAN is booted, lets call in the EDITOR. From the main menu
screen (the one above), type the number 1 (for editing) and ENTER. After
a short delay, and some disk activity, the following MENU will appear:
99 Editor
Press:
1 To Load Program
2 Edit Program
3 Save Program
4 Purge Workspace
5 Display Statistics
6 Print File
Lets first edit a program. Press the number "2". The screen will clear,
and the following will be displayed:
<EOD> (Version 3.0)
Depress ENTER to open a line, then type in the following program lines:
(note that every FORTRAN statement must be preceded by SIX or more blanks,
and statement labels must fall in columns one through 5. A character other
than a blank or zero in column 6 means this is a continuation line.
Characters past column 72 are ignored):
c cc
o oo
l ll
1 67
v vv
PROGRAM SAMPLE
I = 0
DO WHILE ( I .NE. 999 )
WRITE ( 6, 9100 ) I
READ ( 6, 9110, END=9999, ERR=9999 ) I
ENDDO
9999 STOP
9100 FORMAT ( '+', C12, M10.4, 'Value of I is: ',I6,
+ M18.4, 'Enter New Value:', M18.22 )
9110 FORMAT ( I6 )
END
When finished, depress fctn/back (function/9) to return to the menu display.
Insert a blank, formatted, disk into DSK1, and select item 3 (Save Program).
99 FORTRAN responds:
File to save?
Type in a file name of:
DSK1.SAMPLE
The program source will be saved to the disk in display/var/80 format.
You have now created a program source. Note that the 99 FORTRAN editor is
a minimal editor, there is no string search or replace capability. If you
need to do a LOT of editing, you might chose to use the editor/assembler
editor or TI-Writer, if it is available to you. Just make sure to save
the file in display/var/80 format!
Exiting the editor is simple, type function/back (function/9). The message:
Are you sure (Y/N)?
will be displayed. Type a 'Y', and you will return to the MAIN MENU.
Compiling the Program
---------------------
Now lets compile the sample program. Its simple! Just type the number
"2" on the MAIN MENU (for Compile). The compiler will load into memory,
and the following message will be displayed:
99 FORTRAN Compiler V3.1
Input File Name?
Enter the name of the source input file you created above, DSK1.SAMPLE
and press ENTER. The next question is:
Object File Name?
Enter the name of the resulting object file:
DSK1.SAMPOBJ
and ENTER. The next question is displayed:
Listing File Name?
If you want a listing to a printer, then you can enter the device name
here. Some device names that are common are:
PIO or RS232/1.BA=4800
If you want the listing to be displayed on the screen, type in a device
name of CRT. If you don't want a listing, just press ENTER.
The next question displayed is the Scratch Disk Number (1-3). If your
program is longer than about 80 lines, then 99 FORTRAN may have to create
some temporary files on the disk. It will delete them when the compilation
is finished. In this case, just use 1 (just hit ENTER).
The last question is:
Compilation Options?
Just leave this blank for now (just hit ENTER).
The message:
Press ENTER to Continue
will be displayed. Press ENTER to start the compilation.
After a few seconds (longer if you are printing the listing), the following
should be displayed on the screen:
Compilation in Progress
0000 Warning(s)
0000 Error(s)
Compilation Complete
Press ENTER to Continue
If you have accumulated errors here, go back to the editor, load the program
source, edit it to remove the errors, and recompile. Do NOT attempt to
run a program which has compilation errors! The results are unpredictable.
Press the ENTER key to return to the MAIN menu.
99 FORTRAN "remembers" the last function executed, so that if you have
multiple compilations to perform, just select item 2 again. The compiler
will be immediately available without reloading from disk.
Linking the Program
-------------------
Before the program can be executed, the object must be "linked" to produce
an absolute executable module. To link your sample program, press "3"
and ENTER on the MAIN MENU.
You can now link the sample program. The linker first displays the following
question:
99 Linker V3
Listing File Name?
If you want a listing, enter the same device name you entered while compiling
the program (e.g. PIO, or RS232/1.BA=4800, or CRT). If you don't want a
listing, just press ENTER. The following question will then be displayed:
Object File Name?
Enter the name of DSK1.SAMPOBJ. This will load your sample object into
main memory, ready for execution. Note that after the file is read the
question:
Object File Name?
is displayed again! This allows you to enter multiple object files for
precompiled FORTRAN and Assembly Language subroutines. Just hit ENTER
for now.
If you selected the listing option, a map will be produced on the selected
listing device. It should look like this:
Fortran Map V3
Logic Area Size = 009C
SAMPLE A000
Spare Area Size = 5A32
Data Area Size = 0008
SAMPLE * FAD0
Press ENTER to Continue
This map shows the logic area location and size, the data area location and
size, and the spare area (unused) size in hexadecimal bytes.
Press ENTER to return to the MAIN MENU.
Running the Program
-------------------
To RUN your program, select item 4 (Run) on the MAIN MENU, and press enter.
One file will be loaded from the disk, and the program will be started,
displaying the following:
Value of I is: 0
Enter New Value: _
enter the number 123 and ENTER. The screen will be re-displayed showing
this number.
It is now time to examine the program line by line to see what it is doing:
The first line is:
PROGRAM SAMPLE
this line really is just for documentation. The program name will appear
on the link map. It serves no other function.
The next line:
I = 0
assigns the value of zero to the integer variable I. In FORTRAN, all
variables starting with the letters I, J, K, L, M or N are defaulted to
INTEGER, all other letters are of type REAL. We are dealing with all
integer variables here. You can change the IMPLICIT defaults using the
IMPLICIT statement, you can also change each variable EXPLICITLY using
the INTEGER, REAL, LOGICAL, or DOUBLE PRECISION statements.
The next statement starts a loop construct, starting with the DO WHILE
statement and ending with the ENDDO statement:
DO WHILE ( I .NE. 999 )
.
. statements here
.
ENDDO
These statements say "do the following statements, up to the ENDDO statements,
while the logical expression within the parenthesis is TRUE". In this case,
the statements will be executed as long as the variable I is not equal to
the value 999.
The following two statements are FORTRAN write and read statements:
WRITE ( 6, 9100 ) I
READ ( 6, 9110, END=9999, ERR=9999 ) I
they are indented to the right to make the program easier to read (since
the statements are part of a loop construct). The first WRITE statement
says "write on device 6, according to FORMAT statement starting with label
9100, the variable I". The READ statement says "read from device 6, according
to the FORTRAN statement starting with label 9110, if an END condition occurs
then branch to statement starting with label 9999, if an ERROR condition
occurs, then branch to the statement starting with label 9999, the variable
I".
FORTRAN devices are opened via the CALL OPEN statement. There is one
device automatically assigned for both input and output for every FORTRAN
program, device 6, the CRT.
The next statement:
9999 STOP
is branched to when the loop exits (if the value of I is 999) or when an
END condition or ERROR condition is detected on the READ statement.
The next two statements are the associated FORMAT statements for the WRITE
and READ statements:
9100 FORMAT ( '+', C12, M10.4, 'Value of I is: ',I6,
+ M18.4, 'Enter New Value:', M18.22 )
9110 FORMAT ( I6 )
The first FORMAT (9100) is associated with the WRITE statement (write
according to FORMAT 9100, remember?), and the next statement is associated
with the READ statement (9110).
The first FORMAT starts with a quoted string (single quotes in FORTRAN, not
double), with a FORTRAN carraige control character ('+'). I am using a
plus sign here to disable the FORTRAN carraige control convention.
The next FORMAT literal is "C12". This is a special 99 FORTRAN extension
which says "write the ascii character whose value (12) follows". This
character, a form feed, clears the screen.
The next FORMAT literal "M10.4" is again a special 99 FORTRAN extension which
says "move the cursor to row 10, column 4".
The next quoted string 'Value of I is: ' displays that string at row 10,
column 4 on the screen. This is followed by a standard FORTRAN "I6"
literal, which says "display an integer value (I) in a six character
field, right justified, and padded to the left with blanks".
The cursor is again moved to row 18, column 4 (via M18.4) and the quoted
string 'Enter new value:' is displayed there. This is followed by a
final cursor move M18.22, which moves the cursor to row 18, column 22.
Since I used the '+' carriage control, above, then the cursor will remain
there for the next READ operation.
The next format:
9110 FORMAT ( I6 )
is used in conjunction with the READ statement, and says "read an integer
in an up to six character field". Actually 99 FORTRAN works just like
basic here, except the field width is limited to what you enter. For
example, the following numbers will be produced in response to the
following (try it!):
c c
o o
l l
2 2
2 7
v v
12 produces 12
12 produces 12
12 produces 12
-12 produces -12
123456 produces -7616 (integer overflow)
We can exit the program by entering the value 999, by entering a non-numeric
character (remember the ERR= exit in the READ statement above), or by en-
tering the "end of data" characters >EOD (remember the END= exit in the
READ statement above).
The final statement of the program terminates the program compilation. If
control is ever passed to the END statement, it is treated as a STOP state-
ment:
END
In Summary
----------
The procedures outlined above show you how to edit, compile, link, and
run 99 FORTRAN programs. It may seem tedious the first time through, but
the reward are programs that are easy to follow and liberally commented,
and run anywhere from twice as fast to hundreds of times faster than their
TI BASIC counterparts.
In future tutorials, I will go more in depth on the FORTRAN language itself,
and how to use the extensive FORTRAN libraries.
Enjoy!
Copyright 1988
by A.L.Beard 29-May-1988
(please ask permission to reproduce or post on bulletin boards.
permission given freely)
U)3=GUUUUUUUU
Download complete. Turn off Capture File.