home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / Geneve / 9640news / CAT39 / FRTRNTT.ARK < prev    next >
Text File  |  2006-10-19  |  18KB  |  477 lines

  1. ?
  2.  
  3.        Understanding 99 FORTRAN, for your TI-99/4A and MYARC Geneve
  4.        ------------------------------------------------------------
  5.  
  6.  The following is the start of a tuturial on 99 FORTRAN.  In this section,
  7.  I give a little history of FORTRAN, and take the user through editing,
  8.  compiling, linking, and running a small FORTRAN program.
  9.  
  10.                        Part 1 - The basics
  11.                        -------------------
  12.  
  13.  99 FORTRAN offers unique capabilities for your TI-99 and GENEVE, a syntax
  14.  similar to BASIC with the execution speed of a true compiler!  FORTRAN is
  15.  more like BASIC than C or FORTH.
  16.  
  17.  FORTRAN is the oldest "higher level language" developed in the 1950's.  It
  18.  is best known for numerical analysis (and is still probably the best suited
  19.  language for such applications) but can easily handle other types of programs,
  20.  such as games or database programs or just about anything.  As a matter of
  21.  fact, the original granddaddy adventure game "ADVENTURE" was written in
  22.  FORTRAN on a PDP-11.
  23.  
  24.  As FORTRAN evolved from a very simple numerical language, to a very rich
  25.  and powerful language, various standards emerged.  FORTRAN II, FORTRAN III,
  26.  and finally FORTRAN IV was standardized in 1966, with the ANSI standard
  27.  FORTRAN 66.  During the 1970's, a new and very important style of pro-
  28.  gramming emerged, structured programming.  What is it?  Well, look at
  29.  the following pieces of FORTRAN code and see which is easier to understand:
  30.  
  31.            IF ( ICODE - 10 ) 100, 110, 100
  32.    100     J = 2
  33.            GOTO 120
  34.    110     J = 3
  35.    120     CONTINUE
  36.  
  37.                     or
  38.  
  39.            IF ( ICODE .EQ. 10 ) THEN
  40.              J = 3
  41.            ELSE
  42.              J = 2
  43.            ENDIF
  44.  
  45.  The first example shows a FORTRAN arithmetic IF statement, whereas the
  46.  second a structured block IF statement.   Both code segments do the exact
  47.  same function, if the variable ICODE is equal to 10, then the variable
  48.  J is set equal to 3, otherwise the variable J is set equal to 2.  The
  49.  second example is MUCH easier to understand, especially later when you
  50.  go looking for statement labels.
  51.  
  52.  99 FORTRAN has some FORTRAN 66 and some FORTRAN 77 features.  Most important
  53.  with FORTRAN 77 is the structured IF statement, as shown above.
  54.  
  55.  
  56.                          Equipment Needed
  57.                          ----------------
  58.  
  59.  To run 99 FORTRAN, you need a TI-99/4A with 32k memory, disk drive, console,
  60.  monitor, and one of the modules Editor Assembler, MINI-Memory, Extended
  61.  BASIC or TI-Writer.  If you have the MINI-Memory, then use it, 99 FORTRAN
  62.  makes use of the extra 4k of memory to speed compilation and for the symbolic
  63.  debugger.
  64.  
  65.  You also need a copy of 99 FORTRAN.  This is available from TENEX Computer
  66.  Express, Disk Only Software, or Quality 99 Software, suggested retail of
  67.  $49.95.
  68.  
  69.  99 FORTRAN can also be run on a GENEVE in GPL mode (sorry, MDOS version is
  70.  not available, yet).  It can be run at the highest speed (5) available.
  71.  It can also access RAM disks.
  72.  
  73.  Note that the released versions of 99 FORTRAN include 2.1, 2.1.1, 2.1.2,
  74.  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
  75.  currently have a version 2 (see the label on the boot or library disk,
  76.  or read the VERSION file on the boot or library disk) then you should
  77.  send in your warranty registration to LGMA Products.  You will then
  78.  receive a letter explaining how to upgrade your system to the latest
  79.  version 3 release.
  80.  
  81.  If you make copies of the boot disk, then make sure the name of the disk
  82.  is kept the same, e.g. FORTCOMP for the boot disk, and FORTLIBR for the
  83.  two library disks.  If you copy the boot disk to a RAM disk (e.g. DSK5),
  84.  then make sure the name of the RAM disk is FORTCOMP also.  This can be
  85.  changed with the preferences program, see the FORTRAN manual for a
  86.  description.
  87.  
  88.                         Booting in FORTRAN
  89.                         ------------------
  90.  
  91.  Booting in FORTRAN is easy, just put the BOOT disk in any drive (suggest
  92.  drive one to cut down on searches), and enter BASIC, and type:
  93.  
  94.                         OLD "DSK.FORTCOMP.LOAD"
  95.                         RUN
  96.  
  97.  There are several other ways of booting in FORTRAN.  A quick way with the
  98.  editor/assembler module is to use option 5 (load and run), and type:
  99.  
  100.                         DSK.FORTCOMP.UTIL1
  101.  
  102.  If the boot process went ok, you will see a menu on the screen:
  103.  
  104.                          99 FORTRAN
  105.  
  106.                   1 Edit           6 Save
  107.                   2 Compile        7 Load
  108.                   3 Link           8 USER
  109.                   4 Run            9 Utilities
  110.                   5 Run/Debug
  111.  
  112.  a blinking underscore will also be at the bottom of the screen, this is
  113.  the cursor.
  114.  
  115.  To perform a function, type the number associated with the function (e.g.
  116.  1 to edit a program) followed by ENTER (or return).  The boot disk will
  117.  be read for that function, the appropriate program(s) related to that
  118.  function will be read, and the function initiated.  If you don't have the
  119.  boot disk plugged into a drive, then you will get a cryptic "I/O Error"
  120.  message.  Just put the boot disk in and try again.
  121.  
  122.  
  123.                          Editing a program
  124.                          -----------------
  125.  
  126.  Now that FORTRAN is booted, lets call in the EDITOR.  From the main menu
  127.  screen (the one above), type the number 1 (for editing) and ENTER.  After
  128.  a short delay, and some disk activity, the following MENU will appear:
  129.  
  130.                             99 Editor
  131.  
  132.                        Press:
  133.  
  134.                            1 To Load Program
  135.                            2    Edit Program
  136.                            3    Save Program
  137.                            4    Purge Workspace
  138.                            5    Display Statistics
  139.                            6    Print File
  140.  
  141.  Lets first edit a program.  Press the number "2".  The screen will clear,
  142.  and the following will be displayed:
  143.  
  144.         <EOD> (Version 3.0)
  145.  
  146.  Depress ENTER to open a line, then type in the following program lines:
  147.  (note that every FORTRAN statement must be preceded by SIX or more blanks,
  148.  and statement labels must fall in columns one through 5.  A character other
  149.  than a blank or zero in column 6 means this is a continuation line.
  150.  Characters past column 72 are ignored):
  151.         c    cc
  152.         o    oo
  153.         l    ll
  154.         1    67
  155.         v    vv
  156.               PROGRAM SAMPLE
  157.               I = 0
  158.               DO WHILE ( I .NE. 999 )
  159.                 WRITE ( 6, 9100 ) I
  160.                 READ ( 6, 9110, END=9999, ERR=9999 ) I
  161.               ENDDO
  162.          9999 STOP
  163.          9100 FORMAT ( '+', C12, M10.4, 'Value of I is: ',I6,
  164.              +              M18.4, 'Enter New Value:', M18.22 )
  165.          9110 FORMAT ( I6 )
  166.               END
  167.  
  168.  When finished, depress fctn/back (function/9) to return to the menu display.
  169.  Insert a blank, formatted, disk into DSK1, and select item 3 (Save Program).
  170.  99 FORTRAN responds:
  171.  
  172.          File to save?
  173.  
  174.  Type in a file name of:
  175.  
  176.          DSK1.SAMPLE
  177.  
  178.  The program source will be saved to the disk in display/var/80 format.
  179.  
  180.  You have now created a program source.   Note that the 99 FORTRAN editor is
  181.  a minimal editor, there is no string search or replace capability.  If you
  182.  need to do a LOT of editing, you might chose to use the editor/assembler
  183.  editor or TI-Writer, if it is available to you.  Just make sure to save
  184.  the file in display/var/80 format!
  185.  
  186.  Exiting the editor is simple, type function/back (function/9).  The message:
  187.  
  188.          Are you sure (Y/N)?
  189.  
  190.  will be displayed.  Type a 'Y', and you will return to the MAIN MENU.
  191.  
  192.  
  193.                        Compiling the Program
  194.                        ---------------------
  195.  
  196.  Now lets compile the sample program.  Its simple!  Just type the number
  197.  "2" on the MAIN MENU (for Compile).  The compiler will load into memory,
  198.  and the following message will be displayed:
  199.  
  200.                       99 FORTRAN Compiler V3.1
  201.  
  202.              Input File Name?
  203.  
  204.  Enter the name of the source input file you created above, DSK1.SAMPLE
  205.  and press ENTER.  The next question is:
  206.  
  207.              Object File Name?
  208.  
  209.  Enter the name of the resulting object file:
  210.  
  211.              DSK1.SAMPOBJ
  212.  
  213.  and ENTER.  The next question is displayed:
  214.  
  215.              Listing File Name?
  216.  
  217.  If you want a listing to a printer, then you can enter the device name
  218.  here.  Some device names that are common are:
  219.  
  220.              PIO  or RS232/1.BA=4800
  221.  
  222.  If you want the listing to be displayed on the screen, type in a device
  223.  name of CRT.  If you don't want a listing, just press ENTER.
  224.  
  225.  The next question displayed is the Scratch Disk Number (1-3).  If your
  226.  program is longer than about 80 lines, then 99 FORTRAN may have to create
  227.  some temporary files on the disk.  It will delete them when the compilation
  228.  is finished.  In this case, just use 1 (just hit ENTER).
  229.  
  230.  The last question is:
  231.  
  232.             Compilation Options?
  233.  
  234.  Just leave this blank for now (just hit ENTER).
  235.  
  236.  The message:
  237.  
  238.             Press ENTER to Continue
  239.  
  240.  will be displayed.  Press ENTER to start the compilation.
  241.  
  242.  After a few seconds (longer if you are printing the listing), the following
  243.  should be displayed on the screen:
  244.  
  245.             Compilation in Progress
  246.                0000 Warning(s)
  247.                0000 Error(s)
  248.             Compilation Complete
  249.             Press ENTER to Continue
  250.  
  251.  If you have accumulated errors here, go back to the editor, load the program
  252.  source, edit it to remove the errors, and recompile.  Do NOT attempt to
  253.  run a program which has compilation errors!  The results are unpredictable.
  254.  
  255.  Press the ENTER key to return to the MAIN menu.
  256.  
  257.  99 FORTRAN "remembers" the last function executed, so that if you have
  258.  multiple compilations to perform, just select item 2 again.  The compiler
  259.  will be immediately available without reloading from disk.
  260.  
  261.  
  262.                         Linking the Program
  263.                         -------------------
  264.  
  265.  Before the program can be executed, the object must be "linked" to produce
  266.  an absolute executable module.  To link your sample program, press "3"
  267.  and ENTER on the MAIN MENU.
  268.  
  269.  You can now link the sample program.  The linker first displays the following
  270.  question:
  271.  
  272.                           99 Linker V3
  273.  
  274.                 Listing File Name?
  275.  
  276.  If you want a listing, enter the same device name you entered while compiling
  277.  the program (e.g. PIO, or RS232/1.BA=4800, or CRT).  If you don't want a
  278.  listing, just press ENTER.  The following question will then be displayed:
  279.  
  280.                 Object File Name?
  281.  
  282.  Enter the name of DSK1.SAMPOBJ.  This will load your sample object into
  283.  main memory, ready for execution.  Note that after the file is read the
  284.  question:
  285.  
  286.                 Object File Name?
  287.  
  288.  is displayed again!  This allows you to enter multiple object files for
  289.  precompiled FORTRAN and Assembly Language subroutines.  Just hit ENTER
  290.  for now.
  291.  
  292.  If you selected the listing option, a map will be produced on the selected
  293.  listing device.  It should look like this:
  294.  
  295.                 Fortran Map V3
  296.  
  297.                 Logic Area     Size = 009C
  298.                   SAMPLE          A000
  299.  
  300.                 Spare Area     Size = 5A32
  301.  
  302.                 Data Area      Size = 0008
  303.                   SAMPLE    *     FAD0
  304.  
  305.                 Press ENTER to Continue
  306.  
  307.  This map shows the logic area location and size, the data area location and
  308.  size, and the spare area (unused) size in hexadecimal bytes.
  309.  
  310.  Press ENTER to return to the MAIN MENU.
  311.  
  312.                         Running the Program
  313.                         -------------------
  314.  
  315.  To RUN your program, select item 4 (Run) on the MAIN MENU, and press enter.
  316.  One file will be loaded from the disk, and the program will be started,
  317.  displaying the following:
  318.  
  319.                        Value of I is:     0
  320.  
  321.                        Enter New Value:   _
  322.  
  323.  enter the number 123 and ENTER.  The screen will be re-displayed showing
  324.  this number.
  325.  
  326.  It is now time to examine the program line by line to see what it is doing:
  327.  
  328.  The first line is:
  329.  
  330.               PROGRAM SAMPLE
  331.  
  332.  this line really is just for documentation.  The program name will appear
  333.  on the link map.  It serves no other function.
  334.  
  335.  The next line:
  336.  
  337.               I = 0
  338.  
  339.  assigns the value of zero to the integer variable I.  In FORTRAN, all
  340.  variables starting with the letters I, J, K, L, M or N are defaulted to
  341.  INTEGER, all other letters are of type REAL.  We are dealing with all
  342.  integer variables here.  You can change the IMPLICIT defaults using the
  343.  IMPLICIT statement, you can also change each variable EXPLICITLY using
  344.  the INTEGER, REAL, LOGICAL, or DOUBLE PRECISION statements.
  345.  
  346.  The next statement starts a loop construct, starting with the DO WHILE
  347.  statement and ending with the ENDDO statement:
  348.  
  349.               DO WHILE ( I .NE. 999 )
  350.                    .
  351.                    .  statements here
  352.                    .
  353.               ENDDO
  354.  
  355.  These statements say "do the following statements, up to the ENDDO statements,
  356.  while the logical expression within the parenthesis is TRUE".  In this case,
  357.  the statements will be executed as long as the variable I is not equal to
  358.  the value 999.
  359.  
  360.  The following two statements are FORTRAN write and read statements:
  361.  
  362.                 WRITE ( 6, 9100 ) I
  363.                 READ ( 6, 9110, END=9999, ERR=9999 ) I
  364.  
  365.  they are indented to the right to make the program easier to read (since
  366.  the statements are part of a loop construct).  The first WRITE statement
  367.  says "write on device 6, according to FORMAT statement starting with label
  368.  9100, the variable I".  The READ statement says "read from device 6, according
  369.  to the FORTRAN statement starting with label 9110, if an END condition occurs
  370.  then branch to statement starting with label 9999, if an ERROR condition
  371.  occurs, then branch to the statement starting with label 9999, the variable
  372.  I".
  373.  
  374.  FORTRAN devices are opened via the CALL OPEN statement.  There is one
  375.  device automatically assigned for both input and output for every FORTRAN
  376.  program, device 6, the CRT.
  377.  
  378.  The next statement:
  379.  
  380.          9999 STOP
  381.  
  382.  is branched to when the loop exits (if the value of I is 999) or when an
  383.  END condition or ERROR condition is detected on the READ statement.
  384.  
  385.  The next two statements are the associated FORMAT statements for the WRITE
  386.  and READ statements:
  387.  
  388.          9100 FORMAT ( '+', C12, M10.4, 'Value of I is: ',I6,
  389.              +              M18.4, 'Enter New Value:', M18.22 )
  390.          9110 FORMAT ( I6 )
  391.  
  392.  The first FORMAT (9100) is associated with the WRITE statement (write
  393.  according to FORMAT 9100, remember?), and the next statement is associated
  394.  with the READ statement (9110).
  395.  
  396.  The first FORMAT starts with a quoted string (single quotes in FORTRAN, not
  397.  double), with a FORTRAN carraige control character ('+').  I am using a
  398.  plus sign here to disable the FORTRAN carraige control convention.
  399.  
  400.  The next FORMAT literal is "C12".  This is a special 99 FORTRAN extension
  401.  which says "write the ascii character whose value (12) follows".  This
  402.  character, a form feed, clears the screen.
  403.  
  404.  The next FORMAT literal "M10.4" is again a special 99 FORTRAN extension which
  405.  says "move the cursor to row 10, column 4".
  406.  
  407.  The next quoted string 'Value of I is: ' displays that string at row 10,
  408.  column 4 on the screen.  This is followed by a standard FORTRAN "I6"
  409.  literal, which says "display an integer value (I) in a six character
  410.  field, right justified, and padded to the left with blanks".
  411.  
  412.  The cursor is again moved to row 18, column 4 (via M18.4) and the quoted
  413.  string 'Enter new value:' is displayed there.  This is followed by a
  414.  final cursor move M18.22, which moves the cursor to row 18, column 22.
  415.  Since I used the '+' carriage control, above, then the cursor will remain
  416.  there for the next READ operation.
  417.  
  418.  The next format:
  419.  
  420.          9110 FORMAT ( I6 )
  421.  
  422.  is used in conjunction with the READ statement, and says "read an integer
  423.  in an up to six character field".  Actually 99 FORTRAN works just like
  424.  basic here, except the field width is limited to what you enter.  For
  425.  example, the following numbers will be produced in response to the
  426.  following (try it!):
  427.                  c    c
  428.                  o    o
  429.                  l    l
  430.  
  431.                  2    2
  432.                  2    7
  433.                  v    v
  434.  
  435.                  12           produces 12
  436.                     12        produces 12
  437.                      12       produces 12
  438.                   -12         produces -12
  439.                  123456       produces -7616 (integer overflow)
  440.  
  441.  We can exit the program by entering the value 999, by entering a non-numeric
  442.  character (remember the ERR= exit in the READ statement above), or by en-
  443.  tering the "end of data" characters >EOD (remember the END= exit in the
  444.  READ statement above).
  445.  
  446.  The final statement of the program terminates the program compilation.  If
  447.  control is ever passed to the END statement, it is treated as a STOP state-
  448.  ment:
  449.  
  450.               END
  451.  
  452.  
  453.                             In Summary
  454.                             ----------
  455.  
  456.  The procedures outlined above show you how to edit, compile, link, and
  457.  run 99 FORTRAN programs.  It may seem tedious the first time through, but
  458.  the reward are programs that are easy to follow and liberally commented,
  459.  and run anywhere from twice as fast to hundreds of times faster than their
  460.  TI BASIC counterparts.
  461.  
  462.  In future tutorials, I will go more in depth on the FORTRAN language itself,
  463.  and how to use the extensive FORTRAN libraries.
  464.  
  465.  Enjoy!
  466.  
  467.  Copyright 1988
  468.  by A.L.Beard       29-May-1988
  469.  
  470.        (please ask permission to reproduce or post on bulletin boards.
  471.                permission given freely)
  472. U)3=GUUUUUUUU
  473.  
  474. Download complete.  Turn off Capture File.
  475.  
  476.  
  477.