LnSOS BOOT 1.1 SOS.KERNEL SOS KRNLI/O ERRORFILE 'SOS.KERNEL' NOT FOUND%INVALID KERNEL FILE: xةw,@  ȱlmi8#)!)JBACK3vs' '*NEW8B.TEXT !@sc$*NEW7X.TEXT*sU,+PAGE51.TEXT9 sFŠ*LISTB.TEXTBsNŠ*LISTA.TEXTGsa*NEW8A.TEXTLFORTRAN.DOC2u' JBACK3sJJBACK5s J >dLԡm#i㰼m#iЕOLԡȱfg hi !dLԡ憦  Ljmkm l y`2 Lԡ8(Je稽)ʈ@L4sc *NEW9X.TEXTg0sŠ*NEW6X.TEXT4sk G^;*9'nnn is the length in number of characters of a character .variable or character array element. It must be an  unsigned integer in the range 1 to 255.   ^ne 6  The following are examples of CHARACTER type statements: 'REAL A Declares that A holds a REAL value  ^ne 9  The form of a CHARACTER type statement is:  %CHARACTER [*nnn [,]] var [*nnn] [, var [*nnn] ]...   where: var is a variable name, array name, or an array declarator.  ray name, function name, or an  array declarator.   ^ne 7  The following are examples of the TYPE statement:  'INTEGER MATRIX Does not include Dimension information  'INTEGER MATRIX(16,10) Includes Dimension information  The name of a subroutine or  main program cannot appear in a type statement.  ^ne 8  The form of an INTEGER, REAL, or LOGICAL type statement is:  %type var [,var]... %  where: type is INTEGER, REAL, or LOGICAL.  'var is a variable name, ar the type of that name for the entire program unit. Within a program  unit, a name may not have its type explicitly specified by a type  statement more than once. A type statement may confirm the type of an  intrinsic function, but is not required.  Type statements may also specify dimension information.   ^ne 2  A user name for a variable, array, external function, or statement  function may appear in a type statement. Such an appearance defines example of an array element name:  'MATRIX(2,3) referring to column 3, row 2  ^ne 6  @TYPE STATEMENT ^zz  Type statements are used to specify the type of user defined names. A  type statement may confirm or override the implicit type of a name. n array. The number of subscript expressions must  match the number of dimensions in the array declarator. The value of a  subscript expression must be between 1 and the upper bound for the  dimension it represents.   ^ne 3  The following is an  ^ne 7  The form of an array element name is:  %arr(sub [,sub]... )   where: arr is the name of an array.  'sub is a subscript expression.   ^ne 2  A subscript expression is an integer expression used in selecting a  specific element of a  !"#$%&'( 'CHARACTER*100,A A holds up to 100 characters  'CHARACTER*50,STRING Variable name STRING can hold up to >50 characters   ^ne 2  The length nnn following the type name CHARACTER is the default length  for any name not having its own length specified. If not present, the  default length is assumed to be one. A length immediately following a  variable or array overrides the default length for that item only. For  an array the length specifies the length of each element of that  ar Each user name may only appear once in an INTRINSIC statement. If a  name appears in an INTRINSIC statement, it cannot appear in an  EXTERNAL statement. All names used in an INTRINSIC statement must be  system-defined INTRINSIC functions. For a listatement is used to declare that a user name is an  intrinsic function. The form of an INTRINSIC statement is:  %INTRINSIC name [,name]...   where: name is an intrinsic function name.   ^ne 2 the name of an external  procedure, and the corresponding intrinsic function can no longer be  ^ne 2  called from that program unit. A user name can only appear once in an  EXTERNAL statement.   ^ne 9  @INTRINSIC STATEMENT ^zz  An INTRINSIC s  Appearance of a name in an EXTERNAL statement declares that name to be  an external procedure. Statement function names cannot appear in an  EXTERNAL statement. If an intrinsic function name appears in an  EXTERNAL statement, then that name becomes An EXTERNAL statement is used to identify a user defined name as an  external subroutine or function. The form of an EXTERNAL statement  is:  %EXTERNAL name [,name]...   where: name is the name of an external subroutine of function.   ^ne 2 units, the size  must be the same in all program units.  &HAND If Named COMMON blocks are used, you will have to link before you can run your program. See chapter 5 for that procedure.  ^ne 10  @EXTERNAL STATEMENT ^zz they refer to the same actual  storage.   ^ne 2  The size of a COMMON block is equal to the number of bytes of storage  required to hold all elements in that COMMON block. If the same named  COMMON block is referenced by several distinct programpe  CHARACTER or none of type character. Furthermore, if two program units  reference the same named COMMON containing character data, association  of character variables of different length is not allowed. Two  variables are said to be associated if in the same program unit. All elements in all nlists for the same  COMMON block are allocated storage sequentially in that COMMON storage  area in the order that they appear.   ^ne 2  All elements in a single COMMON area must be either all of tyin that COMMON  block. If the first cname is omitted, all elements appearing in the  first nlist are specified to be in the blank COMMON block.   ^ne 2  Any COMMON block name can appear more than once in COMMON statements atement:  (COMMON/SHARE/MATRIX,ARRAY,A Block SHARE can refer to the E variable names MATRIX, ARRAY, E and A.  ^ne 2  In the COMMON statement, all variables and arrays appearing in each  nlist following a COMMON block cname are declared to be specified.  ' nlist is a list of variable names, array names, and array 0declarators separated by commas. Formal argument 0names and function names cannot appear in a COMMON 0statement. 0  ^ne 5  The following is an example of the COMMON st without passing it as arguments. The form of the COMMON statement is:   ^ne 9 %COMMON [/ [cname] /] nlist [[,] / [cname] / nlist]...  where: cname is the name of the Named COMMON block. If a cname is 0omitted, then the Blank COMMON block isray.    ^ne 6  @COMMON STATEMENT ^zz  The COMMON statement provides a method of sharing storage between two  or more program units. Such program units can share the same data t of these functions, see  Table 2 in Appendix C. Note that the use of the INTRINSIC statement is  optional. The INTRINSIC function can be used without the INTRINSIC  statement.   ^ne 5  @SAVE STATEMENT ^zz  A SAVE statement is used to retain the definition of a COMMON block  after the return from a procedure that defines that COMMON block.  Within a subroutine or function, a COMMON block that has been  specified in a SAVE statement does not become undefined upon exit from  the subroutine o0A repeat factor followed by a constant is the 0equivalent of the value of the constant repeated 0a number of times that is equal to the repeat  constant.   ^ne 2  There must be the same number of values in each clist as th is a list of variable, array element, or array names.   clist is a list of constants or constants preceded by an 0integer constant repeat factor and an asterisk, 0such as: 0 45*3.14159 3*'Help' 100*0  If present, it must  appear after all specification statements and prior to any statement  function statements or executable statements. The form of a DATA  statement is:   ^ne 14 %DATA nlist / clist / [[,] nlist / clist /]...   where: nlist lowed because it extends the COMMON block by adding storage  preceding the start of the block.    ^ne 5  @@DATA STATEMENTS   The DATA statement is used to assign initial values to variables. A  DATA statement is a non-executable statement.  An EQUIVALENCE statement can extend a COMMON block by adding storage  elements following the COMMON block, but not preceding the COMMON  block. For example:   ^ne 6  COMMON /ABCDE/ R(10) %REAL S(10) %EQUIVALENCE (R(1),S(10))   is not al   ^ne 2  When EQUIVALENCE statements and COMMON statements are used together,  several further restrictions apply. An EQUIVALENCE statement cannot  cause storage in two different COMMON blocks to become equivalenced. inct memory locations.   ^ne 7  Furthermore, an EQUIVALENCE statement cannot specify that consecutive  array elements are not stored in sequential order. For example:  %REAL R(10),S(10) %EQUIVALENCE (R(1),S(1)),(R(5),S(6))   is not allowed. nt of the array.   ^ne 2  An EQUIVALENCE statement cannot specify that the same storage location  is to appear more than once, such as:   ^ne 4 %REAL R,S(10) %EQUIVALENCE (R,S(1)),(R,S(5))   which forces the variable R to appear in two dist causes its list of variables to become associated. An element of type  character can only be associated with another element of type  character with the same length. If an array name appears in an  EQUIVALENCE statement, it refers to the first elemeifies that the storage sequences of the  elements that appear in the nlist have the same first storage  location. Two or more variables are said to be associated if they  refer to the same actual storage. Thus, an EQUIVALENCE statement  array element names separated by commas.   ^ne 3  Argument names may not appear in an EQUIVALENCE statement. Subscripts  must be integer constants and must be within the bounds of the array  they index.   ^ne 2  An EQUIVALENCE statement specdifferent types, the EQUIVALENCE does not cause any kind of  automatic type conversion. The form of an EQUIVALENCE statement is:   ^ne 4 %EQUIVALENCE (nlist) [, (nlist)]...   where: nlist is a list of at least two variable names, array names, or  the SAVE statement has no effect and is not normally used.    ^ne 5  @EQUIVALENCE STATEMENT ^zz  An EQUIVALENCE statement is used to specify that two or more variables  or arrays are to share the same storage. If the shared variables are  of r function. The form of a SAVE statement is:   ^ne 3 %SAVE /name/ [,/name/]...   where: name is the name of a COMMON block.   ^ne 2  Note: In Apple FORTRAN, all COMMON blocks are statically allocated, so ere are  variables or array elements in the corresponding nlist. The appearance  of an array in an nlist is the equivalent to a list of all elements in  that array in storage sequence order. Array elements must be indexed  only by constant subscripts.   ^ne 2  The type of each non-character element in a clist must be the same as  the type of the corresponding variable or array element in the  accompanying nlist. Each character element in a clist must correspond  to a character variable or ar or statement label to an integer variable. The form of the statement  is:   ^ne 5 %ASSIGN label TO var   where: label is a format label or statement label. 0  var is an integer variable.   ^ne 2  Execution of an ASSIGN statacters on the right are  truncated to make the sizes the same.    ^ne 6  @LABEL ASSIGNMENT STATEMENT ^zz  The label assignment statement is used to assign the value of a format  variable in a character assignment statement, it is adjusted so that  it does. If the expression is shorter, it is padded with enough blanks  on the right to make the sizes equal before the assignment takes  place. If the expression is longer, charreal | REAL(expr) | expr | %+-----------------+-------------------+------------------+  #Table of Type Conversions for Arithmetic Assignment Statements   ^ne 2  If the length of the expression does not match the size of the%| array element | integer | real | %+-----------------+-------------------+------------------+ # | integer | expr | INT(expr) | %+-----------------+-------------------+------------------+ $ |  ^ne 11  +-----------------+--------------------------------------+ %| Type of | Type of expression | %| variable or +-------------------+------------------+ ement.   ^ne 2  If the types of the elements of an arithmetic assignment statement are  not identical, automatic conversion of the value of the expression to  the type of the variable is done. The following table gives the  conversion rules:  left. The type of the variable or array  element and the expression must be compatible. They must both be  either numeric, logical, or character, in which case the assignment  statement is called an arithmetic, logical, or character assignment  stat where: var is a variable or array element name.  'expr is an expression.   ^ne 2  Execution of a computational assignment statement evaluates the  expression and assigns the resulting value to the variable or array  element appearing on thes of assignment statements,  computational assignment statements and label assignment statements.  ^ne 10  @COMPUTATIONAL ASSIGNMENT STATEMENT  ^zz  The form of a computational assignment statement is: % 'var = expr % in the second example that the array called MATRIX must have 6  elements, one for each DATA constant.     ^ne 6  @@ASSIGNMENT STATEMENTS  An assignment statement is used to assign a value to a variable or an  array element. There are two kind in COMMON, and function names  cannot be assigned initial values with a DATA statement.   ^ne 5  The following are examples of the DATA statement:  *DATA X,Y,Z,A,C/1.0,3.8,4.5,6.7,1.9/  *DATA MATRIX/1.5,2.0,2.5,3.0,10.5,3.2/   ^ne 2  Note the right. Note that a single character constant cannot be used to  define more than one variable or even more than one array element.   ^ne 3  Only local variables and array elements can appear in a DATA  statement. Formal arguments, variablesray element in the nlist, and must have a  length that is less than or equal to the length of that variable or  array element. If the length of the constant is shorter, it is  extended to the length of the variable by adding blank characters to ement sets the integer variable to the  value of the label. The label can be either a format label or a  statement label, and it must appear in the same program unit as the  ASSIGN statement. When used in an assigned GOTO statement, a variable  must currently have the value of a statement label. When used as a  format specifier in an I/O statement, a variable must have the value  of a format statement label. The ASSIGN statement is the only way to  assign the value of a label to a variable.  ^bger part, a decimal point, and a fraction part. The integer and  fraction parts consist of one or more decimal digits. Either the  integer part or the fraction part may be omitted, but not both. Some  examples of real constants follow:  %-123.456o consecutive words, four bytes, of storage. The  range of real values within a power of 10 is approximately:   -1.7E+38 ... -5.8E-39 0.0 5.8E-39 ... 1.7E+38   A basic real constant consists of an optional sign followed by an  inte%123 +123 -123 0 00000123 32767 -32768    @@THE REAL TYPE  The real data type consists of a subset of the real numbers. A real  value is normally an approximation of the real number desired. A real  variable occupies twf one or more decimal digits preceded by an  optional arithmetic sign, + or -, and must be in the allowable value  range. A decimal point is not allowed in an integer constant. The  following are examples of integer constants:  he integers. An integer  value is an exact representation of the corresponding integer. An  integer variable occupies one word, two bytes, of storage and can  contain any value in the range -32768 to 32767. Integer constants  consist of a sequence o Integer, real,  logical, and character. This chapter describes the properties of each  type, the range of values for each type, and the form of constants for  each type.    @@THE INTEGER TYPE  The integer data type consists of a subset of t   @@CHAPTER 7    @@@DATA TYPES   40 Introduction  40 The Integer Type !40 The Real Type !41 The Logical Type !41 The Character Type    ^bp     @@INTRODUCTION   There are four basic data types in Apple FORTRAN:)+,-./01234567G^;Zmp  ^bp +123.456 123.456 %-123. +123. 123. (-.456 +.456 .456   ^ne 2  An exponent part consists of the letter 'E' followed by an optionally  signed integer constant. An exponent indicates that the value  ^ne 4  preceding it is to be multiplied by 10 to the value of the exponent  part's integer. Some sample exponent parts are:  %E12 E-12 E+12 E0  %200 CH = 'ABC DEF'   ^ne 3  with the single space between the C and D being the equivalent to the  space in column 7 of the continuation line. Very long character  constants can be represented in this manner.  ^bp  posed  immediately after the last character on the initial line. Thus, the  FORTRAN source:   ^ne 2 %200 CH = 'ABC *X DEF'   ^ne 4  where indicates a carriage return, or the end of the source  line is equivalent to:  ource lines with up to 72 columns. Shorter lines are  not padded out to 72 columns, but left as input. When a character  constant extends across a line boundary, its value is as if the  portion of the continuation line beginning with column 7 is juxtang as a single apostrophe  character. Some sample character constants are:   ^ne 3 %'A' ' ' 'Help!' 'A very long CHARACTER constant' ''''   Note the last example, '''', represents a single apostrophe, '.  ^ne 2  FORTRAN allows s (or single quote) within a character constant is represented by two  consecutive apostrophes with no blanks in between. The length of a  character constant is equal to the number of characters between the  apostrophes, with doubled apostrophes countionsists of a sequence of one or more characters  enclosed by a pair of apostrophes. Blank characters are allowed in  character constants, and count as one character each. An apostrophe ge for each two characters in the sequence,  plus one word if the length is odd. Character variables are always  aligned on word boundaries. The blank character is allowed in a  character value and is significant.   ^ne 2  A character constant ccharacters.  The length of a character value is equal to the number of characters  in the sequence. The length of a particular constant or variable is  fixed, and must be between 1 and 255 characters. A character variable  occupies one word of stora word of all zeros except a one in the least significant bit. If a  logical variable contains any other bit values, its logical meaning is  undefined.     ^ne 5  @@THE CHARACTER TYPE  The character data type consists of a sequence of ASCII tes, of storage.  There are only two logical constants, .TRUE. and .FALSE., representing  the two corresponding logical values. The internal representation of  .FALSE. is a word of all zeros, and the representation of .TRUE. is a 100.0E-4 .0001E+2   all represent the same real number, 1/100.    ^ne 5  @@THE LOGICAL TYPE  The logical data type consists of the two logical values true and  false. A logical variable occupies one word, two by^ne 8  A real constant is either a basic real constant, a basic real constant  followed by an exponent part, or an integer constant followed by an  exponent part. For example:  %+1.000E-2 1.E-2 1E-2  +0.01 G^˟V without conversion of the integer, and results in an expression of  type real. An integer raised to a real power is converted to type real  and the operation results in an expression of type real. Note that for  integer I and negative integer J, I * a real and an  integer converts the integer to type real and performs the operation,  resulting in an expression of type real.   ^ne 2  * For the operator **, a real raised to an integer power is computed sion are:   ^ne 2  * An operation between two integers results in an expression of type  integer. '  ^ne 2  * An operation between two reals results in an expression of type  real. %  ^ne 3  * For any operator except **, an operation betweeno 0. %   ^ne 6  @TYPE CONVERSIONS AND RESULT TYPES ^zz  Arithmetic expressions may involve operations between operands which  are of different types. The general rules for determining type  conversions and the result type for an arithmetic expres @INTEGER DIVISION ^zz  The division of two integers results in a value which is the  mathematical quotient of the two values, rounded toward 0. Thus,  7 / 3 evaluates to 2, (-7) / 3 evaluates to -2, 9 / 10 evaluates to 0  and 9 / (-10) evaluates tal, since they are not  mathematically meaningful; such as dividing by zero. Other prohibited  operations are raising a zero-valued operand to a zero or negative  power and raising a negative-valued operand to a power of type real.    ^ne 5 rs from appearing consecutively. Thus,  A ** -B is prohibited, although A ** (-B) is permissible. Parenthesis  may be used in a program to control the order of operator evaluation  in an expression.  ^ne 2  Certain arithmetic operations are illegociative. Thus,  A / B * C is the same as (A / B) * C and A ** B ** C is the same as  A ** (B ** C). Arithmetic expressions can be formed in the usual  mathematical sense, as in most programming languages, except that  FORTRAN prohibits two operato All of the operators are binary operators appearing between their  arithmetic expression operands. The + and - may also be unary,  preceding their operand. Operations of equal precedence are left  associative except exponentiation which is right ass8:;<=>?@* J is the same as  1 / (I ** IABS(J)) which is subject to the rules of integer division.  For example, 2 ** (-4) is 1 / 16 which is 0. '  ^ne 2  * Unary operators result in the same result type as their operand  type.   ^ne 2  The type which results from the evaluation of an arithmetic operator  is not dependent on the context in which the operation is specified.  For example, evaluation of an integer plus a real results in a real  FHIJO^S^zs  ^fo ''%  ^so jback3:page51  ACDEO^SVStatement  ^bp     @@INTRODUCTION   This chapter describes specification statements, DATA statements, and  assignment statements in Apple FORTRAN. The rules for forming FORTRAN  names and the scope of names are included in this chapter also. ment !49 COMMON Statement !50 EXTERNAL Statement !51 INTRINSIC Statement !51 SAVE Statement !51 EQUIVALENCE Statement !52 DATA Statements !53 Assignment Statements !54 Computational Assignment Statement !54 Label Assignment    @@CHAPTER 8    @@@FORTRAN STATEMENTS   !44 Introduction !44 FORTRAN Names !44 Scope of FORTRAN Names !45 Undeclared Names !45 Specification Statements !46 IMPLICIT Statement !47 DIMENSION Statement !48 Type StateKMNOPQRSTUVWXYZ[\]^_`abcdeG^;Z,^zs  ^fo ''%  ^he '''Program Structure  ^so jback3:new6x  ^he '''Data Types  ^so jback3:new7x  ^he '''FOTRAN Statements  ^so jback3:new8a  ^so jback3:new8b  ^he '''Expressions ^so jback3:new9x      ^ne 5  @@FORTRAN NAMES   A FORTRAN name, or identifier, consists of an initial alphabetic  character followed by a sequence of 0 through 5 alphanumeric  characters. Blanks may appear within a FORTRAN name, but have no  significance. A name is used to denote a user or system defined  variable, array, function, subroutine, and so forth. Any valid  sequence of characters may be used for any FORTRAN name. There are no  reserved names as in other languages. Sequencesme that has not appeared before is encountered in an  executable statement, the compiler infers from the context of its use  how to classify that name. If the name is used in the context of a  variable, the compiler creates an entry into the symbol tab to the single statement forming that statement function. Any  other use of those names within that statement function is not  allowed, and any other use outside that statement function is allowed.    ^ne 5  @UNDECLARED NAMES ^zz  When a user na such as /NAME/, and are therefore always distinguishable from ordinary  names by the compiler.   ^ne 2  Another exception to the scoping rules is made for parameters to  statement functions. The scope of statement function parameters is  limitedle to refer to a globally scoped common name in  the same program unit that an identical locally scoped name appears.  This is allowed because common names are always enclosed in slashes, l scope errors, and issues an error message should  they occur, so the user need not worry about undetected scope errors  causing bugs in programs.   ^ne 2  One exception to the scoping rules is the name given to common data  blocks. It is possibaining the local name. Thus, a  function can be named FOO, and a local variable in another program  unit can be named FOO without error, as long as the program unit  containing the variable FOO does not call the function FOO. The  compiler detects al parameters, and statement functions all have local scope. A name with  a local scope can be used in the same compilation as another item with  the same name but a global scope as long as the global name is not  referenced within the program unit contle program unit.  A name with a local scope can be used in another program unit with a  different or similar meaning, but is in no way required to have a  similar meaning in a different scope. The names of variables, arrays, be a function subprogram that has the  same name as a subroutine subprogram or a common data area. Similarly,  no two function subprograms in the same program can have the same  name.   ^ne 2  A name with local scope is only defined within a singo the same  entity. In fact, names with global scope can only be used in a single,  consistent manner within a program. All subroutine, function  subprogram, and common names, as well as the program name, have global  scope. Therefore, there cannot  definition within its scope. The same name, however, can have  different definitions in distinct scopes.   ^ne 2  A name with global scope may be used in more than one program unit, a  subroutine, function, or the main program, and still refer te referenced within a FORTRAN program. In general, the  scope of a name is either GLOBAL or LOCAL, although there are several  exceptions. A name can only be used in accordance with a single , READ, or GOTO, with no error indicated by  the compiler, as long as it conforms to the rules that all arrays must  obey.   ^ne 5  @SCOPE OF FORTRAN NAMES ^zz  The scope of a name is the range of statements in which that name is  known or can b of alphabetic  characters used as keywords are not to be confused with FORTRAN names.  The compiler recognizes keywords by their context and in no way  restricts the use of user chosen names. Thus, a program can have, for  example, an array named IFle for a  variable of that name. Its type is inferred from the first letter of  its name. Normally, variables beginning with the letters I, J, K, L,  M, or N are considered integers, while all others are considered  reals, although these defaults can be overridden by an IMPLICIT  statement. If an undeclared name is used in the context of a function  call, a symbol table entry is created for a function of that name,  with its type being inferred in the same manne one IMPLICIT statement, but all  implicit statements must precede all other specification statements in  that program unit. The same letter cannot be defined more than once in  an IMPLICIT statement in the same program unit.    ^ne 13  @DIMENSexplicit type in a FUNCTION statement also takes priority over an  IMPLICIT statement. If the type in question is a character type, the  user name's length is also overridden by a later type definition.   ^ne 2  The program unit can have more than in which it appears. IMPLICIT statements do not change the type of any  intrinsic functions.   ^ne 2  Implicit types can be overridden or confirmed for any specific user  name by the appearance of that name in a subsequent type statement. An  ICIT statement defines the type and size for all user defined  names that begin with the letter or letters that appear in the  specification. An IMPLICIT statement applies only to the program unit range 1 to 255. If *nnn .is not specified, it is assumed to be *1.   The following are examples of IMPLICIT statements:  'IMPLICIT INTEGER (I-N)  'IMPLICIT INTEGER (I-Z),REAL(A-G)  'IMPLICIT CHARACTER*100(H)   ^ne 2  An IMPL in the range separated by a minus sign. For .a range, the letters must be in alphabetic order. ' 'nnn is the size of the character type that is to be .associated with that letter or letters. It must be .an unsigned integer in the%IMPLICIT type (a [,a]...) [,type (a [,a]...)]...   where: type is one of INTEGER, LOGICAL, REAL, or CHARACTER[*nnn]  'a is either a single letter or a range of letters. A .range of letters is indicated by the first and last .lettersappear in any order within their own  group.   ^ne 5  @IMPLICIT STATEMENT ^zz  An IMPLICIT statement is used to define the default type for user  declared names. The form of an IMPLICIT statement is:  tements.  ^ne 2  Specification statements must precede all executable statements in a  program unit. If present, any IMPLICIT statements must precede all  other specification statements in a program unit as well. The  specification statements may table. They are used to define  the attributes of user defined variable, array, and function names.  There are eight kinds of specification statements: These are the  IMPLICIT, DIMENSION, type, COMMON, EXTERNAL, INTRINSIC, SAVE, and  EQUIVALENCE sta default meaning can sometimes result in logical errors that are quite  difficult to locate.    ^ne 5  @@SPECIFICATION STATEMENTS   This section describes the specification statements in Apple FORTRAN.  Specification statements are non-execued to declare all names used within a  program unit, since it helps to assure that the compiler associates  the proper definition with that name. Allowing the compiler to use a  ^ne 2 e coordinated with those of the newly created symbol  table entry. If any inconsistencies are detected, such as a previously  defined subroutine name being used as a function name, an error  message is issued.   ^ne 2  In general, one is encouragr as that of a variable.  Similarly, a subroutine entry is created for a newly encountered name  that is used as the target of a CALL statement. If an entry for such a  subroutine or function name exists in the global symbol table, its  attributes arION STATEMENT  ^zz  A DIMENSION statement is used to specify that a user name is an  array. The form of a DIMENSION statement is:   DIMENSION var(dim) [,var(dim)]...   where: var(dim) is an array declarator of the form:  % var is the user defined name of the array.  ' dim is a dimension declarator.   ^ne 9  The following are examples of the DIMENSION statement:  )DIMENSION A(100,2),B3(10,4)  )DIMENSION ARRAY(10) # )DIMENSION MATRIX(16,10)  fhijklmnopqrstuvwxyz{|}~G^˟V The order of array elements in memory is column-major order. That is,  the left most subscript changes most rapidly in a memory sequential  reference to all array elements. Note that this is the opposite of  Pascal which has row-major order.    ^ne 2  All adjustable and assumed sized arrays must also be formal arguments  to the program unit in which they appear. Additionally, an assumed  size dimension declarator may only appear as the last dimension in an  array declarator.   ^ne 3 *,100) RLARR1(1), RLARR2(1) $100 FORMAT(2F8.4) *END *SUBROUTINE SUBARR(R) *DIMENSION R(*) $C WHEN AN ACTUAL ARGUMENT IS PASSED TO SUBARR AS R, IT MAY HAVE  C ANY NUMBER OF ELEMENTS. *R(1)=2.0 $C CLOBBER THE FIRST ELEMENT OF R *END ,RLARR2(20) $C TWO ARRAYS OF DIFFERENT SIZE TO PASS TO SUBARR BELOW. *RLARR1(1)=1.0 *RLARR2(1)=3.14159 $C TWO DUMMY VALUES TO BE CLOBBERED BY SUBARR *CALL SUBARR(RLARR1) *CALL SUBARR(RLARR2) $C TWO CALLS OF SUBARR WITH DIFFERENT SIZE ARRAYS *WRITE(f the dimension declarator is an asterisk, the array is an assumed  sized array and the upper bound of that dimension is not specified.  The following program is an example of an asterisk array dimension:  PROGRAM ARR *DIMENSION RLARR1(10) integer argument, then that dimension is defined to be of a size equal  to the initial value of the integer argument upon entry to the  subprogram unit at execution time. In such a case the array is called  an adjustable sized array.   ^ne 3  I is an integer  constant, then the array has the corresponding number of elements in  that dimension. An array has a constant size if all of its dimensions  are specified by integer constants. If a dimension declarator is an unsigned integer constant.  * A user name corresponding to a non array integer formal argument.  * An asterisk.   ^ne 2  A dimension declarator specifies the upper limit of the dimension. The  lower limit is always one. If a dimension declarator )DIMENSION MAXDIM(4,4,5)  ^ne 3  The number of dimensions in the array is the number of dimension  declarators in the array declarator. The maximum number of dimensions  is three. A dimension declarator can be one of three forms:  ^ne 5  * An  FORTRAN prohibits two operators from appearing consecutively. Thus,  A ** -B is prohibited, although A ** (-B) is permissible. Parenthesis  may be used in a program to control the order of operator evaluation  in an expression.  ^ne 2  Certain entiation which is right associative. Thus,  A / B * C is the same as (A / B) * C and A ** B ** C is the same as  A ** (B ** C). Arithmetic expressions can be formed in the usual  mathematical sense, as in most programming languages, except that of Arithmetic Operators.   All of the operators are binary operators appearing between their  arithmetic expression operands. The + and - may also be unary,  preceding their operand. Operations of equal precedence are left  associative except exponr Negation | | %+-----------------+-----------------------------------+ Lowest | $ | + | Addition or Identity | | %+-----------------+-----------------------------------+------------+  5Table %+-----------------+-----------------------------------+Intermediate| $ | * | Multiplication | | %+-----------------+-----------------------------------+------------+ # | - | Subtraction o----+ %| ** | Exponentiation | Highest | %+-----------------+-----------------------------------+------------+ # | / | Division | | entheses and these arithmetic operators:   +-----------------+-----------------------------------+------------+ %| Operator | Representing Operation | Precedence | %+-----------------+-----------------------------------+-------- Moreover, the  value of an integer variable must be defined with an arithmetic value,  rather than a statement label value previously set in an ASSIGN  statement.   Other arithmetic expressions are built up from the above simple forms  using par * Integer or real variable reference.  * Integer or real array element reference.  * Integer or real function reference. %  The value of a variable reference or array element reference must be  defined for it to appear in an arithmetic expression.  @@ARITHMETIC EXPRESSIONS   An arithmetic expression produces a value which is either of type  integer or type real. The simplest forms of arithmetic expressions  are:   * Unsigned integer or real constant. y variable, array  element, or function referenced in an expression must be defined at  the time of the reference. Integer variables must be defined with an  arithmetic value, rather than a statement label value as set by an  ASSIGN statement.   ator Precedence  ( ( ( <  ^bp     @@INTRODUCTION   This chapter describes the four classes of expressions found in the  FORTRAN language. They are the arithmetic, the character, the  relational, and the logical expression. Note that an   @@CHAPTER 9    @@@EXPRESSIONS  !58 Introduction !58 Arithmetic Expressions !59 Integer Division !59 Type Conversions and Result Types !60 Character Expressions !60 Relational Expressions !61 Logical Expressions !62 Operarithmetic operations are illegal, since they are not  mathematically meaningful; such as dividing by zero. Other prohibited  operations are raising a zero-valued operand to a zero or negative  power and raising a negative-valued operand to a power of type real.    ^ne 5  @INTEGER DIVISION ^zz  The division of two integers results in a value which is the  mathematical quotient of the two values, rounded toward 0. Thus,  7 / 3 evaluates to 2, (-7) / 3 evaluates to -2, 9 / 10 evaluates to 0 1Table of Relational Operators.   ^ne 2  All of the operators are binary operators, appearing between their  operands. There is no relative precedence or associativity among the  relational operands since an expression of the form A .LT. B .NE. C  | Greater than | %+-----------------+-----------------------------------+ $ | .GE. | Greater than or equal to | %+-----------------+-----------------------------------+  -----+ $ | .EQ. | Equal to | %+-----------------+-----------------------------------+ # | .NE. | Not equal to | %+-----------------+-----------------------------------+ $ | .GT. ---------------------------+ %| .LT. | Less than | %+-----------------+-----------------------------------+ # | .LE. | Less than or equal to | %+-----------------+------------------------------ ^ne 2  Relational expressions may use any of these operators to compare  values:   ^ne 17  ^ce 18  +-----------------+-----------------------------------+ %| Operator | Representing Operation | %+-----------------+--------re used to compare the values of two  arithmetic expressions or two character expressions. It is not legal  in Apple FORTRAN to compare an arithmetic value with a character  value. The result of a relational expression is of type logical.  ble reference.   * Character array element reference.   * Any character expression enclosed in parenthesis. %  There are no operators which result in character expressions.     ^ne 5  @@RELATIONAL EXPRESSIONS   Relational expressions abe immediately assigned into an  integer variable.     ^ne 5  @@CHARACTER EXPRESSIONS  A character expression produces a value which is of type character.  The forms of character expressions are:   * Character constant.  * Character varia ^ne 2  The type which results from the evaluation of an arithmetic operator  is not dependent on the context in which the operation is specified.  For example, evaluation of an integer plus a real results in a real  even if the value obtained is to ative integer J, I ** J is the same as  1 / (I ** IABS(J)) which is subject to the rules of integer division.  For example, 2 ** (-4) is 1 / 16 which is 0. '  ^ne 2  * Unary operators result in the same result type as their operand  type.  r power is computed  without conversion of the integer, and results in an expression of  type real. An integer raised to a real power is converted to type real  and the operation results in an expression of type real. Note that for  integer I and neg^ne 3  * For any operator except **, an operation between a real and an  integer converts the integer to type real and performs the operation,  resulting in an expression of type real.   ^ne 2  * For the operator **, a real raised to an intege conversions and the result type for an arithmetic expression are:   ^ne 2  * An operation between two integers results in an expression of type  integer. '  ^ne 2  * An operation between two reals results in an expression of type  real. %  and 9 / (-10) evaluates to 0. %   ^ne 6  @TYPE CONVERSIONS AND RESULT TYPES ^zz  Arithmetic expressions may involve operations between operands which  are of different types. The general rules for determining type violates the type rules for operands. Relational expressions may  only appear within logical expressions.   ^ne 2  Relational expressions with arithmetic operands may have an operand of  type integer and one of type real. In this case, the integer operand  is converted to type real before the relational expression is  evaluated.   ^ne 2  Relational expressions with character operands compare the position of  their operands in the ASCII collating sequence. An operand is less  than another iG^۞*onal | | %+-----------------+------------+ $ | Logical | Lowest | %+-----------------+------------+  &Table of Operator Precedence.  ^bp   expression, their relative precedences are:  ^ne 12 ^ce 12  +-----------------+------------+ %| Operator | Precedence | %+-----------------+------------+ %| Arithmetic | Highest | %+-----------------+------------+ # | Relatistandard mathematical  semantics, with .OR. being nonexclusive, that is .TRUE. .OR. .TRUE.  evaluates to the value .TRUE..     ^ne 5  @@OPERATOR PRECEDENCE  When arithmetic, relational, and logical operators appear in the same R. (B .AND. C). It is  not permitted to have two .NOT. operators adjacent to each other,  although A .AND. .NOT. B is an example of an allowable expression with  two operators being adjacent.   ^ne 3  The meaning of the logical operators is their preceding its operand. Operations of equal precedence are left  associative. For example, A .AND. B .AND. C is equivalent to (A .AND.  B) .AND. C. As an example of the precedence rules, .NOT. A .OR. B  .AND. C is interpreted the same as (.NOT. A) .O%+-----------------+-----------------------------------+------------+  7Table of Logical Operators.   ^ne 2  The .AND. and .OR. operators are binary operators, appearing between  their logical expression operands. The .NOT. operator is unary,  --+ # | .AND. | Conjunction | | %+-----------------+-----------------------------------+------------+ $ | .OR. | Inclusive disjunction | Lowest | Representing Operation | Precedence | %+-----------------+-----------------------------------+------------+ %| .NOT. | Negation | Highest | %+-----------------+-----------------------------------+----------onal expression. %  ^ne 2  Other logical expressions are built up from the above simple forms  using parenthesis and these logical operators:  ^ne 12  +-----------------+-----------------------------------+------------+ %| Operator |  A logical expression produces a value which is of type logical. The  simplest forms of logical expressions are:   * Logical constant.  * Logical variable reference.  * Logical array element reference.  * Logical function reference.  * Relatif it appears earlier in the collating sequence, etc. If  operands of unequal length are compared, the shorter operand is  considered as if it were blank extended to the length of the longer  operand.    ^ne 5  @@LOGICAL EXPRESSIONS  ^ne 2 ,  originating in a .TEXT file, consisting of: %  * Fifty-two upper and lower case letters A through Z and a through z %  * Digits from 0 to 9 %  * Special characters consisting of the remaining printable characters  of the ASCII character set  significance in the description of FORTRAN  statements. The general rules for blanks, covered in this chapter,  govern the interpretation of blanks in all contexts. %   @@CHARACTER SET  A FORTRAN source program consists of a stream of characters Example: The computed GOTO statement is described by 'GOTO ( s [, s]  ...) [,] i' indicating that the syntactic item denoted by s may be  repeated any number of times with commas separating the items. *  ^ne 3  ^in -5  * Blanks normally have no  specifying a character format. *  ^ne 2  ^in -5  * Three dots (...) are used to indicate ellipsis. That is, the  optional item preceding the three dots may appear one or more times. %  ^ne 2  ^in +5 l statement, F7.4 or F22.0 are valid. Notice that  the period, as a special character, is taken literally.   ^ne 4  ^in -5  * Brackets indicate optional items. %  ^in +5  Example: 'A[w]' indicates that either A or A12 are valid as a means of tegers is denoted  'Iw', where w is a nonzero, unsigned integer constant. Thus, in an  actual statement, a program might contain I3 or I44. The format which  describes editing of reals is 'Fw.d', where d is an unsigned integer  constant. In an actua substitution in actual statements as described in the text. The reader  may assume that once a lower case entity is defined, it retains it  meaning for the entire context of discussion. %  ^in +5  Example: The format which describes editing of inntions  used in this manual:   * Upper case and special characters are to be written as shown in  programs.   * Lower case letters and words indicate entities for which there is a o group the character stream into substructures, as  well as various constraints on how these substructures may be related  to each other in the source program, are the topic of this chapter.  First, however, it is important to note the notation conve @@INTRODUCTION   A FORTRAN program is a sequence of characters that are interpreted by  the compiler in various contexts as characters, identifiers, labels,  constants, lines, statements or other syntactic groupings. The rules  the compiler uses t    @@CHAPTER 6   @@@PROGRAM STRUCTURE    34 Introduction !34 Character Set !35 Lines !35 Columns !36 Blanks !36 Comment Lines  36 Statements, Labels, and Lines  37 Statement Ordering   ^bp    The letters and digits, treated as a single group, are called the  alphanumeric characters. FORTRAN interprets lower case letters as if  they were upper case letters in all contexts except in character  constants and hollerith fields. Thus, the following user defined names  are all the same to the FORTRAN system:  %ABCDE abcde AbCdE aBcDe   In addition, actual source programs submitted to the FORTRAN compiler  contain certain hidden oA statement label is a sequence of from one to five digits. At least  one digit must be nonzero. A label may be placed anywhere in columns 1  through 5 of an initial line. Blanks and leading zeros are not  ^ne 2  significant. It is traditional to l complete statements according to the rules specified here. Specific  statements and their properties will be covered individually. When it  is necessary to refer to specific kinds of statements here, they are  simply referred to by name.  ^ne 2   comment lines but they are not followed by an initial line.    ^ne 5  @@STATEMENTS, LABELS, AND LINES  We will define a FORTRAN statement in terms of the input character  stream. The compiler recognizes certain groups of input characters as  another comment line. They must not be followed by a continuation  line. Note that extra blank lines at the end of a FORTRAN program  result in a compile time error since the system interprets them as %  * A C or c character in column 1.   * Asterisk (*) in column 1.   * Line all blanks.   ^ne 2  Comment lines do not effect the execution of the FORTRAN program in  any way. Comment lines must be followed immediately by an initial line  ortion lines. %  ^ne 2  * Blanks are included in the total count of characters that the  compiler must process per line and per statement.   ^ne 5  @@COMMENT LINES  A line is treated as a comment if any one of the following conditions  is met:  * Blanks within string constants are significant. %  * Blanks within Hollerith fields are significant. %  * Blanks on compiler directive lines are significant. %  ^ne 2  * A blank in column 6 is used in distinguishing initial lines from  continuaank character, with the exceptions noted below, has no  significance in a FORTRAN source program and may be used for the  purpose of improving the readability of FORTRAN programs. The  exceptions are: % olumn in which a  character resides is significant in FORTRAN. Columns 1 through 5 are  reserved for statement labels, column 6 is used to indicate a  continuation line, and executable statements start in column 7.    ^ne 5  @@BLANKS  The blat is a throwback to the days  of punched cards, when each statement or line required its own card.     ^ne 5  @@COLUMNS  The characters in a given line fall into columns that are numbered  from left to right, beginning with column 1. The c that lines with fewer than 72 characters are possible and, if shorter  than 72 columns, the compiler does treat as significant the length of  a line. See Chapter 7 which describes character constants for an  illustration of this. This 72 column formence of  lines, corresponding to the normal notion of lines in the text editor.  Only the first 72 characters in a line are treated as significant by  the compiler, with any trailing characters in a line ignored. Note iles,  into the FORTRAN character set.   The collating sequence for the FORTRAN character set is the same as  the ASCII sequence. Refer to Table 5 in Appendix C.     ^ne 5  @@LINES  A FORTRAN source program may also be thought of as a sequr nonprintable control characters inserted by  the text editor which are invisible to the user. FORTRAN interprets  these control characters in exactly the same way that the text editor  does and transforms them, using the rules of Apple Pascal .TEXT feft-justify statement labels. A  statement label on a nonexecutable statement is ignored.  ^ne 2  An initial line is any line that is not a comment line or a compiler  directive line and contains a blank or a 0 in column 6. The first five  columns of the line must either be all blank or contain a label. With  the exception of the statement following a logical IF, FORTRAN  statements begin with an initial line.  ^ne 2  A continuation line is any line which is not a comment line or a ------------------+  | | | Executable Statements |  +----------+--------------------+---------------------------------------+  | END Statement |  +-----s | DATA Statements |  | | +---------------------------------------+  | | | Statement Function Statements |  | | +--------------------- | | +---------------------------------------+  | | | Other Specification Statements |  | Comment | FORMAT +---------------------------------------+  | Lines | Statement------------------+  | | PROGRAM, FUNCTION, or SUBROUTINE Statement |  | +------------------------------------------------------------+  | | | IMPLICIT Statements | ithin the specification statements, the IMPLICIT statement must  precede all other specification statements.   These rules are summarized in the program rules chart that follows.  ^ne 17    +----------+------------------------------------------%  ^ne 3  * DATA statements must appear after the specification statements and  precede all statement function statements and executable statements. %  ^ne 2  * Statement function statements must precede all executable  statements. %  ^ne 2  * W * FORMAT statements may appear anywhere after the SUBROUTINE or  FUNCTION statement, or PROGRAM statement if present. %  ^ne 2  * Specification statements must precede all DATA statements, statement  function statements, and executeable statements. s must appear in an order consistent with the following  rules: %  ^ne 2  * A SUBROUTINE or FUNCTION statement, or PROGRAM statement if present,  must appear as the first statement of the program unit. %  ^ne 2  statement, or any other than a SUBROUTINE or FUNCTION statement, and  ends with an END statement. A subprogram or a main program is often  called a program unit.   ^ne 3  Within a program unit, whether a main program or a subprogram,  statemente FORTRAN statements  mentioned in this section. The rules for ordering statements appear  below.   ^ne 2  A subprogram begins with either a SUBROUTINE or a FUNCTION statement  and ends with an END statement. A main program begins with a PROGRAM  lines which make up a FORTRAN compilation. In general, a compilation  consists of from zero to some number of subprograms and at most one  main program. Refer to Chapter 13 for more information on programs,  subroutines, and functions, as well as thnt are the  total number of characters, up to 660, found in columns 7 through 72  of these lines.     ^ne 5  @@STATEMENT ORDERING  The FORTRAN language enforces a certain ordering among statements and tatement will not fit on a  single initial line, it may be extended to include up to 9  continuation lines.  ^ne 2  A FORTRAN statement consists of an initial line, which may be followed  by up to 9 continuation lines. The characters of the stateme compiler directive line and contains any character in column 6 other  than a blank or a 0. The first five columns of a continuation line  must be blanks. A continuation line is used to increase the amount of  room to write a given statement. If a s------------------------------------------------------------------+  ^ne 9    Guidelines for interpreting the Program Rules Chart: %  * Classes of lines or statements above or below other classes must  appear in the designated order. %  * Classes of lines or statements may be interspersed with other  classes which appear across from one another.  ^bp  For instance, in order to call Pascal functions and  procedures from a FORTRAN program, the Pascal routines must first be  compiled into a Pascal unit. The FORTRAN program must then contain a  $USES compiler directive statement for that unit as descr ^bp     @@INTRODUCTION   As was discussed in Chapter 3, Programs in Pieces, if you want to mix  FORTRAN and Pascal code, you must first separately compile all the  subprograms that will be needed using the compiler of their native  language.^co [FORTRS2:FORPAS.TEXT]  @@CHAPTER 15   @@@BI-LINGUAL PROGRAMS    116 Introduction  116 Pascal in FORTRAN Main Programs  118 FORTRAN in Pascal Main Programs  119 I/O from Bilingual Programs  120 Calling Machine Code Routines  B A Y Z BUG ENDBUG  G^;2s a JBACK5vs ' ',NEW15AX.TEXT s c8,NEW16BX.TEXT s k ,NEW15BX.TEXTs ^+NEW14X.TEXT(s c),NEW16AX.TEXT%Hs *LISTA.TEXTibed in  Chapter 4.   In attempting to interface the two languages, there are some  fundamental differences which must be pointed out. For instance, the  exceedingly rich type and data structures in Pascal are not available  in FORTRAN. Also, the I/O systems of FORTRAN and Pascal are not  compatible. The fact that they both execute P-code on the Apple Pascal  operating system overcomes most of the other problems, however. This  section is designed to help you interfaceot designated Z:, you will have to  change the FORTRAN program to give the correct name.   ^ne 6  C FORTRAN PROGRAM TO CALL PASCAL ROUTINE  $USES PUNIT IN Z:PAS.CODE 'I=ADDONE(3) 'WRITE(*,100)I  100 FORMAT(I8) 'END   ^ne 14  This is the t to value parameters, but  the FORTRAN compiler does generate the correct calling sequence for  Pascal routines with value parameters.   ^ne 3  The following FORTRAN program calls a Pascal unit called PUNIT found  in Z:PAS.CODE. If your disk is n Note: Be aware that the results of passing some of the more esoteric  Pascal data types to FORTRAN INTEGER data types can be tricky. You  should do trials first to determine the exact results. %  ^ne 3  Note: There is no proper FORTRAN equivalen-----------------------  REAL REAL %BOOLEAN LOGICAL %CHAR CHARACTER*1 %any other identifier INTEGER %  ^ne 3 PROCEDURE X(arg-list); SUBROUTINE X(arglist) %FUNCTION X(arg-list): type; type FUNCTION X(arglist)   Note: Type of FUNCTION may only be INTEGER, LOGICAL, or REAL. %  ^ne 5  DATA TYPES:  ---------------------------------------------l FORTRAN   DECLARATIONS:  -------------------------------------------------------------------- %CONST anything ... ; Ignored %TYPE anything ... ; Ignored %VAR anything ... ; Ignored   have value parameters in its argument list, it will generate the  correct calling sequence for that Pascal procedure.   The following table shows how FORTRAN views Pascal declarations that  it finds via a $USES statement:   ^nf  ^ne 11 %Pasca should be understood that the Apple FORTRAN compiler cannot create  FORTRAN subroutine argument calls by value, but that if, via a $USES  statement, it encounters a Pascal procedure or function which does the variable is first copied into a special  temporary location before the subroutine is called. The subroutine is  only given the address of this temporary cell, which allows the  original variable to be protected from the subroutine.  ^ne 2  Itthe address of the  variable is passed to the subroutine, so that the subroutine can then  fetch the contents of that variable, and possibly replace its contents  with another value. When a variable is passed to a subroutine by  value, the contents of is a global variable in a unit called by FORTRAN, the Linker will  gemerate the error message: PUBLIC UNDEFINED.  ^ne 2  The difference between value and reference arguments is that, for a  variable passed to a subprogram by reference, ubprogram; they only recognize passing arguments by  reference. It should be noted that FORTRAN does not recognize global  variables declared in the INTERFACE portion of a Pascal unit. If there ORTRAN compiler must  make some translations of the kinds of data it finds there. The table  below shows how these are mapped into FORTRAN data types.   ^ne 2  Ordinary FORTRAN compilers do not recognize the passing of an argument  by value to a s the two languages.   @@PASCAL IN FORTRAN MAIN PROGRAMS  Since there are Pascal types that have no FORTRAN equivalent, the way  FORTRAN looks at Pascal data structures is somewhat limited. Thus,  when a FORTRAN program $USES a Pascal unit, the FPascal unit called by the FORTRAN program:   (*$S+*) 'UNIT PUNIT; 'INTERFACE )FUNCTION ADDONE(INT:INTEGER): INTEGER; 'IMPLEMENTATION )FUNCTION ADDONE; +BEGIN -ADDONE:=INT+1; +END )BEGIN )(* NO INITIALIZATION CODE IN THIS EXAMPLE *) )END ' '  ^ne 23  @@FORTRAN IN PASCAL MAIN PROGRAMS  The following table gives the data type correspondences:  $FORTRAN Pascal   DECLARATIONS:  ------------------------------------------------------^co [fortrs2:ch7b.text]  ^ne 5  @@THE APPLESTUFF UNIT  This section tells you how to generate random numbers, how to use the  control paddle and button inputs, how to read the cassette audio  input, how to switch the control's TTL outputs and how B A X HHG.EAOR.CODE:  'INTEGER FUNCTION ADDONE(I) 'ADDONE=I+1 'END  Note that the FORTRAN unit got the name UADDONE automatically from the  concatenation of U to the first function or subroutine name  encountered in the file, ADDONE.  ^ne 2  The following Pascal program is used to call a FORTRAN function called  ADDONE:   ^ne 6 PROGRAM CALLFORTRAN; '(*$U Z:FOR.CODE*) 'USES UADDONE; 'BEGIN 'WRITELN(ADDONE(3)); 'END   ^ne 5  This is the FORTRAN function saved as Z:F lead to duplicate type definitions should a program use two FORTRAN  units in which each declare the same entity.   ^ne 2  Note: Pascal stores its multidimensional arrays by row-major order,  while FORTRAN stores them by column-major order.  N unit, it is the responsibility of  the Pascal program to make sure that any needed type declarations for  the string or packed array of CHAR types are properly defined for the  FORTRAN unit. This cannot consistently be done by FORTRAN as it would TEGER $REAL REAL $LOGICAL BOOLEAN $CHARACTER* CHAR D $argument list: $(I) (VAR I: type) $type I   ^ne 2  When a Pascal program USES a FORTRA------------- $SUBROUTINE X(arg-list) PROCEDURE X(arg-list); $type FUNCTION X(arg-list) FUNCTION X(arg-list): type; $  DATA TYPES:  ------------------------------------------------------------------- $INTEGER INto generate  ^ne 4  sounds on the Apple's speaker. To use these special Apple features  from FORTRAN, you first have to place the statement   $USES APPLESTUFF   ^ne 2  before any executable statements in your program. The $ must appear in  column 1. This compiler directive statement may appear after other  compiler directive statements or comment statements. If you wish to  use both TURTLEGRAPHICS and APPLESTUFF you would say both:   ^ne 2  $USES TURTLEGRAPHICS ($USES A until TTLOUT is invoked with the DATA set to false.    ^ne 9  @MAKING MUSIC: THE NOTE SUBROUTINE  ^zz  The NOTE subroutine has the form %NOTE (PITCH, DURATION)  where PITCH is an integer from 0 through 50 and DURATION is an integer  fro  ^ne 2  where SELECT is an integer treated modulo 4 to select one of the four  TTL outputs numbered 0, 1, 2, and 3. DATA is a logical expression.   ^ne 2  If DATA is true, then the selected output is turned on. It remains on f the input signal.   ^ne 5  There are four TTL level outputs available on the game connector along  with the button and paddle inputs. The TTLOUT subroutine is used to  turn these outputs on or off. TTLOUT has the form  &TTLOUT (SELECT, DATA)  of true if  the selected game-control button is pressed, and false otherwise.   ^ne 3  When BUTTON(3) is used to read the audio cassette input, it samples  the cassette input, which changes from true to false and vice versa at  each zero crossing o The BUTTON function has the form  &BUTTON (SELECT)   where SELECT is an integer treated modulo 4 to select one of the three  button inputs numbered 0, 1, and 2, or the audio cassette input  numbered 3. The BUTTON function returns a logical value USING A DO (NOTHING) LOOP TO SLOW DOWN  C  $USES APPLESTUFF  300 I=PADDLE(0)  DO 200 K=0,3  200 CONTINUE  J=PADDLE(1)  WRITE(*,100)I,J &IF (.NOT. KEYPRE()) GOTO 300  100 FORMAT(2I8)  END  ^ne 6 not return the correct results. A suitable delay is  given by using a do-nothing loop as illustrated in the following example.  This program reads the paddles and loops until a key is pressed.   ^ne 12  C DEMO OF PADDLE FUNCTION  C  C HERE WE ARE ohm variable resistance can be connected in place of  any of the four paddles.   ^ne 2  If you try to read two paddles too quickly in succession, the hardware  may not be able to keep up. PADDLE data will be clipped and the PADDLE  function will &PADDLE (SELECT)   where SELECT is an integer treated modulo 4 to select one of the four  paddle inputs numbered 0, 1, 2, and 3. PADDLE returns an integer in  the range 0 to 255 which represents the position of the selected  ^ne 2  paddle. A 150Khe starting point for the random sequence does not change.   ^ne 5  @USING THE GAME CONTROLS  ^zz  The PADDLE and BUTTON functions and the TTLOUT subroutine are  known as the game controls.   ^ne 6  The PADDLE function has the form  nless you  use RANDOI.   ^ne 2  RANDOI uses a time-dependent memory location to generate a starting  point for the random generator. The starting point changes each time  you do any input or output operation in your program. If you use no  I/O, tDO 100 I=1,10 &X=(HI-LO)/32767.0 &RESULT=X*RANDOM()+LO  100 WRITE(*,200)RESULT  200 FORMAT(I8) &END   ^ne 3  RANDOI is a subroutine with no parameters. Each time you run a given  program using RANDOM, you will get the same random sequence u psuedo-random sequence of integers. The following routine will display  a random integer on the screen that is between the indicated limits:   ^ne 11  C DEMO PROGRAM OF RANDOM FUNCTION  $USES APPLESTUFF &INTEGER HI,LO,RESULT &HI=100 &LO=10 &PPLESTUFF   ^ne 5  @RANDOM FUNCTION/RANDOI SUBROUTINE  ^zz  RANDOM is an integer function with no parameters. It returns a value  from 0 through 32767. If RANDOM is called repeatedly, the result is a m 0 through 255.   ^ne 3  A PITCH of 0 is used for a rest, and 2 through 48 yield a tempered  (approximately) chromatic scale. DURATION is in arbitrary units of  time.   NOTE (1,1) gives a click.   ^ne 11  A musical scale is played by the following program: +  C PROGRAM PLAYS MUSICAL SCALE  C  $USES APPLESTUFF &PROGRAM MUSIC &INTEGER PITCH &DO 100 PITCH=2,48  100 CALL NOTE(PITCH,10) &END    ^ne 5  @THE KEYPRE FUNCTION  ^zz  The KEYPRE function returns a value of true if There are several precautions that the user must take for FORTRAN I/O  to work from a Pascal program. The Pascal main program must USES the  FORTRAN run time unit RTUNIT. This must be done in such a manner that  RTUNIT is assigned unit number 8 by the is called from  a Pascal main program. In general, however, this practice should be  avoided. The following information is provided to allow the user who  absolutely must mix I/O operations from both languages to do what is  possible.   ^ne 2   providing that there is no file name in the I/O statement. The Pascal  routines RESET, REWRITE, CLOSE, etc., should not be called from Pascal  routines running under a FORTRAN program.  ^ne 2  It is possible to do I/O from a FORTRAN procedure thatto very mysterious  results.  ^ne 2  It is not generally possible to do I/O from Pascal routines called  from a main program that is written in FORTRAN. Normal Pascal I/O to  and from the console, however, can always be done from Pascal routines t it will be assigned number 8. For this to happen, RTUNIT must be  the second unit used by the Pascal program. While not all FORTRAN  units actually call run time support routines that reside in RTUNIT,  the absence of RTUNIT in such a case can lead ng the  two languages.   ^ne 2  The FORTRAN compiler assumes that the run time support unit RTUNIT is  assigned unit number 8. Therefore, it is generally a good idea for  Pascal programs that use FORTRAN units to USES RTUNIT in such a manner  tha   ^ne 5  @@I/O FROM BILINGUAL PROGRAMS  Because the I/O systems of FORTRAN and Pascal are not compatible, it  is not always possible to do everything that is desired. This section  does, however, help the user to do what is possible in interfaciG^Sՠa key is pressed from  the console. Refer to the program in the Using the Game Controls  Section for an example of the KEYPRE function.  ^bp Pascal main program. Prior to  any FORTRAN I/O operations, the Pascal program must call the procedure  RTINITIALIZE. After all FORTRAN I/O is completed, the Pascal program  must call the procedure RTFINALIZE. Both of these procedures exist in  the FORTRAN run time unit. The FORTRAN I/O procedures use the heap for  the allocation of file related storage, so the user should not force  the deallocation of heap memory via calls to MARK and/or RELEASE. If  the user USES TURTLEGRAPHICS in the PTRUE.)  400 FORMAT(2I12) &END   ^ne 2  The example simply reads the two control paddles and writes the values  returned to the screen. This is a handy routine for game programming,  and the incredible speed of the machine language operations can called PADDLE because it  is a function. We do, of course, CALL TTLOUT.   ^ne 10  $EXT INTEGER FUNCTION PADDLE 1  $EXT SUBROUTINE TTLOUT 2  C &PROGRAM CALASM &DO 100 I=1, 100 &WRITE(*,400)PADDLE(0),PADDLE(1)  100 CONTINUE &CALL TTLOUT(0,. a FORTRAN program. The following example calls the machine language  routines listed above. You should note a couple of things here. First,  we don't use the normal $USES statement, but substitute $EXT.  Secondly, we don't have to CALL the routineA (LDA RETURN (PHA (RTS ;GO BACK TO PASCAL ( ( ( (.END ;END OF ASSEMBLY  ^ne 2  The $EXT statement can be used to call machine language routines from AND #03 ;TREAT IT MOD 4 (ROL A ;DOUBLE, ADD DATA FOR INDEX (TAY ;PUT I/O STROBE INDEX IN Y (LDA 0C058,Y ;ACTIVATE I/O STROBE (PLA ;DISCARD MSB SELECT PARAM (LDA RETURN+1 ;RESTORE PASCAL RETURN ADDR (PHURN ADDR  (POP RETURN ;SAVE PASCAL RETURN ADDRESS 8;POP PARAMETERS, LAST FIRST (PLA ;GET LSB BOOLEAN DATA 1=TRUE (LSR A ;SAVE BOOLEAN IN CARRY (PLA ;DISCARD MSB BOOLEAN DATA (PLA ;GET LSB SELECT ( ;_________________________________________________  ;  ; ROUTINE TO SET OR CLEAR ONE OF THE TTL I/O BITS  ; (This procedure provided in APPLESTUFF unit.)  ;  ; PROCEDURE TTLOUT(SELECT: INTEGER; DATA: BOOLEAN);  ;  RETURN .EQU 0 ;TEMP RET=0 (TYA (PHA ;PUSH LSB OF RETURN VALUE (LDA RETURN+1 ;RESTORE PASCAL RETURN ADDR (PHA (LDA RETURN (PHA (RTS ;AND RETURN TO PASCAL CALLER ( ( (.PROC TTLOUT,2 ;TWO WORDS OF PARAMETERS EST PADDLE (BPL DONE ;BRANCH IF TIMER DONE (INY ;ELSE INC Y EVERY 12 USEC (BNE PREAD2 ;LOOP UNLESS 255 EXCEEDED (DEY ;MAKE 0 INTO 255 (MAX COUNT)  DONE LDA #0 (PHA ;PUSH MSB OF RETURN VALUEENT ADDR (LDY #0 (LDA (TEMP),Y ;LOAD ARGUMENT'S VALUE (AND #3 ;FORCE INTO RANGE 0..3 (TAX (LDA 0C070 ;TRIGGER PADDLES (LDY #0 ;INIT COUNT IN Y REG (NOP ;COMPENSATE FIRST COUNT (NOP  PREAD2 LDA 0C064,X ;T8;note: 0..35 hex available  TEMP .EQU 2 ;TEMP VAR FOR ARGUMENT ADDR 8 (POP RETURN ;SAVE PASCAL RETURN ADDR (PLA ;DISCARD 4 BYTES STACK BIAS (PLA ;( ONLY DO FOR .FUNC ) (PLA (PLA (POP TEMP ;GET ARGUM_____  ;  ; SAMPLE GAME PADDLE FUNCTION FOR PASCAL  ; (This function provided in APPLESTUFF unit.)  ;  ; FUNCTION PADDLE(SELECT: INTEGER): INTEGER;  ;  ;__________________________________________  RETURN .EQU 0 ;TEMP VAR FOR RETURN ADDR he following example uses a machine code function and a subroutine.  ;  ; SAMPLE MACRO POPS 16 BIT ARGUMENT  ; (.MACRO POP (PLA (STA %1 (PLA (STA %1+1 (.ENDM ( ( (.FUNC PADDLE,1 ;ONE WORD OF PARAMETERS  ;____________________________________ascal program, then INITTURTLE  must be called prior to calling RTINITIALIZE. This is due to the way  that TURTLEGRAPHICS handles the heap marker. Other restrictions may  apply in special cases.    ^ne 4  @@CALLING MACHINE CODE ROUTINES  T be  very useful in such real-time applications.  ^bp G^۞;F" followed by the name of its first procedure. For example:  $C --- No PROGRAM statement present *SUBROUTINE X *... *END *SUBROUTINE Y *... *END *... *SUBROUTINE Z *... *END   would be compiled into a single unit named UX. Assume for lat also contained in  the .CODE file. This is the FORTRAN run-time system.   If a FORTRAN compilation contains no main program, then it is output  as if it were a Pascal unit compilation. The unit is given the name U, a distinct unit in order for the linker to properly define  named common data areas and file support for the run time system.  Unit number 7, given the name of the main program, contains all of the  user code. A reference to unit number 8, RTUNIT, isreference to a third. Unit  number 1, called MAINSEGX, contains code to manage all other segments,  defines named common blocks, initializes the run time system, etc. No  actual user code resides in the segment MAINSEGX. It must, however,  remain as overlays in FORTRAN. The next section describes how you link FORTRAN  with Pascal.    @@UNITS, SEGMENTS, PARTIAL COMPILATION  When a full FORTRAN program is compiled in one piece, the .CODE file  created contains 2 distinct segments and a ion deals with linking FORTRAN programs. The  third describes the $USES compiler directive. This directive provides  access to libraries or already compiled procedures, and provides ake advantage of separate  compilation or libraries, the details contained here are helpful.   The first section of this chapter discusses the general form of a  FORTRAN program in terms of the operating system object code  structure. The next sectN   This chapter describes the relationship between FORTRAN and the Apple  Pascal segment mechanism. In normal use, the user need not be aware of  such intricacies. However, if you want to interface FORTRAN with  Pascal, to create overlays, or to t    @@CHAPTER 14    @@@COMPILATION UNITS   110 Introduction  110 Units, Segments, Partial Compilation  111 Linking  112 $USES Compiler Directive  113 Separate Compilation  113 FORTRAN Overlays   ^bp    @@INTRODUCTIOer  examples that the object code is output to file X.CODE. All procedures  called from within unit UX must be defined within unit UX, unless a  $USES or a $EXT statement has shown them to reside in another unit.  Similarly, procedures in unit UX cannot be called from other units  unless the other units contain a $USES UX statement. Thus, a typical  main program that would call X might be:  ^ne 14 %C %C --- This is the main program BIGGIE %C %$USES UX IN X.CODE +PROGRAM BIGGIE +... +CALL  present in memory when one of its procedures is active. If the OVERLAY  field is not present, the unit is loaded into memory before the user  program is executed, and remains there until execution is over.   ^ne 3  Warning: If a FORTRAN main pros present, the name  filename is used as the file to process. If it is not, the file  *SYSTEM.LIBRARY is used as a default. If the optional field OVERLAY is  present, the unit in question is treated as an overlay. It is only variables in the INTERFACE portion of a Pascal unit. All $USES  commands must appear before any FORTRAN statements, specification or  executable, but they are allowed to follow comment lines and other $  control lines. If the optional 'IN filename' iIBRARY if the filename is absent, locate the  unit unitname, and process the INTERFACE information associated with  that unit, generating a reasonable FORTRAN equivalent declaration for  the FORTRAN compilation in progress. There cannot be any global  where  unitname is the name of a unit.  filename is a valid file name.   ^ne 2  As with all $ control statements, the $ must appear in column one.  This compiler directive directs the compiler to open the .CODE file  filename, or the SYSTEM.L units. It also provides an overlay mechanism to the FORTRAN  user that is somewhat more general than that provided in the Pascal  language.   ^ne 7  The format of the $USES control statement is:  '$USES unitname [ IN filename ] [ OVERLAY ]  tions in separately compiled units, such as  the system library, to be called from FORTRAN. It provides a  relatively secure form of separate compilation for FORTRAN programs.  It allows us to call Pascal routines that have been compiled into  Pascal %Linking UX # 8 %Linking MAINSEGX # 1 %  You could then eX(ecute the code file called BIG.CODE.     ^ne 5  @@$USES COMPILER DIRECTIVE   The $USES compiler directive provides several distinct functions. It  allows procedures and func%Lib file? X File containing user defined unit. %Opening X.CODE %Lib file? %Map name? %Reading MAINSEGX %Reading BIGGIE %Reading UX %Output file? BIG.CODE File for linked object code %Linking BIGGIE # 7 would run the linker by using the L(ink command, and respond as shown below.   ^ne 18  Linker II.1 [A4] %Host file? BIGGIE User inputs the name of the file %Opening BIGGIE.CODE containing the main program. . Normally, you specify the file containing the main program as the 'host file'. In addition, you must specify the files containing any user defined units referenced via the $USES statement as 'lib file' entries. Thus, to link the program BIGGIE you a simple  use of the $USES statement. More inforation on the $USES statement,  will be found later on in this chapter.     ^ne 5  @@LINKING  If external units or Named COMMON are used, the user program must be linked before it may be executed somewhere after subroutine W. Assume that the object code for this  compilation is output to the file BIGGIE.CODE.   ^ne 2  Thus, the user can create libraries of functions and partial  compilations, and save compilation time and disk space, by X +... +END +SUBROUTINE W +... +CALL Y +... +END   ^ne 2  If the $USES statement were not present, the FORTRAN compiler would  expect subroutines X and Y to appear in the same compilation, gram $USES a Pascal unit, that Pascal  unit cannot have any global variables in the INTERFACE part of its  declarations.     ^ne 5  @@SEPARATE COMPILATION  Separate compilation is accomplished by compiling a set of subroutines  and functions without any main program. Each such compilation creates  a code file containing a single unit. Then, when the main program is  compiled, possibly along with many subroutines or functions, it $USES  the separately compiled units. The routines compileB X A Y Z H8HG.šrocedures, thus overcoming  this limitation.  ^bp  ^bp of  either one causes the overlay to be loaded into memory, due to the  fact that the static nesting of Pascal procedures hides any sub-  procedures from any outside caller. The FORTRAN mechanism allows many  such procedures to be visible to outside pocedure and all nested procedures are to become  an overlay. Thus, whenever that procedure is active, the segment is  present in memory, and not otherwise! There is no way to combine two  or more procedures into a single overlay such that the calling  @@FORTRAN OVERLAYS  The FORTRAN overlay mechanism is slightly more general than the Pascal  mechanism. In Pascal, an overlay procedure is specified by the  reserved word SEGMENT appearing prior to that procedure's name. The  meaning is that the prIf unit B $USES unit  A, and unit C $USES unit B, then unit C must first $USES unit A.  Likewise, if units D and E both $USES unit F, they both must contain  exactly the same $USES statements prior to the $USES F statement.     ^ne 5 to get the unit numbers allocated consistently.   ^ne 2  In more complex cases, the user must insure that all references to  procedures in outside units are preceded by the proper $USES statement  in the same order, and are not missing any units. are calls to procedures in unit  A from unit B, then unit B must contain a $USES A statement. The main  program must then contain a $USES A statement as its first $USES  statement, followed by a $USES B statement. This is necessary for the  compiler  separate compilations, the user simply $USES all separately compiled  FORTRAN units in the main program. However, this limits the procedure  calls in each of the separately compiled units to procedures defined  in the that particular unit. If there d with the main  program obtain the correct definition of each externally compiled  procedure through the $USES directive.   ^ne 2  In the simplest form, when no $USES statements appear in any of the ^co [fortrs2:ch7a.text]    @@CHAPTER 16    @@@SPECIAL UNITS    124 The Turtle Graphics Unit  124 The Apple Screen  124 The INITTU Subroutine  125 The GRAFMO Subroutine  125 The TEXTMO Subroutine  125 The VIEWPO Subroutinween graphics and text display.    ^ne 5  @THE TEXTMO SUBROUTINE  ^zz  The TEXT MOde subroutine has no parameters. It switches from graphics  mode, obtained by INITTU or GRAFMO, to showing text. It is a very,  very good idea to conclude anFMO SUBROUTINE  ^zz  The GRAFics MOde subroutine has no parameters. It switches the monitor  or TV to show the graphics screen, without the other initialization  that INITTU does. It is usually used to show graphics in a program  that switches bet INITTU does a few other things as well: the turtle (more about it  later) is placed in the center of the screen facing right, the pen  color is set to NONE (more about this later too) and the viewport is  set to full screen.   ^ne 5  @THE GRA  ^ne 6  @THE INITTU SUBROUTINE  ^zz  This subroutine has no parameters. It clears the screen, and allows  the screen to be used for graphics rather than text. It is a good idea  to use this routine before starting any graphics.   ^ne 2 integers.  ^ne 2  There are two different screen images stored in the Apple's memory.  One of them holds text, the other holds a graphic image. There are  three statements that switch between the modes. They are INITTU,  TEXTMO and GRAFMO.  z  The Apple screen is a rectangle with the origin (X=0,Y=0) at the lower  left corner. The upper right corner has the coordinates (X=279,Y=191).  Since points may only be placed at integral coordinates, all arguments  to the graphics functions are  dragging a pencil along. Very simple algorithms in this system, which  could be called relative polar coordinates, can give more interesting  images than an algorithm of the same length in Cartesian coordinates.   ^ne 5  @THE APPLE SCREEN  ^zasy for  children who might have difficulty understanding Cartesian  coordinates, Papert et al. invented the idea of the turtle who could  walk a given distance and turn through a specified angle while  TURTLEGRAPHICS or APPLESTUFF is executed.   Incidentally, this graphics package is called Turtle Graphics since it  is based on the turtles devised by S. Papert and his co-workers at the  Massachusetts Institute of Technology. To make graphics ehis section can be used. This statement tells the  FORTRAN system to get the graphics subprograms from the library. These  subprograms are loaded in at run-time, which means that the library  file must be available to the system when any program using  The statement must come before any executable statement or  specification statement. It may appear after other compiler directive  statements or comment lines.   If this statement appears, the graphics subroutines and functions  described in tutines that have been designed to enable the use of fancy color-  graphics on your Apple.  The following compiler directive statement must appear near the top of  the program or subprogram that uses this CODE unit:   $USES TURTLEGRAPHICS Function/RANDOI Subroutine  132 Using the Game Controls  134 Making Music: the NOTE Subroutine  134 The KEYPRE Function  '  ^bp     @@THE TURTLE GRAPHICS UNIT  There is a CODE unit in SYSTEM.LIBRARY which contains a set of  subroe  126 Subroutines for Using Color  127 Cartesian Graphics  127 Turtle Graphic Subroutines  128 Turtle Graphic Functions  129 Sending an Array to the Screen  130 Text on the Graphic Screen  131 The Applestuff Unit  132 RANDOM y graphics program with a return to text  mode. If you forget to do this, you may not be able to see the usual  COMMAND: prompt or any other text. When you switch to text mode, the  image that you saw in GRAFMO is not lost, but will still be there when  you use GRAFMO to go into graphics mode again, unless you deliberately  changed it.    ^ne 9  @THE VIEWPO SUBROUTINE ^zz  The VIEWPOrt subroutine has the form   colors give a wider line  in order to make the colors show. If you wish to make a white or black  line that corresponds exactly in position and width with a green or  violet line then you should use WHITE1 or BLACK1. If you wish to make  a white or levision sets concoct their color, interacting with the technique  that Apple uses to get a lot of color very economically. Rather than  explaining how this all works, suffice it to say here that WHITE and  BLACK give the finest lines possible, and the CALL PENCOL (6)   ^ne 2  Now, it may seem strange that aside from WHITE, BLACK, GREEN, VIOLET,  ORANGE, and BLUE, there are two additional flavors of WHITE and BLACK.  These are due to the intricate, not to say bizarre, way that color  tese with orange and blue) % $10 ORANGE % $11 BLUE $ $12 WHITE2 (two dots wide, for use with orange and blue) %   ^ne 3  If you'd like the drawing to be in GREEN, you would use the statement:  re 0applications.  $5 BLACK1 (two dots wide, for use with green and violet) $ $6 GREEN $ $7 VIOLET % $8 WHITE1 (two dots wide, for use with green and violet) % $9 BLACK2 (two dots wide, for uto BLACK2, GREEN to VIOLET and ORANGE to BLUE and 0vice versa. It is rather a magical pen. It allows 0you to draw, say, a line across a complex background 0and have it still show up. $4 RADAR 0This "color" has been left unused for futu that happens to be there already, or as invisible ink. $1 WHITE $ $2 BLACK $ $3 REVERSE 0Drawing with REVERSE changes BLACK to WHITE and WHITE 0to BLACK. It also changes WHITE1 to BLACK1, WHITE2 0---------------------------------------------------  0 NONE $ Drawing with this "color" produces no change on the  screen. You can consider it as drawing with the color e sets the pen color. It has the form   PENCOL (PENMODE)   where penmode is an integer which corresponds to a particular color or  other mode as described in the table below.   ^ne 39  Integer PENMODE color  -------------------plot off-  screen all day, and never see a thing or get an error message.  Clipping cannot be disabled.    ^ne 9  @SUBROUTINES FOR USING COLOR  ^zz  The PENCOL and FILLSC subroutines are used for color in Turtle  Graphics. The PENCOL subroutin the current viewport is displayed. Points whose coordinates are not in  the current viewport, even those points that would not be on the  screen at all, are legal but are ignored.  ^ne 3  This allows some dramatic effects. It also allows you to descriptions of the line drawing subroutines, FILLSC and DRAWBL.    ^ne 3  &HAND  Clipping: When a line is drawn using any of the graphic commands, it  is automatically clipped so that only the portion which lies within   VIEWPO (130, 150, 86, 106)   ^ne 2  This example would allow the screen-plotting of all points whose  X-coordinates are from 130 through 150 and whose Y-coordinates are  from 86 through 106. For further information on VIEWPO see the  VIEWPO (left, right, bottom, top)   where the four parameters are integers which give the boundaries you  want the viewport to have. If you don't use this subroutine, Apple  FORTRAN assumes that you want to use the whole screen for your  graphics. black line that corresponds exactly in position and width  with an orange or blue line, then you should use WHITE2 or BLACK2.   ^ne 2  On a black-and-white monitor or TV set, just use WHITE and BLACK for  your colors.   The FILLSC subroutine has the form  &FILLSC (PENMODE)   where PENMODE is any of the integers standing for colors described  above. FILLSC fills the entire viewport with the color indicated by  PENMODE. For example  &FILLSC (2)   clears tMODE)   where the SOURCE parameter is the name without subscripts of a two-  dimensional array of type LOGICAL. All the other parameters are  integers.  ^ne 2  DRAWBL copies an array of dots in memory or a portion of the array  onto the screen is at  that point, but only whether there is a turtle-mark, anything  nonblack, there.  ^ne 11  @SENDING AN ARRAY TO THE SCREEN ^zz  The DRAWBL subroutine has the form  &DRAWBL (SOURCE, ROWSIZE, XSKIP, YSKIP, WIDTH, HEIGHT, XSCREEN, &YSCREEN,  The SCREEN function has the form &SCREEN (X,Y)   where X and Y are screen coordinates. This function returns the  logical value true if the specified location on the screen is not  black, and false if it is black. It doesn't tell you what color return integers giving  the current X and Y coordinates of the turtle.   ^ne 2  The TURTLA function, no parameters, returns an integer giving the  current turtle angle as a positive number of degrees modulo 360.   ^ne 6 and SCREEN allow you to ask your  Apple about the current state of the turtle and the screen. Note that  any functions specified without parameters must have ( ) following  the function name.   ^ne 2  The TURTLX and TURTLY functions, no parameters,:   ^ne 9 &CALL PENCOL (1) &CALL MOVE (50) &CALL TURN (120) &CALL MOVE (50) &CALL TURN (120) &CALL MOVE (50)   draws an equilateral triangle, for instance.    ^ne 5  @TURTLE GRAPHIC FUNCTIONS ^zz  The functions TURTLX, TURTLY, TURTLA  &MOVE (DISTANCE)   where DISTANCE is an integer. This subroutine makes the turtle move in  the direction in which it is pointing a distance given by the integer  DISTANCE. It leaves a trail in the current pen color. The sequence of  statementsnteger number treated modulo 360. This  subroutine causes the turtle to rotate counterclockwise from its  current direction through the specified angle. It causes no change to  the image on the screen.   ^ne 6  The MOVE subroutine has the form ver causes any change to  the image on the screen. A negative argument causes clockwise  rotation; a positive argument causes counterclockwise rotation.   ^ne 6  The TURN subroutine has the form  &TURN (DEGREES)   where DEGREES is again an iets out of the range -359 through 359. When invoked, this subroutine  causes the turtle to turn from its present angle to the indicated  angle. Zero is exactly to the right, and counterclockwise rotation  represents increasing angles. This command ne walk in the direction it is facing. As it walks, it leaves behind a  trail of the current pen color.   ^ne 6  The TURNTO subroutine has the form  &TURNTO (DEGREES)   where DEGREES is an integer. It is treated modulo 360, and thus never  g not changed by  MOVETO.   ^ne 5  @TURTLE GRAPHIC SUBROUTINES  ^zz  To understand turtle graphics, first imagine a small turtle sitting at  the center of the screen, facing right. This turtle can turn or it can ETO creates a line in  the current penmode from the last point drawn to the coordinates given  by (X,Y). When you INITTU, the turtle moves (with color NONE) to the  center of the screen.   ^ne 2  The direction of the turtle, as described below, ishe viewport. The statement &FILLSC (3)   makes a color negative of the contents of the viewport.    ^ne 9  @CARTESIAN GRAPHICS ^zz  The MOVETO subroutine has the form  &MOVETO (X, Y)   where X and Y are integer screen coordinates. MOVto form a screen image. You may choose to copy the  entire SOURCE array, or you may choose to copy any specified window  from the array, using only those dots in the array from XSKIP to  XSKIP+WIDTH and from YSKIP to YSKIP+HEIGHT. Furthermore, you can  specify the starting screen position for the copy, at (XSCREEN,  YSCREEN).   The DRAWBL subroutine parameters have the following meaning:   ^ne 2  SOURCE is the name of thHAR. This subroutine places the  character on the screen with its lower left corner at the current  location of the turtle. When this subroutine is used, the turtle is  shifted to the right 7 dots from its old position. For example, this  puts an X 3  If you make up a file containing your own character set, you should  rename the old SYSTEM.CHARSET and then name your new array  SYSTEM.CHARSET.   ^ne 6  The WCHAR subroutine has the form  &WCHAR (CH)   where CH is an expression of type C initialization routine when your program $USES TURTLEGRAPHICS. The  subroutine DRAWBL is then used to copy each character from the array  onto the screen. (Note that WSTRING is not available in FORTRAN  because its argument is a string.)   ^ne an use these subroutines to put a  character or string on the screen with its lower left corner at (X,Y).  The WCHAR subroutine uses an array stored in the file SYSTEM.CHARSET.  This array contains all the characters used, and is read in by the with screen. (~A OR S)  %14 ORs array with screen. (A OR S)  %15 Fills area with white.    ^ne 5  @TEXT ON THE GRAPHIC SCREEN  ^zz  Two subroutines, WCHAR and CHARTY, allow you to annotate graphics. If  the turtle is at (X,Y) you cthe screen. (A AND S) &9 EQUIVALENCEs array and the screen. (A = S)  %10 Copies array to the screen. (A)  %11 ORs array with the complement of the screen. (A OR ~S)  %12 Screen replaces screen. (S)  %13 ORs complement of array &3 Complements the screen. (~S)  &4 ANDs the complement of array with the screen. (~A AND S) &5 Complements array. (~A) &6 XORs array with the screen. (A XOR S)  &7 NANDs array with the screen. (A NAND S)  &8 ANDs array and --------------------------------------------------------------- % &0 Fills the area on the screen with black.  &1 NOR of array and the screen. (A NOR S)  &2 ANDs array with the complement of the screen. (A AND ~S)  peration is *performed on the data in the array and on the screen, and *thus what appears on the screen. The algebraic notation *uses A for the array, and S for the screen. The symbol ~ *means NOT.  ^ne 34  MODE EFFECT  -------- option which can simply *send white or black to the screen, irrespective of what is *in the array, copy the array literally, or combine the *contents of the array and the screen and send the result to *the screen. The following table specifies what o*of the area to be copied into. The WIDTH and HEIGHT *determine the size of the rectangle.  ^ne 2 %MODE ranges from 0 through 15. The MODE determines what appears *on the portion of the screen specified by the other *parameters. It is a powerfuly, starting at XSKIP, *will be used.   ^ne 2 %HEIGHT tells how many dots height of the array, starting at *YSKIP, will be used.   ^ne 3 %XSCREEN and YSCREEN are the coordinates of the lower left corner ls how many vertical dots in the array to skip over *before beginning the copying process. Note that copies are *made starting from the bottom up. The array, in effect, *gets turned upside down.   ^ne 2 %WIDTH tells how many dots width of the arrae two-dimensional BOOLEAN array to be  copied.  %ROWSIZE is the number of bytes per row in the array.   ^ne 2 %XSKIP tells how many horizontal dots in the array to skip over *before the copying process is started.   ^ne 4 %YSKIP telin the center of the screen:   ^ne 3 &CALL PENCOL (0) &CALL MOVETO (137,90) &CALL WCHAR ('X')  ^ne 2  In this example, note that it was not necessary to specify a new  PENCOL before calling WCHAR. The character is not plotted with the  current pen color; rather it depends on the current MODE, just as  DRAWBL does. For details, see CHARTY below.   ^ne 6  The CHARTY subroutine has the form  &CHARTY (MODE)   where MODE is an integer selecting one of the 16 modes described ab statement. Note that transfer of control into an IF block from outside  that block is not allowed.    ^ne 9  @@ELSEIF  The format of an ELSEIF statement is:  %ELSEIF (e) THEN %  where e is a logical expression. The ELSEIF block associat^zs  ^fo ''%  ^he '''Compilation Units  ^so jback5:new14x  ^he '''Bi-Lingual Programs  ^so jback5:new15ax  ^so jback5:new15bx  ^he '''Special Units  ^so jback5:new16ax  ^so jback5:new16bx  O^Scs oriented program.  ^ne 2  Another useful MODE is 5, which gives inverse characters. Lastly,  inverted exclusive OR would be a MODE of 9. ive OR of the character with the  current contents of the screen. Note that redrawing a character in  exclusive OR mode effectively erases the character, leaving the  original image unaffected. This is especially useful for user messages  in a graphiove  for DRAWBL. MODE defines the way characters get written on the screen.  The default MODE is 10, which places each character on the screen in  white, surrounded by a black rectangle. One of the most useful other  MODEs is 6, which does an exclused with an  ELSEIF statement consists of all of the executable statements,  possibly none, that follow the ELSEIF statement up to, but not  including, the next ELSEIF, ELSE, or ENDIF statement that has the same  IF-level as this ELSEIF statement. The execution of an ELSEIF  statement begins by evaluating the expression. If its value is true  and there is at least one statement in the ELSEIF block, the next  statement executed is the first statement of the ELSEIF block.  Following the execution of%1. The expressions e1, e2, and e3 are evaluated. If e3 is not (present, it is as if e3 evaluated to 1; e3 must not evaluate (to 0.  %2. The DO variable, i, is set to the value of e1.   ^ne 7 %3. The iteration count for the loop is computed to associated  with it. It is not allowed to jump into the range of a DO loop from  outside its range.   ^ne 2  The execution of a DO statement causes the following steps to happen  in order:   ^ne 3 the particular block. If a block IF statement appears  within the range of a DO loop, its associated ENDIF statement must  also appear within the range of that DO loop. The DO variable, i, may  not be set by the program within the range of the DO loopy contained within the range  of the enclosing DO loop, although the loops may share a terminal  statement. If a DO statement appears within an IF block, ELSEIF block,  or ELSE block, the range of the associated DO loop must be entirely  contained in  A DO loop is said to have a range, beginning with the statement which  follows the DO statement and ending immediately after the terminal  statement of the DO loop. If a DO statement appears in the range of  another DO loop, its range must be entirelck IF, ELSEIF, ELSE, ENDIF,  RETURN, STOP, END, or DO statement. If the terminal statement is a  logical IF, it may contain any executable statement EXCEPT those not  permitted inside a logical IF statement. %  ^ne 2  unit. In the DO statement, i is an integer variable, and e1, e2, and  e3 are integer expressions. The statement labeled by s is called the  terminal statement of the DO loop. It must not be an unconditional  GOTO, assigned GOTO, arithmetic IF, blolar block IF  statement.    ^ne 9  @@DO  The format of a DO statement is:  %DO s [,] i=e1, e2 [, e3] %  where s is a statement label of an executable statement. The label  must follow this DO statement and be contained in the same program The format of an ENDIF statement is:  %ENDIF %  ^ne 2  There is no effect in executing an ENDIF statement. An ENDIF statement  is required to match every block IF statement in a program unit in  order to specify which statements are in a particuefore any intervening ELSE or ELSEIF statements of the  same IF-level. There is no effect in executing an ELSE statement. Note  that transfer of control into an ELSE block from outside that block is  not allowed.     ^ne 6  @@ENDIF statement consists of all of  the executable statements, possibly none, that follow the ELSE  statement up to, but not including, the next ENDIF statement that has  the same IF-level as this ELSE statement. The matching ENDIF statement  must appear be same IF-level as the  ELSEIF statement. Note that transfer of control into an ELSEIF block  from outside that block is not allowed.     ^ne 9  @@ELSE  The format of an ELSE statement is:  %ELSE %  The ELSE block associated with an ELSE executable statements, the next statement executed is the next ENDIF  statement at the same IF level as the ELSEIF statement. If the  expression evaluates to false, the next statement executed is the next  ELSEIF, ELSE, or ENDIF statement that has th the last statement in the ELSEIF block, the  next statement to be executed will be the next ENDIF statement at the  same IF-level as this ELSEIF statement. If the expression in this  ELSEIF statement evaluates to true and the ELSEIF block has no be *MAX0(((e2 - e1 + e3)/e3),0) (which may be zero (Note: unlike FORTRAN 66) if either * *e1 > e2 and e3 > 0 1or *e1 < e2 and e3 < 0.   ^ne 2 %4. The iteration count is tested, and if it exceeds zero, the (statements in the range of the DO loop are executed.   ^ne 2  Following the execution of the terminal statement of a DO loop, the  following steps occur in order:   ^ne 3  1. The value of the DO variable, i, is incremented by the % value of e3 which was computed when the DO stG^۞˦Mrogram unit.  ^bp  ^ne 2 The effect of executing the END statement in a subprogram is the same as execution of a RETURN statement and the effect in the main program is to terminate execution of the program. The END statement must appear as the last statement in every pcontents of n, if present, are displayed as  part of the prompt requesting input. When input is received, execution  resumes as if a CONTINUE statement had been executed.    ^ne 6  @@END  The format of an END statement is:  %END % %PAUSE [n] %  where n is either a character constant or a string of not more than 5  digits. The effect of executing a PAUSE statement is to cause the  program to PAUSE until input is received from the keyboard. Execution  will then continue. The ayed on the  CONSOLE: upon termination.   ^ne 4  Example: STOP 'DONE!'   The message DONE! will be displayed on the screen when the program  executes the STOP statement.     ^ne 9  @@PAUSE  The format of a PAUSE statement is:   The format of a STOP statement is:  %STOP [n] %  where n is either a character constant or a string of not more than 5  digits. The effect of executing a STOP statement is to cause the  program to terminate. The argument, n, if present, is displ  C EXAMPLE OF CONTINUE STATEMENT &DO 200 I=1,10 &WRITE(*,'(I5)')I  200 CONTINUE &WRITE(*,'(I5)')I &END   ^ne 2  Note that CONTINUE simply acts as the terminator statement for the DO  loop in the routine.     ^ne 9  @@STOP ed with execution of a CONTINUE statement.  The primary use for the CONTINUE statement is as a convenient  statement to label, particularly as the terminal statement in a DO  loop.   ^ne 8  Here's an example of the CONTINUE statement in action:  %C This program fragment prints the number 1 to 11 on the CONSOLE: +DO 200 I=1,10 %200 WRITE(*,'(I5)')I +WRITE(*,'(I5)')I   ^ne 6  @@CONTINUE  The format of a CONTINUE statement is:  %CONTINUE %  ^ne 2  There is no effect associat The value of the DO variable is well defined regardless of whether the  DO loop exits as a result of the iteration count becoming zero or as a  result of a transfer of control out of the DO loop.   ^ne 6  Example of final value of DO variable:  atement (was executed. ' %2. The iteration count is decremented by one.   ^ne 2 %3. The iteration count is tested, and if it exceeds zero, the  statements in the range of the DO loop are executed again. %  ^ne 2