4. Writing the Fortran operator#

This is the main Fortran routine for the command, the one we chose the name when writing Order catalog. When adding a new order, it is necessary to declare the associated op in the Ex0000.F90 switch routine (provided). Each Fortran routine is completed by a header file to be included in each calling in order to check the arguments during compilation. This is bibfor/include/asterfort/op0190.h.

The skeleton to be completed in the routine is bibfor/OP/OP0190.f90:

subroutine op0190 ()
    Implicit none

#include "asterc/getfac.h"
#include "asterc/getres.h"
#include "asterfort/as_allocate.h"
#include "asterfort/as_deallocate.h"
#include "asterfort/assert.h"
#include "asterfort/dismoi.h"
#include "asterfort/getvid.h"
#include "asterfort/getvr8.h"
#include "asterfort/jedema.h"
#include "asterfort/jemarq.h"
#include "asterfort/jeveuo.h"

    character (len=8):: mesh, result
    character (len=16):: concept, cmd name
    character (len=19): chord
    character (len=24):: vect_core
    integer: i, j, iret, dim, nbocc, nbnodes
    real (kind=8), pointer:: vect (:) => null ()
    real (kind=8):: transl (3)
    real (kind=8), pointer:: coordinate (:) => null ()

    Call jemarq ()

! Read the input mesh name: mesh_sdaster, see d6.03.01, §2.1.1
    call getvid (..., nbret=iret)
    ASSERT (iret = 1)

! Read the mesh result (must be identical to the input), see d6.03.01, §2.1.5
    Call letters (...)
    ASSERT (result == mesh)

! check that TRANSLATION exists, see d6.03.01, §2.1.6
    call getfac ('TRANSLATION', nbocc)
    ASSERT (bocc=1)

! Get the size of the translation vector for a dynamic allocation, see d6.03.01, §2.1.1
    call getvr8 (..., nbval=0, nbret=dim)
    Sun = -Sun
    ASSERT (2 <= dim.and. dim <= 3)
! Allocate the vector of size 'dim'
    AS_ALLOCATE (...)
! Read the translation vector values
    call getvr8 (..., nbval=dim, vect=vect)

! Name of the Jeveux Vector Containing the Coordinates of the Mesh
! See d4.06.01 for the COORDO object and d4.06.05 for its VALE vector
    chord =...
    vect_coordinate =...

! Get the address and the size of this vector
    Call Jeveuo (...)
    Call tell me (...)

! Loop on the Nodes
    ...

    Call Jedema ()
End subroutine

4.1. Detailed description#

See Programming rules.

We start with the inclusion of the interface files, then the declaration of required variables. When the routine has arguments, you state them first. The statement must be the same as in the interface file. We must specify if the argument is input (integer, intent (in):: size**), output (``real (kind=8), intent (out):: residual) or modified inout. An argument can be optional and must be declared as such (optional).

Any routine using Jeveux objects should be supervised by ``call jemarq () ``/``call jedema () ``. This makes it possible to automatically release and unused items at the right time.

It is recommended to read the values of the keywords in a single place, not at the bottom of the programming, possibly in a routine dedicated to the command if it is significant. We use the interfaces between Fortran and the command file: routines getvxx, getres, ``getfac »…

« ASSERT » allows you to check that there are no programming errors. For example, we expect one mesh and only one. This is normally imposed by the order catalog. If iret is different from 1, it is a programming error, no use.

« AS_ALLOCATE » allows dynamic allocation (whose size is not fixed). It’s simply Fortran’s allocate that is coated to detect when the release has been forgotten.

To access coordinate values, you must find it in the documentation the name of the mesh object that contains them, and in this object, the name of the vector that contains the values.

We get the address of the vector with jeveuo (look for an example of use in the code).

We call the ``Tell me »utility to retrieve the number of nodes in the mesh (look for the documentation for this utility).

Complete the skeleton and test your code: Build and test.