An Introduction to Fortran Programming
Total Page:16
File Type:pdf, Size:1020Kb
--,-"N* ,,-.0 IDOCOIRNT prsunt 'ItO 193361 . $1 029 526 AUTHOR, Fisher D. D.: And Others TITLE An,Int;oduc.tion,to Fortran Programming': An XPI Approach: INSTITUrION Oklahoma Statv Univ*, Stillwater, S'PONS AGENCY ' National science Foundation, Washin-gton: PUB DATE 71 GRANT NSP-GY19310(EN) NOTE '3B2p. 0 0 r.DRS PRICE HF011PC16 Plus Postage. DESCRIPTORS . Computer 'Oriented Programs; Computer Science; *Compoter Science Education; Flow Charts; Higher -FidmeatIen: *IwavidualizedInstrqcLionl Invut 0-u-tputt .*Pacing; *Programing: Programing Languages; Programing Problems - IDENTIFIERS *FORTRI Programing.Language 111STRACT This text.is 'desi'gned tb give individually paced ins ion in Fortran Programing. The text contains fifteen units. Unit :4tles Include: Flowcharts, Input and Output, Loops, and ' Debugging. Also ingluded.is an extensive set of appendices. These were designed to coritain a great deal of practical informatiOn necessary to the codrse. These appendices include iristructions for operating card readers, listers, printers:and terminals,as well as a 'omputer science glossary. (MK) 0 1. etiv r 4 ,ReproductiOns.lupplied by"EDPS are the1beSt thatgan be mada * * fr9m the original document. *****t************************* 1NTR ts r.. __. ORTRAN ". r AN INDIVI WALLY PACED ', INSTRUC ION APPROCH A a, a II HI\41'.',It I 'Hi 'H PI, , I tic , ti % QC PAR TME NT OF Ha Al TH MA' t * DU( ATION J. Nit lr ARE IIA t'tI 4 ,AjIi 1.) HY NA TIONAl INSTVUTE OK /1 f DUC AT ION MGkryLCbckett,(5 t.. N fIASIU f N I f KA. v 141I .v1 f (IAA t..I u .oN .)14,f4t.ANI/ A (,{7....N P (WI N Mg ti,Nit".N, 1, (Jol.a NI N.,A41,1 141 I l.. , A NA )7.4 A; IN.,1I o,I f 10,1 '..)I I N1'. 1 1 (1 A ,N !11N( IN 14.1l F. )f,,, i; laigoma StareUn)versity. anuary; 1972 6,9parlmentof Computing and InformationScienoos &XL GENERAL 17 FORTRAN PROGRAMS S. 14 ARITIRIM4 COMTE& Cowers ,IEBUaGING CONCEPTS r \ FORMATS 11- I/0 SURROGRAMS LOQPS; 10 ITERATION ARRAYS , 9 SUBSCRIPTED VARIABLES CONDITIONAL BRANCHES READ WRITE IMPB4CRNG 5. tROGRAM. DOCUMENTATION MINING A SIMPLE ..TT RTRAN PROGRAMING UNCONDITION-4 HIRARCHY . AL BRANCHES STATEMENT 'NUMBERS CONSTANFS 3 VARIABLES - FLOWCHARTS EXPRESSIONS ASSIGNMENT ?it STATEMENTS; yr- of.ass. Kt. ve4ia 4.6431 .W4 "°.t" I 4 TERMINAL FAMIL-I. S. IARIZATION OMRCARDS ammidiqte AUCOQS0 Wit) er .1t N\ /VI Introduction 'to Fortran Programming . An Approach -^, Copyright 1911 D. D. rishor T. L. Bailey D. H. Seeger OklahoMa etate Univelity All Rights Reserved , PrtnEed in the United.States of America Composed and Brinted by the Division of Engineering 0%, Oklahoma 'State University Stillwater, Oklahoma 74074 4 No part of th.4 material Wilay be used or reproduced ' in any manner Obatsoever without permission,.exceptin the case of brief quotations'embodied in critical.articles and reviews. V4Revised December, 1971) a 4 is,- -- za=.34, , * PREFACE The main objectiveof the Fortran pi2Ogramming units isto de- ;. velop the necessaty pkillsto ( ) translate a problem.stateventto a programming problem statement; (ii) developa debugged progra'M that obtains a "workable" t. solution for the original problem;, (iii) prepa e a description of the programso that others may malcc;use of the program, or the author mayuse the pro- gram at a later date with a minimum inVestment in time; (iv) accomplish the-previous three skills with,reasoilable degrees of efficiency.. To accomplish'0.5 and (ii) it isnecessary tp learn a computer --, programming language ond to practice thetranslation phase fô x. a variety of problems. Preparing pkogram descriptions and develop- \ ins efficiency will be emphasized at each step. Several programs . will be written that may be usedas problem salving tools in sub°.t' sequent courses. A programming language isa language used to describe an also- rithm, that is, a procedure for solvinga problem, in such a way ' that a computer cian interpret the'algorithmand can carry,out each ' of the :s4ops prescribed by the algorithm. Programming languages vary in complexity. In general the languages thatare easiest for . 7 the machine to uae require considerableknorledge of the computer pn the programmer'll part. On the other hand, languages thatare .r easiest for 0.11,1 prolerammer touse generally require the- computer to translate Ole program from the-source languageto. machine len- : suage. The translation process'fromsource language to.machine or object languae, is a task thatcomputers do reasonabf well; con-. sequently.,alost of the programs written todayare_written ln so- called "higher level" programming languages,which.invoke the com-. puter to trawl-late as well as to oompute. Fortran (an acronym obtained from formulatranslator) is an example of a higher level programming language-It is the most widely ubed programming langtage for scientificapplications. There are many variationsor dialects of Fortran. Ydu should be aware that different computer manufacturers support different dialects, one manufacturer may support different diale.cts,and users maycrletheir own dialeas. In order to be able to move programs from one computer installation to another', it isnecessary - to hav \a set of standards. Appendix I gives comparisons between. a USAstalardFortran'and,other available Fortrans. The U64S BASIC Fortran is a subset bf USAS FULL Fortran. It is likely that you will discover useful features bf some of thecompilers-that are not included in USAS Fortran. If you use those featureit,you do so flat your own risk. Someeatures notincluded iUSAS.Fktran are very desirable; consequently, if it is unlikely that the pro.:- gram will haye to be run on different computers, it is wortfiWhilm * to make use of those featpres. On the other hand, if a prosram'i6 todbe run at several.differentcomputer installations, oeilly those ' ' AtZ' 1. features liseed in USAS Fortranshould bq used. 7C, Thils4is an. examiile of one ofmany possible choices yoU may make while completing thecomputer science units:\ Other decisions willlbe required to'geta program to "work," to transforma work- ing program to an effici ntprogram, to "tune" a program, etc. :An aspect of computinemany find challenging is that,in generalt.there . , _ . is to best way to attack'a new problem. You will find this to be true in some of the programs you attemptto develop. Othelr higher level,progreTming languagesin widgspread use- t.. , are listed below.. Cobol a business language RPG a report generator used primariLy for business appliNtions PL/I combines features of Algol, Fortran andGobol Algol a scientific language Basic a versiOn of Fortran used in cotpinction with. typewriter like eerminals APL .a mathematical language Assembler a form-of machine language a everal dndergraduate and graduatecourses make use of these and other programming languages..Translator's of varying sophistica-. tio4 are req9kre convert programs l'rom these source languages 1 to machine languege Take some time to examine the Organization ofthp book.' The 1:nstruaional materialsare organized into units in the text.. 4 Each unit contains a daacriptive title,a rationale explaining..the purpose for includingthemaier l in the uniti'tha bihavioral ,e is 7' % objective thaI.states what5Tu will be able to perform afteryou have mastered the material inthe,unit,.prerequisites for the unit, - a series of activities desrgned to point you-inth,directiepn of the objective and helpyou. attain it, some self evaluation matbri-:- als sp that' you can assess for yourself wheth(4: you have attained. the objective, assessment tasks withwhich you demonstrate toyour., instructor alat'you.have:fattainag.theLohje"ctiveandpnallyin', structions telling you what to donext. The book.also containsa rather extensive set of appendic-es. - Read the titles of the'appendicesin the-Table of Contents, and thumb'through them. They contain a great deal pfpractical infor- mation that you Will need throughout thecourses; ,Particularly at this time'be aWare of the appendixcontaining tWe glossary of terniS. If terms which you do not underssandappear in the text, look for th'em in the glossary. If there are omitted terms Which,youthink should be included in the glossary,write them down and give them' - to your instructor. The page numbers in the textare designed to be usedfor quick 1. referencing. The first number is the unit number, andthe second nuMbet liumbers the page insequence in tfiat unit: For exabple, page 8.3 is page 3 r Unit 8. Adpendices are'numberedsimilarly except that Roman numerals are used. For,example, page V.2 ispage 2 of Appendix V. The cover of the book shows thesequence of units 'forthe course in the fotm of a fldw chait (discutoi;ed furtherin Unit 2). This flOW chart will help y.ou toassess your progress 'toward tilt ;\cterminalunit. iv A .eve - Unit1 requires a card l'eader with optical mark read (OMR) capability. If this feature is not available, then Unit Imay be 4,s 1 omitted without disturbini the sequence of t1ie material. 4r. soft) 1.r se 1 ro ,9 It TABLE OP CONTENTS . Unit 1. Becoming Acquainted With the Computer 2. Flowcharts 3. Variables, Consta4ts, txpressions.and AssignmentStatements 4. Statement thnlbers ancPUnconditional Branches 5 4 Preparing a ?iob for Runningon the Computer 6. fnput and Output ! 8. Conditipnal Branching or Transfer Statements 9.: Arrays and Subscriptea Variables 10. Lobps )( 1Y. Input, Output, Formats 12. ,Arithmetic Concepts 13, Subprograms 14. Debuggimg 16, Computer Concepts 17. General Forti:an Programs Units 117 and #13 are omitted% APPENDIX,J. Comparisons of Various Fortran Implemeritations APPENDIX II: Computeer Science Closaary APPENDIX III. Running a WATFIV ...lob on the IBM System/360 Model 65 User Terminal 'APPENDIXIV. Additional Instructions for Operating the IBM 2501 Card Reader APPENDIX V. Instructions for Using the IBM 1403 Printer . APPENDIX VI. How to.Get an 80/80 Listing With the *ystem/360 a User TermUal a 4 vi 4 APPENDIX VII. Running Fortran Jobso the IBM 1130 Computer APPENDIX VIII, User Terminal WATFIV APPENDIX IX.