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...
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
-
type css_type (derived type container of scalar string of default kind SK) or
-
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
-
type
character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) or
-
type
integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64) or
-
type
logical of kind any supported by the processor (e.g., LK) or
-
type
complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128) or
-
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 :
-
If
val is of type complex and the sign argument is missing, then format = "(*('(',g0,',',g0,')',:,','))" .
-
If
val is of type complex and sign = .true. , then format = "(*('(',sp,g0,',',g0,')',:,','))" .
-
If
val is of type integer or real and the sign argument is missing, then format = "(*(g0,:,','))" .
-
If
val is of type integer or real and the sign argument is missing, then format = "(*(sp,g0,:,','))" .
-
If
val is neither integer nor real nor complex , then format = "(*(g0,:,','))" . However,
-
If
val is of type character , then the blank characters are trimmed form the right side of each value.
-
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 ⛓
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,...
This module contains the generic procedures for converting values of different types and kinds to For...
- 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 ⛓
12 type(display_type) :: disp
16 call disp%show(
"getStr('paramonte')")
21 call disp%show(
"getStr(' paramonte')")
26 call disp%show(
"getStr(' paramonte ')")
31 call disp%show(
"getStr(['paramonte', 'library '])")
32 call disp%show(
getStr([
'paramonte',
'library ']) , deliml
= SK_
"""" )
36 call disp%show(
"getStr(['paramonte ', ' library '])")
37 call disp%show(
getStr([
'paramonte ',
' library ']) , deliml
= SK_
"""" )
61 call disp%show(
"getStr(1234_IKD, signed = .true._LK)")
62 call disp%show(
getStr(
1234_IKD, signed
= .true._LK) , deliml
= SK_
"""" )
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_
"""" )
71 call disp%show(
"getStr(987654321_IKH, length = 15_IK)")
72 call disp%show(
getStr(
987654321_IKH, length
= 15_IK) , deliml
= SK_
"""" )
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_
"""" )
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_
"""" )
91 call disp%show(
"getStr([9.e100_RKH, -123456._RKH])")
92 call disp%show(
getStr([
9.e100_RKH,
-123456._RKH]) , deliml
= SK_
"""" )
96 call disp%show(
"getStr((1._CKH,-1._CKH))")
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_
"""" )
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_
"""" )
This is a generic method of the derived type display_type with pass attribute.
This is a generic method of the derived type display_type with pass attribute.
This module contains classes and procedures for input/output (IO) or generic display operations on st...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter CKH
The scalar integer constant of intrinsic default kind, representing the highest-precision complex kin...
integer, parameter IKS
The single-precision integer kind in Fortran mode. On most platforms, this is a 32-bit integer kind.
integer, parameter IKL
The scalar integer constant of intrinsic default kind, representing the lowest range integer kind typ...
integer, parameter IKH
The scalar integer constant of intrinsic default kind, representing the highest range integer kind ty...
integer, parameter RKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision real kind ty...
integer, parameter CKL
The scalar integer constant of intrinsic default kind, representing the lowest-precision complex kind...
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter CKD
The double precision complex kind in Fortran mode. On most platforms, this is a 64-bit real kind.
integer, parameter RKD
The double precision real kind in Fortran mode. On most platforms, this is an 64-bit real kind.
integer, parameter IKD
The double precision integer kind in Fortran mode. On most platforms, this is a 64-bit integer kind.
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
integer, parameter RKH
The scalar integer constant of intrinsic default kind, representing the highest-precision real kind t...
Generate and return an object of type display_type.
Example Unix compile command via Intel ifort
compiler ⛓
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example Windows Batch compile command via Intel ifort
compiler ⛓
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
Example Unix / MinGW compile command via GNU gfortran
compiler ⛓
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
Example output ⛓
14getStr([
'paramonte',
'library '])
18getStr([
'paramonte ',
' library '])
19"paramonte, library"))
"
38getStr(1234_IKD, signed = .true._LK)
42getStr(1234_IKD, length = 10_IK, signed = .true._LK)
46getStr(987654321_IKH, length = 15_IK)
50getStr(987654321_IKH, length = 15_IK, format = SK_'(1I15)')
58getStr(123._RKD, format = SK_'(E25.15)') ! use scientific notation with a width of 25.
59" 0.123000000000000E+03"
62getStr([9.e100_RKH, -123456._RKH])
63"0.899999999999999999999999999999999983E+101,
-123456.000000000000000000000000000000"
66getStr((1._CKH,-1._CKH))
67"(
1.00000000000000000000000000000000000,
-1.00000000000000000000000000000000000)
"
70getStr([(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK)
71"(
+1.0000000000000000,
-1.0000000000000000), (
+2.0000000000000000,
-2.0000000000000000)
"
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)
"
- 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.
-
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.
-
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.
- Copyright
- Computational Data Science Lab
- 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.