ebook img

From Pascal to FORTRAN 77: Applications for Scientists and Engineers PDF

308 Pages·12.817 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview From Pascal to FORTRAN 77: Applications for Scientists and Engineers

—-+ oe , FS = = — Ss iY L esl 2 — =F Quick Index to FORTRAN 77 264 BACKSPACE unit 187 BLOCK DATA name 101 CALL sub_name (arg, {,...} {, arg,} ) 145 CHARACTER {+ length} var_name {( subscripts )} 145 CHARACTER+«(*) var_name {( subscripts )} 149 CHARACTER+(*) FUNCTION function_name (arg, {,...} {, arg,} ) 265,273 CLOSE ( unit {, STATUS = [‘KEEP’]/['DELETE’]} {, IOSTAT = check? ) 182 COMMON / name /v ar_list 62,166 COMPLEX var_name {( subscripts )} 40 CONTINUE 70 DATA varib_name / const / 41 DO label varib = init, final {, step} 62 DOUBLE PRECISION var_name {( subscripts )} 16 ELSE 16 ELSEIF ( log_expr ) THEN END ENDFILE unit ENDIF label FORMAT ( field, {, . . .} {, field,} ) date_type FUNCTION function_name (arg, {, .. .} {, arg,} ) GOTO label IF (log_expr ) THEN INQUIRE ( [UNIT = unit]/[FILE = ‘file_name’] {, ERR = error_label} {, EXIST = log_ exist} {, NAMED = log_named} {, IOSTAT = check} {, OPENED = log_opened} {, number = unit_numb} {, NAME = file_name} {, ACCESS = char_access} {, SEQUENTIAL = char_seq} ({, DIRECT = char_direct} {, FORM = char_form} {, UNFORMATTED = char_unform} {, RECL = rec_length} {, NEXTREC = next_numb} {, BLANK = char_bla} ) 62 INTEGER var_name {{ subscripts )} 120 (1/O_list, varib = init, final {, step} ) 62 LOGICAL var_name {( subscripts )} 268,274 OPEN (unit {, FILE = ‘file_name’} {, STATUS = [‘'NEW’]/[‘OLD’]} {, FORM = [‘FORMATTED’]/['UNFORMATTED’]} {, IOSTAT = check} ) (continued on inside back cover) FROM PASCAL TO FORTRAN 77 APPLICATIONS FOR SCIENTISTS AND ENGINEERS DAVID DONALD MILLER Bemidji State University HARCOURT BRACE JOVANOVICH, PUBLISHERS and its subsidiary, Academic Press San Diego ¢ New York ¢ Chicago ¢ Austin London ¢ Sydney ¢ Tokyo ° Toronto FROM PASCAL TO FORTRAN 77 APPLICATIONS FOR SCIENTISTS AND ENGINEERS Microsoft is a registered trademark of Microsoft Corporation. MS is a trademark of Microsoft Corporation. HP and Touchscreen are trademarks of Hewlett-Packard. DEC, VAX, and VMS are trademarks of Digital Equipment Corporation. Copyright © 1987 by Harcourt Brace Jovanovich, Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopy, recording, or any information storage and retrieval system, without permission in writing from the publisher. Requests for permission to make copies of any part of the work should be mailed to: Permissions, Harcourt Brace Jovanovich, Publishers, Orlando, Florida 32887. ISBN: 0-15-529175-0 Library of Congress Catalog Card Number: 86-70532 Printed in the United States of America PREFACE In recent years, the popular computer science programming textbooks have been gradually swinging toward Pascal, primarily because computer science concepts are easily taught and learned using Pascal. But other disciplines, in particular engineering and the physical sciences, require a knowledge of programming. In the engineering work-a-day world, pro- gramming is firmly entrenched in FORTRAN for the following reasons: = Because of its simple structures, FORTRAN is easy to use in some applications. = FORTRAN offers mathematical sophistication not available in standard Pascal or in any Pascal extensions. = FORTRAN supports a wide variety of file manipulation constructs not available in standard Pascal. Vv vi — Preface = A real-world application often involves a combination of several subprograms, which is supported by the FORTRAN system but not by Pascal. = Because of its longevity, millions of lines of FORTRAN already exist and must be maintained (modified, added to, and used). = FORTRAN compilers are usually error free and generate optimized code. From Pascal to FORTRAN 77: Applications for Scientists and Engineers is directed to those students who have been introduced to programming through Pascal but whose career goals are in engineering or the physical sciences. Such students will need a working knowledge of FORTRAN. This textbook is also directed to practitioners who must make a transition from Pascal to FORTRAN. FORTRAN is a programming language of the ancients—it could even be called a classical language, since in the world of computers 30 years is quite a long time. And, just like an old house, it has acquired a whole attic full of elaborate rules and special cases. Many of the original FORTRAN constructions have been replaced over the years, because we know more about compiler languages now than we did when FORTRAN was pi- oneering the field. This book cuts through the historical bric-a-brac and concentrates primarily on the most useful parts of FORTRAN. Inciden- tally, many of the best parts of FORTRAN have Pascal counterparts as well, and I will draw heavily on the student’s Pascal knowledge to show, by example and counter-example, FORTRAN and Pascal code side by side. The older FORTRAN constructions have been included, for the sake of completeness, in an appendix, because students will surely see older ver- sions of FORTRAN in their careers. HOW TO USE THIS TEXTBOOK The material moves along quickly, especially through the introductory chapters. In fact, the student will be coding simple programs at the end of the first chapter and writing serious FORTRAN by the end of the third chapter. Each chapter contains the following features: = A discussion of the chapter material, often including FORTRAN program segments and the equivalent Pascal segment for comparison. Preface vil m An example, including explanation, algorithm, commented code, sample execution, and testing suggestions. m ‘Pitfalls’ that a Pascal programmer and a novice FORTRAN programmer would be likely to encounter. @ Exercises that elaborate on the example and that introduce related topics. The text makes the following assumptions about the student’s level of computer expertise: . m It assumes the student has already been introduced to such primary programming topics as basic computer architecture, interactive terminal sessions, program structure, and the like. The student’s time will not be wasted by the introduction of that kind of information again, and the text will, instead, draw upon that knowledge and extend it. = It assumes the student is acquainted with problems that occur in the physical world—some of the examples may have been seen in other courses. m Since this is a textbook for engineers and other physical scientists, most of the examples and exercises are drawn from the scientific and mathematical world; the student will never have to compute a payroll. A few examples involve games, since programming should be fun too. Some problems involve mathematics through calculus and, in some cases, differential equations. But higher math is not normally required, especially early in the text. The intention is to introduce real-world problems, approaches, and software solutions, and in doing so, to introduce topics like modeling functions, solving systems of equations, and numerical integration. All of the students’ acquired mathematical skills should be brought into focus in this course. The last point requires some elaboration: Computer generated an- swers tend to be believed without supporting evidence. This is an ex- tremely dangerous attitude and one that should be corrected. A secondary purpose of the text is to illustrate some introductory applications of digital computing in a practical world. This is not supposed to be a nu- merical analysis course, but it may well be the only exposure some stu- dents will ever have to the subject. I am concerned that students learn both the possibilities and the impossibilities of digital computation, and that they be made aware of the misapplication of computers as well as viii Preface their applications. I have tried to impart a “feeling’’ for detecting unrea- sonable answers—and have listed some heuristics that may help students examine their code when they are suspicious of their answers. One other thing: This book will force students to go back into some of their ‘‘old” textbooks. Maybe they thought they would never have to open them again, but I want them to know that education in a technological world is never ending: Those texts are still valuable. Several of the exer- cises are designed to send students into those other books to look up deri- vations and formulas: I have not simply provided the necessary equation as part of the exercise. That is how it is done in industry: Employees are given a problem statement and it is up to them to define an approach and do the necessary research. This book concentrates on the standard, FORTRAN 77. Many of the examples here are coded using VAX FORTRAN in the “‘standard’”’ FOR- TRAN 77 mode. Several of the examples are also coded using MS-DOS FORTRAN on the HP 150: Touch Screen. MS-FORTRAN is based on the “subset” standard FORTRAN 77, which in this case also includes many “full” standard features. It has its shortcomings, however, and when it is appropriate, I warn the student of any implementation-specific snags that I have discovered in the process. Maybe they will not have any trouble on their particular machine and maybe they will have other problems. ACKNOWLEDGMENTS I wish to thank the following reviewers for their helpful suggestions: Bev- erly Bilshausen, College of DuPage; Mark J. Christiansen, Georgia Insti- tute of Technology; Larry Cottrell, University of Central Florida; Charlotte Fischer, Vanderbilt University; Charles Gould, Florida Institute of Tech- nology; Lawrence O. Hall, Florida State University; Larry Neal, Eastern Tennessee State University; Charles Neblock, Western Illinois University; Bob Pabasco, University of Idaho; Jim Pannell, DeVry Institute; Paul Paul- son, Central Michigan University; Don Ramsey, Tennessee Technological University; Paul Ross, University of Millersville; Richard Sleight, Univer- sity of Washington; and Terry Smith, Northeastern University. DAVID DONALD MILLER

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.