项目作者: victorsndvg

项目描述 :
Fortran Parameter List. A fortran dictionary where to put the parameters of your application.
高级语言: FORTRAN
项目地址: git://github.com/victorsndvg/FPL.git
创建时间: 2015-10-13T09:31:57Z
项目社区:https://github.com/victorsndvg/FPL

开源协议:GNU Lesser General Public License v3.0

下载


FPL

Fortran Parameter List

Build Status
codecov.io

License

License

What is FPL?

FPL is pure fortran 2003 library that can manage the parameters of your program from a single point.

FPL is an extendible container (dictionary) of <Key, Value> pairs, where the Key is a character string and the Value can be, by the default, of the following data types:

  • Integer (kinds 1, 2, 4, 8)
  • Real (kinds 4, 8)
  • Logical
  • String

Value can be a scalar or an array of any dimension.

FPL stores copies of the passed data by assignment.

FPL is based in Teuchos::ParameterList of the Trilinos project.

How to get FPL

git clone --recursive https://github.com/victorsndvg/FPL.git

Compilation

FPL compile with GNU Fortran compiler 5.1 (and newer versions) and Intel Fortran compiler 15.0.1 (and newer versions).

Note: Due to an issue with IBM XLF 14.0.1 Fortran compiler, if you want to use this compiler use the branch XLF_workaround

FPL uses CMake as a portable compilation system.

The easiest way to compile FPL under Linux is:

  1. $ cd FPL
  2. $ mkdir build
  3. $ cd build
  4. $ cmake ../
  5. $ make

To compile FPL under Windows use de equivalent commands

Getting started with FPL

Notes:

  • Source code documentation
  • FPL cannot handle non-allocated variables while calling Set(Key, Value) or Get(Key, Value) procedures.
  • To succesfull get a stored value into your target variable, data type and shape of both variables must agree.

Using FPL in your program

  1. USE FPL
  2. type(ParameterList_t) :: My_List
  3. call FPL_Init()
  4. call My_List%Init()
  5. ... [Program body]
  6. call My_List%Free()
  7. call FPL_Finalize()

Setting parameters

  1. FPLError = My_List%Set(Key='Max Iters', Value=1500)
  2. FPLError = My_List%Set(Key='Tolerance', Value=1.e-10)
  3. FPLError = My_List%Set(Key='Solver', Value='GMRES')

Getting parameters

  1. integer :: MaxIters
  2. FPLError = My_List%Get(Key='Max Iters', Value=MaxIters)

Getting parameters as strings

  1. character(len=:), allocatable :: MaxItersString
  2. FPLError = My_List%GetAsString(Key='Max Iters', String=MaxItersString)

Check if you can assign a parameter to your variable

Check if the target variable has the same type and shape as the stored variable :bangbang:

  1. integer :: MaxIters
  2. if(My_List%isAssignable(Key='Max Iters', Value=MaxIters)) then
  3. FPLError = My_List%Get(Key='Max Iters', Value=MaxIters)
  4. endif

Deleting parameters

  1. call My_List%Del(Key='Max Iters')

Checking if a parameter is present

  1. logical :: solver_defined
  2. solver_defined = My_List%isPresent(Key='Solver')

Checking if a parameter is of the expected data type

  1. logical :: has_same_type
  2. real :: Tolerance
  3. has_same_type = My_List%isOfDataType(Key='Tolerance', Mold=Tolerance)

Checking the shape of a parameter

  1. logical :: has_same_type
  2. integer, allocatable :: Shape(:)
  3. FPLError = My_List%GetShape(Key='Tolerance', Shape=Shape)

Working with parameter sublists

Every parameter list can recursively store parameter sublists.

  1. type(ParameterList_t), pointer :: Prec_List
  2. Prec_List => My_List%NewSubList(Key='Preconditioner')
  3. call Prec_List%Set(Key='Type', Value='ILU')
  4. call Prec_List%Set(Key='Drop Tolerance', Value=1.e-3)

Checking if it is a parameter sublist

  1. logical :: prec_defined
  2. prec_defined = My_List%isSubList(Key='Preconditioner')

Print (recursive) the content of a parameter list

  1. call My_List%Print()

Iterate on a ParameterList

ParameterList also includes a derived type that works like an iterator to go through all stored parameters without asking for the key.

ParameterList_Iterator interface is almost the same than ParameterList interface plus some procedures like HasFinished() and Next() to manage the advance of the iterator.

The example below iterates on a ParameterList containing integer vectors and getting the stored values.

  1. type(ParameterListIterator_t) :: Iterator
  2. integer,allocatable :: array(:)
  3. integer,allocatable :: shape(:)
  4. Iterator = Parameters%GetIterator()
  5. do while (.not. Iterator%HasFinished())
  6. if(Iterator%GetDimensions() /= 1) stop -1
  7. if(Iterator%GetShape(Shape=shape) /= 0) stop -1
  8. if(.not. Iterator%IsOfDataType(Mold=array)) stop -1
  9. if(allocated(array)) deallocate(array)
  10. allocate(array(shape(1)))
  11. if(Iterator%Get(array) /= 0) stop -1
  12. print*, ' Key = '//Iterator%GetKey()
  13. print*, ' Bytes = ', Iterator%DataSizeInBytes()
  14. print*, ' Dimensions = ', Iterator%GetDimensions()
  15. print*, ' Value = ', array)
  16. call Iterator%Next()
  17. enddo