a text bookon compurter

15
A text bookon Compurter Ogramming with INDUSTRIAL & ENGINEERING APPLICATIONS S.RAMANI N.V.KOTESWARA RAO R.NAGARAJAN START READ FOREWORD PREFACE.LIST OF CONTENT YES DO YOU NO KNOW FORTRAN OUT OF MEMORY READ THE CASE STUDIES READ ENTIRE BOOK NO ES ERSTOOD ? UNDERSTOO0? ai Irigasi 3/8 CAME ACROSS ANY ERRORS NO YES COMMUNICATE WITH PUBLISHER RECOMMEND THIS BOOK TO OTHER STOP

Upload: others

Post on 02-Jun-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: A text bookon Compurter

A text bookon

CompurterOgramming

with INDUSTRIAL & ENGINEERING APPLICATIONS

S.RAMANI N.V.KOTESWARA RAO

R.NAGARAJAN

START

READ FOREWORD PREFACE.LISTOF CONTENT

YES DO YOU NO KNOW FORTRAN

OUT OF MEMORY READ THE

CASE STUDIES

READ ENTIRE BOOK

NO ES ERSTOOD ? UNDERSTOO0?

ai Irigasi

3/8 CAME ACROSS ANY ERRORS

NO YES

COMMUNICATE WITH

PUBLISHER

RECOMMEND THIS BOOK TO OTHER

STOP

Page 2: A text bookon Compurter

A TEXT BOOK ON

COMPUTER

PROGRAMMING

th inoustriai

Engineering Applications

Da S. RAMANT

Departmem af Humanites & Social Scienes

(industr Enginetring & Matagemem)

indian Institute of Technnio

Madras-6ON36

Da N. V. KOTESWARA RAO Senior Technicai Ofmoer

Electroic Corporaion of India Lid

Hyderabad-500762

Dr R. NAGARAJAN

Compuier Cente

Indian Institute of Technology Madras-600036

CBS

CBS PUBLISHERS & DISTRIBUTORS

485, Jain Bhawan, Bhoia Nath Nagar Shahdra. Delhi-110032 (India).

Page 3: A text bookon Compurter

CBS Publishers and Distributors, 1981

All ri ghts reserved. No part of this publication may be reproduced or transmitted, in any form or by any means, without written permission from the author and publishers.

First EditionSecond Edition: 1977 Reprint

: 1970

:1981

Price 35.00

Distributors

College Book Store 1701, Nai Sarak, Delhi-110006 (India) Published by Satish Kumar Jain for CBS Publishers and Distributors. 485, Bhola Nath Nagar Shahdra, Delhi-110 032 (India) Printed at Goyal Offset Press, Daya Basti Delhi-110007.

Page 4: A text bookon Compurter

FOREWORD

The versatility of the digital computer in all kinds of infor-

mation processing applications is having a profound eftect not

only on the educational system, but also in business, industrial

and governmental procedures. As far as education is con-

cerned, there are two parts to be considered one dealing with

computer design and development; the other to treat the com-

puter as a tool. Education, in the use of a computer as a tool, cannot be properly taught without a computer with which to

experiment Computer development with its emphasis on nume-

rical methods has an advantage of practical generality not

possessed by classical methods. The operations executed by a digital computer must be

planned in advance

in numerical methods and computer programming is a must at

the present time for engineers and scientists. There are features

in common to several problems and it is possible to use

programines which are available. Thus, programme libraries are

developed over the years by expert programmers.

This book on 'Fortran Programming is indeed most

timely, as the computer ficld has literally exploded upon our

society. The authors have lucidly explained the procedures and

illustrated the same with worked examples and case studies in

a variety of fields.

I have great pleasure in commending this book to all

interested in learning Fortran Programming.

a process called programming. A course

A. RAMACHANDRAN,

Director.

16th May 1970. Indian Institute of Technology, Madras.

Page 5: A text bookon Compurter

PREFACE TO THE SECOND EDITION

While introducing the second edition, the authors have

kept in mind the need to preserve the structure of the first edition which apparently was well received. However, in addi-tion to the chapter on Digital-Analog Simulation an appendix on details of the continuous system modelling programme (CSMP) has been included with suitable illustrations. Some more appendices have becn added.

Some

Page 6: A text bookon Compurter

PREFACE

While compiling this book the authors have taken into consideration the needs of students, research workers and programmers, in the area of Fortran programming. Besides Serving as a text-book for students, the book will cater to the needs of industries faced with the problem of programming in Fortran. The authors have anticipated the doubts that are ikeiy to arise in the minds of the readers on exposure to Fortran programming without access to a computer and the text has been suitably presented.

Numerous solved examples and exercises have been given towards the end of each chapter to enable the reader to assess and reinforce his own understanding of the concepts.

The chapters have been arranged in such a manner that an understanding of a chapter in the text does not depend upon the material provided in a subsequent chapter.

Another feature of the book is an effective treatment of FORTRAN IV in addition to FORTRAN II. This is in in keeping with the trend that modern digital computers invariably employ FORTRAN IV compilers.

Chapter 1 of the book introduces the reader to computer programming. Chapters2 through 8 deal with the various aspects of FORTRAN II. Chapter 9 deals exclusively with the

various aspects of FORTRAN IV. Chapter 10 deals with Digital-Analog Simulation techniques, which are versatile and particularly useful for solving problems arising in the Chemical Engineering Industries.

Chapter 11 deals with miscellaneous topics such as economy of computer time and programming for efñiciency. Some useful and informative case studies of interest to research workers and industries are given in the later part of the book. The case studies cover several branches of engineering besides numerical analysis.

The book also includes a few useful Appendices towards the end.

Page 7: A text bookon Compurter

viil

The authors have great pleasure in recording their gratitude

to Prof. Dr. A. Ramachandran, Director, Indian Institite of

echnology, Madras, for his encouragenient throughout th varicus stages of writing this book and for having given th»

Foreword. The authors thank the Deputy Director, the Heads

ot the Departments of Humanities and Social Sciences, Mathe- matics and Chenmical Engineering, and Prof, Dr. S. K. Srinivasan

for their sustained interest during the preparation phase of this book. The authors also thank Shri T. V. G. K. Murthy of I.I.T.

tor his constructive criticisms and Mr. S. Ananthanarayanan,

Data Processing Manager, Integral Coach Factory, Madras for his helpful suggestions.

The authors also wish to thank Prof. K. S. Hegde, Prin-

cipal, Co!lege of Engineering, Guindy, and the authorities ot the Fundamental Engineering Research Establishment for having given them opportunities to work on the IBM 1620 computer

ACKNOWLEDGEMENT

The authors thank M/s. International Business Machines Corporation for kindly permitting the publication of the photo-

graphs of their data processing machines. The authors wish to place on record the co-operation

offered by M/s. Jupiter Press Private Ltd., Madras and thank them for the excellent printing and binding work executed by

them including the cover design.

Page 8: A text bookon Compurter

cONTENTs

Page

Foreword

Vi Preface vili Acknowledgement

INTRODUCTION TO COMPUTER

PROGRAMMING CHAPTER 1

Historical Backeround 2

1 4

1.1 The Digital Computer Flow Chart

1.

I.4 1.5

3 Solved Examples Exercise1

15 18 20

ARITHMETIC EXPRESSIONS AND

STATEMENTS CHAPTER 2

Introduction Arithmetic Expressions Fortran Constants

Fortran Variables

22 23 26

2.2 2 .3

2. 2.5

4 Rules regarding Naming ot

Variables 26

2.6 Rules regarding the Use of

Operation Symbols 2.7 Hierarchy of Arithmetic

Operations Use of Parentheses Rules regarding Parentheses

Arithmetic Statements

Built-in Functions

Soived Examples Exercise 2

27

2.8 2.9 2.10 2.11

29 30 31 31 34 36 49 2.12

2.13

INPUT, OUTPUT AND FORMAT STATEMENTS CHAPTER 3

52 53 3.1 Introduction

3.2 3.3

Input and Output Devices

General Form of Input/Output

Statements 53

Page 9: A text bookon Compurter

Page 3.4 Precautions regarding

Input/Output Statements 55 56 Other Features 3.5

3.6 Format Statement 3.7 Genceral Forms of Basic Format

57

58 64

Specifications 3.8 Blank Field Specitication 3.9 Use of Slash 3.10 Hollerith Ficld Specification 3.11 *A" Specification 3.12 Multiple Use of Single

Specification 3.13 Solved Examples 3.14 Exercise 3

65 66 68

69 72 83

PUNCHING OF FORTRAN STATEMENTS

CHAPTER 4

4.1 The 1IBM Punched Card-Historical Development

The Punched Card Concept 3 Identification of Cards

87 87 89 90

4.2

The Card Punch and Verifier 4.5 Punching of Fortran Statements..

Solved Examples

4.4

94 95 97

4.6 4.7 Exercise 4

CHAPTER5 CONTROL STATEMENTS

5.1 Introduction 98 5.2 Statement Numbers 5.3 Classification of Control

Statements 5.4 Unconditional "GO TO"

Statement 5.5 Conditional Control Statements:

(i) "IF" Statement

98

99

99

100 (1) Computed " G0 TO"

Statement 5.6 Logical Control Statements 5.7 PAUSE Statement

STOP Statement 5.9 END Statement

102 103 103 104 105 106 111

5.8

5.10 Solved Examples 5.11 Exercise 5

Page 10: A text bookon Compurter

xi Page

CHAPTIR 6 SUBSCRIPTED VARIABLES, "DIMENSION" AND "DO" STATEMENTS

6.1 115 Subscripted Variables 6.2 Rules regarding Subscripted

Variables 6.3 DIMENSION Statement

116 118

6.4 General Form of a DIMENSION

Statement "DO" Statement

6.6 General Form of a " DO"

118 120 6.5

120 125

Statement 6.7 CONTINUE Statement 6.8 General Form of a CONTINUE

Statement 125 126 6.9 Rules regarding DO Statements

6.10 6.11 Solved Examples 6.12 Exercise 6

127 130 138

Nested D0 Loops

ADDITIONAL FORTRAN

STATEMENTS CHAPTER 7

140 140 7.1 CALL EXIT Statement

DEFINE DISK Statement

RECORD Statement

FETCH Statement

FIND Statement

7.1 7.2 142

143 7.3 7.4 7.5 7.6 1.7

144

144 IF (SENSE SWITCH) Statement

145 IF(OVERFLOW) Statement

IF (ACCUMULATOR OVERFLOW) Statement

7.9 IF (EXPONENT CHECK)

Statement

7.8 146

146 147

147 7.10 ASSIGN Statement

Assigned GO TO Statement 7.11 7.12 READ DRUM Statement

7.13 7.14 READ TAPE Statement

7.15 REWIND Statement

7.16 EQUIVALENCE Statement 7.17 Solved Examples

148

148 READ INPUT TAPE Statement

149

150 I50

152 153

7.18 Exercise 7

Page 11: A text bookon Compurter

xii

Page CHAPTER 8 ARITHMETIC STATEMENT FUNCTION ANDD SUB-PROGRAMMES

8.1 8.2 8.3 Rules regarding an Arithmetic

Introduction Arithmetic Statement Function.. 155

154

Statement Function Sub-Programme 8.4

8.5 RETURN Statement 8.6 FUNCTION Sub-Programme 8.7 FUNCTION Sub-Programme

155 157 158 158

Statement 159 8.8 Rules regarding a FUNCTION Sub-Programme

8.9 SUBROUTINE Sub-Programme. . 8.10 SUBROUTINE Sub-Programme 160 162

Statement 162 8.11 Rules regarding a SUBROUTINE Sub-Programme 8.12 CALL Statement 163

165 8.13 Differences between FUNCTION Sub-Programmes and SUBROUTINE Sub-Programmes 165

8.14 COMMON Statement 166 8.15 Rules regarding COMMON

Statement 8.16 The Other Type of CALL Statement

168

8.17 Solved Examples 8.18 Exercise 8

169 171 185

CHAPTER9 SOME ASPECTS OF FORTRAN IV

9.1 Introduction 9.2 Constants, Variables and

Expressions 188

188 9.3 Logical Constants and Variables 190 9.4 Relational Operators and Expressions 190 9.5 Logical Operators and Expressions 191 9.6 Logical Assignment Statement.. 9.7 Logical Statement Function

Logical *" IF" Statement

9.9 Complex Variables and Expressions

192 192 193

9:8

195

Page 12: A text bookon Compurter

xii Page

9.10 Complex Arithmetic Statement 9.11

196 Double Precision Variables and

Expressions 9.12 Type Declaration for FUNCTION

Sub-Programme Statements

196

198

199 201 202 203 204 205 206 209

9.13 COMMON Statement 9.14 DATA Statement 9.15 BLOCK DATA Sub-Programme 9.16 9.17

Input and Output Operations L and D Format Specifications..

9.18 Library Functions 9.19 Solved Examples 9.20 Exercise 9

CHAPTER 10 DIGITAL-ANALOG SIMULATION

10.1 Introduction 210 10.2 Punching System for PACTOLUS 212 10.3 Application of PACTOLUS

Programme to a Problem in Process Dynamics 215

CHAPTER 11 MISCELLANEOUS TOPICS

11.1 Control Cards 220 220

Estimation of Computer Time .. 223 Debugging Computer Programme 226

227

Programming for Efficiency 11.2 11.3 11.4 11.5 Hybrid Computers

CASE STUDIES

CASE STUDY 1 Economic Order Quantity Calculatio 231 232 233 234

CASE STUDY 2 Compound Interest Table .

CASE STUDY 3 Table of Present Values

CASE STUDY 4 Present Value Assessment CASE STUDY 5 Identification of Low Sales Items 237 CASE STUDY 6 Correlation Coefficient using Pearson's

Product Moment Formula 237 239 241

Linear Regression CASE STUDY 7 CASE STUDY 8 CASE STUDY 9 Inversion of Matrix by Partitioningg

Calculation of Mean and Varance

Method 243

Page 13: A text bookon Compurter

Page CASE STUDY 10 Printed Output Pattern corresponding to

Format Speciication CASE STUDY 11 Ovcrail Reiiability of a System

SOrting oi Sales Figures Steady-state Temperature Calcuiation

CASE STUDY 14 Evaluation of Matrix Polynomial

245 246 248 250 253

CASE STUDY 12 CASE STUDY 13

CASE STUDY 15 Trend-adjusted Exponentially-smoothed Sales Forecasting

CASE STUDY 16 Design of the Length and Temperature 255

Distribution of a Chemical Reactor 258 CASE STUDY 17 Conduction Heat Transfer through an

Insulating Wall CASE STUDY 18 Optimum Thickness of Pipe Insulation CASE STUDY 19 Evaluation of Friction FactorsCASE STUDY 20 Evaluation of x-y Data for a Binary

Mixture CASE STUDY 21 Linear Programming (Simplex Method

applied to a 3 x 5 matrix) CASE STUDY 22 Lincar Interpolation (Method of

False-Position) CASE STUDY 23 Newion-Raphson Method (Method of

Tangents) CASE STUDY 24 Predictor-Corrector Method (Milne's) CASE STUDY 25 Miine's Method (Solution of a Second

261 265 268

270

272

275

278 280

Order Ordinary Differential Equation) 282 285 287 289 293 295 298 304

CASE STUDY 26 Adams-Stormer Method CASE STUDY 27 Largest Eigen Value CASE STUDY 28 Eigen Value near a Constant CASE STUDY 29 Runge-Kutta Method (Fourth Order) CASE STUDY 30 Runge-Kutta-Merson Method CASE STUDY 31 A Two-Point Boundary Value Problem

Crout's Method CASE STUDY 32

Page 14: A text bookon Compurter

XV Page

ANSWERS

Exercise1 309

Exercise 2 313

Exercise 3 314 Exercise 4 318

Exercise 55 319

Exercise 6 323 Exercise 7 325 Exercise 88 325 Exercise 9 327

APPENDIX I Elements of CSMP APPENDIX II An Overview of the Operating Systems .. 342 APPENDIX I Important Aspects of

329

System 1BM 370/155 (Hardware) 353 APPENDIX Iv Comparison of Speeds of Different

Computers 354 APPENDIX v Error Messages (FORTRAN II-D) .. 356

APPENDIX VI Summary of FORTRAN Statements 359 APPENDIX VII Summary of FORMAT Specifications 364

APPENDIX VII List of Computer Facilities in India 366

Suggestions for Further Reading

Index

370

371

Page 15: A text bookon Compurter

A TEXT BOOK ON

COMPUTER PROGRAMMING

WITH INDUSTRIAL& ENGINEERING APPLICATIONS

While compiling this book the authors have taken into considera-

tion the needs of students, research workers and programmers, in

the area of Fortran programming. Besides serving as a text-book

for students, the book will cater to the needs of industries faced

with the problem of programming in Fortran. The authors have

anticipated the doubts that are likely to arise in the minds of the

readers on exposure to Fortran programming without access to

a computer and the text has been suitably presented. Numerous

solved examples and exercises have been given towards the end of

each chapter to enable the reader to assess and reinforce his own

understanding of the concepts. The chapters have been arranged

in such a manner that an understanding of a chapter in the text

does not depend upon the material provided in a subsequent chap-

e ter. Another feature of the book is an effective treatment of

FORTRAN IV in addition to FORTRAN II. This is in keeping with the

trend that modern digital computers invariably employ FORTRAN

IV compilers. A comprehensive survey of digitalanalog simulation

techniques. A brief summary of FORTRAN STATEMENTS meant

for quick reference. Applications of Fortran Programming through

CASE STUDIES selected from various fields of Engineering, Indu-strial and Business Management. A List of Computer Centres in

India and a typical set of error messages.

Rs.

NEW BOOKS ON ELEC TRICAL & ELEC TRONICS Perp

Problems in Electrical Engineering, 9th ed. Rs Parker Smith

Basic Television (Transmission & reception) Rs Majni

CBS PUBLISHERS & DISTRIBUTORS

485, BHOLA NATH NAGAR, SHAHDARA, DELHI-110032

DISTRIBUTORS-

COLLEGE BOOK STORE

1701, NAI SARAK, DELHI-110006