Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

2. Development of Fortran codes

2.1 Subroutine syntax

subroutine name ( <in/out arguments list> [,code_parameters] [,diagnostic_info] )

  • name - subroutine name
  • in/out arguments list - a list of input and output subroutine arguments
  • diagnostic_info - arbitrary output diagnostic information

2.2. Arguments list

  • A mandatory position
  • A list of input and output subroutine arguments including:
    • Fortran intrisic data types, eg:
      • integer :: input
      • character(50) :: charstring
      • integer,dimension(4) :: tabint
    • IDSes, eg:
      • type (type_equilibrium),pointer :: equilibriumin(:)
      • type (type_distsource),pointer :: distsourceout(:)
Warning
  • Always describe IDS as an array. In case of time slice, the size of the input IDS is 1 (!)
  • Do not forget to add: use imas_schemas, while playing with IDSes
  • Please use intent(in), intent(out) to point in/out parameters

2.3. Code parameters

  • user defined input parameters
  • input / optional
  • Argument of type: type_param

    Code Block
    type type_param  !
      character(len=132), dimension(:), pointer ::parameters 
      character(len=132), dimension(:), pointer ::default_param  
      character(len=132), dimension(:), pointer ::schema         
    endtype
  • Derived type type_param describes:
    • parameters - Actual value of the code parameters (instance of coparam/parameters in XML format).
    • default_param - Default value of the code parameters (instance of coparam/parameters in XML format).
    • schema - Code parameters schema.
  • An example: 
    • (type_param) :: codeparam{{

2.4. Diagnostic info

  • arbitrary output diagnostic information
    • output / optional

      Code Block
           !----  Diagnostic info  ----
           integer, intent(out)     ::     user_out_outputFlag
           character(len=:), pointer, intent(out)    ::    user_out_diagnosticInfo
    • outputFlag - indicates if user subroutine was successfully executed

      • outpuflag = 0    - SUCCESS, no action is taken

      • outputFlag > 0  - WARNING, a warning message is displayed, workflow continuue execution

      • outputFlag < 0 - ERROR, actor throws an exception, workflow stops

    • diagnosticInfo - an arbitrary string

2.5. Examples

Code Block
titleExample 1 Simple in/out argument types
subroutine noids(input, output)
   integer, intent(in):: input
   integer, intent(out):: output

 

 

Code Block
titleExample 2 A IDS array as a subroutine argument
subroutine equil2dist(equilibriumin, distsourceout)
  use imas_schemas
  implicit none

 !input
 type (type_equilibrium), pointer :: equilibriumin(:)
 !output
 type (type_distsource), pointer :: distsourceout(:)

 

 

Code Block
titleExample 3 Usage of code input parameters
subroutine teststring(coreprof,equi,tabint,tabchar,codeparam)
   use imas_schemas                                                                              
   implicit none                                             

  !input
  type(type_coreprof),pointer,dimension(:) :: coreprof
  integer, dimension(4), intent(in) :: tabint

  !output
  type(type_equilibrium),pointer,dimension(:) :: equi
  character(50), intent(out) :: tabchar

  !code parameters
  type(type_param), intent(in) :: codeparam


 


 

4. Delivery of the user code

The user code should be delivered as a static library.
Please find examples of the simple "makefiles" below:


 
CXX=g++ CXXFLAGS= -g -fPIC CXXINCLUDES= ${shell eval-pkg-config --cflags ual-cpp-gnu} all: libsimplecppactor.a libsimplecppactor.a: simplecppactor.o ar -rvs $@ $^ simplecppactor.o: simplecppactor.cpp $(CXX) $(CXXFLAGS) $(CXXINCLUDES) -c -o $@ $^ clean: rm *.a *.o
Code Block
languagebash
titleExample 6. Building of Fortran code
F90 = $(ITM_INTEL_FC)
COPTS = -g -O0 -assume no2underscore -fPIC -shared-intel

INCLUDES = $(shell eval-pkg-config --cflags ual-$(ITM_INTEL_OBJECTCODE))

all: equilibrium2distsource.o libequilibrium2distsource

libequilibrium2distsource: equilibrium2distsource.o
        ar -rvs libequilibrium2distsource.a equilibrium2distsource.o

equilibrium2distsource.o: equilibrium2distsource.f90
        $(F90) $(COPTS) -c -o $@ $^ ${INCLUDES} 

clean:
        rm -f *.o *.a
Code Block
titleExample 7. Building of C++ code

 


 

 

Tip

Recomendations

  • Please use eval-pkg-config to get UAL flags and not hard coded references.
  • The usage of environment variables for identifying compilers and versions of the pkg-config is recommended.

 

 

...