Skip to content

Improving the Fortran API

Giannis Nikiteas requested to merge feature/improve-fortran-api into master
  • Removes non-standard DEC$ directives
  • Changes comments to F90 (!) from F77 (C)
  • Adds semver major, minor, patch variables
  • Changes semver version to a larger string
  • Changes docstrings to be Doxygen abiding
  • Changes module name from gmsh_fortran to gmsh
  • Changes file extension from .h to .f90
  • Changes indentation to 4-space (fixed for now)
  • Fixes & being erroneously placed at the start of newlines vs EOL
  • Reformats variable commas, spacings, etc. to be consistent
  • Removes hardlimit for procedures names> 45 to be excluded from the API
  • Makes Fortran API more user friendly by:
    • Allowing for Fortran arrays to be input
    • Allowing for Fortran arrays to be output
    • Allowing for Jagged arrays to be represented by a 1D array and a an array with the individual dimensions e.g. array=[1, 2, 3, 4, 5] and dims=[2, 3] instead of what previously was a c_ptr to the array a c_ptr for the dims array and a c_size_t integer for the length of dims
    • Pairs are represented by arrays that are (2,n) in dimensions in Fortran, when passed to C the array gets unwrapped to a single 1D array where the first and second pair values i.e. (1,x) and (2,x) are contiguous in memory (Fortran is column major)
    • Allowing Fortran strings to be input as names, they are then internally cast to C strings and a C null character is appended to all.
  • Introduces the public integer variables, GMSH_API_VERSION_MAJOR, GMSH_API_VERSION_MINOR, GMSH_API_VERSION_PATCH and GMSH_API_MAX_STR_LEN

Requirements

The API uses optional arguments with the C interop so a Fortran 2018 or Fortran 2008+TS29113 compiler is required.

TODO List:

  1. Abide by indent, currently spacing manually set to 4spaces
  2. Add optional arguments for things such as gmshModelAddPhysicalGroup
  3. Change names _n _nn to more descriptive names
  4. Simplify spacing between procedure types
  5. Convert API names to be user friendly get, set, etc.
  6. Convert Python strings to fstrings
  7. Free allocated memory in C
  8. Wrap lines to 132 chars; break bind(C,...) to next line, break arg list to next line, break C_API call to next line
  9. Change indentation to 2-spaces from 4

Additional

  1. I would like to find a way to provide the Gmsh Fortran API via the Fortran Package Manager (fpm). We would only have to provide the single Fortran file (and possibly the tutorials as examples). I think the easiest way to do this would be from outside the main Gmsh repo. I use mostly GitHub so I will ping you there if I get it working.

  2. I have added all the existing 21 tutorials for Fortran. I have tested all of them and they work as expected. Maybe we can add some CMake targets to build the examples.

  3. I have not added anything about flog in the Fortran section of the Python GenApi.py script. I would be keen to leave this for another PR.

  4. File paths in tutorials are hardcoded e.g. '../../input_file.stl' so the tutorials will only work when run from UNIX shells

Edited by Giannis Nikiteas

Merge request reports