|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 216192 (0x34c80) Types: TextFile Names: »D58«
└─⟦6966c2393⟧ Bits:30005867/disk08.imd Dokumenter (RCSL m.m.) └─⟦this⟧ »D58«
RC FORTRAN User's Manual Third Edition August 1979 A/S Regnecentralen af 1979 RCSL 42-i 1205 \f Authors: Jens Hald Alan Wessel Technical Editor: Bo Tveden-Jørgensen Keywords: RC 4000, RC 6000, RC 8000, Basic Software, FORTRAN, User's Guide. Abstract: This manual describes the RC FORTRAN language and the RC FORTRAN compiler for the RC 4000, RC 6000, and RC 8000 systems. The description is close to ISO FORTRAN. Users ... Copyright 1979 A/S Regnecentralen af 1979 Printed by A/S Regnecentralen af 1979, Copenhagen \f F_ PREFACE This user's manual describes the RC FORTRAN language and the RC FORTRAN compiler for the RC 4000, RC 6000 and RC 8000 systems.The definition of the language is based on the Draft ISO Recommandati- on No. 1539, Programming Language FORTRAN. The manual may, how- ever, be read independently of this publication. The notation used for the format definition of the language is de- scribed in the beginning of Appendix A, which contains a concen- trated formal description of RC FORTRAN. The notation is used in the remaining part of the manual, frequently in a relaxed form to improve readability. The compiler was deloped by Bodil Larsen, Lise Lauesen, Jørgen Lindballe, Jes Linderoth, Ellen Randløv and the authors. Themain part of the library procedures was programmed by Inger Møller and Volker Raab. The compiler has been thoroughly tested and corrected by Flemming Hermansen and Bo Tveden-Jørgensen. R_e_f_e_r_e_n_c_e_s_: Ref. 1: Søren Lauesen: Utility programs part one: RCSL No. 31-D 364, part two: RCSL No. 31-D 494, part three: RCSL No. 31-D379. Ref. 2: Hans Dinsen Hansen: Algol 6, User's Manual. RCSL No. 31-D322. Ref. 3: Chr. Gram, T. Aris: Magnetic Tape System, MTS 2. RCSL No. 31-D198. Ref. 4: T. Sandvang: Code Procedures and Run Time Organization of Algol 5 Programs, RCSL No. 31-D199. Ref. 5: ISO: R646-1967(E), 6 and 7 bit coded character set for information processing interchange. Ref. 6: ISO: DR 1539, Programming Language FORTRAN. Ref. 7: Søren Lauesen: Boss 2, User's Manual. RCSL No. 42-i 1265 Ref. 8: Kirsten Mossin: External Processes. RCSL No. 31-D37. Ref. 9: Jørn Jensen: Indexed Sequential Files in RC 4000 ALGOL. RCSL: 55-D99. Ref. 10: P. Brinch Hansen: Multiprogramming System. RCSL: 55-D140. \f F_ TABLE OF CONTENTS 1 EXTERNAL AND INTERNAL REPRESENTATIONS Page 7 1.1 Character Set and Compounds 7 1.2 Line Format 10 1.3 Constants and the Internal Representation of Values 11 1.4 Variables and Arrays 14 1.4.1 Names 14 1.4.2 Variables 14 1.4.3 Arrays 14 2 DECLARATIONS 16 2.1 Type Statement 16 2.1.1 Form 16 2.1.2 Rules 16 2.2 DIMENSION Statement 17 2.2.1 Form 17 2.2.2 Rules 17 2.3 EQUIVALENCE Statement 18 2.3.1 Form 18 2.3.2 Rules 18 2.3.3 Notes 19 3 EXPRESSIONS 20 3.1 Arrays and Subscripts 20 3.2 Precedence Rules 20 3.3 Arithmetical and Masking Expressions 21 4 EXECUTABLE STATEMENTS 23 4.1 Arithmetical and Logical Assignment 23 4.2 GOTO Statements 24 4.2.1 Simple GOTO 24 4.2.2 Assigned GOTO 25 4.2.3 ASSIGN Statement 25 4.2.4 Computed GOTO 25 4.2.5 Examples 26 4.3 IF Statements 27 4.3.1 Logical IF 27 4.3.2 Arithmetical IF 27 4.4 DO Loops 28 4.4.1 Form 28 4.4.2 Execution of a DO Loop 28 4.4.3 Rules 28 4.5 CONTINUE Statement 29 4.6 STOP Statement 30 \f 5 INPUT/OUTPUT 31 5.1 Zones and Logical Units 31 5.1.1 Introduction 31 5.1.2 Zone Descriptor 31 5.1.3 Share Descriptor 32 5.1.4 Buffer Area 33 5.1.5 Declaration of Zones 33 5.1.6 The Standard Zones IN and OUT 34 5.1.7 Multishare Input/Output 35 5.1.8 Algorithms for Multishare Input/Output 37 5.2 Documents, Basic Input/Output 40 5.2.1 Documents 40 5.2.1.1 Backing Storage 41 5.2.1.2 Typewriter 41 5.2.1.3 Paper Tape Reader 41 5.2.1.4 Paper Tape Punch 42 5.2.1.5 Line Printer 42 5.2.1.6 Card Reader 42 5.2.1.7 Magnetic Tape 42 5.2.1.8 Internal Process 43 5.2.1.9 Devices Without Documents 44 5.2.2 Principles of Communication 44 5.2.3 Subroutine OPEN 47 5.2.4 Subroutine CLOSE 50 5.2.5 Logical Function SETPOSITION 51 5.2.6 REWIND, BACKSPACE, and ENDFILE 52 5.2.7 Subroutine ZASSIGN 52 5.3 Treatment of I/O Errors 53 5.3.1 Logical Status Word, Kind of Errors 53 5.3.2 Standard Error Actions 54 5.3.3 The Block Procedure and the Giveup Mask 58 5.3.4 Subroutine STDERROR 59 5.4 READ/WRITE Statements 59 5.4.1 Introduction 59 5.4.2 READ/WRITE with Format Control 59 5.4.3 The FORMAT Statement 62 5.4.4 Details about the Format Elements 63 5.4.4.1 E-Conversion 63 5.4.4.2 F-Conversion 65 5.4.4.3 D-Conversion 66 5.4.4.4 A-Conversion 66 5.4.4.5 I-Conversion 66 5.4.4.6 B-Conversion 67 \f 5.4.4.7 L-Conversion 68 5.4.4.8 Scaling Factor 68 5.4.4.9 Spaces and Text 68 5.4.5 Execution of Formatted READ/WRITE 69 5.4.5.1 Line Change 70 5.4.5.1.1 Line Change in READ 70 5.4.5.1.2 Line Change in WRITE 70 5.4.5.2 READ/WRITE Errors 72 5.4.5.3 Treatment of WRITE Errors 73 5.4.5.4 Treatment of READ Errors, Standard Variable READERR 73 5.4.6 READ/WRITE without Format Control 75 5.5 Record Handling 77 5.5.1 Input/Output System 77 5.5.2 Integer Function INREC 78 5.5.3 Integer Function OUTREC 79 5.5.4 Integer Function SWOPREC 81 5.5.5 Subroutine GETPOSITION 82 5.5.6 Logical Function SETPOSITION 82 5.5.7 EQUIVALENCE and ZONES 85 6 PROGRAM STRUCTURE 87 6.1 Program Units and their Mutual Communication 87 6.1.1 Structure of a Program Unit 87 6.1.2 Calling Functions and Subroutines 88 6.1.3 Parameter Checking 88 6.1.4 EXTERNAL Statement 89 6.1.5 Formal and Adjustable Arrays 89 6.1.6 Formal and Adjustable Zones 91 6.1.7 END Statement 91 6.1.8 RETURN Statement 91 6.1.9 ENTRY Statement 91 6.2 COMMON and DATA 92 6.2.1 COMMON 92 6.2.2 Local Variables versus COMMON Variables 93 6.2.3 Zones in COMMON 93 6.2.4 DATA Statement 93 6.3 Program Units from the Catalog 95 6.3.1 Algol Externals 95 6.3.2 Program Units in Machine Language 95 APPENDIX A: RC FORTRAN SYNTAX DESCRIPTION 96 A.1 Explanation 96 A.2 Symbols and Primitives 97 A.3 Declarations 99 \f A.4 Expressions 100 A.5 Executable Statements 101 A.6 Input/Output Statements 102 A.7 Program Structure 104 APPENDIX B: CALL OF COMPILER 105 APPENDIX C: MESSAGES FROM THE COMPILER 109 APPENDIX D: PROGRAM EXECUTION 116 D.1 Execution of an RC FORTRAN Program 116 D.2 Run Time Alarms 117 D.2.1 Initial Alarm 117 D.2.2 Normal Form 118 D.2.3 Undetected Errors 119 D.2.4 Alphabetic List of Alarm Causes 120 D.3 The Object Code 122 APPENDIX E: SURVEY OF STANDARD NAMES 124 E.1 List of Standard Externals 125 APPENDIX F: DEVIATIONS FROM ISO FORTRAN 127 F.1 Limitations 127 F.2 Extensions 127 APPENDIX G: EXECUTION TIMES IN MICRO SECONDS 128 G.1 Operand References 128 G.2 Constant Subexpressions 128 G.3 Saving Intermediate Results 129 G.4 List of Execution Times for a Selection of FORTRAN Constructs 129 INDEX 131 \f F_ 1. EXTERNAL AND INTERNAL REPRESENTATIONS 1.1 Character Set and Compounds The RC FORTRAN character set is a subset of the ISO 7-bit charac- ter set extended with the Danish letters: æ, Æ, ø, Ø, å, Å (see Ref. 5). Programs written in an external representation (console typewriter, punched cards, punched paper tape, etc.) are conver- ted internally to the ISO representation. The RC FORTRAN charac- ter set is an extension of the ISO FORTRAN character set as small letters are allowed and also many special characters may appear in texts and comments. The character set table (Table 1.1.1) shows (1) the decimal value of the ISO 7-bit representation. (2) the character, or an abbreviated name for the character. (3) the program input class. The treatment of the characters depends on their appearence in the program text as defined in Section 1.2. The effect is shown in Table 1.1.2. RC FORTRAN distinguishes between capital and small letters in texts only. For simplification the syntax using capital letters only is given. Names of characters are written in the abbreviated form shown in Table 1.1.1. The used syntax description is explai- ned in Appendix A. The legal characters are divided into syntactical groups: <symbol> ::= <letter> <digit> <separator> <terminator> <graphic> <arithmetical operator> <blind> <in text> <blind> ::= NUL DEL <in text> ::= SP _ \f F_Table 1.1.1. C_h_a_r_a_c_t_e_r_ _S_e_t_ _a_n_d_ _P_r_o_g_r_a_m_ _I_n_p_u_t_ _C_l_a_s_s_ (1) (2) (3) (1) (2) (3) (1) (2) (3) (1) (2) (3) 0 NUL blind 32 SP in text 64 @ graphic 96 graphic 1 SOH illegal 33 ! graphic 65 A basic 97 a basic 2 STX illegal 34 " graphic 66 B basic 98 b basic 3 ETX illegal 35 graphic 67 C basic 99 c basic 4 EOT illegal 36 S basic 68 D basic 100 d basic 5 ENQ illegal 37 % graphic 69 E basic 101 e basic 6 ACK illegal 38 & graphic 70 F basic 102 f basic 7 BEL illegal 39 ' basic 71 G basic 103 g basic 8 BS illegal 40 ( basic 72 H basic 104 h basic 9 HT basic 41 ) basic 73 I basic 105 i basic 10 NL basic 42 * basic 74 J basic 106 j basic 11 VT illegal 43 + basic 75 K basic 107 k basic 12 FF basic 44 , basic 76 L basic 108 l basic 13 CR blind 45 - basic 77 M basic 109 m basic 14 SO illegal 46 . basic 78 N basic 110 n basic 15 SI illegal 47 / basic 79 O basic 111 o basic 16 DLE illegal 48 0 basic 80 P basic 112 p basic 17 DC1 illegal 49 1 basic 81 Q basic 113 q basic 18 DC2 illegal 50 2 basic 82 R basic 114 r basic 19 DC3 illegal 51 3 basic 83 S basic 115 s basic 20 DC4 illegal 52 4 basic 84 T basic 116 t basic 21 NAK illegal 53 5 basic 85 U basic 117 u basic 22 SYN illegal 54 6 basic 86 V basic 118 v basic 23 ETB illegal 55 7 basic 87 W basic 119 w basic 24 CAN illegal 56 8 basic 88 X basic 120 x basic 25 EM basic 57 9 basic 89 Y basic 121 y basic 26 SUB illegal 58 : graphic 90 Z basic 122 z basic 27 ESC illegal 59 ; basic 91 Æ basic 123 æ basic 28 FS illegal 60 < graphic 92 Ø basic 124 ø basic 29 GS illegal 61 = basic 93 Å basic 125 å basic 30 RS illegal 62 > graphic 94 graphic 126 - graphic 31 US illegal 63 ? graphic 95 _ in text 127 DEL blind \f F_ Table 1.1.2. T_r_e_a_t_m_e_n_t_ _o_f_ _P_r_o_g_r_a_m_ _I_n_p_u_t_ _C_l_a_s_s_e_s_ input character in class comment or text label or statement field basicmeaningfulmeaningful graphic meaningful illegal in text meaningful skipped except after compound blindno effect, not even counting as symbol of the line illegalskipped, but causes warning RC FORTRAN includes the compounds listed in Table 1.1.3. A com- pound is an element made up of several characters. The compounds of the two rightmost columns in Table 1.1.3 must be followed by an in text' whenever the compound symbol is followed by a name or a digit. Accordingly, to avoid misinterpretation a name star- ting with the same letter as a compound should never have an <in text' separation at that place. Table 1.1.3. C_o_m_p_o_u_n_d_ _S_y_m_b_o_l_s_ Logical valuesDeclarativesIn statements .TRUE.PROGRAMASSIGN .FALSE.SUBROUTINETO FUNCTION OperatorsENTRYGOTO GO TO DATA **COMMON CONTINUE EQUIVALENCECALL .LT.RETURN .LE.INTEGERSTOP .EQ.LONG .NE.REALIF .GE.DOUBLE PRECISION .GT.COMPLEXDO LOGICAL .NOT.DIMENSIONEND .AND.ZONE .OR.EXTERNAL .SHIFT. FORMATREAD FORMATOWRITE \f T_1.2 Line Format A FORTRAN program is a sequence of symbols divided into lines by either the NL symbol or the FF symbol. When using punched cards a NL is generated at the end of each card. A program consists of &_ program text and comments. In a line the symbols are counted starting with number 1, only blind symbols do not count. Normally all symbols of a line are considered to be program text. By the compiler option cardmode.yes symbol 73 and onwards are treated as a comment. The first 6 symbols of a correct line are either (1) a control field, or (2) a label field. The examination has the steps: 1.1. If symbol 1 is a / (slash), the line will be treated as line starting with M (a message line). The compiler will not read any further source-text lines. 1.2. If symbol 1 is one of the letters A, B, C, ..., K, L, M, or an asterisk (*), the line is normally a comment line. By choise of parameters for the compiler the letters A, B, C, ..., K may be substituted by an <in text> symbol. The line is then a program line and can hold statements for testing. The letter L may start a conditional listing, while the let- ter M leads messages that may be output during compilation. 1.3. If symbol 6 is neither <in text> nor 0, the line is a con- tinuation line and symbols 1 through 5 must then be <in text>. The line is treated as a continuation of the program text of the previous line, i.e. cancelling the terminating effect of the foregoing NL, FF or comment. 2. If the 6 symbols are not a control field, symbols 1 through 5 must either contain a label or all be <in text>, and sym- bol 6 must be <in text> or 0. The label consists of digits only, leading spaces and zeroes are ignored. The line is an initial line. The 7th and following symbols either including the 72nd symbol or the rest of the line make up the statement field. The statement\f field may hold several statements seperated by the terminators ; (semicolon) or S (dollar). If a line holds less than 6 symbols, <in text> filling is supposed and the statement field is empty. When the statement field contains END, the line is an end line and the program unit terminates. Comments are allowed after the END. The compiler continues reading of source-text lines until: a. the source-list is exhausted (see appendix B, Call of compiler). or b. a line is read, with a / (slash) as symbol 1 (see step 1.1. above). T_ 1.3 Constants and the internal representation of values Integer, real, double precision, complex, and logical constants agree with the ISO FORTRAN syntax. RC FORTRAN includes long integer constants, short texts, and bitpatterns as described below, while the detailed syntax is given in Appendix A. The internal representation of values, as constants, variables, and array elements will claim from 1 halfword to 8 halfwords (1 halfword = 12 bits) depending on the type: INTEGERs LONGs REALse DOUBLEe---- esss000 000 COMPLEXsese LOGICAL Variable in storeO---OL Array elementO---OL s indicates the sign of integer, long or fixed-point parts. e indicates the sign of exponent. L indicates the determining bit of logical 0 indicates zeroed bits. For each type details of the representation and the range of va- lues are described. The representation of arithmetical values is binary using the 2-complement for negative values. \f T_ 1.3.1 INTEGER 1 word = 24 bits. Fixed-point representation: bit 0 : sign bit 23 : unit position Range : -2**23 <_ integer <_ 2**23-1 2**23 = 8 388 608 &_ Significant digits: 6-7 Integer constants in the program text exceeding the integer range are treated as long constants. T_ 1.3.2 LONG 2 words = 48 bits. Fixed-point representation: bit 0 : sign bit 47 : unit position Range : -2**47 <_ long <_ 2**47-1 2**47 = 140 737 488 355 328 &_ Significant digits: 14-15 Long constants in the program text exceeding the long range cause error messages during compilation. 1.3.3 REAL 2 words = 48 bits. T_ Floating-point representation: bit 0 : sign of fixed point part bit 0-35 : fixed-point part bit 36 : sign of exponent bit 36-47 : exponent Range : 2** (2**(-11)) <_ abs(real) < 2**(2**11-1) 2**(2**11) = 2**2048 = appr. 10**616 Significant digits: 10-11 &_ Real constants in the program text holding more than 11 signifi- cant digits are treated as double precision constants. T_ 1.3.4 DOUBLE 4 words = 96 bits. PRECISION Floating-point representation: bit 0-11 : extended sign of exponent bit 12 : sign of exponent bit 12-23 : exponent bit 24-26 : sign of fixed-point part bit 27-47 : fixed-point part 1, 21 bits bit 48-50 : 000 bit 51-71 : fixed-point part 2, 21 bits bit 72-74 : 000 bit 75-95 : fixed-point part 3, 21 bits. Range : as reals &_ Significant digits: approx. 19. Double precision constants exceeding the precision mentioned cause error messages during compilation.\f T_ 1.3.5 COMPLEX 4 words = 96 bits. Floating-point representation of real and imaginary parts: bit 0-47 : real part, represented as real bit 48-95 : imaginary part, represented as real. Complex constants in the program text holding more than 11 significant digits in the real or the imaginary part cause error messages during compilation. T_ 1.3.6 LOGICAL 1 halfword = 12 bits. .TRUE. 000 000 000 001 &_ .FALSE. 000 000 000 000 For simple variables a word is reserved but only the last halfword, i.e. bits 12-23 is used. Logical array elements occupy each one halfword only. 1.3.7 SHORT TEXT 2 words = 48 bits. Internally short texts are handled as long integers inferring a maximum of 6 characters each of 8-bits to be stored in a long integer. Short texts are allowed in expressions and as parameters. Text are written either (1) as a Hollerith text, i.e. nHxxx where n is integer and xxx is n non-blind symbols that are left-justified with SPACE filling when n < 6, or (2) as an apostrophed text i.e. 'xxx', in this case left-justified with NUL filling. Texts with more than 6 characters appearing where only short texts are allowed cause error messages during compilation. T_ 1.3.8 BITPATTERN short 1 word = 24 bits. &_ long 2 words = 48 bits. Bitpatterns are written as gBddd, where g is the number of bits in a group and may take the values 1, 2, 3, or 4, causing the T_ digits ddd to be interpreted accordingly. The binary digits are: 01 The quaternary digits are : 0123 The octal digits are: 01234567 The sedecimal digits are : 0123456789ABCDEF &_ Bipatterns are right-justified with zero filling for missing digits. If possible only 1 word is used. Short bitpatterns are treated internally as INTEGER constants while long bitpatterns are treated as LONG constants. Bitpatterns violating the syntax cause error messages during compilation. \f T_ 1.3.9 E_x_a_m_p_l_e_s_ _o_f_ _C_o_n_s_t_a_n_t_s_ In program type 0 integer -1 integer -8388608 integer 23 integer 8388607 integer -8388609 long 8388608 long -12345678 long 12345678 long 0.0 real -123.456 real 123.4e1 real, with value 1234 123.4e-1 real, with value 12.34 1234.56789012double precision 123.4d1 double precision, with value 1234 123.4d-1 double precision, with value 12.34 (1.2, 0.0) complex 5hhello short text (as long constant) 'hello' short text (as long constant) 4b123456 bitpattern (as integer constant with the value 1193046) 4b1234567 bitpattern (as long constant &_ with the value 19088743) T_ 1.4 Variables and arrays 1.4.1 N_a_m_e_s_ A FORTRAN symbolic name is a string of letters and digits begin- ning with a letter. RC FORTRAN allows and distinguishes names of &_ any length. Names are used for simple variables, arrays, zones, commons, and program units. Two different entities must not have identical names within one program unit. T_ 1.4.2 V_a_r_i_a_b_l_e_s_ A variable is a datum defined by its name and type. 1.4.3 A_r_r_a_y_s_ An array is an ordered set of data. Arrays may have any number of dimensions and are stored by columns in ascending storage loca- &_ tions. \f An array element is identified by following the array name by a parenthesized list of subscript expressions. The index check secures that elements refered to lie within the array. A subscript expression is an arithmetical expression. There is no restriction on the complexity and type of the expression; if the type is not integer the conversions follows the rules of assign- ment to integer (see arithmetical assignment, Section 4.1). The number of subscript expressions must agree with the dimensiona- lity of the array wherever array elements are referenced, except in EQUIVALENCE statements (see 2.3.2 step 6). The element A(i1, ..., in) of an array declared A(c1, ..., cn) is identified by use of the successor function f = i1 + c1*(i2+ ... + c(n-1)*in)...). By inserting ij = 1 and ij = cj for j = 1, ..., n the two limiting numbers f1 = f(ij = 1) and fc = f(ij = cj) de- fine the first and the last element of the array. The index check is performed on the value of successor function, and there is no check that 1 <_ ij <_ cj for j = 1, ..., n. \f F_ 2 DECLARATIONS 2.1 Type statement The type and dimensioning associated with a name may be con- trolled by type statements and/or DIMENSION statements. 2.1.1 F_o_r_m_ 1 * <type> <name> (<fixed bounds>) 0 1 <type> :: = LOGICAL INTEGER REAL LONG COMPLEX DOUBLE PRESICION * <fixed bounds> :: = <integer> 1 E_x_a_m_p_l_e_ _2_._1_._1_ real ra (3, 7, 4, 2) declares an array of type real with 4 dimensions. The first dimension ranges from 1 to 3, the second from 1 to 7, etc. E_x_a_m_p_l_e_ _2_._1_._2_ integer x, ia(2, 3, 4), y declares two simple integers x,y and an integer array ia. 2.1.2 R_u_l_e_s_ 1. The type statement associates the specified type with all names occuring in the list of names. If fixed bounds are spe- cified the name is associated with an array with dimensions and range corresponding to the bound list. 2. The type and dimensions of the name may be specified only once within a program unit. 3. If a name is not explicitly type declared, type integer is\f implicitly assumed if the name starts with i, j, k, l, m, or n, otherwise type real is assumed. 4. Any number of dimensions are allowed (ISO standard: 3). 5. Arrays are stored column by column - in consecutive storage locations. E.g., the array ia of Example 2.1.2 will occupy 24 storage locations as shown: ia(1, 1, 1) ia(2, 1, 1) ia(1, 2, 1) ia(2, 2, 1) ia(1, 3, 1) ia(2, 3, 1) ia(1, 1, 2) ia(2, 1, 2) etc. 2.1.3 N_o_t_e_s_ 1. Variable bounds may be used, when an array appears as a formal parameter. See Section 6.1.5. 2. A few names of intrinsic functions and basic external func- tions are implicitly of type complex or double precision (see Appendix E). 2.2 DIMENSION statement 2.2.1 F_o_r_m_ * DIMENSION <name> (<fixed bounds>) 1 * <fixed bounds> :: = <integer> 1 2.2.2 R_u_l_e_s_ The DIMENSION statement may be used for stating separately the dimensionality of one or more names. See Section 2.1.2 above for further rules. \f 2.3 EQUIVALENCE statement The order in which names occur in type statements and/or DIMEN- SION statement does not control the mutual placement of the variables in core, i.e. names declaring after each other in a type statement are not necessarily placed in the same order in core. The storage allocation may be controlled by the EQUIVALENCE statement or by the COMMON statement (see Section 6.2). 2.3.1 F_o_r_m_ * <variable name> * EQUIVALENCE ( ) <array name>(<constant subscripts>) 2 1 * <constant subscripts> :: = <integer> 1 E_x_a_m_p_l_e_ _2_._3_._1_ real a(5), b(3, 4), x integer q(6) equivalence (a(2), b(2, 3) x, q(2)) The variables a(2), b(2, 3) and x now refer to the same four halfwords. The integer variable q(2) corresponds to the two first of these. Note that q(3) will correspond to the two last half- words, a(3) and b(3, 3) are equivalent, etc. E_x_a_m_p_l_e_ _2_._3_._2_ long p integer ia(2), i1, i2 equivalence (p, ia(1), i1), (ia(2), i2) i1 and ia(1) now correspond to the first half of the long integer p while i2 and ia(2) correspond to the last half. 2.3.2 R_u_l_e_s_ The EQUIVALENCE statement permits the use of different names in connection with the same element(s). The variables referenced within an equivalence group describe the same data element with the following clarifications and restrictions: 1. The variables referenced may be of different type and kind. \f 2. If the variables are of different size the shorter one will correspond to the first halfword(s) of the longer one. 3. Within a group of equivalenced variables at most one variable may directly or through equivalence be a common variable (Section 6.2). 4. The equivalences must not be contradictory, e.g., by making elements of the same array equivalent. 5. Only local or COMMON variables may occur in EQUIVALENCE statements. 6. The number of subscripts in a subscripted variable must a. be exactly one or b. agree with the declaration of the array. An instance of form a, like: a(7) is the same as a(7,1,...,1) of form b. T_ 2.3.3 N_o_t_e_s_ &_ 1. A special form of equivalence connected with zones is described in Section 5.5.7. \f F_ 3 EXPRESSIONS 3.1 Arrays and subscripts A subscript expression is an arithmetical expression with no re- striction on the complexity and type of the expression; if the type is not integer the conversion follows the rules of assign- ment to integer (see Arithmetical assignment, Section 4.1). The number of subscript expressions must agree with the dimen- sionality of the array wherever arrays elements are referenced, except in EQUIVALENCE statements (see 2.3.2 step 6). 3.2 Precedence rules The syntax (Appendix A) defines 3 different sorts of expressions, namely arithmetical, masking, and logical. The precedence of ope- rators is not included in the syntax. The following rules hold for the sequence of operations in any expression: a. In an expression the precedence of the operators is 1st: ** .SHIFT. 2nd: * / 3rd: + - 4th: .LT. .LE. .EQ. .NE. .GE. .GT. 5th: .NOT. 6th: .AND. 7th: .OR. b. Operators of the same precedence level are executed from left to right. c. Expressions enclosed in parantheses and function calls are evaluated by themselves and the value is used in subsequent cal- culations. Monadic operators operate on one operand, e.g. -A. Dyadic ope- rators combine two operands, e.g. A/B. Operands combined through dyadic operators may be of different types except in shift and logical operations. This often implies that one operand has to be converted before the operation. \f Operations that are not mathematically defined or violate the value range may cause alarm. If the execution of procedure calls refer to variables in the same statement, side effects may be triggered. This is prohibited in the ISO standard, but no check is performed. T_ 3.3 Arithmetical and masking expressions The monadic operators + - may be considered to operate as if a zero precedes the same dyadic operator; the result is of the same &_ type as the original operand. The dyadic operators + - * / ** combine operands of arithmetical type integer, long, real, double precision, and complex. The types may be mixed, the type of the result is given in the table below. Only the power operator ** is restricted: - the exponent must not be of type long, double precision or complex. - the radicand must not be of type double precision or complex. T_ Table 3.3.1. R_e_s_u_l_t_i_n_g_ _t_y_p_e_s_ _o_f_ _a_r_i_t_h_m_e_t_i_c_a_l_ _o_p_e_r_a_t_i_o_n_s_ _+_ _-_ _*_ _/_ _*_*_ a <op> b b integer long real double complex a (not**) (not**) (not**) integer integer long real double complex long long long real double complex real real real real double complex double (not**) double double double double complex &_ complex (not**) complex complex complex complex complex R_e_a_l_ _o_v_e_r_f_l_o_w_ _a_n_d_ _u_n_d_e_r_f_l_o_w_. The reaction on real overflow is controlled by the external integer variable OVERFLOWS in the FORTRAN system as follows: T_ OVERFLOWS < 0 The run is terminated at overflow. OVERFLOWS >_ 0 The value of OVERFLOWS is increased by one. The result of the actual &_ arithmetical operation is 0. When the program execution starts, the value of OVERFLOWS is -1. \f Real underflow is controlled analogously by the external integer UNDERFLOWS. When using the mask operators .NOT., .AND., .OR., and .SHIFT. the already shown precedence of operators holds. Mixing of types in- teger, real, and long is permitted as shown in the syntax and further explained below and in table 3.3.2, other types are pro- hibited. .NOT. The operator is monadic, all bits of the operand are complemented. The result is either short or long depending on the operand. T_ .AND. The operators are dyadic and work as the same logical .OR. operators on all bits of the operands. If short and long operands are mixed the short operand is combined with the &_ last 24 bits of the long operand, i.e. the result is short. The type is long when a real operand is masked. .SHIFT. The operator is dyadic. The result of A .SHIFT. B is either short or long agreeing with A, and the operation is to shift the A-operand B bits to the left (i.e. to the right when B<0) with zeroes entering from either side. A may be of type integer, real or long, while B must be an integer operand. Arithmetical expressions resulting in type integer, real, or long (table 3.3.1) may appear as operands of .NOT., .AND., and .OR. T_ Table 3.3.2. R_e_s_u_l_t_i_n_g_ _t_y_p_e_s_ _o_f_ _m_a_s_k_i_n_g_ _o_p_e_r_a_t_i_o_n_s_. .NOT. A A .AND. B A .SHIFT. B A .OR. B A B integer B long B real B integer integer integer integer integer integer integer long long integer long long long real real integer long real real \f 4 EXECUTABLE STATEMENTS 4.1 Arithmetical and logical assignment 4.1.1 A_r_i_t_h_m_e_t_i_c_a_l_ _A_s_s_i_g_m_e_n_t_ In arithmetical assignments v=e the value of the arithmetical expression e is evaluated first resulting in a value of arithme- tical type. The element v must also be of arithmetical type, and if it corresponds to the type of e the assignment is made, if not an implied conversion precedes the assignment as shown in table 4.1.1. Some of these will be two-stage conversions. Table 4.1.1. A_r_i_t_h_m_e_t_i_c_a_l_ _A_s_s_i_g_n_m_e_n_t_. v=e eintegerlongrealdoublecomplex v integerL.CONV.IR.TRUNC.ID.TRUNC.RC.CONV.R =2==2==2=R.TRUNC.IR.TRUNC.I xxy=2= xy=2= xy longI.CONV.LR.TRUNC.L D.TRUNC.LC.CONV.R =4==4==4==4= R.TRUNC.L xyxy=4= xy realI.FLOAT.RL.FLOAT.R D.TRUNC.RC.CONV.R =4==4==4==4==4= yy doubleI.FLOAT.R C.CONV.R R.CONV.DL.FLOAT.DR.CONV.DR.CONV.D =8==8==8==8==8= complexI.FLOAT.RL.FLOAT.RD.TRUNC.R R.CONV.CR.CONV.CR.CONV.CR.CONV.C =8= =8==8==8= y=8= E_x_p_l_a_n_a_t_i_o_n_: x Integer overflow may occur. y Precision may be lost. =n= Assign means transmit the resulting value, without change, to entity. n 12-bit halfwords are transmitted. e.CONV.v Convert the resulting value of e-type to representation of the v-type. e.TRUNC.vTruncate means preserve as much precision of the\f resulting value of e-type as can be contained in datum of receiving v-type. See below. e.FLOAT.v Float means change fixed-point value of e-type to floating-point representation of v-type T_r_u_n_c_a_t_i_o_n_ _o_f_ _R_e_a_l_ _V_a_l_u_e_s_: The truncations R.TRUNC.I and R.TRUNC.L are controlled by the compiler-option: trunc.yes or trunc.no (see Appendix B). trunc.yes: if R <1, the result is 0; if R >_1, the result is the integer (respectively long) whose magnitude does not exceed the magnitude of R and whose sign is the same as the sign of R. trunc.no: The result is the nearest integer (respectively long). T_ T_h_e_ _C_o_n_v_e_r_s_i_o_n_s_: L.CONV.I The first word of L is excluded, overflow when the bits 0-23 of L are not equal to bit 24 of L. &_ I.CONV.L The sign of I is extended 24 bits. Multiple arithmetical assignments are allowed when all elements assigned to are of the same arithmetical type. 4.1.2 L_o_g_i_c_a_l_ _E_x_p_r_e_s_s_i_o_n_s_ _a_n_d_ _A_s_s_i_g_n_m_e_n_t_s_ A relation operator compares the values of two arithmetical ex- pressions. When these values are of different type an implied conversion takes place. Logical expressions agree with the ISO standard. A part of an expression need only be evaluated when necessary to establish the value of the total expression. This will be used to optimise the calculation of logical expressions without rearranging the terms in the expression. Logical assign- ment v=e demands both v and e to be of type logical. Multiple lo- gical assignments are allowed when all elements assigned to are of type logical. T_ 4.2 GOTO statements 4.2.1 S_i_m_p_l_e_ _G_O_T_O_ Form: GO TO <statement label> The statement causes unconditional transfer of control to the statement identified by the statement label. Both GO TO and GOTO &_ are permitted. \f 4.2.2 A_s_s_i_g_n_e_d_ _G_O_T_O_ * Form: GO TO <label name,>(<statement label> ) 1 R_u_l_e_s_: 1. The statement acts as a many branch GOTO statement. Before executing an assigned GOTO the referenced label variable must be assigned (see below). By the assigned GOTO statement con- trol is transferred to the statement identified by the as- signed label value. If the label variable is unassigned the execution will cause a run time alarm. 2. A label name must explicitly or implicitly be of type integer and it must not be COMMON. 3. When an integer name is referenced in an ASSIGN statement or an assigned GOTO statement it is considered a label name. It must not be used as an arithmetical operand within the same program unit. Violating this rule will cause a type error at compilation time. 4. The comma and the label list is optional. No check is per- formed based on the label list. 4.2.3 A_S_S_I_G_N_ _S_t_a_t_e_m_e_n_t_ Form: ASSIGN <statement label> TO <label name> The statement assigns the specified statement label to the label variable. See 4.2.2, rule 2 and 3. E_x_a_m_p_l_e_ _4_._2_._1_ assign 1017 to lab ... GOTO lab, (1010, 1012, 1017) After the execution of the shown ASSIGN statement, the assigned GOTO statement will transfer control to the statement with label 1017. 4.2.4 C_o_m_p_u_t_e_d_ _G_O_T_O_ * Form: GO TO (<statement label> ), <integer expression> 1 The statement works as follows: the value of the integer ex-\f pression is evaluated giving the result, r. Control is then transferred to the statement identified by the r'th statement label in the label list. If r is less than 1 the first label is selected, if r is greater than the number of labels in the list the last label is selected. T_ 4.2.5 E_x_a_m_p_l_e_s_ E_x_a_m_p_l_e_ _4_._2_._2_ The following GOTO statements all effect a transfer to the state- ment with label 100: assign 100 to lab GOTO lab GOTO 100 inx = 3 &_ GOTO (300, 200, 100, 50), inx T_ E_x_a_m_p_l_e_ _4_._2_._3_ _ _A_d_m_i_n_i_s_t_r_a_t_i_o_n_ _o_f_ _A_c_t_i_o_n_s_ Processing of records may be implemented as a set of actions, numbered from 1 to k, and an action table, integer actab(n), &_ where actab(i) specifies the actions to be executed for records of type i. If action numbers range from 1 to 15, the action numbers may be packed in 4 bit groups, so that up to 6 actions may be specified for each record. The administration of the action execution may then look like: T_ iac=actab(record type) c extract action number 50 action=iac .and. 1b1111 c prepare extraction of next action number iac=iac .shift. (-4) c select action, goto 9999 if no more c actions for this record goto(9999, 100, 200 ..., 1500),action + 1 ... c action 1 ... 100 num=record(numbinx) ... goto 50 c action 2 ... 200 if (type .gt. max) ... ... goto 50 &_ etc. \f 4.3 IF statement 4.3.1 L_o_g_i_c_a_l_ _I_F_ Form: IF (<logical expression>) <statement> R_u_l_e_s_ 1. The statement works as follows: the logical expression is evaluated. If the value is true, the conditional statement is executed, otherwise the statement is bypassed. 2. The statement must not be a DO statement. 4.3.2 A_r_i_t_h_m_e_t_i_c_a_l_ _I_F_ 3 Form: IF (<arith expression>) <statement label> 3 R_u_l_e_s_ 1. The statement works as follows: the value of the arithmetical expression is evaluated. If the resulting value is negative the first label is chosen, if the value is equal to zero the second label is chosen, else the third label is chosen. Con- trol is then transferred to the statement identified by the chosen label. 2. The expression must not be of type complex. E_x_a_m_p_l_e_ _4_._3_._1_ The algol statement goto if x<0 then L100 else if x<y then L10 else if x=y then L20 else L30 may be written in fortran as if (x .lt. 0) goto 100 if (x-y) 10,20,30 \f 4.4 DO loops 4.4.1 F_o_r_m_ 3 DO<statement label><integer name> = <expression> 2 4.4.2 E_x_e_c_u_t_i_o_n_ _o_f_ _a_ _D_O_ _L_o_o_p_ The statement causes a sequence of statements starting with the DO statement, up to and including a terminal statement to be exe- cuted repeatedly. The terminal statement is determined by the specified label. The number of repetitions is controlled by the three expressions. The variable specified by the integer name is called the control variable, the first expression determines the starting value, the second expression determines the limit and the third expression determines the step. If the third expression is omitted, the step 1 is used. The execution of a DO loop may be described as follows: 1. Evaluate values of step and limit: The second and third expressions are evaluated and if necessary truncated to integers. 2. Compute value of control variable: At first entry the control variable is assigned the starting value, the following times the current value of step is added to the control variable. 3. Conditional execution of DO range. The statements within the range of the DO loop are executed if (limit-control variable)*step .ge. 0 After execution of the DO range the procedure is repeated from 1. above. If the condition is not fulfilled the DO loop is exhausted and execution proceeds with the statement after the terminal statement of the DO loop. 4.4.3 R_u_l_e_s_ 1. The control variable must be of type integer. 2. The expressions must be of arithmetical type. After each evaluation the value is truncated to an integer before it is used in the DO control, i.e. addition to the control variable and test is performed in integer mode. \f 3. The terminal statement must be found after its corresponding DO statement within the program text. 4. A DO loop may contain other DO loops but the inner loop must be completely contained within the surrounding DO loop. 5. A nest of DO loops may have the same terminal statement, the terminal statement is then considered as part of the innermost DO loop (see Example 4.4.1). 6. When a DO loop is exhausted the control variable retains its last assigned value (see 4.4.2 step 2). T_ E_x_a_m_p_l_e_ _4_._4_._1_ N = 0 DO 100 I = 1,10 J = I DO 100 K = 1,5 L = K 100 N = N + 1 &_ 101 CONTINUE After execution of these statements and at the execution of the CONTINUE statement, I = 11, J = 10, K = 6, L = 5, and N = 50. T_ E_x_a_m_p_l_e_ _4_._4_._2_ N = 0 DO 100 I = 1,10 J = I DO 100 K = 5,1 L = K 200 N = N + 1 &_ 201 CONTINUE After execution of these statements and at the execution of the CONTINUE statement I = 11, J = 10, K = 5, and N = 0. L is not defined by these statements. T_ 4.5 CONTINUE statement The CONTINUE statement consists solely of the word CONTINUE and serves as a dummy statement to which a label may be attached. The &_ statement has no effect. \f 4.6 STOP statement 1 Form: STOP <integer> 0 The execution of a STOP statement terminates program execution in a way similar to passing the END statement of the main program. All zones are released, the word 'end' is written on current out- put. \f F_ 5 INPUT/OUTPUT 5.1 ZONES AND LOGICAL UNITS 5.1.1 I_n_t_r_o_d_u_c_t_i_o_n_ The input/output system of RC FORTRAN utilizes a concept called a zone. A zone is a compound entity consisting of three distinct parts: 1) z_o_n_e_ _d_e_s_c_r_i_p_t_o_r_ 2) one or more s_h_a_r_e_ _d_e_s_c_r_i_p_t_i_o_n_s_ (hereafter just called shares) 3) b_u_f_f_e_r_ _a_r_e_a_ A zone may be assigned a unitnumber whereby the zone is acces- sible as a traditional logical unit. The READ/WRITE statements may specify either the zone name or the unitnumber when indicating the logical unit to be worked upon. The extended input/output system of RC FORTRAN, like INREC/OUTREC etc, providing tools for record handling, may only specify the zone name. 5.1.2 Z_o_n_e_ _D_e_s_c_r_i_p_t_o_r_ A zone descriptor consists of the following set of quantities which specify a process or a document connected to the zone and the state of this process: Process name: A text string specifying the name of a process or a document. Mode and kind: An integer specifying mode and kind for a document (see 5.2.3 open). Logical position: A set of integers specifying the current position of a document. Give up: An integer specifying the conditions under which <block proc> is to be called. State: An integer specifying the latest operation on the zone. \f Line change mode: An integer specifying the proper line change action for WRITE (in ALGOL this field is called: Free parameter). Record: Two integers specifying the part of the buffer area nominated as the zone record. Used share: An integer specifying a share descriptor within the zone. Last byte: An integer specifying the end of a physical block on a document. Block procedure: The procedure <block proc> (see 5.1.5). The normal use of these quantities is explained in details in chapter 5.2. Further details may be found in ref. 2, GETZONE. 5.1.3. S_h_a_r_e_ _D_e_s_c_r_i_p_t_o_r_ Each zone contains the number of share descriptors given by <shares> in the parenthesis following the zone identifier (see 5.1.5). The share descriptors are numbered 1, 2, ..., <shares>. A share descriptor consists of a set of quantities which de- scribes an external activity sharing a part of the buffer area with the running program. An activity may be a parallel process transferring data between a document and the buffer area under supervisory control of the FORTRAN program. Further details may be found in ref. 2. The set of quantities forming one share descriptor is: Share state: An integer describing the kind of activity going on in the shared area. Shared area: Two integers specifying the part of the buffer area shared with another process by means of the share descriptor. Operation: Specifies the latest operation performed by means of the share descriptor. \f 5.1.4 B_u_f_f_e_r_ _A_r_e_a_ The buffer area is used for containing the data for input/output. When using the record procedures, like INREC/OUTREC etc., a part of this zone buffer is made available for the program as the socalled z_o_n_e_ _r_e_c_o_r_d_. The zone record is a real array of one dimension with the same name as the zone itself. The zone elements are numbered 1, 2, ..., <record length>. 5.1.5 D_e_c_l_a_r_a_t_i_o_n_ _o_f_ _Z_o_n_e_s_ 5.1.5.1 S_i_m_p_l_e_ _Z_o_n_e_s_. A simple zone may be declared as follows: ZONE <zone name>(<bufsize>,<shares>,<blproc name>) bufsize (integer) The size of the buffer area expressed in double words. shares (integer) The number of shares. blproc name (procedure)The name of the attached block procedure. T_h_e_ _b_u_f_f_e_r_ _a_r_e_a_. This parameter defines the size of the total buffer area attached to the zone. The area is measured in double words. T_h_e_ _n_u_m_b_e_r_ _o_f_ _s_h_a_r_e_s_. A general multibuffer administration is used by the input/output system. The number of shares defines the number of buffers into which the total buffer area is divided. Normally the user will choose the values 1 or 2 for single or double buffered input/output. The size of a share should normally match the block size of the connected external device. If the share does not match the block size, part of the block may be lost when transferred. This is considered a hard error (see Sec- tion 5.3). A longer share is just waste of core. T_h_e_ _b_l_o_c_k_ _p_r_o_c_e_d_u_r_e_. The block procedure is called by the in- put/output system when hard errors occur during the input/output operations. Normally the use of a standard block procedure is recommended (see Section 5.3.4 and Ref. 3), but the user may de- sign individual block procedures according to the detailed con- ventions found in Section 5.3.3 and Ref. 2. The use of a block procedure in a zone declaration works as an EXTERNAL declaration of the name. \f T_ 5.1.5.2 Z_o_n_e_ _A_r_r_a_y_s_. An array af zones is declared by combining the zone declaration with a DIMENSION statement. Only one dimension is al- lowed. The parameters specified in the zone declaration are common to all zones in the zone array, but each zone has its own descrip- tion and its own buffer area of the specified size. A single zone from a zone array is referred by writing the name &_ of the zone array followed by one subscript. T_ 5.1.6 T_h_e_ _S_t_a_n_d_a_r_d_ _Z_o_n_e_s_ _I_N_ _a_n_d_ _O_U_T_ &_ The standard zones IN and OUT are preopened zones which may be used on character level (i.e. by formatted READ/WRITE). The zone IN is preassigned the unitnumber 5, while OUT has been preassigned the unitnumber 6. If the names of these standard zones are to be used in a program unit they must be declared as external zones as follows: External in, out; zone in, out If these standard zones are used solely by the unitnumbers they need not be declared as external zones. T_ E_x_a_m_p_l_e_ _5_._1_._1_ The declaration zone zo(256, 2, stderror) &_ declares a zone named zo, with a buffer of 256 double words. The buffer is divided in two shares and the standard block procedure, stderror, is used.The name stderror is automatically declared external. T_ E_x_a_m_p_l_e_ _5_._1_._2_ The declarations zone (10, 1, stderror); dimension za (3) &_ declares a zone array consisting of three zones, each with a buffer of 10 double words in a single share.\f T_ 5.1.7 M_u_l_t_i_s_h_a_r_e_ _I_n_p_u_t_/_O_u_t_p_u_t_ The amount of information transferred to or from a share in one operation is called a b_l_o_c_k_. On a magnetic tape a block is a &_ physical block or a tape mark. On a backing storage area a block is one or more segments. On a paper tape reader a block is usually one share of characters. I_n_p_u_t_ During input from a document via a zone with sh shares the system uses one of the shares for unpacking of information and the remaining sh-1 shares for uncompleted input of later blocks. The following picture shows the state of the blocks of the document. T_ I_n_p_u_t_,_ _s_h_ _=_ _3_ logical position physical begin of position &_ document completed transfers uncompleted transfers if close was called Note that when the document is closed the physical position of the document is far ahead of the logical position. This is particular important at the end of magnetic tapes where the 'waved' blocks may be absent and the tape then comes off the reel. O_u_t_p_u_t_ During output to a document via a zone with sh shares one share is used for packing of information, and 0 to sh-1 of the remain- ing shares are used for uncompleted output of previous blocks. The following picture shows the state of the blocks in the output stream. T_ O_u_t_p_u_t_,_ _s_h_ _=_ _3_ logical position physical begin of position document completed transfers uncompleted transfers if close was called &_ for packing Note that when the document is closed the physical position is just after the block corresponding to the logical position. \f S_w_o_p_r_e_c_ The procedure swoprec utilizes the shares as follows: One share is used for packing and unpacking of information. If sh > 1 another share is used for uncompleted output. Remaining shares are used for uncompleted input of future blocks. C_h_o_i_c_e_ _o_f_ _s_h_ The advantage of the multishare input/output is that differences in speed between the program and the device may be smoothed to any degree. The most frequent choise is between single or double buffer input/output. The following rule of thumb may help you to choose in cases where you scan a document sequentially: th = time spent by the program with handling of the information in a block. td = time spent by the device with transfer of a block. td + th is the total time in single buffer mode (sh = 1). max. (td, th) is the total time in double buffer mode (sh = 2). If th varies from block to block the situation is more complicated and sh > 2 may pay. The following rule of thumb concerns the sequential use of swoprec: th + 2*td is the total time per block with sh = 1. max (th, td) + td is the total time per block with sh = 2. max (th, 2*td) is the total time per block with sh = 3. You should always use s_i_n_g_l_e_ _b_u_f_f_e_r_i_n_g_ _o_n_ _p_r_i_n_t_e_r_,_ _p_l_o_t_t_e_r_,_ _a_n_d_ p_u_n_c_h_, except when you know for sure that your job is not stopped and started by the operating system. The reason is that an output operation is terminated halfway when the job is stopped, but with sh > 1 the next output operation is started before the first is checked and output again. You should always use s_i_n_g_l_e_ _b_u_f_f_e_r_i_n_g_ _f_o_r_ _t_y_p_e_w_r_i_t_e_r_ _o_u_t_p_u_t_ because the operator at any moment may stop the output operation to send a console message to send a console message. \f T_ M_e_s_s_a_g_e_ _B_u_f_f_e_r_s_ _O_c_c_u_p_i_e_d_ Input/output by means of sh shares occupies permanently sh-1 of the message buffers available for the job (see ref. 10). From the moment SETPOSITION has been called for a magnetic tape and until the first input/output operation is performed one message buffer &_ is occupied (even when sh = 1). T_ 5.1.8 A_l_g_o_r_i_t_h_m_s_ _f_o_r_ _M_u_l_t_i_s_h_a_r_e_ _I_n_p_u_t_/_O_u_t_p_u_t_ You must know about these algorithms if you want to interfere with the system in the block procedure of the zone. More details &_ about the variables in a zone may be found in Ref. 2. Ref. 8 while Ref. 10 explain the rules behind the communication with devices. The algorithms below are written in algol, and sh denotes the number of shares in the zone. T_ S_n_a_p_s_h_o_t_s_ _o_f_ _S_h_a_r_e_s_ _i_n_ _T_y_p_i_c_a_l_ _S_i_t_u_a_t_i_o_n_s_ _(_s_h_ _=_ _3_)_ Just after setposition on a magnetic tape: move operation free free (always share 1) After inrec: record input free input (used share) After several outrecs: record output free output &_ (used share) \f C_h_a_n_g_e_ _o_f_ _B_l_o_c_k_ _a_t_ _I_n_p_u_t_ rep: if share _state (used share) = free then begin start transfer (input); used _share:= used _share mod sh + 1; goto rep end; comment now all shares are busy with transfers except after a positioning; wait _transfer (used _share); comment share state becomes free. The operation checked might be a positioning operation; last byte := top transferred (used share) -1; comment now the share contains data from record base to last byte; C_h_a_n_g_e_ _o_f_ _B_l_o_c_k_s_ _a_t_ _O_u_t_p_u_t_ if share _state (used share) <> free then begin wait _transfer (used _share); comment a positioning operation might be uncompleted; end; start transfer (output); used _share := used _share mod sh + 1; comment one or more shares behind used _share are busy with transfers; wait _transfer (used _share); comment share state becomes free and the share may be filled from record base to last byte; S_t_a_r_t_ _T_r_a_n_s_f_e_r_ _(_O_p_e_r_a_t_i_o_n_)_ This procedure works only on used _share. It sets a part of the message and sends it: first absolute address of block := abs address of first shared; segment number of message := segment count; update segment count for next transfer; operation in message := operation; comment the mode is left unchanged; send message; share state := uncompleted transfer; \f W_a_i_t_ _T_r_a_n_s_f_e_r_ This procedure waits for the answer from a transfer or tape positioning, checks it, and performs the standard error actions (error recovery). Finally, it may call the block procedure of the zone. In details this works as follows: record _base:= abs address of first _shared(used _share) -1; last _byte:= abs address of last _sh _red(used _shared) +1; record _length:= last _byte - record _base; st:= share _state(used share); if st <> running child process then share _state(used share):= free; if st <> uncompleted transfer then goto return: wait _answer(st); if kind = magnetic tape then begin if some words were transferred then block _count:= block _count + 1; if tape mark sensed and operation is input or output mark then begin file _count:= file _count +1; block _count:= 0 end end; compute logical status word; comment the logical status word is 24 bits describing the error conditions of the transfers (see 5.3); top _transferred(used _share):= if operation = io then 1 + address _of _last _byte _transferred else first _shared(used _share); users _bits := common ones in logical status and give up mask; remaining _bits := logical _status - users _bits; perform standard error actions for all ones in remaining bits (see 5.3). if a hard error is detected then logical _status := logical _status + 1; (continued) \f (continued) if hard error is detected or usersbits <> 0 then begin b:= toptransferred(usedshare) - 1 - record base; let record describe the entire shared area from first shared to last shared; save:= zone state; if operation = input and tapemark and b = 0 then b:= 2 blockproc (z, logical _status, b); zone _state:= save; if b < 0 or b + record base > lastbyte then index _alarm; top transferred(used _share):= b + 1 + record _base; end; return: 5.2 Documents, basic input/output 5.2.1 D_o_c_u_m_e_n_t_s_ The various external media which may be used in RC FORTRAN are called documents. A document may be a deck of cards, a roll of paper tape, a reel of magnetic tape, etc. Documents are identifi- ed by a document name, which is a string of up to 11 small ISO- letters or digits starting with a letter and terminated by the NUL-character. A document may be thought of as a string of information, either a string of 8-bit characters or a string of binary words. The string is on some documents broken into physical blocks (e.g., on magnetic tapes and backing storage areas). The procedures for in- put/output on character level and record level keep track of the current logical position of the document. The logical position points to the boundary between two characters or two elements of the document. During normal sequential use of the document, the logical position moves along the document corresponding to the calls of the input/output procedures. For documents consisting of physical blocks, the logical position is given by a position within the physical block, plus a block number, plus (for magnetic tapes) a file number. Note that the block number is ambiguous in the case where the logical position points to the boundary between two physical blocks. This ambigui- ty is resolved explicitly in the description on the individual procedures: The term 'the logical position is just before a cer- tain item' implies that the block number is the block number of that item. \f The following sections give a survey of some documents and the way they transfer information to and from the zone buffer. The rules for protection of documents and further details are found in Ref. 1. T_ 5.2.1.1 B_a_c_k_i_n_g_ _S_t_o_r_a_g_e_. The backing storage may consist of drums and/or discs. You have no direct access to the entire backing storage, but only to documents which are backing storage areas consisting of a number of segments. Each segment contains 512 halfwords, equivalent to 128 real variables. The segments are numbered 0, 1, &_2, ... within the area, and the block numbers mentioned above are exactly these segment numbers. File numbers are irrelevant. One or more segments may be transferred directly as bit patterns to or from the core store in one operation. The number ofseg- ments transferred is the maximum number that fits into the share used. Details about the various types of backing storage devices may be found in Ref. 8. T_ 5.2.1.2 T_y_p_e_w_r_i_t_e_r_. A typewriter may be used both for input and output. The sequence of characters input forms one document (infinitely long), and the sequence of characters output forms another docu- &_ ment. File number and block number are irrelevant on a typewri- ter. One input operation transfers one line of characters (including the terminating New Line character) to the share. If the share is too short, less than a line is transferred, but that is an abnor- mal situation. The characters are packed in ISO 7-bit form with 3 characters to one word, and the last word is filled up with NULs. One output operation transfers characters packed in the same form to the typewriter. Several lines may be output by one operation. T_ 5.2.1.3 P_a_p_e_r_ _T_a_p_e_ _R_e_a_d_e_r_. A document consists of one roll of paper tape. It may be read in various modes: with even parity, with odd pari- ty, without parity, or with transformation from flexowriter code &_ to ISO code. File number and block number are irrelevant for a paper tape. \f One input operation will usually fill the share with characters packed 3 per word, but fewer characters may also be transferred, for instance at the tape end. In such cases, the last word is filled up with NUL characters. The characters are not necessarily T_ ISO characters, that depends on the meaning you assign to them. 5.2.1.4 P_a_p_e_r_ _T_a_p_e_ _P_u_n_c_h_. A document is infinitely long, even when the &_ operator divides the output into more paper tapes. A paper tape may be punched in various modes: with even parity, with odd pari- ty, without parity, or with transformation from ISO code to fle- xowriter code. File number and block number are irrelevant for tape punch. One output operation may punch any number of characters packed 3 per word. In all modes, except the mode without parity, only the last 7 bits of the characters are output and extended with a pa- T_ rity bit. &_ 5.2.1.5 L_i_n_e_ _P_r_i_n_t_e_r_. A document is infinitely long. File number and block number are irrelevant on a printer. One output operation may print any number of characters packed 3 per word. Several lines may be output by one operation. The cha- T_ racters must be in ISO 7-bit code. 5.2.1.6 C_a_r_d_ _R_e_a_d_e_r_. A document is one deck of cards. It may be read in &_ various modes: in binary, in decimal, and with conversion from Hollerith to ISO. File number and block number are irrelevant on a card reader. One input operation will usually fill the share, but fewer cards may also be read, for instance at the end of the deck. One column contains always one character. The characters are packed 2 per word in binary mode, and 3 per word in the other modes. In the latter case, a card is stored as 81 characters, where the 81st is T_ a New Line character generated by the monitor. 5.2.1.7 M_a_g_n_e_t_i_c_ _T_a_p_e_. A document is one reel of tape. It consists of a &_ sequence of files seperated by a single file mark. Each file con- sists of physical blocks with possibly variable lengths. The blocks may be input or output in even or odd parity. The files and blocks are numbered 0, 1, 2, ... as shown in the figure. \f T_ One operation transfers one physical block to or from a share. If an input block is longer than the share, only the first part of the block is transferred. A magnetic tape document: logical position &_ load point file 0 tape mark file 1 tape mark end of x x tape block 0 block 1 ... block 0 block 1 ... Two kinds of tape stations exist: 7-track stations where a block consists of a sequence of 6-bit bytes; one word of the share is here transferred as four 6-bit bytes. 9-track stations where a block consists of a sequence of 8-bit bytes; one word of the sha- re is here transferred as three 8-bit bytes. The difference cau- ses no trouble as long as the tapes are written and read on RC 4000, RC 6000, or RC 8000. But if you try to move a 7-track tape to another computer (or to an off-line converter), you should remember that READ and WRITE work with 8-bit characters. The share length used for output to a magnetic tape determines the physical block length. Because the blocks are seperated by a block gap of 3/4 inch, the share length has influence on the a- mount of information the tape can hold and also on the maximum transfer speed. With density of 556 bpi (bytes per inch), a share length of 60 elements will generate blocks of about 3/4 inch (mo- re or less depending on the kind of the station). In this case half of the tape is used for blocks and half for block gaps. The data are transferred with 0.38 times the maximum tape speed, be- cause block gaps take 1.6 the time of blocks of the same length. If you use a share length of 600 elements, 10/11 of the tape is T_ used for data and the transfer rate is 0.86 of the maximum. 5.2.1.8 I_n_t_e_r_n_a_l_ _P_r_o_c_e_s_s_. An internal process (another program executed &_ at the same time as your job) may read or write a document. The process may be designed to react according to the rules given for the document. After calling OPEN with the name of the internal process and the kind corresponding to the document the process may then be used exactly as the document. The internal process may also handle the information in its own way, and then no general rules can be given, but usually, the end of the document is signalled as explained in Section 5.3. \f T_ 5.2.1.9 D_e_v_i_c_e_s_ _w_i_t_h_o_u_t_ _D_o_c_u_m_e_n_t_s_. Some peripheral devices, for instance the clock do not scan documents, and they cannot be handled by the high level zone procedures. However, the primitive input/out- &_ put level may handle such devices too. T_ 5.2.2 P_r_i_n_c_i_p_l_e_s_ _o_f_ _C_o_m_m_u_n_i_c_a_t_i_o_n_ The following principles generally apply for the use of a docu- &_ ment: a. The document must be loaded on a specific device and connected to a zone. This is done by calling the standard procedure OPEN. b. Input/output operations and maneuvering is thereafter perfor- med by calling i/o-procedures referring exclusively to the zone. c. The document may finally be released from the zone andpossib- ly unloaded by use of the procedure CLOSE. NOTE: if the document is a magnetic tape the call of OPEN must be followed by a call of the procedure SETPOSITION before input/out- put operations are legal. \f The main features of the input/output system may be illustrated by the example below and the comments following it. In the examp- le file 1 from a magnetic tape is read by unformatted READ and printed on a line printer by formatted WRITE. F_ E_x_a_m_p_l_e_ _5_._2_._1_. P_r_i_n_t_i_n_g_ _o_f_ _a_ _M_a_g_n_e_t_i_c_ _T_a_p_e_ _F_i_l_e_ line no. 1 program taprint 2 common/eofcom/ eof, prnam 3 data eof, prnam/ 0, 'printer'/ 4 logical setposition; long prnam(2); integereof 5 zone tapzon(256,2,blp) 6 zone przon(40,2,stderror) 7 call open (tapzon,18, 't5011', 1 .shift. 16) 8 call open (przon,14,prnam(1), 0) 9 call setposition (tapzon,1,0) 10 10 read(tapzon) x,y,z,v 11 if(eof) 100,20,100 12 20 write(przon, 1000) x,y,z,v 13 goto 10 14 1000 format(4h x= ,f8.2, e.t.c. 15 100 call close(tapzon, .true.) 16 call close(przon, .true.) 17 end 18 function blp(z,s,b) 19 zone z; integer s,b,eof; long prnam(2) 20 common/eofcom/eof, prnam 21 if( s .and. 1) 10,20,10 22 10 call stderror(z,s,b) 23 20 if (b) 40, 40, 30 24 30 eof = 1; b =16 25 40 end Comments to example 5.2.1: line 3 eof is initiated to zero, the array prnam is initiated to the document name, printer, with trailing NUL characters (see Section 6.2.4 about DATA and long texts). line 5 The zone for tape reading is declared. The zone buffer is 256 reals in two shares corresponding to a block length of 128 reals. The function blp is to be called, when hard\f errors occur on the magnetic tape at the end of file. Details about the block procedure are given in Section 5.3.3. line 6 The zone for the line printer is declared. The share size here is 20 double words corresponding to 120 8-bit characters. With this zone the standard block procedure STDERROR is to be used. This means that in case of a hard error the run is terminated with a standard messa- ge on the current output unit. See section 5.3.4 about STDERROR. line 7 The tape zone is opened. The second parameter, 18, means that the document to be connected is a magnetic tape in odd parity. The possible codes for kind and mode of document are given in Section 5.2.3. The third parameter is the name of the relevant document to be mounted on a tape unit. The fourth parameter says, that when end of file is read (indicated by status bit, see Section 5.3.1), the normal reaction (described in Section 5.3.2) is to be replaced by a call of the block procedure. line 8 The line printer zone is opened. Note, that a special document name, printer, is used. Usually each installa- tion has certain document names connected with devices as tape reader, tape punch, and printer, where the do- cuments are anonymous. The giveup mask is zero, which means that errors are treated as described in the subsection of 5.3.2 headed Paper tape punch, line printer. line 9 The document connected to the zone tapzon is now posi- tioned to file 1, block 0, as specified by the two last parameters. lines These lines should be considered together with lines 10-14 18-25 declaring the special block procedure. This is the central loop, which reads from the input tape, writes on the line printer until end of file is met on the magnetic tape. When this happens the block procedure is called and indicates the end of file by setting the variable eof to 1.\f m_ lines The zones are closed, i.e. transfers are terminated and 15-16 the documents are disconnected from the zones. The pa- rameters .true. specifies that the documents are made available to other users. lines The block procedure is called after a block transfer if 18-19 end of file is sensed or if an i/o-error occurs (parity error, etc.). The giveup mask of 1 .shift. 16 in line 7 signals, that the block procedure must be called at end of file instead of executing the standard action. The parameters are: z the zone, s the status word with information about the reason of the call, b the length of the block transferred. lines If the call reason is an i/o-error the standard block 21-22 procedure is called. line 23 The block procedure may be called when positioning the tape to file 1, but the value of b determines if the tapemark was sensed during a read or during a positioning. (See section 5.3.2, subsection for magnetic tape). line 24 End of file is signalled to the main program by setting eof to 1. The block length b is set to 16 corresponding to 4 reals (see Section 5.3.3). The following pages contain the procedure descriptions for OPEN and CLOSE together with some notes on SETPOSITION, which are necessary for use with simple input/output. 5.2.3 S_u_b_r_o_u_t_i_n_e_ _O_P_E_N_ Connects a document to a given zone in such a way that the zone may be used for input/output with the high level zone procedures. CALL OPEN(z, modekind, doc, giveup) z (call and return value, zone). After return, z descri- bes the document. modekind (call value, integer). Mode.shift.12 + kind. See below. doc (call value, text). A text specifying the name of the document as required by the monitor, i.e. a small let- ter followed by a maximum of 10 small letters or digits ended by a NUL-character. Short texts of up to 5 cha- racters + NUL may be given as a LONG variable or a text constant. Longer document names must be given in two consecutive element of a LONG array. The first element of the array is given as parameter to OPEN (see Example p_5.2.1). \f giveup (call value, integer). Used in connection with the checking of a transfer. See below. T_ M_o_d_e_k_i_n_d_ Specifies the kind of the document (typewriter, backing storage, magnetic tape, etc.) and the mode in which it should be operated (even parity, odd parity, etc.). &_ T_ The kind of the document tells the input/output procedures how error conditions are to be handled, how the device should be po- sitioned, etc. As a rule, the procedures do not care for the ac- tual physical kind of the document, but disagreements will usual- ly give rise to bad answers from the document and an error condi- tion arises. If you, for example, open a backing storage area with a kind specifying printer, and later attempt to output via the zone, the backing storage area will reject the message becau- se the document was initialised as required by a printer. On the other hand, if new kinds of devices are introduced, these may be used directly in fortran if you can find a kind which cor- responds to the way these devices should be handled. Mode and kind must be coded as shown in the table below. If you attempt a mode or kind which does not fit into the table, the run is &_ terminated. T_ K_i_n_d_ 0 Internal process, mode = 0. 4 Backing storage area, mode = 0. 8 Typewriter, mode = 0. 10 Paper tape reader, mode = 0 for odd parity, 2 for even parity (the normal ISO form), 4 for no parity, and 6 for conversion from flexowriter code to ISO. 12 Paper tape punch, mode = 0 for odd parity, 2 for even parity (the normal ISO form), 4 for no parity, and 6 for conversions from ISO to flexowriter code. 14 Line printer, mode = 0 for all printers, except centronics 101A via medium speed tmx where mode = 64. 16 Card reader, see Ref. 8 for full details. 18 Magnetic tape (tapes of 6 or 8 bit physical characters). For RC 747 and RC 749: Mode = 0 or 4 means odd parity. &_ Mode = 2 or 6 means even parity. \f For RC 4739 and RC 4775 modekind is defined to be: T .shift. 16 + Mode .shift. 12 + 18, where Mode = 0 means 1600 bpi, PE, odd parity. Mode = 2 means 1600 bpi, PE, even parity. Mode = 4 means 800 bpi, NRZ, odd parity. Mode = 6 means 800 bpi, NRZ, even parity. For output 0 <_ T < 6 specifies that the last T physical characters in a block should not be output to the tape. For input T should be 0. If you use T <> 0 during output, you should set the word defect bit (1 shift 7) and the stopped bit (1 shift 8) in your giveup mask and after a check of bytes transferred simply ignore the bits in your block proce- dure. I_n_i_t_i_a_l_i_s_a_t_i_o_n_ _o_f_ _a_ _D_o_c_u_m_e_n_t_ Open prepares the later use of the document according to kind: Internal process, backing storage area, typewriter: Nothing is done. When a transfer is checked later, the necessary initialisation is performed. Paper tape reader, card reader: First, open checks to see whether the reader isreser- ved by another process. If it is, the parent receives the message wait for <name of document> and open waits until the reader is free. Second, open initialises the reader and empties it. Third, open ini- tialises the reader again (in order to start reading in lower case), sends a parent message asking for the rea- der to be loaded, and waits until the first character is available. Paper tape punch, line printer: Open attemps to reserve the document for the job, but the result of the reservation is neglected. \f T_ Magnetic tape: If the tape is not mounted, a parent message is sent asking for mounting of tape. The message is sent with- &_ out wait indication (see Ref. 7). Some of these rules have been introduced to remedy a possible lack of an advanced operating system. T_ G_i_v_e_u_p_ &_ The parameter giveup is a mask of 24 bits which will be compared to the logical status word each time a transfer is checked. If the logical status word contains a one in a bit where giveup has a one, the standard action for that error condition is skip- ped and the block procedure is called instead (the block procedu- re is also called if a hard error is detected during the check- ing). T_ Z_o_n_e_ _S_t_a_t_e_ &_ The zone must be in state 4, after declaration. The state becomes positioned after open (ready for input/output) except for magnetic tapes, where setposition must be called prior to a call of an input/output procedure. The entire buffer area of z is divided evenly among the shares and if the document is a backing storage area, the share length is made a multiple of 512 halfwords. If this cannot be done without using a share length of 0, the run is terminated. The logical position becomes just before the first element of block 0, file 0. T_ 5.2.4 S_u_b_r_o_u_t_i_n_e_ _C_L_O_S_E_ Terminates the current use of a zone and makes the zone ready for a new call of open. Close may also release a device so that it &_ becomes available for other processes in the computer. CALL CLOSE(z, rel) z (call and return value, zone). Specifies the document, the position of the document, and the latest operation on z. rel (call value, logical). True if you want the document to be released, false otherwise.\f CLOSE terminates the current use of the zone as described for SETPOSITION. If the document is a magnetic tape which latest has been used for output, a tape mark is written. Finally, CLOSE releases the document if rel is true. Releasing means for a backing storage area that the area process descrip- tion inside the monitor is released for use by other zones of yours. The area itself is not removed and you may later open it again, provided that it has not been removed meanwhile by some other process (this may be prevented as described in Ref. 1). Releasing means for other documents that the corresponding peri- pheral device is made available for other processes. T_ Z_o_n_e_ _S_t_a_t_e_ &_ The zone may be in any state when CLOSE is called. After the call the zone is in state 4, after declaration, meaning that it must be opened before it can be used for input/output again. T_ 5.2.5 L_o_g_i_c_a_l_ _F_u_n_c_t_i_o_n_ _S_E_T_P_O_S_I_T_I_O_N_ CALL SETPOSITION(z, file, block) setposition (return value, logical). True if a magnetic tape &_ positioning has been started, false otherwise. z (call and return value, zone) Specifies the docu- ment, the position of the document, and the latest operation on z. file (call value, integer). Irrelevant for documents other than magnetic tape. Specifies the file number of the wanted position. Files are counted from 0. block (call value, integer). Irrelevant for documents other than magnetic tape or backing storage. Specifies the block number of the wanted position. Blocks are counted from 0. SETPOSITION performs the following actions: 1. If the zone is used for output remaining data blocks in the buffer area are transferred to the document. A tape mark is then output if the document is a magnetic tape. If the zone is used for input possible running transfers are waited for. 2. If the document is a magnetic tape, this is now moved to a position immediately in front of the block determined by the specified file number and block number. If the document is a\f backing storage area no movement takes place, but the next block to be transferred is determined by the specified block number. A detailed description of SETPOSITION is found in Section 5.5.6. T_ 5.2.6 R_E_W_I_N_D_,_ _B_A_C_K_S_P_A_C_E_,_ _a_n_d_ _E_N_D_F_I_L_E_ ISO FORTRAN (see Ref. 6) specifies some auxiliary procedures for magnetic tape operation. The functions of these procedures are &_ included in the procedures SETPOSITION and CLOSE as follows: REWIND Rewind magnetic tape to load point. Replace by: CALL SETPOSITION(z,0,0) BACKSPACE Backspace one block. A subroutine performing this operation within the current file may look like: SUBROUTINE BACKSPACE(z) zone z; integer file , block call GETPOSITION(z, file, block) if (block .gt. 0) call SETPOSITION(z, file, block-1) end ENDFILE Write file mark. This is done automatically when SETPOSITION or CLOSE is called with a zone, which has latest been used for output. T_ 5.2.7 S_u_b_r_o_u_t_i_n_e_ _Z_A_S_S_I_G_N_ CALL ZASSIGN (z, unitnumber) z (call value, zone) &_ unitnumber (call value, integer) Assigns a unitnumber to the specified zone so that future READ/ WRITE statements may access the zone by specifying the unitnum- ber. If the zone already has been assigned a unitnumber the zone will only be accessible via the new unitnumber. If the unitnumber already has been assigned to a zone only the new zone will be accessible via the unitnumber. If the unitnumber is negative the zone is not accessible via a unitnumber. \f The assignment is only defined as long as the zone is defined. The zone is (of course) always accessible by means of the zone name itself. The standard zones IN and OUT have been preassigned the unitnum- bers 5 and 6 respectively. T_ 5.3 Treatment of i/o errors 5.3.1 L_o_g_i_c_a_l_ _S_t_a_t_u_s_ _W_o_r_d_,_ _K_i_n_d_ _o_f_ _E_r_r_o_r_s_ Errors occurring during i/o-operations are indicated in the logi- cal status word, which is generated by the basic i/o system at &_ the end of each operation of a document. The following sections give a survey of the conventions for the logical status word and the standard actions taken for each kind of error and each kind of document. The bits of the logical status word: 1 .shift. 23: Intervention. The device was set in local mode during the operation, presumably because the operator changed the paper or the like. 1 .shift. 22: Parity error. A parity error was detected during the block transfer. 1 .shift. 21: Timer. The operation was not completed within a certain time defined in the hardware. 1 .shift. 20: Data overrun. The high speed channel was overloaded and could not transfer the data. 1 .shift. 19: Block length. A block input from magnetic tape was longer than the buffer area allowed for it. 1 .shift. 18: End of document. Means various things, for instance: Reading or writing outside the backing storage area was attempted; the paper tape reader was empty; the end of tape was sensed on magnetic tape; the paper supply was low on the printer; end of deck on card reader. See Ref. 1 for further details. 1 .shift. 17: Load point. The load point was sensed after an operation on the magnetic tape or output tray was full on card reader. 1 .shift. 16: Tape mark. A tape mark was sensed or written on the magnetic tape, or the attention button was pushed during typewriter i/o. 1 .shift. 15: Write-enable. A write-enable ring is mounted on the magnetic tape. \f 1 .shift. 14: High density. The magnetic tape is in high density mode. 1 .shift. 13: Reading error on card reader. 1 .shift. 12: Card rejected on card reader. 1 .shift. 8: Stopped. Generated by the check routine when less than wanted was output to a document of any kind or less than wanted was input from a backing storage area. 1 .shift. 7: Word defect. Generated by the check routine when the number of characters transferred to or from a magnetic tape is not divisible by the number of words transferred, i.e. when only a part of the last word was transferred. 1 .shift. 6: Position error. Generated by the check routine after magnetic tape operations, when the monitors count of file and block number differs from the expected value in the zone descriptor. 1 .shift. 5: Process does not exist. The document is unknown to the monitor. 1 .shift. 4: Disconnected. The power is switched off on the device. 1 .shift. 3: Unintelligible. The operation attempted is illegal on that device, e.g., input from a printer. 1 .shift. 2: Rejected. The program may not use the document, or it should be reserved first. 1 .shift. 1: Normal answer. The device has attempted to execute the operation, i.e. 1 shift 5 to 1 shift 2 are not set. (Other bits may be set) 1 .shift. 0: Hard error. The standard error action has classi- fied the transfer as a hard error, i.e. the error recovery could not succeed. 5.3.2 S_t_a_n_d_a_r_d_ _E_r_r_o_r_ _A_c_t_i_o_n_s_ The bit 'normal answer' is always ignored; the remaining standard error actions depend on the document kind given in OPEN as shown below. This kind has not necessarily any relation to the actual physical kind. Situations not covered by the description are hard errors, which mean that the block procedure is called (see be- low). B_a_c_k_i_n_g_ _S_t_o_r_a_g_e_ End of document after an The empty block read is replaced by input operation: a block of two halfwords containing 3 End of Medium characters. \f Stopped: If the original status word does not show 'end of document', the operation is repeated (see below). Process does not exist: The corresponding area process is created. If the creation fails, it is a hard error. Otherwise, the operation is repeated. Rejected: The area process is reserved for exclusive access. If the reserva- tion fails, it is a hard error. Otherwise the operation is repeated (see below). T_y_p_e_w_r_i_t_e_r_ Intervention: Ignored. Timer after input operation: Igrored. Stopped: The remaining part of the block is output (see below). P_a_p_e_r_ _T_a_p_e_ _R_e_a_d_e_r_,_ _C_a_r_d_ _R_e_a_d_e_r_ Parity error: Ignored. End of document: If some characters were input, the bit is ignored. Otherwise the empty block is replaced by a block of two halfwords containing 3 End of Medi- um characters. P_a_p_e_r_ _T_a_p_e_ _P_u_n_c_h_,_ _L_i_n_e_ _P_r_i_n_t_e_r_ Intervention: Ignored. End of document: A message is sent to the parent asking for stop of the job until the paper has been changed (see parent message below). Stopped: The remaining part of the block is output (see below). M_a_g_n_e_t_i_c_ _T_a_p_e_ Note that the handling of 'does not exist' and 'rejected' makes a magnetic tape very robust against operator errors. In fact, the operator may unload a magnetic tape at any moment and later mount\f it on another station without harming the job which used the tape. Intervention, load point, write-enable, and high density: Ignored Parity error and word defect: The stopped bit is ignored in this case. An input operation is re- peated up to 5 times (see below), but if the parity error persists, the error is a hard one. An output operation is repeated up to 5 times with erasure of 6 inches of tape the first time, 12 the second, and so on. If the parity error per- sists, the error is a hard one. During erasure and positioning only parity error, timer, and technical- ly impossible bits cause a hard error. Tape mark: (Ignored after a sense or move ope- ration.) The position error bit, word defect bit, and parity error bit are ignored when the tape mark bit is set. If the tapemark occurs after an input operation the block is replaced by a block of two half- words containing 3 End of Medium characters. Stopped: If the write-enable bit is 1, the output is repeated (see below). Otherwise, a parent message is sent asking for stop of the job until the ring has been mounted. The error action continues as if the operation had been rejected. Does not exist: This bit is ignored after a sense operation or a move operation. In other cases, a message is sent to the parent asking for stop of the job until the tape has been mounted (see parent message below). Next, the tape is reserved for exclusive access and if this fails, the pa- rent message is sent again. Thirdly the tape is positioned according to\f file and block count, and the ope- ration is repeated as explained be- low. Rejected: Handled as 'does not exist', except that the parent message is not sent initially. T_ I_n_t_e_r_n_a_l_ _P_r_o_c_e_s_s_ End of document after an If a non-empty block was input, the &_ input operation: bit is ignored. Otherwise, the emp- ty block is replaced by a block of two halfwords containing three End of Medium characters. Stopped: If the original logical status word does not show 'End of document' the remaining part of the block is output (see below). T_ O_u_t_p_u_t_ _R_e_m_a_i_n_i_n_g_ The remaining part of a block is output as described under repeat &_ operation. T_ R_e_p_e_a_t_ _O_p_e_r_a_t_i_o_n_ An operation is repeated in 4 steps: 1) If the document is a magnetic tape, it is positioned in front of the latest block &_ which was succesfully transferred and then the tape is upspaced one block (this is a safe method when rewriting a block). 2) The operation (or the remaining part of an output transfer) is star- ted again. 3) All other operations in the zone are waited for (but not checked), and then started again. 4) The first operation is waited for and checked again. Only the last check involved in a series of repetitions may cause a call of the block procedure. T_ P_a_r_e_n_t_ _M_e_s_s_a_g_e_ The parent (the operating system for your job) may either handle &_ a message according to its own rules, or it may pass the request on to the operator. The job may ask the parent to stop the job temporarily until the operation has been performed. The exact rules depend on the operating system in question. \f T_ 5.3.3 T_h_e_ _B_l_o_c_k_ _P_r_o_c_e_d_u_r_e_ _a_n_d_ _t_h_e_ _G_i_v_e_u_p_ _M_a_s_k_ If the standard error actions described in Section 5.3.2 are sufficient, the giveup mask 0 should be used in the call of OPEN &_ and STDERROR should be used as block procedure. This will usually be sufficient with formatted READ/WRITE. Formatted READ will stop on end of medium and signal this through the external variable READERR (see Section 5.4.5). The standard error action for a given kind of error may be sup- pressed by calling OPEN with a giveup mask containing a 1 in the bitposition connected to the relevant error situation. The procedure for each completed block transfer proceeds in the following steps: 1. Perform standard error actions for all bits in the logical status word, which are not suppressed by the giveup mask. This may include repetition of the operation, in which case the procedure starts with 1. again. 2. Call the block procedure if either (a) one of the standard error actions has terminated with a hard error, or (b) if an error corresponding to one of the bits in the giveup mask has occured. The block procedure is called as follows: CALL BLOCKPROC(z,s,b) z (call value, zone). The record of z is the entire share available for the transfer. s (call value, integer). The logical status word after the transfer. b (call and return value, integer). The number of halfwords transferred. If the block procedure is called because of a hard error, the last bit of the status word is 1. If the call is caused by a bit in the giveup mask, the bit is 0. T_ P_u_r_p_o_s_e_ _a_n_d_ _R_e_t_u_r_n_ In the block procedure, you can do anything to the zone by means of the primitive zone procedures (see Ref. 2) and the high level &_ i/o-zone procedures (in the latter case you must be prepared for a recursive call of the block procedure). \f You signal the result of the checking back to the high level zone procedure by means of the final block length, b. The value of b has no effect when an output operation is checked, but after an input operation you may signal a larger or a shorter block or even an empty block (b = 0). However, the value of b at return must correspond to a block which is inside the shared area speci- fied by the value of used share at return. Otherwise, the run is terminated with an index alarm. Further details may be found in Ref. 2. 5.3.4 S_u_b_r_o_u_t_i_n_e_ _S_T_D_E_R_R_O_R_ Terminates the run with an error message specifying an error condition on a peripheral device. CALL STDERROR(z, s, b) z (call value, zone). Specifies the name of the document. s (call value, integer). The logical status word after a device transfer. b (call value, integer). The number of halfwords transferred. The run is terminated with the alarm message: giveup<value of b> ... called from ... The file processor prints the logical status word 's' after the alarm message from the fortran program. 5.4 READ/WRITE statements 5.4.1 I_n_t_r_o_d_u_c_t_i_o_n_ The READ/WRITE statements are used for transmission of data be- tween the core store and the external media. The transmission may be on character level with format controlled READ/WRITE or it may be a transmission of binary values without format control. 5.4.2 R_E_A_D_/_W_R_I_T_E_ _w_i_t_h_ _f_o_r_m_a_t_ _c_o_n_t_r_o_l_ The formatted READ/WRITE statement has the form \f READ 1 (<logical unit>,<format label>) <data list> WRITE 0 <zone name> <logical unit>::= <zone array name> (<expression>) <unit number> <unit number>::= <expression> <implied do list> UU*DD <data list>::= <simple data list> DD1UU 3 <implied do list>::= (<data list>,<integer name>= <expression> ) 2 * <simple data list>::= <simple data elements> 1 <expression> <simple data elements>::= <array name> <zone name> The READ/WRITE statement specifies a. The operation to take place (read or write). b. The zone (maybe specified by means of a unit number)(to which a document must be connected) to be involved in the input/out- put operation. c. A controlling format, which contains a list of format elements each describing the picture of an external field and a pos- sible conversion to take place between the external and the internal representation (or vice versa) of a data element. d. A list of data elements to be transferred to or from the docu- ment Depending on their kind the data elements are treated according to the following basic rules: simple variables: A value is transmitted to or from the variable. subscripted variable: The subscript value(s) are evalua-\f ted and a value is transmitted to/ from the determined array element. array: Values are transmitted to or from all array elements column by column. Values are transmitted to or from the whole zone record. expression or constant: With WRITE the value of the expres- sion or the constant is transmitted as a simple variable. With READ the operation is meaningless. A value is read but lost internally. I_m_p_l_i_e_d_ _D_O_ A list of i/o elements may be controlled by an implied DO loop. The interpretation of the control parameters in the implied DO loop is quite analogous with that of the normal DO loop (see Sec- tion 4.4). For each value of the control variable the controlled i/o list is processed according to the rules described in the re- maining part of the paragraph. An implied DO list is considered a basic element in an i/o list and may again be controlled by another implied do construction. E_x_a_m_p_l_e_ _5_._4_._1_ (x(2,j), (a(i,j), b(i), i = 1,7), c(j), j = 1,3) is analogous to the following DO loop: do 20 j = 1, 3 transfer to x(2, j) do 10 i = 1, 7 transfer to a(i, j) 10 transfer to b(i) 20 transfer to c(j) Note that all the parameters in a <simple data list> are evalua- ted before any data are transferred to or from the data elements, so that the call: read (unit,10) n, A(n) \f will mean: i = n n = number A (i) = number while the call: read (unit, 10) n, (A (n), i = 1,1) will mean: n = number A (n) = number 5.4.3 T_h_e_ _F_O_R_M_A_T_ _S_t_a_t_e_m_e_n_t_ Form: FORMAT (<format list>) FORMATO 1 * <integer> <repeatable format element> <format list>::= 0 <non-repeatable format element> 1 <simple format element> <repeatable format element>::= <format group> <format group>::= (<format list>) <simple format element>::= B <integer>.<integer> DD1UU I <integer> .<integer> DD0UU F <integer>.<integer> E <integer>.<integer> D <integer>.<integer> A <integer> L <integer> X \f <non-repeatable format element>::= <integer> H <symbols> '<symbols>' <integer> P / The G-conversion is not implemented. R_u_l_e_s_ 1. The comma between format elements may be replaced by a / (slash), which will work as a change of line (see Section 5.4.5). 2. A format statement must be labelled. The label is called a format label. 3. The <integer> in front of <repeatable format element> is called the repeat-factor. If the <integer> is omitted it is the same as the repeat-factor = 1. 4. A comma after a P-format-element is not needed. O_p_e_n_ _F_o_r_m_a_t_s_ Formats declared by the word FORMATO are called open formats. They differ from the usual (closed) formats in two situations: (1) When a READ/WRITE statement is terminated, a line change will take place if the format is closed, but not with an open format. (2) When the terminal right parenthesis is passed during the for- mat interpretation, a closed format will effect a line change, but an open format will not. See Section 5.4.5 for further de- scription of the execution of READ/WRITE statements. See Ex. 5.4.10 about open format. 5.4.4 D_e_t_a_i_l_s_ _a_b_o_u_t_ _t_h_e_ _F_o_r_m_a_t_ _E_l_e_m_e_n_t_s_ 5.4.4.1 E_-_C_o_n_v_e_r_s_i_o_n_ Form: E <field length>.<fraction length> The E conversion may be used with real values. \f I_n_p_u_t_ An external field of the specified length is read and converted to a real value. The external field must have the form: D 1 <integer> <integer> E <real> <signed integer> 0 The fraction length defines the number of digits behind an impli- cit decimal point. If an explicit decimal point is found this overrules the implicit point defined by the format. In the following examples b denotes a blank position. E_x_a_m_p_l_e_ _5_._4_._2_ external field format internal value b1234E02 E8.4 12.34 bb1234+5 E8.0 123400000.0 b1.23E04 E8.3 12300.0 1.23D+4b E8.3 1.23 * 10 ** 40 12345678 E8.3 12345.678 O_u_t_p_u_t_ The external field produced will be of the form: 1 - <digit>.<fraction part><exponent> 0 <exponent> ::= E <sign><digit><digit> E <digit><digit><digit> - The number of digits in the fraction part is determined by the fraction length of the specified format. The specified field length includes the positions occupied by the exponent. If the value cannot be accomodated by the format specified this is indicated by printing an asterisk in the first position followed by as many digits as possible discarding the leftmost digits. \f E_x_a_m_p_l_e_ _5_._4_._3_ internal value format external field 1234.567 E10.3 b0.123E+04 -1234.567 E10.3 -0.123E+04 1.234*10**107 E10.3 b0.123+108 1.234*10**(-107) E10.3 b0.123-106 5.4.4.2 F_-_C_o_n_v_e_r_s_i_o_n_ Form: F <field length>.<fraction length> The F-conversion may be used with real values. I_n_p_u_t_ An external field of the specified length is read and converted to a real value. The external field must be as described under the E-conversion. E_x_a_m_p_l_e_ _5_._4_._4_ external field format internal value 1234567 F7.3 1234.567 bbbbb67 F7.4 0.0067 12.3456 F7.3 12.3456 123bbbb F7.2 12300.00 O_u_t_p_u_t_ The internal value is converted to an external value and rounded according to the specified fraction length and total field length. If the value requires more positions than provided by the format an alarm takes place as follows: the number is printed with with E-format thus supplying the approximate size. The fractional part of the alarm print contains an asterisk followed by some irrele- vant digits. \f E_x_a_m_p_l_e_ _5_._4_._5_ internal value format external field 123.45432 f8.3 b123.454 123.45432 f8.2 bb123.45 123.45432 f8.1 bbb123.5 123.45432 f7.5 *54E+03 5.4.4.3 D_-_C_o_n_v_e_r_s_i_o_n_ Form: D <field length>.<fraction length> The D conversion may be used with double precision values. I_n_p_u_t_ An external field of the specified length is read and converted to a double precision value. The external field must have a form as described for E-conversion. O_u_t_p_u_t_ The external field corresponds to that of an E-field except that the maximum number of digits in the basic constant is 19. 5.4.4.4 A_-_C_o_n_v_e_r_s_i_o_n_ Form: A <integer> The A-conversion may be used with type integer, long, real and complex. On input external characters are converted to internal 8-bit ISO codes. The codes are packed left-adjusted, 3 per word filling with SPACE. On output each 8-bit group is considered an ISO character code and converted to an external character. If the number of characters specified exceeds the capacity of the variable, the last characters are lost at input and replaced by SPACE at output. Note that NUL-characters do not count, that is: NUL-characters are ignored at input and are never output by write. 5.4.4.5 I_-_C_o_n_v_e_r_s_i_o_n_ Form: 1 I <field length> .<point position> 0 \f The I-conversion may be used with integer or long values. I_n_p_u_t_ An external field of the specified length is read and converted to an integer value. A point position specified with input has no effect. The external input field may not contain a decimal point. O_u_t_p_u_t_ The integral internal value is converted to an external integer field adding leading spaces if necessary. If the value is nega- tive a minus sign is printed in front of the first digit. If the point position is specified a decimal point is printed in front of the 'point position' rightmost digits. If the value cannot be accomodated by the specified format this is indicated by an as- terisk followed by the last digits of the number. 5.4.4.6 B_-_C_o_n_v_e_r_s_i_o_n_ Form: B <field length>.<radix power> The B-conversion may be used with type integer, long, real and complex. I_n_p_u_t_ An external field of the specified length is read and interpreted as an integer with the radix 2** <radix power>. The radix power may take the values 1, 2, 3, or 4 only. O_u_t_p_u_t_ The internal value is converted to an external integer each digit occupying <radix power> bits internally. E_x_a_m_p_l_e_ _5_._4_._6_ internal bit pattern format external field 000 001 010 011 100 101 110 111 B12.2 bb1103211313 B8.3 b1234567 B6.4 b53977 \f 5.4.4.7 L_-_C_o_n_v_e_r_s_i_o_n_ Form: L <field length> The L-conversion may be used with logical values. I_n_p_u_t_ An external field of the specified length is read and converted to a logical value. The external field must have the form * F * <spaces> <character> 0 T 0 T will result in the value .true. and F in the value .false. O_u_t_p_u_t_ If the logical value is .true. a T will be output, F otherwise. 5.4.4.8 S_c_a_l_i_n_g_ _F_a_c_t_o_r_ A scaling factor may be imposed on reals converted with E, F and D conversions. The prefix <10-exponent> P will cause that external values are equal to their corresponding internal values multiplied by 10 raised to the integer given. With E- and D-conversions and WRITE, the fraction part of the external number is multiplied by the scaling factor and the exponent part is reduced correspondingly. The scaling factor is deleted at the termination of the actual READ/WRITE statement. If an exponent part is explicitly present in an input field the scaling factor is ignored during the conversion of that field. 5.4.4.9 S_p_a_c_e_s_ _a_n_d_ _T_e_x_t_ The element X has no corresponding internal value. At input a single external character is skipped. At output a single SPACE is printed. \f Text elements, which may be used for output only may be specified in two ways: <length of textstring> H <textstring> or '<text string not containing '>' 5.4.5 E_x_e_c_u_t_i_o_n_ _o_f_ _F_o_r_m_a_t_t_e_d_ _R_E_A_D_/_W_R_I_T_E_ The execution of a formatted READ/WRITE is controlled by the i/o list and the format as follows: 1. The format is scanned, and each format element is inspected. 2. Whenever a repeatfactor occurs, the succeeding repeatable format element is repeated the specified number of times. In case of a format group, the whole group is repeated the specified number of times. 3. Whenever the current format element requires a value to be converted, an element from the i/o list is processed. If the i/o list already was exhausted, the execution of the formatted READ/WRITE is terminated. 4. In case the i/o list is not exhausted when the terminating parenthesis is met, the interpretation of the format is restarted. The restart of a format takes place from: a. The beginning of the format, in case the format contains no format groups, b. From the last non-nested format group (i.e. the last format group at the outermost level), including a possible repeat factor, in case the format contains format groups. The execution of a formatted READ/WRITE is terminated when: a. the current format element requires an element from the i/o list, and the i/o list is exhausted, or \f b. the terminating right parenthesis is met and the i/o list is exhausted, or c. the terminating right parenthesis is met, and no values have been converted since the last restart of the format (or since the initial start), whichever occurs first. The following examples may clarify the restart-point of a format: 10 format (<anything><repeatfactor> (<anything>) <anything not containing ()>) 20 format (<anything not containing ()>) The arrows show where the format scan will be restarted. See also example 5.4.7. 5.4.5.1 L_i_n_e_ _C_h_a_n_g_e_ Record change (in RC FORTRAN: line change) is controlled by the format. The line change action is envoked when: a. A / (slash) is encountered in the format b. A c_l_o_s_e_d_ format is restarted c. Interpretation of a c_l_o_s_e_d_ format is terminated 5.4.5.1.1 L_i_n_e_ _C_h_a_n_g_e_ _i_n_ _R_E_A_D_. By READ the line change action means that all characters up to and including the first occurring NL-character are skipped. 5.4.5.1.2 L_i_n_e_ _C_h_a_n_g_e_ _i_n_ _W_R_I_T_E_. By WRITE there are two different line change modes, depending on the zone: 1. If the zone is connected to a printer-like device (e.g. a terminal or a printer etc.) the line change action is actually delayed until the f_i_r_s_t_ character a_f_t_e_r_ the line change. This character is used as control character for vertical spacing, i.e. it is replaced as follows: \f Vertical spacing Converted Character before printing character(s) 0 two lines NL, NL 1 to first line FF of next page + no advance CR Anything else one line NL Notice: The 'no advance' facility will n_o_t_ work on all output devices. 2. If the zone is connected to a non-printer-like device (e.g. a disc file etc.) the line change action is carried out imme- diately. The line change action consists of output of a NL character. The discrimination between the two line change modes is con- trolled by means of the 'line _change _mode' in the zone descriptor: The first bit (i.e. 1 .shift. 23) means: 0: printer-like device 1: non-printer-like device The last bit (i.e. 1 .shift. 0) means: 0: line change action is pending (i.e. a_f_t_e_r_ FORMAT) 1: no pending line change action (i.e. a_f_t_e_r_ FORMATO) When a zone has been declared, the 'line change mode' is zero, i.e. printer-like device with pending line change action. The standard zones IN and OUT both have the 'line change mode' set to zero, when the program is started. \f The following subroutine will set the 'line change mode' to n_o_n_-_ p_r_i_n_t_e_r_-_l_i_k_e_: SUBROUTINE NONPRINT(Z) ZONE Z INTEGER ZONEDESCR(20) CALL GETZONE6(Z, ZONEDESCR) ZONEDESCR(11) = ZONEDESCR(11) .OR. 1 .SHIFT. 23 CALL SETZONE6(Z, ZONEDESCR) END The following subroutine will set the 'line change mode' to p_r_i_n_- t_e_r_-_l_i_k_e_: SUBROUTINE SETPRINT(Z) ZONE Z INTEGER ZONEDESCR(20) CALL GETZONE6(Z, ZONEDESCR) ZONEDESCR(11) = ZONEDESCR (11) .SHIFT. 1 .SHIFT. (-1) CALL SETZONE6 (Z, ZONEDESCR) END (details about the procedures GET/SETZONE6 may be found in the ALGOL manual, see ref. 2). 5.4.5.2 R_E_A_D_/_W_R_I_T_E_ _E_r_r_o_r_s_. Logical READ/WRITE errors occur if the type of a data element conflicts with the conversion specified by the format, e.g. a logical variable to be converted by an E-version. At READ operations an error also occurs if the length of an input line is shorter than specified by the controlling format. The following table shows the result of combining the conversion codes from the format with data elements of different types. \f T_ elem. type integer long real double pr. logical conv. code I X X (X) F F E, F F (X) X F F D F F F X F L F F F F X A X X X F F B X X X F F F: illegal X: legal &_ (X): legal but result is strange T_ 5.4.5.3 T_r_e_a_t_m_e_n_t_ _o_f_ _W_R_I_T_E_ _E_r_r_o_r_s_. With WRITE the illegal combinations are indicated by filling the external field with asterisks. 5.4.5.4 T_r_e_a_t_m_e_n_t_ _o_f_ _R_E_A_D_ _E_r_r_o_r_s_,_ _S_t_a_n_d_a_r_d_ _V_a_r_i_a_b_l_e_ _R_E_A_D_E_R_R_. After the execution of a formatted READ statement information about the result is available from the standard integer variable READERR. &_ The variable contains the ISO-values of the last processed character and of a possible erroneous character. READERR has the following values: (1) if an error occured: error char .shift. 8 + last char (2) if no error: last char If more than one error occurs within a READ statement, the first is indicated in READERR. After a line change, error synchronisa- tion is performed as follows: The format is scanned without reading any input text until a line change is required by the format. Elements from the i/o list are taken according to the scanned format but are left unchanged. Reading then proceeds from the current position within the for- mat, the i/o list and the input text. If an i/o list element is involved in a conversion error the element is left unchanged. Note, however, that elements read with A-conversion will be filled with spaces. \f F_ E_x_a_m_p_l_e_ _5_._4_._7_. I_n_t_e_g_e_r_ _S_t_a_n_d_a_r_d_ _V_a_r_i_a_b_l_e_ _R_E_A_D_E_R_R_. The program will read a collection of v inserted values to the array elements a(1), a(2) ... a(v). These values are sorted in ascending order and finally the p'th through q'th lowest af the v values are written on current out. This process is repeated until the input file is exhausted. In case of error during input the erroneous character and the last character read is written on current out. program simplesort real a(500) integer p, q, v 10 read(5,1000) p, q, v if (inerror(0)) 20,100,99 20 read(5,1010) (a(i),i=1,v) if (inerror(2) .ge. 0) goto 100 do 50 i=1,v j = i 30 index = j ; small = a(index) do 40 j=j+1,v 40 if (small .gt. a(j)) goto 30 a(index) = a(i) 50 a(i) = small write(6,2000) (a(i),i=p,q) goto 10 1000 format(3i5) 1010 format(7f10.1) 2000 format(//,4(3x, f10.1)) 99 call inerror(1) 100 end function inerror(number) external readerr integer readerr, errorchar errorchar = readerr .shift. (-8) inerror = -1 if (errorchar .eq. 0) return inerror = errorchar if (errorchar .eq. 25) inerror = 0 if (number .eq. 0) return write(6,2000) number, errorchar, readerr .and. 4bff 2000 format(/,' ***readerror in situation ', i3, 1 /,' errorchar value: ', i3, 2 /,' last char value: ', i3) end \f 5.4.6 R_E_A_D_/_W_R_I_T_E_ _w_i_t_h_o_u_t_ _F_o_r_m_a_t_ _C_o_n_t_r_o_l_ An unformatted READ/WRITE statement has the form READ 1 (<logical unit>) <data list> WRITE 0 Data are transferred between external media and data elements in core store without conversion. E_x_a_m_p_l_e_ _5_._4_._8_. U_n_f_o_r_m_a_t_t_e_d_ _R_E_A_D_ zone zo(256, 2, stderror) integer i1, ia(10) real a, b(4) - read(zo) i1, (ia(j), i = 3, 6), a, b The following words are transferred: word 1 i1 words 2-5 ia(3), ... ia(6) words 6, 7 a words 8-15 b(1), ... b(4) \f E_x_a_m_p_l_e_ _5_._4_._9_. R_e_c_o_r_d_ _I_n_p_u_t_ _w_i_t_h_ _U_n_f_o_r_m_a_t_t_e_d_ _R_E_A_D_ A file consists of records with the following layout: word 1 item no 2 number of transactions, N 3 price of item 4 no of items on store 5 - One subrecord per transaction (1) Salesman no (2) no of items sold (3) customer no (4) total This file may be read like READ(stfile) itemno, notrans, price, 1onstore, (salem(j), sold(j), cost(j), tot(j), j = 1, notrans) do 100 j = 1, notrans if (sold(j) .gt. 50) write(out,20) salem(j), cost(j), tot(j) altot = altot + tot(j) etc. E_x_a_m_p_l_e_ _5_._4_._1_0_. R_e_a_d_i_n_g_ _a_ _P_a_p_e_r_ _T_a_p_e_ _f_r_o_m_ _t_h_e_ _T_a_p_e_ _R_e_a_d_e_r_. Usually the paper tape reader of an RC 4000/6000/8000 installation is named 'reader', and a typical piece of program may look like long rname(2) zone z(50, 2, stderror) rname(1) = 'reader' rname(2) = 0 - call open(z, 2.shift.12 + 10, rname(1), 0) - read (z, ...) call close (z, .true.) Note that (1) document names must be terminated by a NUL-character, (2) names exceeding 5 characters are stored in a long array, and the first element of this array is given as parameter to OPEN. \f T_ E_x_a_m_p_l_e_ _5_._4_._1_1_. S_y_n_t_a_x_ _C_h_e_c_k_i_n_g_ _w_i_t_h_ _O_p_e_n_ _F_o_r_m_a_t_. READ may be used for partly checking of input records of various layouts. Suppose that three types of input records are defined. &_ The format corresponding to the types are: T_ type format 1 (i2, 2x, i6, 1x, i9, 1x, i4) 2 (i2, 2x, i6, 2x, 10a6) &_ 3 (i2, 2x, i6, 4x, i6, 1x, i9) T_ The input program may then look like: 100 formato (i2, 2x, i6) 111 format(1x, i9, 1x, i4) 112 format(2x, 10a6) 113 format(4x, i6, 1x, i9) integer readerr; external readerr - read(zon, 100) rectype, partnumber c go to write error message etc. if(readerr .gt. 255) goto 9991 c check value of record type and branch c to read remaining record goto (9992, 10, 20, 30, 9992), rectype - 10 read(zon, 111) amount, supplier c go to error procedure if read error if(readerr .gt. 255) goto 9993 &_ etc. T_ 5.5 Record Handling 5.5.1 The input/output system of RC FORTRAN contains a set of proce- dures for reading and writing on record level. For this purpose a ZONE RECORD is introduced as the part of a zone buffer currently &_ available to the user. The definition of the current record may be changed by the record input/output procedures. Thus data may be transferred blockwise between the document and the core store but communicated to the user as a sequence of zone records. The zone name may be used in two different ways: (1) as the name of a zone and (2) as the name of the zone record, considered as a real array with one dimension. E.g., a new record may be input from a\f T_ zone by a statement like &_ call inrec(z, recordlength) and the elements of the zone record may be used as operands like this: x = y + z(2) The rules for use of a zone record and elements hereof in execu- teable statements are exactly as those for a one-dimensional real array. A record element of a subscripted zone is referred with two sub- scripts, e.g. za (2,7) where the first subscripts selects the zone from the zone array, while the second subscript selects the element from the current zone record of that zone. The example above thus refers to the 7th element of the 2nd zone of the zone array. The following sections contain detailed descriptions of the re- cord input/output procedures INREC, OUTREC and SWOPREC, and of the procedures SETPOSITION and GETPOSITION used for positioning of documents. RC FORTRAN handles other record procedures, like INVAR/OUTVAR. For further details, see the ALGOL manual (ref. 2). The index-sequential system may also be used from RC FORTRAN, see ref. 9. T_ 5.5.2 I_n_t_e_g_e_r_ _F_u_n_c_t_i_o_n_ _I_N_R_E_C_ Gets a sequence of doublewords (elements) from a document and makes them available as a zone record. The document may be scanned sequentially by means of INREC. CALL INREC(z, length) inrec (return value, integer). The number of elements left in the present block for further calls of inrec. z (call and return value, zone). The name of the record. Determines further the document, the buffering, and the position of the document. \f length (call value, integer or real). The number of elements in the new record. Length must be >_ 0. Z_o_n_e_ _S_t_a_t_e_ The zone state must be open and ready for INREC, i.e. the pre- vious call of record handling procedure must be either OPEN, SETPOSITION, or INREC. When using magnetic tape SETPOSITION must follow OPEN. To make sense, the document should be an internal process, a backing storage area, a typewriter, a paper tape reader, a card reader, or a magnetic tape. B_l_o_c_k_i_n_g_ INREC may be thought of as transferring the elements just after the current logical position of the document and changing the logical position to after the last element of the record. How- ever, all elements of the record are taken from the same block, so if the length exceeds the remains of the current block, the block is changed. Then the record becomes the first elements of the new block, but if this still cannot hold the record the run is terminated (empty blocks are completely disregarded). Records of length 0 need a special explanation. If not even a single element is left in the block, the block is changed and the logical position points to just before the first element of the new block. Note that inrec changes the blocks in such a way that a portion at the end of a block may be skipped. So be careful to read a backing storage area with the same share length as that with which it was written, otherwise wrong portions might be skipped at reading. Note furthermore the special considerations about variable length records on backing storage mentioned in Section 5.5.3 on OUTREC. 5.5.3 I_n_t_e_g_e_r_ _F_u_n_c_t_i_o_n_ _O_U_T_R_E_C_ Creates a zone record which later will be transferred to a docu- ment as a sequence of doublewords (elements). The content of the record is initially undefined but the user is supposed to assign values to the record variables. The document may be filled sequentially by means of OUTREC. CALL OUTREC(z,length) outrec (return value, integer). The number of elements avail- able for further calls of OUTREC before change of block takes place. \f z (call and return value, zone). The name of the record. Determines further the document, the buffering, and the position of the document. length (call value, integer or real). The number of elements in the new record. Length must be >_ 0. Z_o_n_e_ _S_t_a_t_e_ The zone z must be open and ready for OUTREC, i.e. the previous call of a record handling procedure must be either OPEN, SETPOSI- TION, or OUTREC. When using magnetic tape SETPOSITION must follow OPEN. To make sense, the document should be an internal process, a backing storage area, a typewriter, a line printer, a punch, a plotter, or a magnetic tape. B_l_o_c_k_i_n_g_ OUTREC may be thought of as transferring the record to the ele- ments just after the current logical position of the document and moving the logical pointer to just after the last element of the record. The user is supposed to store information in the record before OUTREC is called again. As the output is blocked, the ac- tual transfer of the elements to the document is delayed until the block is changed or until CLOSE or SETPOSITION is called. All elements of the record are put into the same block, so if the block cannot hold a record of the length demanded, the block is changed in this way: 1. Documents with fixed block length (backing storage): The remaining elements of the share are filled with binary zeroes, and the total share is output as one block. 2. Documents with variable block length (all others): Only the part of the share actually used for records is output as a block. The transfer is checked and the record becomes the first elements of the next share, but if the record still is too long, the run is terminated. A record length of 0 is handled as for INREC. The first rule above requires special attention when variable length records are stored on backing storage. The input administration must be prepared to skip possible binary zeroes. The following piece of program shows one way of doing this. The\f record length is supposed to be stored in the first word of each record. E_x_a_m_p_l_e_ _5_._5_._1_ integer remaining, length, rlng zone z (...) equivalence (length, z(1)) - 50 remaining = inrec (z, 1) rlng= length c save record length before next call of inrec if (rlng) 100, 100, 200 100 call inrec (z, remaining) goto 50 200 call inrec(z, length - 1) 5.5.4 I_n_t_e_g_e_r_ _F_u_n_c_t_i_o_n_ _S_W_O_P_R_E_C_ This procedure gives you direct access to a sequence of elements of a document. The elements become available as a zone record, and you may modify them directly without changing the surrounding elements of the document. This makes sense for a backing storage area, only. The procedure works as a combination of INREC and OUTREC in the sense that a sequence of elements is taken from a document and later transferred back to the same place on the document. The document may be scanned and modified sequentially by means of swoprec. CALL SWOPREC(z, length) swoprec (return value, integer). The number of elements left in the present block for further calls of swoprec. z (call and return value, zone). The name of the record. Specifies further the document, the buffering, and the position of the document. length (call value, integer or real). The number of elements in the record. Length must be >_ 0. Z_o_n_e_ _S_t_a_t_e_ The zone z must be open and ready for SWOPREC, i.e. the previous call of record handling procedure must be either OPEN, SETPOSITI- ON, or SWOPREC. The document must be a backing storage area. \f T_ B_l_o_c_k_i_n_g_ SWOPREC may be thought of as transferring the elements just after the current logical pointer of the document and moving the logi- &_ cal pointer to the last element of the record. As the records are blocked, the actual transfer back to the device is delayed until the block is full or until CLOSE or SETPOSITION is called. All elements of the record are taken from the same block and when the block cannot supply the record requested, the block is trans- ferred back to the document and the next block is read. The checking of all transfers is performed. If the block still cannot supply the record, the run is terminated. A record length of 0 is handled as for INREC. If the zone contains 3 shares, one is used for input, another is used for output, and the last holds the current record. This ensures maximal overlapping of computation and input-output. T_5.5.5 S_u_b_r_o_u_t_i_n_e_ _G_E_T_P_O_S_I_T_I_O_N_ Gets the block and file number corresponding to the current lo- &_ gical position of a document. CALL GETPOSITION(z,File,Block) z (call value, zone). Specifies the document, the position of the document, and the latest operation on z. File (return value, integer). Irrelevant for documents other than magnetic tape. Specifies the file number of the current logical position. Files are counted 0, 1, 2,... Block (return value, integer). Irrelevant for documents other than magnetic tape and backing storage. Specifies the block number of the current logical position. Blocks are counted 0, 1, 2,... GETPOSITION does not change the zone state and it may be called in all states of the zone. If the zone is not opened, the position will be undefined. The position is also undefined after a call of CLOSE. T_ 5.5.6 L_o_g_i_c_a_l_ _F_u_n_c_t_i_o_n_ _S_E_T_P_O_S_I_T_I_O_N_ Terminates the current use of a zone and positions the document to a given file and block on devices where this makes sense. The &_ positioning will only involve time-consuming operations on the document if this is a magnetic tape. \f CALL SETPOSITION(z,File,Block) setposi- (return value, logical). True if a magnetic tape tion positioning has been started, false otherwise. z (call and return value, zone). Specifies the document, the position of the document, and the latest operation on z. File (call value, integer). Irrelevant for documents other than magnetic tape. Specifies the file number of the wanted position. Files are counted 0, 1, 2,... File 0 will normally contain the tape volume label, file 1 is then the first file available for data. File = -1 specifies that the tape is to be unwound. Block (call value, integer). Irrelevant for documents other than magnetic tape and backing storage. Specifies the block number of the wanted position. Blocks are counted 0, 1, 2,... SETPOSITION proceeds in 3 steps: Terminate the current use, write tape mark, and start positioning. T_ T_e_r_m_i_n_a_t_e_ _C_u_r_r_e_n_t_ _U_s_e_ If the zone latest has been used for output, the used part of the last block is sent to the document. A block sent to a backing &_ storage area is not filled with zeroes, contrary to OUTREC. If the zone latest has been used for character output, the termina- tion may involve output of one or two NUL-characters in order to fill the last word of the buffer. Next, all the transfers invol- ving z are completed, the input transfers are just waited for, and the output transfers and other operations are checked. The physical position of a magnetic tape used for input is sh-1 blocks ahead of the logical position where sh is the number of shares. If some of these sh-1 blocks are tape marks, the posi- tioning strategy is affected, as explained below. T_ W_r_i_t_e_ _T_a_p_e_ _M_a_r_k_ If the document is a magnetic tape used latest for output, a tape mark is written. The document is then in a position after this &_ tape mark, which influences the positioning strategy (see below). T_ S_t_a_r_t_ _P_o_s_i_t_i_o_n_i_n_g_ SETPOSITION assigns the value of Block to the zone descriptor variable "segment count" and returns then for all devices other &_ than magnetic tape. If the document does not exist or if the job is not a user of the device, SETPOSITION sends a parent message asking for stop of the job until the tape is ready. \f SETPOSITION starts the first operation involved in the tape positioning. The remaining operations are executed the first time the zone is used for input or output, or the first time SETPOSI- TION is called again. That may be used for simultaneous positio- ning of more tapes. The positioning is accomplished by means of the operations re- wind, backspace file, upspace file, backspace block, upspace block, and unwind tape. The positioning is complete as soon as File and Block match the monitors count of the tape position for that device. Checking against tape labels is not performed. P_o_s_i_t_i_o_n_i_n_g_ _S_t_r_a_t_e_g_y_ If the actual physical file number differs from File, the tape is first positioned to block 0 of that file. SETPOSITION chooses between rewind and backspace file in this way: if actual file number / 2 >_ File then rewind else backspace file This tends to minimise the number of tape operations. During po- sitioning within a file, SETPOSITION chooses between backspace file (rewind for File = 0) and backspace block in this way: if actual blocknumber / 2 >_ Block then backspace file else backspace block If the tape is not mounted when SETPOSITION is called, the normal mounttape action is performed before the positioning starts. Z_o_n_e_ _S_t_a_t_e_ The zone must be open when SETPOSITION is called. SETPOSITION changes the zone state so that the zone is ready for input/out- put. The logical position of a magnetic tape or a backing storage area becomes just before the first element of the block specified by File and Block. The logical position is unchanged for other de- vices. \f 5.5.7 E_Q_U_I_V_A_L_E_N_C_E_ _a_n_d_ _Z_O_N_E_S_ In RC FORTRAN equivalences involving zone record elements are allowed, i.e.: * <variable name> * EQUIVALENCE ( <array element> ) <zone record element> 2 1 The zone equivalence allows the user to connect different names and/or types to the zone record or elements hereof. R_u_l_e_s_ 1. At run time it is controlled that zone equivalenced variables are in accordance with the length of the currently defined zone record when used. If the variable is a subscripted variable the usual optional index check is also performed. 2. Normal index checking is performed on arrays equivalenced to zones independent of rule 1. 3. Zone records may not directly or indirectly be equivalenced to other zone records or to variables in COMMON. 4. All subscripts in an EQUIVALENCE statement must be integer constants. E_x_a_m_p_l_e_ _5_._5_._2_ A file contains records consisting of three parts. a 3 variables of type real. b an integer array with 6 elements. c a long array with 8 elements containing text. The declarations etc. may look like real price, sum, total integer count(6) long text(8) zone z(500,2,stderror) equivalence (z(1),price),(z(2),sum) equivalence (z(3),total),(z(4),count(1)),(z(7),text(1)) Now, after having called INREC the user may refer to the different parts of the zone record by the names, e.g., if (price .gt. lim) write(out, 100) price,text(2) \f E_x_a_m_p_l_e_ _5_._5_._3_ Merging of two tape files into a third file. The records are 10 doublewords long and the first element is the merging key. function endf(z, s, b) zone z c simulate record with a large key if (s .and. 1) 10, 20, 10 c error 10 call stderror (z,s,b) 20 b=4*10; z(1) = 1.E100 end c start of main program program merge zone in1(512,2,endf); dimension in1(2) common innames(2) long innames data innames/'doc1', 'doc2'/ zone result (512,2,stderror) logical setposition; integer inrec,outrec call open (result, 18, 'docu', 0) call setposition (result, 1, 0) do 10 i = 1,2 call open (in1(i), 18, innames(i), 1 .shift. 16) call setposition (in1(i), 1,0) 10 call inrec (in1(i), 10) 20 i=1 if (in1(2,1) - in1(1,1)) 30,40,50 30 i=2 c check for end of file 40 if (in1(2,1) .ge. 1.E100) goto 70 50 call outrec (result,10) do 60 j=1,10 60 result (j)= in1 (i,j) call inrec (in1(i),10) goto 20 70 call close (result, .true.) do 80 i=1,2 80 call close (in1(i), .true.) end \f \f «eof»