Skip to content

Commit 04303e3

Browse files
committed
differences for PR #29
1 parent 5450e3e commit 04303e3

File tree

9 files changed

+1247
-224
lines changed

9 files changed

+1247
-224
lines changed

02-variables.md

Lines changed: 482 additions & 0 deletions
Large diffs are not rendered by default.

03-maths.md

Lines changed: 608 additions & 0 deletions
Large diffs are not rendered by default.

04-logic.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: 'Logic'
3+
teaching: 15
4+
exercises: 15
5+
---
6+
7+
::::::::::::::::::::::::::::::::::::: questions
8+
9+
- How do we declare and assign values to variables?
10+
11+
::::::::::::::::::::::::::::::::::::::::::::::::
12+
13+
::::::::::::::::::::::::::::::::::::: objectives
14+
15+
- Understand the different intrinsic data types.
16+
- Declare and assign variables and parameters.
17+
18+
::::::::::::::::::::::::::::::::::::::::::::::::
19+
20+
Fortran's `logical` type has two values:
21+
22+
```fortran
23+
logical :: is_below_20_metres = .false.
24+
logical :: use_stochastic_physics = .true.
25+
```
26+
27+
### Logical operators
28+
29+
Values can be tested logical operators `.or.`, `.and.` and `.not.` are available, and
30+
these can be used to set the value of logical variables.
31+
32+
The precedence is illustrated by, e.g.,
33+
```fortran
34+
q = i .or. j .and. .not. k ! evaluated as i .or. (j .and. (.not. k))
35+
```
36+
where q, i, j, and k are all logical variables.
37+
38+
Use brackets to avoid confusion over operator precedence.
39+
40+
### Relational operators
41+
42+
To form logical expressions from numeric or other expressions, we require
43+
relational operators. The are two forms in Fortran, illustrated in the table
44+
below. It is recommended that you avoid the older form.
45+
46+
| Relation | Operator | Older form | For |
47+
|--------------------------|----------|------------|------------------|
48+
| Less than | `< ` | `.lt.` | `integer` `real` |
49+
| Less than or equal to | `<=` | `.le.` | `integer` `real` |
50+
| Greater than | `> ` | `.gt.` | `integer` `real` |
51+
| Greater than or equal to | `>=` | `.ge.` | `integer` `real` |
52+
| Equal to | `==` | `.eq.` | `integer` `real` `complex`|
53+
| Not equal to | `/=` | `.neq.` | `integer` `real` `complex`|
54+
55+
### Logical equivalence
56+
57+
Equivalence between two logical expressions or variables is established
58+
via the logical operators `.eqv.` and `.neqv.`.
59+
60+
While some some compilers may allow the use of `==`, this should be avoided.
61+
62+
### Using logical operators
63+
64+
These operators can be used to check and set the values of logical variables, dependent on other variables, e.g.
65+
```fortran
66+
program example4
67+
implicit none
68+
69+
real, parameter :: pi = 3.14159265
70+
logical, parameter :: switch1 = .true.
71+
72+
real :: a=3.0
73+
logical :: test1, test2, test3
74+
75+
test1 = a >= pi ! True if a is greater than or equal to pi
76+
77+
test2 = (.not. test1) ! True if test1 is False, False if test1 is True
78+
79+
test3 = (test2 .eqv. switch1) ! True if test2 is True, False if test2 is False
80+
81+
print *, test1
82+
83+
print *, test2
84+
85+
print *, test3
86+
87+
end program example4
88+
```
89+
Compiling and running this code will give the following output
90+
```
91+
$ ./a.out
92+
F
93+
T
94+
T
95+
```
96+
97+
:::::::::::::::::::::::::::::::::::::::: keypoints
98+
99+
- Th
100+
101+
::::::::::::::::::::::::::::::::::::::::::::::::::

05-strings.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: 'Strings'
3+
teaching: 15
4+
exercises: 15
5+
---
6+
7+
::::::::::::::::::::::::::::::::::::: questions
8+
9+
- How do we declare and assign values to variables?
10+
11+
::::::::::::::::::::::::::::::::::::::::::::::::
12+
13+
::::::::::::::::::::::::::::::::::::: objectives
14+
15+
- Understand the different intrinsic data types.
16+
- Declare and assign variables and parameters.
17+
18+
::::::::::::::::::::::::::::::::::::::::::::::::
19+
20+
Variables store information we can use in our
21+
22+
:::::::::::::::::::::::::::::::::::::::: keypoints
23+
24+
- Th
25+
26+
::::::::::::::::::::::::::::::::::::::::::::::::::

config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ contact: 'd.theodorakis@metoffice.gov.uk'
6060

6161
# Order of episodes in your lesson
6262
episodes:
63-
- introduction.Rmd
63+
- 02-variables.md
64+
- 03-maths.md
65+
- 04-logic.md
66+
- 05-strings.md
6467

6568
# Information for Learners
6669
learners:
@@ -78,4 +81,3 @@ profiles:
7881
sandpaper: astroDimitrios/sandpaper
7982
pegboard: astroDimitrios/pegboard
8083
varnish: astroDimitrios/varnish
81-

data/exercises.tar.gz

5.33 KB
Binary file not shown.

discuss.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Discussion
3+
---
4+
5+
## Frequently Asked Questions
6+
7+
People often have questions about Fortran beyond the scope of the core material.
8+
Students who have completed episodes early
9+
might find value in looking through the following topics.
10+
11+
Note that since this material isn't essential for most Fortran usage,
12+
it won't be covered by the instructor.
13+
14+
## Floating point precision
15+
16+
There is a great article
17+
[Examples of floating point problems](https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/)
18+
by Julia Evans.
19+
The article outlines what floating points numbers are
20+
and common problems with precision.

introduction.md

Lines changed: 0 additions & 220 deletions
This file was deleted.

0 commit comments

Comments
 (0)