Complete study guide for Introduction to Programming using Fortran 95/2003/2008 chapter 1-, Study Guides, Projects, Research of Programming Languages

Complete study guide for Introduction to Programming using Fortran 95/2003/2008 chapter 1- 27 Latest Update Table of Contents 1 Introduction...................................................................................................................................... 1 1.1 Why Learn Programming........................................................................................................... 1 1.2 Fortran........................................................................................................................................ 1 1.3 Complete Fortran 95/2003/2008 Documentation....................................................................... 1 1.4 What Is A Program..................................................................................................................... 2 1.5 Operating System....................................................................................................................... 2 2 Computer Organization...

Typology: Study Guides, Projects, Research

2023/2024

Available from 03/24/2024

star_score_grades
star_score_grades 🇺🇸

3.6

(19)

1.6K documents

1 / 235

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Complete study guide for Introduction to
Programming using
Fortran 95/2003/2008 chapter 1- 27 Latest Update
Table of Contents
1 Introduction.................................................................................................................................
..... 1
1.1 Why Learn Programming...........................................................................................................
1
1.2 Fortran.......................................................................................................................................
. 1
1.3 Complete Fortran 95/2003/2008
Documentation....................................................................... 1
1.4 What Is A Program.....................................................................................................................
2
1.5 Operating System.......................................................................................................................
2
2 Computer
Organization................................................................................................................... 3
2.1 Architecture Overview...............................................................................................................
3
2.2 Compiler.....................................................................................................................................
4
2.3 Information
Representation........................................................................................................ 4
2.3.1 Decimal Numbers...............................................................................................................
4
2.3.2 Binary Numbers..................................................................................................................
5
2.3.3 Character
Representation.................................................................................................... 5
2.4 Exercises.....................................................................................................................................
5
2.4.1 Quiz
Questions.................................................................................................................... 5
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Complete study guide for Introduction to Programming using Fortran 95/2003/2008 chapter 1- and more Study Guides, Projects, Research Programming Languages in PDF only on Docsity!

Complete study guide for Introduction to

Programming using

Fortran 95/2003/2008 chapter 1- 27 Latest Update

Table of Contents

1 Introduction................................................................................................................................. ..... 1 1.1 Why Learn Programming........................................................................................................... 1 1.2 Fortran.......................................................................................................................................

. 1 1.3 Complete Fortran 95/2003/ Documentation....................................................................... 1 1.4 What Is A Program..................................................................................................................... 2 1.5 Operating System....................................................................................................................... 2 2 Computer Organization................................................................................................................... 3 2.1 Architecture Overview............................................................................................................... 3 2.2 Compiler..................................................................................................................................... 4 2.3 Information Representation........................................................................................................ 4 2.3.1 Decimal Numbers............................................................................................................... 4 2.3.2 Binary Numbers.................................................................................................................. 5 2.3.3 Character Representation.................................................................................................... 5 2.4 Exercises..................................................................................................................................... 5 2.4.1 Quiz Questions.................................................................................................................... 5

3 Getting Started................................................................................................................................. 7 3.1 Required Skills........................................................................................................................... 7 3.2 Program Formats........................................................................................................................ 7 3.2.1 Program Statement.............................................................................................................. 7 3.2.2 Comments..........................................................................................................................

. 8 3.2.3 Simple Output..................................................................................................................... 8 3.2.4 Example – First Program.................................................................................................... 8 3.3 Text Editor.................................................................................................................................. 8 3.4 Compiling................................................................................................................................... 9 3.4.1 Advanced Compiler Options............................................................................................... 9 3.5 Executing.................................................................................................................................... 9 3.6 Exercises................................................................................................................................... 10 3.6.1 Quiz Questions.................................................................................................................. 10 3.6.2 Suggested Projects............................................................................................................ 11 4 Fortran 95/2003/2008 – Basic Elements....................................................................................... 13 4.1 Variables................................................................................................................................... 13 4.1.1 Variable Names................................................................................................................. 13 4.1.2 Keywords.......................................................................................................................... 14 4.2 Data Types................................................................................................................................ 14 4.2.1 Integer............................................................................................................................... 14 ii

5 Expressions.................................................................................................................................. ... 21 5.1 Literals...................................................................................................................................... 21 5.1.1 Integer Literals.................................................................................................................. 21 5.1.2 Real Literals...................................................................................................................... 21 5.1.2.1 E- Notation................................................................................................................. 21 5.1.3 Complex Literals.............................................................................................................. 22 5.1.4 Character Literals.............................................................................................................. 22 5.1.5 Logical Constants............................................................................................................. 23 5.2 Arithmetic Operations.............................................................................................................. 23 5.2.1 Assignment....................................................................................................................... 23 5.2.2 Addition............................................................................................................................ 23 5.2.3 Subtraction........................................................................................................................ 24 5.2.4 Multiplication................................................................................................................... 24 5.2.5 Division............................................................................................................................ 24 5.2.6 Exponentiation.................................................................................................................. 25 5.3 Order of Operations.................................................................................................................. 25 5.4 Intrinsic Functions.................................................................................................................... 26 5.4.1 Mathematical Intrinsic Functions..................................................................................... 26 5.4.2 Conversion Functions....................................................................................................... 26 iv

5.4.3 Summary........................................................................................................................... 27 5.5 Mixed Mode............................................................................................................................. 27 5.6 Examples.................................................................................................................................. 28 5.7 Exercises................................................................................................................................... 28 5.7.1 Quiz Questions.................................................................................................................. 28 5.7.2 Suggested Projects............................................................................................................ 29 6 Simple Input and Output.............................................................................................................. 31 6.1 Output – Write.......................................................................................................................... 31 6.1.1 Output – Print................................................................................................................... 32 6.2 Input – Read............................................................................................................................. 32 6.3 Example.................................................................................................................................... 33 6.4 Exercises................................................................................................................................... 34 6.4.1 Quiz Questions.................................................................................................................. 34 6.4.2 Suggested Projects............................................................................................................ 34 7 Program Development................................................................................................................... 37 7.1 Understand the Problem........................................................................................................... 37 7.2 Create the Algorithm................................................................................................................ 38 7.3 Implement the Program............................................................................................................ 38 7.4 Test/Debug the Program........................................................................................................... 39 v

8.5 SELECT CASE Statement....................................................................................................... 50 8.6 Example Two............................................................................................................................ 53 8.6.1 Understand the Problem................................................................................................... 53 8.6.2 Create the Algorithm......................................................................................................... 53 8.6.3 Implement the Program.................................................................................................... 53 8.6.4 Test/Debug the Program................................................................................................... 54 8.7 Exercises................................................................................................................................... 55 8.7.1 Quiz Questions.................................................................................................................. 55 8.7.2 Suggested Projects............................................................................................................ 56 9 Looping........................................................................................................................................ ... 59 9.1 Counter Controlled Looping.................................................................................................... 59 9.2 EXIT and CYCLE Statements.................................................................................................. 61 9.3 Counter Controlled Example.................................................................................................... 61 9.3.1 Understand the Problem................................................................................................... 62 9.3.2 Create the Algorithm......................................................................................................... 62 9.3.3 Implement the Program.................................................................................................... 62 9.3.4 Test/Debug the Program................................................................................................... 63 9.4 Conditional Controlled Looping.............................................................................................. 63 9.5 Conditionally Controlled Loop Example................................................................................. 65 9.5.1 Understand the Problem................................................................................................... 65 9.5.2 Create the Algorithm......................................................................................................... 65 vii

9.5.3 Implement the Program.................................................................................................... 66 9.5.4 Test/Debug the Program................................................................................................... 67 9.6 Exercises................................................................................................................................... 67 9.6.1 Quiz Questions.................................................................................................................. 67 9.6.2 Suggested Projects............................................................................................................ 69 10 Formatted Input/Output............................................................................................................. 71 10.1 Format.................................................................................................................................... 71 10.2 Format Specifiers................................................................................................................... 71 10.3 Integer Format Specifier......................................................................................................... 72 10.4 Real Format Specifier............................................................................................................. 73 10.5 Horizontal Positioning Specifiers........................................................................................... 73 10.6 Logical Format Specifier........................................................................................................ 74 10.7 Character Format Specifier.................................................................................................... 74 10.8 Advance Clause...................................................................................................................... 75 10.9 Example.................................................................................................................................. 76 10.9.1 Understand the Problem................................................................................................. 76 10.9.2 Create the Algorithm....................................................................................................... 76 10.9.3 Implement the Program.................................................................................................. 77 10.9.4 Test/Debug the Program................................................................................................. 79 10.10 Exercises............................................................................................................................... 79 10.10.1 Quiz Questions.............................................................................................................. 79 10.10.2 Suggested Projects........................................................................................................ 80 viii

12.4 File Read................................................................................................................................. 93 12.5 Rewind.................................................................................................................................... 93 12.6 Backspace............................................................................................................................... 93 12.7 Close File................................................................................................................................ 94 12.8 Example.................................................................................................................................. 94 12.8.1 Understand the Problem................................................................................................. 94 12.8.2 Create the Algorithm....................................................................................................... 94 12.8.3 Implement the Program.................................................................................................. 95 12.8.4 Test/Debug the Program................................................................................................. 96 12.9 Exercises................................................................................................................................. 96 12.9.1 Quiz Questions................................................................................................................ 97 12.9.2 Suggested Projects.......................................................................................................... 97 13 Single Dimension Arrays............................................................................................................. 99 13.1 Array Declaration................................................................................................................. 100 13.1.1 Static Declaration.......................................................................................................... 100 13.1.2 Static Array Declaration............................................................................................... 100 13.1.3 Dynamic Array Declaration.......................................................................................... 101 13.1.3.1 Dynamic Array Allocation.................................................................................... 101 13.2 Accessing Array Elements.................................................................................................... 102 13.2.1 Array Bounds................................................................................................................ 102 x

13.3 Implied Do-Loop.................................................................................................................. 103 13.4 Intrinsic Functions................................................................................................................ 103 13.5 Initializing Arrays................................................................................................................. 104 13.6 Example................................................................................................................................ 104 13.6.1 Understand the Problem............................................................................................... 104 13.6.2 Create the Algorithm..................................................................................................... 105 13.6.3 Implement the Program................................................................................................ 106 13.6.4 Test/Debug the Program............................................................................................... 108 13.7 Arrays of Strings................................................................................................................... 109 13.8 Exercises............................................................................................................................... 109 13.8.1 Quiz Questions.............................................................................................................. 109 13.8.2 Suggested Projects........................................................................................................ 110 14 Multidimensional Arrays........................................................................................................... 113 14.1 Array Declaration................................................................................................................. 113 14.1.1 Static Declaration.......................................................................................................... 114 14.1.2 Dynamic Declaration.................................................................................................... 114 14.1.3 Dynamic Array Allocation............................................................................................ 114 14.2 Accessing Array Elements.................................................................................................... 115 14.3 Example................................................................................................................................ 116 14.3.1 Understand the Problem................................................................................................ 116 xi

15.7 Subroutines........................................................................................................................... 127 15.8 Example................................................................................................................................ 128 15.8.1 Understand the Problem............................................................................................... 129 15.8.2 Create the Algorithm..................................................................................................... 130 15.8.3 Implement the Program................................................................................................ 131 15.8.4 Test/Debug the Program............................................................................................... 132 15.9 Exercises............................................................................................................................... 132 15.9.1 Quiz Questions.............................................................................................................. 132 15.9.2 Suggested Projects........................................................................................................ 134 16 Derived Data Types.................................................................................................................... 137 16.1 Definition.............................................................................................................................. 137 16.2 Declaration........................................................................................................................... 138 16.3 Accessing Components......................................................................................................... 138 16.4 Example One........................................................................................................................ 139 16.4.1 Understand the Problem............................................................................................... 139 16.4.2 Create the Algorithm..................................................................................................... 140 16.4.3 Implement the Program................................................................................................ 140 16.4.4 Test/Debug the Program............................................................................................... 142 16.5 Arrays of Derived Data......................................................................................................... 143 16.6 Example Two........................................................................................................................ 144 xiii

16.6.1 Understand the Problem............................................................................................... 144 16.6.2 Create the Algorithm..................................................................................................... 144 16.6.3 Implement the Program................................................................................................ 145 16.6.4 Test/Debug the Program............................................................................................... 148 16.7 Exercises............................................................................................................................... 148 16.7.1 Quiz Questions.............................................................................................................. 148 16.7.2 Suggested Projects........................................................................................................ 149 17 Modules....................................................................................................................................... 151 17.1 Module Declaration.............................................................................................................. 151 17.2 Use Statement....................................................................................................................... 152 17.3 Updated Compilation Commands........................................................................................ 152 17.4 Module Example Program.................................................................................................... 153 17.4.1 Understand the Problem............................................................................................... 153 17.4.2 Create the Algorithm..................................................................................................... 153 17.4.3 Implement the Program................................................................................................ 154 17.4.3.1 Main Program....................................................................................................... 154 17.4.3.2 Module Routines................................................................................................... 155 17.4.4 Compile the Program.................................................................................................... 156 17.4.5 Test/Debug the Program............................................................................................... 156 17.5 Exercises............................................................................................................................... 156 xiv

19.2 Numeric to Character String Conversion............................................................................. 171 19.3 Exercises............................................................................................................................... 172 19.3.1 Quiz Questions.............................................................................................................. 172 19.3.2 Suggested Projects........................................................................................................ 172 20 System Services.......................................................................................................................... 175 20.1 Date and Time...................................................................................................................... 175 20.1.1 Date and Time Options................................................................................................. 175 20.1.2 Date and Time Example Program................................................................................. 176 20.2 Command Line Arguments................................................................................................... 178 20.2.1 Argument Count............................................................................................................ 179 20.2.2 Get Arguments.............................................................................................................. 179 20.2.3 Command Line Arguments, Example Program............................................................ 180 20.3 Exercises............................................................................................................................... 182 20.3.1 Quiz Questions.............................................................................................................. 183 20.3.2 Suggested Projects........................................................................................................ 183 21 Appendix A – ASCII Table......................................................................................................... 185 22 Appendix B – Start-Up Instructions......................................................................................... 187 22.1 Working Files....................................................................................................................... 187 22.2 Obtaining The Compiler....................................................................................................... 187 xvi

22.2.1 Windows Download and Install.................................................................................... 187 22.2.2 MacOS Download and Install....................................................................................... 188 22.3 Windows Compilation.......................................................................................................... 188 22.3.1 Command Prompt Window.......................................................................................... 188 22.3.2 Device and Directory.................................................................................................... 189 22.3.3 Compiler Installation Verification................................................................................ 189 22.3.4 Compilation.................................................................................................................. 189 22.3.5 Executing...................................................................................................................... 190 22.3.6 Example........................................................................................................................ 190 22.4 MacOS Compilation............................................................................................................. 190 22.4.1 Terminal Window......................................................................................................... 191 22.4.2 Device and Directory.................................................................................................... 191 22.4.3 Compiler Installation Verification................................................................................ 192 22.4.4 Compilation.................................................................................................................. 192 22.4.5 Executing...................................................................................................................... 193 22.4.6 Example........................................................................................................................ 193 23 Appendix C – Random Number Generation........................................................................... 195 23.1 Initialization.......................................................................................................................... 195 23.2 Generating Random Number................................................................................................ 195 23.3 Example................................................................................................................................ 196 xvii

26 Appendix F – Quiz Question Answers...................................................................................... 207 26.1 Quiz Question Answers, Chapter 1...................................................................................... 207 26.2 Quiz Question Answers, Chapter 2...................................................................................... 207 26.3 Quiz Question Answers, Chapter 3...................................................................................... 207 26.4 Quiz Question Answers, Chapter 4...................................................................................... 208 26.5 Quiz Question Answers, Chapter 5...................................................................................... 208 26.6 Quiz Question Answers, Chapter 6...................................................................................... 209 26.7 Quiz Question Answers, Chapter 7...................................................................................... 209 26.8 Quiz Question Answers, Chapter 8...................................................................................... 209 26.9 Quiz Question Answers, Chapter 9...................................................................................... 210 26.10 Quiz Question Answers, Chapter 10.................................................................................. 211 26.11 Quiz Question Answers, Chapter 11................................................................................... 212 26.12 Quiz Question Answers, Chapter 12.................................................................................. 212 26.13 Quiz Question Answers, Chapter 13.................................................................................. 212 26.14 Quiz Question Answers, Chapter 14.................................................................................. 213 26.15 Quiz Question Answers, Chapter 15.................................................................................. 214 26.16 Quiz Question Answers, Chapter 16.................................................................................. 215 26.17 Quiz Question Answers, Chapter 17.................................................................................. 216 26.18 Quiz Question Answers, Chapter 18.................................................................................. 216 26.19 Quiz Question Answers, Chapter 19.................................................................................. 217 26.20 Quiz Question Answers, Chapter 20.................................................................................. 218 27 Appendix G – Fortran 95/2003/2008 Keywords...................................................................... 219 Index..................................................................................................................................................

. 223 xix

Illustration Index

Illustration 1: Computer Architecture........................................................................................................ Illustration 2: Fortran 95/2003/2008 Compile Process..............................................................................4 Illustration 3: Factorial Recursion Tree................................................................................................. xx