Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Table of Contents | ||||||
---|---|---|---|---|---|---|
|
Introduction
Expand |
---|
The aim of this document is to give OpenRadioss development guidelines. These guidelines cover the style and the efficiency of the code. OpenRadioss is mostly written in Fortran (Fortran77 and Fortran90 and above) https://fortran-lang.org/. A few functions are written in C and C++. The following rules apply for new code. |
OpenRadioss Coding Standards
Expand |
---|
Fortran LanguageFortran90 is the programming language used for OpenRadioss development. Fortran95, Fortran2003, Fortran2008 and future extensions may be used only if necessary, and explicitly approved by OpenRadioss maintainers. In such case, these programming guidelines will have to be amended accordingly. It is allowed to use Intrinsic functions coming from Fortran95 up to Fortran2008 For Fortran code, the files should be named “<subroutine_name>.F”, “<module_name>_mod.F>” and “<include_file_name>.inc”. Only fixed format is allowed, extended to 132 columns C/C++ LanguageC routines deal with low level I/O, system calls. C++11 may be used PreprocessorC Preprocessor directives can be used to include files, define constants and macros IMPLICIT NONEEvery OpenRadioss Fortran routine needs to include implicit_f.inc that contains Fortran90 RestrictionsFortran90 features that penalize performance should be avoided:
Obsolete Fortran77 CodingThe following statements are not allowed in new code:
It is also forbidden to use label for |
WIP: Below being edited/modified
Precompiler Directives
Expand |
---|
Fortran files are of type foo.F. Fortran precompiler is automatically called Therefore, it is forbidden to name a file .f or .f90 In particular the below directives are in use: Examples:
|
IMPLICIT NONE
Expand |
---|
For historical reasons, (in the past it was not supported everywhere) IMPLICIT NONE is automatically added to the source via a specific include implicit_f.inc. Its usage forces the programmer to declare every variable Every Radioss Fortran routine needs to include implicit_f.inc |
Fixed Format
Expand |
---|
To keep coherency between original code and new code, only fixed format is allowed, extended to 132 columns Comments need to begin with They can be placed anywhere ( Several instructions per line are allowed using |
Fortran95, Fortran2003, Fortran2008 Extensions
Expand |
---|
Intrinsic functions are allowed, especially Other Fortran95 extensions are refused Fortran2003 and Fortran2008 extensions are refused |
Fortran 90 Restrictions
Expand |
---|
Object oriented features like operator overloading are forbidden as they can highly penalize performance Array manipulation, and especially non-contiguous section as subroutine argument is forbidden (assumed-shape-array) Array reduction and special functions like |
Fortran 77 Extensions
Expand |
---|
Fortran77 extensions which are not Fortran90 standard are refused |
Obsolete Fortran 77 coding
Expand |
---|
EQUIVALENCE
Use There is an ongoing effort to clean out the remaining instances in the code COMMON
For new development, Current/existing SAVE
Multiple RETURNMultiple GOTOThe use of DO loop with label
|
Data Types
Expand | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
IntegerAll integers are by default 32-bit integers ( Where it is required 64-bit integer ( Use of RealReals can be either 32-bit simple precision or 64-bit double precision reals Real variables need to be declared as my_real.inc is automatically included together with implicit_f.inc to define The pre-compiler automatically replaces
Example:
For some exceptions, it is sometimes needed to explicitly use Such exceptions are limited in the source code Logical
In particular, it is forbidden to use “ Derived data typeDerived data type is one of the main improvements of Fortran90 standard The use of derived data types is strongly encouraged (see OpenRadioss Coding Recommendations ). Derived data type allows to define new structured types The name of a new type should use suffix Example:
Intrinsic functionsProgrammers are only allowed to use generic functions compatible with both single and double precision: Explicitly typed functions are prohibited: Numerical constantsAll real constant variables are declared inside constant.inc common and initialized using Examples: Forbidden:
Allowed:
Zero & infinite valuesTo avoid division by zero, it is advised to test against To avoid infinite value test against These values are generally a good compromise for both double and single precision It is always possible to check version precision using flag
Bitwise logical operationsSemantic of bitwise logical operators like Note: |
Interfacing Fortran and C
Expand | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Calling conventionThere is no standard calling convention between Fortran and C Here is described the way it is handled in Radioss by defining every potential calling convention Notice that the importance of this specific point is decreasing with the number of architectures and compilers supported Fortran 90 calling routine:
C callee routine:
Argument variable correspondence
Examples of type definition under Linux and Windows
|
Specific code management
Expand |
---|
For some reason, some code may depend on a specific architecture or compiler. In this case, such code is gathered into a unique directory (one for Starter and one for Engine) called spe and spe_inc for include files The rest of the code needs to be machine independent. This facilitates porting to new machine or compiler The specific part of the code is managed by the precompiler using The different supported architectures are defined under hardware.inc A clean up of the supported architecture must be scheduled |