mod_utils Module

This module contains some very generic utils for string manipulation, or very basic computational/mathematic operation. It should not depend on any module except from mod_memory.


Uses

  • module~~mod_utils~~UsesGraph module~mod_utils mod_utils module~mod_constants mod_constants module~mod_utils->module~mod_constants module~mod_memory mod_memory module~mod_utils->module~mod_memory iso_c_binding iso_c_binding module~mod_constants->iso_c_binding module~mod_memory->module~mod_constants module~mod_memory->iso_c_binding module~mod_io mod_io module~mod_memory->module~mod_io module~mod_io->module~mod_constants

Used by


Contents


Interfaces

interface

  • public function atoi(in) bind(c)

    Arguments

    Type IntentOptional Attributes Name
    character :: in(*)

    Return Value integer(kind=c_int)

interface

  • public function atof(in) bind(c)

    Arguments

    Type IntentOptional Attributes Name
    character :: in(*)

    Return Value real(kind=c_double)


Functions

public function str_to_lower(s)

Convert string in input from upper case to lower case and return the lower case string as output.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String to be converted in lowercase

Return Value character

String converted to lowercase

public function str_uncomment(s, comment_char)

Remove inline comments from a srting s, comments should begin with the string or character contained in comment_char

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String in input

character(len=*), intent(in) :: comment_char

Char that begin the comment

Return Value character

String converted to lowercase

public function count_substr_occurence(s, c)

Count the number of occurence of substring c in string s, and return the number of occurence, if c is not contained in s, zero is returned.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String where to search the substring

character(len=*), intent(in) :: c

Substring to search

Return Value integer(kind=ip)

public function starts_with_alpha(s)

Decide if a string starts with a letter or not.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String to analyze

Return Value logical

public function isint(s)

Decide if a string can be interpreted as an integer or not

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String to analyze

Return Value logical

public function isreal(s)

Decide if a string can be interpreted as a real

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: s

String to analyze

Return Value logical

public pure function tokenize_pure(s, ib, ntok) result(tokenize)

This function is used to subsequently break a string into tokens. Tokens separators are any number of spaces.
If just the string is provided, the function returns the position of the first printable character;
If also ib is provided it saves the position of the first printable character after position ib (or ib itself) in ib and return the position of the last printable character before the first space after ib. If ntok is specified instead of a single token, ntok are returned. In case of last token hitten -1 is returned.
To divide a string follow the following scheme:
1. ib = tokenize(s)
2. ie = tokenize(s, ib)
3. tok1 = s(ib:ie)
4a. ib = ib+1
4b. ie = tokenize(s, ib)
5. tok2 = s(ib:ie)

Arguments

Type IntentOptional Attributes Name
character(len=OMMP_STR_CHAR_MAX), intent(in) :: s

String to subdivide in token

integer(kind=ip), intent(in), optional :: ib

Index where to start token research (input)/Index where token begins (output)

integer(kind=ip), intent(in), optional :: ntok

Number of token to be extracted

Return Value integer(kind=ip), (2)

Index where token ends.

public function tokenize(s, ib, ntok)

This function is used to subsequently break a string into tokens. Tokens separators are any number of spaces.
If just the string is provided, the function returns the position of the first printable character;
If also ib is provided it saves the position of the first printable character after position ib (or ib itself) in ib and return the position of the last printable character before the first space after ib. If ntok is specified instead of a single token, ntok are returned. In case of last token hitten -1 is returned.
To divide a string follow the following scheme:
1. ib = tokenize(s)
2. ie = tokenize(s, ib)
3. tok1 = s(ib:ie)
4a. ib = ib+1
4b. ie = tokenize(s, ib)
5. tok2 = s(ib:ie)

Arguments

Type IntentOptional Attributes Name
character(len=OMMP_STR_CHAR_MAX), intent(in) :: s

String to subdivide in token

integer(kind=ip), intent(inout), optional :: ib

Index where to start token research (input)/Index where token begins (output)

integer(kind=ip), intent(in), optional :: ntok

Number of token to be extracted

Return Value integer(kind=ip)

Index where token ends.

public pure function cross_product(a, b) result(c)

Computes the cross product between two vectors of dimension 3. Used as an inlinable function in geometric manipulations

Arguments

Type IntentOptional Attributes Name
real(kind=rp), intent(in), dimension(3) :: a

Input vector

real(kind=rp), intent(in), dimension(3) :: b

Input vector

Return Value real(kind=rp), dimension(3)

Output vector

public pure function vec_skw(a) result(b)

Computes the matrix operator corresponding to a cross product of an input vector of dimension 3.

Arguments

Type IntentOptional Attributes Name
real(kind=rp), intent(in), dimension(3) :: a

Return Value real(kind=rp), dimension(3,3)

public pure function versor_der(a) result(g)

Computes the derivativative matrix of a versor wrt its generator vector . [\frac{\partial \hat{A}}{\partial \vec{A}} = \frac{1}{||\vec{A}||^3} (||\vec{A}||^2 \mathbb{1}_3 - A^\dagger A) = \frac{1}{||\vec{A}||^3} \begin{bmatrix} ||\vec{A}||^2 - \vec{A}_x^2 & - \vec{A}_x \vec{A}_y & - \vec{A}_x \vec{A}_z \ !! - \vec{A}_y \vec{A}_x &

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=rp), intent(in), dimension(3) :: a

Return Value real(kind=rp), dimension(3,3)


Subroutines

public subroutine skip_lines(f, n)

Skips n lines while reading an input file

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in) :: f

unit file

integer(kind=ip), intent(in) :: n

number of line to be skipped

public subroutine sort_ivec(iv, ov)

This is a simple -- and unefficient -- routine to sort a vector of integers. It is just used during some output to simplify comparisons with older version of the code.

Read more…

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in), dimension(:) :: iv

Input vector

integer(kind=ip), intent(out), allocatable :: ov(:)

Output, sorted vector

public subroutine sort_ivec_inplace(iv)

Inplace equivalent of sort_ivec routine.

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(inout), dimension(:) :: iv

Vector to be reordered in place

public subroutine compute_bicubic_interp(x, y, z, dzdx, dzdy, nx, ny, xgrd, ygrd, v, vx, vy, vxy)

Evaluate the z value at position (x, y) of a surface built as a bicubic spline interpolating the points
(xgrd(, ), ygrd(, ), vxgrd(, )).
In order to do so, also the derivatives of the surface at the points of the grid are needed; in particular if we consider the surface points as also value of , and at grid points are needed.

Arguments

Type IntentOptional Attributes Name
real(kind=rp), intent(in) :: x

Coordinates at which the z value of the surface should be computed

real(kind=rp), intent(in) :: y

Coordinates at which the z value of the surface should be computed

real(kind=rp), intent(out) :: z

The z value of the surface

real(kind=rp), intent(out) :: dzdx

Derivatives of z valure w.r.t. x and y coordinates

real(kind=rp), intent(out) :: dzdy

Derivatives of z valure w.r.t. x and y coordinates

integer(kind=ip), intent(in) :: nx

Number of grid points along x and y direction

integer(kind=ip), intent(in) :: ny

Number of grid points along x and y direction

real(kind=rp), intent(in), dimension(ny,nx) :: xgrd

X-coordinate value of points on the grid

real(kind=rp), intent(in), dimension(ny,nx) :: ygrd

Y-coordinate value of points on the grid

real(kind=rp), intent(in), dimension(ny,nx) :: v

V(x, y) of points on the grid

real(kind=rp), intent(in), dimension(ny,nx) :: vx

of points on the grid

real(kind=rp), intent(in), dimension(ny,nx) :: vy

of points on the grid

real(kind=rp), intent(in), dimension(ny,nx) :: vxy

of points on the grid

public subroutine cyclic_spline(n, x, y, a, b, c, d)

Compute the cyclic interpolating cubic spline (2D) that passes for
points . Each segment is described by the curve: The algorithm used to compute the coefficients is taken from "Numerical Algorithm with C" - Gisela ENGELN-MULLGES Frank UHLIG (10.1007/978-3-642-61074-5)

Arguments

Type IntentOptional Attributes Name
integer(kind=ip), intent(in) :: n

Dimension of the data series

real(kind=rp), intent(in) :: x(n)

X-values of input data

real(kind=rp), intent(in) :: y(n)

Y-values of input data

real(kind=rp), intent(out) :: a(n)

Coefficients of the cubic spline in each segment of the spline

real(kind=rp), intent(out) :: b(n)

Coefficients of the cubic spline in each segment of the spline

real(kind=rp), intent(out) :: c(n)

Coefficients of the cubic spline in each segment of the spline

real(kind=rp), intent(out) :: d(n)

Coefficients of the cubic spline in each segment of the spline