Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
11c9482
English - Derived types
zmoon May 8, 2021
b487a25
Mostly code style - Derived types
zmoon May 8, 2021
20722d3
Bit more code style - Derived types
zmoon May 8, 2021
ee094f7
English & code style - Arrays and strings
zmoon May 8, 2021
865996d
English - Ops. & control flow
zmoon May 8, 2021
b310970
Code style - Ops. & control flow
zmoon May 8, 2021
4666adc
English - Organizing code
zmoon May 8, 2021
090adb8
`.f90` in code style
zmoon May 8, 2021
13abfd7
Code - Organizing code
zmoon May 8, 2021
ed75112
`kind`s (mostly)
zmoon May 8, 2021
ba1654b
`pi` in Variables
zmoon May 8, 2021
33817e0
Clean up whitespace in some code examples
zmoon May 9, 2021
e79287f
More code block whitespace cleanup
zmoon May 9, 2021
b003ce2
More English
zmoon May 10, 2021
abd8122
Start tutorial style guidelines
zmoon May 10, 2021
56b407a
Update CONTRIBUTING.md
zmoon May 10, 2021
925e275
edits
zmoon May 10, 2021
74c895f
Mainly indentation
zmoon May 15, 2021
da79de1
Merge branch 'master' into quickstart
zmoon May 29, 2021
c2bcd1f
Fix regressions
zmoon May 29, 2021
a4adc21
Add some comma examples
zmoon May 29, 2021
0bb267d
Some enforcing of code style guidelines
zmoon May 29, 2021
9efdc33
More edits
zmoon May 30, 2021
e192e45
fix a comma example
zmoon May 30, 2021
2b1a93c
Update learn/quickstart/operators_control_flow.md
zmoon May 30, 2021
d1269e9
Update `do concurrent` note
zmoon Jun 3, 2021
b059eb7
Remove gfortran flag info; use `capture`
zmoon Jun 10, 2021
1746fe6
Add some missing colons for examples
zmoon Jun 10, 2021
459ca2e
Revert bumped version in Gemfile.lock
awvwgk Jun 17, 2021
e544b2e
Mention Oxford comma in mini-book text style
zmoon Jun 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 123 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ This will force the GitHub content delivery network to serve you an updated vers

### Markdown

- Use [code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting),
denoted by back ticks (```), to surround code excerpts, programming language keywords, variables names and file names.
- Place code excerpts in [code blocks](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting),
denoted by back ticks (```` ``` ````). Use inline code style (`` `code` ``) for inline code excerpts, programming language keywords, variables names and file names.

- Have no more than one sentence per source-code line, and break-up long sentences across multiples lines -
this is important to avoid large git diffs and code review blocks on github.
Expand Down Expand Up @@ -185,3 +185,124 @@ populated by the `<h2>` headings on the current page.
__Implementation:__
the functionality described above is implemented in the javascript file
[assets/js/page_nav.js](./assets/js/page_nav.js).


## Tutorials

Guidelines for mini-book content.

### General

Use the `book` layout.

Follow the [Markdown guidelines](#markdown).

### Code style

Use two spaces for indentation, indenting bodies of units but keeping the `contains` statement at the same level as its `module` or `type`. Try to limit line length to 90 characters. These considerations should make the code more readable and easier to view on devices with smaller viewport widths.
```fortran
module m
implicit none
private
public :: a_t

type :: a_t
integer :: val
contains
procedure :: func
end type a_t

contains

subroutine func(self)
class(a_t), intent(in) :: self
if (self%val > 0) then
print *, self%val
end if
end function func

end module m
```

Each code block should have a base indentation level of 0, even if it would be indented if put into a larger context.
```fortran
integer :: i1 ! yes
integer :: i2 ! no
```

Avoid vertically aligning `::` and inline comments since this adds maintenance burden and pushes the line length in most cases.

If a code block contains lines that are not valid Fortran, leave it as a language-less code block to avoid the syntax highlighter's red boxes.
```
module <module name>
...
end module <module name>
```

Feel free to omit spacing in expressions where it helps with readability, but generally include whitespace around operators.
```fortran
y1 = a * b
y2 = a*b + c*d ! instead of a * b + c * d
y3 = a**2 + 1
y4 = (a*b + c*d) / 2
s3 = s1 // s2
```

Generally add a space after commas, except when indexing with short index values or variables names.
```fortran
a(:,1)
a2(1:10, 2:5)
b(i,j)
b2(long_i_name, long_j_name)
b3(i + 2, j)
call some_subroutine(a, b, an_option=.false.)
c = [1, 2, 3, 10]
d = [(i, i = 1, 10)]
do i = 1, 10
! ...
```

Other situations besides simple indexings where white space can be omitted:
* Aliasing in imports
```fortran
use, intrinsic :: iso_c_binding, only: sp=>c_float, dp=>c_double
```
* String concatentation
```fortran
print *, 'hello '//'world'
```
* Accessing components (attributes) of derived types
```fortran
p%x
p%calc_something(a, b)
```
* Around `=` when passing keyword arguments
```fortran
call sr(a, b, c=3)
point = t_point(x=1., y=2.)
character(len=:), allocatable :: s
```

Capitalize the first letter for inline comments except for trailing inline comments that only consist of one word or a short phrase.
```fortran
! Compute new values
y = m*x + b ! meters
```

These code style recommendations are similar to those in [the DFTB+ style guide](https://dftbplus-develguide.readthedocs.io/en/latest/fortranstyle.html).

### Text

Use sentence case (as opposed to title case) for page and section titles.

Use *emphasis* (`*emphasis*`/`_emphasis_`, rendered as italic) for key words/phrases when they are first introduced, for emphasis, ...

Avoid use of **strong** (`**strong**`, rendered as bold) within paragraphs, since bold style is used for headings, drawing attention to examples (**Example:**), admonition/aside titles, etc.

Make use of the admonition/aside [includes](_includes) (*note*, *tip*, *important*) where appropriate.
* *note*: extra information, something that might appear in a footnote
* *tip*: information about best practices, practical tips
* *important*: warnings, things to avoid, etc.

Prefer including the [Oxford comma](https://en.wikipedia.org/wiki/Serial_comma). It usually makes things more clear.
> Fortran is fast, fun, and famed.
9 changes: 7 additions & 2 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ blockquote small:before {
}

pre {
overflow: auto;
overflow-x: scroll;
overflow-y: auto;
padding: 0.8rem;
border-radius: 0.2rem;
border: solid 1px rgba(0, 0, 0, 0.1);
background-color: rgba(0, 0, 0, 0.05);
white-space: pre-wrap;
}

pre code {
white-space: pre; /* `pre-wrap` in Bootstrap */
}

.container {
margin: 0 15px;
}
Expand Down Expand Up @@ -301,7 +306,7 @@ pre {
@media (min-width: 568px) {
.col-right {
/* display: table-cell; */
width: 61.8%;
width: calc(100% - 380px);
vertical-align: top;
margin-left: 380px;
min-height: 500px;
Expand Down
40 changes: 20 additions & 20 deletions learn/quickstart/arrays_strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ permalink: /learn/quickstart/arrays_strings
More often than not, we need to store and operate on long lists of numbers as opposed to just the single scalar variables
that we have been using so far; in computer programming such lists are called _arrays_.

Arrays are _multidimensional_ variables which contain more than value
where each value is accessed using one or indices.
Arrays are _multidimensional_ variables that contain more than one value
where each value is accessed using one or more indices.

{% include important.html content="Arrays in Fortran are __one-based__ by default; this means
{% include important.html content="Arrays in Fortran are _one-based_ by default; this means
that the first element along any dimension is at index 1." %}


## Array declaration

We can declare arrays of any type. There are two common notations for declaring array variables;
We can declare arrays of any type. There are two common notations for declaring array variables:
using the `dimension` attribute or by appending the array dimensions in parentheses to the variable name.

__Example:__ static array declaration
Expand All @@ -33,7 +33,7 @@ program arrays
integer :: array2(10)

! 2D real array
real, dimension(10,10) :: array3
real, dimension(10, 10) :: array3

! Custom lower and upper index bounds
real :: array4(0:9)
Expand All @@ -53,32 +53,32 @@ program array_slice
implicit none

integer :: i
integer :: array1(10) ! 1D integer array of 10 elements
integer :: array2(10,10) ! 2D integer array of 100 elements
integer :: array1(10) ! 1D integer array of 10 elements
integer :: array2(10, 10) ! 2D integer array of 100 elements

array1 = [1,2,3,4,5,6,7,8,9,10] ! Array constructor
array1 = [(i,i=1,10)] ! Implied do loop constructor
array1(:) = 0 ! set all elements to zero
array1(1:5) = 1 ! set first five elements to one
array1(6:) = 1 ! set all elements after five to one
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ! Array constructor
array1 = [(i, i = 1, 10)] ! Implied do loop constructor
array1(:) = 0 ! Set all elements to zero
array1(1:5) = 1 ! Set first five elements to one
array1(6:) = 1 ! Set all elements after five to one

print *,array1(1:10:2) ! print out elements at odd indices
print *,array2(:,1) ! print out the first column in a 2D array
print *,array1(10:1:-1) ! print an array in reverse
print *, array1(1:10:2) ! Print out elements at odd indices
print *, array2(:,1) ! Print out the first column in a 2D array
print *, array1(10:1:-1) ! Print an array in reverse

end program array_slice
```

{% include note.html content="Fortran arrays are stored in __column major__ order; the first
{% include note.html content="Fortran arrays are stored in _column-major_ order; the first
index varies fastest." %}

## Allocatable (dynamic) arrays

So far we have specified the size of our array in our program code -
this type of array is known as a _static_ array since its size is fixed when
So far we have specified the size of our array in our program code---this
type of array is known as a _static_ array since its size is fixed when
we compile our program.

Quite often, we do not know how big our array needs to be until we run our program, for example if we are reading data from a file of unknown size.
Quite often, we do not know how big our array needs to be until we run our program, for example, if we are reading data from a file of unknown size.

For this problem, we need `allocatable` arrays.
These are _allocated_ while the program is runnning once we know how big the array needs to be.
Expand All @@ -94,7 +94,7 @@ program allocatable
allocate(array1(10))
allocate(array2(10,10))

...
! ...

deallocate(array1)
deallocate(array2)
Expand Down
Loading