Skip to content

Commit 1a9f2fc

Browse files
LXYan2333perazz
andauthored
fix highlight issue (#495)
Co-authored-by: Federico Perini <[email protected]>
1 parent 0679907 commit 1a9f2fc

File tree

10 files changed

+41
-39
lines changed

10 files changed

+41
-39
lines changed

source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,5 @@
213213
post_auto_excerpt = 2
214214

215215
gettext_compact = "index"
216+
217+
copybutton_exclude = '.linenos, .gp, .go'

source/learn/building_programs/compiling_source.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ the GNU compiler collection. To compile a simple program like the one
2828
above, that consists of one source file, you run the following command,
2929
assuming the source code is stored in the file "hello.f90":
3030

31-
```shell
31+
```console
3232
$ gfortran -c hello.f90
3333
```
3434

@@ -40,7 +40,7 @@ leave it out, then the default action of the compiler is to compile the
4040
source file and start the linker to build the actual executable program.
4141
The command:
4242

43-
```shell
43+
```console
4444
$ gfortran hello.f90
4545
```
4646

@@ -55,7 +55,7 @@ Some remarks:
5555
not get an object file or an executable program. For instance, if
5656
the word "program" was inadvertently typed as "prgoram":
5757

58-
```shell
58+
```console
5959
$ gfortran hello3.f90
6060
hello.f90:1:0:
6161

@@ -78,7 +78,7 @@ again.
7878
Otherwise the link step will complain about a missing "symbol", something
7979
along these lines:
8080

81-
```shell
81+
```console
8282
$ gfortran hello2.f90
8383
/usr/lib/../lib64/crt1.o: In function `_start':
8484
(.text+0x20): undefined reference to `main'

source/learn/building_programs/distributing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ end module user_functions
7575

7676
- Provide a basic build script with a command like:
7777

78-
```shell
78+
```console
7979
gfortran -o functions.dll functions.f90 -shared
8080
```
8181

8282
or:
8383

84-
```shell
84+
```console
8585
ifort -exe:functions.dll functions.f90 -dll
8686
```
8787

source/learn/building_programs/include_files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ tabulate/
3535

3636
Compiling the file "functions.f90" with the commands
3737

38-
```shell
38+
```console
3939
$ cd sub
4040
$ gfortran -c functions.f90
4141
```
@@ -55,7 +55,7 @@ tabulate/
5555
To successfully compile and subsequently build the program we need to
5656
tell the compiler where it can find the file "user_functions.mod":
5757

58-
```shell
58+
```console
5959
$ cd main
6060
$ gfortran -c tabulate.f90 -I ../sub
6161
$ gfortran -o tabulate tabulate.o ../sub/functions.o

source/learn/building_programs/linking_pieces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ program. Because the program "tabulate" depends on the module
5555
"function", we need to compile the source file containing our module
5656
first. A sequence of commands to do this is:
5757

58-
```shell
58+
```console
5959
$ gfortran -c functions.f90
6060
$ gfortran tabulate.f90 functions.o
6161
```

source/learn/building_programs/managing_libraries.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ create your own libraries.
99
Libraries contain any number of object files in a compact form, so that
1010
the command-line becomes far shorter:
1111

12-
```shell
12+
```console
1313
$ gfortran -o tabulate tabulate.f90 functions.o supportlib.a
1414
```
1515

@@ -20,7 +20,7 @@ Linux and Linux-like platforms. On Windows the extension ".lib" is used.
2020
Creating your own libraries is not that complicated:
2121
on Linux, you can achieve this using a utility like `ar`:
2222

23-
```shell
23+
```console
2424
$ gfortran -c file1.f90 file2.f90
2525
$ gfortran -c file3.f90 ...
2626
$ ar r supportlib.a file1.o file2.o
@@ -29,7 +29,7 @@ $ ar r supportlib.a file3.o ...
2929

3030
or on Windows using the `lib` utility:
3131

32-
```shell
32+
```console
3333
c:\...> ifort -c file1.f90 file2.f90
3434
c:\...> ifort -c file3.f90 ...
3535
c:\...> lib /out:supportlib.lib file1.obj file2.obj
@@ -75,15 +75,15 @@ like `ar` or `lib`.
7575

7676
On Linux:
7777

78-
```shell
78+
```console
7979
$ gfortran -fpic -c file1.f90 file2.f90
8080
$ gfortran -fpic -c file3.f90 ...
8181
$ gfortran -shared -o supportlib.so file1.o file2.o file3.o ...
8282
```
8383

8484
On Windows, with the Intel Fortran compiler:
8585

86-
```shell
86+
```console
8787
$ ifort -c file1.f90 file2.f90
8888
$ ifort -c file3.f90 ...
8989
$ ifort -dll -exe:supportlib.dll file1.obj file2.obj file3.obj ...
@@ -136,14 +136,14 @@ Also, no import library is generated.
136136
Since our dynamic library can be built from a single source file, we
137137
can take a shortcut:
138138

139-
```shell
139+
```console
140140
$ gfortran -shared -o functions.dll functions.f90
141141
```
142142

143143
This produces the files "functions.dll" and "user_functions.mod". The
144144
utility `nm` tells us the exact name of the function `f`:
145145

146-
```shell
146+
```console
147147
$ nm functions.dll
148148
...
149149
000000054f9d7000 B __dynamically_loaded
@@ -160,7 +160,7 @@ other routine "f" that might be defined in another module.
160160

161161
The next step is to build the program:
162162

163-
```shell
163+
```console
164164
$ gfortran -o tabulate tabulate.f90 functions.dll
165165
```
166166

@@ -189,7 +189,7 @@ real function f( x )
189189

190190
Again we take a shortcut:
191191

192-
```shell
192+
```console
193193
$ ifort -exe:functions.dll functions.f90 -dll
194194
```
195195

source/learn/building_programs/runtime_libraries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ To illustrate that even a simple program depends on external run-time
44
libraries, here is the output from the `ldd` utility that reports such
55
dependencies:
66

7-
```shell
7+
```console
88
$ ldd tabulate.exe
99
ntdll.dll => /cygdrive/c/WINDOWS/SYSTEM32/ntdll.dll (0x7ff88f2b0000)
1010
KERNEL32.DLL => /cygdrive/c/WINDOWS/System32/KERNEL32.DLL (0x7ff88e450000)

source/learn/quickstart/gotchas.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All code snippets are compiled with gfortran 13.
88
Implicit typing
99
---------------
1010

11-
```
11+
```{play-code-block} fortran
1212
program foo
1313
integer :: nbofchildrenperwoman, nbofchildren, nbofwomen
1414
nbofwomen = 10
@@ -25,7 +25,7 @@ Wait... Fortran is unable to multiply two integer numbers?? Of course not... The
2525

2626
Implicit typing is as old as Fortran, in times where there was no explicit typing. Although it can still be convenient for quickly writing some test code, this practice is highly error prone and is discouraged. The strongly recommended good practice is to always disable implicit typing by stating `implicit none` (introduced in Fortran 90) at the beginning of all program units (main program, modules, and standalone routines):
2727

28-
```
28+
```{play-code-block} fortran
2929
program foo
3030
implicit none
3131
integer :: nbofchildrenperwoman, nbofchildren, nbofwomen
@@ -45,7 +45,7 @@ Error: Symbol 'nbofchildrem' at (1) has no IMPLICIT type; did you mean 'nbofchil
4545
Implied save
4646
------------
4747

48-
```
48+
```{play-code-block} fortran
4949
subroutine foo()
5050
implicit none
5151
integer :: c=0
@@ -64,7 +64,7 @@ implicit none
6464
end program
6565
```
6666
People used to C/C++ expect this program to print 5 times `1`, because they interpret `integer :: c=0` as the concatenation of a declaration and an assignment, as if it was:
67-
```
67+
```fortran
6868
integer :: c
6969
c = 0
7070
```
@@ -77,19 +77,19 @@ c = 0
7777
5
7878
```
7979
`integer :: c=0` is actually a one-shot **compile time initialization**, and it makes the variable persistent between calls to `foo()`. It is actually equivalent to:
80-
```
80+
```fortran
8181
integer, save :: c=0 ! "save" can be omitted, but it's clearer with it
8282
```
8383
The `save` attribute is equivalent to the C `static` attribute used inside a function to make a variable persistent, and it is *implied* in the case the variable is initialized. This is a modernized syntax (introduced in Fortran 90) compared to the legacy (and still valid) syntax:
84-
```
84+
```fortran
8585
integer c
8686
data c /0/
8787
save c
8888
```
8989
Old fortraners just know that the modernized syntax is equivalent to the legacy one, even when `save` is not specified. But as a matter of fact the *implied save* can be misleading to newcomers who are used to the C logic. That's why it is generally recommended to **always** specify the `save` attribute.
9090

9191
*Note: an initialization expression of a derived type component is a fully different case:*
92-
```
92+
```fortran
9393
type bar
9494
integer :: c = 0
9595
end type
@@ -101,7 +101,7 @@ Floating point literal constants
101101
---------------------------------
102102

103103
The following code snippet defines a double precision constant `x` (which is on most systems a IEEE754 64 bits floating point, with 15 significant digits):
104-
```
104+
```{play-code-block} fortran
105105
program foo
106106
implicit none
107107
integer, parameter :: dp = kind(0d0)
@@ -116,7 +116,7 @@ The output is:
116116
So, `x` has 15 significant digits as expected, and still the printed value is wrong from the 8th digit. The reason is that floating point literal constants have implicitely the default real kind, wich is usually the IEEE754 single precision floating point (with about 7 significant digits). The real number $9.3$ has no exact floating point representation, so it is first approximated to single precision up to the 7th digit, then casted to double precision before being assigned to `x`. But the previously lost digits are obviously not recovered.
117117

118118
The solution is to explicitly specify the kind of the constant:
119-
```
119+
```fortran
120120
real(kind=dp), parameter :: x = 9.3_dp
121121
```
122122
And now the output is correct up to the 15th digit:
@@ -128,7 +128,7 @@ Floating point literal constants (again)
128128
---------------------------------
129129

130130
Suppose now you need a floating point constant that is 1/3 (one-third). You may write:
131-
```
131+
```{play-code-block} fortran
132132
program foo
133133
implicit none
134134
integer, parameter :: dp = kind(0d0)
@@ -143,7 +143,7 @@ Then the output is (!):
143143
The reason is that `1_dp` and `3_dp` are **integer** literal constants, despite the `_dp` suffix that is *supposed* to represent a floating point kind. Consequently the division is the integer division, with 0 as a result. The gotcha here is that the standard allows compilers to use identical kind values for `REAL` and `INTEGER` types. For instance with gfortran, on most platforms the value $8$ is both the double precision kind AND the 64 bits integer kind, so that `1_dp` is a fully valid integer constant. In constrast, the NAG compiler uses by default unique kind values, such that in the example above `1_dp` would produce a compilation error.
144144

145145
The right way to denote floating point constants is to **always** include the point:
146-
```
146+
```fortran
147147
real(dp), parameter :: onethird = 1.0_dp / 3.0_dp
148148
```
149149
Then the ouput is:
@@ -154,23 +154,23 @@ Then the ouput is:
154154
Leading space in prints
155155
-----------------------
156156

157-
```
157+
```{play-code-block} fortran
158158
program foo
159159
implicit none
160160
print*, "Hello world!"
161161
end program
162162
```
163163
Ouput:
164-
```
164+
```console
165165
% gfortran hello.f90 && ./a.out
166166
Hello world!
167167
```
168168
Note the extra leading space, which is not present in the string of the source code. Historically, the first character was containing a [carriage control code](https://en.wikipedia.org/wiki/ASA_carriage_control_characters) for the early printers, and it was not printed per se. The space " " was instructing the printer to perform a CR+LF sequence before printing the content, and was automatically prepended by the Fortran `print*` statement. Some compilers still do that, although the modern output devices do neither intercept nor use the control character, which is hence "printed". If this leading blank is a problem (it rarely is), then instead of the `*` (which means "let the compiler decide how to format the output") we can code an explicit format:
169-
```
169+
```fortran
170170
print "(A)", "Hello world!"
171171
```
172172
In this case, the compiler does no longer prepend the leading space:
173-
```
173+
```console
174174
% gfortran hello.f90 && ./a.out
175175
Hello world!
176176
```
@@ -179,7 +179,7 @@ Filename extension
179179
------------------
180180

181181
Suppose we put the above "Hello world" program in the source file `hello.f`. Most compilers will produce many compilation errors:
182-
```
182+
```console
183183
% gfortran hello.f
184184
hello.f:1:1:
185185

source/learn/quickstart/hello_world.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ On Windows, you can get native binaries [here](http://www.equation.com/servlet/e
2222

2323
To check if you have _gfortran_ setup correctly, open a terminal and run the following command:
2424

25-
```shell
25+
```console
2626
$> gfortran --version
2727
```
2828

@@ -48,7 +48,7 @@ end program hello
4848

4949
Having saved your program to `hello.f90`, compile at the command line with:
5050

51-
```shell
51+
```console
5252
$> gfortran hello.f90 -o hello
5353
```
5454

@@ -57,7 +57,7 @@ $> gfortran hello.f90 -o hello
5757
5858
To run your compiled program:
5959

60-
```shell
60+
```console
6161
$> ./hello
6262
Hello, World!
6363
```

source/learn/quickstart/organising_code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ use my_mod, only: printMat=>print_matrix
176176

177177
An advantage of placing subroutines and functions in modules is that they can have ```optional``` arguments. In a procedure with an argument declared optional, the ```present``` function is used to test if the argument was set in the caller. Optional arguments that are not present may not be accessed within the procedure. Here is a generalization of the ```vector_norm``` function that can use powers other than 2 to compute the Lp norm.
178178

179-
```
179+
```{play-code-block} fortran
180180
module norm_mod
181181
implicit none
182182
contains

0 commit comments

Comments
 (0)