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.
- Returns
- Parameters
-
[out] | str | : The output scalar of type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) containing the input value as a string with the specified format.
|
[out] | length | : The output scalar of type integer of default kind IK representing the length of the record written to the output string (i.e., str(1:length) is the record).
|
[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 followed by white space character , .) |
[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. ) |
Possible calling interfaces ⛓
call setStr(str, val,
format = format, length
= length, signed
= signed)
call setStr(str, val(:),
format = format, length
= length, signed
= signed)
call setStr(str, 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
- The length of the input argument
str
must be large enough to contain the full input value.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
- See also
- getStr
setStr
getInt
setInt
getLogical
setLogical
getComplex
setComplex
getReal
setReal
Example usage ⛓
14 character(
1023, SK) :: str
16 type(display_type) :: disp
20 call disp%show(
"call setStr(str, lenstr, 'paramonte')")
21 call setStr(str, lenstr,
'paramonte')
25 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
29 call disp%show(
"call setStr(str, lenstr, ' paramonte')")
30 call setStr(str, lenstr,
' paramonte')
34 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
38 call disp%show(
"call setStr(str, lenstr, ' paramonte ')")
39 call setStr(str, lenstr,
' paramonte ')
43 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
47 call disp%show(
"call setStr(str, lenstr, ['paramonte', 'library '])")
48 call setStr(str, lenstr, [
'paramonte',
'library '])
52 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
56 call disp%show(
"call setStr(str, lenstr, ['paramonte ', ' library '])")
57 call setStr(str, lenstr, [
'paramonte ',
' library '])
61 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
65 call disp%show(
"call setStr(str, lenstr, .true.)")
66 call setStr(str, lenstr,
.true.)
70 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
74 call disp%show(
"call setStr(str, lenstr, .false.)")
75 call setStr(str, lenstr,
.false.)
79 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
83 call disp%show(
"call setStr(str, lenstr, -1_IKL)")
84 call setStr(str, lenstr,
-1_IKL)
88 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
92 call disp%show(
"call setStr(str, lenstr, 1234_IKS, signed = .true._LK)")
93 call setStr(str, lenstr,
1234_IKS, signed
= .true._LK)
97 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
101 call disp%show(
"call setStr(str, lenstr, 987654321_IKD)")
102 call setStr(str, lenstr,
987654321_IKD)
106 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
110 call disp%show(
"call setStr(str, lenstr, 987654321_IKH)")
111 call setStr(str, lenstr,
987654321_IKH)
115 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
119 call disp%show(
"call setStr(str, lenstr, 987654321_IKD, format = '(I15)')")
120 call setStr(str, lenstr,
987654321_IKD,
format = '(I15)')
124 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
128 call disp%show(
"call setStr(str, lenstr, 123._RKL)")
129 call setStr(str, lenstr,
123._RKL)
133 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
137 call disp%show(
"call setStr(str, lenstr, 123._RKS)")
138 call setStr(str, lenstr,
123._RKS)
142 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
146 call disp%show(
"call setStr(str, lenstr, 123._RKD, format = '(E25.15)') ! use scientific notation with a width of 25.")
147 call setStr(str, lenstr,
123._RKD,
format = '(E25.15)')
151 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
155 call disp%show(
"call setStr(str, lenstr, [huge(0._RKH), -123456._RKH])")
156 call setStr(str, lenstr, [
huge(
0._RKH),
-123456._RKH])
160 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
164 call disp%show(
"call setStr(str, lenstr, (1._CKH,-1._CKH))")
165 call setStr(str, lenstr, (
1._CKH,
-1._CKH))
169 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
173 call disp%show(
"call setStr(str, lenstr, [(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK)")
174 call setStr(str, lenstr, [(
1._CKD,
-1._CKD), (
2._CKD,
-2._CKD)], signed
= .true._LK)
178 call disp%show( str(
1:lenstr) , deliml
= SK_
"""" )
182 call disp%show(
"call setStr(str, lenstr, reshape([(1._CKS,-1._CKS), (2._CKS,-2._CKS), (3._CKS,-3._CKS), (4._CKS,-4._CKS)], shape = [2,2]), signed = .true._LK) ! input object of rank 2")
183 call setStr(str, lenstr,
reshape([(
1._CKS,
-1._CKS), (
2._CKS,
-2._CKS), (
3._CKS,
-3._CKS), (
4._CKS,
-4._CKS)], shape
= [
2,
2]), signed
= .true._LK)
187 call disp%show( str(
1:lenstr) , 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 CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
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...
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
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 ⛓
2call setStr(str, lenstr,
'paramonte')
9call setStr(str, lenstr,
' paramonte')
16call setStr(str, lenstr,
' paramonte ')
23call setStr(str, lenstr, [
'paramonte',
'library '])
30call setStr(str, lenstr, [
'paramonte ',
' library '])
37call setStr(str, lenstr,
.true.)
44call setStr(str, lenstr,
.false.)
51call setStr(str, lenstr,
-1_IKL)
58call setStr(str, lenstr,
1234_IKS, signed
= .true._LK)
65call setStr(str, lenstr,
987654321_IKD)
72call setStr(str, lenstr,
987654321_IKH)
79call setStr(str, lenstr,
987654321_IKD,
format = '(I15)')
86call setStr(str, lenstr,
123._RKL)
93call setStr(str, lenstr,
123._RKS)
100call setStr(str, lenstr,
123._RKD,
format = '(E25.15)')
104" 0.123000000000000E+03"
107call setStr(str, lenstr, [
huge(
0._RKH),
-123456._RKH])
111"0.118973149535723176508575932662800702E+4933, -123456.000000000000000000000000000000"
114call setStr(str, lenstr, (
1._CKH,
-1._CKH))
118"(1.00000000000000000000000000000000000, -1.00000000000000000000000000000000000)"
121call setStr(str, lenstr, [(
1._CKD,
-1._CKD), (
2._CKD,
-2._CKD)], signed
= .true._LK)
125"(+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000)"
128call setStr(str, lenstr,
reshape([(
1._CKS,
-1._CKS), (
2._CKS,
-2._CKS), (
3._CKS,
-3._CKS), (
4._CKS,
-4._CKS)], shape
= [
2,
2]), signed
= .true._LK)
132"(+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.
- Todo:
- Low Priority: This generic interface can be expanded to arrays of higher dimensions than two.
- Todo:
- Critical Priority: The default length of fields must be generically defined.
Currently, the maximum length of the fields is set to 127
.
While this number is more than enough precisions of much higher orders available by compilers, it is bound to fail in the distant future.
Therefore, it must be generically set based on the precision
of the fields.
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 1670 of file pm_val2str.F90.