ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_val2str::setStr 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.

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
  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 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

use pm_val2str, only: setStr
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...
Definition: pm_val2str.F90:58
Remarks
The procedures under discussion are pure.
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

1program example
2
3 use pm_kind, only: IK, LK
4 use pm_kind, only: SK ! All other processor string kinds are also suppored.
5 use pm_kind, only: IKL, IKS, IKD, IKH
6 use pm_kind, only: CKL, CKS, CKD, CKH
7 use pm_kind, only: RKL, RKS, RKD, RKH
8 use pm_io, only: display_type
9 use pm_val2str, only: setStr
10
11 implicit none
12
13 integer(IK) :: lenstr
14 character(1023, SK) :: str
15
16 type(display_type) :: disp
17 disp = display_type(file = "main.out.F90")
18
19 call disp%skip()
20 call disp%show("call setStr(str, lenstr, 'paramonte')")
21 call setStr(str, lenstr, 'paramonte')
22 call disp%show("lenstr")
23 call disp%show( lenstr )
24 call disp%show("str(1:lenstr)")
25 call disp%show( str(1:lenstr) , deliml = SK_"""" )
26 call disp%skip()
27
28 call disp%skip()
29 call disp%show("call setStr(str, lenstr, ' paramonte')")
30 call setStr(str, lenstr, ' paramonte')
31 call disp%show("lenstr")
32 call disp%show( lenstr )
33 call disp%show("str(1:lenstr)")
34 call disp%show( str(1:lenstr) , deliml = SK_"""" )
35 call disp%skip()
36
37 call disp%skip()
38 call disp%show("call setStr(str, lenstr, ' paramonte ')")
39 call setStr(str, lenstr, ' paramonte ')
40 call disp%show("lenstr")
41 call disp%show( lenstr )
42 call disp%show("str(1:lenstr)")
43 call disp%show( str(1:lenstr) , deliml = SK_"""" )
44 call disp%skip()
45
46 call disp%skip()
47 call disp%show("call setStr(str, lenstr, ['paramonte', 'library '])")
48 call setStr(str, lenstr, ['paramonte', 'library '])
49 call disp%show("lenstr")
50 call disp%show( lenstr )
51 call disp%show("str(1:lenstr)")
52 call disp%show( str(1:lenstr) , deliml = SK_"""" )
53 call disp%skip()
54
55 call disp%skip()
56 call disp%show("call setStr(str, lenstr, ['paramonte ', ' library '])")
57 call setStr(str, lenstr, ['paramonte ', ' library '])
58 call disp%show("lenstr")
59 call disp%show( lenstr )
60 call disp%show("str(1:lenstr)")
61 call disp%show( str(1:lenstr) , deliml = SK_"""" )
62 call disp%skip()
63
64 call disp%skip()
65 call disp%show("call setStr(str, lenstr, .true.)")
66 call setStr(str, lenstr, .true.)
67 call disp%show("lenstr")
68 call disp%show( lenstr )
69 call disp%show("str(1:lenstr)")
70 call disp%show( str(1:lenstr) , deliml = SK_"""" )
71 call disp%skip()
72
73 call disp%skip()
74 call disp%show("call setStr(str, lenstr, .false.)")
75 call setStr(str, lenstr, .false.)
76 call disp%show("lenstr")
77 call disp%show( lenstr )
78 call disp%show("str(1:lenstr)")
79 call disp%show( str(1:lenstr) , deliml = SK_"""" )
80 call disp%skip()
81
82 call disp%skip()
83 call disp%show("call setStr(str, lenstr, -1_IKL)")
84 call setStr(str, lenstr, -1_IKL)
85 call disp%show("lenstr")
86 call disp%show( lenstr )
87 call disp%show("str(1:lenstr)")
88 call disp%show( str(1:lenstr) , deliml = SK_"""" )
89 call disp%skip()
90
91 call disp%skip()
92 call disp%show("call setStr(str, lenstr, 1234_IKS, signed = .true._LK)")
93 call setStr(str, lenstr, 1234_IKS, signed = .true._LK)
94 call disp%show("lenstr")
95 call disp%show( lenstr )
96 call disp%show("str(1:lenstr)")
97 call disp%show( str(1:lenstr) , deliml = SK_"""" )
98 call disp%skip()
99
100 call disp%skip()
101 call disp%show("call setStr(str, lenstr, 987654321_IKD)")
102 call setStr(str, lenstr, 987654321_IKD)
103 call disp%show("lenstr")
104 call disp%show( lenstr )
105 call disp%show("str(1:lenstr)")
106 call disp%show( str(1:lenstr) , deliml = SK_"""" )
107 call disp%skip()
108
109 call disp%skip()
110 call disp%show("call setStr(str, lenstr, 987654321_IKH)")
111 call setStr(str, lenstr, 987654321_IKH)
112 call disp%show("lenstr")
113 call disp%show( lenstr )
114 call disp%show("str(1:lenstr)")
115 call disp%show( str(1:lenstr) , deliml = SK_"""" )
116 call disp%skip()
117
118 call disp%skip()
119 call disp%show("call setStr(str, lenstr, 987654321_IKD, format = '(I15)')")
120 call setStr(str, lenstr, 987654321_IKD, format = '(I15)')
121 call disp%show("lenstr")
122 call disp%show( lenstr )
123 call disp%show("str(1:lenstr)")
124 call disp%show( str(1:lenstr) , deliml = SK_"""" )
125 call disp%skip()
126
127 call disp%skip()
128 call disp%show("call setStr(str, lenstr, 123._RKL)")
129 call setStr(str, lenstr, 123._RKL)
130 call disp%show("lenstr")
131 call disp%show( lenstr )
132 call disp%show("str(1:lenstr)")
133 call disp%show( str(1:lenstr) , deliml = SK_"""" )
134 call disp%skip()
135
136 call disp%skip()
137 call disp%show("call setStr(str, lenstr, 123._RKS)")
138 call setStr(str, lenstr, 123._RKS)
139 call disp%show("lenstr")
140 call disp%show( lenstr )
141 call disp%show("str(1:lenstr)")
142 call disp%show( str(1:lenstr) , deliml = SK_"""" )
143 call disp%skip()
144
145 call disp%skip()
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)')
148 call disp%show("lenstr")
149 call disp%show( lenstr )
150 call disp%show("str(1:lenstr)")
151 call disp%show( str(1:lenstr) , deliml = SK_"""" )
152 call disp%skip()
153
154 call disp%skip()
155 call disp%show("call setStr(str, lenstr, [huge(0._RKH), -123456._RKH])")
156 call setStr(str, lenstr, [huge(0._RKH), -123456._RKH])
157 call disp%show("lenstr")
158 call disp%show( lenstr )
159 call disp%show("str(1:lenstr)")
160 call disp%show( str(1:lenstr) , deliml = SK_"""" )
161 call disp%skip()
162
163 call disp%skip()
164 call disp%show("call setStr(str, lenstr, (1._CKH,-1._CKH))")
165 call setStr(str, lenstr, (1._CKH,-1._CKH))
166 call disp%show("lenstr")
167 call disp%show( lenstr )
168 call disp%show("str(1:lenstr)")
169 call disp%show( str(1:lenstr) , deliml = SK_"""" )
170 call disp%skip()
171
172 call disp%skip()
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)
175 call disp%show("lenstr")
176 call disp%show( lenstr )
177 call disp%show("str(1:lenstr)")
178 call disp%show( str(1:lenstr) , deliml = SK_"""" )
179 call disp%skip()
180
181 call disp%skip()
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)
184 call disp%show("lenstr")
185 call disp%show( lenstr )
186 call disp%show("str(1:lenstr)")
187 call disp%show( str(1:lenstr) , deliml = SK_"""" )
188 call disp%skip()
189
190end 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 CKS
The single-precision complex kind in Fortran mode. On most platforms, this is a 32-bit real kind.
Definition: pm_kind.F90:570
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
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
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
2call setStr(str, lenstr, 'paramonte')
3lenstr
4+9
5str(1:lenstr)
6"paramonte"
7
8
9call setStr(str, lenstr, ' paramonte')
10lenstr
11+11
12str(1:lenstr)
13" paramonte"
14
15
16call setStr(str, lenstr, ' paramonte ')
17lenstr
18+11
19str(1:lenstr)
20" paramonte"
21
22
23call setStr(str, lenstr, ['paramonte', 'library '])
24lenstr
25+18
26str(1:lenstr)
27"paramonte, library"
28
29
30call setStr(str, lenstr, ['paramonte ', ' library '])
31lenstr
32+20
33str(1:lenstr)
34"paramonte, library"
35
36
37call setStr(str, lenstr, .true.)
38lenstr
39+4
40str(1:lenstr)
41"TRUE"
42
43
44call setStr(str, lenstr, .false.)
45lenstr
46+5
47str(1:lenstr)
48"FALSE"
49
50
51call setStr(str, lenstr, -1_IKL)
52lenstr
53+2
54str(1:lenstr)
55"-1"
56
57
58call setStr(str, lenstr, 1234_IKS, signed = .true._LK)
59lenstr
60+5
61str(1:lenstr)
62"+1234"
63
64
65call setStr(str, lenstr, 987654321_IKD)
66lenstr
67+9
68str(1:lenstr)
69"987654321"
70
71
72call setStr(str, lenstr, 987654321_IKH)
73lenstr
74+9
75str(1:lenstr)
76"987654321"
77
78
79call setStr(str, lenstr, 987654321_IKD, format = '(I15)')
80lenstr
81+15
82str(1:lenstr)
83" 987654321"
84
85
86call setStr(str, lenstr, 123._RKL)
87lenstr
88+10
89str(1:lenstr)
90"123.000000"
91
92
93call setStr(str, lenstr, 123._RKS)
94lenstr
95+10
96str(1:lenstr)
97"123.000000"
98
99
100call setStr(str, lenstr, 123._RKD, format = '(E25.15)') ! use scientific notation with a width of 25.
101lenstr
102+25
103str(1:lenstr)
104" 0.123000000000000E+03"
105
106
107call setStr(str, lenstr, [huge(0._RKH), -123456._RKH])
108lenstr
109+84
110str(1:lenstr)
111"0.118973149535723176508575932662800702E+4933, -123456.000000000000000000000000000000"
112
113
114call setStr(str, lenstr, (1._CKH,-1._CKH))
115lenstr
116+79
117str(1:lenstr)
118"(1.00000000000000000000000000000000000, -1.00000000000000000000000000000000000)"
119
120
121call setStr(str, lenstr, [(1._CKD,-1._CKD), (2._CKD,-2._CKD)], signed = .true._LK)
122lenstr
123+86
124str(1:lenstr)
125"(+1.0000000000000000, -1.0000000000000000), (+2.0000000000000000, -2.0000000000000000)"
126
127
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) ! input object of rank 2
129lenstr
130+110
131str(1:lenstr)
132"(+1.00000000, -1.00000000), (+2.00000000, -2.00000000), (+3.00000000, -3.00000000), (+4.00000000, -4.00000000)"
133
134
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.

  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 at Austin

Definition at line 1670 of file pm_val2str.F90.


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