: . (f) : *: '_ſ, - : -*. ſº * , * * • . w is 'A ~ * ** \ Prº-g t * º | 1 is "..., * fºr: * -- sº *... • { Z. *S*... \ : — , * ºa — . . . . , , º – º :-. li- ? - § ºr...; * C t tr; `--waſ. E", s **: computer language connputer language & & º º HARRY L. col-MAN Armour Research Foundation, Illinois Institute of Technology formerly with Western Data Processing Center CLARENCE SMALLWOOD, Educational Consultant Western Data Processing Center Graduate School of Business Administration University of California, Los Angeles Foreword by GEORGE W. BROWN, Director Western Data Processing Center McGRAV-HILL BOOK COMPANY, INc. New York San Francisco Toronto London 1962 Sº s s Copyright (c) 1962 by the McGraw-Hill Printed in the United States Book Company, Inc. of America. All rights reserved. This book, or parts thereof, may not be reproduced in any form without permission of the publishers Library of Congress Catalog Card Number: 62–17640 III - , 4. • * ~ * - .*, **, Foreword This autoinstructional text was originally designed to solve a difficult training problem at the Western Data Processing Center. The center serves academic re- Search projects at the University of California, Los Angeles, and over seventy Other institutions of higher learning in the thirteen Western states. Most users wish to use the Fortran Programming System even though they come from many dif- ferent academic disciplines and their technical backgrounds vary markedly. The WDPC runs a Fortran Open Shop. Training problems at WDPC are similar to those met in most such open shops but exist here in exaggerated form. It would, for ex- ample, be extremely impractical to send instructors on monthly tours of seventy institutions. It is undesirable to have one person deliver the same lecture month after month, both because it is not sufficiently challenging for the instructor and be- Cause the audiences are so heterogeneous both in their interests and in their tech- nical backgrounds. Although the training problem at WDPC may be extreme, many of the relevant Circumstances have counterparts at other academic and industrial installations. This text constitutes a self-contained training system for introducing students of almost any background or professional interest to the details of Fortran coding and the art of computer programming. The System provides detailed information for students who have little or no fa– miliarity with algorithmic notation but also permits students with this familiarity to skim that information efficiently. The examples and exercises are based on commonplace experience and do not require knowledge of a specialized application. Furthermore, the system contains an indexed reference manual that is cross-refer– enced to the program for periodic, voluntary review. Upon completion of the pro- gram, students will have written their first Fortran program. This program can be keypunched and compiled and executed. A short period of advanced training on the special features of any particular system should produce Fortran programmers ready to write useful computer programs for that system. G E O R G E W . B R O WN Director Western Data Processing Center University of California, Los Angeles ^ sº sº sº tºº sm ſº m sº ºn sº Gº tº º ºs m. Preface Fortran is the name of a simple algebra-like language for programming com- puters. It is a contraction of "FORmula TRANslator" and is potentially valuable for Solving any problem that can be expressed as a series of numerical relations or algebraic formulas. Such problems are common in most professional and academic specialties. Peo- ple working in these specialties are rapidly coming to depend on computers to alle- viate the cost, the drudgery, and the often insurmountable hurdles of manual and mechanical calculations. The computer, however, has become not only a symbol of relief from tedium, but an indispensable tool for the day-to-day operation of large-scale data processing systems, for the conduct of research projects, and for the solutions of complex, practical problems. As this trend continues, it becomes essential for more and more people to acquaint themselves with computer program- mlng. Fortran is a relatively "old" computing language. The first version of it, for the IBM 704, was distributed in 1957. Since then it has been expanded and enriched and is currently available for programming many manufacturers' computers. The For- tran presented in this text is taken from IBM FORTRAN II. To avoid an unneces – sary source of potential confusion, however, some of the nonessential, optional flexibility has been omitted. What remains is fairly universal and basic. Once this basic information has been learned and applied, the additional features of a particular Fortran System can be learned with relative ease as the need arises. This book is an introduction, not only to Fortran, but also to the art of computer programming. It will be helpful to those who are planning to use the computer for the first time and to those who wish merely to acquaint themselves with the rudi- ments in Fortran programming. It should be usef , to managers and administrators who need a basic acquaintance with the concepts and terminology of computer pro- gramming and to high school and college students in mathematics, statistics, engi- neering, and business administration. Wii The teaching technique used is called autoinstructional. It is based on B. F. Skin- ner's reinforcement theory of learning—the theory of programmed learning and teaching machines. Traditional applications of this theory require students to res- pond overtly to every new unit of information by writing down a word, numbers, or phrase, the correctness of which is immediately verified in the text. Experiments, particularly by Arnold Roe at UCLA, indicate, however, that under some circum- stances, if the overt response and verification are omitted, the result is a program of instruction that is equally as effective and significantly more efficient. This mode of autoinstruction is usually called the no-response mode. It has been used exten- Sively and, we believe, successfully in the present text. The book also differs from traditional autoinstructional texts in the layout of the pages. Each page was individually designed by Elizabeth Paine, on the assumption that its unique appearance will aid those who remember information visually. The no-response sections are supplemented by exercises and program-writing tasks. The exercises were added, not as instructional, but as a means of building confidence. The tasks are larger segments of behavior, and are analysed and cor- rected upon their completion, as part of the autoinstructional technique. The tasks, the exercises, and the examples were all chosen for the generality of their content. This was also done so that students without particular background knowledge would not be aversively affected. The program has never been experimental. It was designed as a practical re- placement for eight hours of traditional instruction. Early drafts underwent infor- mal trials, which resulted in extensive revisions and retrials. We hope the end product will add a modicum of efficiency to the job of learning Fortran. We thank the following institutions and people: the Western Management Science Institute, Graduate School of Business Administration, University of California, Los Angeles, for its support, under a grant from the Ford Foundation, of the prepara- tion and reproduction of the early drafts of the program; the director and staff of the Western Data Processing Center for their guidance and assistance: Mr. Arnold Roe of the UCLA engineering department's Teaching Systems Project for consulta- tion; and the students who exposed themselves to the early drafts and provided feed- back so essential for effective revision. H A R R Y L. C. O L M A N C L A R E N C E S M A L L WOOD Wiii To the Reader This text is an autoinstructional program. It has been written and designed to provide an efficient, self-contained system for learning the basic concepts of Fortran program- mlng. The subject matter is presented in short, concise incre- ments printed inside a frame. The type of frame denotes the kind of information inside it. Essential Fact Explanation = * ſº i ſº I tº a i º tº a * . | tº . . . * tº † : tº u tº it tºº tº a i. tº i.e. i = Example, Exercise, The appearance of each frame and each page has been Directions planned to attract your attention and to enhance your re- tention of the information. | * = m = m = m = m = m = m ms m = m, m = m = m = m. m = m. There are four program-writing tasks with diagnoses. Fortran Coding Sheets, which may be removed for convenience, have been provided at the back of the book. Each concept is taught in a sequence of frames. Following each concept or group of -> related concepts are exercises with anSWerS On the pages indicated. To the Reader You may use the Index to review. It indicates pages in the program and in the Reference Manual section. Beside Reference Manual entries are page num- bers for further review in the program. There are many specialized words in the vocabulary - of programming. Most of these words are defined explicitly or by example. Others are defined implicitly by their use in contexts where their meanings should become clear. The program assumes that you have no Special background in computer programming. Therefore, proceed rapidly in those parts which seem clear, and read more carefully in other Oarts. ! Learning time has varied from two to Over ten hours. Use this autoinstructional system in the way that suits you best. * If the subject matter is easy to understand, concentrate on the Essential Facts, and skim over the Explanations and Examples. Yr If, while working the Exercises, you are confident your answer is correct, Omit verifying it. X* Review concepts at any time, using either the Index or the Table of Contents. . Xi To the Reader xii To the Reader Xk Make notes on questions that are not answered in the program. If they are not answered in subsequent Sections, seek help from a more advanced Fortran reference manual or from an experienced Fortran programmer. × If you are already familiar with the concepts covered in Part One: Introduction, start with Part Two: Program Structure. Table of Contents Foreword W Preface wii To the Reader ix Part One: INTRODUCTION Computer Programs 1 Computer Instructions 3 Flow Diagrams 6 Memory 17 Object Programs and Source Programs 20 Fortran Source Program Compilation 23 Kinds of Fortran Statements 27 Fortran Coding Sheets 29 Punched Cards 34 Exercises 39 Part Two: PROGRAM STRUCTURE A Job 43 Subroutines 44 Main Program 47 Interprogram Flow of Control 48 Exercises 53 Main Program Task 54 Diagnosis 55 Comment Statements 57 Part Three: VARIABLES AND CONSTANTS Fortran Variables 58 Exercises 63 Fortran Constants 63 Exercises 65 Sub- scripted Variables 66 DIMENSION Statements 67 Exercises 69 Common Storage 70 Exercises 73 Part Four: INPUT STATEMENTS Input Data Fields 75 Input FORMAT Description 77 Multiple Fields 80 READ Statements 82 Relations between Fields, Descriptions, and the Variable List 84 Exercises 87 Input Task and Diagnosis 89 xiii Xiw Table of COntents Part Five: ARITH METIC EXPRESSIONS Expressions 94 The Hierarchy of Operations 95 Parentheses 97 Exercises 100 Mixed Expressions 103 Exercises 105 Part Six: ARITH METIC STATEMENTS General Form 106 Incrementing 107 Accumulating 108 Defining a Variable 108 Conversion 109 Exercises 111 Part Seven: CONTROL STATEMENTS Normal Flow of Control 112 Unconditional Transfer of Control 114 Conditional Transfer of Control 115 IF-Loops 117 DO-Loops 120 Exercises 126 A Sorting Example 130 Sorting Task 139 Diagnosis 141 Part Eight: OUTPUT STATEMENTS Relation to Input 147 Output Field Specifications 148 Carriage Control 152 Relations between Fields, Specifications, and the Variable List 155 Exercises 156 Output Task 158 Diagnosis 159 Conclusion 161 Amswers to Eatercises 162 Reference Mamual 179 Imded: 195 Fortram Coding Sheets 197 s - Computer Programs e Computer Instructions Flow Diagrams e Memory e Object Programs and Source Programs o Fortran Source Program Compilation O Kinds of Fortran Statements Fortran Coding Sheets e Punched Cards e Ex- ercises Part One: INTRODUCTION F - - - - - - - - - - - - - ºn m = m ms tº gº ºn tº ºn m ſº m º ºs ºf sº º ºſ º- m A program for a computer: is like a Set Of instructions for a clerk who is running a desk i Calculator. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ºn I ºn tº gº ºn ºn tº I-1 ºn ºn tº ºn I, tº L = tº tº ºf ºl E. - - - - - - - - - - - - - - - - - - - - We can tell the calculator Clerk what We can, for instance, instruct the clerk to add all the numbers on List A, write tlıat total on a piece of blue paper, and label it Total of List A. to do with some numbers without saying what the particular numbers are. j * * * * * * * * * * * * * * * * * * * * * * * * * * = = - - - - - - - - - - - - - - - The clerk will know what to do without knowing the numbers On the list Or the purpose for adding them. 1 Computer Programs 2 One: Introduction --------Y-------------- ºn tº ºn tº ºn º ºs º ºs ºn tº an ºn tº m ºn ºn tº ºn as ºn m = m = : In fact, the same instructions to the clerk : will work for any list of numbers that we choose to call "List A. " * Computer Programs are like the set of instructions to the On one day List A may contain one set calculator Clerk. | | | L | | : of numbers, and on another day T | * another set. i r: tº tº gº ºn tº ºn tº ºn tº Lº ºn tº E ºn tº tº ºf * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * { * that there are three fairly distinct : ------------------------------------------------------- Operations involved: All three ph as e s a re in volved in Input – e. g., List A * º p g most computer programs. The instructions -> Calculation - e. g., Accumulating the total that make up a computer p r Og r a m Output - e. g., Writing the total on a piece of blue paper cause the computer to read the input data, per f Orm SO m e C a 1 cu la ti O n s , a n d º D [. | | [. L L U | [. | U. | [. U º | I [. * Naturally, the analogy between the calculator clerk and the computer has limits. We can tell the clerk to add the numbers without saying how many there are, and without saying, "Now add the next one, now the next one, etc." We must, however, instruct the computer first to add the first number, then to add the second number, then the third, etc. print the results. ‘t ----------------------------- It would be marvelous, indeed, if the raw data of a problem could simply be "fed to the computer, " and the computer could Somehow analyze the problem, arrive at the : There is no computer instruction such as "Calculate the Mean." * [. I : : : | -> : correct solution, and : To cause a computer to calculate a mean, ; t that º : we must order it to perform a large : Carry Out that solution inumber of distinct operations : to produce the desired * * * * * * * m ms m ms m = m m ms m ms m an im m ms m m ms m m mſl. F-------------------------------------------------------------- : "Simulate an Oil Refinery." : : There is no computer that can do this. : I | | [. : The computer program that would simulate an oil : : We cannot give the computer vague : º º | : refinery would be comprised of many thousand : ; instructions about what we want : | instructions related in a very complex way. : ; I : Planning and designing | aliſilliiliiliiliililiiliiliiliiliililililillº : * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - EA Computer 1S wired E Computer programs : T - . ... F L s : We cannot, for example, order the =to react to a specific,5 can be a very compli- y 7 tº it a = • e = | * | computer to "compute the statistical : = limited Set Of = cated affair. But . . . . t 1 ! 7, , ; l = º º - = significance" or to "simulate the E machine instructions E : nearly all programs L - ! 7 - - - - º . . - : g º & = º e - : : average man," without adding certain i->= in a specific, E require planning. H - - • | = s = | ; : pertinent details to the general : E prescribed way. E i ; : instructions. : FiliiliiliiliiliiliiIIIIllililillllllllllllllir * * * * * * * * * * * * * * * = m = m = m ms m ms m ms m sm m msl. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 3 Computer Instructions 4 One: Introduction Our instructions to it must ultimately be a program of these machine in- Structions. It is this fact that requires us to analyze and Organ- ize our problems and solutions to an Whe reas hum a n be in g s h a ve in tuitive capabilities, the high - speed digital computer { does mot. extent that Other E ºn tº tº gº tº gº ºn tº ºn ºf ºn tº ºn tº ſº ºn tº ºn ſº tº ſº tº tº E. E. E. E. Lºº Lº - tº ºn tº I-I º 'º - ºn ſº tº methods often do not demand. ºn m = = * * * tº tº ºn tº tº . . . . . . . . . . . . . . * . . . . . . . . . . tº . . . . . [...] E. E. tº ſº tº ºn E = tº It is not possible to give a computer a * = = * * = = = sº m ºn m ºn m ms ºn tº ºn tº I- I n = m m'. vague or general instruction like "Add any hundred numbers. " It is possible to give a computer foolish but precise (specific) instructions like " A did every other number in the first hundred s to r a ge 1 O C a ti on s in me m O ry. " V. tº sº º - º tº- tº . tº * { tº- - |- | - I- - tº - I- tº- I- tº . T The first instruction, the one the computer is not capable of acting on, is analogous to giving a child a ten-dollar bill and telling (instruct- ing or programming) him to go to the super- market and buy "food." Whereas the child may accurately deduce what we The second is analogous to foolishly adding to want from an the Original instructions, the more specific instruction to bring home from the market each second item of food of the first hundred articles he sees in the market. instruction as vague as the first One, the computer cannot because it does not have the capability of under- standing, comprehending, or interpreting, and -> therefore cannot deduce. º H - --IIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIII IIIIII IIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIlllllllllll! lº- The program me r must clearly specify, It cannot do this even though it has had years of previous experience with perfect programs. via p re c is e instructions, exactly what he wants the computer to do and the order in which it is to be do n e . : * illllllllllllllllllllllllllili IIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIHIIIIIIIllilllllllllllllllllis 5 Computer Instructions 6 One: Introduction * = - - - - - - - - - - - - - - - - - - - - - NOTE The objective of this section is to a C- quaint you with Flow Diagram m in g. {- SJIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlli {- Most beginners de S ign and plan a computer program by drawing a Flow Diagram for the program. ânimumumumumumumumumummiş -> : The emphasis will be : on the order of events in a program, not on the events themselves. We, the refore, -II advise you 700t to be -IIIIIIHIIIllilllllllllllllllllllllllllili IIIIIIIHIIIIHIIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlllllllllll: too concerned with the COntents Of the diagram boxes in the illustrations. A Flow Diagram is a graphic representation of all the sequences and alternate sequences of operations that are to be specified in a computer p r Og r a m . r: gº - - - - - - - - - - - - - - - - = * * * * * * * * * * * * * * = -s. A Flow Diagram shows the temporal and causal relation- ships between Operations and decisions in a program. .” IIIIII IIIIITIIIIIITIIIIHIIIIIIHIIIIIHIIIIII III III IIIIII IIIIIIIIIIIHIIIIITIIIIIHIIIIIHIII IIII IIIll!: In showing alternate paths in the sequence, a Flow Diagram must specify the conditions under which each and every suilliiliiliiliiliiliiliiliiliiliiliiliiliiliº alternate path could be followed. IIIIIII IIITIIIIIIITIIIHIIIIIIIIIIIITIIII IIIIIlllllllllf. IIIIHIIIIIIIIIIII IIII IIIIIIIIIHIIIIIIII IIIIII IN; gº Because Flow Diagrams are not themselves composed Of computer instructions, there are no Stringent rules for making them. You may use any notation you please. tilllllllllllllllllllllllllllllllllllllllllllir | The sequence of events is crucial. We must, for example, instruct the computer to input List A before we instruct it to add the first number On that list. When computing a mean, we must instruct the computer to accumulate the total before dividing by the number of numbers. H gilliiliiliiiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu: On the other hand, because the Flow Diagram will be used to write a computer program, it does no harm to Orient it to computer operations. {- Flow Diagrams 8 - One: Introduction EIIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: There are many conventional techniques for drawing Flow Diagram s. Their use :IIIlliiiiiiiIII.iii.III.iiiIIIIllililiiliiliiliile tº- Conventional Flow Diagrams are composed of geometrical shapes connected by arrows. Filiiliiiiiiiiiiiiiiiiiiiiiiiuliiliiliiliiliir: auiliiiniiliiliiliiliſiliiliiliilill: is recommended for the simple reason that #4 other people will be able to understand the m without learning a new set of techniques every time they look at a Flow Diagram . illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllli * :NIIII IIIIIIIIIIIIIIIIIIllilllllllllllllllllllllllllllllllllllllllllllllll): Aº Rectangles are used to indicate Operations, such as addition, subtraction, multiplication, division, and exponentiation. The shapes are called "boxes" even though they are not all rectangular. —) X = A + B Hº III IIIIIII IIIIIIIII IIIIIIIIIII III IIIIIIIIIIIII IIIIIIIIIIIIIIIIII IIIIIIIls V. :IIIIIIIIIIIIllil IIIIIIIIIIIHIIIIIIIII III III III IIII III III III III IIIII IIII IIII III III IIII III IIIII III III III III III;2. Diamonds are used to specify branching decisions. The exit YES taken depends on the value of the expression inside the box. NO l, ! Illlllllllllllllllllllllllili IIII IIIIIIIIII IIIIIIIIIII IIIIIII IIIIIIIIIIIIIIIIIIIIIIIIII IIIII Rectangles with rounded ends are used to specify input and output operations. (negative). — + (positive) --> O (Zer0) 1111111 IIII IIII III IIII III III III IIIIIIIIIHIIIIIIIIII IIII IIII III IIII IIHIII III III III IIIII IIII IIIllililili IIIliriº :IIII IIIII IIIIHIIIII IIII IIII III IIIII IIIII:11||||||||IIIIlllllllllllllllllllll IIIIIIIIHIIIIIII : w siliiliiliiliiliiliiliiliiliiliiliiliiliiiiiIII.iiiIII.iiiIII.iiiIII.iiiiniiiiiiiiiriiniiiiiiiiiiiiiiiIII.iiiiIII: Explanation {- If the result of the subtraction of B from A is negative, the minus exit is taken. If the result of the subtraction of B from A is positive, the plus exit is taken. If the result of the subtraction of B from A is zero, the Zero exit is taken. illiLLIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIHIIIHIIIIIIIIIIIIIIIllililllllis isſiliiliiliiliiliiliiliiliiliiliililiiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiu; starting and stopping points. –Gº tº- ::ſill|||||IIIIIIIIHIIIIIIIIIIIIIIIllilili IIIIIIIIllili IIIIIIIIIIIIIIIIIIINº -> tº- L 2. r g € C i r C l € S al r € Ul S € d t O l Il d l C a. t € * 9 Flow Diagrams 10 One: Introduction isliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiiniiiiiiiiiiii!: Arrows indicate the sequence in which the operations in the boxes are to be performed. They specify what is called the '''Flow Of Execution'' This is a Flow Diagram of a very simple, straightforward program. It reads (inputs) four values, computes two new values, and prints Out the two new ones. Or the "Flow Of COntrol" Illilllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll * -, ſ l S. The numbers in parentheses Opposite the boxes Correspond to the explanatory frames On the next page. siliiliiliililiiliiliililiiliiliiliiliiliiliiiIII.iiiliiliſiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii!: Inside the boxes, any notation may be used: Algebra, English imperative sentences, Boolean symbology, Proofreader's marks, Swahili, Roman numerals, or cartoons. However, because Fortran operations are algebraically oriented, you should use algebra wherever possible. Filiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliili -> P = - - - - - - - - - - - - º- ºn tº I- ºn - ſº - - - - - - tº B- E - E - * READ THESE BOXES IN NUMERICAL, ORDER L I | I : This is the starting point. : : : : : P = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m | ºn tº tº º gº tº ºn tº ºn tº tº ºt ºt tº ºn tº E - E - tº- tº tº E - tº tº tº a - Lºs - E - J I | lm jo Four numbers are read in : . and designated : : A, B, C, and D : +------------------- - L = -s tº ſº tº ºn tº I- Lºs = Gº ºn tº i FZººs E = -º ºn ºn ºn tº tº ºn tº gº ºn ºf - E - ſº tº sº tº L = M_i º ºs ºn tº me ºn ºn * #6) Z is set equal to the result : : Of the division Of : {2 \""" tº E. E. E. E. tº tº ºn tº ºs º- ºn tº - ºn tº tº sº E sº ºn ºn tº ºn ºn ºn m ms º I : A by B : : Y is set equal to the result of : | | * * * * * * * * * * = - - - - - - - - - - * = * * * * * * * * * * * * * : C divided by D, plus Z : : : ******* - - - - - - - - - - - - - - - - - - - - - - - - - - - - J r = In º ºs º-, -, -, - tº - - - - - - - - - - - - - - - - - - - Lº tº ºn tº tº tº * F = - - - - - - tº- tº tº E tº tº tº º sº ºn tº tº ºn ºn tº ºn tº gº ºn *g I | | jo Z d Y inted out : #9 This is the end of the : all are printed out. : program. : : : : : | | | ----------------------------------- i. tº E = - tº I- a-, -, ºn tº El Lº - E - tº sº ºn tº ºn ºn sº tº me tº ºn i 11 Flow Diagrams 12 One: Introduction * This is a Flow Diagram Of a subroutine called PAPER. The purpose of PAPER is to keep a tally of how many ten-five-and one- dollar bills will be needed in making change equal to "R. " (Assume the "R" is Computed in some other subroutine.) READ THESE BOXES IN NUMERICAL ORDER F - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * F - - - - - - - - m me m = m ms m ºn m m m in m m = ± = m ºn tº ºn ºn tº ---, ; (1) : ; (2) The counters, SAW B UK, : This is the starting point of : : FIN, and BUCK : : P A P E R. : : must all be started at : L | [. Z € I O . : +---------------------------------- i !----------------------------------- l m = * * * * * * * sº- ºr ºn I tº tº ºn tº ºn ºn tº a sº tº ºn tº ſº ºn ºn tº º ºn tº El ºl E tº tº ſº tº ºn E - L. * If R, the value of change still to be ºn m ms s m ms m m ms ºn sm mº ºn m = m º º ºs º ºs ºn tº ºs ºs ºn tº I- M. E - tº ºt tº º ſº ºn E - Lº tº tº E - tº sº. E = tº I- M - I -, -, - tº º ºs ºn ºn T tallied, is greater than $10.00, #6). If R is greater than $1.00, add one to BUCK, add one to SAW B UK, and and subtract 1.00 from R. Subtract 10.00 from R. Repeat this decision and Operation ºf m ºn gº ºn tº ſº º ºs ºn tº gº ºn m ºn tº º, º ºs ºn tº I-I ºn tº tº ºn tº º ſº tº E tº ºn tº ſº tº tº ſº tº ºf m = all until R is less than $1.00. r --- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --___________ - - gº ºs º-, -, -, -, -, - - - - - - tº - - - - - - - - tº sº ºn tº E - tººl ºf tº tº tº tº tº a ºn tº tº tº El tº ºn tº ºn tº ºn I- iQ As soon as R is less than $10.00, (6) When R is less than $1.00 return to the Main decide if R is greater than $5.00. Program. If it is, add one to FIN, and (The next thing to happen in the Main Program Will be to call another subroutine to compute the coins needed to make up R.) 13 FIDW Diagrams 14 One: Introduction P-------------------------------- | This is a Flow Diagram of a Main Program that : calls four subroutines. : The purpose is to compute: the number of bills and coins needed to make up change. : | al ls m = m = m = m = m = m = m = m = m = m ms m = m = = m = m = m. READ THESE BOXES IN NUMERICAL OFDER F----------------------------------- . ; (1) : : This is the starting point : : | : i. ºn tº ºn tº tº ºn tº ºn tº tº ºn E - E - E & E L E - G- ºn tº m ºn Mº tº [-º, sº ºn tº ºn * = H f2. ºn tº ºs ºn tº gº ºn tº gº tº º E = - tº tº tº tº E. E. - - - - - - - - ----. fº I will be 2.Il - dex Or C t fo H iQ The value read in for N will | - 1I] ounter tor ! : be the total number of times: : keeping track of the number of times : € Une Ill IIIl Iſle : : change has been computed. : : change shall be computed. : : : ; : I will be incremented each time i ºn as mm mm mm m s m as ºn as m = m ms as m = m ms m ms m m = n = = * * * * * : change has been computed. [. i. f CALL INPUT means that the INPUT Subroutine shall Operate at this point. CALL PAPER means that the PAPER subroutine shall operate at this point. PAPER will compute the number of bills needed to make up R. The RETURN Statement in the INPUT Subroutine will bring the flow to the exit arrow from this box. INPUT reads in a transaction and computes a value for R, the amount of change needed. The RETURN statement in PAPER will return the flow to the exit arrow from this box. º - - º . . º tº- |- - tº- º | * - t- tº º ſº - cº- º tº t_ . º tº tº- º tº º i_ t- I- - tº- - tº º º º tº- | I sº V. Flow Diagrams 16 One: Introduction (8) CALL COINS means that the COINS Sub- routine will function at this point. This is a decision box. If I is now equal to N, the program should terminate. This COINS will compute the amounts of nickels, is the "yes" exit from the decision box. pennies, dimes, etc., needed to make up R. If I does not yet equal N, the process must be repeated. Another cycle of change- making should begin. The RETURN statement in COINS will return the flow to the exit arrow from this box. (i) º:ºº:: º (9) Before the next cycle begins, I should be increased by one. OUTPUT will print out the numbers of each denomination of coin and bill needed to make up an amount of money equal to R. The first time through the cycle, I was one. The second time through, I was two. The RETURN Statement in OUTPUT will The last time through it will equal N. return the flow to the exit arrow from this box. ******************************************************** i------------------------------------------------------ ió gº gº tº ſº ºn tº tº I- tº ºn tº tº ºn tº L. E tººl tº ſº tº L. L. tº ſº. [º Lº tº ſº º + : This is the end Of the : : Program . ſº i---------------------------------- ; The three basic parts of a computer 2.I’é . OThe Input-Output Units OThe Memory Unit OThe Central Processing Unit (CPU) Memory consists of several thousand "storage locations" or "memory loca- tions." The COntents Of a storage location are called a "WOrd." The re a re a p p r Oxim a tely 32,000 storage locations in the IBM 709 and 7090. Each storage location has a numerical "address." When programs are being executed, they always refer to storage locations (and the words in them) by using m em O ry. ) this numerical address. A memory of this size is referred to as a 32K 17 Memory One: Introduction & # {- Each word is 36 binary digits—3.6 bits. Every pattern of 36 bits in a Word represents a numerical value in the binary number system. Words in memory may represent: When words are transmitted from a memory Decimal numerical Values converted to binary tººd sº :IJIIIIllil IIIII IIIIIIIII IIHIIIIIIIIIIIIHIII IIIIHIIIIIIIII IIII IIIll IIIIIHIIIIIIIIIIIIIIIIIITN, J. EIILIIIHIIIIIIIIIIII.iiiII.iiiIIIllilillº EIn fact, all Émachine instruc- =tions for the C O m put e r a re words, and may be represented as patterns of 36 : location, they are not erased in that Octal numerical Values converted to binary memory location. A replica of the pattern Of bitS is transmitted. B in a r y numbers Binary-codº alphabetic O information M a C h in e in St r u C ti O n S H Eb its . Billili III IIIIII IIIIIIIIIIIIIIHIIIII However, when a bit pattern (a word) is stored in a location, it replaces and erases the word that was in that location before it. illilillllllllllllllllllllllllllllliſillili IIIIIIIIIIIIIIHIIHIIIllilillilllllllllllllllllllllk: Words a re t ran s m i t t e d between siliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliili This transmitting of words, of the computer ' s m em O ry and Central Pro c e s sing Un it (CPU) in mic rose c on ds course, is always done in (millionths of a second). uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuulf response to machine instructions in a program. (IIII IIIII IIIII IIIHIIIIII IIIIIIIIIII IIIIIII IIITIIIIIIIIIIIIHIIIIII *. A program Of machine instructions iſiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliilillº 1S And this program of machine= instructions is itself stored= called 7 l Il t h € C O II]. D Ul t € r S IIl e II]. O r y Object Program F 19 Memory IIIIIIIIIIIII IIIIHILIII.I.I.I.IIIIIIIIIIII IIIIIIIIIII IIII IIIlliiing: A m a chine instruction is a pattern of binary digits in a computer word. *IIIHIIIIllililillilillllllllllllllllllllllllllllllllllllllllllllllll | T. r: III.iiiiiiliiliiliiliiliiliiliiliilill: Machine instructions are transmitted in sequence to the Central Processing Unit (CPU). IIIllililiiliiliiliiliiliiliiliiliiliiliiliiliiiniiniiniiiliiling The CPU is designed to react in a particular way to particular instructions. III IIIIIHIIIHIIIIIIIIIII IIIIIIIIIIII IIIIIIIIIIIIIIIIIIII IIHIIIIIII A typical machine instruction causes the CPU to "Clear" its accumulator "and add" to it the contents of the storage location specified in the instruction. gº º | | | | | | | l, -z---------------------------------------------------------- For example – the following binary machine instruction 000101000000000000000000000000010100 would cause the CPU to set its accumulator at zero and then to add to it the contents of storage location 010100. *E º Gº & Lº Gº tº ºn tº ſº I º ſº ſº I Lº tº ſº I ºn tº ºn ºf ºn tº ºn tº Is tº ºn tº ºn tº ſº tº tº tº ſº ºn tº ºn tº tº º ºn tº y * | One: Introduction 20 S. IIIIllllllllllllllllllllllllllllllllll IIIIIIIII IIIII IIIIllililllllll: = Fortunately, these days, = tº É it is no longer necessary to = A sequence of binary = write programs in binary #4- machine instructions, = machine instructions. = to periorºam gful WillIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIllililililiili IIIIIIIIII.iii.IIIliş computations, is called an Object Program Most p r of ess ion al programmers, and all amateurs, write programs in one or more of the many symbolic languages that have been developed for the purpose. Programs written in these languages are called: §III/III III III/III IIIIII IIIIJIIIIIIIHIII IIII): Source Language Programs In general, there are two levels of Source Program Language S : 1. One-to-One & :Al * tº IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIII IIIIIHIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII As so c iated with each Source Language * Languages Program is an elaborate system of computer 2. One-to- programs that can translate Source Programs many Languages into Object Programs. * tº -Illil III IIIlli III IIII IIHIIIIII IIIHIIIIIIII l N. : illlllllllllllllllllllllllllllllllllllllllllllllllllliiIIIIIIIIIIIIIIIIII IIIIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIlls Object Programs and Source Programs 22 One: Introduction 4. 2. till IIIIIII IIIII IIIIIIHIIIII IIIIIIHIII IIII IIIIIIIII IIIIHIIIII III IIIIIIIIIIIHIII III IIIIIIII III IIIHIIIIIIIII III; In a one-to-one Source Language, there is a translation from One symbol in the Source L a nguage to one machine instruction. {- º IIIllilillllllllllllllllllllllllllililili III The translation from symbols to machine instruc- tions is called "as s embly. " The translator is called the "as s emble r. " {- In a one-to-many Source Language º :4IIIllil IIIIIIIHIIIIHIIIHIIIHIIIHIIIIIHIII III IIHIIIHIIIHIII IIIIIHIII III IIIIIIIIllil IIIIII.1||||IIIIIIIIHIIIIHF: there may be many m a C h in e in St r u C ti O n S for each Statement The translation is called in the "compilation, " and the translator program is called the S Our C e L a n guage. "Compiler. " y ºf Fortran is a one-to-many Source Program Language. Statements in Fortran are compiled into Object Program machine instructions. :IITIIII IIIII IIII IIII IIHIIIIIIIIHIIII IIIIIIIHIII III III IIIHIIII Nº. s Programs Written in Fortran are called Fortran Source Programs The computational statements in For tran resemble ordinary algebra. Control and input-output statements resemble Ordinary English language imperative sentences. Storage statements resemble declarative Sentences. ;III.iiiiliiliiliiliiliiliiliiliiſſiliiiiiiiiii The transformation of a Fortran Source Program into an Object Program is called Compilation. IIIIIIIIIIIIIIIIIII IIHIIII IIIHIIIHIIIIIIIIIT- Fortram Source Program Compilation 23 24 * One: Introduction : - uniliiliiliiliiliiliulililililulilililiiliiliiliiliiliiliiliilitig Compilation is done in the computer by a program called the each statement in the Fort ran Source # Fortrain Compile r Program , and generates a sequence of machine :IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIII?IIIIIIIIIIIIIIIIIſr: The Fort ran Compiler Program analyzes F {- instructions which, when executed, will perform precisely those computations, etc., specified in the Sour c e Program . il P: Having successfully generated an Object Program, the compiler does two things with it: As the compiler analyzes each statement, it uncovers certain kinds Of errors. These are referred to as 1. A copy of the Object Program is temporarily stored on a special tape for Subsequent execution. 2. Another copy is punched into tabulating cards for storage, and for execution at later dates. Diag no stic E r r O rs :1IIIIIIIIIIIIIIIIIIIHIIIHIIIIIIIIIIII IIIIIIIIIIIHIIIIIIIIIIIIIIIIIII IIII IIIII IIIIHIIIIIIIIIIIIII IIIIIIIIIIII r: 2: & tillllllllllllllllllllllllllllllllllllllllillllllllllllllllllllllllllllllil IIIIIIIIIIIIIHIIIIIIITIIIHIIIIII III The compiler can diagnose the following kinds of errors in a Source Program : * Illegal characters * Illegal combinations of characters * Improper flow of control through the program. : IIIIIIIIIIIIIIIIHIIIIIIIIHIIIIIHIIIIIIIIIIIIIIII IIIIIIIIHIIIIHIIIIIHIIIIHIIIHIIIIHIIIII III III IIII III IIHF: grillililililuliiiiuuuuuuuuuuuuuuuliliiliiliiliiliuſz The Fortran compiler cannot diagnose A Source Program containing logical errors. It cannot deduce your an error that the compiler can diagnose will not be compiled into an Object Program. Fºllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: - intentions. It cannot compensate for even | the most obvious mistakes in specifying : computations, etc. • * 4. uniliiliiliiliiliiliiiniiiiliiliiliiliiliiliiliiliiliiliiliiliiliniliiliiliiliiliiliilin In the case of diagnosable errors, the compiler prints out the erroneous statement, and attempts to catalogue the kind of error. h gº FIIIIIII IIII III III IIIIHIII IIII IIIIII III III IIHIIII IIIHIIIIIHIIIHIIII IIII III IIII IIIIIIIIIIIl 25 Ny Fortram Source Program Compilation 26 One: Introduction For example, if your program were computing areas of circles, and you wrote 3. 7416 instead of 3. 1416 the compiler could not diagnose the error. m = m = m = m = m = m = m = m, m = m = m = m = * * * * * * * * * * * * * = * sº º tº Programs containing errors that the compiler cannot diagnose will be successfully compiled. The Object Program so compiled, however, will certainly not produce the results intended by the author of the Source Program. Therefore, it is essential that you be i. precise in writing a program, by paying close attention to even the Smallest detail. si iiiuuuuuuuuliiiniiniiiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliilini; |IIIlllllllllllllllllllllllllllllllll- A sequence of Fortran Statements Comprises a Fortran Source Program. Executable statements result in machine instructions. {- | l T. tº- 7IIIIIIIIIIIIIIIIIIIIIIIIIllillil IIIIIIIIllllllllllllllllllllllllllll FIIIIIIIIIIlliSIIIIIIIIllillllllllllllr= SJIIII.iii.IIIIIIIIIIlliiiiIIIllililllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: tº- Nonexecutable Statements tell the compiler what kind of storage require- ments will be needed and how input There are two kinds of Source and Output data are laid out. Program statements: * Executable IIIIIIIIHIIIIIIIIIIHIIIIIHIIIIIIHIIIHIIIIIIIIHIIIIIIlllllllllllllllllllllllllllllllllllllliſ. X* No nexe cutable 2] J. Kinds of Fortram Statements 28 One: Introduction agiliiiniiniiniiniiliiliniiniiiuuuuuuuuuuuuuuuin There ENonexecutable statements affect 2.I’é =the design of the Object Program. four =Executable statements affect kinds =the content. Of :IIIIIIIIIIIIIIII IIIIIIIIIIIIIIITIIIII IIHIIIIIIIIIIIIIllilllllllllll nonexecutable | l r Statements: There are four kinds Of executable Statements: KArithmetic statements **Control statements X-Input statements Storage statements Format statements Subroutine-defining *Output statements Statements O Comment statements The rules for writing these different kinds of state ments will be discussed in the next S e C ti O n . Statements in a Fortran Source Program are first written on coding sheets. º X- Note: Do not ponder the meanings * of the Fortran statements in the A typical short Main Program with Samples. a typical short subroutine looks something like the following: They are not important at this point, and will become clear as you progress through the program. -> | L |. | | | | | | | al 29 - V. Fortram Coding Sheets S}90|Sºulpoº) UEI) IQ3 19. —I I f | { I I--- | | ſ I -I —r— |-- —r- | W W I- T- I r— —r---—T-- —r-----|--——I---——I- -y I- | I f I T —T I-I-I-I-T-----T —I-– r—y I | ! { I- T- | -—— r—r F----------------—I- —r—r I W I I- I I —ſ r I- -r I— I —I---— I | } H T { I--- | —I---—T- -T——I--— —r— I ! I t r H | - | : I- -] I-, --, --, --, GNä wº-º-º-º- I---—- ——H —I- I I I- I —F I IX: Two I —r I : I I- T- I ~--- r—I – – I- – – } NVäWTTwo —r—y—r-w— (N ‘I = I ‘(I)x) 'ZZ CIVE&H (7'OI+/) LWWAZ- ZC r—T-- I- I I-r —I- –H–F–F–F–F–F–F– r—r-r—, N 'IZ CIVE&H ſ I H I I I -—I- I I 1–1–––––F–––. r—r--r-, (8I) LWWAZ- IZ I I I I HøvåAv'N' x NøWWZO —r—r I . . . . . . . (666x NøSNinia y ; t I T I I I H- T- I––––. I O N i = i (DX 23 JNV N A2: Saniya Savās II o T---—- – -----—I----------—I --- F--------——I---——I----, VX45)(2)}{d NIVW V SI SIHL O I- f | — T- -] | I I I- T-- I I -r-r-—r - r | I-- | T-- -I -—T- ---, - H F--—T- I-- -] —r—r—r-r H-I------------ - I ----- I -ºr--- I --- r I —T-- ---T— --------|--——I-– r—T-P-r & Z 04 $9 O9 ç ç. Og Gy Oy G8 O9. SZ O& 9 | Ol Z || 9 || G l 1N3 W B | V | S N V & 1 & O = 3| 839wnN 2 º O8 £4 iN3 WWO O NO3 D F----—T-- UOI! OD (414 U 9 Á Z }o I a 6pd * !!! p| CINVH WVS 9 peºpau) AVG(2, L *Q NWää. Wiſ “... WR O - 9 N | O O.J NV8 l? O H WV892)\Ha NIWW d --- **** FORTRAN COD |NG FORM program SUBROUTINE MEAN coded by JIM, BRZWN Dale TøDAY Checked By SAM CLARK ldentification Page 2 of 2 —1––––– C FOR COAAAAENT 73 80 ſº |NUMBER FORTRAN STATEMENT } 5 || 6 || 7 30 35 40 SUBROUTINE MEAN DIMENSIZN X(999) CZMMøN X, N, AVEAGE SUMX = O.O FLN = N DQ) 10 I = 1, N SUMX = SUMX + X CQ)NTINUE AVEAGE = SUMX/FLN RETURN END 33 Fortram Coding Sheets 34 One: Introduction gilliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliililillº T h € l Il f O r IIl al t i O Il O Il e a. C h l 1I] € O f E the coding sheet is punched on a E Separate tabulating card. Filmminimumnuuuuuuuuuuuuuuuuuuuuuuuſ; E r § siliiIIIIllililiiliſilliiliiliiliiliiliiliiliiliilius There are 80 columns in a tabulating card. IIIIIIIHIIIIHIIII IIIIIIIIIHIIII IIIIIIII IIHIIII | | - - - - **----.. ------ -- - - - - + - -- --- ,’ y - * w * -º referred to in other statements.) # Columns = gunnummumumumumumumumumumumumumming = 7 – 72 are = = Columns 1 - 5 are used for the statement = = used for the body of E E = = the = ( = number. = É Fortran = É (It is necessary to number some = E \ Statement. = E statements so that they may be = ETIllilllllllllllllllili IIIIIII IIIIIIIIIIIIIIHF: E E ; = filllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll. IIIII : IIIIIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: CO lu m n 73 – 80 are used only for - º giliuliiiniiiiiuuuuuuuuuuuuuuuuuuniliiliiliiliiliiliiliiliiliiliiliiing To avoid confusion, the following printing conventions are recommended on Fortran Coding Sheets: sequencing and identification. | F.IIIIIIIHIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIllililliLIIIlliliº *IIIHIIIHIIITIIIIHIII III III IIIII IIHIIIII IIIII IIIII IIII IIIIII III III IIIIIIIII IIII III III IIIIHIII]º 1 ſº- One I gºg Eye Column 6 is normally left blank. 2 - Two # - Zee However, if a Fortran statement requires more 0 - Zero Ø — Oh than One line (one card) it may be continued On * iiiiiiuliiliiiniiiiiiiiiliiliiliiliiliiiniiliiliiliiliiliiliiliſiiniiiiiiiiiliiliiliiliş another one. In this case, the continuation card must have some character punched in column 6. This character may be any character other than a blank. iiiiiiiiiliiliiliiliiliiliiiiiiiiiiiiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiiniiili *4 *g * 35 * Ny Punched Cards 36 One: Introduction What is a Punched Card? A punched card or tabulating card is a card of uniform size and shape that has holes punched in it according to an established code-pattern. isilliilillllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: =The contents of Fortran statements punched on tabulating cards by al r € using a keypunch machine. This machine has a keyboard like a Punched cards have the important advantage of being relatively permanent, and they can be read quickly and accurately by several different kinds of machines. They are often called Hollerith Cards. t y p € W r l t € r ſº Hitting a key causes a =pattern of holes to be punched in a Écard and the character to be Eprinted. FIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIliili Y * º filiiliiliiliiliililiiliiliiliiliiliiliiliiliº Fortran programs and data are & W2. guiuluuluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu punched into cards Each column is capable of containing the punched using a COde for One character. The code-pattern for the character is punched code-pattern: in the column, and the character itself is usually printed on top at the head of the column. Each card consists Of 80 Printing the character at the top of the column vertical columns. alleviates the necessity of memorizing the = code-pattern. *||" agiliiliiliiniiiiiiliiliiliiliiliiliiliililiiliiliiliiliililiiliiliile The printed character is never read by the machine; it is only for human | COnvenience. Fiiliiliiliiiniiniiniiiiiiiiliiliiliiliiliiliiliiliiliiliiliiliili Each Column consists of 12 & r: possible punch positions. :TIII III III III IIII III III, III, III III III IIII º * |r. Following are Sample Cards with the Numeric, Alphabetic, and Special Characters punched in. 37 Punched Cards 38 - One: Introduction IIIllililiiliilius: There are several alternative sets of special characters that may be used at different computer installations. -T IIITIII IIHIII III IIHIII III III IIIIHILIJIIII III III: | | - - r ! f f : Programs to be : : The process of i : Compiled are : : producing a : : called : : Fortran Object : : programS. : : Program from a -------------Rºswer-55-5-1; ; Source Program : : : º § * * * * * * * * * * * * * * * * * * * * * * * * * * * is called R N P 1 G). ----------------------1 I Ø- : Executable : : Source Programs : : statements 2.I'6 : : must be compiled : : º into : i into : : Iſla CIll]16 : : programs before : : e : : they can be : +----------------------- ; executed. : NSWE P, 171 ---------ºf-ºr-ſº 39 Exºrcises 40 One: Introduction This program will not terminate until COntrol reaches bOx te 7 N § P. 1 7 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - When will this program terminate? 1) Never 2) At box (e) 3) At box (d) 41 Exercises | L | : : i e as: : g = i : cy" G * = . : ^ =e^ O 3 * : : - à ... E.; ; : H ; : : ; : 3 * : º: O : E ă ă: : E (D - i. : % § -t; | ~ E: >: * : 2n Q = C/2- C = : E Triº e-t- i. *: 3 : 9: 5 : | TUI " . al !-all SJI F = == Colº m = = * * * * F---- | I : FI: : * @ : > = : O | : * 3 # L → ; : | O Fº | (D } - : G’ Q = ; : 3 : I ; : § { - e O : E - i Q. m H. H (D (D | >n O. ; : ā; ºr 5 m * -.' : # E E. : 20- at O : čh >: : 2: 3 : *-* V. •-N.) Hall SJ === NME m = m = * * * ă ; RS Part Two: Fººliº Elliºuºlº; A Job C Subroutines e Main Program e Interprogram Flow of Control O Exercises C Main Program Task e Diagnosis © Comment Statements System Control Cards identify the Job, and A "Job" consists of: regulate the preprocessing of the programs 1. The Program Section 2. The Data Section 3. The System Control Cards in it. The control cards required at computing installations are different from installation to installation. 43 v A Job 44 - TWO: Program Structure aſiliiliiliiliiliitiiniiiuuuuuuuuuuuuuuuuul || || tº L iſ . . . . - iiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliing The data are in one section and that Section is usually marked by a particular System Control Card. |IIIHIII III IIIIIIIII IIIIIIIHIIIIIIHIII IIIIIIIIIIIII IIII IIIIIII III : The Program Section contains all the related program segments { | that have been written to accomplish z a particular task. There must be One and - only one Main Program in the program section. But there may be many IIIluliiniiiiuuuiliiiiiiiiiiiiiiiujiiiiiiiiiliiliiliiliiliitiiº: subroutines—or none. Most large, well-organized jobs consist of one Main Program and several subroutines. Fililllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllli | * h A subroutine is a self-contained program that is compiled independently of other sub- routines or the Main Program. º - || |||III III, III ||||||||I||1|1||||||||||I||||||III: A set of Fortran Statements is defined as a Subroutine by the first Statement in the set. :TIIIIIIIIIII IIIIHIIIIII III IIIIIIIIIIIIIIIIIIIIIHIIIIIr: The general form of a subroutine-defining Statement is | T SUBROUTINE Name where "Name" may be any combination of from One to six alphabetic characters. The last Statement in a subroutine must be an "END'' Statement. E N D - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - For example, SUBROUTINE DGIT defines a set of statements as a subroutine whose name is ailiiliiliiliiliiliiliiliilill: ÉThe end Of a Subroutine is • * * §IIII III IIII III III IIII III III III III, III.1111111111111111|||||I||1|||||Ill!!!: also marked DQIT". with a The compiler will compile all the - tº tº I- - - - is m = ºn m ºn m ºn m = m ms m ms m m ms ºn m = m m Statements between the Special SUBROUTINE Statement and the END statement as a single Statement. Subroutine. :IIIIHIIIIIIIIIIIIIIIIIIIIllllik :1|||||||||I||1|||||||||III III III III IIII IIIIII, III.I.I.I.I.III IIHIIII] * 45 Subroutines 46 Two: Program structure The END statement says, "This is the last card in this program. " The termination of a The RETURN statement will cause the flow of control (execu- tion) to return to wherever it was before control was trans- ferred to the Subroutine. subroutine must be the following State m ent : R. E. T. U R N A RETURN statement is the last logical Statement. The END Statement is the last physical Statement. * Jº HIllilililillllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll Thus, there are three crucial statements in every subroutine: SUBROUTINE Name | ) Other Statements RETURN | E Illillllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: f - * : wºmmy wº - Subroutines may be "called" from any point in a Main Program. The calling Statement is - C A L L Name º The last State- ment in a Main where "Name" is the name of the Subroutine to which COntrol is to be Program must transferred. be an END Statement: A program is defined as a Main Program. suiliiliiliiliiliiliiliiliiliiliiliiliiliilililiiliiliiliiliiliiliiliiliiliiliiliiliiliiliili by the single fact that the first statement in it º * is not a Subroutine-defining statement. statement in the Main Program that calls a special System Subroutine which returns control to the Monitor System. |||||Illili llllllllllllllllllll IIII Vº Thus, a program that is a Main Program may begin with any statement €3:Cept a subroutine- defining Statement. 311|||||IIIIIII III IIII IIIIIHIII IIHIIIllllllllllllllllllllllllil IIIIIll 41 Ny - - Main Program d | s: 48 - TWO: Program Structure Although there are several Program-terminating System Subroutines, the One to use here is C A L L E XIT P. * §IIIIIIIIIIIIIIIIIIIIIIIIIIIllillº 111||||IIII E. subroutine EXIT terminates the job, and returns control to the Monitor System. It is from the Main Program that Subroutines are normally called. Control flows from the Main Program called from other to a subroutine, and then back Sub r Out in eS . to the C on trol could flow , for example, from a Main Program to a sub routine, and from the re to a second sub r Out in e. The RETURN state m ent in the se c on d sub routine returns control to the fir St. Main Program. tº ºt IIIIIHIII IIIIIIIIIIIIIIIIIIIIIIHIIIIllllllllis * FI = = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sº tº tº sº sº tºº sm ºm ºn as mus ºn mº m ºn sº Interprogram Flow Of COntrol 49 P- - - - - - - - - - - - - tº ſº ºn tº E tº m ºn tº tº L. ºr ſº tº - tº | | This box c a uses C On trol to transfer Out to Sub r Out in e A B L E ſº ſº ſº tº El Lº tº Lº ºn tº tº Lºs ºn tº tº Lºs nº ºn tº I- = * * * tº Lº L. . . . . . . . tº tº Lº 4– r" : (2) Control reaches º : : subroutine ABLE : : and proceeds through . ; : it until it reaches : : the RETURN : : box. : [. | * * * * * * * * * * * * * = ** = = * * * = = * = tº ºf al - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The R. E. T. U R N box returns control to the exit arrow Of the ''C A. L. L. A B L E '' box, box (1). sº J tº J tº iº a * , sº * I tº . tº ºn ſº . tº a * . tº [… tº [… | i. ºf tº- tº tº 4\ Control proceeds to box (4). Here control is transferred Out to subroutine B A K E R . * > º *-g º tº * … *- tº- ſº gº a ſº- : . tº- * * tºº º . * . º tº tº ºn tº- I ºt tºº *. When C On trol reaches Subroutine BAKER, it proceeds through that program until the Af R. E. T. U R N returns Control to the CALL BAKER box. TWO: Program Structure 50 fº . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tº Lº ºn ºn tº ºn { i Lºs ºn ſº tº l :0 H : : : "STOP" indicates the termination : r = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - m : of the job ;G) C A L L CHA R L Y causes : : g : control to be : ); : ; transfer r, ed Out to : * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - al : sub r Out in e C H A R L. Y. ; ------ tº ºn m = m = ± = Gº ºn m m ms m ms m ms m = - ºn tº ºn tº m ºn sº m ms i m me m = nº - - - - - - - - - - | | jo : : : : ; Subroutine : F;------------------------------N. ------------------ : CHARLY : ; (1) On the next page is a Fortran Source : : OperateS. : : Program corresponding to the : : : : Flow Diagram you have just studied. : : : Compare box (1) with statement (1). : : 3 : Compare box (2) with statement (2), : "J. . . . . . . . . . . . . . . . . . . : etc., etc. : FF---------------------- -- : Note the flow of control through : : \º The RETURN box : the Source Programs. : | : sends control back to : * = = m = = = = * * * * * * = = m = m = m = = = tº tº . . . . . . . . . . . . . tº ºn tº . . . . . . . . ; m ºn ºn sº ºn tº m º ºn m = ± a ; the Main Program. : | +-------------------------- 51 v Interprogram Flow of Control l I 1. à f SAMPLE FORTRAN COD |NG FORM TWO: Program Structure Program coded by Q2LMAN Date TøDAY Checked By DøTSøN ldentification Page 1 of 1 ——l— [- c for cowent 73 80 |siºnſ # NUMBER |3 FORTRAN STATEMENT l 5 || 6 |7 10 15 20 25 30 35 40 45 50 55 60 65 7O 72 C THIS MARKS, THE BEGINNING ØF THE MAIN PROGRAM i_*. *—a—º-1–1—*—*—a *——1–4—1—1–––a–A–1— it *—1–1—a 1—l—l—1–1—1—1–4—1–1—a 1–1 | | | | l CALL ABLE ——1––––– —l —————— | | | | CALL BAKER - | —l- I , —l l | | | I | | | – L CALL CHARLY –––––––––. | 1– ——1–––––––––. | 1–––––– I CALL EXIT l –––––––. 1––––– —————— -——1––––––. —l- | f —1– END - ————————l—l—1–––––––––––– 1–––––––. I l ———1–––––––––––. | --|-- | | 1–1 | L | l l SUBRZUTINE ABLE i–1 ———H–———1––––1—1––––––––––. H––––––. | I C CALCULATIONS ØMITTED | 1 | | I l | | | RETURN l — — — — — 1––––––––––1—1–––––––––––––––– | | 1– | END ——————1–––––––– 1– 1– | | | | | 1–1–1– ———1––––––––––––. | | I I | | l l 1– SUBRZUTINE BAKER | | l l | f | l | | C CALCULATIONS ØMITTED } | | | 1– | | | –– ––– RETURN . . . . . . . . . . . . . . . . . . —l---—— –––. | | 1– END –––– ————1–1—l—1–1– | | –––. 1– –––––––––––––– ſ | | I | | — –––. 1– | SUBROUTINE CHARLY__ l | | | | | | | | C_ CALCULATIONS ØMITTED. . . . . . . . . . . . . . . . . . . . . . . . . . . . | | 1––––––. RETURN 1––––––––––1—1– —1–––– l I––––––––. END | R | | | | —l-––––––––––––– l 3. i i i º L i l i 3. l i 1 | i i k i l Á Å I i * I i l ——----|--|--——1– 52 Only one of the Subprograms in a job may be a Which of the following statements must be the last physical statement in every program? program. (i) --------ºr:frº-r; Which of the following statements must be the first statement in every Subroutine? CALL SUBROUTINE CALL SUBROUTINE END RETURN =l ANSWER ON P. 162 8 END RETURN (5) “…~~~~ * ©. tº tº ºn tº ºn tº tº . . . . . . . . . . [E → -i tººl tº ſº E E ºn tº ºn ". ----------------ºriº-rº in Fortran, a group of . : Which of the following : : º: º a. subroutine; : statements must be the last : ; it and only, the first : : statement eacecuted in every : (2) ; statement is a , , ; i subroutine? : f ------------------ : Statement and the last : I - | Statement is an L : CALL SUBROUTINE END : : consists of a : H statement. : : RETURN : : Program Section, : i--------------- ºn tº tº tº tº º iſ tº tº Lº tº i i : a Data Section : ANSWER ON P. 171 ºn tº ºn tº E E = tº Bºl ºn tº tº G - tº "7TRWEF57: "t; : and : | System Control Cards.; l 53 Exºrcises 54 TWO: Program Structure ls m = m = m = = = m = m = m = m = | : The Correct Statement in a : : Which of the following statements causes : : Main Program to call a : : control to be returned to the Monitor : ; subroutine named BAKER is ; : System, thus terminating the program? : - RETURN BAKER : T : GET BAKER : : CALL EXIT END RETURN SUBROUTINE : l | | | : CALL BAKER : *------------------------------------------------Rºsºf-5F-F-Tº: | : Beginning on about the fifth line of a Fortran coding sheet, write a complete, but short, Main Program that calls each of the following subroutines in turn: INPUT, SQRT, QUTPUT, and EXIT. SPECIAL INSTRUCTIONS: X X X Do not continue until you have completed this task. = * * * * * = - - - - - - - - - - - - - - - - - - - - Was the first Statement in your program CALL INPUT r | ſ I I im | Was the next statement : in your program -): CALL SQRT : and was the "O" Slashed? lº m = * * * * * * * * * * * * * * * * * * * = * * * * * * * = ====== * * * * * * * * INPUT is the name Of the Subroutine that will read in the data to be used in the SQRT subroutine. These data must be read in before this subroutine can be expected to use it. i * ==== F ================== - . m = m m = m = m = m = m ms m m = m ms m = m m = m = n = * * * * * * * * Was the third Statement in | your program : CALL QUTPUT +: and was the "O" slashed? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Subroutine SQRT is the subroutine i{ that will be doing the main work in this job. | | ſ : It must be called after INPUT, but | - | before ØUTPUT. * = m = m = m = m = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Diagnosis 55 56 TWO: Program Structure : | | | g- - - - - - - - - - - - - - - - - - - gº tº m ºn tº ºn I- - - - - - - - - tº sº tº tº ºn tº tº sº tº =l | : ;4 } : ØUTPUT is the subroutine that will ;V - : print the results of the work done in : ; SøRT. : | - | : Obviously, it must occur after SQRT. : F - - - - - - - - - - - - - - - - - - - - - - - - - - T +------------ - - - - - - - - - - - - - - - - - tº El Mº i tº ºn tº ºn ---- M. Was the fourth statement :{– -" in your program I | : CALL EXIT !--------------------------- CALL EXIT is a System Library V S "º 2 F-------------------------- Subroutine. When it is called, the Was the fifth Statement in your program END Calling program is terminated, and Control is returned to the Monitor System. | º * . tº . º I- ſº º - tº tº - ſº tº- ſº ºn tº- tº- º a- Lºs tº - i - - tº i is - tº º tº- º I tº tº s Every subroutine and Main Program must have an END Statement as the last statement in the program. This statement defines the limit of the program; all the Statements up to and including the END statement are Compiled as a Single Subprogram. In front of the first statement, write the following statements with a "C" in column 1 and the following "comment" beginning in column 7: C THIS IS THE MAIN PRQGRAM. * uſiliiliiliiiniiniiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliili P: This Comment statement is not compiled. It is merely a way to identify and label programs. You may insert Comment statements anywhere in your Source Program. d 57 Comment Statements Part Three: VARIABLES AND CONSTANTS Fortran Variables O Exercises O Fortran Con- stants O Exercises O Subscripted Variables C DIMENSION Statements O Exercises O Com- mon Storage © Exercises summuliminiiniinimummillinuliminiumillilululiiniiniiniiliilining: Every numerical value that is input data must be "assigned" to a Fortran Variable. F = = * * * * * * * * * * * * * * * * * * * * * * * = - - - - - - - - - - - - - - - - - The heart of every Fortran program is the arithmetic calculations that are performed. -> Each Fortran variable has a specific storage location in memory for its numerical value. IIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIII IIIIIIIllili IIIIIIIHIIIIIIIIIIIIIIIIIIIIIlº These calculations are done with numbers. * IIIIIIIIIIIIIIIIIIIIIIIIII III IIIIIIHIIIIIIIIIIIIIHIII IIIIIIIIIIlliſill; sº * = = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Every numerical value that is read in by a program is stored in the memory location corre- sponding to the variable to which it is assigned. iiiiiiiii!III.iiiiIII.iiiiiliiliiliiliiIIII.iiiiiiiiIII,iiiiiiIII.iiiili umbers may be written in Source Programs as Fortran Constants or they may be input data. III.iiiiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii | | 58 Thus, a Fortran variable is like a symbolic "tag" for a storage location. Before Fortran variables can be used in a calculation, they must be "defined." The value of the variable at any moment during eacecution is the value of the number in its storage location. A variable is said to be defined if it Occurs in a Fortran statement that stores a number in the location named by the variable. This rule enSures that a variable will have a value before it is used. i. illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllliiIIIIIIIIIIIllililliiIIIIIIIIII: Whenever a variable is used in a program, it is the storage location that it names that will be affected. º :N - Fºlliii.IIIHIIIIIIIII IIIIIIIIIIIIHIIIIIIIIHIIIIHIIIIIllllllllllllllllllſ Variables may be defined The actual Storage location named by a particular variable cannot be known until after the program is compiled. in Input Statements, in DQ-loop Statements, and as the name of the location And while the program is being written, it is not necessary to know the actual storage location. where, the result of an arithmetic wº Calculation Should be Stored. s 59 Fortram Wariables 60 Three: Wariables and Constants A Fortran variable may be any combination of from one to six alphabetic characters. It should contain no special characters, such as >k () • 3 / + - Some legal Fortran variables are: X P Z I J K C H ABLE JøHN PAPUT BFIMD A B MAN Wºman WDPC IBM WPA CIA NAACP {- : For example, if : a program is to : deal with code inumbers, a ); variable like CQDENQ ; might be used. If : temperatures are : involved, TEMP A. -*- The number of possible combinations of letters that could be used as legal Fortran variables is very large; too large to think about here. The purpose of this freedom is to allow you to invent variables that have some connection with the quantities to be stored in the location of the variable. * might be used. [IIIIIIITIIIITIIIIIIIIII IIIIHIIIlllllllllllllllllllil IIIIIIII IIII.I.I.I.III IIIIIIIIIIIHIIIIIHIIII III IIHIIIIº |- Numbers are stored in one of two possible modes. These two modes are called Floating Point Mode and Fiaced Point, or Integer Mode ! siliiliiliiliiliiliiliiliiliiliiliiliiiiliiliiliiliiliiiniiiiiiiiiiiiiniiniiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii!: Note that the use of words Fixed Point suilliiiiiiiiiiiiiuuuuuuuuuilliiliiliiliiliiliitiiliiliiliiliiliº = Fixed Point numbers are stored …tº l I). O I} € p 2. r t O f 2. C O II) D Ul t € r W O r d Floating Point Whole Integer number does not correspond precisely with the use of these terms in mathematics. If it helps, you may think of Fixed Point numbers as having an arbitrary, (The box-like enclosure is illustrative of how the number would be laid out in the particular storage location.) IIIIIIIIIIIIIIIllilill HIIII IIIIIIHIII IIII III IIIIllillllllllllllllllllliſ, imaginary decimal point at the right of the number. :1||||IIIIHIIIIIIIIIIIIIIIIlllllllil IIII IIIHIIII IIII IIHIII IIIIHIIIIIIIIIIIIIII IIIIIIIIIIIIHIIIIIHIIIIIIIIIII: T- * - Variables are either Floating Point Mode Or Fixed Point Mode depending on the first character. 4 Sºllllllllllllllllllllllllllllllliſ Hill.iii.11111111111111111111111111111111HIJIIIIIIIIIIII III III IIIIII III III] Floating Point numbers are stored in two parts: Exponent Fraction -> Fill ill! III III III III III IIII III IIIIHIII IIII IIIIIIIIIII IIIIIHIIIIIHIIIIIIIIII IIIIIIIIIIIIIIIIIIIIII IIIII, IIIII III: If the first character is I, J, K, L, M, N The variable is Fiaced Point. 61 FDrtrail Wariables 62 Three: Wariables and Constants On the other hand, these variables are all Floating Point Mode If the first character is A, B, C, D, E, F, G, H, --- Ø, P, Q, | R, S, T, U, V, W, X, Y, Z, the variable is FLOATING + X P Q A F R DQG Y TQM TABLE TABQ.NE TABTWQ) GIZMG) PETER ZENITH RATE RCA ETC º E tº º – º – ſº ſº ºn tº ºn ºn I-, - tº gº ºn I- nº ºn I- nº 2------------------ g º ºn tº ºn ºf ºn tº I- ºg º ºn tº E tº For example, the following variables are Fiaced Point Mode I J K L M N MAN KQUNT ITEMNQ NUMBER JOBNQ, NANCY LUCK MANNQ LUCY JANE -T T : Invent º ºnes : : Invent the names : ; of five Fixe : : of five Floating ; Point variables. : Point variables. : º (Write them on : i (Write them on : scratch paper.) : ; scratch paper.) : ----------------------- H------------------------ l SW P. 164 ANSWER ON P. 167 To be able to use a number in a program, it is not always necessary to invent a Fortran variable for it, and then read in a value. Numbers may be written as deci- Trval numerals in Fortram state- 'me?! ts. 63 FOntran GOnStants 64 Three: Wariables and Constants isſiiniiniiniiiIIIlliiliiiiiiiiiiiiiiiiiiii!: When a Statement containing a Fortran constan, Such numbers are compiled, #4 called Fortran constants. a special Storage location IIII III IIIIHI JIII11||||III IIIIIll III IIIIIIIIIIIII IIIIllllllllllllll)}: And because constants actually E occupy storage locations, they too may be either Fixed Point or Floating Point Mode. containing that number is set –) up within the Object Program. Fiaced Point constants must be whole integer nwmbers IIII IIIHIIIHIIIIIIIIHill||1||||||||||||||||||1||||||||||||||[[[[[i. gº ºf filliiIII.iii.III.iii.III.iii.III.iiii iliili IIIIIllins with no decimal point. Some typical Fixed Point COnStants are: 748 98.732 1 100 999 In fact, Fixed Point Mode is frequently called Integer Mode. 7362 98.20 84733 8 ..Y. i Notice that they have no decimal points. P- * HIIIIIIIIII ſimummummumminimumming The absolute value Of a FOrtran Fiaced Point constant must be less than 131072 C On Stants that are Written with a decimal point are Floating Point Mode. Such numbers are, like Floating Point Variables, stored as a fraction and an eXp On ent . ºrd isºtypical"Flºatin: Éiſt Wºde";4- - variables are 98.36 98.0073 0.000746 0.983 1. agiliiliiliiliiliiliiliiliulililuliiliiliiliiliiliiliiliiliiliiliilie =A Fortran Floating Point Constant . 0 1.5 0.1 0.00000008 0.78 ); should not be greater than nor & g Éless than 10°3; and only eight i-Notice that they all have decimal points: * Esignificant digits are retained. º- Filiiliiliiliiliiliiliiliiliulililiiliiliiliiliiliiliiliiliiliiliili Write some | Fiaced Point Constants. Write some (Write them on Floating Point scratch paper.) Constants. (Write them on scratch paper.) ANSWER ON P. 168 24 º, | L | | | N ANSWER ON P. 16 65 Exercises 66 Three: Wariables and Constants Subscripted Variables, on the other hand, are assigned as many Storage locations as you sulliluliliiliiliiliiliiliiliiliiliililililuliiiniiliiliiliiliiliiliulliiliuliiniiiiiiuuuliliiliili © * specify in the program. The Fortran variables you have learned about thus far have been single entities. They are called "nonsubscripted" variables to distinguish them from another type of variable, the "subscripted" variable. * ----------------------------------------- : NOTE: A variable with one subscript (a . single subscripted variable) is called a One-dimensional Array. A variable with more than One subscript is possible, but will not be discussed here. ºn m mm mm mm sºme ºn sº mºn's m = - - - is m = m = m = m m in m = m = n = * * * = Nonsubscripted variables are automat- ically assigned one storage location by the compiler, when it compiles the Source Program into an Object Program. Because the storage allocation for any subprogram is built into the Object Program, any change in the storage requirements for that subprogram can be made only by changing the DIMENSION statement in the Source Program, and then recompiling that Source Program. siliiliiliiliiliiliiliiliiliiliiliiliiliiliiliililiiliiliiliililiiliiliiliiliiliiliiliiliiliiliiliiliiliilillº The statement that must be used to assign storage locations to a subscripted variable is called a DIMENSION Statement. r: This statement instructs the Fortran Compiler to reserve a specified number of locations for each subscripted variable in the program it is COmpiling. guillilililuliiiniiiuuuuuuuuuuuuuuuuuuuuuuus = For this reason, Subscripted III IIIIIllililililililillili IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIllilililililllllllllllllllllllilillllllll: =Variables should be dimensioned = = for the maximum number that will; =ever be needed for that variable. E FIIIIIIIIIIllilililillilililillilillilililillilillIIIIIIIIIIIIIIIIIIIR. É The general form of a DIMENSION statement is DIMENSION V1(n), v2 (n2), . . . "v" is any legal Fortran variable -- "n" is a Fixed Point Constant specifying H ; Note: : Several variables may be H "dimensioned" in one ; DIMENSION Statement. the number of storage locations to be reserved or allocated to "v." As mm mm mm mm mm mm mm mm mm m = m m = n = * 67 ! DIMENSION Statements 68 Three: Wariables and Constants rºll|||||||Ill III III III III IIII III III III III.iil IIII IIII IIII III; 11 IIHIII III IIIll III III III IIIll III IIIlli lllllllll!2. The general form of a For tra n subscripted In algebra, subscripts are written like this: variable is v(i) X 56 or Zi "v" may be either a Fixed Point or a Floating Point Variable; However, because we cannot space down a half line on a tabulating card, Subscripts in Fortran are enclosed in parentheses: X(56) or Z(I) : III III III III III III III; III III IIII III III IIII III III III IIII IIII III || || || |||Illi lllllllllllllllllllllllllllllli "i" may be either a Fixed Point Variable or a Fixed Point Constant. *III IIII IIII III III III IIII III III III III IIII IIII IIIIHIIIII IIII IIII III III IIIIII IIIIIIII III IIII/2 Subscripted Variables allow you to refer Systematically to long lists of values simply by systematically changing the value of the subscript of the Variable that names the particular list. º ºn ºn tº ºn M. º. º. º. º. º. º. In ºn tº tººl º ºs º ºn a ºn tº m ºn tº . . . . . ºn tº ºn -i ºn x(56) refers tº the 56th ºf the One-dimensional Array, called X. | : : Z(I) refers to the Ith member of the : [. | -> Ny 2. T * Array Z. When I = 16, Z(I) refers to the 16th member. When I = 88, Z(I) refers i to the 88th member. P = - - - - - - - - - - - - - - - - - - - - - - - - - - i Some of the ways to systematically vary the value of a subscript Will be covered in later SectionS. Assuming Z is the name of a One-dimensional Array of 100 numbers, write Z as a Subscripted Variable that refers to the first number in the Array. @. Write Z as a Subscripted Variable referring to the last number in a One- dimensional Array of 100 numbers. TNSWFTERFET"; 1 For Z(I) to refer to the Sixty-first number in a One- dimensional Array of 100 numbers, I must be set equal to what fixed point quantity? If I = 15, to which number in a One- dimensional Array of 100 numbers does Z(I) refer? * = * * * * * * * * * * * * * * * * * **** *** ** == SW P. & ANSWERTORTTTg, 69 Exercises -> You have already learned that 1. Variables are allocated Storage locations by the Fortran Compiler, 2. Nonsubscripted Variables are allocated one storage location, and 3. Subscripted Variables are allocated as many locations as you specify in the DIMENSION Statement. Actually the compiler allocates storage locations in either of two ways: 1. as a relative address, internal to the program in which the variable is used, or 2. as an absolute address in a special part of memory called Common. Three: Wariables and This technique allows the compiler to compile One Subprogram completely independent from any other Subprogram. The compiler does not need to keep track Of the relative addresses Of internal variables from one Subprogram to the next, even Within the same job. Constants 70 You may communicate the values of internal And the external, absolute Variables from one subprogram to another addresses assigned to Common Variables are always assigned in a systematic way starting at the same absolute location. by means of arguments in a calling sequence; a Complicated technique reserved for a future learning experience. [III]]|IIIIIIIIIIIHIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIHIIIIHITITIIIIIIHIIIIIIIIIIIHIIIHIIIIIIIIIIII: º 4 suiliiliiliiliiliiliiliiliiliiliiliiliiniiliiliiliiliilililiiliililiiliiliiliiliiliilililillº: Thus, the problem of communicating values You may communicate Common º Variables from One Subprogram to the next is not a by listing them in COMMON problem solved by the compiler. It is your Statements in the Subprograms between which yOu Want them COmmunicated. responsibility, and must be a part of the design of your program. * Y. The general form of a COMMON statement is COMMON VI, v.2, vs, The TV's are variables. Hilliliiliiliiliiliiliiliiliiliiliiliiliiliile E Variables that are = El llllllllllllllllllllllllll-IIII III IIIll IIIIHIIII tº- El If a variable is not listed in a COMMON Statement, it is an Internal Variable. -IIIlllllllllllllllllllllllllllllllllllllllllllllllllir = statement are called = Com m on V a ria b les. IIIHIII.iii.IIIHIIIIIIIIIHIIIIIIIIIIIIIIIIIHIr: -> | r 71 Common Storage 72 - - Three: Wariables and Constants { w U For example: The statement, CQMMGN P, Q, R ): would assign "P" the first : absolute location in Common, : "Q" the second, and "R" the The first variable listed in the COMMON Statement is assigned the first location in Common Storage. The Second Variable is assigned the second location, etc. -II Filiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiiliiliiliiliiſ; –III III III III IIIII IIIIII IIIIHIIII IIIII IIII IIHITIIIIII IIIIHIIIITITIIII IIHIIII III IIIII III III IIIII III III III.1. Now if you want another program to use "P, " the first location in Common, you would have to write this COMMON statement, CQMMQN P in this other subprogram. Whenever P was used in this second subprogram, it would This assignment to Common would hold through- out the subprogram in which the COMMON statement appeared (and only in that subprogram). Whenever R, Q, or P was used in the also be the first location in Common Storage that would be affected. y subprogram, it would be the Common Storage location that would be affected. ſº e Fºlllllllllllllllllllili III IIIIIIIIIIIIIIIIIIIIIIIIllil IIIIIIIllilliili IIIIIIllili IIIIHIIIlllllllllllllllllllliº; : These statements 1I] a. | Subprogram, CQMMGN E, F DIMENSIGN E(50), F(50) I would assign the first fifty »; locations in Common to ; variable "E," and the second º * If a Common Variable is also listed in the DIMENSION statement of a subprogram, the Compiler assigns it as many Common Storage locations as you specify in that DIMENSION Statement. tº- FILLIIIIIIIIIIIIHIIIIIIIIIIIII IIIIIHIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlllll: T : Write a COMMON : @ : statement that : F---------------------------- tº tº Lº tº ºn ºn I- -------, ! will put variables {(3) | ºn ºn I-s ºn ºn º tº L I ºf Lºs tº tº ºn tº gº ºn ºn L. ºn tº I ... º. º tº . Fº I : In a subprogram, variables : ; A, BIGX, and : I T : that are not listed in a COMMON : ; CHI in Common ; : Write a COMMON Statement : i statement and, therefore, are in- : : Storage. ; : containing the following variables: : : ternal to the subprogram are : E F tº - tº- tº º ANSWERTONTE THE : DELTA, Z, : : Called : : XBAR, JQE, : | LAPD * = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = H | ANSWER ON P. 162 i. .. @). Of the following variables, only one will need to be in º T | | ; Common storage, write a COMMON statement that : g : : will put the third variable from the left in Common. : : A Common Variable can : : : : only be communicated be- : : ZEBRA, F@X, NAY, A, C, DIST, B, PI : # tween subprograms in a : : : : job when it is listed in a i--------------------------------------------------------------- : statement in : ANSWER ON P. 162 mºsºmºsºsºmºmºmºsºmsºmºsº | ; each subprogram. : ©---------------------------- tº m t------------------------------ |Now write a COMMON statement : ANSWER ON P. 171 ithat will put the fourth and seventh; :variables from the left (in the : above list) in Common. : ---------------------Rºswer-55-5-1; T3 Exercises 74 Five: Arithmetic Expressions If the nonsubscripted variables, A, B, and C are used in Subroutine PETER, Write the COMMON Statement that will assign them to the first three Common Storage locations. : If A, B, and C are also to be used in ; Subroutine HELP, write the COMMON ! statement for HELP that will also I assign them to the first three locations ; in Common. - * ANSWER ON P. 168 Q. 34 If Subroutine : SPECAL uses only C Write a COMMON Statement for SPECAL. If A, B, and C are also to be used in the Main Program that calls PETER and HELP, Write the COMMON State- ment for A, B, and C. s "RNSWFF-5R-E-77; 35 ©.… How many Common Storage locations will be allocated by these two statements 2 CQMMGN AJAX, BILLY, LAZY DIMENSIQN BILLY (100) How many Common Storage locations will be allocated by the following pair of statements? CQMMGN X, Y, Z DIMENSIGN X(100), Y(100), Z(100) tº = m = - º, ºn ANSWER ON P. 168 ANSWER ON P. 165 Part Four: INIPUT STATEMENTS Input Data Fields e Input FORMAT Description o Multiple Fields e READ Statements e Relations between Fields, Descriptions, and the Variable Liste Exercises O Input Task and Diagnosis HIllllllllllllllllllllllllllllllllllllllllllll- There may be only one, or there may be several numerical Values, punched on One tabulating card. Billlllllllllllllliiliil III.1111111111111111111 The transmission of numerical values into and Out of the computer durin p g illilililililililiiliiliiliiliiliiliiliilillº: A tabulating card containing several numerical values is described as having several data fields. IIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIII IIII IIII the execution of a program is controlled by Input and Output instructions. E r: * * tº In their original form, these numerical values are punched on tabulating cards. Each digit of the numerical value is punched in one column. For purposes of description, each value is said to occupy One "data field. " T. t 75 Ny Input Data Fields Four: Imput Statements For example, if the numerical value 89.42 is to be read in as one numerical value, there will need to be at least five columns in its data field. Each data field is made up of a certain number of columns. The number of columns in any data field is called the "width" of the field. They could be the first five columns of a tabulating card. aſſumiliiliiliiliiliiliiliiliiliiliiliiling A data field may be one column wide, Or Several Columns wide. It must be wide enough to contain all the digits of the numerical value for the field, and the decimal point. But it may be wider. g----------------------- The data field description, therefore, would be: F5. 2 The "F" specifies Floating Point mode Storage. The "5" specifies five columns in the data field. The 12" specifies two digits in the fractional part Of the number. III. IIIIIIIIIHIIIIII IIIIHIII IIIII J2. IIIIllililiili III.iii.11111111111111111111111111111111111111111111111 Aºi -> To describe this data field in the Program that will be reading it, the width of the field must be specified. In Illiiliiliiliiliiliiliiliiliiliiliiliullilililiiliiliiliiliiliiline The description in a Fortran Source Program of this data field would be FQRMAT (F5. 2) addition, it must also be specified that the Value is Floating Point, and that there are two digits in the fractional part. R 77 Input FORMAT Description T8 Four: Imput Statements = m = m ms m = m = = m = m ms m = m = m ms m = m = m = m = m, m = m = as sº For example, if 1000 is to be read in as the value of "k," it could be punched in the first four columns of a card Numbers may also be read in that are to be value (s) of Fiaced Point variables. illililililiiliiliiliiliiliililiiliili The description of E this data field Would be I4 Where ''I'' Specifies Fiaced Point (Integer) mode; and where "4" specifies four Columns in the data field. F =========================== In a FORMAT Statement it would be Written as : F@RMAT (I4) | | agiliiliiliiliiliiliiliiliiliiliilililiiliiliiliiliiliiliiliiliiliiling There may be more columns in a data field than are needed to If the number is Fixed Point, the field should be described so that the number will be "right- justified" within it. The extra columns should be at the left of the number. contain the number in that field. | | IIIIIIIIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllſº ) --------------------------------------------------------------1 should be read in with an I9 data field description. The unused columns are treated as Zeros. Zeros to the left Of a Fixed Point number will not effect its value. Zeros to the right will increase its value by factors of 10. 79 Input FORMAT Description 80 Four: Imput Statements Floating Point numbers, therefore, V. may be punched * = =========== - - - - - - - - - - - - - - - - - - - anywhere in their data fields. [. : For example, 000008976 is equal to 8976 BUT 89760000 is not equal to 8976 Floating Point numbers, on the other hand, are not affected by zeros at the left or at the right. 00000473. 17600000 is equal to 473. 176 There may be many data fields on One card. The descriptions of them must account for every column beginning with column one, but need not account for all 80 columns. ! Af * º For example, the four fields could be described as follows I4, F10.3, F10.3, F10.3 Notice that all the columns from 1 to 34 are accounted for. None are omitted. Notice, too, that columns 35 through 80 are not described in the Format Statement. | | | | | | | | | al lm . 81 Multiple Fields 82 Four: Input Statements Several data fields in a row, having the same The data field descriptions for a card should description, may be described by multiplying be written in a FORMAT statement in the Fortran the description. program that reads the card: The three data field descriptions, F10.3, F10.3, F10.3 can be written as FQRMAT (I4, 3F10.3) This statement is not eacecuted. Its only purpose 3F10, 3 is to supply information for the statement which, The "3" before the "F" means that there are when executed, actually causes the card to be read. three fields described. guilliluliiiniiniiiuuuuuuuuuniliiliiliiliiliiliiliiling = The statement which, when = executed, causes the card to = be read is a R E A D state- # ment. IIIIHIIIIIIIII IIIIIIHIIIIIIIIIIIIIIIIIHIIII IIIIIIIIIIIIII IIIIIIIII | IIIIIIIIIIHIIIIIIIIIIII IIIIII IIIHIIIIIII IIHIIIIIIIIIHIIII IIIITU- The effect of the execution of this READ statement will be to store one thousand for the Value Of N. Statement that describes the card to be read, Fºllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllli and where the "Variable List" is a list of the variables where the numbers are to be stored. |- The general form of a R E A D statement is READ n, Variable List Where "n" is the number of the FOR MAT l N. This card could be read in with these Statements: F- I : Thus, to read this card, : : | | | ! | | | | | the following 4 FQRMAT (I4, 3F10.3) F@RMAT and READ 4, N, X, Y, Z READ statements -- | -- _ could be used: kā ſ 3 FQRMAT (I9) : |||||||||IIIII IIII IIHIIIHIIIHIIIIHIIIHIIIIIII * i.…:…~~~~ After execution of H. gºint Statement N = 3 X = 16. 341 Y = 14. 942 and Z = 12. 131 | 83 READ Statements 84 Four: Imput Statements *IIIHIIIIIIHIIIIIIIIIIIIIIIIIIITIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlllllllllllllllllllllllllllllll. * * J The READ statement will cause a value to be read in for every variable On the variable list. Each variable requires a FORMAT description. Nº. * There should be agreement of mode. There is a one-to-one positional correspondence between the variables on the list and the description in the FOR M A T Statement. The number in the first data field, the one described by the first descrip- tion, is stored in the first variable on the variable list. Integer number in the data field; Fixed Point (I) description in the FOR MAT statement; Fixed Point variable in the list. Floating Point number in the data field; Floating Point (F) description in the FOR M A T state m ent ; Floating Point Variable in the list. The numerical value in the second data field becomes the value of the second variable on the list. The third value is assigned to the third variable, etc. This process continues until every variable On the list has a value assigned to it. w - 4. - 4. Descriptions in the FORMAT statement Several cards can be read with the same apply consecutively to variables on the list. FORMAT statement during the execution of one R E A D statement. If the last description has been applied and if there are still more variables on the list, the FORMAT descriptions are repeated from the left parenthesis, but apply to the next card following the one just read. The R E A D statement continues to read in numbers as long as there are variables on its list for which no values have yet been read in. El |- EIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIll: Values for subscripted variables may be read in the tº Same Way. Filiiliiliiliiliiliiiiiiiiiiiiiiiiliiliiliiliiliiliili º For example, 33 FQRMAT (F10.3, F8. 2) READ 33, A, B, C, D, E, F, G, H would read in a value for "A" and "B" from the first card, then return to the beginning of the FORMAT statement and read in two values from the second card for "C" and "D", two for "E" and "F" from the third card, and for "G" and "H" from the fourth Card. | For example, to read in values for the subscripted variable X(I) where the subscript "I" runs from one to fifteen, the following R E A D statement could be used: 5 READ 11, x(t), x(2), x(3), x(4), x(5), X(6), X(7), X(8), X(9), X(10), X(11), X(12), X(13), X(14), X(15) 1 1 i * - ſº tº º º La L = tº a ºn I-, -, ºn tº ºn tº I- - ºn tº º ºs º ºn tº mº m = m ms m ºn m ºn tº m ms wºn m ºn m ºn m ms tº ºn tº M II m = m = m m = 85 ! Relations between Fields, Descriptions, and the Wariable list 86 Four: Imput Statements illlllllllllllllllllllllllllllllllllllllllllllllllllilililililililillº: But this rather lengthy (and tiring) procedure can be short- ened considerably by using a technique called "List Control. "E 7IIIllilllllllllllllllllllllllllllllllllllllllllllllliililililllllllli i = m, n is the range of the subscript iſilliililillililililililiiliiliiliiliiliiliiliiliiliiliiliiiuuuuuuuuuuliiniiiIIII The general form of List Control is (x(i), i = m, n) where x(i) is the subscripted variable and In a READ statement, values will be read in and stored in "m" and succeeding locations until and including ''n.'' When using subscripted variables, the number of values that will be read in is determined by the Tange of the subscript. This range is specified in the List * For example, 44 F@RMAT (7F10.3) READ 44, (X(I), I = 1, 7) | : will read in eight values from the data : card for X(1), X(2), X(3), X(4). . . X(7), ißpectively. : Fºllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll List Control is, therefore, a special technique that can be used to read in the values of a Control. IIIIIIIIIIIIIIIIIHIIIIIIIIIIIIHIIIIIIIII IIIIIHIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIII IIIIII: subscripted variable. ||||||I||||III.IIIIII IIIHIIIHIIIIHIIIHIIIIIII IIII IIII IIIIIII g this combination, 66 FQRMAT (7F10.3) READ 66, (X(I), I = 1,700) seven values will be read from the first card for X(1) through X(7). Repeating the FORMAT description and reading from the next card, seven more values will be read for X(8) to X(14), etc. ºn m = m = m = m = m = m * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = + : Usin This process of reading from the next card and repeating the FORMAT description will continue until the List is exhausted. The R E A D statement will continue to be executed until X(700) has a value read in for it. At that point the R E A D statement will be finished, and control will pass to the next Statement. {- & I I ** = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ſº I ºn tº ſº tº m = m = = = = H ** | | | | : On a tabulating card, a group of : : columns containing numbers to : @ : be read in as one numerical value ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - : is called a field. : : Whenever a READ statement is : : : - : executed, it reads values from : -----------------------------Rºsweg-55-5-77; : the next data card according to : : the descriptions Specified in a : &- : Statement. : : : : : One data field is : * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [. e ANSWER ON P. 171 : read in for every : On the : : : *-ºn- : º var. : : fields will be : : How many data fields will be : ---------7Fºrº-ºº: : d by thi : ; read by a READ statement that ; : j' 1S : i has five variables on its : - & | : statement? : i----º:--------------- : READ 62, A, B, C : ANSWER ON P. 175 1.----------------------- º ANS . 172 #. many areas": ; FORMAT statements : : are on the card : : describe the : idescribed by this : : : : Statement? : ; on data cards. : #62 FGRMAT (3F10.4): -------------iſsºr:FF-º: *---------------------- P. 165 Exºrcises 87 88 Four: Imput Statements tº º sº sº tº sº tº ºn tº gº ºn ºf ºr ºn ºf tº º ſº tº E - sº ºn I ºf ſº, º ºs ºn tº Wº ºn tº ºn * : How many data cards will be : ©...... * = m tº ºn tº ºn m = m ºn mº m tº mº m tº ºn an ºn tº * read by these statements? : ! How many data fields are: ; 62 FøRMAT (3F10.4) : : on the card described by : ; READ 62, A, B, C H ; this statement? : +---------------------------------- i ; 23 FQRMAT (10F 8. 3) : ANSWER ON P, 172 +-------------------------- ANSWER ON P, 169 F------------------- tº ºn tº ºn tº tº sº ºn tº ºn tº ºn m = - - - - - E tº tº ºf T : How many data fields will be : : read by a READ statement that : * • f * * Lºº ºn tº tº ºn tº ºn tº ºn tº ºn ºn tº º ºſ º- E-1 tº ºn tº ºn tº sº ºn tº El tº E - ºn tº E- ºn tº ºn m : has one º º variables On its : : How many data cards will be : : Variable List'. : ! read by these statements? : : : ; 23 FGRMAT (10F8.3) : i----------------------------------------- -: : READ 23, (Z(K), K = 1, 100) : ANSWER ON P. 173 i---------- tº L_ _ _ _ _ _ ºn tº gº tº tº tº ºn tº Lº Lº tº tº ºn tº E → E. i "RNSWFF"5R-E-777 How many data cards will be read by these two statements'? 44 F@RMAT (I4) How many data fields will be read by this statement? @. I 3 - 3 - 2 3. 5 tº tº º 'º - El ºn ºn tº ºt tº Lº - ºn tº ºn ºn tº ºn ºn tº gº ºn : How many data fields will be : ºn tº gº ºn ºn ſº ſº tº ſº ſº ºn I-, º ſº ºn tº E tº E. Leº ºn tº ſº tº El ºl tº ºn tº ºn tº ºn tº º FR57:F-5R-E-17: : read in by this statement? : ANSWER ON P. 175 #READ 65, (A(M), M = 1, N) : * = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * M. 5 * * * * * * * * * * * * * * * * = - - - - - - - - - - - - - - - - - - - - * * * * * * | On the first line of a fresh coding sheet, write a subroutine-defining statement : for a Subroutine to be called INPUT. Begin this Statement in column 7. f * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = F - - - - - - - - - - - - - - - - - - - - - - - - - - - Did your statement look like this? >- - - - - - - SUBROUTINE INPUT * * * * * * * tº tº tº Lºs - I -, -, -, -, º sº E = tº E tº Illlllllllllllllll III III III IIIIIII IIIII III IIIIII III IIIIII III III IIIII Correct it so that it does. This is the correct form of a = subroutine-defining Statement. ziliili IIIHIIIIIIIHIIIIIIIIIIlliiIII.iii.III.iii.III.iii.III IIIIIIIIIIHIII: | ----ºf-ºf-fºr::::::::------. DIMENSION Statement for a variable called X. Make provision for a maximum of 1000 storage 19% ſigns.[2]-}. —) Input Task and Diagnosis 89 90 - Four: Imput Statements F----- tº ºn tº ºn tº - sº tº sº º ºs m m imm mm mm m in m tº º ºs º-, -, -t = - tº tº - - - tº Lº º ºg º ºſ º ºs º Lºſ I. In m ºn ºn m º f tº ºn I- tº ºn tº I- - - - - - tº tº tº ºn t- tº- tº tº I- tº- tº E tº I- tº- tº tº tº I- - - tº -: L : : ; Did your statement look like | | T - | : The function of a DIMENSION Statement : ; this : : is to instruct the Compiler to set aside a : : DIMENSIQN X(1000) : : Specified number of storage locations for a : Wºm m ms m m m m F------------- tº- - ºn tº tº ºn I- - - - - - = * * : variable that is to be subscripted. The : -- | : number of locations is specified by the : : number in parentheses after the name : : Of the variable. This number must be : : a Fixed Point Constant. : : : }; Write a COMMON Statement º * * * * * * * * * * * * * * * * * * * * * = = = = * * * * * * * * * * * * * * tº gº tº ºn tº ºn ºn ºn m = m º ºs º ºs ºn tº ºn tº ºn ºl : assigning : I : N and X to COMMON storage : : locations. : * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * J. tº ºn tº ºn tº ºn tº ºn tº tº I- I ºn ºn tº ºn tº * = - - - - - - - - - - - - - - - - # not, the Order is not important, except that it should be th: {- Hsame in later COMMON statements. : X here is named only. No subscript notation is needed. The Compiler will learn from the DIMENSION statement that X . requires more than one storage location. : {N will automatically be assigned one storage location. : Did your statement look like this: CQMMGN N, X * = = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = YES Nº. DO your last two statements look something like this: 63 F@RMAT (I4) READ 63, N —) Write and number a FORMAT statement that describes a card with One Fixed Point data field having a width of four columns. lm "I º | : Next, write a READ statement : that reads in the value of a : variable called N, according : to the FORMAT statement you : just wrote. | The READ statement must refer to a FORMAT statement by using the number of that FORMAT Statement. In the "correct" answer the FORMAT statement was number 63. Your answer may have a different number. This is all right. If necessary, repair yOur Statements. ºn m = = * * * * * * * * * * ºf E - E - ºn tº m tº m ms m m ms ºn m = m ºn m m = m = m = m. m = H Assume that the values to be read in for X are already punched in tabulating cards. {– Assume that there are three digits in the fraction, that each data field is eight columns wide, and that there are ten data fields On a card. Now Write and number a FORMAT Statement to be used to read these Values. A j 91 Input Task and Diagnosis 92 Four: Imput Statements Now write a READ statement, referring to the FORMAT statement you just º | I | I I I | —): wrote. Using List Control, specify that | I | I I | I I º N values are to be read in for the subscripted variable X(I). F = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * : Do your FORMAT and READ : : statements look something ;4 : like this: i" | . : 15 FQRMAT (10 F8. 3) : H : }< YES : READ 15, (X(I), I = 1, N) : N * = - - - - - - - - - - - tº m ºn tº sº. In ºn tº ſº tº ºn tº m ºn º ºs º ºn m = m ºn ºn mº m sº me m ms tº m F------------- ſº º sº ºn tº º ºs º ºn tº ºn ſº tº E - Gº tº º Lº Lº Gº tº Lº º ſº tº ºn ºn tº ºn tº ºn tº º tº E tº º ºs ºn tº m ºn m ºn tº m ºn m * : The FORMAT statement number must be the same as the : : reference to it in the READ statement. : | : The number of values to be read in by the READ : : statement is specified by List Control. : | w ; (X(I), I = 1, N) : k--------- gº tº ºn tº ºn tº sº tº ºn ºn ºn ºn tº ºn tº ºn tº ºt tº E tº º sº ºn tº ſº Jº º sº ºm m ºn m - ºn m = m ºn ºn tº º E - tº ºn ºn tº ºn ºn m m = nº T “ºr * Aſ l r = - - - - - - - - - - - - - - - - - - tº E tº tº E tº ºn I-s tº sº m - f Whatever value is read in for N in the previous READ"T" i : : : Statement will determine the upper limit of the : : The work required of this : l I I. - - I ; value of the subscript, I., if 100 is rºad in for N, 100 —): sº ...; : values of X will be read in in this READ i icº ; statement List Control. If necessary, repair your : : Main Program e; : READ and FORMAT statements. : : gram. : * = - - - - - - - - - - - - - - - - - - ºn tº tº ºn tº tº ºn tº ºn tº tºº lºs tº ºn tº tº a ºn I- ºn tº ºn nº ºn tº ºt m ºn m = m ms tº m ms m m ºn m m ºn m m mſ. : : * * * * * * * * * * * * * * * * * * * * * * * * * * * = * * * * F-------------------------- : Did your statement : H look like this: ;4 | *WT : RETURN : Ł-1 tº ºn tº ºn tº I-I ºn ºn g º ºſ ºn I-, - tº ºn tº ºn tº ºs ºn m = tº ! | f If not, repair it. This * i ! statement returns * * * * * * * * * * * * * * * * * * * * * * * = = = - - - - - - - - - ** : control to the : This subroutine now requires : : Main Program. : only one more statement: : * * * * * * * * * * * * * * * * * * * * * * * * = = - +): the One that marks its end. : : Write that Statement. : * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - J. * = tº ºn tº m ºn m = º ºs º ºs º ºs ºn ºn tº gº ºn ºn tº m = m = m. r sº tº tº sº ºn tº º tºº ºn ºn tº ºne - ºn tº ºn * = m = m = m = m = m. Does it look like this: END If so, you have completed {{ the task for this Section. - tº - $º E- - ºn tº- º -- ſº ºn ſº º º º - tº - m i 93 Input Task and Diagnosis Part Five: ARTHIMETIC EXPRESSIONS Expressions e The Hierarchy of Operations e Parentheses e Ex- ercises o Mixed Expressions e Exercises & IIIIHIIIIIIIII III IIIIII III III IIIIIIIII IIII IIIIIlllllllllllllllllllliſ III IIIllili IIIll! II An eacpression is a series of variables and/or constants connected by arithmetic operation symbols. A + B – ALPHA (9) ** 2 is an arithmetic expression. A numerical value of an expression is calculated during the execution of the Object Program. º R t tº- se w - *: 94 The following examples are expressions: The following arithmetic operations may be P + k V PETER +* JøHN specified in an expression: T / D 3.1416/PEI FORTRAN SYMBOL OPERATION E + F 89. 65 ** ALPHA >k >k tº & A - B B - 3. 975 Exponentiation Division X + Y S + 2.0 Multiplication Subtraction Addition & Jº =III.iiiiiiniiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiiniiiiiiiiiiiuuuuuuuuuiliiliiiiiili In an expression, there may be any number (within reason) of variables and/or constants connected by operation symbols: A + B + C / D ++ F + G ++ 2.876 - PETER (A : B & # G* - PETER) in normal algebraic notation. 2. In calculating the value of an expression, only one arithmetic Operation is done at a time. The order in which they are done is (and must be) specified in the expression itself. Or, there may be just one variable, BAKER, or one constant, 89.64. Iſiſſil IIIIſIIIIIIIIIIſ IIIIIIIHIIIIHIIIIIHIIIHIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIHIIIIIIIHIIIHIIIIHIIllilillili; d ſ :1LIIIIIIIIIIIIIIIIIIIllili III IIIIIIHIIIIIIllili IIIIHIIIIllllllllllllllllliſ, 95 The Hierarchy of Operations 96 Five: Arithmetic Expressions The Hierarchy of Operations rules state that in every arithmetic expression: agiliiliilililiiliiliiliiliiliiliiliiliiliiliiliililiiliiiniiiiiiiiile The rules governing the order of operations in expressions are called: The Hierarchy of Operations. III IIIIIHIIIII IIIIIIIIIIIIIIIIII IIIIIHIIIIIHIIII IIIIIIHIII IIIIIIIIII Exponentiation (**) is done first, Multiplication (*) and Division (/) second, and Addition (+) and Subtraction (-) last. ) | RIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIIIIllllllllllllllllllllllllllll!”. In the expression, X – Z + A ** F. the exponentiation, A **F, is calculated first, the result is multiplied by Z, and the result griliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliililiiliiliiliili This means that in the expression, A + B/C the division of B by C is done first. The result Of that of that multiplication is sub- tracted from X. #4 F Filiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiliiliiliiliiliiliili division is then added to A. * SUITIIIIHIII III IIII IIIIIHIIIII IIIIIII IIIIIIIIIII IIII III III IIIIIII IIII tº. J 2. Tº : There are three "levels" in the Hierarchy of Operations: (1) Exponentiation (2) Multiplication and Division (3) Addition and Subtraction FiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiliiliiliiliiliiIIII Each first level operation (exponentiation) in an expression is done first, from left to right. Operations at the second level (Multiplication and Division) are done next, from left to right. Operations at the third level (Addition and Subtraction) are done next, from left to right. To alter the order indicated by the Hierarchy of Operations, parentheses may be added. Those parts of an expression that are enclosed in parentheses will be calculated before those that are not. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - : In the expression A * B/C * D/E all the operations are | second level; therefore, the first multiplication (A * B) is done first. This result is divided by C. his result is multiplied by D. This result is divided by E. Thus, in the expression, (A + B)/C A will be added to B first iſſiliiliiliiliiliiliiliiliiliiliiiiuuuuuuuuuuniliiliiliiliº even though it is a third # Thus, it is possible (and # advisable) to analyze precisely :: the Order in which each level of # operation will be done in any := expression. level operation, because it is enclosed in parentheses. This sum will be divided by C second. t tº ºn 'fillllllllllllllllllllllllllllllllllllllllllllllllllllllllliſ IIIIIIIII: 97 Parentheses 98 Five: Arithmetic Expressions | W ill then be the power; O which A is raised. t ºn m = m s m = m = m = m = m = m = m = m = m = T : There may be more than one operation inside a pair of º : In the expression : ; parentheses: : >k | #A ** (X - Z) : : (A + B/C)* D : : - : : In this case, the operations inside the parentheses will be : ; the Z will be X : done in the order indicated by the Hierarchy of Operations: : ;subtracted from : : B/C first; added to A second, raised to D third. : : first. This difference; * ------------------------------- tº E tº I-, -, -, - Lº tº is tº tº ºn tº ſº I- tº ºn tº sº ºn tº tº I- E- ºn tº º Lºs L. ºn sº | : | | W. The Hierarchy of Operations inside a pair of parentheses is the same as the Hierarchy of Operations outside the parentheses. And, the Hierarchy inside may be altered by using an additional set of paired parentheses: ((A + B)/C) * D guiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiling The Way most programmers use the parentheses rule and the Hierarchy of Operations is this: first, they write an expression that they believe will accomplish the operations they desire; then they analyze it to determine whether it really does. Operations within the innermost pair of parentheses are performed first, as indicated by the Hierarchy of Operations. iſiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiliiliiliiliº Finally, they add parentheses or otherwise change the expression so that it will do whatever is originally intended. IIII III, IIIIIlliili IIIIIIIlliili IIIIHIIIIIIIII.11 Illililill 111111111FE | The next innermost next, etc., until the expression is one numerical value. | º R In writing an expression be careful not to have two operations in a row. For example, A + - B is illegal. To repair it, parentheses are added: A + (-B) is legal. siliiliiliiliiliiliiliiliiliiliiliiliiliililiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliº = Fortran expression are operations, E and never the sign of a variable or constant. = Therefore, (-B) should not be thought of as a negative number. The ninus symbol in this example is an operation Symbol, not a sign. 7IIIllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: SulilililiiliiliiliiliiliiliiliilililililililililliiIIIlliliiliiIIIIIIIllililiiliiliiliiliilº Thus, (-B) is compiled as though there were a Zero before the m in u S S ign. (-B) means (0.0 - B) Fillilillil IIIIIllili III III IIIIIIIIIIIIIIIIHIIIIIIIIIIIHIII IIIIIIIIIIIIII IIIIIIII IIIIIIIll IIII º R t 99 Parentheses 100 - Five: Arithmetic Expressions (3) 7. 0 + 8.0/4.0 8.0 / 4.0 + 8.0 | º : l | e e g T tº | : * : : Which arithmetic ; ; which : i operation wou : : operation would : : this be performed ; | º ; : first in thi ; be performed : ; expression? ; 11rst in this ; first in this | | : : expression? : | tº : : (A + B) ** 2 | ; A + B / C : : expression? : | : i----------------------- : (A + B) / C H 1--------7Rsº-ºf-Fº: ANSWER ON P. 1 3 --------7Rºtº-º: ; what : : What is the : : What is the value ; : ; value Of this | : L i is the value ; | * : ; of this : ; of this : : expression? : : : T * : expression? : ; (8.0 + 8.0) : : expression? : ; 8.0/4.0 ; : : ; 8.0 + 8.0 : * m ºn as m ºn m = m ms as m m ms m ms m m is m m in m msl. +----------------------- : ;G)....................” ANSWER ON P. 171 : ; : What is the : ©---------------------- "ºº-ºº: ; value of this : What is the : expression? : value of this : : expression? : : : : ANSWER ON P. 165 I | | | | | w ANSWER ON P. 168 @. @. What is the value - What is the Of this What is the value value Of this expression? of this expression? expression? (8.0 + 3.0) / 4.0 (A + B) / if 2.0 - (3.0 + 4.0) m = m = - m = m = m ms is ºn m = m = = m = * * * ANSWER ON P. 162 º º ANSWER ON P. 172 : What is the value i I---------- |- ſº ſº, ſº I - - - ---- : Of this : | Write the Fortran : : expression? : ſº tº ſº tº ſº tº tº ºn tº mº m at am ºn tº tº ſº mº m º ºs ºn ºn tº m ºn mº m ºn tº m : expression for the : ! : Now rewrite the expression : : following algebraic : :º ºg tº ºn tº ºn 2.9. 3.9 + 4.0 tº gº ºn tº i ; using the following values for; ; formula: : ANSWERTENTE. Tºg ; each of the variables: : : a + b – cd” : ; A = 1.0 B = 2.0 : € + C : | ---------7Rsº-º-º-º: : C = 3.0 D = 4.0 : @5. ON P. 173 : : F- tº º º ºs º- E - ſº tº ºs º ºn tº º º mº m ºn tº mº m = m tº gº gº ºn ºn * * * * * * * * * * * * * * i:…! ; : : - E- - - - - - - - - - -----ºf-ºf-prººf : Now perform the operation indicated in : ; the parentheses. Then remove the : ; parentheses, and rewrite the formula, : : still using the numbers for the variables. : i. tº º tº ſº tº tº I- (- - - - ºn tº ºn tº º, ºn ºn tº I- tº - - --~~~~~ ANSWER ON P. 175 101 Exercises 102 Five: Arithmetic Expressions : Now, performing : I o : the first-level : : operations : ©!--~~~~ ; in the Hierarcy of : : : : Operations, : : : ; carry out the : : Next, perform ;exponentiation, : : the left-most : : and rewrite : : third-level : : the : operation and : tº:-------------- : rewrite the : ANSWER ON P. 169 : formula. : | | ANSWER ON P. 169 : Now, working from the left, I | s | ; perform the first second- : i level operation, and rewrite : : the formula. : ---------------------Rºswer-55-5-154 ©-------- * - ºn . . . . . . . . . . -: : NOW : : perform the : F----------------------------------. : last remaining : i Now, again moving from the ; ; Operation. : : left, perform the other second- . *------------------ -------- : level operation and rewrite the ANSWER ON P. 172 ; formula. : ---------------------Rºsier-ER-E-774 III.iiiiiiiiiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiling = Calculations are carried out in >= the computer in Fixed Point = Mode or in Floating Point Mode. : = tº . tºº *IIIIIIIIIIIIIIIIIIHIIIIIIlllllllllllllllllllllllllllllllllllllllllll griliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiling Floating Point calculations are used for most arithmetic computations. A reminder: Integer Mode (Fixed Point) variables 7must have I J K L M Or N as the first character. Floating Point Mode variables must begin with A B C D E F G H Q P Q R S T U V W X Y. Z Fixed Point calculations are used =primarily for counting and indexing Operations. -> º 7 S. * - - - - - - - - - - - - - - - - - - - - - - 1 | : For example, : Fixed Point Mode. =: 103 J Mixed Expressions L T : A + 1 : : : . g -- : In general, the calculations specified : ! is a 7miaced expression: : | ;because "A" is in the : in One expression must be entirely : I e - ić- fronuns Point Mode, : : of one mode, and must not be a mixture : I [. | and "I" is in the : : of modes. : | mm mm mm mm mm mm mm mm mm mm mm m = m, m = m = * * * * * * * * = mx = m = m = = * * * * * * * * * * * * * * = m = nº : 104 Five: Arithmetic Expressions ! and 3. 1416 is and constants may be raised Floating Point. to Fiaced Point powers. T : Similarly, : [. : J 3.1416 : & ; is also a mixed : The only eacception : expression: to the Mixed Expression : because "J" is | rule is eacponentiation. : Fixed Point ) Floating Point variables l : l | l Mixed Expressions are illegal, with one exception. all IIIIIIIHIIIIIIIIIIIIIIIIIIIII IIHIIIII IIHIIIII III IIIIHIIIIHIIIHIIIIIIIHIJ2: III]]||||III IIII III, III III III III III III III IIIP tº- The illegality of mixed expressions is not arbitrary. It follows Raising fractional from the different ways numbers (Floating the numbers are stored in the computer. Point) to whole ºm number (Fixed ** 2 is legal ** K is legal j r º F Point) powers is : alliilillilillilililililililililililill: Raising whole numbers to fractional powers = is not reasonable because the result will be = fractional. Fiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiif: reasonable 2 ** X is not legal N ** 2.0 is not legal ecause the result b will be fractional . Filiiliililiiliiliiliiliiliililiiliiliiliilillſ; i ) What mode are the following (3) I | | : H | What mod ! : : Fortran : | IQOCle : What mode are | : Variables 2 : : are the : : the following : : & ſº tº : | following : : : : FOrt | L Fortrain : A B : O I’t Tal] : : Variables? : i-----------------------, : Expressions? : : ANSW P. 173 : A + B : : K M : | | : A / C : : A + + C : What mode are I | º : : : the following : : What mode is : : Fortran : : : ©--~~~~ : Expressions? : : X + + 2 : : Is the following : : K -- M : +------------issº-ºr-º-º: ; ºn ; : K - M. : º €9, all : I | | Cº------~~~~ ; les ; ; ; ; M ; : : : X + + 2 ; : K / M : : Is the following : -------------Rºswig-55-5-133 i K + k f : tº : --------Rºsºf-ºf-F-Tº: | expression : : legal 7 : i. 2 ++ X 3 WEFºrt Hºrrº 9 105 Exercises Part Six: ARTHIMETIC STATEMENTS General Form e Incrementing e Accumulating O Defining a Vari- able O Conversion O Exercises | - A Fortran Arithmetic Statement has • A = B -- C : the following general form: 1S a. : o Fortran Arithmetic ; Variable = Expression Statement. : | | After the numerical value of the expression is calculated, its value is Stored as the value of the variable On the left of the equal sign. F - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - X = ALPHA / (C ** I)-FACTOR / SLIDE = m = m = m, m = * * * * * * * * * * * * * * * * * * * r : I = K L : is a Fortran Arithmetic Statement. i is a Fortran Arithmetic {{ | I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * tº:--------------- 106 The effect Of an Arithmetic Statement (when executed) is first to perform all the Operations in the expression to the right of the equal sign, reducing that expression to one numerical value. Then this value is stored in the storage location for the variable named on the left of the equal sign. Everytime a variable is set equal to the value of an express i O n, Variable = Expression the previous value of the variable is replaced by the new value. The old value (if any) is lost. m in m = m in m = m = n = m = m as m = n = * * * * * * * * * * * In Fortran, INCREMENTING may be accomplished by a Statement like this: I = I + 1 ºn m = m. m. m. m = m = m = m = m = as m. m = = m = * * * = - - - - º I | | T I | uſiliiliiliiliiliililiiliiliiliiliiliiliiliiiniiiiiiiiiiiuuuuuuuuuuuuuuuuuliº The effect Of is to add One to the Current value Of I. In other words, it adds one to the current value of I. III IIII IIIIII IIITIIIllilillili IIIIIllil IIIlilillllllli IIIIIIIIIII IIIIIIIHIIIIIIIIIIIII IIIſ. I = I + 1 I and then to store this sum back in Incrementing 107 108 Six: Arithmetic Statements F------------------------------- In Fortran, ACCUMULATING A TOTAL may be accomplished by a Statement like this: SUMX = SUMX + X * = * * * * * * * = = = = * * * * * * * * * * * * * * * * * * iſiiiiiiiiiiiiliiliiliiliil III.ii.11111111111HIIII III.iii.111111111111111: E. Note that in all the examples º cited so far, it has been assumed= that all the variables in the expression had "current values." ăuluiuluiuluiuluiuluiuluiuliiiniiniiiuuuliiniiniiſ; • * *. t II III IIII IIII III IIII IIHIII IIII III.ii.IIII III IIIIIII IIIIHIIIHIII IIIIII III III IIIllili III IIII IIHIIIIHL: |For a variable to have a current value, it must The effect Of SUMX = SUMX + X is to add the current value Of X to the current value of SUMX and then to store the sum back in - have been used in some previous statement which, when executed, would have the effect of Storing a value in its storage location. |Variables that have current values are said to be "'defined. '' SUMX. | * :1 IIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll Variables on the left side of the equal sign in arithmetic statements * iNIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIHIIIIIIIIIIIIIIIIHIIIII IIIIIIIIIIIIIIIIIIIIIIIHIIIIa. t-, Variables that appear in COMMON Statements are also said to be defined, be- cause their value presumably has been are defined because the established in some previous Subroutine numerical value of the expression or in the Main Program. will be stored in the variable. :1 l r agiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliilill Variables appearing on the Variable List of a READ State- mºlent are defined. Numerical = values are read in for them. - FIIII III.iii.III.iii.iiitiiliiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiff illllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll!”. The indexing variable in a DO statement (to be discussed later) aſiliiliiliiliiliiliiliiliililti iiiliiliiliiliiliiliiliiliiliiliiliilillº: #In all arithmetic statements cited Eso far, the variable on the left of is defined. The indexing variable is INITIALIZED and INCREMENTED each time the DO- loop is repeated. t h e eq Ul al S l g Il h al S b e € Il O f t h e S al Iſl e mode as the expression. This need not be the case. IIIIIIIIIIIIIHIIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIIHIIIllilillillilllll | * 109 Conversion 110 Six: Arithmetic Statements If a Floating Point variable is set equal to a Fixed Point expression, F == gº ºu ºn tº ſº ſº. [… my sº m ms m ms m ms tº us m tº an ºn m #For example, : if N equals 4 FLN = N the value of the Fixed Point expression is converted to Floating Point mode before it is stored in the Floating Point variable. A Fixed Point variable may be set equal to a Floating Point expression. In this case, the value of the Floating Point expression is "truncated." The fractional part of the value is discarded, and the Fixed Point variable is set equal to the whole part of the value of the Floating Point expression. F = m = = * * * = F.T.."; BºigtäTää"; J = B will set J equal to 64. The entire fractional part is truncated. = = m = m = m = m = m = m = m = m = = = m = m = = m = @). ----------------------1 Write an arithmetic Statement that will add One to the variable I. ANSWER ON P. l 7 2 (3) Write an arithmetic Statenment that Will increase SUMX by the Current Value Of X. What would be the value of : Y after execution of this : Sequence of arithmetic . statements? : tº ſº º U = T + 2.0 - R = 8. 0 Y = U/S : S = 4. 0 : T = R + S : Write an arithmetic Statement that will Set the Variable DIST equal to the expression, TIME, multiplied by RATE. RNSWERTöNTE º l 7 @). Write an arithmetic statement that will increase the value of SUMX by X(I). P l ==== * = = * = = = H ANSWER ON P. 17O ----------------------1 The general form of an arithmetic Statement in Fortran is P. 16 2 What would be the value of X after execution of the following sequence of arithmetic Statements? A = 3.5 B = 4.5 X = A + B Exercises 111 EIILIIIIIIHIIII IIIIHIIIIIIIIIHIIII IIHIIII III Part Seven: CONTROL STATEMENTS Normal Flow of Control © Unconditional Transfer of Control © Conditional Trans- fer of Control © IF-Loops e DO-Loops e Exercises e A Sorting Example © Sort- ing Task O Diagnosis The Order in which Statements are executed is extremely important in every program. IIIIIIIIIIIHIIIIIIIIIHIIIIIIHIIIIIIIHIIIII iſiliiliiliiliiliiliiliiliiliiliiliiliiliiliuliiliiliiliiliiliiliiliuliº ->= In Fortran programs, the Normal Flow of Control (the normal order of execution) is the actual sequence in r: Normal Flow of Control means that when all the Operations specified in one Statement have been COm- pleted, control passes to the next Statement forward in Sequence. which the statements appear in the program. - 112 Normal Flow of Control applies Normal Flow of Control does not apply to non- executable statements. It does not apply to to D IM ENSIGN, C GMM GN, F @ RM AT, C @ M M E N T statements. Arithmetic Statements READ Statements PRINT Statements Whenever these kinds of statements appear in the path of control, they are skipped, i. e., Control ignores them. - - - J - - - ºn tº +– There is, however, a group of Fortran Control statements illlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: tº- There are three basic kinds of Control Statements: that CauSeS COntrol to be transfered to a specified statement that may Unconditional Transfer j| Or may not be the next one in sequence. Conditional Transfer LOOp-defining tº * 113 NOrmal FIDW Of Control 114 Seven: Control Statements The general form of a simple unconditional transfer Statement is G@ TQ n where ''n'' is the number of some other statement in the program. lº HIIIIIIIIIIIITIIIIIIIIIIIIllillllllllllllllllllllllllllllllllll )# en executed, the GO T statement unconditionally O | transferS Control to the Statement number specified. ºſillllllllllllllllllllllllllllllllllllllllllllllliLIIIIIIIIIIIIHIIIII REMINDER = * * * * * * * * * * * * * * * * * * * * * * * * * * * * Bºjillllllllliliſ[IIIIIIIIIIIIIIIIIIIIIIIIIIIII: Any statement in a program HIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIHIIIIIIIIIIIIII For example, control to One may be 4- The GO TO statement is numbered for called an unconditional transfer v >k >k reference - 55 X = Y + Z / A ** 2 purposes. because it always transfers One reason for numbering a Statement is SO particular statement every time it is executed. {- 74 G3 to 55 : When control reaches ! statement 74, the GO TO 55 : causes it to transfer to ištátēment-32: that there may be a GO TO Statement that transfers control = to it. 711 IIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIlirt Fl : IIIIllili IIIHIIIHIIIIIIIIIIIIIIIIIHIIIIIII IIIIIIIIIIIHIIIIIIIIIHIIIII r: in Fortr'an transfers control to One iſiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiiliº = The basic conditional = uſliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiling = transfer statement in E The comditional transfer statement = Fortran is an IF = =: statement. E F Filiiliiliiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiif: of three statements depending On the value of a Specified Fortran expression. The general form of an IF statement is :IIIllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllſº IF (e) n1, m2, n 3 where "e" is any arithmetic expression, and where n1, n2, and n 3 are statement numbers. Pl IIIII IIII IIIIIIHITIII IIIII IIII III IIII IIIII III.IIIIIllilllllllllllllllll: Control is transfered to n 1 if "e" is negative. Control is transfered to n2 if "e" is zero. The branches of an IF Control is transfered to n; if "e" is positive. statement may all be forward in the program; they may all be backwards; or they may be a combination of the two types of branching. *. 115 Conditional Transfer of Control 116 Seven: Control Statements tº Lº Gº tº ſº tº a * * * * * * * * * * * * * * * * * illiiliiliiliiliiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiuuuuuuuuuuuliiiiiiiiiiiili An IF statement, then, is like a three- way fork. The Flow of Control is to one of three statements (specified in the IF For example, if you want to compute the value of FACTOR: statement). These statements may be anywhere in the program. ) using ALPHA on Some Occasions, IllililllllllllllllllllllllllllllllllliiIIHIIIIIlliiIIIHIIIlliiIIIIIIIllilillllllllllllllſ: and using BETA on other occasions, you could branch Control to eithero; In a Flow Diagram this problem would look like this: the two paths depending on the Alſº { : value of FACTOR SWITC H. Bºw FACTOR *** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ! ailiiliiliiliiliiliiiniiiiiiiiiiiiiiniiiiiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiliiliiliiliiliiliiliiliº F------~~~~ E = | E - [. = If the value of SWITCH is negative or zero, = i e : = control will pass from the IF statement to = i * program the problem would look like : = - | tº tº e e E E T = statement 10. FACTOR will be computed using = : 10 º "..” : = ALPHA. Control will pass (normally) to the #4 : GQ, TQ 30 : = E | E E * : = >k >k = GO TO statement. And then to statement 30, = : ; FACTOR = BETA 2 : # bypassing statement 20. = : tº tº º : ăilliiiniiiiiiiiiiii iliiliiliiliiliiliiiniiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliilif i-------- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - suiliiliiliiliiliiliiliiliililiiliiliiliiliiliililiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliili If the value of SWITCH is positive, control will pass from the IF statement J * ->= to statement 20, bypassing statement 10 and the GO TO Statement. FACTOR will be computed using BETA, and control will pass (normally) to statement 30. : º IIIIIHIIII III III IIIIIIIIIHIIIIIIIIIIIIIIIIHIIIIIII III.iiiliiliiling IF Statement may also The repeated branching of COntrol backwards by an IF statement is called an IF-loop. branch control backwards in a program. :IIIIIIHIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIHIIIIIIIHIIII | 117 lF-L00ps 118 | Seven: Control Statements tº. IIIHIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIllillllllllllllllllllllllllllllllllllllllllllll): The Counter to record the number Of times If you wanted to repeat a the series had been repeated, series of Statements ten times (i.e., construct a looping process), you would need three basic things. tºº A Counter, a Tester, and ); the loop, an Incrementer. º the Tester to keep control cycling within the loop until the tenth pass was completed then to transfer = C O Il t r O l t O t h e Il e X t e X e C Ul ta b 1 € S t al t e IYl € I} t O Ul t S l d € the Incrementer to increase the Counter by One at each pass in the loop. ;IIIIIIIIIIIIIIIIIllili IIIIllillf HIIIIIIIIIIIIIIIlliiIIIIHilllllllllllllllllllllllllllllllllllllllllllllllllſ: iiiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiling The IF statement would fulfill the three following functions: IIIHIIIHIIIIHIIIIIIIIII IIIIHIIIIHITIIIITIIIIIIIIIIIIIIIIHIIII III.11111|IIIllil III IIIIII: To accomplish this in a program, you could define a variable to be used as the counter; use an IF statement to { = w uniliiliiiniiniiniiniiniiniiiuuuuuuuuuuniliiiniif repeat the loop the prescribed number of times; and write a special Ammi arithmetic statement that would increment = 1. Testing the counter E = the counter by one at each pass. = variable at each pass = Filiili IIIIIIIIIIIIIIIIIIIIIIIIHIIIIIIIIIIIIIIIIllili IIIHIIIIIIIIIIIIIIIIIIIIIIIIIIHIIIIIllin = for equality with ten. = ñuuuuuuuuuuuuuuuuuuuuuuuuuä 3. p 2. Branching COntrol at each pass to the incrementing statement, which would increase the Taking control out of the loop after the tenth pass test and branching it to the next eXecutable Statement in the program. counter variable by one before going back to the first state- ment in the loop. -> : IIII III/IIIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll: IIIIIII IIIIIHIIIII IIIIIIII IIIIITIIIIIIIIIIIIº º & Illlllllllllllllllllllllllllſ IIIlllllllíIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII IIIIIIIIIIIIIIIIIIIIIIIIIII III IIIII As long as "I" is less than ten, the expression in the IF statement will be positive; 2nd control will branch to Jº The form could be like this: statement 75 where "I" will be in- I = 1 #(- cremented by one. Then control will = 45 be transferred back to statement 45. E tº ſe e As soon as (10 – I) is zero, control É 75 * º i I) 56, 56, 75 will branch to statement 56. = Gø TQ 45 *IIIIIIHIIIIIIlliiIIIIIllil|IIIIIIIIIIIII.iii.III.iiiIIIiliiliiiniiiiiiiiiiiiiiiiiiiiiiiiiiliiliiliiliiliiliiliº 56 119 |F-L00ps 120 Seven: Control Statements suillililililiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliig An easier way to set up loops is With a DO statement. A DO statement may be put at the beginning of the series of statements to be repeated. IIIIllil IIII III IIHIII IIIII IIHIIIIHIII III IIII IIIHIIIIHIII IIII IIIHIIIIII III IIIIII IIIIIIIſ. : ſ & J * guiiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii A DO statement differs from an IF Statement in the following manner: It specifies the counting (or index) variable, gives its initial and final value, and indicates the statement number of the last statement in the Series. : r The general form of a DO statement is DQ n i = m1, m2 Other Statements in the Series ''n'' is the Statement number of the last Statement in the series of statements to be repeated. "i" is the index variable. 1 t m 1" is the initial Value Of the index variable. f : m2" is the final value Of the index variable. ''n'' must be a statement number. "i" must be a Fixed Point variable "mi" must be a Fixed Point constant Or a Fixed Point variable. "m2" must be a Fixed Point constant Or a Fixed Point variable. 121 D0-100ps 122 Seven: Control Statements 1. IIIIIIIIIIIIIIIIIIIIIIIIIllili III IIIIIIIIIllili IIIIIIIII IIIIIIllilili IIIIIII IIIIIII IIHII): * All the Statements following the DO statement will be executed in sequence until control reaches Statement number 88. r For example, DQ 88 I = 1, 10 At this point, control will tº ſº tº loop back to the first statement after the DO Statement. ) ** Illil IIIllllllllllllllllllllllllllllllllllllllllllllllllllllllili IIIIII IIIIIIIII IIHIIIHIIII *H R † 88 cóNTINUE º -Illililllllllllllllllllliºl|IIIllilill||||IIIHIII III IIHITIII III IIITITIII III, IIII IIITIIIII IIIIIllill IIIllſº The CONTINUE statement is a dummy Statement that has no effect On the agiliiliiliiliililiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliº program. E After the sequence has been re- Épeated ten times, control will =pass to the next statement fol- Élowing the CONTINUE statement. Filiililiiliiliiliiliiliiliiliiliiliiliiiiiiiiiiuuliliiliiliiliili | It functions only as a convenient marker for the last statement in the range (the complete series of statements) of the DO Statement. : III IIIIIIIIIIIIIIIIIIIII IIHIIIII IIIHIIITIIIIIIIIIIIIIIIIIIIIIHIII III IIIIIIIIIIIITIIII IIII IIII IIIIIIIITIN: The "range" of a DO Statement Or DO-loop is the sequence of Statements included in it. The general form of a CONTINUE statement is n CQNTINUE where ''n'' is the Statement number specified in the DO statement. iiiiiiiiiiiiiiii iliiliiliiliiliiliile The first statement in the range of a DO-loop must be eacecwtable. It must not, for example, There is no limit5 be a FORMAT Statement. On the number of The last statement in the range StatementS that may be in the range of a DO must not be a transfer statement. It must not, for example, be a GO TO Or an IF statement. statement. Filllllllllllllllſ|[IIIIHIIIIIIIIIIIIIIr: r: *III IIIIIIIHIII IIIIHIII IIIIII IIIIIHIIIHIIIIIIIIIIIIHIIIIIIIIIIIIIIHIIIIIIIHIIIIIHIIIIIII]. You may have a statement in a DO-loop that transfers control out of the middle of the loop, but you iſſiliiliiliiliiliiliiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiII: You may have CALL StatementS in a DO-loop. i may not have a statement in your program that WOuld transfer control into the middle of the loop. iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiif: º R Y. º IIIIlliliſiliiliiliiliiliiliiliiiniiniiiiiuuulie Huililililiiliilliiliiliiliiliiliullililille And you may have DO- loops within DO-loops. You may have IF Statements in a DO-loop. - * r * :1 :IIIIIIHIIHIIIIII IIHIIIIHIIIHIIIIIIIHIII IIIIII T 123 D0-Loops 124 . Seven: Control Statements Loops within loops are executed as f O 1 1 O W S : EIIIllillllllllllllllllllllllllllllllllili IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII III III: P: The DO statement governing the Outer loop determines the number of times that control will reach the inner loop. Thus, an index variable (in a DO statement governing an When control reaches the inner loop on the first pass, it remains ) there until that loop is satisfied. outer loop) with parameters from one to one hundred, would cause control to reach the inner loop one hundred times. | Control then returns | to the remaining statements in the Fillllllllllllllllllllllllllllllllllllllllllllilili III IIIIII III.IIIII IIIIIIIIIII IIIIIIIIII.iiiIIIIIIII IIIIII III: : outer loop. It remains there until it reaches the last statement. ſ"; ; ;rººf-ºrgſgårſ;g";------------ Having completed the first pass, control then returns to the beginning of the outer loop and Starts the entire process Over again. DQ 99 I = 1, 100 Dò 53 J = 1, 50 tº ſº tº inner Outer tº gº tº loop loop 53 CQNTINUE 99 continue P- r -- - -- - - w HIIlliliiliiliiIIIllilill IIIIIIlliliiliiliiliiliiliiliiliiliiiniiiiiuujiuluiiiiiiiiiiiiiiiiiiiiiiiiiiiii.2 In this example each statement in the inner loop will be executed 5,000 times. (Every time the inner loop is executed, each statement in it will be executed 50 times. And since the inner loop will be executed a total of 100 times, according to the example, each inner loop State- ment will, therefore, be executed a total of 50 × 100 times.) IIIlliiIIIllilililili III.iiiiliiliililililillililiiliiliiIII.1111111111111111111111111111111111111111HIIIIII Each time control reaches the | inner loop, the index variable there is initialized causing control to remain in the loop until the the loop is satisfied. º riſ f Yºu | filllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllliº: r: -IIIlllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllliili IIITIIIIIIII Note: - Jº: All the statements in the range of the inner loop are within the range of the Outer loop. Both the inner and outer loop index variables may be used as subscripts in the inner loop; however, the inner loop index may not be used as an Outer loop subscript. ;IIIIIHIIIIIII IIIIII IIHIIIIIIllllllllllllllllllllllllllllllllllllllllllllllllllllllll. IIII IIII III IIIIII IIIII T. T 125 D0-100ps 126 Seven: Control Statements When executed, the Control statement IF (X) 10, 20, 30 will cause control to be transferred to Statement number 10 if X is To statement number 20 if X is g And to statement number 30 if X is When executed , the Control Statement G@ TQ, 55 will cause control to be trans- ferred to statement number * * * * * * * * ANSWER ON P. 169 tº- - - - ºn - ©---------~~~~ E R O N P 1 6 T. RNSWERT5N*E* T 3 (5) : The general form of a GöTöT. : Statement is G@ TQ n i In the following group of statements, : Where ''n'' is the Statement : #) 66, 77, 77 : of an executable statement. : 77 5 5 ºn * = i e e - 6 control will branch backwards to statement 66 until the expression (X - XTEST) is either Or s' - s - ©--~~~~ I T : If the value of ABLE is larger than the : H ; value of this expression (negative, zero, In the following group of : : positive)? : ! statements : ; (ABLE – BAKER) : I : If (WHICH) 100, 200, 300 : * * * * * * * * * = m = m = m = m = m ms m ms m = m. m. m. m =ANSWER-5NTE-75; H 100 : : : ; Gó Tø 999 : :200 e & ſº : ©- º . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tº g º ºn sº I tº º º ſº I * * | i G@ TQ 999 : : When i. following statement is : : 300 ; executed, : : tº º º : ; IF (ABLE – BAKER) 10, 20, 30 ; : 999 | : ; where will control be transfered if : | F = 5? : Control will branch forward; : ABLE = 10 and BAKER = 5? : : to statement 100, if WHICH !---------------------- --------------------- i is : ANSWER ON P. 165 | * e : Control will branch forward; : to statement 200, if WHICH iis : F----------------------------------------------- --------------- ——" H Control will branch forward: : If, when executed, this statement branches control to : ito statement 300, if WHICH I statement 60 ! His e & : : IF (GAMMA - TEST) 40, 50, 60 we may deduce that the : : Regardless of which path : value of (GAMMA -TEST) was , and that GAMMA : control follows, it will : I was than TEST. *== : ;always reach statement : t t_ _ _ _ = - º Lº ºn ºn ºn tº sº I - II ºn ſº ſº. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . tº a º ºs º ºn ºn gº º ſº ºn ºn ºn ºn tº gº gº L : ANSWER ON P. 170 tº . m as mºl ANSWER ON P. 163 127 - Exºrcises 128 Seven: Control Statements (3) BIG will equal TABLE if TABLE was than * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - : At the end Of this Series Of : tº- tº a - tº- tº I- - ºf E tº ºn ºn tº- tº º ºn tº - - º tº ſº Lº - - - - - - - ---, : statements, : ; BIG will equal CHECK if CHECK ; IF (CHECK - TABLE) 10, 20, 20 : : was than TABLE, or : : 10 BIG = TABLE : : if CHECK was to : : G@ TQ 40 : : TABLE. -*-*s i ANSWER ON P. 170 ; GQ Tø 40 : : 40 º * º : | T I | | | | | | | | | |. al 5 CHECK. The following DO-loop : tº tº E tººl ºn tº º ºs º ºn tº ºn tº tº E tº E tº tº ºn tº sº ºf M = - ºn sº II ºn ºn tº ºn º ºs ºs ºn ºn : DQ 666 I - 1, 1000 : ANSWER ON P. 1 : tº & © H : : i. [. i tº º e : m : 666 CONTINUE : tº . - m mm mm. e : What will be the value of CRS: ; will be repeated exactly : times. ; (10) after this statement? : i-º-º:----------- : CRS (10) = M : ANSWER ON P. 169 : if M ~ 64 : @- Lºº Lº ºn tº- ºn tº E! tº ºn tº º ſº. El tº ſº ºn tº ſº ºf ----------, ANSWER ON P. 163 : DQ 74 K = 1, N : t-n - tº tº - - - º tº - º ºg º ºn - - - - tº I-I ºn E. E. L. u_ _ - - - - - - - - - - - - tº tº L - - - - - - - - - - - - * * * * * * * * * * : Z (K) - 1. 0 : | : What would be the DIMENSIGN : ; : ºne : value of Z(3) after DQ 10 I = 1, 300 : : the first N entries in the , , ; : execution of this Z(I) = I + + 2 : : list Z will all be set equal to: : Sequence of 10 CQNTINUE : : tº : : Statements 2 tº º te : -----------------Rºsºf-35-5-1; | . * ----------- mº tº Lºs tº º ºs º ºn tº º E. E. ſº L_ tº- tº Bº Lº ſº tº tº Lºs - Dº I ºf I- -----------Rºsºrºr-F-Tº: '. - - - - - w - ©-----------~~~~ & ŽS$323 §3& 3& & º What WOuld be the value Of Z(N) after execution of this sequence? In the following DO-loop SUMX = 0. 0 DQ 666 I = 1, 1000 SUMX = SUMX + X(I) 1 FöRMAT (14) 666 CQNTINUE READ 1, N gº tº gº DQ 22 I = 1, N the total of all the values of X Z(I) = I ++ 2 I from X(1) to X(1000) will be 22 CQNTINUE stored in º e ANSWER P. 1 - * = H ANSWER ON P. 163 -------------------------------------1 Fill in the statement numbers in the IF statement in this DO-loop so that BIGE will equal the largest value of E when the loop is satisfied. @. What will be the Significance of K after this loop has been executed? BIGT = 0.0 DQ 99 M = 1, MEND BIGE = 0. 0 IF (BIGT – T(M)) 54, 999, 999 DQ 10 I = 1, N 54 BIGT = T(M) IF (BIGE - E(I)) 5 5 K = M 77 BIGE = E(I) 10 CONTINUE 999 CONTINUE T | | l | I | | | I | | I I I ! ANSWER ON P. 170 Write a DO-loop that will increase by 1.0 each value | | Write another DO-loop i of X from X(1) to X(100). i H 6 that will increase all N values of Y by ten. lm * . - - * * * * * * * * * * * * * * [ . … El 1 RNSWERTöNTE ANSWER ON P. 16 129 Exercises 130 Seven. COntrol Statements m = m = m = = = m = = m = m. m = - m = m = m = m = m = m = m = m = m ºn Numerical sorting is the systematic rearranging of a list of numbers in Some prescribed order. * = m = m = m = m = m = m = m m = . . . . . . . . . Most ways, however, involve a repetitive process, and repetitive processes can usually be - - ºn ºf ºn . . . . | programmed as loops. There are, of course, many ways to rearrange lists of numbers and many : == m = n different ways to sort For example, if you were told to sort a list of them. numbers in descending order, you could proceed m = ma mm mm mm m = m is m = an ºn m ºn m = m ms m 'm m ms m = nº aS follows: You could repeatedly | F = ========================= * (1) search through the list for the biggest The detailed step-by-step: number, | process would be i (2) copy that number onto a new list, and : something like this: : | (3) erase that number from the original : VTi-------------------------- : list. f ithe first time, you will have the first flargest number. This number should be copied onto a new list. It will be the first inumber On this new list. number and copy it on the new list in the Second position. E. wº * | | | r------------------------------ -: : Keep track Of the assumed biggest number by writing it : : Begin by assuming that the : tº gº tº ſº g H : first number on the list was: : down and noting its position on the list. Then every : I the biggest one. Then, by : : g wº e : i comparing it with the next :-): time you find a bigger number, repeat this process. : | L ** ==== tº L_ _ _ _ _ _ ] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ºn tº tº II tº ſº = * * * * : number, the one following i : that one and so on, you would : : change your assumption each ; f = = - - - - - - - - - - - - - - - - - - - - - - - - = m = = m = m = m = m = = m = m = m = m = m = m = m m = m. : time a bigger one was found. : : | H I | * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - mº mill | * e : Before searching for the second biggest : : number on the original list, you must : F------------- its - E - ºn ſº ºn ºn tº . . . . . . . . . . . . . . as s m s m ms in mm mm mm. | | : : erase the first biggest one. The second time you : : When you reach the bottom of the list search the list, you will find the second biggest : : : | | : : H : lm tº . 0. lº tº º º tº- † ſº * : ſº tº . º [ _ sº- g- º I tº | […] ſº ſº ſº tº- § - * , -: J tº- ſº ºn º tº- sº tº | tº ; To arrange this sorting procedure so that it could be programmed in Fortran, you could represent the list as a subscripted variable. Each subscript would then represent a different number on the list. "J. 131 A Sorting Example 132 Seven: Control Statements ºn m ms m ms is m m was m ms ºn m = - m m = m, m = m. m. m. m. m. m. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - I F--------------------------, : Notice that there are alternate paths through loop: : : The search and compare : : 7 ?-, 77 ..." e t 7 ! ? : # process may be : : 1. If "x;" is not bigge. than BIGX" control drops : i illustrated in a flow : : dºwn tº the "Done?... bºut ". . ; : diagram as follows: : : 2. If "x" is bigger than "BIGX", the value of "x; : i---- ſº- - |- : replaces "BIGX" and "k" is set equal to "i." : ~f~~~~~ ---------- -mº sº J GET THE * T NEXT X. SET —). SET tº ºn tº ºn tº ºn tº t- > - - - - - - - - - - ºn tº º ºs º- tº- tº sº tº m = m ºn m = m = m mss m = m m = m mss m = m m ms m sº BIGX = X. K = i "BIGX" is the currently assumed biggest number on the list. "k" is its position on the list. When there is : no change in this assumption, the no path is followed. When the assumption is changed, the yes path is followed. ºn m = m mm mm mm mm mm m = m m = = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * lm - L- tº º- - º i - º tº º tº tº. º [… - I , tº tº º º tº- tº t_ tº- --> tº tº- ſº - * - tº tº- tº- tº º - tº - º tº- º º - - - e - - - t - - - *~ ! - s - • f - # 4 - - \ - § t { * j i’ - - . - - - - - t ºn m = m m = m ms tº ºn ºn tº ºn tº m tº ºn m = - m tº ºn m = m ºn m = as sº sº ºn m ms m m ms in m ms m ms ºn m in sm ºn m m m = m ºn m ºn as ºn m ms m = - T : The Fortran program to carry out this process would : { ; consist of two loops: An inner loop to find each biggest H | F = m = m = m = * * * * * I : * * * * * = m = | m m = m ms m m im m ºn m ºn ºn m = m. m. m. m. * : number and its position on the list, and an outer : : The Flow Diagram on the following page : : loop to move that number to the next position on ; : is a description of an entire sortin : : a new list and to erase it from the original list. :-): p 9. : * = * * * * * = U- i - - tº L. º. º. L. º. º. L. L. L. L. E . . . . . . ſº tº ºn I-1 ºn ºn nº m - ºn m ºn ºn ºn ºn tº ſº ºn m = - ºn tº gº ºs ºn tº a gºs = - .. : process. : : Inside the boxes are Fortran-like : i Statements and expressions. : ſº º ºs º ºſ º º ſº ſº I ſº tº º ſº I ºf sº I, IE, tº ºs º ºs ºn tº ſº ºn gº ºn ºn m sº gº ºn tº gº ºn tº sº f ºn ºn tº --------------- ! ---------------------------------------- : Box (3) initializes : f ! | | T | : #ºn : : The inner loop, the one that does the : p g g i{ : Search and compare process, is : ; each search. i composed of boxes : : | p ; m = * * * * * * * * * * * * * * * * * * * * * * * * = *---------------------- -: ; (3) (4) (5) (6) (T) (8) and (9). : : : +-------- tº tº tº ſº ſº, ſº tº tº [- - - - - - - - tº ºn tº º tº Dº tº ºn ºn tº º sº. It ºn tº ſº .. : Box (4) initializes ; : the index counter. : | ; F------------------------- ---. : : Box (5) compares the value ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * of BIGX and X(I). The first time through his loop, BIGX will equal zero, so X(1) will certainly be bigger, and the minus exit will be taken. ) j 133 J. A SOrting Example 134 Seven: COntrol Statements 135 A SOrting Example 136 Seven: Control Statements r = = * * * * * * * ======= * * * * * ===================== 1 F = * m = m = = m = m = m = m = m = m = I tº . . . . . . . . . branch, BIGX will be set equal to X(1). : ; branch, K will be set equal to 1. * =========================================== * ====================================== m m msl. *h Box (6) sets BIGX equal to the value of Box (7) sets K equal to I, the subscript X(I). of an X(I) that is larger than a previous : i --~. BIGX. : : The first time through this loop and this ) The first time through this loop and : | | | TTE. (8) tests the current value of the f + Subscript to determine whether the loop- | Box (9) re : increments the : ing process has been completed. ; value of {{- The first time through this loop, I : I by one. : will be less than N, so the plus exit Will be taken. Nº. The second time through the loop, BIGX will be compared with X(2) in box (5). If X(2) is smaller than BIGX, control will pass to box (8), bypassing boxes (6) and (7). If X(2) happens to be bigger than BIGX, control will branch to boxes (6) and (7). H This process will be repeated until all N numbers on the list have been compared. m = tº ſº tº a ſº tº I- ºn tº tº Lº ºn tº º Lº - tº I-1 ºn tº a tº ſº. In - -- l . . •. ‘. * * * * - * One search through the list will When J equals one, the inner yield one biggest X. loop will be searching for the first biggest X. When the inner loop has completed a search, control passes from box (8) to box (10). And since there are N values of X, the entire Search will have to be repeated N times. ---------------------------------------s---------------- The repetition of the entire searching process is controlled by the Outer loop. *— Box (11) sets X(K) equal to zero. The first time control reaches box (11), this will have the * IT ſº sº Box (10) sets Y(J) equal to BIGX. The first time control reaches box (10), Y(1) i will be set equal to the first biggest X found in the search in the inner loop. * rº- tº - e. U- E = m s m m m = n m = m = m ms m in mm mm. Box (2) initializes the index counter for the outer loop. * = mim in m = m. m. m. m. m. ºn m = m ºn ºn m m ºn tº m m in mi mi m m m ºn tº ºn tº ºn m ºn tº ºn ºn tº ºn tº Box (12) tests the current value of J to determine whether the Outer loop is finished. effect of erasing the first biggest X from the Original list. (If this step is omitted, the first biggest X will always turn out to be the biggest X.) The first time through the Outer loop, J will be srmaller than N and the plus exit Will be taken. 137 l A Sorting Example 138 Seven: Control Statements r |Box (14) initializes another i loop which is designed sº ºn tº ºn tº tº tº* * * * * * * * * * * * * * * * * * * * * * = = m = m = m = = m = * * * * * * * * * * * * * * * * * Box (13) increments the value of J by one. The second time through the loop, BIGX and the I index counter must be reinitialized. If BIGX is not reinitialized, it will equal Y back into X. The first time control reaches ; box (14), L will be set equal Box (15) sets X(L) equal to | :to transfer the sorted list in -> | L | the first biggest X, and the second biggest X will not be found. If I is not reinitialized, the search will not begin with the first X. Box (16) tests the index counter to In box (12), J will equal N, causing control to pass to box (14). determine whether this loop is finished T ** | | : : # , º, I-, -, ºn tº gº ºn tº ºn tº º ºs - - - - - - - - tº Lºs ſº º sº º Ll ºl º º ſº tº tº Lº L. is ºn s tº ºn tº º tº tº Lºi º Lº Gº Lº º : Y(L). : : The first : : time control : : reaches this rºm ms in m ms an ºn m m in m ºn m ============== = - - - - - - - gº ºn tº tº . . . . . . . * - Tº Lº tº nº tº tº L. tº ºn Mº Li Lº Lº Li ºl E. E. ** * : box, X(1) Will : : The outer loop will reinitialize and execute the inner loop ; : be set equal : until N biggest X's have been transfered to Y. When the : : to Y(1) Q : º ====<--------- : outer loop is satisfied, Y will contain all the Original : * = = = = sº : numbers sorted in descending order. : m = = = = = = = * * * * * * * * * * * * tº ºf tº ſº tº ſº ºn tº ºn - tº ſº a ºn tº - ºn tº : : W. wº The first time control reaches this box, L will be less than N so the plus exit will be taken. m m = m = m = m m = m = m = m = m mm m = m = m m = m. Box (17) in c rements the value of L by one. ºn = * * * * * * * * = m = m = m m = m, m = m, m = m = m. Using the Flow F------------------------------------------, Diagram on page 134 as a : The second time through this loop, L, model. write a ; is equal to two. X(2) is set equal to Y(2). 5 | T e : This transfer process is continued : SORT Subroutine until all N numbers in Y have been moved; that will sort array "X" in descending r = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - a : When all N values have been transferred, | | Order. Remember that N and X are in Common Storage, ; L will equal N, and control will follow the minus-zero exit from box (16), and | L | | : the work of the routine is completed. : | [. : : don't forget to * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -º dimension both P = - - - - - - - - - - - - - - - - - - - - - - - - - - F - - - - - - - - - - - - - - - - - - - - - - - - - - - | | : Box (18) returns : i Box (1) identifies the : X and Y. : control, to the i—); routine as i-O tº ºn tº ºn tº mº, º ºs º ºs ºn ºn ºn m = m = m = m = m = - m º gº ºn ; Main Program. : SUBROUTINE SøRT : | | I | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * = - - - - - - - - - - - - - - - - - - - - - - - - - -8 139 Sorting Task 140 Seven: Control Statements There are three loops in the Flow Diagram. You may use DO statements to set up these loops, or you may use IF statements. DO-loops, however, are generally more efficient, and are, therefore, the recommended technique. Remember that you must reserve ); 1,000 storage locations for X in Common Storage. Remember that N is in Common Storage. - * - .* - * - | T Q Cº. | { } * i * ſº º - - & F = - - - - - - - - - - - - - - - - - - - - - - - - - -\; Is the first statement '; in your Subroutine SUBROUTINE SQRT - - - - - - - - - - - - - - - - - - - - - - - - - - i ~ P = = = * * * * * * * * * * * * * * * * * = * = = = = * * * * * * * * * * * * * * * * P = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Does your subroutine have a The subroutine-defining : : DIMENSION | | statement must be first. Otherwise the Fortran Compiler will compile this program as a Main Program. _k Statement that looks like this? V; DIMENSIGN X(1000), Y(1000) *- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * = a - - - - - - = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | | -1 P = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Any number of subscripted variables i{-------- may be dimensioned in a DIMENSION : Statement. *: F------------------------------------ : Does your subroutine have a ; COMMON statement that looks \, like this 2 Both are specified at 1000, because r; X was dimensioned at 1000, in INPUT.; !. = n = * = * * * * * * * * * * * * * * = * = = = * = = = = = = = = * = = = = = = = = ** CQMMGN N, X 141 Diagnosis 142 Seven: Control Statements ~~ r----------------------------------------------- tº a tº s ∈ M. º. ºn tº m ºn I tº #N and X must appear in the COMMON statement in the same i order that they did in subroutine INPUT. You may have put | V | gº e #y in COMMON like this CQMMGN N, X, Y and no troubles would ensue. Notice, however, that since no : other subroutine will be using Y, it need not be in COMMON.; “G” f ſº tº tº tº tº tº ſº tº tº tº ſº tº ºn I-, -, mi ſº m sº ºn gº tº ſº gº ºn Ti4 : Does your subroutine in F = * * * * * * * * = = = * * * * * * * * * * * * * * * = = = = = = = = ** = * * * * = * I have a : : RETURN : : The RETURN statement is absolutely : H statement? 3: essential to return control to the Main : +------ tº i-º, sº tº L. L. . . . . . . . . . . . . . . . ſº tº ºn tº r; Program. - : : It should be the last statement to be : executed in the subroutine. : * = = = = = = = = = = = = * * * * * * * * * * * * * * * = = * * * * * * * * * * * * = i gº ºn s = * * * * * = = = - - - - - - - - - - - - - - - º HA ;Is the very last statement NT in your subroutine an END: istatement? : | | =l ls | tº º tº ſº I -, -, -, -, -, - . . . . tº ſº tº ſº ºn tº T---- The END Statement is also absolutely essential. It marks the end of the Statements to be included in your subroutine. t A r tººl ſº [… ſº […] tº |- ſº I † ſº : tº . ſº tº |- f : tº L_ i. ºf [.. º A Did you program the innerit loop with a DO statement? : g” - - - - - - - - - - - - 4------------- * * : : :Did you program the inner: floop in an : : H : IF-loop? : * * * * = = = = = * = = = = = = = * * * = ** = = = = = H ſº DO statement does the work of boxes (4) (8) (9) } i You should not have duplicate statements to do this. You . : should not have statements : : I = 1 : : IF (N - I) , 9 : i---------------------------|--|--|-- _ _ _ _ _ ! . . . .-tº ſº º ºn tº ſº tº ſº i The IF-loop will work here, but is less efficient than a DO-loop. The pattern of loop control should look something like this: I = 1 iF (N - 1) 10, 10, 20 20 I = I + 1 G@ TQ 5 5 143 ~ l Diagnosis 144 Seven: Control Statements ~ It ºr ſº tº . . * = * = = m. fº = - HDid you program the outer: N0 floop as a R N ſ i. ad : DO-loop? | F = = = = * * * * * * * * * * * * * * * * * * * * * * * = = * = = - - - - - - - - - - - - - - - - - - - - - - #The DO statement for the outer loop replaces boxes : (2) (12) and (13). Therefore, you should not have statements : corresponding to them. You should not have these ! statements in addition to the DO: = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Did you program the outer loop with an IF statement? J = 1 * * * * * * * * * * * * * = * = * = = = * * * * * * * * * * * * * * = IF (N - J) — — — J = J + 1 ~~ l - 's # of control for the ſºliº shºuld loºk something like this: f al : : I : J = 1 : : 77 tº gº tº : : (inner loop) : tº e $ | : IF (N - J) 66, 66, 55 : ...# gº ºn ºn tº ºn ºn tº sº LE E ºl E. Bº Đ tº ſº tº ſº º : 55 J = J + 1 : | L G | : Did you program the : : Ø TG 77 : : transfer back loop as a : *------------------------------------------------------ al : DO-loop? : ---------- ſº ſº tº tº ºn tº ºn tº L. E. +--- + Did you program the transfer k loop as an C (14) (16) and (17) Therefore, you should not have statements corresponding to them. You Should not have L IF Statement? T | : | ba. | I ſº ls tº tº ºn tº ºn tº E tº E tº tº Lº ºf E. E. tº tº ºn tº ºn I-, - tº º – m º ºs º gº ºn sº = 1 IF (N - L) ’ —” — L = L + 1 145 Diagnosis 146 Eight: 0utput Statements The pattern of control for this IF-loop should look something like this: L = 1 43 tº IF (N - L.) 27, 27, 99 99 L = L + 1 G@ TQ 43 27 © tº º ~ r : If necessary, make a clean #and correct copy of your y; program. Then go on to the next section. • - g Part Eight: ourPur snarevenirs Relation to Input e Output Field Specifications e Carriage Control e Relations between Fields, Specifications, and the Variable List O Exercises C Output Task e Diagnosis O Conclusion El agiliulililililililluſilluſiliiliiliiliiliiliiliiliiliiliiliiliiile Planning output is the * - Input FORMAT statements describe how numbers are already arranged on data Cards. IIIllil IIIIII IIIIIIII IIIllilill IIIHIIIIIII IIHIIIIIHIIIIIIHIIIII Iº e V e T S 6 of planning input. IIIIIIIIIIIIIIIHIIIII ||||IIIIIIIIIIIIHIIIllllllllll | | | Output FORMAT statements specify how numbers are to be arranged on a printed page of output. 2. PRINT statements specify 2|IIIIIIIIIIIIIIHIIIIII IIIIIIIIIII IIIHIIIIHIII IIIIIIP: which numbers, already in { READ storage, shall be printed out. statements specify Where the numbers shall be stored. IIIIIIIIIIIIIIIIIIIIIIIHIIIHIIIIIIIIIIIIIIIIIIIHIIIIr: | 147 Relation to input 148 Eight: 0utput Statements In the output process there are two statements involved: A FORMAT Statement and a PRINT Statement v - gunununiuluuuuuuuuuuuuuuuuuuuuuuuuung The first step in planning output is designing the layout of each printed line. | III IIIIIIII III IIIIIIIIIIIllillllllllllllillllllllllllllllllllllllllſ: Each printed line is comprised of 120 Output FORMAT specifications must account for every print position "print positions." ) beginning at the left. Extra positions at the right may be Omitted. There are four kinds Of fields that raay be specified in an output FORMAT Statement: I - for Fixed Point F – for Floating Point X – for Blanks H – for Hollerith characters il ill|||||||IIIIII IIIIIIHIII IIIIIIlllll “I” and “F” a.I’é used to print the values Of the variables in the Variable List in the PRINT Statement. IIIllil III IIIIllllllllllllllll IIIII. Tº agiliſiiniiiiiiliiliiliiiniiniiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiile "X" and "H" specifications are used for spacing and labeling. FIIIIIIllil IIIIIIIIIIIIIIIIIIII IIIII IIIIIII IIIIIIIIIII IIIIIIHIII IIIll: The general form for the - * * - - - IlluſiiniiiIII.iiiIIIIIlluſiliiiniiiIIIIlluſillilululiiIII.iiiiiiuu: "I" specification is he Variables are Fixed POint mode, they should be printed with the I FORMAT statement specification. : III IIII IIHIIIIIHIIIIII IIHIII III III IIHIIII III III III III III IIHIIII IIIHIIII: lº: IW Where "W" is the number Of print positions in the field (i.e., the width). 4- | º tº ºl ºl ºf Bº tº tº Bº ºf I- tº tº I-1 ºn tº E - E - - - - - -, -º ºn I- ºn ºn ºn *T. s : If the value of a variable iwere 87 and if it were printed :With an I4 format, it would flook like this: º: If the variable is Floating Point, its value should be printed with an F OG)87 FORMAT statement specification. (The blanks "GO" would not be printed.) -> T Y !- 149 Output Field Specifications 150 - Eight: 0utput Statements The general form of the "F" specification is The general form of the X FORMAT specification is nX where ''n'' is the number of the print positions to be left blank. FW. d "w" is the number of print positions Of the field. "... d" is the number of digits to be printed in the fractional part of the value. If the value of a variable were 95.273842 and if it were printed with an F5. 2 format specification, it would look like this: 95.27 The general form of the H Fºr Specification is n H C 1 c2 C3 . . . Cn "n" is the number of characters to be printed. Note that the fractional part is rounded to two places, which is the number of places (digits) specified in the F5.2 format specification. c1 c2 c 3 . . . cn are the actual characters. They may be alphabetic, numeric, or special characters. Ny Note: "n" nust be precise because the next n CharacterS in the FORMAT statement, following the ſº- - - - tº ==================== = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - T. For example, if 23HTHISOISOTHEOFIRSTOPHASE were specified in a FORMAT statement, the printed output would look like this: "H," will be printed. SNIIIIHIII]|IIIIIIIllillllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll): º -º = É injiiiiiiiiiiiIIIlliiliiliii.IIIIlliiIII.iiiIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlliiliiIIIIIIII: = The four kinds of output specifi- E = E = cations (I, F, X, and H), used individually 5 = "23H" indicates that there Will be 23 = = or in combination, specify the #4– Hollerith characters in this field of É = layout of one line of printing. = = output, and the dotted zeros = = E = indicate the character positions = = = = that will be left blank. = ñiiiiiiiiiiiiiiiiiiiriliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiiiiiiiiuuuiiliº = = Finnliminimunuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuſſ 151 Output Field Specifications 152 Eight: 011tput Statements 3. The position of a line on a page is specified by a "carriage control" character. This character is and must be the first The format specification for the first print position is the "carriage control" character. character specified by the FOR M A T S ta t e ment. -> The carriage control character is not printed. It is an instruction to the printer to space down before printing. The following carriage control characters are interpreted by the printer as follows: Carriage control characters are specified as Hollerith fields of one character: 1HO specifies a blank as the first character in the O (blank) space down one line before printing line and instructs the printer to space down One line. 0 (zero) space down two lines before printing 1 (one) skip to new page before printing 1H0 specifies a zero as the first character and instructs the printer to space down two lines 1H1 specifies a one as the first character and instructs the printer to skip to a new page = = m = = * * * * * * * * * * * * * * * * * * = m = m = m = m = = n = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * º l | H FøRMAT (1H1,6X,23HTHISOISOTHEOFIRSTOPHASE, 5X, I4, 5X, F5.2) : m ∈ ºn m = - m = m, ſº sº. In mº ºn ºn sº tº Is I, ºn ſº I ºn ºn ºn m - nº ºn m ºn tº me - ſº º m ms ºn tº º ºs ºn tº Lºs II Is tº ºn tº ºn tº ºr tº m ſº tº tº ºr ºs º ºs º ºs º- ºr ºn tº º ºs ºn tº ºn tº a = m = Assuming that this output is to be started on a new page, the FORMAT statement describing it would be: 153 Carriage Control 154 Eight: 0utput Statements gill milliluliiniiniiiuuuniniiniiniiniiniiniiniiliiling # - # guilliluliiliiliiliiliiiuuuuuuuuuuuuuuuuuullililillilullilullilulling # The first Hollerith field, "1H1," = = = = is carriage control. It causes E = The "X" fj e e = E © * E E e "X" fields provide spacing E = ..º, Skip to a new page = = loetween the other fields. = = p £. = = The "I" field is for the number = = The second Hollerith field is 5–); 87, and the "F" field is for the = = for the titling sentence, "THIS = = number 95.38. = = IS THE FIRST PHASE." = = = filliiiniiniiniiniiniiniiniiniiniiniiniiniiniiniiiuuliuſ Filiiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiliiſ; Only the "I" and the "F" fields require values of variables. These Variables must be in the Variable List Of the PRINT statement that uses this FORMAT statement. nº m imm mm mm mm mm mm mm mm mm mm mm mm mm mm mm mm mm m = m = m in m = m = n = ** * * * * * * * * * * = mº ºn m ºh ºf mº M. I. I. º. tº º ſº mº m ſº | If K equals 87, and X equals 95.378424, the correct PRINT statement would be: 55 FøRMAT (1H1,6X,23HTHIS IS THE FIRST PHASE, 5x, 14, 5x, F5.2) T PRINT 55, K, x º w - ( ) A Hillllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllip; If several fields have identical formats, the Specification for one of them may be multiplied: F8. 3, F8.3, F8. 3, F8.3, may be written 4 F8. 3 T h e P R[ N T S t at € IIl € Il t Ca. Ul S € S th € Values of the variables on the List to be printed according to the I4 4. and F5. 2 FORMAT specifications. R. s P. The PRINT statement continues to print values for every variable on its List. -> It repeats the FORMAT as often as necessary, and terminates after printing the last value on the List. It terminates even though it may be in the middle of the format specifications. 4. : - ill T. * Just as with input FORMAT statements, output FORMAT specifications will be re-used whenever there are more Thus, 45 FGRMAT (1HO, 5E10.4) PRINT 45, (X(I), I = 1, 50) would print five values of X on each line. There would be ten such lines, double Spaced. variables on the L is t than there are Specifications in the FORMAT statement. IIIIIIIIHIIIIII IIIIIIIIIIIIIIIIIIIIHIIIIIIIHIIIIIHIIIIIHIIIIIIIIIHIIIIIIIIIIIIIIIIIIIIIIIIIIIllili; 155 Relations between Fields, Specifications, and the Wariable List 156 Eight: Output Statements Write a FORMAT statement with single spacing, a field of eight blanks, and a * º e tº ſº e : Now write a Print statement : field of ten print positions for g e :a Floating É. ºalue retain- : that will print the value of the : ; : tº º ſº & - Variable, ''TEST. " usin #ing four digits in the 5 3. g | ing Iſ g : FORMAT statement 55 : ifractional part. Number it 55. i. * > i n | | ©------------ : Write another PRINT : : How many lines will be : : "Z" will be printed : : number 55, but this ti : i needed to print all 25 : on each line? : : mber 29, put ims time ; * ; values of "Z"? : ; : ; to print out all 25 values ; : : ls ANSWER ON P. 166 ; or "z. : | | * = = m = m = m = m = m. * = = * * * * * * * * * * * * * ANSWER ON P. 163 * * * * = m = m = m = m = m = m ms m = m = m ms * = = * * * * * * ANSWER ON P. 166 Write a FORMAT statement and a PRINT Statement for 80 values of "Y" according to the following format Specifications: 1. Eight values per line. 2. Each field nine print positions wide, with four digits in the fractional part. "...~~~~~~ T 3. Double space the lines. Write a FORMAT and PRINT Statement that will do nothing more than cause the printer to skip to a new page. m m =l ANSWER ON P. 170 7RSWFF&N Prº Write your own FORMAT and PRINT statement according to your own specifications. Then, on a piece of scratch paper, draw your conception of how the printed output will look. AN s ſº E F. O N P l 7 157 Exercises 158 Eight: 0utput Statements ----------------------------------------------------------1 Write a subroutine called OUTPUT. Design it so that it will print all the values of X that were sorted in subroutine SORT. Plan the printed page so that it looks something like this: TABLES OF VALUES SORTED IN DESCENDING OFDER XX. XX XX. XX XX. XX F ========= ----------------------- XX. XX : REMINDER | – XX. XX In some of the diagnoses, references will be made XX. XX {- about Other SubroutineS. These subroutines are the ones you wrote as previous TASKS. (The "xx. xx" notation above is used to indicate the positioning of the numbers.) r | | | I [. I | | | L | | | | L | I | I | | | L | I | | I s | I | | | I | | F = * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Is the first statement in your Subroutine SUBROUTINE QUTPUT F = = = = = = * * * * * * * * * * * * * * * * * * * * * * * * * | | : : : The subroutine-defining : ! : statement must be first. A : F - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - : Otherwise, the Fortran N : Does your subroutine have a ; : compiler will compile : : DIMENSION statement that looks : : this program as a : }: like this? : ; Main Program. : : DIMENSION X(1000) : * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - i------------- F ------------F--------- | | ; F------------------------------------------, ! : Subscripted variables must be : : dimensioned in a DIMENSION : : Statement. X is Specified at : : 1000, because it was dimensioned : that way in subroutine INPUT. : | | ! 159 ~ Diagnosis 160 o Eight: 0utput Statements tº º Gº tº sº º ſº. I tº ſº ºn tº Im tº I tº ſº º ºn tº ºn tº Lºs - ſº gº º ºs * = * * * tº | Does your subroutine have a ;4 r ; COMMON statement that looks :" F = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | sº ic ‘P : like this '. : : Does your subroutine have a i-----1-29MM2N.N.: tº ºn E - ſº ºn L. º. i. ºn tº i : RETURN statement? : ! : : - Mi i ; 7--------------F-------------------- : r = - - - - - - - - - - - - -+-------- ---------- ; , N and X must appear in the F = * * * * * * * * * * * * * * * = = * * = --->----------------- ; COMMON statement in the same : : The RETURN statement is absolutely : : Order that they appeared in : : essential to return control to the : I e J [. | . i. Subroutines INPUT and sº.; : Main Program. It should be the last : tº ºf ſº tº gº tº ſº tº º ſº tº El Es El Es tº ºn tº sº tº ºn tº ºn tº ºn tº ºn ºn tº tº LT; ſº Lºs ! statement to be executed in the : ! subroutine. : : : * = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | I ! tº tº º ſº sº tº I-s ºn tº ºn tº . . . . . * = - - - - - - - - - - - - - - - - - - - - - - - - - - - tº E ºn -------------->------------------ It is important that you remember that { - e the END statement is also absolutely Is the very last statement in your. & Subroutine an END statement? essential. It marks the end of the statements to be included in your subroutine. F - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - You have been asked to write four Subprograms: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * A Main Program X- Subroutine INPUT X- Subroutine SORT X. Subroutine OUTPUT If you do have your Job run, it will probably not be successful the first try. You will probably get back diagnostic results from the compiler. º | I L | | | | | | | & lºss m m = m, m = m = m. m. m. m. m. m. m. m = m ms m = m m = m = m = ºn m = m = m = = * * * * * * * * * * * * * * = * = These subprograms could be organized into a Job by keypunching each statement on tabulating cards, adding in put data in a format compatible with your Every diagnostic is caused by a violation Of a rule. Every rule is necessary either because of the limitations of the Computer and the compiler Or because it prohibits ambiguity in the program. In One case you must serve it, and in the Other case it serves you. INPUT Subroutine, and then adding the System Control Cards required by the computing installation where it is to be compiled and executed. |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -------------------------------------------- 161 COIlclusion 162 Answers Answers to Exercises 163 Answers 164 Answers 165 AIISWers 166 - AmSWGIS ¿? ??¿ >>=_≥_.*¿¿.*)?). Answers 167 Answers & ;: && 168 169 Answers * i. sº * ...; .º.º. s º f º Answers 170 171 Answers 172 Answers 173 Answers 1. Assign a value to the first variable on the List in your PRINT statement. 2. Interpret the first character specified in your FORMAT statement as carriage control. 3. Print all Hollerith and "X" fields (if an r) that precede the first "I" or "F" field specification. *. 4. If the field is an "F" field, mark off the width; print the decimal point; print the whole part of the number leaving Answers 174 175 AmSWCrs reference innanual CONCEPTS Program Structure Main Program STATEMENTS SUBROUTINE END A Subroutine is a subprogram of the program section of a job deck. The first statement must define it as a Subroutine. The general form is: Subprogram SUBROUTINE Name A subprogram is a Main Program, if the first state- ment in it is not a SUBROUTINE Statement. There must be one and only one Main Program in a Job. A subprogram is any program segment of a Job. A Subroutine is a subprogram. A Main Program is a Subprogram. Interprogram Flow of Control "Name" may be any combination of from One to six alphabetic characters. STATEMENTS CALL Every subprogram of a job deck must have an END statement as the last physical statement in the subprogram. The general form is: END The CALL statement causes control to be transferred to the first executable Statement in the subroutine named in the CALL Statement. The general form is: CALL Name 47 48 47 Reference Manual 43 179 44 45 180 Statements (cont.) 46 RETURN "Name" may be the name of º any subroutine in the Job, or any System Subroutine on the & Library Tape. CALL state- ments may appear in Main Programs and in Subroutines. The RETURN Statement in a Subroutine causes control to be transferred back to the first executable statement following the CALL statement which caused control to be transfer- || red to the Subroutine. The º general form is : RETURN CONCEPTS 27 First Statement Executed Last Statement Executed The first statement executed in a job is the first executable statement in the Main Program. The last statement executed in a Job must return control to Reference Manual the Monitor System. One way to do this is with the following Statement: CALL EXIT "EXIT" is a System Subroutine on the Library Tape. The last statement executed in a Subroutine must be either a CALL EXIT statement Or a RETURN Statement. Constants CONCEPTS Floating Point Constants A Floating Point Constant is any number of decimal digits with decimal point. Only the first eight significant digits are used in computations, and the absolute value should lie between 10** and 107* (but may vary with different computers). 48 58, 63 65 Concepts (cont.) Fixed Point Constants A Fixed Point Constant is one to five decimal digits With no decimal point. The absolute value must be less than 2" (but may vary with different computers). Variables CONCEPTS Floating Point Variables Fixed Point Variables A Floating Point variable is any combination of from One to six alphabetic or numeric characters and no Special characters. The first character of the Floating Point Variable must be any of the following letters: ABCDEFGH OPQRSTUVWXYZ A Fixed Point variable is any COmbination of from One to six alphabetic or numeric Characters and no Special Subscripted Variables characters. The first Character must be One Of the following letters: I J K L M N Variables of either mode may 66 be subscripted. The general form of a single subscripted variable is: v(i) "v" may be any legal Floating Point or Fixed Point variable; "i" may be any legal Fixed Point variable or constant. "i" should not exceed the total number of Storage locations available. For double and triple suscripted variables, See a FOrtran Reference Manual. Reference Manual 64 181 58 61 61 Input STATEMENTS READ The READ statement causes values to be transmitted from data cards according to a FORMAT statement, and to be stored as the values of variables. The general form is: Input FORMAT READ n, vi., v.2, v3, . . . ''n'' is the Statement number Of the FORMAT Statement that describes the fields on the data. card(s) being read. "vi, v2 , v3 , . . . " are the names Of the variables Where the values in the data fields are to be Stored. These variables may be Fixed or Reference Manual Floating Point mode, and they may be subscripted or non- subscripted. Subscripts may be under DO-loop Control or List Control. The input FORMAT statement contains descriptions of the data fields on the data cards to be read by a READ statement. The general form is: n F@RMAT (d1,d2, d3, . . .) ''n'' is the Statement number Of the FORMAT Statement. "(d1,d2, d3, . . . )" are the I Field or F Field descriptions that describe the data fields from left to right on the data 77 182 82 75 Statements (cont.) card to be read by a READ statement. Columns to the right of the data fields described in the FORMAT statement are ignored. The set of descriptions in a FORMAT statement will be repeated until Values have been read for every variable on the Variable List in the Read statement. Every time the set is repeated, it applies to the next data card. CONCEPTS List Control The sequence of values of the subscript of a subscripted variable may be specified in the Variable List of a READ statement by using List Control. The general form is: (v(i), i=m 1, m2, m3) Data Fields "V" may be any legal variable. "i" may be any legal Fixed POint variable. "m 1" may be any legal Fixed POint unsigned Constant Or variable. It is the initial value of "i. " It must be greater than Zero, but equal to or smaller than "m2 . " "m2" may be any legal Fixed Point unsigned constant or variable. It is the terminal value Of "i. " It must be greater than Zero, and equal to or larger than "mi." "ms" may be any legal Fixed Point unsigned constant or variable. It is the amount by which "i" shall be incremented. It must be greater than zero. If "ms" is not specified, it is understood to be equal to One. A data field (for input) is a 75 group of one or more columns on a punched card. The width of the data field is the number Of columns in it. Reference Manual 85 183 184 Reference Manual Concepts (cont.) 78 I Fields If the number in an input data "n" is the number of fields field (on a card) is an integer described. If ''n'' is not number, the value should be specified, it is understood to transmitted under the I be one. "W" is the width of conversion symbol. The § the field, and "... d" is the general form of the I number of digits in the FORMAT description is: fractional part. nIW § - * Repeating Input If the Variable List Contains 86 * FORMAT more variables than there are ''n'' is the number Of fields º Descriptions input data field descriptions in described. If ''n'' is not º the FORMAT statement, the specified, it is understood to § FORMAT statement will be be One. "w" is the width Of º repeated from its beginning the field. : and will automatically apply : º to the next data card. 77 F Fields If the number in an input data field (on a card) has a decimal Storage Allocation 67, 70 point in it, the value should be transmitted under the F conversion symbol. The º general form of the F FORMAT specification is: º STATEMENTS DIMENSION The general form of a 67 DIMENSION Statement is: nFw. d * DIMENSIQN v1(ii), v, (i2), . . . - , -º- - -” * 2 * * Statements (cont.) "V 1" and "V2'' . . . are the names of the variables. "ii" CONCEPTS and "i 2" are Fixed Point constants equal to the maximum Nonsubscripted Nonsubscripted variables are number of locations that will Variables automatically assigned One ever be needed by the variable. Any number of variables may be listed in One DIMENSION storage location within the area used by the program in which the variable appears. statement. If the Variable is listed in a COMMON statement, the location is in Common Storage, 70 COMMON The general form of a and not in the program. COMMON Statement is: Subscripted Subscripted variables are 66 Variables assigned as many locations within the area used by the program as Specified in the DIMENSION Statement in which the variable is listed. All subscripted variables must be listed in a DIMENSION Statement. If the variable is also listed in a COMMON statement, the locations assigned will be in Common Storage, and not in the CQMMQN vi, v, , . . . "vi, v2. . . " are the names of legal variables. If a variable is not subscripted, and does not appear in a DIMENSION statement, one Common Storage location Will program. be allocated to it. If it is listed in a DIMENSION State- Constants All constants are allocated 63 ment, it will be allocated as many locations as specified for it in the DIMENSION Statement. one storage location within the area used by the program in which the constant appears. 185 Reference Manual 186 Reference Manual "e" is any legal expression, and ''n 1, n2, n 3, " are state- 112 ment numbers of any numbered, executable statements in the program. STATEMENTS If the computed value of "e" is - negative, control branches to 114 GO TO The normal flow of control is statement number "ni." altered by execution of a GO TO Statement. The general form If the computed value of "e" is to a GO TO statement is: zero, control branches to "n 2." If the computed value of "e" is GQ, TQ n - positive, control branches to "n 3. ! I & § "ni, n2, and n 3" need not all be : § different statement numbers. ''n'' is the Statement number & of any numbered, executable DO A sequence of statements may 120 statement in the program. : be executed repeatedly by defining the sequence as a DO- 115, IF The normal flow of control is º ...” form of a 117 altered by the execution of an º IF statement. The general form of an IF statement is: IF (e)n 1, n2, n, DQ n i = m1, m2, m3 Statements (cont.) ''n'' is the Statement number Of the last numbered executable Statement in the Sequence; "i" is any legal Fixed Point Variable; and "m 1, m2, m3" are any legal Fixed Point variables or constants. "i" is the index counter for the loop. "m 1" is the intial value of the index, "i. " "m2" is the terminal value of the index, "i. "I "ma" is the increment for the index, "i. " If "ma" is not specified, it is understood to be one. - The "range" of a DO statement is all the statements beginning with the first one following it, and ending with statement number ''n.'" The Statements in the Range of a Do statement are executed in Normal Sequence first with i = m1. After they have been executed once, i is incremented by m 3. If i does not eacceed m2, the statements in the range will be executed again, with i incremented. This process is repeated until the incrementing of i causes it to exceed m2. At this time, control passes to the first Statement following the range of the DO statement. The index variable i is available for Subscripting and for inclusion in expressions within the loop, but itS Value Should never be changed by any statement in the loop. It must not, for example, appear as the index variable in an inner DO-loop or as the index Variable in the list COntrol of an input or output statement. Control statements are permitted in a DO-loop. Control may be transferred to a Statement Out- side the loop by an IF or a GO TO statement. Control may be transferred to a Subroutine by a CALL statement. Control may not, however, be transferred into a DO-loop except by the RETURN Statement in a Sub- routine called in the loop. DO- loops within DO-loops are permitted, provided only that Reference Manual 187 & * Statements (cont.) CONTINUE Normal Flow of Control no statement in the range of an inner loop lies outside the range of an Outer loop. The first and last statements in the range of a DO statement must be executable. The last statement in the range of a DO statement must not be a transfer - Statement. It is customary to mark the last statement in the range of a DO- loop with a CONTINUE state- ment. The general form is: n CQNTINUE "n" is the statement number of the Statement. The CONTINUE statement is executable, but specifies no computation Or transfer of control. In the normal flow of COntrol of execution, after all the Reference Manual operations specified in one statement are carried out, control automatically passes to the next succeeding executable Statement. Computations 94. CONCEPTS Expressions * Mixed º Expressions Operation Symbols An expression is any legal Fixed 94 Point or Floating Point variable or constant; or any legal com— bination of them – separated by operation symbols. When executed, an expression results in One numerical value. With only one exception, all the 103 variables and constants in an expression must be of the same mode. The only exception is that Floating Point mode variables may be raised to Fixed Point powers. The following symbols specify 94 - - - *- *- - 188 112 122 Concepts (cont.) Hierarchy of Operations Parentheses the following arithmetic operations: ** Exponentiation * Multiplication / Division Addition ſº- Subtraction Operations in an expression are performed according to the following preference scheme, and from left to right: 1) Exponentiation 2) Multiplication and Division 3) Addition and Subtraction Those parts of an expression that are enclosed in parentheses are performed before those parts that are not enclosed. Those parts enclosed in the innermost paired parentheses are performed first; the next innermost, next. |Conversion to Fixed Point Conversion to Floating Point Functions The value of a Floating Point variable may be converted to Fixed Point mode by setting the variable equal to a Fixed Point variable. When executed, the Fixed Point variable will be set equal to the whole part of the value of the Floating Point variable: The frac- tional part is truncated and discarded. Fixed Point variables may be converted to Floating Point mode by setting the variable equal to a Floating Point variable. When executed, the whole part of the value of the Floating Point variable will be set equal to the value of the Fixed Point variable, and the fractional part will be Zerº O. A large number of Standard functions, such as square root, sin, cosine, etc., are available. For an explanation of their use, see a Fortran Reference Manual. 110 109 Reference Manual 95 189 97 Output STATEMENTS Output Reference Manual Output tape in sequence. After the last value has been trans- mitted, control will pass to the next statement. - - The layout of one line of output FORMAT may be specified in one The PRINT Statement CauSeS FORMAT statement. The the values of a list of variables general form is: to be transmitted for printing according to the specifications - of an output FORMAT state- - ment. The general form of a n F@RMAT (c, s1, s2, . . .) PRINT Statement is: PRINT n, vi., v.2, v3, . . . ''n'' is the Statement number of the FORMAT Statement. ''n'' is the statement number of re is the carriage control field. the output FORMAT statement specifying the layout of th "S1, s2, . . . " are output field printed page. ; Specifications. "v 1, v.2, v3, . . . " are any legal CONCEPTS subscripted or non-subscripted % Variables. List Control The sequence of values of the The value of each variable will be transmitted to the standard Subscript of a subscripted variable may be specified in the Variable List of a PRINT 148 155 190 147 147 Concepts (cont.) statement by using List Control. The general form is: (v(i), i = m1, m2, m3) "v" may be any legal variable. "i" may be any legal Fixed Point variable. "m 1" may be any legal Fixed Point unsigned constant Or variable. It is the initial value of "i." It must be greater than || Zero, but equal to or Smaller than "m2." "m 2" may be any legal Fixed Point unsigned constant or variable. It is the terminal value of "i." It must be greater than zero, and equal to Or larger than "m 1. " "ms" may be any legal Fixed Point unsigned constant or variable. It is the amount by Which "i" shall be incremented. Data Fields Carriage Control H Fields It must be greater than zero. If "ms" is not specified, it is understood to be equal to one. An output data field consists of one or more print positions. The width of an output data field is the number of print positions in it. The following Hollerith Carriage Control fields result in the following carriage control operations: 1H1 Skip to beginning of new page 1HO Double-space before printing 1HG) Single space before printing 1H+ No space before printing (Carriage Control fields may vary with different computers.) A Hollerith (H) field is a group of characters specified in a FORMAT statement, that are to be printed exactly as they 149 152 150 Reference Maſlilal 191 192 Reference Manual Concepts (cont.) appear in the statement. The general form is: ''W'' is the "width" Of the field – the number of print positions in nHC1, C2, C3, o º © Cn it. "d" is the number of decimal digits to be retained in the fractional part of the value to be printed. The fractional part of the value will be rounded to "d" digits. ''n'' is the total number of characters in the field. "c '' through "cm," are the characters. They may be any of the alphabetic, special or numeric characters available in Fortran. There is no variable On the Variable List corresponding to an H field. If the width "w" is greater than the number of printed positions needed, the printed value will be "right-justified" within the 150 F Fields Floating Point values should be field. * printed in F-type output fields. The general form is: I Fields Fixed Point values should be 149 printed in I-type output fields. The general form is: nFW. d ''n'' is the number of fields described. If ''n'' is not specified, it is understood to be One. nIw Concepts (cont.) X Fields ''n'' is the number Of fields described. If ''n'' is not specified, it is understood to be one. º "I" is the conversion symbol sº for Fixed POint values. sº ''W' is the "width" Of the field – à the number of print positions in it. If the width, "w," is greater than the number of print positions needed, the value will be right- justified within the field. Fields of blanks for spacing, etc., may be specified in an º output FORMAT statement. The general form is: sº & º º ''n'' is the number of blanks in the field. "X" is the symbol for blank fields. If the Variable List contains more variables than the output field specifications in the output FORMAT statement, the entire FORMAT Statement (including carriage control) will be repeated, and will automatically apply to the next line Of Output. Source Program Preparation CONCEPTS Coding Sheets Fortran Coding Sheets are available from computer installations, manufacturers, and business forms companies. Source Programs should be on these sheets in pencil, for easier correction. Statements should be written in large, unambiguous characters. The following conventions may be 29 Reference Manual 150 193 194 Statements (cont.) 35 Statement Number followed: Continuation 0 – for zero 1 — for One 2 – for two Q – for the letter O I - for the letter I Z - for the letter Z. Comment Statements should start in column 7 and not exceed column 72. Column 6 should be used only for continuation of a 3. previous line, and statement numbers may be written any- where in columns 1-5. Any statement may be numbered. Statement numbers, however, have no effect on the Order in which the StatementS are exe- cuted. Numbering is for reference purposes only. State- ment numbers may be written anywhere in columns 1 through 5. They must be unsigned, and should not exceed the number of storage cells in the computer. No two statements in the same program may have the same statement number. Data Preparation Reference Manual One statement may be "COntinued." Onto another tab card (or line on a coding sheet) by writing any nonblank character in column 6. There may not be more than nine COntinuation cards for One Statement. A Comment may be inserted anywhere in any program. It is not compiled, but is listed in the printout of the Source Program. The general form is: | C Any legal characters The character, "C" is in COlumn One. Keypunching of data is the user's responsibility. The layout of data is extremely important. It must conform to the expectations of the program using it. It must, therefore, be carefully edited. 35 57 Index Items in capital and lower case letters are referenced to concepts in the Reference Manual. ITEMS IN CAPITAL LETTERS ARE REFERENCED TO STATEMENTS IN THE REFERENCE MANUAL. Items in bold face are referenced to main headings in the Reference Manual. Items in italics are referenced to the Program directly. A Accumulating 108 Arithmetic Statements 106 C CALL 179 Carriage Control 191 Coding Sheets 193 Comment Cards 194 COMMON 185 Compilation 23 Computations 188 Constants 180 Constants, Storage of 185 Continuation 194 CONTINUE 188 Control 186 Conversion to Fixed Point 189 Conversion to Floating Point 189 D Data Fields, Input 183 Data Preparation 194 Defining a Variable 108 DIMIENSION 184 DO 186 E END 179 Exit 180 Expressions 188 F F Fields, Input 184 F Fields, Output 192 First Statement Executed 180 Fixed POint COnStants 181 Fixed Point Variables 181 Floating Point Constants 180 Floating Point Variables 181 Flow Diagrams 6 FORMAT, Input 182 FORMAT, Output 190 Functions 189 G GO TO 186 H H Fields 191 Hierarchy of Operations 189 195 | IF 186 I Fields, Input 184 I Fields, Output 192 Incrementing 107 Input 182 J Job 43 L Last Statement Executed 180 List Control, Input 183 List Control, Output 190 M Main Program 179 Mixed Expressions 188 Multiple Fields 80 N Nonsubscripted Variables 185 Normal Flow of Control 188 0 Object Programs 20 Operation Symbols 188 Output 190 --~~ - - - *T - - •. } - - \ P Parentheses 189 PRINT 190 Program Structure 179 Punched Cards 34 R READ 182 Repeating Input FORMAT Descriptions 184 Repeating Output FORMAT Descriptions 193 RETURN 180 S Source Program Preparation 193 Statement Numbers 194 Storage Allocation 184 Subprogram 179 SUBROUTINE 179 Subscripted Variables 181 Subscripted Variables Storage 185 W Variables 181 X X Fields 193 Index 196 FORTRAN coping Form . - C = ** * - - - - - - - - comMENT FORTRAN STATEMENT STATEMENT NUMBER FORTRAN coding ForM FOR C < FORTRAN STATEMENT CO M M ENT STAT E M ENT NU M BER | 5 º FORTRAN coolNG Form FORTRAN STATEMENT FOR STAT E M ENT NU M BER C < CO M M ENT FORTRAN coping ForM FOR C < FORTRAN STATEMENT CO M M ENT STATE MENT NUM BER l 5 + - - f . FORTRAN coding Form FORTRAN STATEMENT FOR STAT E M ENT N U M BER ! 5 C < CO M M ENT FORTRAN coding Form C < FOR CO M M ENT FORTRAN STATEMENT STAT E M ENT NUMBER I S. $ - - *- ~ - FORTRAN coding ForM FORTRAN STATEMENT : 6 FOR STATEM ENT NUM BER C < CO M M ENT FORTRAN coding ForM FOR C < FORTRAN STATEMENT COMMENT STATE MENT N U M BER I 5 - ORTRAN coding Form FORTRAN STATEMENT C < STATE MENT N U M BER CO M M ENT FORTRAN coolNG ForM FOR à < º C comMENT : FORTRAN STATEMENT STATE MENT : , number 5 || 6 |7 72 FORTRAN coding ForM FORTRAN STATEMENT 6 FOR STAT E M ENT NU M BER | C < CO M M ENT FORTRAN coping Form C < FOR # CO M M ENT ; FORTRAN STATEMENT STAT E MENT : N U M BER Q 1 5 6 7 72 : Tº º Tºº Tºº Tºll tº Tºº Tºº Tºº Tº TūT. Tº Tºm FORTRAN STATEMENT FOR STAT E M ENT NU M BER I 5 C < CO M M ENT FORTRAN coding ForM FOR C < CO M M ENT FORTRAN STATEMENT STAT E MENT NUM BER ! 5 UNIVERSITY OF MICHIGAN , ! |||||||||||||||||||||||||| 3 9015 06829 2492 -~º: …, -.-.-; … ~~~~. :-) → «ºrtº-~~~~); №r: ***… :- !, --~~~~~~*=~~~~);- ; -,- -- - ---· *·• , ,· • ¶-.**-~ _ ·* į , . - - -;«? —~~~~ ~~~~ ~~~~x : ! », « —• • • •~~ --+----- -> ~~~~~ ·... - …-+ - - - . r~~~~ ~~~~);** --~~~~–.- ---- ~- - .-> --~~~~ · · · · · · · · · · · · · · · -.3- -· · · ·- *-- - - - } * §: & ! .* \ & } * - *...* : * * * - , ºr . . - * --~...~~~~~ . *: º tº f d [ _ \ } , # ‘. . ; '*. s . * ,” * *-** *...; f ſº º ſ * %),- . … ~ * *-ș**- .! -*-- -**~~~~ . . . . . . ; , , , į.----* * a.--------º- (---) ****_*=~- -* …–.…*- -** --→—— --_.. (...-…... →* * ·,≤)&((**) ***.**