Syntax highlighting OK

This commit is contained in:
Anthony Scemama 2018-11-20 19:16:09 +01:00
parent 9351d38eff
commit dc8631ed59
4 changed files with 82 additions and 68 deletions

View File

@ -8,7 +8,8 @@ canonifyurls = true
DefaultContentLanguage = "en"
theme = "beautifulhugo"
metaDataFormat = "yaml"
pygmentsUseClassic=true
#pygmentsuseclasses = true
PygmentsCodeFences = true
[Params]
@ -19,7 +20,7 @@ pygmentsUseClassic=true
commit = false
rss = true
comments = true
# gcse = "012345678901234567890:abcdefghijk" # Get your code from google.com/cse. Make sure to go to "Look and Feel" and change Layout to "Full Width" and Theme to "Classic"
useHLJS = true
[[Params.bigimg]]
src = "img/triangle.jpg"

View File

@ -49,26 +49,26 @@ The production tree of *E* is represented as:
The calculation of *E* could be done in Fortran using subroutine
calls to imperatively ask the program to realize the needed calculations, such as
```bash
program compute_Energy
double precision :: E_nucl, E_pot, E_kin, E_elec, E
```fortran
program compute_Energy
double precision :: E_nucl, E_pot, E_kin, E_elec, E
call compute_E_nucl(E_nucl)
call compute_E_pot(E_pot)
call compute_E_kin(E_kin)
call compute_E_elec(E_elec,E_pot,E_kin)
call compute_E(E,E_nucl,E_elec)
call compute_E_nucl(E_nucl)
call compute_E_pot(E_pot)
call compute_E_kin(E_kin)
call compute_E_elec(E_elec,E_pot,E_kin)
call compute_E(E,E_nucl,E_elec)
print *, 'Energy = ', E
print *, 'Energy = ', E
end
end
```
In this example, it is not clear which are input and output
arguments in the subroutine calls. A clearer way to express the same code
would be using functions:
```bash
```fortran
program compute_Energy
double precision :: E_nucl, E_pot, E_kin, E_elec, E
double precision :: compute_E_nucl, compute_E_pot, compute_E_kin, &
@ -89,13 +89,13 @@ In both example, the programmer needs to know the production tree of *E*,
in order to be position the statements in the correct order.
For instance, the line
```bash
```fortran
E_nucl = compute_E_nucl()
```
has to be positioned before
```bash
```fortran
E = compute_E(E_nucl,E_elec)
```
@ -103,7 +103,7 @@ otherwise the program is wrong.
If the code is written in this way:
```bash
```fortran
program compute_Energy
double precision :: compute_E_nucl, compute_E_pot, compute_E_kin, &
compute_E_elec, compute_E
@ -126,7 +126,7 @@ the code would be unreadable by a programmer.
If the parameters of function calls could be automatically inserted by a tool,
the program would be as simple as
```bash
```fortran
program compute_E
print *, 'Energy = ', E
end
@ -140,7 +140,7 @@ production tree. It is defined by a provider function, whose role is to build
the value of the entity. In this example, the provider function of *E*
would be
```bash
```irpf90
BEGIN_PROVIDER [ double precision, E ]
E = E_nucl + E_elec
END_PROVIDER
@ -181,8 +181,7 @@ IRPF90_man IRPF90_temp Makefile
and a standard `Makefile` is build, using the gfortran compiler:
```bash
$ cat Makefile
```make
IRPF90 = irpf90 #-a -d
FC = gfortran
FCFLAGS= -ffree-line-length-none -O2
@ -204,7 +203,7 @@ We can now start to write the code.
First, we write a very simple program which prints the surface and the
volume of a cube. In a file named ``cube_example.irp.f``, write:
```bash
```irpf90
program cube_example
implicit none
@ -230,7 +229,7 @@ We can now write in the file named `properties.irp.f` how the properties are
computed. The calculation of a property appears in the *provider function*
of the property.
```bash
```irpf90
BEGIN_PROVIDER [ real, surface ]
BEGIN_DOC
@ -241,7 +240,7 @@ BEGIN_PROVIDER [ real, surface ]
END_PROVIDER
```
```bash
```irpf90
BEGIN_PROVIDER [ real, volume ]
BEGIN_DOC
@ -256,7 +255,7 @@ These two properties depend on the value of the ``edge`` variable which can be
given in the standard input. The edge is the way we define a cube, so we
write in a file named ``cube.irp.f``:
```bash
```irpf90
BEGIN_PROVIDER [ real, edge ]
BEGIN_DOC
! Value of the edge of the cube
@ -272,7 +271,7 @@ Here the ``ASSERT`` keyword guarantees that when ``edge`` is provided, its value
is positive. Otherwise, if the `-a` option of the ``irpf90`` command is used,
the program will fail will an error message:
```bash
```
Stack trace: 0
-------------------------
cube_example
@ -301,7 +300,7 @@ using the irpman tool (shown in next section).
To understand what happens at the execution, turn on the `-a` and `-d` options
of `irpf90` in the `Makefile` by removing the `#` in the first line. Then, run `make`.
```bash
```
$ make
Makefile:9: irpf90.make: No such file or directory
irpf90 -a -d
@ -330,7 +329,7 @@ file ``irpf90.make`` was generated, and contains the dependencies between the ``
files. The file ``irpf90_entities`` contains the list of the IRP entities,
their type and the file in which they are defined:
```bash
```
$ cat irpf90_entities
cube.irp.f : real :: edge
properties.irp.f : real :: surface
@ -345,7 +344,7 @@ $ irpman surface
you obtain a man page describing the entity surface and its dependencies:
```text
```
IRPF90 entities(l) surface IRPF90 entities(l)
Declaration
@ -369,7 +368,7 @@ IRPF90 entities surface IRPF90 entities(l)
Recall that the `-d` and `-a` options were activated in the `Makefile`.
Run the program, and choose 2 for the value of the edge of the cube:
```bash
```
$ ./cube_example
0 : -> provide_volume
0 : -> provide_edge
@ -404,7 +403,7 @@ wrote.
We first need to provide ``surface``
```bash
```
-> provide_surface
```
@ -412,33 +411,33 @@ As ``surface`` is not valid, we have to build it, but as ``surface`` needs
``edge``, we first need to provide ``edge`` before computing the value of
``surface``.
```bash
```
-> provide_edge
```
As ``edge`` is not valid, it has to be built.
```bash
```
-> bld_edge
```
Building ``edge`` asks the user to enter the value with the standard
input.
```bash
```
Value of the edge of the cube
```
Now ``edge`` is valid
```bash
```
<- bld_edge 0.00000000000000
<- provide_edge 0.00000000000000
```
and we can build the value of ``surface``:
```bash
```
-> bld_surface
<- bld_surface 0.00000000000000
```
@ -447,14 +446,14 @@ We are now back into the main program with a valid value for the surface.
The value of ``volume`` is also requested in the main program, so the
exploration of the production tree of ``volume`` starts:
```bash
```
-> provide_volume
```
``volume`` needs ``edge``. As ``edge`` is valid, it is not re-built at its
value is used to calculate ``volume``
```bash
```
-> bld_volume
<- bld_volume 0.00000000000000
<- provide_volume 0.00000000000000
@ -463,20 +462,20 @@ value is used to calculate ``volume``
We can now execute the main program with valid values of ``surface`` and
``volume``.
```bash
```
-> cube_example
```
These values can now be used to be printed:
```bash
```
Surface Area : 24.00000
Volume : 8.000000
```
The last line tells us we leave the program
```bash
```
<- cube_example 0.00000000000000
```
@ -512,7 +511,7 @@ which constitute the faces, and calculate the centers.
In the main code, just add the information that you want to print the
coordinates of the centers of the faces of the cube:
```bash
```irpf90
program cube_example
implicit none
@ -539,7 +538,7 @@ anywhere.
Now, we introduce the ''center'' entity, which contains the values of the
centers of the faces of the cube, in the `properties.irp.f` file:
```bash
```irpf90
BEGIN_PROVIDER [ real, center, (3,face_num) ]
implicit none
@ -576,7 +575,7 @@ in the array ``vertex``. The array ``face`` contains, for each face, the
indices of the array ``vertex`` corresponding to the vertices of the face:
these last arrays are defined in the ``cube.irp.f``:
```bash
```irpf90
BEGIN_PROVIDER [ integer, vertex_num ]
implicit none
BEGIN_DOC
@ -626,7 +625,7 @@ For simplicity, the cube is chosen to have one point at the origin, and faces
in the *xy*, *yz* and *xz* planes. The faces are computed using the squared
distance matrix of the vertices:
```bash
```irpf90
BEGIN_PROVIDER [ integer, face_num ]
implicit none
@ -697,7 +696,7 @@ END_PROVIDER
where the squared distance matrix is defined with:
```bash
```irpf90
BEGIN_PROVIDER [ real, distance2, (vertex_num,vertex_num) ]
implicit none
@ -720,7 +719,7 @@ END_PROVIDER
and the squared value of the edge is computed only once using:
```bash
```irpf90
BEGIN_PROVIDER [ real, edge2 ]
BEGIN_DOC
! edge2 : Square of the value of the edge
@ -750,7 +749,7 @@ IRPF90_temp/properties.irp.o IRPF90_temp/irp_touches.irp.o
and run it:
```bash
```
$ ./cube_example
0 : -> provide_volume
0 : -> provide_edge
@ -822,7 +821,7 @@ In the ``cube.irp.f`` file, we first modify the provider of the ``edge`` entity.
Considering that the vertices constitute a cube, the edge is the minimum value
of the distance matrix
```bash
```irpf90
BEGIN_PROVIDER [ real, edge ]
BEGIN_DOC
! Value of the edge of the cube
@ -850,7 +849,7 @@ END_PROVIDER
Then, we modify the provider of the ``vertex`` entity to read 8 points from
the input file.
```bash
```irpf90
BEGIN_PROVIDER [ real, vertex, (3,vertex_num) ]
implicit none
@ -876,7 +875,7 @@ To be sure that the data read by the code is valid, we write the function
``is_a_cube`` which returns `.True.` when the points given are vertices of a
cube. This function is a standard Fortran function:
```bash
```irpf90
logical function is_a_cube(v)
implicit none
@ -962,7 +961,7 @@ gfortran -o cube_example IRPF90_temp/cube_example.irp.o IRPF90_temp/irp_stack.i
```
```bash
```
$ ./cube_example
0 : -> provide_volume
0 : -> provide_edge
@ -1045,7 +1044,7 @@ long as the value of the surface is below a threshold. At the end of one
iteration, the length of the edge is incremented by the value ``increment``.
In file ``iterative_test.irp.f``, write:
```bash
```irpf90
program iterative_test
implicit none
@ -1065,7 +1064,7 @@ have to be provided again.
The ``threshold`` and ``increment`` values are given in input, in file
``control.irp.f``:
```bash
```irpf90
BEGIN_PROVIDER [ real, threshold ]
BEGIN_DOC
@ -1108,7 +1107,7 @@ you can remark that the executable ``cube_example`` of the previous section is s
Running the program gives:
```bash
```
$ ./iterative_test
0 : -> provide_threshold
0 : -> threshold
@ -1194,14 +1193,14 @@ code. Let us write a simple header for the code, which returns the name of the
user who compiled the code, and the date of compilation. We now remove the
`-d` option of ``irpf90`` for shorter outputs.
```bash
```irpf90
program iterative_test
implicit none
print *, 'Program ', irp_here
BEGIN_SHELL [ /bin/sh ]
echo print *, \'Compiled by : $USER\'
echo print *, \'Compilation date: `date`\'
echo "print *, \'Compiled by : $USER \'"
echo "print *, \'Compilation date: `date`\'"
END_SHELL
do while (surface < threshold)
@ -1215,7 +1214,7 @@ end program
Running this program returns the following output:
```bash
```
Threshold for the surface:
100
Vertices of the cube:
@ -1244,14 +1243,14 @@ gathering information from the input. This is due to the fact that in IRPF90,
the entities are provided as soon as possible. If you really want to print the
header at the beginning of the program, you can use the following trick:
```bash
```irpf90
program iterative_test
implicit none
print *, 'Program ', irp_here
BEGIN_SHELL [ /bin/sh ]
echo print *, \'Compiled by : $USER\'
echo print *, \'Compilation date: `date`\'
echo "print *, \'Compiled by : $USER \'"
echo "print *, \'Compilation date: `date`\'"
END_SHELL
call run_iterative_process
@ -1270,7 +1269,7 @@ end program
which gives the output:
```bash
```
Program iterative_test
Compiled by : scemama
Compilation date: Fri Sep 25 16:03:58 CEST 2009
@ -1387,7 +1386,7 @@ END_SHELL
and a new main program is created (``get_doc.irp.f``) to print the documentation of
a variable if it is present in the command line:
```bash
```irpf90
program get_doc
integer :: iargc
@ -1448,7 +1447,7 @@ $ ./get_doc
```
```bash
```
$ ./get_doc volume
Volume of the cube
```
@ -1460,7 +1459,7 @@ $ ./get_doc volume
Memory of an IRP entity can be freed using the ``FREE`` keyword
```bash
```irpf90
FREE x
```
@ -1474,7 +1473,7 @@ If it is not an array, the ``FREE`` keyword will only mark it as invalid.
Conditional compilation is possible using the ``IRP_IF ... IRP_ELSE .. IRP_ENDIF`` directives.
```bash
```irpf90
IRP_IF MPI
include 'mpif.h'
print *, 'Multiprocessor code'

View File

@ -1,4 +1,15 @@
<!--
If you want to include any custom html just before </body>, put it in /layouts/footer_custom.html
Do not put anything in this file - it's only here so that hugo won't throw an error if /layouts/footer_custom.html doesn't exist.
-->
-->
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.pack.js"></script>
<!--
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/highlight.min.js"></script>
-->
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/fortran.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/languages/irpf90.min.js"></script>
<script>
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
</script>

View File

@ -1,4 +1,7 @@
<!--
If you want to include any custom html just before </head>, put it in /layouts/head_custom.html
Do not put anything in this file - it's only here so that hugo won't throw an error if /layouts/head_custom.html doesn't exist.
-->
-->
<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github.min.css" rel="stylesheet">