-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0350db9
Showing
10 changed files
with
494 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: "Contributor Code of Conduct" | ||
--- | ||
|
||
As contributors and maintainers of this project, | ||
we pledge to follow the [The Carpentries Code of Conduct][coc]. | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior | ||
may be reported by following our [reporting guidelines][coc-reporting]. | ||
|
||
|
||
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html | ||
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
title: "Licenses" | ||
--- | ||
|
||
## Instructional Material | ||
|
||
All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry) | ||
instructional material is made available under the [Creative Commons | ||
Attribution license][cc-by-human]. The following is a human-readable summary of | ||
(and not a substitute for) the [full legal text of the CC BY 4.0 | ||
license][cc-by-legal]. | ||
|
||
You are free: | ||
|
||
- to **Share**---copy and redistribute the material in any medium or format | ||
- to **Adapt**---remix, transform, and build upon the material | ||
|
||
for any purpose, even commercially. | ||
|
||
The licensor cannot revoke these freedoms as long as you follow the license | ||
terms. | ||
|
||
Under the following terms: | ||
|
||
- **Attribution**---You must give appropriate credit (mentioning that your work | ||
is derived from work that is Copyright (c) The Carpentries and, where | ||
practical, linking to <https://carpentries.org/>), provide a [link to the | ||
license][cc-by-human], and indicate if changes were made. You may do so in | ||
any reasonable manner, but not in any way that suggests the licensor endorses | ||
you or your use. | ||
|
||
- **No additional restrictions**---You may not apply legal terms or | ||
technological measures that legally restrict others from doing anything the | ||
license permits. With the understanding that: | ||
|
||
Notices: | ||
|
||
* You do not have to comply with the license for elements of the material in | ||
the public domain or where your use is permitted by an applicable exception | ||
or limitation. | ||
* No warranties are given. The license may not give you all of the permissions | ||
necessary for your intended use. For example, other rights such as publicity, | ||
privacy, or moral rights may limit how you use the material. | ||
|
||
## Software | ||
|
||
Except where otherwise noted, the example programs and other software provided | ||
by The Carpentries are made available under the [OSI][osi]-approved [MIT | ||
license][mit-license]. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
## Trademark | ||
|
||
"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library | ||
Carpentry" and their respective logos are registered trademarks of [Community | ||
Initiatives][ci]. | ||
|
||
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/ | ||
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode | ||
[mit-license]: https://opensource.org/licenses/mit-license.html | ||
[ci]: https://communityin.org/ | ||
[osi]: https://opensource.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
site: sandpaper::sandpaper_site | ||
--- | ||
|
||
This is a new lesson built with [The Carpentries Workbench][workbench]. It is currently in pre-alpha development by the [Edinburgh Parallel Computing Centre][epcc-link], the [National Centre for Atmospheric Science][ncas-link], the [National Oceanography Centre][noc-link], and the [UK Met Office][uk-met-link]. | ||
|
||
This course is aimed at users and developers who know how to program, | ||
but have little or no experience in Fortran, and those who may wish to | ||
have a refresher in Fortran. | ||
|
||
::::::::::::::::::::::::::::::::::::: prereq | ||
|
||
### Prerequisites | ||
|
||
Learners *must* be familiar with the basic concepts of | ||
programming: variables, logic, flow of control, loops, functions and | ||
so on. No knowledge of Fortran is assumed. Previous programming | ||
experience might typically be in the context C/C++ or python. | ||
If you know no programming, we suggest this course on Fortran is not | ||
the place to start. | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
Fortran (a contraction of Formula Translation) was the first programming | ||
language to have a standard (in 1954), but has changed significantly over | ||
the years. More recent standards (the latest being Fortran 2018) come | ||
under the umbrella term "Modern Fortran". Fortran retains very great | ||
significance in many areas of scientific and numerical computing, | ||
particularly for applications such as quantum chemistry, plasmas, and in | ||
numerical weather prediction and climate models. | ||
|
||
This course provides an introduction to the basics of writing Fortran. | ||
It will cover basic syntax, variables, expressions and assignments, | ||
flow of control, and introductions to i/o and user-defined types. | ||
Common Fortran idioms are introduced and contrasted with those | ||
available in C-like languages; the course will try to focus on | ||
real usage rather than formal descriptions. | ||
|
||
At the end of the course you should be able to understand many Fortran | ||
programs and be confident to start to write well-structured and portable | ||
Fortran. Fortran is a rather "large" language, so it is not possible to | ||
cover all its features in a two day course. Further elements of Fortran | ||
are discussed in the "Intermediate Modern Fortran" course. | ||
|
||
The course requires a Fortran compiler, for which a local machine or | ||
laptop may be appropriate [1]. If you do not have access to a Fortran | ||
compiler, course training accounts on archer2 will be available which | ||
provide access to various compilers. Use of a text editor will be | ||
required (some may prefer an IDE, but we do not intend to consider or | ||
support IDEs). | ||
|
||
[1] This may typically be GFortran, freely available as part of | ||
Gnu Compiler Collection (GCC). | ||
See e.g., [Link to GFortran install page on fortran-lang][install-gfortran] | ||
|
||
|
||
[workbench]: https://carpentries.github.io/sandpaper-docs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Instructor Notes | ||
--- | ||
|
||
This is a placeholder file. Please add content here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
--- | ||
title: 'Introduction' | ||
teaching: 10 | ||
exercises: 10 | ||
--- | ||
|
||
::::::::::::::::::::::::::::::::::::: questions | ||
|
||
- What is Fortran? | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: objectives | ||
|
||
- Understand some of Fortrans colourful history | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
## Introduction | ||
A very simple program might be: | ||
|
||
```fortran | ||
program example1 | ||
! An example program prints "Hello World" to the screen | ||
print * , "Hello World" | ||
end program example1 | ||
``` | ||
|
||
Formally, a Fortran program consists of one or more lines made up of | ||
Fortran _statements_. Line breaks are significant (e.g., there are | ||
no semi-colons `;` required here). | ||
|
||
Comments are introduced with an exclamation mark `!`, and may trail | ||
other statements. | ||
|
||
The `program` statement is roughly doing the equivalent job of `main()` | ||
in C/C++. However, note there is not (and must not be) a return statement. | ||
|
||
::::::::::::::::::::::::::::::::::::: challenge | ||
|
||
## Compiling your first program | ||
|
||
Check now you can compile and run the first example program `example1.f90`. | ||
|
||
:::::::::::::::: solution | ||
|
||
Using `ftn`: | ||
|
||
```shell | ||
$ something something something | ||
``` | ||
|
||
::::::::::::::::::::::::: | ||
::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
### Formal description | ||
|
||
``` | ||
[ program [program-name] ] | ||
[ specification-part ] | ||
[ exectuable-part ] | ||
[ contains | ||
internal-subprogram-part ] | ||
end [program-name] | ||
``` | ||
|
||
Optional components are represented with square brackets `[...]`. It | ||
follows that the shortest standard-conforming program will be (see | ||
`example2.f90`): | ||
|
||
```fortran | ||
end | ||
``` | ||
|
||
If the `program-name` is present, it must be at both the beginning and | ||
the end, and must be the same in both places. | ||
|
||
We will return to the `contains` statement in the context of modules. | ||
|
||
## `print` statement | ||
|
||
In general | ||
|
||
```fortran | ||
print format [ , output-item-list ] | ||
``` | ||
|
||
where the `format` is a format specifier (discussed later) and the | ||
`output-item-list` is a comma-separated list of values/variables | ||
to be printed to the standard output. | ||
|
||
If the format is a `*` (a so-called free-format) the implementation | ||
is allowed to apply a default format for a given type of item. | ||
|
||
|
||
## Alternative | ||
|
||
Consider the following program (available as `example3.f90`): | ||
|
||
```fortran | ||
program example3 | ||
use iso_fortran_env, only : output_unit | ||
write (output_unit, *) "Hello ", "world" | ||
end program example3 | ||
``` | ||
|
||
This example shows a more general way to provide some output. Here we are | ||
also going to employ the `use` statement to import a symbol from the | ||
(intrinsic) module `iso_fortran_env`. The symbol is `output_unit` which | ||
identifies the default standard output (cf. `stdout`). | ||
|
||
|
||
### `use` statement | ||
|
||
Formally, | ||
|
||
```fortran | ||
use [[ , module-nature] ::] module-name [ , only : [only-list]] | ||
``` | ||
|
||
If `module-nature` is present, it must be either `intrinsic` or | ||
`non_intrinsic`. The implementation must provide certain intrinsic | ||
modules such `iso_fortran_env`. | ||
|
||
There is no formal namespace mechanism in Fortran (cf. C++), so | ||
restrictions on which symbols are visible can be made via an optional | ||
`only-list`. If there is no `only-list` then all the public symbols | ||
from `module-name` will be visible. | ||
|
||
|
||
### `write` statement | ||
|
||
Formally, | ||
|
||
```fortran | ||
write (io-control-spec-list) [output-item-list] | ||
``` | ||
|
||
where the `output-item-list` is a comma separated list of items to | ||
be output. The `io-control-spec-list` has a large number of potential | ||
arguments (again comma separated). For formatted output, these must | ||
include at least a unit number and a format: | ||
|
||
```fortran | ||
write ([unit = ] io-unit, [fmt = ] format) [output-item-list] | ||
``` | ||
|
||
where the `io-unit` is a valid integer unit number, and the `format` | ||
is a format-specifier (as for `print`). | ||
|
||
Examples are | ||
|
||
```fortran | ||
write (unit = output_unit, fmt = *) | ||
write (output_unit, *) | ||
write (*, *) | ||
``` | ||
|
||
C programmers looking for a new-line like symbol will notice that none | ||
has appeared so far. The default situation is that both `print` and | ||
`write` generate a new-line automatically. The `*` symbol in the context | ||
of `io-unit` is a default output unit (usually the screen). | ||
|
||
We will return to the `write` statement and format-specifiers in more | ||
detail in the context of i/o to external files. | ||
|
||
## Some comments on style | ||
|
||
Modern Fortran is not case sensitive. Older versions required capitals, | ||
a style which has persisted to the present day in some places. So you | ||
may see things such as | ||
|
||
```fortran | ||
PROGRAM example1 | ||
PRINT *, "Hello World" | ||
END PROGRAM example1 | ||
``` | ||
|
||
As modern etiquette tends to regard capitals as shouting, this can cause | ||
some strain. In addition, as the compiler will accept mixed | ||
case, an additional tool would be required to enforce style (if | ||
enforcement was wanted). | ||
|
||
This course therefore prefers an all lower-case style. | ||
|
||
::::::::::::::::::::::::::::::::::::: challenge | ||
|
||
## Writing your first program | ||
|
||
Write a program which prints out the actual values of the symbols | ||
`output_unit`, `error_unit`, and `input_unit` | ||
(all from `iso_fortran_env`) to the screen. | ||
|
||
If you haven't used the `only` clause in your `use iso_fortran_env`, | ||
add it now. What happens to the results if you miss out one of the | ||
symbols referenced from the `only` clause? This behaviour will be | ||
explained in the following section. | ||
|
||
:::::::::::::::: solution | ||
|
||
A version of this program is available as `exercise1.f90`. | ||
|
||
::::::::::::::::::::::::: | ||
::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: keypoints | ||
|
||
- A Fortran program is made up of one or more _statements_ which are separated by line breaks | ||
- Comments are declared with an `!` and may trail other statements | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: FIXME | ||
--- | ||
|
||
This is a placeholder file. Please add content here. |
Oops, something went wrong.