Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf ·...

377
Computer Languages for Engineers Some Steps Ernst Baeck Institute of Baustatik - Baukonstruktion April 7, 2014 E. Baeck (Uni-DUE) CM-CLFE / General Points 1 / 104

Transcript of Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf ·...

Page 1: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Computer Languages for EngineersSome Steps

Ernst Baeck

Institute of Baustatik - Baukonstruktion

April 7, 2014

E. Baeck (Uni-DUE) CM-CLFE / General Points 1 / 104

Page 2: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

General Points I

1 IntroductionInfrastructureGiant StepsExams

2 Some HistoryThe ComputerThe Language

3 Console StepsSome Windows Commands

4 Bits and BytesBitsBytesWords

E. Baeck (Uni-DUE) General Points 2 / 104

Page 3: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 4: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. Baeck

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 5: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 6: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 7: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck or like baeckagain.

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 8: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck or like baeckagain.But please don’t forget the e in that name!

My Office

V15-S03-D03

My eMail

[email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 9: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck or like baeckagain.But please don’t forget the e in that name!

My Office V15-S03-D03

My eMail [email protected]

My internal Phone

2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 10: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck or like baeckagain.But please don’t forget the e in that name!

My Office V15-S03-D03

My eMail [email protected]

My internal Phone 2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 11: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Addresses

Lecturer?That’s me, Mr. BaeckLike the Beatles song get baeck or like layed baeck or like baeckagain.But please don’t forget the e in that name!

My Office V15-S03-D03

My eMail [email protected]

My internal Phone 2613

E. Baeck (Uni-DUE) General Points 3 / 104

Page 12: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Calling the Info.Server

All the stuff of this lecture you’ll find on the info.serverURL: http://info.baustatik.uni-due.de

E. Baeck (Uni-DUE) General Points 4 / 104

Page 13: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Calling the Info.Server

All the stuff of this lecture you’ll find on the info.serverURL: http://info.baustatik.uni-due.de

E. Baeck (Uni-DUE) General Points 4 / 104

Page 14: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into CLFE

The root folder of CLFE

The Scripts-folder offers you some useful scripts for the software

The Software-folder offers you the software packages we will use

The remaining folders content the stuff of all previous semesters

SS14 will be created soon!

E. Baeck (Uni-DUE) General Points 5 / 104

Page 15: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into CLFE

The root folder of CLFE

The Scripts-folder offers you some useful scripts for the software

The Software-folder offers you the software packages we will use

The remaining folders content the stuff of all previous semesters

SS14 will be created soon!

E. Baeck (Uni-DUE) General Points 5 / 104

Page 16: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into CLFE

The root folder of CLFE

The Scripts-folder offers you some useful scripts for the software

The Software-folder offers you the software packages we will use

The remaining folders content the stuff of all previous semesters

SS14 will be created soon!

E. Baeck (Uni-DUE) General Points 5 / 104

Page 17: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into CLFE

The root folder of CLFE

The Scripts-folder offers you some useful scripts for the software

The Software-folder offers you the software packages we will use

The remaining folders content the stuff of all previous semesters

SS14 will be created soon!

E. Baeck (Uni-DUE) General Points 5 / 104

Page 18: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into CLFE

The root folder of CLFE

The Scripts-folder offers you some useful scripts for the software

The Software-folder offers you the software packages we will use

The remaining folders content the stuff of all previous semesters

SS14 will be created soon!

E. Baeck (Uni-DUE) General Points 5 / 104

Page 19: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into the New Semester’s Folder

The content of the semester you find in

a subfolder for FORTRAN examples

a subfolder for C++ examples,

and a subfolder for the exam project descriptions.

E. Baeck (Uni-DUE) General Points 6 / 104

Page 20: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into the New Semester’s Folder

The content of the semester you find in

a subfolder for FORTRAN examples

a subfolder for C++ examples,

and a subfolder for the exam project descriptions.

E. Baeck (Uni-DUE) General Points 6 / 104

Page 21: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into the New Semester’s Folder

The content of the semester you find in

a subfolder for FORTRAN examples

a subfolder for C++ examples,

and a subfolder for the exam project descriptions.

E. Baeck (Uni-DUE) General Points 6 / 104

Page 22: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into the New Semester’s Folder

The content of the semester you find in

a subfolder for FORTRAN examples

a subfolder for C++ examples,

and a subfolder for the exam project descriptions.

What you see...

We obviously talk about FORTRAN and C++ language and we willtry to implement some nice examples, I hope.

You also will get the software for free, we use in this lecture.

E. Baeck (Uni-DUE) General Points 6 / 104

Page 23: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Info.Server — Stepping into the New Semester’s Folder

The content of the semester you find in

a subfolder for FORTRAN examples

a subfolder for C++ examples,

and a subfolder for the exam project descriptions.

What you see...

We obviously talk about FORTRAN and C++ language and we willtry to implement some nice examples, I hope.

You also will get the software for free, we use in this lecture.

E. Baeck (Uni-DUE) General Points 6 / 104

Page 24: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — Modules and Registration

You can also access the info.server using the moodle platformURL: http://moodle2.uni-due.de//

Follow the link:Fakultat fur Ingenieurwissenschaften/Abteilung Bauwissenschaften/Bauinformatik.... or simple search for CLFE.

E. Baeck (Uni-DUE) General Points 7 / 104

Page 25: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — Modules and Registration

You can also access the info.server using the moodle platformURL: http://moodle2.uni-due.de//Follow the link:Fakultat fur Ingenieurwissenschaften/Abteilung Bauwissenschaften/Bauinformatik.

... or simple search for CLFE.

E. Baeck (Uni-DUE) General Points 7 / 104

Page 26: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — Modules and Registration

You can also access the info.server using the moodle platformURL: http://moodle2.uni-due.de//Follow the link:Fakultat fur Ingenieurwissenschaften/Abteilung Bauwissenschaften/Bauinformatik.... or simple search for CLFE.

E. Baeck (Uni-DUE) General Points 7 / 104

Page 27: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — Modules and Registration

You can also access the info.server using the moodle platformURL: http://moodle2.uni-due.de//Follow the link:Fakultat fur Ingenieurwissenschaften/Abteilung Bauwissenschaften/Bauinformatik.... or simple search for CLFE.

E. Baeck (Uni-DUE) General Points 7 / 104

Page 28: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — CLFE-Module

You will get topical information in the Forum.

Don’t forget to register.

If you want, you use the forum for postings.

E. Baeck (Uni-DUE) General Points 8 / 104

Page 29: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — CLFE-Module

You will get topical information in the Forum.

Don’t forget to register.

If you want, you use the forum for postings.

E. Baeck (Uni-DUE) General Points 8 / 104

Page 30: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Infrastructure

Moodle.Server — CLFE-Module

You will get topical information in the Forum.

Don’t forget to register.

If you want, you use the forum for postings.

E. Baeck (Uni-DUE) General Points 8 / 104

Page 31: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Languages

FORTRAN 77Very old computer language. Widespreaded language but a realoldtimer with all it’ problems.

FORTRAN 90+Modern extended and down compatible FORTRAN version.

C++A real allrounder and the main language in the LINUX world. Motherof Java, C# and a modern object orientated successor of thelanguage C, which came up with the operating system UNIX.

When will we do this?

We will start with this old FORTRAN, to understand old fashionedsources (like for example the FEAP - package code)

E. Baeck (Uni-DUE) General Points 9 / 104

Page 32: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Languages

FORTRAN 77Very old computer language. Widespreaded language but a realoldtimer with all it’ problems.

FORTRAN 90+Modern extended and down compatible FORTRAN version.

C++A real allrounder and the main language in the LINUX world. Motherof Java, C# and a modern object orientated successor of thelanguage C, which came up with the operating system UNIX.

When will we do this?

We will start in November with the FORTRAN 90/95.We will see, that’s easy to mix the old with new one.

E. Baeck (Uni-DUE) General Points 9 / 104

Page 33: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Languages

FORTRAN 77Very old computer language. Widespreaded language but a realoldtimer with all it’ problems.

FORTRAN 90+Modern extended and down compatible FORTRAN version.

C++A real allrounder and the main language in the LINUX world. Motherof Java, C# and a modern object orientated successor of thelanguage C, which came up with the operating system UNIX.

When will we do this?

We will start in January with OOP and C++... analyzing profile section values!

E. Baeck (Uni-DUE) General Points 9 / 104

Page 34: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Developer Tools

MinGW - Minimalist GNU for WindowsA compiler suite with a FORTRAN and a C++ compiler.The GNU compilers are available for wide range of platforms.Project: http://sourceforge.net/projects/mingw/files/MinGW/

CodeBlocks - IDE-ToolThe IDE originally developed for C and C++.We will use the extend Version for FORTRAN.Project: http://darmar.vgtu.lt/cbdownload

The tools will be available on the Info.Server.You should also check for newer versions on the project site.

E. Baeck (Uni-DUE) General Points 10 / 104

Page 35: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Developer Tools

MinGW - Minimalist GNU for WindowsA compiler suite with a FORTRAN and a C++ compiler.The GNU compilers are available for wide range of platforms.Project: http://sourceforge.net/projects/mingw/files/MinGW/

CodeBlocks - IDE-ToolThe IDE originally developed for C and C++.We will use the extend Version for FORTRAN.Project: http://darmar.vgtu.lt/cbdownload

The tools will be available on the Info.Server.You should also check for newer versions on the project site.

E. Baeck (Uni-DUE) General Points 10 / 104

Page 36: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Giant Steps

Developer Tools

MinGW - Minimalist GNU for WindowsA compiler suite with a FORTRAN and a C++ compiler.The GNU compilers are available for wide range of platforms.Project: http://sourceforge.net/projects/mingw/files/MinGW/

CodeBlocks - IDE-ToolThe IDE originally developed for C and C++.We will use the extend Version for FORTRAN.Project: http://darmar.vgtu.lt/cbdownload

The tools will be available on the Info.Server.You should also check for newer versions on the project site.

E. Baeck (Uni-DUE) General Points 10 / 104

Page 37: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

NO!

E. Baeck (Uni-DUE) General Points 11 / 104

Page 38: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

One project to implement a root analysis of an arbitrary function usingNewton’s root finder.

E. Baeck (Uni-DUE) General Points 11 / 104

Page 39: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

One project to implement a file controlled algorithm to multiply a series ofmatrices.

E. Baeck (Uni-DUE) General Points 11 / 104

Page 40: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

... and one project to implement the calculation of profile section valuesusing an object orientated concept in C++ on the base of the thin-walledapproach.

E. Baeck (Uni-DUE) General Points 11 / 104

Page 41: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

E. Baeck (Uni-DUE) General Points 11 / 104

Page 42: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

It’s recommended to work together in small developer groups.

E. Baeck (Uni-DUE) General Points 11 / 104

Page 43: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Kind of Examn

Written exam

Projects in FORTRAN

Projects in C++

The projects can be developed easily using the software we willdevelop in this lecture.

Working groups YES!

Copy and Paste roped parties NO!

What about this?

To avoid the CopyAndPasteEscape everyone will get an individualizedproject.

E. Baeck (Uni-DUE) General Points 11 / 104

Page 44: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folder

The project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 45: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folderThe project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 46: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folderThe project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 47: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folderThe project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 48: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folderThe project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 49: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Submission Details

Everything should be developed with the CodeBlocks IDE

The projects should be submitted by eMail to [email protected]

Everything should be packed into one zip file

The zip file should have the following nameCLFE-SS14-[Your Name]-Version[Number].zip

The zip file should content the following components

Every project should be in one folderAll sources and the executable should be copied into the project folderThe project report should be copied into the project folder too.

If not, the submission will not be accepted!

E. Baeck (Uni-DUE) General Points 12 / 104

Page 50: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Grading Details

First grading will give you a more detailed overview what to do.

With a second submission you can enhance your grading, if you want.

My personal deadline to submit is one year.

After having graded your projects, the grades will be sent to thePrufungsamt.

E. Baeck (Uni-DUE) General Points 13 / 104

Page 51: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Grading Details

First grading will give you a more detailed overview what to do.

With a second submission you can enhance your grading, if you want.

My personal deadline to submit is one year.

After having graded your projects, the grades will be sent to thePrufungsamt.

What about this?

Therefore it’s necessary to have a version number of the submission toavoid chaos.

E. Baeck (Uni-DUE) General Points 13 / 104

Page 52: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Grading Details

First grading will give you a more detailed overview what to do.

With a second submission you can enhance your grading, if you want.

My personal deadline to submit is one year.

After having graded your projects, the grades will be sent to thePrufungsamt.

What about this?

You should be read with the submission within one year, if no otherdeadline will be established by the Prufungsamt.

E. Baeck (Uni-DUE) General Points 13 / 104

Page 53: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction Exams

Grading Details

First grading will give you a more detailed overview what to do.

With a second submission you can enhance your grading, if you want.

My personal deadline to submit is one year.

After having graded your projects, the grades will be sent to thePrufungsamt.

What about this?

To be sure, that everything is going well, you should check it by your own.

E. Baeck (Uni-DUE) General Points 13 / 104

Page 54: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Zuse’s First Computer

Konrad Zuse (1910–1995) was a German civil engineer, inventor andcomputer pioneer. His greatest achievement was the world’s firstfunctional program-controlled Turing-complete computer, the Z3, whichbecame operational in May 1941.

Figure : Konrad Zuse and his computer Z3 [WP]

E. Baeck (Uni-DUE) General Points 14 / 104

Page 55: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Zuse’s First Computer

Konrad Zuse (1910–1995) was a German civil engineer, inventor andcomputer pioneer. His greatest achievement was the world’s firstfunctional program-controlled Turing-complete computer, the Z3, whichbecame operational in May 1941.

Figure : Z1 and Z3, Deutsches Museum Munchen [WP] 1

1Only the Z4 — the most sophisticated of his creations — survived World War II.E. Baeck (Uni-DUE) General Points 14 / 104

Page 56: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Today’s Supercomputer

Today’s computers in general have more than one processor. Intels I7 has4 processor cores. And even in smartphones today we have more than oneprocessor core (for example the Samsung S3 has a quadcore processor).

Figure : IBM’s Supercomputer with 250.000 processors [WP]

E. Baeck (Uni-DUE) General Points 15 / 104

Page 57: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Performance and Distribution

OP is Operations Per SecondFLOP is FLoating Point Operations Per Second

Results given by the LINPACK benchmark which typically performsL · U decomposition of a large matrix.

Figure : Performance Increase and Supercomputers Distribution [WP]

E. Baeck (Uni-DUE) General Points 16 / 104

Page 58: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Performance and Distribution

OP is Operations Per SecondFLOP is FLoating Point Operations Per SecondResults given by the LINPACK benchmark which typically performsL · U decomposition of a large matrix.

Figure : Performance Increase and Supercomputers Distribution [WP]

E. Baeck (Uni-DUE) General Points 16 / 104

Page 59: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Computer

Performance and Distribution

OP is Operations Per SecondFLOP is FLoating Point Operations Per SecondResults given by the LINPACK benchmark which typically performsL · U decomposition of a large matrix.

Figure : Performance Increase and Supercomputers Distribution [WP]

E. Baeck (Uni-DUE) General Points 16 / 104

Page 60: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

Motivation — Processor-Code

The fibunacci numbers are defined as follows.

fn = fn−1 + fn−2 for n > 2, with f0 = 1 and f1 = 1

The processor code is given below.

1 8B542408 83FA0077 06 B80000 0000 C3832 FA027706 B8010000 00C353BB 010000003 B9010000 008 D0419 83FA0376 078BD98B4 C84AEBF1 5BC3

E. Baeck (Uni-DUE) General Points 17 / 104

Page 61: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

Motivation — Assembler-Code

1 f i b :2 mov edx , [ esp +8]3 cmp edx , 04 j a @f5 mov eax , 06 r e t7 @@:8 cmp edx , 29 j a @f

10 mov eax , 111 r e t12 @@:13 push ebx14 mov ebx , 115 mov ecx , 116 @@:17 l e a eax , [ ebx+ecx ]18 cmp edx , 319 j b e @f20 mov ebx , ecx21 mov ecx , eax22 dec edx23 jmp @b24 @@:25 pop ebx26 r e t

E. Baeck (Uni-DUE) General Points 18 / 104

Page 62: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

First Language — First Compiler — First Bug

First Compiler was written by Grace Murray Hopper in 1952 for A-O.

Hopper is also regarded as the mother of the language COBOL

From her we have the first documented computer bug.

Life was simple before World War II. After that, we had systems.

So we have a lot to do! We will create bugs and will delete them!

Who is Who?

Grace Hopper started to work withthe MARK I computer. On the leftyou see her in front of a UNIVAC I.

E. Baeck (Uni-DUE) General Points 19 / 104

Page 63: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

First Language — First Compiler — First Bug

First Compiler was written by Grace Murray Hopper in 1952 for A-O.

Hopper is also regarded as the mother of the language COBOL

From her we have the first documented computer bug.

Life was simple before World War II. After that, we had systems.

So we have a lot to do! We will create bugs and will delete them!

What about that...?

COBOL (COmmon Business Oriented Language) was developed in 1960.

E. Baeck (Uni-DUE) General Points 19 / 104

Page 64: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

First Language — First Compiler — First Bug

First Compiler was written by Grace Murray Hopper in 1952 for A-O.Hopper is also regarded as the mother of the language COBOLFrom her we have the first documented computer bug.Life was simple before World War II. After that, we had systems.

So we have a lot to do! We will create bugs and will delete them!

What about that...?

Grace Hopper had some problemswith bugs in the MARK II relaycomputer. She coined the term bugfor faults. Therefore we today areusing the term debugging to finderrors in our code.She said: First actual case of bugbeing found!

E. Baeck (Uni-DUE) General Points 19 / 104

Page 65: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

First Language — First Compiler — First Bug

First Compiler was written by Grace Murray Hopper in 1952 for A-O.

Hopper is also regarded as the mother of the language COBOL

From her we have the first documented computer bug.

Life was simple before World War II. After that, we had systems.

So we have a lot to do! We will create bugs and will delete them!

E. Baeck (Uni-DUE) General Points 19 / 104

Page 66: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

First Language — First Compiler — First Bug

First Compiler was written by Grace Murray Hopper in 1952 for A-O.

Hopper is also regarded as the mother of the language COBOL

From her we have the first documented computer bug.

Life was simple before World War II. After that, we had systems.

So we have a lot to do! We will create bugs and will delete them!

What about that...?

One of the debuggers we can use inweb development is called Firebug.This debugger is developed for thefirefox browser, to check websources.

E. Baeck (Uni-DUE) General Points 19 / 104

Page 67: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about FORTRAN

The first version of FORTRAN was released in 1957.

Developed by John W. Backus at IBM for the IBM-704 system.

The first standardized version was FORTRAN 66 or FORTRAN IV.

Next milestone in 1977 with FORTRAN 77.

Next milestone in 1990 with FORTRAN 90.

What about that...

FORTRAN(short for FORmula TRANslator)enabled a computer to perform arepetitive task from a single set ofinstructions by using loops. Thefirst compiler which was able tocompile mathematical formulas intomachine code.

E. Baeck (Uni-DUE) General Points 20 / 104

Page 68: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about FORTRAN

The first version of FORTRAN was released in 1957.

Developed by John W. Backus at IBM for the IBM-704 system.

The first standardized version was FORTRAN 66 or FORTRAN IV.

Next milestone in 1977 with FORTRAN 77.

Next milestone in 1990 with FORTRAN 90.

What about that...

The IBM 704 is the firstmass-produced computer withfloating point arithmetic hardware,introduced by IBM in 1954. SoFORTRAN to use it was the nextlogical step forward.

E. Baeck (Uni-DUE) General Points 20 / 104

Page 69: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about FORTRAN

The first version of FORTRAN was released in 1957.

Developed by John W. Backus at IBM for the IBM-704 system.

The first standardized version was FORTRAN 66 or FORTRAN IV.

Next milestone in 1977 with FORTRAN 77.

Next milestone in 1990 with FORTRAN 90.

What about that...

The new ISO (International Organization for Standardization) standardwas published in 1966, and was known accordingly as FORTRAN 66, itwas the first HLL (High Level Language) standard in the world.

E. Baeck (Uni-DUE) General Points 20 / 104

Page 70: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about FORTRAN

The first version of FORTRAN was released in 1957.

Developed by John W. Backus at IBM for the IBM-704 system.

The first standardized version was FORTRAN 66 or FORTRAN IV.

Next milestone in 1977 with FORTRAN 77.

Next milestone in 1990 with FORTRAN 90.

What about that...

FORTRAN 77 comes with new features which made it possible to applythe concept of structured programming in FORTRAN too.

E. Baeck (Uni-DUE) General Points 20 / 104

Page 71: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about FORTRAN

The first version of FORTRAN was released in 1957.

Developed by John W. Backus at IBM for the IBM-704 system.

The first standardized version was FORTRAN 66 or FORTRAN IV.

Next milestone in 1977 with FORTRAN 77.

Next milestone in 1990 with FORTRAN 90.

What about that...

FORTRAN 90 comes with new features which made it possible to applythe concept of object orientated programming.

E. Baeck (Uni-DUE) General Points 20 / 104

Page 72: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about C++

Developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ extends C with object oriented features, such as classes.

Most of the UNIX/LINUX system is written in C.

The C/C++ GCC compiler is the main development tool of theLINUX system.

What about that...

Stroustrup set out to enhance theC language with Simula-likefeatures. Simula is considered thefirst object-oriented programminglanguage and takes a lot of Algol60.

E. Baeck (Uni-DUE) General Points 21 / 104

Page 73: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about C++

Developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ extends C with object oriented features, such as classes.

Most of the UNIX/LINUX system is written in C.

The C/C++ GCC compiler is the main development tool of theLINUX system.

What about that...

Ken Thompson and Dennis Ritchieare considered fathers of C. Theydeveloped C working on the UNIXOS at Bell Labs. C comes in theALGOL tradition with facilities forstructured programming.

E. Baeck (Uni-DUE) General Points 21 / 104

Page 74: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about C++

Developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ extends C with object oriented features, such as classes.

Most of the UNIX/LINUX system is written in C.

The C/C++ GCC compiler is the main development tool of theLINUX system.

E. Baeck (Uni-DUE) General Points 21 / 104

Page 75: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Some History The Language

What about C++

Developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ extends C with object oriented features, such as classes.

Most of the UNIX/LINUX system is written in C.

The C/C++ GCC compiler is the main development tool of theLINUX system.

E. Baeck (Uni-DUE) General Points 21 / 104

Page 76: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

What about the Console

You can start the console window with the command cmd.

Then you’ll see the console window with it’s prompt.

What about that...

On Windows 7 you can start theconsole window, clicking on theStart button on the main toolbar atthe screen’s bottom left.Then the command cmd should betyped into the edit and be closed bythe enter key.

E. Baeck (Uni-DUE) General Points 22 / 104

Page 77: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

What about the Console

You can start the console window with the command cmd.

Then you’ll see the console window with it’s prompt.

What about that...

On Windows 7 you’ll get a window,which is showing you the Windowsversion and the user, who asexecuted the command. By defaultthe prompt will show you yourstandard home directory.

E. Baeck (Uni-DUE) General Points 22 / 104

Page 78: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and what about it’s Commands

With the command c: you select the c-drive.

To select a specific folder you use the command cd .

To list the content of a folder you use the command dir .

To list the content of a file you use the command type.

And don’t forget: Every command has a lot of parameters!

E. Baeck (Uni-DUE) General Points 23 / 104

Page 79: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and what about it’s Commands

With the command c: you select the c-drive.

To select a specific folder you use the command cd .

To list the content of a folder you use the command dir .

To list the content of a file you use the command type.

And don’t forget: Every command has a lot of parameters!

What about that...

A relative jump can be performedwithout the leading back slash. Anabsolute jump starts with a leadingback slash. By default the currentfolder path is viewed by the prompt.

E. Baeck (Uni-DUE) General Points 23 / 104

Page 80: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and what about it’s Commands

With the command c: you select the c-drive.

To select a specific folder you use the command cd .

To list the content of a folder you use the command dir .

To list the content of a file you use the command type.

And don’t forget: Every command has a lot of parameters!

What about that...

The command shows a list ofall files in the current folder.A file’s attributs and size islisted by default.

E. Baeck (Uni-DUE) General Points 23 / 104

Page 81: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and what about it’s Commands

With the command c: you select the c-drive.

To select a specific folder you use the command cd .

To list the content of a folder you use the command dir .

To list the content of a file you use the command type.

And don’t forget: Every command has a lot of parameters!

What about that...

The dir command’s output ispiped with the > operatorinto a text file. The secondcommand shows how to showthe content of the new textfile.

E. Baeck (Uni-DUE) General Points 23 / 104

Page 82: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and what about it’s Commands

With the command c: you select the c-drive.

To select a specific folder you use the command cd .

To list the content of a folder you use the command dir .

To list the content of a file you use the command type.

And don’t forget: Every command has a lot of parameters!

What about that...

A list of all command’s parameter you get with the commandhelp [command name].

E. Baeck (Uni-DUE) General Points 23 / 104

Page 83: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and some Commands more

To delete a file or a group of files you use the command del.

To create a new folder you use the command mkdir.

What about that...

The first dir shows 2files in the folder. Thedel commandremoves the filedir.lst. This is shownby the second dir.

E. Baeck (Uni-DUE) General Points 24 / 104

Page 84: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Console Steps Some Windows Commands

... and some Commands more

To delete a file or a group of files you use the command del.

To create a new folder you use the command mkdir.

What about that...

The first dir showsthe content of thefolder. The mkdir

command creates thenew folder test. Thesecond dir shows thecreated folder.

E. Baeck (Uni-DUE) General Points 24 / 104

Page 85: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit

The Bit is the elementary unit of the informatics.

John W. Tukey is supposed to coin in 1946 the word bit.

In 1948 Claude Shannons published the paper A Mathematical Theoryof Communication. In this paper the word bit was used the first time.

George Boole used the bit as a truth value. We know him from hisboolean algebra, which he developed in 1854.

E. Baeck (Uni-DUE) General Points 25 / 104

Page 86: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit

The Bit is the elementary unit of the informatics.

John W. Tukey is supposed to coin in 1946 the word bit.

In 1948 Claude Shannons published the paper A Mathematical Theoryof Communication. In this paper the word bit was used the first time.

George Boole used the bit as a truth value. We know him from hisboolean algebra, which he developed in 1854.

E. Baeck (Uni-DUE) General Points 25 / 104

Page 87: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit

The Bit is the elementary unit of the informatics.

John W. Tukey is supposed to coin in 1946 the word bit.

In 1948 Claude Shannons published the paper A Mathematical Theoryof Communication. In this paper the word bit was used the first time.

George Boole used the bit as a truth value. We know him from hisboolean algebra, which he developed in 1854.

E. Baeck (Uni-DUE) General Points 25 / 104

Page 88: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit

The Bit is the elementary unit of the informatics.

John W. Tukey is supposed to coin in 1946 the word bit.

In 1948 Claude Shannons published the paper A Mathematical Theoryof Communication. In this paper the word bit was used the first time.

George Boole used the bit as a truth value. We know him from hisboolean algebra, which he developed in 1854.

E. Baeck (Uni-DUE) General Points 25 / 104

Page 89: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit and it’s Prafixes

SI Prefixes

Name Symbol Value

Kilobit kbit 103

Megabit Mbit 106

Gigabit Gbit 109

Terabit Tbit 1012

Binary Prefix according to IEC

Name Symbol Wert

Kibibit Kibit 210

Mebibit Mibit 220

Gibibit Gibit 230

Tebibit Tibit 240

E. Baeck (Uni-DUE) General Points 26 / 104

Page 90: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit and it’s Prafixes

SI Prefixes

Name Symbol Value

Kilobit kbit 103

Megabit Mbit 106

Gigabit Gbit 109

Terabit Tbit 1012

Binary Prefix according to IEC

Name Symbol Wert

Kibibit Kibit 210

Mebibit Mibit 220

Gibibit Gibit 230

Tebibit Tibit 240

E. Baeck (Uni-DUE) General Points 26 / 104

Page 91: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit and it’s Prafixes

SI Prefixes

Name Symbol Value

Kilobit kbit 103

Megabit Mbit 106

Gigabit Gbit 109

Terabit Tbit 1012

Binary Prefix according to IEC

Name Symbol Wert

Kibibit Kibit 210

Mebibit Mibit 220

Gibibit Gibit 230

Tebibit Tibit 240

E. Baeck (Uni-DUE) General Points 26 / 104

Page 92: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit and it’s Prafixes

SI Prefixes

Name Symbol Value

Kilobit kbit 103

Megabit Mbit 106

Gigabit Gbit 109

Terabit Tbit 1012

Binary Prefix according to IEC

Name Symbol Wert

Kibibit Kibit 210

Mebibit Mibit 220

Gibibit Gibit 230

Tebibit Tibit 240

E. Baeck (Uni-DUE) General Points 26 / 104

Page 93: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

The Bit and it’s Prafixes

SI Prefixes

Name Symbol Value

Kilobit kbit 103

Megabit Mbit 106

Gigabit Gbit 109

Terabit Tbit 1012

Binary Prefix according to IEC

Name Symbol Wert

Kibibit Kibit 210

Mebibit Mibit 220

Gibibit Gibit 230

Tebibit Tibit 240

E. Baeck (Uni-DUE) General Points 26 / 104

Page 94: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

Strange Values of Volumn Size

How can I understand the value given in GB of the volumen size?

We have to apply the IEEE prefix for GB! That means divide it by 230.

Oh! It’s hard to implement an open loop!

E. Baeck (Uni-DUE) General Points 27 / 104

Page 95: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bits

Strange Values of Volumn Size

How can I understand the value given in GB of the volumen size?

We have to apply the IEEE prefix for GB! That means divide it by 230.

Oh! It’s hard to implement an open loop!

The left value is given in Bytes.The right value is given in GiBytes.

735462813696

230= 684

E. Baeck (Uni-DUE) General Points 27 / 104

Page 96: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bytes

The Byte

Bits are subsumed under Bytes.

Originally the number of bits in a byte are given to code onecharacter of a text.

The Telex (TELeprinter EXchange) usesd 5 bits within one byte.

Since the IBM-PC was released 8 bits are used for one byte.

E. Baeck (Uni-DUE) General Points 28 / 104

Page 97: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bytes

The Byte

Bits are subsumed under Bytes.

Originally the number of bits in a byte are given to code onecharacter of a text.

The Telex (TELeprinter EXchange) usesd 5 bits within one byte.

Since the IBM-PC was released 8 bits are used for one byte.

E. Baeck (Uni-DUE) General Points 28 / 104

Page 98: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bytes

The Byte

Bits are subsumed under Bytes.

Originally the number of bits in a byte are given to code onecharacter of a text.

The Telex (TELeprinter EXchange) usesd 5 bits within one byte.

Since the IBM-PC was released 8 bits are used for one byte.

This is not an organ...

Telex, the internet of ourgrandfathers.

E. Baeck (Uni-DUE) General Points 28 / 104

Page 99: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Bytes

The Byte

Bits are subsumed under Bytes.

Originally the number of bits in a byte are given to code onecharacter of a text.

The Telex (TELeprinter EXchange) usesd 5 bits within one byte.

Since the IBM-PC was released 8 bits are used for one byte.

Abraham of the computer century...

5150 or PC was released in1985. The PC was based on theIntel processor 8086. A typicalcomputer office at the middle ofthe 1980s.

E. Baeck (Uni-DUE) General Points 28 / 104

Page 100: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Words

The Word

A word subsume one or more bytes. A word is used for a logical unitin programming.

A word is used to store data within a program. It’s the elementaryunit of a computer program.

Integer numbers are stored within 1, 2, 4 or 8 byte words.

A floating point number is stored within an 4 or 8 byte word.

E. Baeck (Uni-DUE) General Points 29 / 104

Page 101: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Words

The Word

A word subsume one or more bytes. A word is used for a logical unitin programming.

A word is used to store data within a program. It’s the elementaryunit of a computer program.

Integer numbers are stored within 1, 2, 4 or 8 byte words.

A floating point number is stored within an 4 or 8 byte word.

And...

The indivisible atom also isdividable into some smallerparticles, the electrons, the protonsand the neutrons.

E. Baeck (Uni-DUE) General Points 29 / 104

Page 102: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Words

The Word

A word subsume one or more bytes. A word is used for a logical unitin programming.

A word is used to store data within a program. It’s the elementaryunit of a computer program.

Integer numbers are stored within 1, 2, 4 or 8 byte words.

A floating point number is stored within an 4 or 8 byte word.

But...

The availability is often depending on the platform. On a 32-bit platformthere are no 8 byte integers supported by the hardware. 1 byte are 2hex-digits, 2 bytes are 4 and 4 bytes are 8 hex-digits. 1 byte are 3octal-digits, 3 + 3 + 2 ⇒. So we would loose 1 bit.

E. Baeck (Uni-DUE) General Points 29 / 104

Page 103: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Bits and Bytes Words

The Word

A word subsume one or more bytes. A word is used for a logical unitin programming.

A word is used to store data within a program. It’s the elementaryunit of a computer program.

Integer numbers are stored within 1, 2, 4 or 8 byte words.

A floating point number is stored within an 4 or 8 byte word.

Using floats everything is different according to IEEE...

sign bit (bit 31)

exponent (bit-23 to bit-30)

mantissa (bit-0 to bit-22)

E. Baeck (Uni-DUE) General Points 29 / 104

Page 104: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction into FORTRAN I

5 The GFORTRAN Compiler

6 Famous HelloGet Started with FORTRAN 77Get Started with FORTRAN 90

7 FormatsPunch Card FormatModern Free Style Format

8 Data TypesBasic Data TypesFORTRAN 77 Data TypesFORTRAN 90 Data Types

9 OperatorsArithmetic OperatorsBoolean Operators

10 Explicit LoopsE. Baeck (Uni-DUE) Introduction into FORTRAN 30 / 104

Page 105: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction into FORTRAN II

Archaic LoopFactorial and 66-LoopThe 77 LoopThe 90 Loop

11 BranchingThe 66 BranchingThe 90 Branching

12 Implicit LoopsArchaic Open Loop90’s Simple Open LoopThe Float Precision

13 Subroutines and Functions77 Subroutines and Functions90 Subroutines and Functions

14 ArraysE. Baeck (Uni-DUE) Introduction into FORTRAN 31 / 104

Page 106: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction into FORTRAN III

FORTRAN 77 ArraysFORTRAN 90 ArraysScalar ProductAllocatable ArraysAutomatic Arrays

15 FilesFile CommandsOpen CommandsError HandlingWrite to a FileFormat SpecifierFormat LoopsRead from a FileClose Commands

16 EvaluationsE. Baeck (Uni-DUE) Introduction into FORTRAN 32 / 104

Page 107: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Introduction into FORTRAN IV

77’s Deficiency

E. Baeck (Uni-DUE) Introduction into FORTRAN 33 / 104

Page 108: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

The GFORTRAN Compiler

E. Baeck (Uni-DUE) Introduction into FORTRAN 34 / 104

Page 109: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

Using the GFORTRAN

Within the first try we will start the gfortran from the console window.

The first parameter should give the source file(s), with the option -o

[Name] we will specify the name of the executable.

but...

A little batch-file, to make it easier to handle. The first line adds thecompiler’s path, the second line adds the editors path. Don’t use quotesfor a path that contains space characters.

path = %path%;c:\program files (x86)\MinGW\bin;

path = %path%;c:\program files (x86)\PsPad Editor;

E. Baeck (Uni-DUE) Introduction into FORTRAN 35 / 104

Page 110: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

Using the GFORTRAN

Within the first try we will start the gfortran from the console window.

The first parameter should give the source file(s), with the option -o

[Name] we will specify the name of the executable.

The compiler is not very verbose. We get only some comments, ifthere are some errors in the code.

Column based 77-like formatting is supposed by standard using thesource file extension for.

Free style formating, i.e. 90-like formatting, is supposed by standardusing the source file extension f90.

and then...

If the path is established we simply run the compiler for our little hello.forfile, which will tell as a hello in FORTRAN77 style.

gfortran hello.for -o hello.exe

E. Baeck (Uni-DUE) Introduction into FORTRAN 35 / 104

Page 111: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

Using the GFORTRAN

Within the first try we will start the gfortran from the console window.

The first parameter should give the source file(s), with the option -o

[Name] we will specify the name of the executable.

The compiler is not very verbose. We get only some comments, ifthere are some errors in the code.

Column based 77-like formatting is supposed by standard using thesource file extension for.

Free style formating, i.e. 90-like formatting, is supposed by standardusing the source file extension f90.

E. Baeck (Uni-DUE) Introduction into FORTRAN 35 / 104

Page 112: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

Using the GFORTRAN

Within the first try we will start the gfortran from the console window.

The first parameter should give the source file(s), with the option -o

[Name] we will specify the name of the executable.

The compiler is not very verbose. We get only some comments, ifthere are some errors in the code.

Column based 77-like formatting is supposed by standard using thesource file extension for.

Free style formating, i.e. 90-like formatting, is supposed by standardusing the source file extension f90.

E. Baeck (Uni-DUE) Introduction into FORTRAN 35 / 104

Page 113: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

The GFORTRAN Compiler

Using the GFORTRAN

Within the first try we will start the gfortran from the console window.

The first parameter should give the source file(s), with the option -o

[Name] we will specify the name of the executable.

The compiler is not very verbose. We get only some comments, ifthere are some errors in the code.

Column based 77-like formatting is supposed by standard using thesource file extension for.

Free style formating, i.e. 90-like formatting, is supposed by standardusing the source file extension f90.

E. Baeck (Uni-DUE) Introduction into FORTRAN 35 / 104

Page 114: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello

Famous Hello

E. Baeck (Uni-DUE) Introduction into FORTRAN 36 / 104

Page 115: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 116: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 117: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 118: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 119: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

How to print the famous Hello...

c23457

write(*,*)"Hello World!"

end

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 120: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 77

How to get started with FORTRAN77

A FORTRAN77 code is a list of statements and comments.

The column based format has to be used.

No specific start statement is needed.

A FORTRAN77 source is closed with the end statement.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

Which parts we have?

specification part

execution part

end to close the program

E. Baeck (Uni-DUE) Introduction into FORTRAN 37 / 104

Page 121: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 122: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 123: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 124: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 125: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

How to print the famous Hello...

! this is fortran 90!

! free style

program hello90

write(*,*) "Hello World!"

end program hello90

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 126: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

Which parts we have?

program [name] ⇒ to open the program

specification part

execution part

part for internal sub programs

end program [name] to close the program

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 127: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Famous Hello Get Started with FORTRAN 90

How to get started with FORTRAN90

A FORTRAN90 code is a list of statements and comments.

The source in general is coded in free style format.

A program is started with program and a name.

A program is closed with end program and it’s name.

This is shown by the famous Hello World application.

Within a program first we specify then we execute.

77 code can be mixed with a 90 code.

E. Baeck (Uni-DUE) Introduction into FORTRAN 38 / 104

Page 128: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats

Formats

E. Baeck (Uni-DUE) Introduction into FORTRAN 39 / 104

Page 129: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN old Style Formatting

FORTRANs format was developed in 1954. It is column based and itcame the the development of the punch card. One card is exactly oneline of code.

Today we see the influence of our history in the standard with of theconsole window which is also 80.

it has started with the punch card...

Column 1-5 is the label range.Column 6 is used for acontinuation character. Column7-72 is used for the programstatements and column 73-80are used for card comments likea card number.

E. Baeck (Uni-DUE) Introduction into FORTRAN 40 / 104

Page 130: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN old Style Formatting

FORTRANs format was developed in 1954. It is column based and itcame the the development of the punch card. One card is exactly oneline of code.

Today we see the influence of our history in the standard with of theconsole window which is also 80.

How to punch a card?

The typical puncher waspresented by IBM. The frontendlooks like a type writer.

E. Baeck (Uni-DUE) Introduction into FORTRAN 40 / 104

Page 131: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN old Style Formatting

Therefore we have to be very careful with the usage of the columns.If a statement runs out of the coding section, the statement will betruncated by the borderline.

If you are storing your source code on punch cards, you will need a lotof storage space.

Let’s have a look into a hello77.for!

c234567

write(*,*) "Hello CLFE!"

end

E. Baeck (Uni-DUE) Introduction into FORTRAN 40 / 104

Page 132: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN old Style Formatting

Therefore we have to be very careful with the usage of the columns.If a statement runs out of the coding section, the statement will betruncated by the borderline.

If you are storing your source code on punch cards, you will need a lotof storage space.

How to store the punch cards? Isn’t it a giant cloud?

If you want to store your sources froma CD on punch cards you would need agiant warehouse.

E. Baeck (Uni-DUE) Introduction into FORTRAN 40 / 104

Page 133: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Problems with FORTRAN77 Formatting

Truncation of code, which runs out of its range is very dangerous.

Because we only have very little space, we can not indent code blocks.

E. Baeck (Uni-DUE) Introduction into FORTRAN 41 / 104

Page 134: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Problems with FORTRAN77 Formatting

Truncation of code, which runs out of its range is very dangerous.

Because we only have very little space, we can not indent code blocks.

E. Baeck (Uni-DUE) Introduction into FORTRAN 41 / 104

Page 135: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Characters and Restrictions

A comment line starts with a C in the first column.

If you want to continue a line, you put a character which is not aspace character into the 6th column of the following line.

FORTRAN comes with only capital letters. Therefore today’sFORTRAN sources sometimes are written in only capital letters too.

The length of a name was restricted to only 6 characters.Today you can use more than 6 characters.

E. Baeck (Uni-DUE) Introduction into FORTRAN 42 / 104

Page 136: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Characters and Restrictions

A comment line starts with a C in the first column.

If you want to continue a line, you put a character which is not aspace character into the 6th column of the following line.

FORTRAN comes with only capital letters. Therefore today’sFORTRAN sources sometimes are written in only capital letters too.

The length of a name was restricted to only 6 characters.Today you can use more than 6 characters.

E. Baeck (Uni-DUE) Introduction into FORTRAN 42 / 104

Page 137: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Characters and Restrictions

A comment line starts with a C in the first column.

If you want to continue a line, you put a character which is not aspace character into the 6th column of the following line.

FORTRAN comes with only capital letters. Therefore today’sFORTRAN sources sometimes are written in only capital letters too.

The length of a name was restricted to only 6 characters.Today you can use more than 6 characters.

E. Baeck (Uni-DUE) Introduction into FORTRAN 42 / 104

Page 138: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

Characters and Restrictions

A comment line starts with a C in the first column.

If you want to continue a line, you put a character which is not aspace character into the 6th column of the following line.

FORTRAN comes with only capital letters. Therefore today’sFORTRAN sources sometimes are written in only capital letters too.

The length of a name was restricted to only 6 characters.Today you can use more than 6 characters.

E. Baeck (Uni-DUE) Introduction into FORTRAN 42 / 104

Page 139: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

The fixed Column Format

One of the most frequent errors of beginners are column errors!

The best is, to visualize the regions within the editor.

Labels are given by numbers from 1 to 99999, no strings

Columns Remarks

01 - 05 Columns for label numbers (1 to 99999). Column 1 is alsoused to set comment lines.

06 Column 6 marks a continuation line for the previous line. Themark character can be every character of the FORTRAN char-acter set but not zero or a blank. By default there are up to19 continuation lines available.

07 - 72 Columns for statements.73 - 80 Comment Columns. And are used in the days of the punch

cards as card number field.

E. Baeck (Uni-DUE) Introduction into FORTRAN 43 / 104

Page 140: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

The fixed Column Format

One of the most frequent errors of beginners are column errors!

The best is, to visualize the regions within the editor.

Labels are given by numbers from 1 to 99999, no strings

Columns Remarks

01 - 05 Columns for label numbers (1 to 99999). Column 1 is alsoused to set comment lines.

06 Column 6 marks a continuation line for the previous line. Themark character can be every character of the FORTRAN char-acter set but not zero or a blank. By default there are up to19 continuation lines available.

07 - 72 Columns for statements.73 - 80 Comment Columns. And are used in the days of the punch

cards as card number field.

E. Baeck (Uni-DUE) Introduction into FORTRAN 43 / 104

Page 141: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

The fixed Column Format

One of the most frequent errors of beginners are column errors!

The best is, to visualize the regions within the editor.

Labels are given by numbers from 1 to 99999, no strings

Columns Remarks

01 - 05 Columns for label numbers (1 to 99999). Column 1 is alsoused to set comment lines.

06 Column 6 marks a continuation line for the previous line. Themark character can be every character of the FORTRAN char-acter set but not zero or a blank. By default there are up to19 continuation lines available.

07 - 72 Columns for statements.73 - 80 Comment Columns. And are used in the days of the punch

cards as card number field.

E. Baeck (Uni-DUE) Introduction into FORTRAN 43 / 104

Page 142: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN 77 Character Set

The character set of FORTRAN 77 is the following.2

upper case letter A - Z

10 digits 0 - 9

the 12 special characters: + - * / = ( ) : , . ’ $ and the spacecharacter.

FORTRAN is not case sensitive!

2Modern FORTRAN 77 compiler support also lower case letters.E. Baeck (Uni-DUE) Introduction into FORTRAN 44 / 104

Page 143: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN 77 Character Set

The character set of FORTRAN 77 is the following.2

upper case letter A - Z

10 digits 0 - 9

the 12 special characters: + - * / = ( ) : , . ’ $ and the spacecharacter.

FORTRAN is not case sensitive!

2Modern FORTRAN 77 compiler support also lower case letters.E. Baeck (Uni-DUE) Introduction into FORTRAN 44 / 104

Page 144: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN 77 Character Set

The character set of FORTRAN 77 is the following.2

upper case letter A - Z

10 digits 0 - 9

the 12 special characters: + - * / = ( ) : , . ’ $ and the spacecharacter.

FORTRAN is not case sensitive!

2Modern FORTRAN 77 compiler support also lower case letters.E. Baeck (Uni-DUE) Introduction into FORTRAN 44 / 104

Page 145: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Punch Card Format

FORTRAN 77 Character Set

The character set of FORTRAN 77 is the following.2

upper case letter A - Z

10 digits 0 - 9

the 12 special characters: + - * / = ( ) : , . ’ $ and the spacecharacter.

FORTRAN is not case sensitive!

2Modern FORTRAN 77 compiler support also lower case letters.E. Baeck (Uni-DUE) Introduction into FORTRAN 44 / 104

Page 146: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

Modern FORTRAN Formatting

Modern FORTRAN formatting is free of column restrictions.Formatting is like in every modern language.

A comment is started by a ! character. The code at the right side ofthe ! will be totally ignored by the compiler.

The problem with the continuation line is solved by appending a &character to the end of a code line.

E. Baeck (Uni-DUE) Introduction into FORTRAN 45 / 104

Page 147: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

Modern FORTRAN Formatting

Modern FORTRAN formatting is free of column restrictions.Formatting is like in every modern language.

A comment is started by a ! character. The code at the right side ofthe ! will be totally ignored by the compiler.

The problem with the continuation line is solved by appending a &character to the end of a code line.

E. Baeck (Uni-DUE) Introduction into FORTRAN 45 / 104

Page 148: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

Modern FORTRAN Formatting

Modern FORTRAN formatting is free of column restrictions.Formatting is like in every modern language.

A comment is started by a ! character. The code at the right side ofthe ! will be totally ignored by the compiler.

The problem with the continuation line is solved by appending a &character to the end of a code line.

Let’s have a look into a hello90.f90!

! Comments with "!" instead of c

write(*,*) "Hello 90-World ", & ! 1st line

"and CLFE-Fans" ! 2nd line

end

E. Baeck (Uni-DUE) Introduction into FORTRAN 45 / 104

Page 149: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

FORTRAN 90 Character Set

The character set of FORTRAN 90/95 is the following.3

upper case letter A - Z

lower case letter a -z

10 digits 0 - 9

Miscellaneous common symbols, such as+ - * / = ( ) : , . ’ $ ” { } [ ] !

and any special letter of symbol required by the language,such as a, o, u.

3The ASCII coding system which is used in computing stores one character in onebyte. So ASCII is able to code maximal 256 characters. To support languages with morethen 256 characters the Unicode coding, a multibyte coding, was developed, which isalso supported by the actual FORTRAN 90/95.

E. Baeck (Uni-DUE) Introduction into FORTRAN 46 / 104

Page 150: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

FORTRAN 90 Character Set

The character set of FORTRAN 90/95 is the following.3

upper case letter A - Z

lower case letter a -z

10 digits 0 - 9

Miscellaneous common symbols, such as+ - * / = ( ) : , . ’ $ ” { } [ ] !

and any special letter of symbol required by the language,such as a, o, u.

3The ASCII coding system which is used in computing stores one character in onebyte. So ASCII is able to code maximal 256 characters. To support languages with morethen 256 characters the Unicode coding, a multibyte coding, was developed, which isalso supported by the actual FORTRAN 90/95.

E. Baeck (Uni-DUE) Introduction into FORTRAN 46 / 104

Page 151: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

FORTRAN 90 Character Set

The character set of FORTRAN 90/95 is the following.3

upper case letter A - Z

lower case letter a -z

10 digits 0 - 9

Miscellaneous common symbols, such as+ - * / = ( ) : , . ’ $ ” { } [ ] !

and any special letter of symbol required by the language,such as a, o, u.

3The ASCII coding system which is used in computing stores one character in onebyte. So ASCII is able to code maximal 256 characters. To support languages with morethen 256 characters the Unicode coding, a multibyte coding, was developed, which isalso supported by the actual FORTRAN 90/95.

E. Baeck (Uni-DUE) Introduction into FORTRAN 46 / 104

Page 152: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

FORTRAN 90 Character Set

The character set of FORTRAN 90/95 is the following.3

upper case letter A - Z

lower case letter a -z

10 digits 0 - 9

Miscellaneous common symbols, such as+ - * / = ( ) : , . ’ $ ” { } [ ] !

and any special letter of symbol required by the language,such as a, o, u.

3The ASCII coding system which is used in computing stores one character in onebyte. So ASCII is able to code maximal 256 characters. To support languages with morethen 256 characters the Unicode coding, a multibyte coding, was developed, which isalso supported by the actual FORTRAN 90/95.

E. Baeck (Uni-DUE) Introduction into FORTRAN 46 / 104

Page 153: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Formats Modern Free Style Format

FORTRAN 90 Character Set

The character set of FORTRAN 90/95 is the following.3

upper case letter A - Z

lower case letter a -z

10 digits 0 - 9

Miscellaneous common symbols, such as+ - * / = ( ) : , . ’ $ ” { } [ ] !

and any special letter of symbol required by the language,such as a, o, u.

3The ASCII coding system which is used in computing stores one character in onebyte. So ASCII is able to code maximal 256 characters. To support languages with morethen 256 characters the Unicode coding, a multibyte coding, was developed, which isalso supported by the actual FORTRAN 90/95.

E. Baeck (Uni-DUE) Introduction into FORTRAN 46 / 104

Page 154: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types

Data Types

E. Baeck (Uni-DUE) Introduction into FORTRAN 47 / 104

Page 155: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

General Aspects

Integer data types are platform depended.

Floats are called REAL in FORTRAN.

A string data type is not available.We have to use arrays of characters.

Type Size RestrictionINTEGER 2 Bytes Range −215 · · · 215 − 1 = 32767INTEGER 4 Bytes Range −231 · · · 231 − 1 = 2147483647 ≈ 2.14 · 109

INTEGER 8 Bytes4 Range −263 · · · 263 − 1 = 9, 22 · 1018

REAL 4 Bytes Exponent range −38 · · · 38, 7 digits precisionREAL 8 Bytes Exponent range −308 · · · 308, 15 digits precisionCHARACTER 1 Byte one byte character

4The maximum INTEGER often is given by the width of the Operating System.So in this case we need a 64 bit OS

E. Baeck (Uni-DUE) Introduction into FORTRAN 48 / 104

Page 156: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

General Aspects

Integer data types are platform depended.

Floats are called REAL in FORTRAN.

A string data type is not available.We have to use arrays of characters.

Type Size RestrictionINTEGER 2 Bytes Range −215 · · · 215 − 1 = 32767INTEGER 4 Bytes Range −231 · · · 231 − 1 = 2147483647 ≈ 2.14 · 109

INTEGER 8 Bytes4 Range −263 · · · 263 − 1 = 9, 22 · 1018

REAL 4 Bytes Exponent range −38 · · · 38, 7 digits precisionREAL 8 Bytes Exponent range −308 · · · 308, 15 digits precisionCHARACTER 1 Byte one byte character

4The maximum INTEGER often is given by the width of the Operating System.So in this case we need a 64 bit OS

E. Baeck (Uni-DUE) Introduction into FORTRAN 48 / 104

Page 157: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

General Aspects

Integer data types are platform depended.

Floats are called REAL in FORTRAN.

A string data type is not available.We have to use arrays of characters.

Type Size RestrictionINTEGER 2 Bytes Range −215 · · · 215 − 1 = 32767INTEGER 4 Bytes Range −231 · · · 231 − 1 = 2147483647 ≈ 2.14 · 109

INTEGER 8 Bytes4 Range −263 · · · 263 − 1 = 9, 22 · 1018

REAL 4 Bytes Exponent range −38 · · · 38, 7 digits precisionREAL 8 Bytes Exponent range −308 · · · 308, 15 digits precisionCHARACTER 1 Byte one byte character

4The maximum INTEGER often is given by the width of the Operating System.So in this case we need a 64 bit OS

E. Baeck (Uni-DUE) Introduction into FORTRAN 48 / 104

Page 158: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

Negative Numbers

Negative numbers can be represented by the b-complements.

The sum of a digit and it’s complement is the digit’s maximum value.

This would be 1 within the binary system.

We have to add 1 to the complement to get the b-complement.

E. Baeck (Uni-DUE) Introduction into FORTRAN 49 / 104

Page 159: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

Negative Numbers

Negative numbers can be represented by the b-complements.

The sum of a digit and it’s complement is the digit’s maximum value.

This would be 1 within the binary system.

We have to add 1 to the complement to get the b-complement.

E. Baeck (Uni-DUE) Introduction into FORTRAN 49 / 104

Page 160: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

Negative Numbers

Negative numbers can be represented by the b-complements.

The sum of a digit and it’s complement is the digit’s maximum value.

This would be 1 within the binary system.

We have to add 1 to the complement to get the b-complement.

E. Baeck (Uni-DUE) Introduction into FORTRAN 49 / 104

Page 161: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types Basic Data Types

Negative Numbers

Negative numbers can be represented by the b-complements.

The sum of a digit and it’s complement is the digit’s maximum value.

This would be 1 within the binary system.

We have to add 1 to the complement to get the b-complement.

Comments0000|01112 0716, the positive number has the value 71111|10002 FA16, number complement of 7, 1 -digit

+ 12 b-complement = complement +11111|10012 b-complement or negative number

Check of the b-complement to be the searched negative number0000|01112 positive number

+ 1111|10012 b-complement or negative number1|0000|00002 The overflowing bit will be truncated, so it’s ok.

E. Baeck (Uni-DUE) Introduction into FORTRAN 49 / 104

Page 162: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

FORTRAN 77 Standard Data Types

FORTRAN 77s standard data types are a little bit sparse.

The sizer option often is able to extend data types.

The sizer option specifies the number of bytes to use.

So we get INTEGER*1, INTEGER*2, INTEGER*4.

DOUBLE PRECISION is also available as REAL*8.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, single precision3.1415, -5.5, .7E3, 12.5E-5

DOUBLE PRECISION Floatingpoint num-ber, double precision

3.1415D0, -5.5D0, .7D3,12.5D-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 50 / 104

Page 163: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

FORTRAN 77 Standard Data Types

FORTRAN 77s standard data types are a little bit sparse.

The sizer option often is able to extend data types.

The sizer option specifies the number of bytes to use.

So we get INTEGER*1, INTEGER*2, INTEGER*4.

DOUBLE PRECISION is also available as REAL*8.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, single precision3.1415, -5.5, .7E3, 12.5E-5

DOUBLE PRECISION Floatingpoint num-ber, double precision

3.1415D0, -5.5D0, .7D3,12.5D-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 50 / 104

Page 164: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

FORTRAN 77 Standard Data Types

FORTRAN 77s standard data types are a little bit sparse.

The sizer option often is able to extend data types.

The sizer option specifies the number of bytes to use.

So we get INTEGER*1, INTEGER*2, INTEGER*4.

DOUBLE PRECISION is also available as REAL*8.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, single precision3.1415, -5.5, .7E3, 12.5E-5

DOUBLE PRECISION Floatingpoint num-ber, double precision

3.1415D0, -5.5D0, .7D3,12.5D-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 50 / 104

Page 165: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

FORTRAN 77 Standard Data Types

FORTRAN 77s standard data types are a little bit sparse.

The sizer option often is able to extend data types.

The sizer option specifies the number of bytes to use.

So we get INTEGER*1, INTEGER*2, INTEGER*4.

DOUBLE PRECISION is also available as REAL*8.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, single precision3.1415, -5.5, .7E3, 12.5E-5

DOUBLE PRECISION Floatingpoint num-ber, double precision

3.1415D0, -5.5D0, .7D3,12.5D-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 50 / 104

Page 166: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

FORTRAN 77 Standard Data Types

FORTRAN 77s standard data types are a little bit sparse.

The sizer option often is able to extend data types.

The sizer option specifies the number of bytes to use.

So we get INTEGER*1, INTEGER*2, INTEGER*4.

DOUBLE PRECISION is also available as REAL*8.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, single precision3.1415, -5.5, .7E3, 12.5E-5

DOUBLE PRECISION Floatingpoint num-ber, double precision

3.1415D0, -5.5D0, .7D3,12.5D-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 50 / 104

Page 167: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

How to Declare Variables in FORTRAN 77

A variable is declared implicit by an assignment.

A variable is declared explicit by it’s data typetype [variable name]

How to declare implicit?

c234567

i = 1

r = 2

i to n integer, else real⇐ integer because it starts with i

⇐ real*4 because it starts with r

E. Baeck (Uni-DUE) Introduction into FORTRAN 51 / 104

Page 168: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 77 Data Types

How to Declare Variables in FORTRAN 77

A variable is declared implicit by an assignment.

A variable is declared explicit by it’s data typetype [variable name]

How to declare explicit?

c234567

integer i

real r

i = 1

r = 2

⇐ declaring the integer⇐ declaring the real

E. Baeck (Uni-DUE) Introduction into FORTRAN 51 / 104

Page 169: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

FORTRAN 90 Standard Data Types

FORTRAN 90 data types are like the 77 types.

The sizer option also is available in 90.

real types are platform dependent.

With the kind option the real can be specified.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, variable preci-sion

3.1415, -5.5, .7E3, 12.5E-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 52 / 104

Page 170: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

FORTRAN 90 Standard Data Types

FORTRAN 90 data types are like the 77 types.

The sizer option also is available in 90.

real types are platform dependent.

With the kind option the real can be specified.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, variable preci-sion

3.1415, -5.5, .7E3, 12.5E-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 52 / 104

Page 171: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

FORTRAN 90 Standard Data Types

FORTRAN 90 data types are like the 77 types.

The sizer option also is available in 90.

real types are platform dependent.

With the kind option the real can be specified.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, variable preci-sion

3.1415, -5.5, .7E3, 12.5E-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 52 / 104

Page 172: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

FORTRAN 90 Standard Data Types

FORTRAN 90 data types are like the 77 types.

The sizer option also is available in 90.

real types are platform dependent.

With the kind option the real can be specified.

Type Comment ExampleINTEGER Integer number 15, -100, 2500REAL Floatingpoint num-

ber, variable preci-sion

3.1415, -5.5, .7E3, 12.5E-5

COMPLEX Complex numbers,(two REALs)

(3.1415, -5.5), (1.4, 7.1E4)

LOGICAL Logical values .TRUE., .FALSE.

E. Baeck (Uni-DUE) Introduction into FORTRAN 52 / 104

Page 173: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

How to Declare Variables in FORTRAN 90

A variable is declared explicit by it’s data typetype::[variable name]

A real can be specified by a type specifier.

The kind specifier is dependent on the platform.

On Intel kind=4 provides a 4 byte float, kind=8 an 8 byte float.

How to declare implicit? Real type on Intel processors

integer::a ! it’s a standard integer

real::b ! it’s a standard real

real(4)::r4 ! it’s 4 byte real

real(8)::r8 ! it’s 8 byte real

E. Baeck (Uni-DUE) Introduction into FORTRAN 53 / 104

Page 174: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

How to Declare Variables in FORTRAN 90

A variable is declared explicit by it’s data typetype::[variable name]

A real can be specified by a type specifier.

The kind specifier is dependent on the platform.

On Intel kind=4 provides a 4 byte float, kind=8 an 8 byte float.

How to declare implicit? Real type on Intel processors

integer::a ! it’s a standard integer

real::b ! it’s a standard real

real(4)::r4 ! it’s 4 byte real

real(8)::r8 ! it’s 8 byte real

E. Baeck (Uni-DUE) Introduction into FORTRAN 53 / 104

Page 175: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

How to Declare Variables in FORTRAN 90

A variable is declared explicit by it’s data typetype::[variable name]

A real can be specified by a type specifier.

The kind specifier is dependent on the platform.

On Intel kind=4 provides a 4 byte float, kind=8 an 8 byte float.

How to declare implicit? Real type on Intel processors

integer::a ! it’s a standard integer

real::b ! it’s a standard real

real(4)::r4 ! it’s 4 byte real

real(8)::r8 ! it’s 8 byte real

E. Baeck (Uni-DUE) Introduction into FORTRAN 53 / 104

Page 176: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

How to Declare Variables in FORTRAN 90

A variable is declared explicit by it’s data typetype::[variable name]

A real can be specified by a type specifier.

The kind specifier is dependent on the platform.

On Intel kind=4 provides a 4 byte float, kind=8 an 8 byte float.

The kind will control the available precision!

integer::a ! it’s a standard integer

real::b ! it’s a standard real

real(kind=4)::r4 ! kind=4 often provides a 4 byte real

real(kind=8)::r8 ! kind=8 often provides a 8 byte real

E. Baeck (Uni-DUE) Introduction into FORTRAN 53 / 104

Page 177: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

Complex Arithmetic, Quadratic Equation

A complex data type is like a vector of dimension two.

An assignment looks like c = (xr , xi ), i.e. (real,imaginary) part.

Intrinsic functions like sqrt are able to handle the complex.

Solving a quadratic equation with a complex arithmeticprogram csqrt

complex::x,a,b,c

a = (1,0); b = (0,0); c = (4,0);

x = (-b +sqrt(b**2 -4.*a*c))/(2.*a)

write(*,*) x

end program csqrt

⇐ declaring the complex⇐ initialization⇐ apply like real

E. Baeck (Uni-DUE) Introduction into FORTRAN 54 / 104

Page 178: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

Complex Arithmetic, Quadratic Equation

A complex data type is like a vector of dimension two.

An assignment looks like c = (xr , xi ), i.e. (real,imaginary) part.

Intrinsic functions like sqrt are able to handle the complex.

Solving a quadratic equation with a complex arithmeticprogram csqrt

complex::x,a,b,c

a = (1,0); b = (0,0); c = (4,0);

x = (-b +sqrt(b**2 -4.*a*c))/(2.*a)

write(*,*) x

end program csqrt

⇐ declaring the complex⇐ initialization⇐ apply like real

E. Baeck (Uni-DUE) Introduction into FORTRAN 54 / 104

Page 179: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Data Types FORTRAN 90 Data Types

Complex Arithmetic, Quadratic Equation

A complex data type is like a vector of dimension two.

An assignment looks like c = (xr , xi ), i.e. (real,imaginary) part.

Intrinsic functions like sqrt are able to handle the complex.

Solving a quadratic equation with a complex arithmeticprogram csqrt

complex::x,a,b,c

a = (1,0); b = (0,0); c = (4,0);

x = (-b +sqrt(b**2 -4.*a*c))/(2.*a)

write(*,*) x

end program csqrt

⇐ declaring the complex⇐ initialization⇐ apply like real

E. Baeck (Uni-DUE) Introduction into FORTRAN 54 / 104

Page 180: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators

Operators

E. Baeck (Uni-DUE) Introduction into FORTRAN 55 / 104

Page 181: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Arithmetic Operators

Arithmetic Operators of FORTRAN 77

You should be careful with the usage of data types.

Applying integer division will truncate the division rest.

Operator Comment Example+ sum operator x = 2+3 >>> 5

- subtraction operator x = 4-2 >>> 2

* product operator x = 2*4 >>> 8

/ division operator x = 9/2 >>> 4

x = 9./2. >>> 4.5

** power operator x = a**2

// concatenate of strings x = "hello"//"world"

>>> "hello world"

E. Baeck (Uni-DUE) Introduction into FORTRAN 56 / 104

Page 182: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Arithmetic Operators

Arithmetic Operators of FORTRAN 77

You should be careful with the usage of data types.

Applying integer division will truncate the division rest.

Operator Comment Example+ sum operator x = 2+3 >>> 5

- subtraction operator x = 4-2 >>> 2

* product operator x = 2*4 >>> 8

/ division operator x = 9/2 >>> 4

x = 9./2. >>> 4.5

** power operator x = a**2

// concatenate of strings x = "hello"//"world"

>>> "hello world"

E. Baeck (Uni-DUE) Introduction into FORTRAN 56 / 104

Page 183: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators of FORTRAN 77

Boolean operators are very special in FORTRAN 77.

Boolean stuff is put in between two dots.

With FORTRAN 90 the standard operator notation is introduced.

Operator Comment Example.lt. less than x = 23 .lt. 13 >>> .false.

.le. less equal x = 23 .le. 23 >>> .true.

.gt. greater x = 23 .gt. 13 >>> .true.

.ge. left shift of bits x = 23 .ge. 23 >>> .true.

.eq. equal x = 23 .eq. 23 >>> .true.

.ne. not equal x = 23 .ne. 13 >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 57 / 104

Page 184: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators of FORTRAN 77

Boolean operators are very special in FORTRAN 77.

Boolean stuff is put in between two dots.

With FORTRAN 90 the standard operator notation is introduced.

Operator Comment Example.lt. less than x = 23 .lt. 13 >>> .false.

.le. less equal x = 23 .le. 23 >>> .true.

.gt. greater x = 23 .gt. 13 >>> .true.

.ge. left shift of bits x = 23 .ge. 23 >>> .true.

.eq. equal x = 23 .eq. 23 >>> .true.

.ne. not equal x = 23 .ne. 13 >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 57 / 104

Page 185: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators of FORTRAN 77

Boolean operators are very special in FORTRAN 77.

Boolean stuff is put in between two dots.

With FORTRAN 90 the standard operator notation is introduced.

Operator Comment Example.lt. less than x = 23 .lt. 13 >>> .false.

.le. less equal x = 23 .le. 23 >>> .true.

.gt. greater x = 23 .gt. 13 >>> .true.

.ge. left shift of bits x = 23 .ge. 23 >>> .true.

.eq. equal x = 23 .eq. 23 >>> .true.

.ne. not equal x = 23 .ne. 13 >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 57 / 104

Page 186: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators of FORTRAN 90

FORTRAN 90 uses nearly the operator symbols like C.

The not equal /= is different because ! is used as comment symbol.

Operator Comment Example< less than x = 23 < 13 >>> .false.

<= less equal x = 23 <= 23 >>> .true.

> greater x = 23 > 13 >>> .true.

>= left shift of bits x = 23 >= 23 >>> .true.

== equal x = 23 == 23 >>> .true.

/= non equal x = 23 /= 23 >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 58 / 104

Page 187: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators of FORTRAN 90

FORTRAN 90 uses nearly the operator symbols like C.

The not equal /= is different because ! is used as comment symbol.

Operator Comment Example< less than x = 23 < 13 >>> .false.

<= less equal x = 23 <= 23 >>> .true.

> greater x = 23 > 13 >>> .true.

>= left shift of bits x = 23 >= 23 >>> .true.

== equal x = 23 == 23 >>> .true.

/= non equal x = 23 /= 23 >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 58 / 104

Page 188: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Operators Boolean Operators

Boolean Operators for Expressions

The boolean operators for expressions are not depending on theFORTRAN level.

Operator Comment Example.and. logical and x = 1 .lt. 2 .and. 2 .lt. 3 >>> .true.

.or. logical or x = 1 .lt. 2 .or. 2 .gr. 3 >>> .true.

.equ. logical equal x = .true. >>> y = .false.

>>> x .eqv. y >>> .false.

.nequ. logical no equal x = .true. >>> y = .false.

>>> x .neqv. y >>> .true.

.not. logical not x = .not. (1 .lt. 2) >>> .false.

E. Baeck (Uni-DUE) Introduction into FORTRAN 59 / 104

Page 189: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops

Explicit Loops

E. Baeck (Uni-DUE) Introduction into FORTRAN 60 / 104

Page 190: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 191: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 192: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 193: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 194: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 195: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Old Fashion FORTRAN 66/IV Loop

A loop starts with do

The label (in this case 100) specifies the last line of the code block.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

Oh! That FORTRAN66 is very archaic!

c234567

do 100 index = istart, iend, inc

Block of statements

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 61 / 104

Page 196: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Escape a 66/IV Loop

To break a loop you only can jump out using a goto.

If the program should stop without ending the loop, a stop or returncan be used.

Breaking a 66 Loop

c234567

do 100 i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

100 continue

200 continue

The loop will be broken, if ireaches 5. Then executing the gotothe program will continue at level200.

E. Baeck (Uni-DUE) Introduction into FORTRAN 62 / 104

Page 197: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Archaic Loop

Escape a 66/IV Loop

To break a loop you only can jump out using a goto.

If the program should stop without ending the loop, a stop or returncan be used.

Breaking a 66 Loop

c234567

do 100 i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

100 continue

200 continue

The loop will be broken, if ireaches 5. Then executing the gotothe program will continue at level200.

E. Baeck (Uni-DUE) Introduction into FORTRAN 62 / 104

Page 198: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.

The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

We use the loop index i to run the loop.

The range of i is given from 1 to n.

The result variable should be initialized with one, because a productwill be performed in every iteration.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 199: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.

The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

We use the loop index i to run the loop.

The range of i is given from 1 to n.

The result variable should be initialized with one, because a productwill be performed in every iteration.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 200: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.

The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

We use the loop index i to run the loop.

The range of i is given from 1 to n.

The result variable should be initialized with one, because a productwill be performed in every iteration.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 201: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.

The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

We use the loop index i to run the loop.

The range of i is given from 1 to n.

The result variable should be initialized with one, because a productwill be performed in every iteration.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 202: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.

The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

We use the loop index i to run the loop.

The range of i is given from 1 to n.

The result variable should be initialized with one, because a productwill be performed in every iteration.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 203: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops Factorial and 66-Loop

Factorial, a FORTRAN 66/IV Example

Implementation of the factorial for a given number n.The formula is given below.

n! = 1 · 2 · · · · · (n − 1) · n =n∏

i=1

i

Here the source code is given without any comments.

c234567

real*4 f

integer*2 i,n

input data

n = 20

f = 1

do 100 i=2,n

f = f*i

100 continue

end

The comment line shows the numbers of thecolumn. With every statement starts with thecolumn 7.

f, the result variable, gets a new factor withinevery iteration step.

The label 100 must be inside the label columns1-5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 63 / 104

Page 204: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 205: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 206: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 207: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 208: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 209: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 210: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

77 Loop, only one Step into the Future

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

If you want to break the loop there is no any possibility but goto.

Oh! With FORTRAN77 only on step into the future. That label is missing!

c234567

do i = 1,10

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

enddo

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 64 / 104

Page 211: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

Escape and cycle a 77 Loop

To break a loop you only can jump out using a goto.

If the program should stop without ending the loop, a stop or returncan be used.

We cycle with the label 100 and exit with label 200

c234567

do i = 1,10

if (i.eq.2) goto 100

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

100 continue

enddo

200 continue

The loop will be cycled, if i isequal 2.

The loop will be broken, if ireaches 5. Then executing the gotothe program will continue at level200.

E. Baeck (Uni-DUE) Introduction into FORTRAN 65 / 104

Page 212: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 77 Loop

Escape and cycle a 77 Loop

To break a loop you only can jump out using a goto.

If the program should stop without ending the loop, a stop or returncan be used.

We cycle with the label 100 and exit with label 200

c234567

do i = 1,10

if (i.eq.2) goto 100

write(*,*) ’ i=’,i

if (i.eq.5) goto 200

100 continue

enddo

200 continue

The loop will be cycled, if i isequal 2.

The loop will be broken, if ireaches 5. Then executing the gotothe program will continue at level200.

E. Baeck (Uni-DUE) Introduction into FORTRAN 65 / 104

Page 213: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 214: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 215: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 216: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 217: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 218: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 219: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 220: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

90 Loop with modern Features

A loop starts with do

The end of the loop is defined by an end do statement.

The loop index is set to the starting value (istart).

The loop runs until the end value (iend) is reached.

After each cycle the loop index is incremented by the step width inc.

If inc is not specified, 1 is used.

FORTRAN 90 escapes a loop with the exit statement.

FORTRAN 90 starts a new cycle immediately with a cycle statement.

Now the Loop is up to date!

! free style format

do index = istart, iend, inc

Block of statements

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 66 / 104

Page 221: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

Escape and cycle a 90 Loop

To break a loop in FORTRAN 90, we exit with the exit statement.

To cycle a loop in FORTRAN 90, we use the cycle statement.

With FORTRAN 90 structured programming is possible.

Structured programming avoids goto jumping ...

and so called spaghetti code.

Breaking and escaping 90 Loops

! free style format, no goto-jumps

do i = 1,10

if (i.eq.2) cycle

write(*,*) ’ i=’,i

if (i.eq.5) exit

enddo

The loop will be cycled with cycle,if i is equal 2. The loop will bebroken with exit, if i reaches 5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 67 / 104

Page 222: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

Escape and cycle a 90 Loop

To break a loop in FORTRAN 90, we exit with the exit statement.

To cycle a loop in FORTRAN 90, we use the cycle statement.

With FORTRAN 90 structured programming is possible.

Structured programming avoids goto jumping ...

and so called spaghetti code.

Breaking and escaping 90 Loops

! free style format, no goto-jumps

do i = 1,10

if (i.eq.2) cycle

write(*,*) ’ i=’,i

if (i.eq.5) exit

enddo

The loop will be cycled with cycle,if i is equal 2. The loop will bebroken with exit, if i reaches 5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 67 / 104

Page 223: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

Escape and cycle a 90 Loop

To break a loop in FORTRAN 90, we exit with the exit statement.

To cycle a loop in FORTRAN 90, we use the cycle statement.

With FORTRAN 90 structured programming is possible.

Structured programming avoids goto jumping ...

and so called spaghetti code.

Breaking and escaping 90 Loops

! free style format, no goto-jumps

do i = 1,10

if (i.eq.2) cycle

write(*,*) ’ i=’,i

if (i.eq.5) exit

enddo

The loop will be cycled with cycle,if i is equal 2. The loop will bebroken with exit, if i reaches 5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 67 / 104

Page 224: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

Escape and cycle a 90 Loop

To break a loop in FORTRAN 90, we exit with the exit statement.

To cycle a loop in FORTRAN 90, we use the cycle statement.

With FORTRAN 90 structured programming is possible.

Structured programming avoids goto jumping ...

and so called spaghetti code.

Breaking and escaping 90 Loops

! free style format, no goto-jumps

do i = 1,10

if (i.eq.2) cycle

write(*,*) ’ i=’,i

if (i.eq.5) exit

enddo

The loop will be cycled with cycle,if i is equal 2. The loop will bebroken with exit, if i reaches 5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 67 / 104

Page 225: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Explicit Loops The 90 Loop

Escape and cycle a 90 Loop

To break a loop in FORTRAN 90, we exit with the exit statement.

To cycle a loop in FORTRAN 90, we use the cycle statement.

With FORTRAN 90 structured programming is possible.

Structured programming avoids goto jumping ...

and so called spaghetti code.

Breaking and escaping 90 Loops

! free style format, no goto-jumps

do i = 1,10

if (i.eq.2) cycle

write(*,*) ’ i=’,i

if (i.eq.5) exit

enddo

The loop will be cycled with cycle,if i is equal 2. The loop will bebroken with exit, if i reaches 5.

E. Baeck (Uni-DUE) Introduction into FORTRAN 67 / 104

Page 226: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching

Branching

E. Baeck (Uni-DUE) Introduction into FORTRAN 68 / 104

Page 227: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 66 Branching

Branching in FORTRAN 66

Branching is done with an IF statement.

if (boolean expression) statement

Multiple statement branching only is possible with jumps.

Two branches are done two goto jumps.

E. Baeck (Uni-DUE) Introduction into FORTRAN 69 / 104

Page 228: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 66 Branching

Branching in FORTRAN 66

Branching is done with an IF statement.

if (boolean expression) statement

Multiple statement branching only is possible with jumps.

Two branches are done two goto jumps.

E. Baeck (Uni-DUE) Introduction into FORTRAN 69 / 104

Page 229: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 66 Branching

Branching in FORTRAN 66

Branching is done with an IF statement.

if (boolean expression) statement

Multiple statement branching only is possible with jumps.

Two branches are done two goto jumps.

Skip it by a goto jump...

c234567

if (.not. condition1) goto 100

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

100 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 69 / 104

Page 230: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 66 Branching

Branching in FORTRAN 66

Branching is done with an IF statement.

if (boolean expression) statement

Multiple statement branching only is possible with jumps.

Two branches are done two goto jumps.

Double Branching and wild jumping, typical for FORTRAN 66...

c234567

if (condition1) goto 100

.. else code block ..

goto 200

100 continue

.. if code block ..

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 69 / 104

Page 231: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Branching in FORTRAN 90

Branching is done with an if, then, endif statement.

if (boolean expression) then starts the Branch.

Then we can option execute a code block.

The branch is closed with an endif statement.

endif and end if is the same.

Time of jumping with goto can be over...

! this is free styling format

if (condition1) then

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 70 / 104

Page 232: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Branching in FORTRAN 90

Branching is done with an if, then, endif statement.

if (boolean expression) then starts the Branch.

Then we can option execute a code block.

The branch is closed with an endif statement.

endif and end if is the same.

Time of jumping with goto can be over...

! this is free styling format

if (condition1) then

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 70 / 104

Page 233: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Branching in FORTRAN 90

Branching is done with an if, then, endif statement.

if (boolean expression) then starts the Branch.

Then we can option execute a code block.

The branch is closed with an endif statement.

endif and end if is the same.

Time of jumping with goto can be over...

! this is free styling format

if (condition1) then

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 70 / 104

Page 234: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Branching in FORTRAN 90

Branching is done with an if, then, endif statement.

if (boolean expression) then starts the Branch.

Then we can option execute a code block.

The branch is closed with an endif statement.

endif and end if is the same.

Time of jumping with goto can be over...

! this is free styling format

if (condition1) then

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 70 / 104

Page 235: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Branching in FORTRAN 90

Branching is done with an if, then, endif statement.

if (boolean expression) then starts the Branch.

Then we can option execute a code block.

The branch is closed with an endif statement.

endif and end if is the same.

Time of jumping with goto can be over...

! this is free styling format

if (condition1) then

.. statement 1 ..

.. statement 2 ..

.. statement 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 70 / 104

Page 236: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Mulitbranching in FORTRAN 90

Multibranching is done with an else statement.

More then one condition are possible with elseif.

Both statements are optional.

else has to be the last branch, if used.

Even with multibranching jumping with goto can be avoided...

! this is free styling format

if (condition 1) then

.. code block 1 ..

elseif (condition 2) then

.. code block 2 ..

else

.. code block 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 71 / 104

Page 237: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Mulitbranching in FORTRAN 90

Multibranching is done with an else statement.

More then one condition are possible with elseif.

Both statements are optional.

else has to be the last branch, if used.

Even with multibranching jumping with goto can be avoided...

! this is free styling format

if (condition 1) then

.. code block 1 ..

elseif (condition 2) then

.. code block 2 ..

else

.. code block 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 71 / 104

Page 238: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Mulitbranching in FORTRAN 90

Multibranching is done with an else statement.

More then one condition are possible with elseif.

Both statements are optional.

else has to be the last branch, if used.

Even with multibranching jumping with goto can be avoided...

! this is free styling format

if (condition 1) then

.. code block 1 ..

elseif (condition 2) then

.. code block 2 ..

else

.. code block 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 71 / 104

Page 239: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Mulitbranching in FORTRAN 90

Multibranching is done with an else statement.

More then one condition are possible with elseif.

Both statements are optional.

else has to be the last branch, if used.

Even with multibranching jumping with goto can be avoided...

! this is free styling format

if (condition 1) then

.. code block 1 ..

elseif (condition 2) then

.. code block 2 ..

else

.. code block 3 ..

end if

E. Baeck (Uni-DUE) Introduction into FORTRAN 71 / 104

Page 240: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 241: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 242: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 243: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 244: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 245: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 246: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 247: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Branching The 90 Branching

Solving a Quadratic Equation with FORTRAN 66 and 90

Branching is necessary to handle every case.

a · x2 + b · x + c = 0

If a 6= 0 we have the quadratic case.

If a = 0 ∧ b 6= 0 we have the linear case.

If a = 0 ∧ b = 0 we have the constant case.

If a = 0 ∧ b = 0 ∧ c = 0 we have infinite solutions.

If a = 0 ∧ b = 0 ∧ c 6= 0 we have no solutions.

... so, let’s implement it in FORTRAN 66!

... then we will see how it works on FORTRAN 90!

E. Baeck (Uni-DUE) Introduction into FORTRAN 72 / 104

Page 248: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops

Implicit Loops

E. Baeck (Uni-DUE) Introduction into FORTRAN 73 / 104

Page 249: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops Archaic Open Loop

No Statement for an Open Loop in FORTRAN 66/IV

An implicit loop in contrast to an for has to be controlled explicitly.

That is, an endless loop with an explicit break condition.

In FORTRAN 66/IV there is no statement for an implicit loop.

Therefore we have to solve the problem with jumps.

... an endless and lively source of gotos will make everythingincomprehensible. Strategy is like programming in assembler!

Oh! It’s hard to implement an open loop!

c234567

100 continue

.. some statements ..

if (condition) goto 200

goto 100

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 74 / 104

Page 250: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops Archaic Open Loop

No Statement for an Open Loop in FORTRAN 66/IV

An implicit loop in contrast to an for has to be controlled explicitly.

That is, an endless loop with an explicit break condition.

In FORTRAN 66/IV there is no statement for an implicit loop.

Therefore we have to solve the problem with jumps.

... an endless and lively source of gotos will make everythingincomprehensible. Strategy is like programming in assembler!

Oh! It’s hard to implement an open loop!

c234567

100 continue

.. some statements ..

if (condition) goto 200

goto 100

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 74 / 104

Page 251: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops Archaic Open Loop

No Statement for an Open Loop in FORTRAN 66/IV

An implicit loop in contrast to an for has to be controlled explicitly.

That is, an endless loop with an explicit break condition.

In FORTRAN 66/IV there is no statement for an implicit loop.

Therefore we have to solve the problem with jumps.

... an endless and lively source of gotos will make everythingincomprehensible. Strategy is like programming in assembler!

Oh! It’s hard to implement an open loop!

c234567

100 continue

.. some statements ..

if (condition) goto 200

goto 100

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 74 / 104

Page 252: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops Archaic Open Loop

No Statement for an Open Loop in FORTRAN 66/IV

An implicit loop in contrast to an for has to be controlled explicitly.

That is, an endless loop with an explicit break condition.

In FORTRAN 66/IV there is no statement for an implicit loop.

Therefore we have to solve the problem with jumps.

... an endless and lively source of gotos will make everythingincomprehensible. Strategy is like programming in assembler!

Oh! It’s hard to implement an open loop!

c234567

100 continue

.. some statements ..

if (condition) goto 200

goto 100

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 74 / 104

Page 253: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops Archaic Open Loop

No Statement for an Open Loop in FORTRAN 66/IV

An implicit loop in contrast to an for has to be controlled explicitly.

That is, an endless loop with an explicit break condition.

In FORTRAN 66/IV there is no statement for an implicit loop.

Therefore we have to solve the problem with jumps.

... an endless and lively source of gotos will make everythingincomprehensible. Strategy is like programming in assembler!

Oh! It’s hard to implement an open loop!

c234567

100 continue

.. some statements ..

if (condition) goto 200

goto 100

200 continue

E. Baeck (Uni-DUE) Introduction into FORTRAN 74 / 104

Page 254: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops 90’s Simple Open Loop

FORTRAN 90 Comes With a Modern Loop Statement

If we use the do without indexing, it’s an endless loop.

The endless loop can be broken with an exit.

So, like in every modern language, now it looks very comprehensible.

Wonderful!, The pain has gone!

! this is free style format

do

... some statements ...

if (condition) exit

... some statements...

end do

E. Baeck (Uni-DUE) Introduction into FORTRAN 75 / 104

Page 255: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops 90’s Simple Open Loop

FORTRAN 90 Comes With a Modern Loop Statement

If we use the do without indexing, it’s an endless loop.

The endless loop can be broken with an exit.

So, like in every modern language, now it looks very comprehensible.

Wonderful!, The pain has gone!

! this is free style format

do

... some statements ...

if (condition) exit

... some statements...

end do

E. Baeck (Uni-DUE) Introduction into FORTRAN 75 / 104

Page 256: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops 90’s Simple Open Loop

FORTRAN 90 Comes With a Modern Loop Statement

If we use the do without indexing, it’s an endless loop.

The endless loop can be broken with an exit.

So, like in every modern language, now it looks very comprehensible.

Wonderful!, The pain has gone!

! this is free style format

do

... some statements ...

if (condition) exit

... some statements...

end do

E. Baeck (Uni-DUE) Introduction into FORTRAN 75 / 104

Page 257: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 258: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 259: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 260: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 261: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 262: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 263: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 264: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Implicit Loops The Float Precision

Example: Determining the Float Precision

How can we determine the arithmetic precision of a float?

To calculate the relative precision, we should know,that a float has an finite number of digits.

So we start from a value of 1.

Then we divide it by 2.

This we do as long as the result is differentcomparing it with the previous result.

If the current value is equal to the previous withrespect to the finite digits, We have to multiplythis value by 2.

So that is the smallest relative deviation, we candescribe with our float.

You can see easily that the implementation will usean implicit loop.

Start

x1 = 1.x2 = 1.d = 2.

x2 = x2/ds = x1 + x2

s = x1

result =x2 ∗ d

Stop

no

yes

E. Baeck (Uni-DUE) Introduction into FORTRAN 76 / 104

Page 265: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions

Subroutines and Functions

E. Baeck (Uni-DUE) Introduction into FORTRAN 77 / 104

Page 266: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 267: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 268: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 269: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 270: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 271: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 272: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 273: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Subroutines and Functions

subroutine and function encapsulate source code.

Parameter are passed from the caller by the list of formal parameters.

Parameters are passed by reference, i.e. by there address.

Passing by reference provides working on the caller’s memory.

Passing parameter by reference can produce undesired side effects.

A function provides a return value, a subroutine not.

There are no other differences.

A subroutine in C would be a void function.

E. Baeck (Uni-DUE) Introduction into FORTRAN 78 / 104

Page 274: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 275: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 276: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 277: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 278: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 279: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 280: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Interface, List of Parameters

Data are passed to the called sub programs by the parameter list.

A parameter list, is a comma separated list of names.

Parsed parameters are specified like other parameters in thespecification section of the sub program.

A function return value is assigned to the name of the function.

Parameter names are formal. Only the order and the type areimportant.

Wrong orders and wrong types of parsed parameters i.g. will crashthe program.

The compiler is not able to check parameter parsing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 79 / 104

Page 281: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Syntax and an Example of a Subroutine

A subroutine starts with a name, the end is end.

return starts the jump back to the caller.

Add two reals in a subroutinec234567

real s

call AddIt(1.,2.,s)

write(*,*) s

end

c here is the subroutin

subroutine AddIt (a,b,c)

real a,b,c

c = a+b

return

end

⇐ variable for the return⇐ call the subroutineinput values are 1 and 2

⇐ subroutine’s interface⇐ all parameters are real⇐ the third is the return⇐ return is possible becauseof the reference parsing

E. Baeck (Uni-DUE) Introduction into FORTRAN 80 / 104

Page 282: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Syntax and an Example of a Subroutine

A subroutine starts with a name, the end is end.

return starts the jump back to the caller.

Add two reals in a subroutinec234567

real s

call AddIt(1.,2.,s)

write(*,*) s

end

c here is the subroutin

subroutine AddIt (a,b,c)

real a,b,c

c = a+b

return

end

⇐ variable for the return⇐ call the subroutineinput values are 1 and 2

⇐ subroutine’s interface⇐ all parameters are real⇐ the third is the return⇐ return is possible becauseof the reference parsing

E. Baeck (Uni-DUE) Introduction into FORTRAN 80 / 104

Page 283: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Syntax and an Example of a Function

A function starts with a type and a name, the end is end.

return starts the jump back to the caller.

The return value is set by assigning it to the name of the function.

Add two reals in a subroutinec234567

write(*,*) AddIt(1.,2.)

end

c here is the subroutin

real function AddIt (a,b)

real a,b

AddIt = a+b

return

end

⇐ call the functioninput values are 1 and 2

⇐ function’s interface⇐ all parameters are real⇐ assign return value⇐ and return to the caller

E. Baeck (Uni-DUE) Introduction into FORTRAN 81 / 104

Page 284: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Syntax and an Example of a Function

A function starts with a type and a name, the end is end.

return starts the jump back to the caller.

The return value is set by assigning it to the name of the function.

Add two reals in a subroutinec234567

write(*,*) AddIt(1.,2.)

end

c here is the subroutin

real function AddIt (a,b)

real a,b

AddIt = a+b

return

end

⇐ call the functioninput values are 1 and 2

⇐ function’s interface⇐ all parameters are real⇐ assign return value⇐ and return to the caller

E. Baeck (Uni-DUE) Introduction into FORTRAN 81 / 104

Page 285: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 77 Subroutines and Functions

Syntax and an Example of a Function

A function starts with a type and a name, the end is end.

return starts the jump back to the caller.

The return value is set by assigning it to the name of the function.

Add two reals in a subroutinec234567

write(*,*) AddIt(1.,2.)

end

c here is the subroutin

real function AddIt (a,b)

real a,b

AddIt = a+b

return

end

⇐ call the functioninput values are 1 and 2

⇐ function’s interface⇐ all parameters are real⇐ assign return value⇐ and return to the caller

E. Baeck (Uni-DUE) Introduction into FORTRAN 81 / 104

Page 286: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 90 Subroutines and Functions

Subroutines and Functions in 90

90 functions and subroutines are very similar to the 77 routines.

In 90 style the end of a function/subroutine is signed by it’s name.

90 provides internal function inside a contains block.

A little converter function inside the main program.

E. Baeck (Uni-DUE) Introduction into FORTRAN 82 / 104

Page 287: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 90 Subroutines and Functions

Subroutines and Functions in 90

90 functions and subroutines are very similar to the 77 routines.

In 90 style the end of a function/subroutine is signed by it’s name.

90 provides internal function inside a contains block.

A little converter function inside the main program.

E. Baeck (Uni-DUE) Introduction into FORTRAN 82 / 104

Page 288: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 90 Subroutines and Functions

Subroutines and Functions in 90

90 functions and subroutines are very similar to the 77 routines.

In 90 style the end of a function/subroutine is signed by it’s name.

90 provides internal function inside a contains block.

A little converter function inside the main program.

E. Baeck (Uni-DUE) Introduction into FORTRAN 82 / 104

Page 289: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Subroutines and Functions 90 Subroutines and Functions

Subroutines and Functions in 90

90 functions and subroutines are very similar to the 77 routines.

In 90 style the end of a function/subroutine is signed by it’s name.

90 provides internal function inside a contains block.

A little converter function inside the main program.

Converting C Temperature into Fahrenheit

program intfunc

real::TCel,TFah

TCel = 100.

write (*,*) ’TCel=’,TCel,’TFah=’,CelToFah(TCel)

contains

real function CelToFah(t)

CelToFah = t * 1.8 + 32.0

end function CelToFah

end program intfunc

E. Baeck (Uni-DUE) Introduction into FORTRAN 82 / 104

Page 290: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays

Arrays

E. Baeck (Uni-DUE) Introduction into FORTRAN 83 / 104

Page 291: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 292: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 293: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 294: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 295: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 296: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 77 Arrays

Arrays in FORTRAN 77

Arrays are indexed variables.

Arrays only can store the same data type.

Arrays are data types which are used for vectors and matrices.

An array variable first is declared by the data type.

With an dimension statement the index range is set.

77 only provides static arrays. Dynamical allocation is not supported.

Declaring a 3d unity vector in x direction, 77 version

c23457

real v

dimension v(3)

v(1) = 1.

v(2) = 0.

v(3) = 0.

⇐ first the type is set⇐ then the array range is set⇐ access with parenthesis

E. Baeck (Uni-DUE) Introduction into FORTRAN 84 / 104

Page 297: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 90 Arrays

Arrays in FORTRAN 90

Behavior of an array is like in FORTRAN 70.

Type specification and array range in one statement

In contrast to 77 there dynamic arrays too.

Automatic array can be allocated in sub programs.

Specifying 90 arrays

real,dimension(3)::a,b

a(1) = 1; a(2) = 2; a(3) = 0

b(1) = 0; b(2) = 3; b(3) = 1

⇐ standard kind used⇐ ; connects lines

E. Baeck (Uni-DUE) Introduction into FORTRAN 85 / 104

Page 298: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 90 Arrays

Arrays in FORTRAN 90

Behavior of an array is like in FORTRAN 70.

Type specification and array range in one statement

In contrast to 77 there dynamic arrays too.

Automatic array can be allocated in sub programs.

Specifying 90 arrays

real,dimension(3)::a,b

a(1) = 1; a(2) = 2; a(3) = 0

b(1) = 0; b(2) = 3; b(3) = 1

⇐ standard kind used⇐ ; connects lines

E. Baeck (Uni-DUE) Introduction into FORTRAN 85 / 104

Page 299: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 90 Arrays

Arrays in FORTRAN 90

Behavior of an array is like in FORTRAN 70.

Type specification and array range in one statement

In contrast to 77 there dynamic arrays too.

Automatic array can be allocated in sub programs.

Specifying 90 arrays

real,dimension(3)::a,b

a(1) = 1; a(2) = 2; a(3) = 0

b(1) = 0; b(2) = 3; b(3) = 1

⇐ standard kind used⇐ ; connects lines

E. Baeck (Uni-DUE) Introduction into FORTRAN 85 / 104

Page 300: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays FORTRAN 90 Arrays

Arrays in FORTRAN 90

Behavior of an array is like in FORTRAN 70.

Type specification and array range in one statement

In contrast to 77 there dynamic arrays too.

Automatic array can be allocated in sub programs.

Specifying 90 arrays

real,dimension(3)::a,b

a(1) = 1; a(2) = 2; a(3) = 0

b(1) = 0; b(2) = 3; b(3) = 1

⇐ standard kind used⇐ ; connects lines

E. Baeck (Uni-DUE) Introduction into FORTRAN 85 / 104

Page 301: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Scalar Product

Scalar Product, an Array 77 Example

A simple array example is given by the scalar product.

The scalar product of two vectors is given by

s = a · b =3∑

i=1

ai · bi

E. Baeck (Uni-DUE) Introduction into FORTRAN 86 / 104

Page 302: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Scalar Product

Scalar Product, an Array 77 Example

A simple array example is given by the scalar product.

The scalar product of two vectors is given by

s = a · b =3∑

i=1

ai · bi

E. Baeck (Uni-DUE) Introduction into FORTRAN 86 / 104

Page 303: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Scalar Product

Scalar Product, an Array 77 Example

A simple array example is given by the scalar product.

The scalar product of two vectors is given by

s = a · b =3∑

i=1

ai · bi

Implementation of the 77 scalar product

c234567

real a,b,s

dimension a(3),b(3)

...

s = 0

do i=1,3

s = s + a(i)*b(i)

end do

⇐ first we declare⇐ then we set up the ranges⇐ here we initialize the vectors⇐ start up calculation

E. Baeck (Uni-DUE) Introduction into FORTRAN 86 / 104

Page 304: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Scalar Product

Scalar Product, an Array 90 Example

The 90 version only differs in the frame and the array declaration.

Within the vector initialization we connect lines with an ; character.

E. Baeck (Uni-DUE) Introduction into FORTRAN 87 / 104

Page 305: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Scalar Product

Scalar Product, an Array 90 Example

The 90 version only differs in the frame and the array declaration.

Within the vector initialization we connect lines with an ; character.

Implementation of a scalar product in FORTRAN 90

program scalprod

real,dimension(3)::a,b

real::s

a(1) = 1; a(2) = 2; a(3) = 0

b(1) = 0; b(2) = 3; b(3) = 1

s = 0

do i=1,3

s = s + a(i)*b(i)

end do

write(*,*) s

end program scalprod

⇐ standard kind used⇐ scalar declaration⇐ ; connects lines

E. Baeck (Uni-DUE) Introduction into FORTRAN 87 / 104

Page 306: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 307: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 308: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 309: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 310: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 311: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Allocatable Arrays

Allocatable Arrays in FORTRAN 90

In contrast to 77 FORTRAN 90 provides allocatable arrays.

Within a first step the array has to be specified as an allocatable array.

The number of indexes has to be specified.

Within a second step the array has to be allocated.

The available array ranges have to be specified.

If the array is no longer used, the array has to be deallocated.

Allocating an 90 arrayprogram allocmem

real,allocatable, dimension(:)::a

integer::n = 3

allocate(a(1:n))

a(1)=1; a(2)=2; a(3)=3

write(*,*) (a(i),i=1,3)

deallocate(a)

end program allocmem

⇐ specify as allocatable

⇐ allocate the array⇐ use the memory

⇐ and release it from memory

E. Baeck (Uni-DUE) Introduction into FORTRAN 88 / 104

Page 312: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Automatic Arrays

Automatic Arrays in FORTRAN 90

An automatic array lives in the scope of a subroutine or a function.

Memory can be automatically allocated by specifying a flexible range.

The allocated memory is released automatically.

An automatical 90 arrayprogram autoarray

call testauto(3)

contains

subroutine testauto(n)

integer::n

real::s=0. ,f(n)

do i=1,n

f(i) = i; s = s+f(i)

end do

write(*,*) s

end subroutine testauto

end program autoarray

⇐ call the test subroutine

⇐ the n is arbitrary

⇐ allocate f as automatic

⇐ use the array

⇐ it’s released in the return

E. Baeck (Uni-DUE) Introduction into FORTRAN 89 / 104

Page 313: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Automatic Arrays

Automatic Arrays in FORTRAN 90

An automatic array lives in the scope of a subroutine or a function.

Memory can be automatically allocated by specifying a flexible range.

The allocated memory is released automatically.

An automatical 90 arrayprogram autoarray

call testauto(3)

contains

subroutine testauto(n)

integer::n

real::s=0. ,f(n)

do i=1,n

f(i) = i; s = s+f(i)

end do

write(*,*) s

end subroutine testauto

end program autoarray

⇐ call the test subroutine

⇐ the n is arbitrary

⇐ allocate f as automatic

⇐ use the array

⇐ it’s released in the return

E. Baeck (Uni-DUE) Introduction into FORTRAN 89 / 104

Page 314: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Arrays Automatic Arrays

Automatic Arrays in FORTRAN 90

An automatic array lives in the scope of a subroutine or a function.

Memory can be automatically allocated by specifying a flexible range.

The allocated memory is released automatically.

An automatical 90 arrayprogram autoarray

call testauto(3)

contains

subroutine testauto(n)

integer::n

real::s=0. ,f(n)

do i=1,n

f(i) = i; s = s+f(i)

end do

write(*,*) s

end subroutine testauto

end program autoarray

⇐ call the test subroutine

⇐ the n is arbitrary

⇐ allocate f as automatic

⇐ use the array

⇐ it’s released in the return

E. Baeck (Uni-DUE) Introduction into FORTRAN 89 / 104

Page 315: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files

Files

E. Baeck (Uni-DUE) Introduction into FORTRAN 90 / 104

Page 316: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files File Commands

File Commands

open opens a file.

write is used to write into a file.

read is used to read from a file.

close is used to close an open file.

E. Baeck (Uni-DUE) Introduction into FORTRAN 91 / 104

Page 317: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files File Commands

File Commands

open opens a file.

write is used to write into a file.

read is used to read from a file.

close is used to close an open file.

E. Baeck (Uni-DUE) Introduction into FORTRAN 91 / 104

Page 318: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files File Commands

File Commands

open opens a file.

write is used to write into a file.

read is used to read from a file.

close is used to close an open file.

E. Baeck (Uni-DUE) Introduction into FORTRAN 91 / 104

Page 319: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files File Commands

File Commands

open opens a file.

write is used to write into a file.

read is used to read from a file.

close is used to close an open file.

E. Baeck (Uni-DUE) Introduction into FORTRAN 91 / 104

Page 320: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Example to Open a Text File

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 321: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Example to Open a Text File

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 322: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Example to Open a Text File

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 323: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Example to Open a Text File

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 324: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Values of the status Option.

status Commentold The file must existnew A new file is created. No file with this name must exist.replace A new file is created. An existing file will be replaced.scratch A temporary file is created, a file name is not needed. if the file

is closed, the file is automatically removedunknown The same as replace. It’s a pre Fortran90 statement and should

be replaced by replace

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 325: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Open Commands

Open a File

open is controlled by a set of parameters.

Most parameters are optional.

The 1st parameter, an integer, is the unit parameter.

The 2nd parameter specifies the file (file=[filename]).

status specifies the open status.

action specifies the access permissions.

Values of the action Option.

action Commentread The file is opened only for read access.write The file is opened only for write access.readwrite This action is set if the parameter is not given. The file is opened

for reading and writing.

E. Baeck (Uni-DUE) Introduction into FORTRAN 92 / 104

Page 326: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Error Handling

File Commands General Error Handling

The iostat parameter has to be used.

The io error code is assigned to a variable.

If the io status is equal zero, everything is ok.

Error Handling with iostat

integer st

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

if (st /= 0) then

write(*,*) ’*** Error: File not found!’

endif

E. Baeck (Uni-DUE) Introduction into FORTRAN 93 / 104

Page 327: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Error Handling

File Commands General Error Handling

The iostat parameter has to be used.

The io error code is assigned to a variable.

If the io status is equal zero, everything is ok.

Error Handling with iostat

integer st

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

if (st /= 0) then

write(*,*) ’*** Error: File not found!’

endif

E. Baeck (Uni-DUE) Introduction into FORTRAN 93 / 104

Page 328: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Error Handling

File Commands General Error Handling

The iostat parameter has to be used.

The io error code is assigned to a variable.

If the io status is equal zero, everything is ok.

Error Handling with iostat

integer st

open (20, file=’myfile.txt’, status=’OLD’, iostat=st)

if (st /= 0) then

write(*,*) ’*** Error: File not found!’

endif

E. Baeck (Uni-DUE) Introduction into FORTRAN 93 / 104

Page 329: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Write to a File

Write to a Text File

write is used to write to text file.

1st parameter specifies the output channel.

2st parameter specifies the output format.

The 2nd parameter can also be used as a link to a format statement.

Optional an error exception can be set by iostat.

Write with Standard Format into the Standard Channel

write(*,*) ’Write to the standard channel, with standard format!’

E. Baeck (Uni-DUE) Introduction into FORTRAN 94 / 104

Page 330: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Write to a File

Write to a Text File

write is used to write to text file.

1st parameter specifies the output channel.

2st parameter specifies the output format.

The 2nd parameter can also be used as a link to a format statement.

Optional an error exception can be set by iostat.

Write a Value to a Text File with Standard Format

open (10,file=’myfile.txt’,status=’replace’)

write(10,*) ’Write a value:’,value

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 94 / 104

Page 331: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Write to a File

Write to a Text File

write is used to write to text file.

1st parameter specifies the output channel.

2st parameter specifies the output format.

The 2nd parameter can also be used as a link to a format statement.

Optional an error exception can be set by iostat.

Write a Value to a Text File with Specified Format

open (10,file=’myfile.txt’,status=’replace’)

write(10,’(a,i2)’) ’Write a value:’,value

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 94 / 104

Page 332: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Write to a File

Write to a Text File

write is used to write to text file.

1st parameter specifies the output channel.

2st parameter specifies the output format.

The 2nd parameter can also be used as a link to a format statement.

Optional an error exception can be set by iostat.

Write a Value to a Text File with a Format Link

open (10,file=’myfile.txt’,status=’replace’)

write(10,123) ’Write a value:’,value

123 Format(a,i2)

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 94 / 104

Page 333: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Write to a File

Write to a Text File

write is used to write to text file.

1st parameter specifies the output channel.

2st parameter specifies the output format.

The 2nd parameter can also be used as a link to a format statement.

Optional an error exception can be set by iostat.

Write a Value to a Text File Checking the iostat

open (10,file=’myfile.txt’,status=’replace’)

write(10,’(a,i2)’,iostat=st) ’Write a value:’,value

if (st /= 0) then

write(*,*) ’*** Error: can not write to the file!’

endif

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 94 / 104

Page 334: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 335: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.

F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 336: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.

E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 337: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.

A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 338: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.

X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 339: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces.

/, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 340: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 341: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 342: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 343: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 344: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Specifier

Format Specifier for Text IOs

The general form of an output format is [m]Tw[.n].

The Format type T

I, integer format.F, float format with fixed decimal point.E, float format with exponential representation.A, text format, the with of the format is optional.X, output of spaces./, a new line, line break.

multiplier m

width of the output field w

number of significant digits n in float format.

Print some Data using Format Specifiers

write(io,’(a2,i3,a2,f10.2)’) ’ a(’,i,’)=’,a(i)

E. Baeck (Uni-DUE) Introduction into FORTRAN 95 / 104

Page 345: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Loops

Format using Loops

To read or write array data FORTRAN supports loops.

A one dimensional loop is done by(var(i),i=start,stop).

A two dimensional loop is done by((var(i,j),i=istart,istop),j=jstart,jend).

E. Baeck (Uni-DUE) Introduction into FORTRAN 96 / 104

Page 346: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Loops

Format using Loops

To read or write array data FORTRAN supports loops.

A one dimensional loop is done by(var(i),i=start,stop).

A two dimensional loop is done by((var(i,j),i=istart,istop),j=jstart,jend).

Print the Content of an Array using Format Loops

! print a real array

! - setup the format for one row

write(matfmt,’(a,i2,a)’) ’(’,ndim(2),’(f10.3))’

! - iterate all rows

do i=1,ndim(1)

write(io,matfmt) (a(i,j),j=1,ndim(2))

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 96 / 104

Page 347: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Format Loops

Format using Loops

To read or write array data FORTRAN supports loops.

A one dimensional loop is done by(var(i),i=start,stop).

A two dimensional loop is done by((var(i,j),i=istart,istop),j=jstart,jend).

Print the Content of an Array using Format Loops

! print a real array

! - setup the format for one row

write(matfmt,’(a,i2,a)’) ’(’,ndim(2),’(f10.3))’

! - iterate all rows

do i=1,ndim(1)

write(io,matfmt) (a(i,j),j=1,ndim(2))

enddo

E. Baeck (Uni-DUE) Introduction into FORTRAN 96 / 104

Page 348: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Read from a File

Read from a Text File

read is used to read from a file.

Free format reading is done with a * format.

Column bases reading is done by using a format specification.

Read two Values from a Text File, i.e. one Line

open (10,file=’myfile.txt’,status=’old’)

read(10,*) value1, value2

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 97 / 104

Page 349: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Read from a File

Read from a Text File

read is used to read from a file.

Free format reading is done with a * format.

Column bases reading is done by using a format specification.

Read two Values from a Text File, i.e. one Line

open (10,file=’myfile.txt’,status=’old’)

read(10,*) value1, value2

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 97 / 104

Page 350: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Read from a File

Read from a Text File

read is used to read from a file.

Free format reading is done with a * format.

Column bases reading is done by using a format specification.

Two Float Values are Read from a Table with Column Width 10

open (10,file=’myfile.txt’,status=’old’)

read(10,’(2F10.0)’) value1, value2

close(10)

E. Baeck (Uni-DUE) Introduction into FORTRAN 97 / 104

Page 351: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Close Commands

Close a File

close is used to close an opened file.

The unit, specified in the open statement, is used in the closestatement.

Opened files have to be closed to avoid a lack of io handles.

E. Baeck (Uni-DUE) Introduction into FORTRAN 98 / 104

Page 352: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Close Commands

Close a File

close is used to close an opened file.

The unit, specified in the open statement, is used in the closestatement.

Opened files have to be closed to avoid a lack of io handles.

E. Baeck (Uni-DUE) Introduction into FORTRAN 98 / 104

Page 353: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Files Close Commands

Close a File

close is used to close an opened file.

The unit, specified in the open statement, is used in the closestatement.

Opened files have to be closed to avoid a lack of io handles.

E. Baeck (Uni-DUE) Introduction into FORTRAN 98 / 104

Page 354: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations

Evaluations

E. Baeck (Uni-DUE) Introduction into FORTRAN 99 / 104

Page 355: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,

variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 356: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 357: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 358: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 359: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 360: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 361: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Evaluations 77’s Deficiency

Deficiencies of pure FORTRAN 77

There are no dynamic storage facilities at all.

There are no user-defined data types or data structures (except theCOMMON block).

Interfaces to functions are not checked, so it will be very error-prone.

Some platform-dependent features remain, so programs are nottotally portable.

Control structures are still very poor, so you have to jump usingGOTO.

Archaic features left over from the punched-card era.

fixed-format lines,statements all in upper-case,variable names limited to 6-characters.

In practice 77 therefore are used, which will reduce the portability.

E. Baeck (Uni-DUE) Introduction into FORTRAN 100 / 104

Page 362: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

FORTRAN Examples I

17 Newtons AlgorithmDie TheorieAlgorithm’s Flow

E. Baeck (Uni-DUE) FORTRAN Examples 101 / 104

Page 363: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm

Newtons Algorithm

E. Baeck (Uni-DUE) FORTRAN Examples 102 / 104

Page 364: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Isaac Newton (1643-1726)

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 365: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Isaac Newton (1643-1726)

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 366: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Isaac Newton (1643-1726)

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 367: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Geometrical Interpretation

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 368: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Geometrical Interpretation

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 369: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Die Theorie

Newton Scheme to Search for a Root

Newton lays the foundations for most ofclassical mechanics.

Newton developed the differential andintegral calculus.

Let’s discuss his simple formula.

So we search for the root of y = f (x).

The series expansion of f (x) of xn.

f (xn+1) = f (xn) + (xn+1 − xn) · f ′(xn) = 0

xn+1 = xn −f (xn)

f ′(xn)

or we get it from the slope of the triangle:

f ′(xn) =f (xn)

xn − xn+1

Geometrical Interpretation

E. Baeck (Uni-DUE) FORTRAN Examples 103 / 104

Page 370: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 371: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 372: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 373: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 374: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 375: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 376: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104

Page 377: Computer Languages for Engineersinfo.statik.uni-due.de/Lehre/CM/CLFE/Scripts/CLFE-SomeSteps.pdf · Languages FORTRAN 77 Very old computer language. Widespreaded language but a real

Newtons Algorithm Algorithm’s Flow

Pseudo-Code of Newton’s Algorithm

1 We start with an arbitrary x .

2 Calculate f (x)

3 If |f (x)| < ε, then we have the result.

4 If the maximum number of trials are expired, no solution found.

5 Calculate f ′(x).

6 If |f ′(x)| < ε, vanishing slope.

7 Calculate next x-value: x ⇐ x − f (x)f ′(x)

8 Start next cycle with step 2.

E. Baeck (Uni-DUE) FORTRAN Examples 104 / 104