Skip to content

Commit df3e268

Browse files
committed
source commit: ac9f0e6
0 parents  commit df3e268

File tree

11 files changed

+791
-0
lines changed

11 files changed

+791
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Contributor Code of Conduct"
3+
---
4+
5+
As contributors and maintainers of this project,
6+
we pledge to follow the [The Carpentries Code of Conduct][coc].
7+
8+
Instances of abusive, harassing, or otherwise unacceptable behavior
9+
may be reported by following our [reporting guidelines][coc-reporting].
10+
11+
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html
12+
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html

LICENSE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: "Licenses"
3+
---
4+
5+
## Instructional Material
6+
7+
All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry)
8+
instructional material is made available under the [Creative Commons
9+
Attribution license][cc-by-human]. The following is a human-readable summary of
10+
(and not a substitute for) the [full legal text of the CC BY 4.0
11+
license][cc-by-legal].
12+
13+
You are free:
14+
15+
- to **Share**---copy and redistribute the material in any medium or format
16+
- to **Adapt**---remix, transform, and build upon the material
17+
18+
for any purpose, even commercially.
19+
20+
The licensor cannot revoke these freedoms as long as you follow the license
21+
terms.
22+
23+
Under the following terms:
24+
25+
- **Attribution**---You must give appropriate credit (mentioning that your work
26+
is derived from work that is Copyright (c) The Carpentries and, where
27+
practical, linking to <https://carpentries.org/>), provide a [link to the
28+
license][cc-by-human], and indicate if changes were made. You may do so in
29+
any reasonable manner, but not in any way that suggests the licensor endorses
30+
you or your use.
31+
32+
- **No additional restrictions**---You may not apply legal terms or
33+
technological measures that legally restrict others from doing anything the
34+
license permits. With the understanding that:
35+
36+
Notices:
37+
38+
- You do not have to comply with the license for elements of the material in
39+
the public domain or where your use is permitted by an applicable exception
40+
or limitation.
41+
- No warranties are given. The license may not give you all of the permissions
42+
necessary for your intended use. For example, other rights such as publicity,
43+
privacy, or moral rights may limit how you use the material.
44+
45+
## Software
46+
47+
Except where otherwise noted, the example programs and other software provided
48+
by The Carpentries are made available under the [OSI][osi]-approved [MIT
49+
license][mit-license].
50+
51+
Permission is hereby granted, free of charge, to any person obtaining a copy of
52+
this software and associated documentation files (the "Software"), to deal in
53+
the Software without restriction, including without limitation the rights to
54+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
55+
of the Software, and to permit persons to whom the Software is furnished to do
56+
so, subject to the following conditions:
57+
58+
The above copyright notice and this permission notice shall be included in all
59+
copies or substantial portions of the Software.
60+
61+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67+
SOFTWARE.
68+
69+
## Trademark
70+
71+
"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library
72+
Carpentry" and their respective logos are registered trademarks of [Community
73+
Initiatives][ci].
74+
75+
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/
76+
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode
77+
[mit-license]: https://opensource.org/licenses/mit-license.html
78+
[ci]: https://communityin.org/
79+
[osi]: https://opensource.org

data/exercises.tar.gz

359 Bytes
Binary file not shown.

index.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
site: sandpaper::sandpaper_site
3+
---
4+
5+
::: caution
6+
7+
This is a new lesson built with [The Carpentries Workbench][carpentries-workbench].
8+
It is currently in pre-alpha development by the
9+
[British Geological Survey][bgs-link],
10+
the [National Centre for Atmospheric Science][ncas-link],
11+
the [National Oceanography Centre][noc-link],
12+
and the [Met Office][uk-met-link].
13+
14+
The lesson adapts resources from
15+
[ARCHER2](https://github.com/ARCHER2-HPC/archer2-fortran-intro),
16+
[Imperial College London](https://github.com/ImperialCollegeLondon/RCDS-introduction-to-fortran),
17+
[Modern Fortran in Science and Technology course](https://github.com/jonaslindemann/modern_fortran_book?tab=readme-ov-file),
18+
[LRZ's Programming with Fortran course](https://doku.lrz.de/programming-with-fortran-10746212.html),
19+
and more.[^other-courses]
20+
21+
:::
22+
23+
Fortran was created in 1957 by a team at IBM
24+
and excels with numerically intensive science code.
25+
Far from the punchcards, and fixed-form formatting of Fortran's early days,
26+
modern Fortran is fast, supports object orientated programming
27+
and is easy to read.
28+
29+
Fortran is often used to write code for High Performance Computing (HPC).
30+
Many of the research codes run on ARCHER2[^archer2]
31+
are Fortran programs.[^archer2-codes]
32+
Various areas of Science are covered by these Fortran programs.
33+
For example quantum chemistry, plasmas, and numerical weather prediction.
34+
35+
More recent standards of Fortran come under the umbrella term "Modern Fortran".
36+
These are the Fortran 95 standard,
37+
and more recent standards.[^fortran-standards]
38+
39+
::::::::::::::::::::::::::::::::::::: prereq
40+
41+
### Prerequisites
42+
43+
Learners _should_ be familiar with the basic concepts of
44+
programming: variables, logic, control flow, loops, functions and
45+
so on.
46+
No knowledge of Fortran is assumed.
47+
No previous experience with compiled languages is required.
48+
Access to the command line is required.
49+
Learners _must_ be comfortable using the command line[^command-line].
50+
51+
::::::::::::::::::::::::::::::::::::::::::::
52+
53+
This lesson has been tested primarily on Linux.
54+
Windows users may find it easier to install
55+
[Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install).
56+
With WSL you will have access to a Linux command line.
57+
Windows and macOS users should open an
58+
[Issue](https://github.com/carpentries-incubator/intro-to-modern-fortran/issues)
59+
if you find problems with the lesson material.
60+
61+
[^other-courses]: Discussion #3 on the lesson repository, https://github.com/carpentries-incubator/intro-to-modern-fortran/discussions/3, give details on the materials this course draws from.
62+
[^archer2]: ARCHER2, https://www.archer2.ac.uk/, is one of the UKs national supercomputing facilities.
63+
[^archer2-codes]: ARCHER2 code use article: https://www.archer2.ac.uk/news/2021/05/19/code-use.html
64+
[^fortran-standards]: Fortran standards page on the Fortran Wiki: https://fortranwiki.org/fortran/show/Standards
65+
[^command-line]: Learners should be comfortable with the Carpentries Unix Shell lesson material: https://swcarpentry.github.io/shell-novice/

instructor-notes.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: Instructor Notes
3+
---
4+
5+
## Learner Profiles
6+
7+
Before teaching a workshop consider who is attending and their needs. This section highlights audiences for this Fortran course. Instructors can use the profiles to decide which episodes to teach or place more emphasis on.
8+
9+
**_Tahani is a new research software engineer at the Met Office._** She has just joined the office after their degree and have experience in Python, Linux, and shell commands. She has limited experience with compiled languages. The weather and climate code she will be working on is written in Fortran. She thought Fortran was a dead language.
10+
11+
**_Ionas, a researcher joining the JULES (Joint UK Land Environment Simulator) partnership._** They will be adding new functionality to JULES in Fortran. They have extensive experience with C and C++ and have been told there are differences between Fortran and C/C++ that they should be aware of. They are keen to learn Fortran but must fit their learning inbetween teaching duties and other research commitments.
12+
13+
**_Malak is mathematics graduate student working on new timestepping methods._** Malaks previous work was mostly theoretical although he knows basic Python. Malak needs to use Fortran to prototype his new routines which will interface with other Fortran code. Malak has been told by his supervisor that he should set up his preferred text editor for Fortran development.
14+
15+
**_Joe has been employed by a tech company to update their Fortran code._** Joe has years of experience developing mainly C++ code for HPCs but has not used Fortran in a production environment. They have been asked to update legacy code to modern standards, including implementing some form of testing and using standard libraries. Joe is not sure if there is a standard code style that they can adopt.

introduction.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
title: 'Introduction'
3+
teaching: 10
4+
exercises: 10
5+
---
6+
7+
::::::::::::::::::::::::::::::::::::: questions
8+
9+
- What is Fortran?
10+
11+
::::::::::::::::::::::::::::::::::::::::::::::::
12+
13+
::::::::::::::::::::::::::::::::::::: objectives
14+
15+
- Understand some of Fortrans colourful history
16+
17+
::::::::::::::::::::::::::::::::::::::::::::::::
18+
19+
## Introduction
20+
A very simple program might be:
21+
22+
```fortran
23+
program example1
24+
25+
! An example program prints "Hello World" to the screen
26+
27+
print * , "Hello World"
28+
29+
end program example1
30+
```
31+
32+
Formally, a Fortran program consists of one or more lines made up of
33+
Fortran _statements_. Line breaks are significant (e.g., there are
34+
no semi-colons `;` required here).
35+
36+
Comments are introduced with an exclamation mark `!`, and may trail
37+
other statements.
38+
39+
The `program` statement is roughly doing the equivalent job of `main()`
40+
in C/C++. However, note there is not (and must not be) a return statement.
41+
42+
::::::::::::::::::::::::::::::::::::: challenge
43+
44+
## Compiling your first program
45+
46+
Check now you can compile and run the first example program `example1.f90`.
47+
48+
:::::::::::::::: solution
49+
50+
Using `ftn`:
51+
52+
```shell
53+
$ something something something
54+
```
55+
56+
:::::::::::::::::::::::::
57+
:::::::::::::::::::::::::::::::::::::::::::::::
58+
59+
### Formal description
60+
61+
```
62+
[ program [program-name] ]
63+
[ specification-part ]
64+
[ exectuable-part ]
65+
[ contains
66+
internal-subprogram-part ]
67+
end [program-name]
68+
```
69+
70+
Optional components are represented with square brackets `[...]`. It
71+
follows that the shortest standard-conforming program will be (see
72+
`example2.f90`):
73+
74+
```fortran
75+
end
76+
```
77+
78+
If the `program-name` is present, it must be at both the beginning and
79+
the end, and must be the same in both places.
80+
81+
We will return to the `contains` statement in the context of modules.
82+
83+
## `print` statement
84+
85+
In general
86+
87+
```fortran
88+
print format [ , output-item-list ]
89+
```
90+
91+
where the `format` is a format specifier (discussed later) and the
92+
`output-item-list` is a comma-separated list of values/variables
93+
to be printed to the standard output.
94+
95+
If the format is a `*` (a so-called free-format) the implementation
96+
is allowed to apply a default format for a given type of item.
97+
98+
99+
## Alternative
100+
101+
Consider the following program (available as `example3.f90`):
102+
103+
```fortran
104+
program example3
105+
106+
use iso_fortran_env, only : output_unit
107+
108+
write (output_unit, *) "Hello ", "world"
109+
110+
end program example3
111+
```
112+
113+
This example shows a more general way to provide some output. Here we are
114+
also going to employ the `use` statement to import a symbol from the
115+
(intrinsic) module `iso_fortran_env`. The symbol is `output_unit` which
116+
identifies the default standard output (cf. `stdout`).
117+
118+
119+
### `use` statement
120+
121+
Formally,
122+
123+
```fortran
124+
use [[ , module-nature] ::] module-name [ , only : [only-list]]
125+
```
126+
127+
If `module-nature` is present, it must be either `intrinsic` or
128+
`non_intrinsic`. The implementation must provide certain intrinsic
129+
modules such `iso_fortran_env`.
130+
131+
There is no formal namespace mechanism in Fortran (cf. C++), so
132+
restrictions on which symbols are visible can be made via an optional
133+
`only-list`. If there is no `only-list` then all the public symbols
134+
from `module-name` will be visible.
135+
136+
137+
### `write` statement
138+
139+
Formally,
140+
141+
```fortran
142+
write (io-control-spec-list) [output-item-list]
143+
```
144+
145+
where the `output-item-list` is a comma separated list of items to
146+
be output. The `io-control-spec-list` has a large number of potential
147+
arguments (again comma separated). For formatted output, these must
148+
include at least a unit number and a format:
149+
150+
```fortran
151+
write ([unit = ] io-unit, [fmt = ] format) [output-item-list]
152+
```
153+
154+
where the `io-unit` is a valid integer unit number, and the `format`
155+
is a format-specifier (as for `print`).
156+
157+
Examples are
158+
159+
```fortran
160+
write (unit = output_unit, fmt = *)
161+
write (output_unit, *)
162+
write (*, *)
163+
```
164+
165+
C programmers looking for a new-line like symbol will notice that none
166+
has appeared so far. The default situation is that both `print` and
167+
`write` generate a new-line automatically. The `*` symbol in the context
168+
of `io-unit` is a default output unit (usually the screen).
169+
170+
We will return to the `write` statement and format-specifiers in more
171+
detail in the context of i/o to external files.
172+
173+
## Some comments on style
174+
175+
Modern Fortran is not case sensitive. Older versions required capitals,
176+
a style which has persisted to the present day in some places. So you
177+
may see things such as
178+
179+
```fortran
180+
PROGRAM example1
181+
182+
PRINT *, "Hello World"
183+
184+
END PROGRAM example1
185+
```
186+
187+
As modern etiquette tends to regard capitals as shouting, this can cause
188+
some strain. In addition, as the compiler will accept mixed
189+
case, an additional tool would be required to enforce style (if
190+
enforcement was wanted).
191+
192+
This course therefore prefers an all lower-case style.
193+
194+
::::::::::::::::::::::::::::::::::::: challenge
195+
196+
## Writing your first program
197+
198+
Write a program which prints out the actual values of the symbols
199+
`output_unit`, `error_unit`, and `input_unit`
200+
(all from `iso_fortran_env`) to the screen.
201+
202+
If you haven't used the `only` clause in your `use iso_fortran_env`,
203+
add it now. What happens to the results if you miss out one of the
204+
symbols referenced from the `only` clause? This behaviour will be
205+
explained in the following section.
206+
207+
:::::::::::::::: solution
208+
209+
A version of this program is available as `exercise1.f90`.
210+
211+
:::::::::::::::::::::::::
212+
:::::::::::::::::::::::::::::::::::::::::::::::
213+
214+
::::::::::::::::::::::::::::::::::::: keypoints
215+
216+
- A Fortran program is made up of one or more _statements_ which are separated by line breaks
217+
- Comments are declared with an `!` and may trail other statements
218+
219+
::::::::::::::::::::::::::::::::::::::::::::::::
220+

0 commit comments

Comments
 (0)