home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AxoCalculator Package / AxoCalculator Documentation / Programming in Fortran / Example Programs < prev    next >
Encoding:
Text File  |  1993-03-14  |  5.2 KB  |  189 lines  |  [TEXT/AxoC]

  1. LocalLanguage Fortran
  2. c    -------------------------------------------------
  3. c    The following 7 programs demonstrate various aspects of 
  4. c    AxoCalculator's Fortran programming language. 
  5. c
  6. c    •  To load all 7 programs, choose "Select All" under 
  7. c        the "Edit" menu, then press "enter". 
  8. c
  9. c    •  To run a program, either select it under the 
  10. c        "Calculator" menu, or type its name and press "enter".
  11. c
  12. c    •  After the programs are loaded, this file does not need
  13. c        to remain open in order to use them.
  14. c    --------------------------------------------------
  15.  
  16. c    ----------------- Global Variables  ------------------
  17. c    The following 2 line section demonstrates how to declare
  18. c    global variables. See "The Programming Language" for more
  19. c    on variable declaration. Because global "Real" 
  20. c    variables can be created on the fly, global
  21. c    declarations will most commonly be used for creating
  22. c    "Boolean", "Integer" or array variables. 
  23. c    -----------------------------------------------------
  24.     Integer i
  25.     Real globalArr(10)
  26.  
  27.  
  28. c    ------------------- DoCount ------------------------
  29. c    A very simple program which counts to 10.
  30. c    It demonstrates how to declare a program, and assign it a 
  31. c    menu string (Count To 10) with a command key option (/1).
  32. c    ----------------------------------------------------
  33.     program DoCount 'Count To 10/4'
  34.     do i = 1, 10 
  35.         write (i)
  36.     endDo
  37.     writeln
  38.     end
  39.  
  40. c    ---------------- Factorial -----------------------
  41. c    A slightly more complex program which calculates
  42. c    all the factorial numbers from 1 to 15.
  43. c    It demonstrates how to declare a local variable ( f ),
  44. c    and uses a multi-parameter "WriteLn" statement.
  45. c    -------------------------------------------------
  46.     program Fact 'Factorial 1 to 10/5'
  47.     Real f
  48.  
  49.     f = 1
  50.     do i = 1, 10
  51. c    • Calculate the factorial •
  52.         f = f * i
  53.         writeln ('Factorial ',i,' = ',f)
  54.     endDo
  55.     end
  56.  
  57.  
  58. c    ------------------ Trigonometry ------------------
  59. c    This program uses an internal trigonometric function.
  60. c    It uses "print" instead of "WriteLn".
  61. c    -------------------------------------------------
  62.     program Trig 'Cos 0 to 90/6'
  63.     Real cosResult, degrees
  64.  
  65. c    • Calculate the cosine of angles from 0 to 90 in steps of 10 •
  66.     do i = 0, 9
  67.         degrees = i * 10
  68.         cosResult = cos (degrees)
  69.         print ('cos ( ',degrees,') = ',cosResult)
  70.     endDo
  71.     end
  72.  
  73.  
  74. c    ------------ String Variables ------------------
  75. c  This program shows how to create and initialize
  76. c  string variables. It shows how to pass them as 
  77. c  arguments to a procedure or function.
  78. c    ---------------------------------------------
  79.     Subroutine Print2Strings (aString, bString)
  80.     print ('1) ', aString)
  81.     print ('2) ', bString)
  82.     end
  83.  
  84.     program DemoString 'String Variable Example/7'
  85. c    Declared strings
  86. c
  87.     String aString, bString        
  88.  
  89.     aString = 'Anhydrohydroxyprogesterone'
  90.     bString = 'synthetic female hormone'
  91.     
  92. c    String created "on the fly". 
  93. c    The "Concat" function combines 2 or more strings.
  94. c
  95.     cString = concat (aString,':  ',bString)
  96.     
  97.     aString = 'Trinitrophenylmethylnitramine'
  98.     bString = 'a type of explosive.'
  99.     
  100. c    String created procedurally
  101. c
  102.     NewString (dString)
  103.     dString = concat (aString,':  ',bString)
  104.     
  105. c    Strings passed as arguments to a subroutine
  106. c
  107.     Print2Strings (cString, dString)
  108.     end
  109.  
  110. c    -------------- Test Array Arithmetic ------------
  111. c    This program initialize the global array, "globalArr", and
  112. c    creates and initializes a local array, "localArr".
  113. c    It adds, the two arrays, and outputs the result.
  114. c    -----------------------------------------------
  115.     program testArr 'Array Example/8'
  116.     Real localArr(10)
  117.  
  118. c    • Initialize the local and global arrays •
  119.     do i = 1, 10
  120.         localArr(i) = 100
  121.         globalArr(i) = i
  122.     endDo
  123.     
  124. c    • Add the two arrays •
  125.     globalArr = globalArr + localArr
  126.     writeArr (globalArr)
  127.     end
  128.  
  129.  
  130. c    -------------- Sphere Volume and S.A. ----------------
  131. c    This program demonstrates the "poseDialog" and "Alert"
  132. c    commands. It uses poseDialog to prompt the user for
  133. c    a sphere's radius, then calculates the volume and
  134. c    surface area of the sphere, and returns the results
  135. c    to the user in an alert dialog.
  136. c    ----------------------------------------------------
  137.     program sphere 'Volume and S.A. of Sphere/9'
  138.     Real radius, theVolume, theSA
  139.  
  140. c    • Ask the user for the radius of the sphere •
  141.     poseDialog ('\rCalculate the volume and surface area of a sphere', 
  142. &                        'Radius of sphere ',radius)
  143.  
  144. c    • Calculate the surface area and volume •
  145.     theSA = 4 * pi * radius ^ 2
  146.     theVolume = (4 / 3) * pi * radius ^ 3
  147.  
  148. c    • Send the results to an alert dialog •
  149.     Alert ('The volume and surface area of a \r sphere with radius ', 
  150. &                    radius,' are : \r Volume = ',theVolume,
  151. &                      '\r Surface area = ',theSA)
  152.     end
  153.  
  154.  
  155. c    ------------------- Count Down ----------------------
  156. c    This program demonstrates the "FlushOutput" and "Beep"
  157. c    commands. It counts down from 10 to 0 beeping at each
  158. c    count. A pause is introduces between each count by
  159. c    performing several hundred exponential calculations.
  160. c    -----------------------------------------------------
  161.     program CountDown 'Lift Off/0'
  162.     WriteLn
  163.     WriteLn ('Prepare for count down.')
  164.     FlushOutput
  165. c    • Pause •
  166.     Do k = 1, 50
  167.         a = exp(2.0)
  168.     endDo
  169. c    • Start the Count Down •
  170.     Do m = 0, 10
  171.         j = 10 - m
  172.         if (j = 3) WriteLn ('Ignition.')
  173.         if (j = 0) then
  174.             WriteLn ('Lift Off !!')
  175.         else
  176.             WriteLn (j)
  177.         endif
  178.         FlushOutput
  179.         Beep
  180.         j = j - 1
  181.  
  182. c    • Slow down the count •
  183.         Do k = 1, 50
  184.             a = exp(2.0)
  185.         endDo
  186.     endDo
  187. end
  188.  
  189.