ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_val2str::getStr Interface Reference

Generate and return the conversion of the input value to an output Fortran string, possibly with the requested format and sign symbol, if provided. More...

Detailed Description

Generate and return the conversion of the input value to an output Fortran string, possibly with the requested format and sign symbol, if provided.

Parameters
[in]val: The input scalar or contiguous array of rank 0, 1, or 2 of either
  1. type css_type (derived type container of scalar string of default kind SK) or
  2. type css_pdt (parameterized derived type container of scalar string of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU)) or
  3. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
  4. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
  5. type logical of kind any supported by the processor (e.g., LK) or
  6. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
  7. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128).
containing the value to be converted to string.
[in]format: The input scalar of type character of default kind SK representing the Fortran IO format to be used when writing the value to the output allocatable character
(optional, the default value depends on the type of the input val:
  1. If val is of type complex and the sign argument is missing, then format = "(*('(',g0,',',g0,')',:,','))".
  2. If val is of type complex and sign = .true., then format = "(*('(',sp,g0,',',g0,')',:,','))".
  3. If val is of type integer or real and the sign argument is missing, then format = "(*(g0,:,','))".
  4. If val is of type integer or real and the sign argument is missing, then format = "(*(sp,g0,:,','))".
  5. If val is neither integer nor real nor complex, then format = "(*(g0,:,','))". However,
    1. If val is of type character, then the blank characters are trimmed form the right side of each value.
    2. If val is of type logical, then the values TRUE and FALSE are output, corresponding to .true. and .false..
In all cases, the default separator is a comma ,.)
[in]length: The input scalar of type integer of default kind IK representing the length of the output string.
If provided, the output string will be preallocated with the requested input length. Then, the value will be written to it.
If missing, the blank characters on both ends of the output string will be trimmed.
(optional, default = automatically determined such that all leading and trailing blank characters are removed)
[in]signed: The input scalar of type logical of default kind LK. If .true., the output, if it is a number, will be signed (+ or -).
Otherwise, the output numbers will be unsigned. The value of signed is ignored if the optional input argument format is present.
(optional, default = .false.)
Returns
str : The output allocatable scalar of type character of default kind SK containing the input value as a string with the specified format.


Possible calling interfaces

use pm_val2str, only: getStr
str = getStr(val, format = format, length = length, signed = signed)
str = getStr(val(:), format = format, length = length, signed = signed)
str = getStr(val(:,:), format = format, length = length, signed = signed)
Generate and return the conversion of the input value to an output Fortran string,...
Definition: pm_val2str.F90:167
This module contains the generic procedures for converting values of different types and kinds to For...
Definition: pm_val2str.F90:58
Remarks
The procedures under discussion are pure.
Warning
If the input argument length is present, its value must be large enough to contain the full input value.
See also
getStr
setStr
getInt
setInt
getLogical
setLogical
getComplex
setComplex
getReal
setReal


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_kind, only: IKL, IKS, IKD, IKH
5 use pm_kind, only: CKL, CKD, CKH
6 use pm_kind, only: RKL, RKD, RKH
7 use pm_io, only: display_type
8 use pm_val2str, only: getStr
9
10 implicit none
11
12 type(display_type) :: disp
13 disp = display_type(file = "main.out.F90")
14
15 call disp%skip()
16 call disp%show("getStr('paramonte')")
17 call disp%show( getStr('paramonte') , deliml = SK_"""" )
18 call disp%skip()
19
20 call disp%skip()
21 call disp%show("getStr(' paramonte')")
22 call disp%show( getStr(' paramonte') , deliml = SK_"""" )
23 call disp%skip()
24
25 call disp%skip()
26 call disp%show("getStr(' paramonte ')")
27 call disp%show( getStr(' paramonte ') , deliml = SK_"""" )
28 call disp%skip()
29
30 call disp%skip()
31 call disp%show("getStr(['paramonte', 'library '])")
32 call disp%show( getStr(['paramonte', 'library ']) , deliml = SK_"""" )
33 call disp%skip()
34
35 call disp%skip()
36 call disp%show("getStr(['paramonte ', ' library '])")
37 call disp%show( getStr(['paramonte ', ' library ']) , deliml = SK_"""" )
38 call disp%skip()
39
40 call disp%skip()
41 call disp%show("getStr(-1_IKL)")
42 call disp%show( getStr(-1_IKL) , deliml = SK_"""" )
43 call disp%skip()
44
45 call disp%skip()
46 call disp%show("getStr(.true.)")
47 call disp%show( getStr(.true.) , deliml = SK_"""" )
48 call disp%skip()
49
50 call disp%skip()
51 call disp%show("getStr(.false.)")
52 call disp%show( getStr(.false.) , deliml = SK_"""" )
53 call disp%skip()
54
55 call disp%skip()
56 call disp%show("getStr(123_IKS)")
57 call disp%show( getStr(123_IKS) , deliml = SK_"""" )
58 call disp%skip()
59
60 call disp%skip()
61 call disp%show("getStr(1234_IKD, signed = .true._LK)")
62 call disp%show( getStr(1234_IKD, signed = .true._LK) , deliml = SK_"""" )
63 call disp%skip()
64
65 call disp%skip()
66 call disp%show("getStr(1234_IKD, length = 10_IK, signed = .true._LK)")
67 call disp%show( getStr(1234_IKD, length = 10_IK, signed = .true._LK) , deliml = SK_"""" )
68 call disp%skip()
69
70 call disp%skip()
71 call disp%show("getStr(987654321_IKH, length = 15_IK)")
72 call disp%show( getStr(987654321_IKH, length = 15_IK) , deliml = SK_"""" )
73 call disp%skip()
74
75 call disp%skip()
76 call disp%show("getStr(987654321_IKH, length = 15_IK, format = SK_'(1I15)')")
77 call disp%show( getStr(987654321_IKH, length = 15_IK, format = SK_'(1I15)') , deliml = SK_"""" )
78 call disp%skip()
79
80 call disp%skip()
81 call disp%show("getStr(123._RKL)")
82 call disp%show( getStr(123._RKL) )
83 call disp%skip()
84
85 call disp%skip()
86 call disp%show("getStr(123._RKD, format = SK_'(E25.15)') ! use scientific notation with a width of 25.")
87 call disp%show( getStr(123._RKD, format = SK_'(E25.15)') , deliml = SK_"""" )
88 call disp%skip()
89
90 call disp%skip()
91 call disp%show("getStr([9.e100_RKH, -123456._RKH])")
92 call disp%show( getStr([9.e100_RKH, -123456._RKH]) , deliml = SK_"""" )
93 call disp%skip()
94
95 call disp%skip()
96 call disp%show("getStr((1._CKH,-1._CKH))")
97 call disp%show( getStr((1._CKH,-1._CKH)) , deliml = SK_"""" )
98 call disp%skip()
99
100 call disp%skip()
101 call disp%show("getStr([(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK)")
102 call disp%show( getStr([(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK) , deliml = SK_"""" )
103 call disp%skip()
104
105 call disp%skip()
106 call disp%show("getStr(reshape([(1._CKL,-1._CKL), (2._CKL,-2._CKL), (3._CKL,-3._CKL), (4._CKL,-4._CKL)], shape = [2,2]), signed = .true._LK) ! input object of rank 2")
107 call disp%show( getStr(reshape([(1._CKL,-1._CKL), (2._CKL,-2._CKL), (3._CKL,-3._CKL), (4._CKL,-4._CKL)], shape = [2,2]), signed = .true._LK) , deliml = SK_"""" )
108 call disp%skip()
109
110end program example
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
Definition: pm_kind.F90:843
integer, parameter IKS
The single-precision integer kind in Fortran mode. On most platforms, this is a 32-bit integer kind.
Definition: pm_kind.F90:563
integer, parameter IKL
The scalar integer constant of intrinsic default kind, representing the lowest range integer kind typ...
Definition: pm_kind.F90:749
integer, parameter IKH
The scalar integer constant of intrinsic default kind, representing the highest range integer kind ty...
Definition: pm_kind.F90:828
integer, parameter RKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision real kind ty...
Definition: pm_kind.F90:779
integer, parameter CKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision complex kind...
Definition: pm_kind.F90:764
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
Definition: pm_kind.F90:571
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
Definition: pm_kind.F90:568
integer, parameter IKD
The double precision integer kind in Fortran mode. On most platforms, this is a 64-bit integer kind.
Definition: pm_kind.F90:564
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Definition: pm_kind.F90:858
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2getStr('paramonte')
3"paramonte"
4
5
6getStr(' paramonte')
7" paramonte"
8
9
10getStr(' paramonte ')
11" paramonte"
12
13
14getStr(['paramonte', 'library '])
15"paramonte, library, "
16
17
18getStr(['paramonte ', ' library '])
19"paramonte, library")) "
20
21
22getStr(-1_IKL)
23"-1"
24
25
26getStr(.true.)
27"TRUE"
28
29
30getStr(.false.)
31"FALSE"
32
33
34getStr(123_IKS)
35"123"
36
37
38getStr(1234_IKD, signed = .true._LK)
39"+1234"
40
41
42getStr(1234_IKD, length = 10_IK, signed = .true._LK)
43"+1234 "
44
45
46getStr(987654321_IKH, length = 15_IK)
47"987654321 "
48
49
50getStr(987654321_IKH, length = 15_IK, format = SK_'(1I15)')
51" 987654321"
52
53
54getStr(123._RKL)
55123.000000
56
57
58getStr(123._RKD, format = SK_'(E25.15)') ! use scientific notation with a width of 25.
59" 0.123000000000000E+03"
60
61
62getStr([9.e100_RKH, -123456._RKH])
63"0.899999999999999999999999999999999983E+101, -123456.000000000000000000000000000000"
64
65
66getStr((1._CKH,-1._CKH))
67"(1.00000000000000000000000000000000000, -1.00000000000000000000000000000000000)"
68
69
70getStr([(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK)
71"(+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000)"
72
73
74getStr(reshape([(1._CKL,-1._CKL), (2._CKL,-2._CKL), (3._CKL,-3._CKL), (4._CKL,-4._CKL)], shape = [2,2]), signed = .true._LK) ! input object of rank 2
75"(+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+3.00000000, -3.00000000), (+4.00000000, -4.00000000)"
76
77
Test:
test_pm_val2str
Bug:

Status: Unresolved
Source: GNU Fortran Compiler gfortran version 10.3-11
Description: The GNU Fortran Compiler gfortran cannot handle IO of string arrays of zero-length of non-zero size in getStr() in assertion check blocks.
The issue happens to be with deferred-length strings character(:,SKG), allocatable :: Array(:).
The Intel Classic Fortran Compiler ifort can handle this properly.

Remedy (as of ParaMonte Library version 2.0.0): Avoid deferred-length strings where GNU Fortran Compiler gfortran cannot compile.
Bug:
Todo:
Low Priority: This generic interface can be expanded to arrays of higher dimensions than two.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 167 of file pm_val2str.F90.


The documentation for this interface was generated from the following file: