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

Generate and return the best-guess field separator of a (sequential-access) file stored in the input file. More...

Detailed Description

Generate and return the best-guess field separator of a (sequential-access) file stored in the input file.

The current algorithm takes an input string from the user containing the set of best-guess single-character separators.
It then counts the frequency of the separators in the first two lines from the current file position.
If the file format is list-directed or CSV, the searcher will skip singly or doubly quoted strings in each line.
The search will be also skipped into the next line if an opening quotation does not close within the same line (characteristic of CSV files).
Finally, the first input separator whose frequency is the same in both lines is returned as the potential field separator of the file.
At the end of the search, the file position is returned to the original point at entry to the file.

Parameters
[in]file: The input scalar character of default kind SK containing the path to the file whose separator is to be inferred.
On input, the file position will be rewound to the starting point in the file and the file is closed upon return.
If search from a particular point in the file is desirable, open the file first and pass the file unit as input to this generic interface.
(optional. It must be present if and only if the input argument unit is missing.)
[in]unit: The input scalar integer of default kind IK containing the unit of the connected file whose separator is to be inferred.
(optional. It must be present if and only if the input argument file is missing.)
[in]seps: The input object that can be,
  1. a scalar of type character of default kind SK of arbitrary length type parameter, each character of which will be considered as a potential field separator in the file records.
    This form of inputting seps is useful when all potential separators are single characters.
  2. a vector of type css_type container of arbitrary size, each element of which will be considered as a potential field separator in the file records.
    This form of inputting seps is useful when the potential separators have differing length type parameters.
    If there is only one separator candidate, simply wrap the scalar container in the Fortran intrinsic vector notation [seps] and pass it to the interface.
    In such a case, the output sep is either
    1. the input seps implying that sep is the potential separator in the file record, or
    2. is an empty string implying that the input seps is not the record separator, or otherwise, an error occurred.
[in]form: The input scalar constant that can be any of the following:
  1. the constant csv or an object of type csv_type, implying that the contents quoted strings must be excluded from the search for the field separators.
  2. the constant fld or an object of type fld_type, implying that the contents quoted strings must be excluded from the search for the field separators.
    Additionally, any multiple adjacent appearances of (unquoted) blank characters will be counted as one separator instance.
(optional. default = unknown)
[out]nfield: The input scalar integer of default kind IK containing the number of fields (i.e., the number of output sep instances per file record plus 1) identified in each row of file, separated by the output separator.
If no separator is identified (i.e., the output sep is empty) and no runtime IO error occurs, the output value for nfield is 1 implying that there is only one field in the file record.
(optional.)
[in,out]iomsg: The input/output scalar character of default kind SK containing the error message, if any error occurs.
A length type parameter value of LEN_IOMSG is generally sufficient for iomsg to contain the output error messages.
(optional. If missing, no information other than an empty output sep will be given if the algorithm fails.)
Returns
sep : The output allocatable scalar character of default kind SK that will contain the inferred separator if the algorithm returns successfully.
Otherwise, the output sep will be set to an empty string if,
  1. the target file does not exist,
  2. an IO error occurs while reading the file,
  3. the algorithm fails to detect the separator.


Possible calling interfaces

use pm_io, only: getFieldSep
character(:, SK), allocatable :: sep
! read from the current position in unit.
sep = getFieldSep(unit, seps, iomsg = iomsg)
sep = getFieldSep(unit, seps, form, iomsg = iomsg)
sep = getFieldSep(unit, seps, nfield, iomsg = iomsg)
sep = getFieldSep(unit, seps, form, nfield, iomsg = iomsg)
! read from the starting position in file.
sep = getFieldSep(file, seps, iomsg = iomsg)
sep = getFieldSep(file, seps, form, iomsg = iomsg)
sep = getFieldSep(file, seps, nfield, iomsg = iomsg)
sep = getFieldSep(file, seps, form, nfield, iomsg = iomsg)
Generate and return the best-guess field separator of a (sequential-access) file stored in the input ...
Definition: pm_io.F90:9407
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
Warning
The condition 0 < len(seps) must hold for the corresponding input arguments.
The condition 0 < size(seps) must hold for the corresponding input arguments.
The condition all(0 < [(len(seps(i)val), i = 1, size(seps))] must hold for the corresponding input arguments.
Remarks
The procedures under discussion are impure.
See also
setRecordFrom
getContentsFrom
setContentsFrom
isPreconnected
getFileUnit


Example usage

1program example
2
3 use iso_fortran_env, only: output_unit, input_unit, error_unit
4 use pm_str, only: NLC
5 use pm_val2str, only: getStr
6 use pm_kind, only: SK, IK, LK
7 use pm_io, only: display_type
8 use pm_distUnif, only: getUnifRand
9 use pm_io, only: getErrTableWrite
10 use pm_io, only: getContentsFrom
11 use pm_io, only: getFieldSep, csv, fld
12 use pm_io, only: setContentsTo
13
14 implicit none
15
16 integer(IK) :: nfield
17 character(:, SK), allocatable :: file
18 type(display_type) :: disp
19
20 disp = display_type(file = "main.out.F90")
21
22 call disp%skip
23 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
24 call disp%show("!Search for single-character field separators.")
25 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
26 call disp%skip
27
28 block
29 use pm_kind, only: SKG => SK
30 character(2,SKG), allocatable :: table(:,:)
31 call disp%skip
32 call disp%show("table = getUnifRand('aa', 'zz', 3_IK, 6_IK)")
33 table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
34 call disp%show("table")
35 call disp%show( table , deliml = SK_"""" )
36 call disp%show("file = 'temp.temp'")
37 file = 'temp.temp'
38 call disp%show("if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'")
39 if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'
40 call disp%show("getContentsFrom(file)")
41 call disp%show( getContentsFrom(file) )
42 call disp%show("getFieldSep(file, seps = SKG_';|, ')")
43 call disp%show( getFieldSep(file, seps = SKG_';|, ') , deliml = SK_"""" )
44 call disp%show("getFieldSep(file, seps = SKG_';|, ', form = csv)")
45 call disp%show( getFieldSep(file, seps = SKG_';|, ', form = csv) , deliml = SK_"""" )
46 call disp%show("getFieldSep(file, seps = SKG_';|, ', form = csv, nfield = nfield)")
47 call disp%show( getFieldSep(file, seps = SKG_';|, ', form = csv, nfield = nfield) , deliml = SK_"""" )
48 call disp%show("nfield")
49 call disp%show( nfield )
50 call disp%skip
51 call disp%show("call setContentsTo(file, contents = repeat(SK_'""a"", '//getStr([1, 2, 3])//NLC, 2_IK))")
52 call setContentsTo(file, contents = repeat(SK_"""a"", "//getStr([1, 2, 3])//NLC, 2_IK))
53 call disp%show("getContentsFrom(file)")
54 call disp%show( getContentsFrom(file) )
55 call disp%show("getFieldSep(file, seps = SKG_', ')")
56 call disp%show( getFieldSep(file, seps = SKG_', ') , deliml = SK_"""" )
57 call disp%show("getFieldSep(file, seps = SKG_' ,')")
58 call disp%show( getFieldSep(file, seps = SKG_' ,') , deliml = SK_"""" )
59 call disp%skip
60 call disp%show("call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))")
61 call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))
62 call disp%show("getContentsFrom(file)")
63 call disp%show( getContentsFrom(file) )
64 call disp%show("getFieldSep(file, seps = SKG_', ', nfield = nfield)")
65 call disp%show( getFieldSep(file, seps = SKG_', ', nfield = nfield) , deliml = SK_"""" )
66 call disp%show("nfield")
67 call disp%show( nfield )
68 call disp%show("getFieldSep(file, seps = SKG_' ,', nfield = nfield)")
69 call disp%show( getFieldSep(file, seps = SKG_' ,', nfield = nfield) , deliml = SK_"""" )
70 call disp%show("nfield")
71 call disp%show( nfield )
72 call disp%show("getFieldSep(file, seps = SKG_', ', form = fld, nfield = nfield)")
73 call disp%show( getFieldSep(file, seps = SKG_', ', form = fld, nfield = nfield) , deliml = SK_"""" )
74 call disp%show("nfield")
75 call disp%show( nfield )
76 call disp%show("getFieldSep(file, seps = SKG_' ,', form = fld, nfield = nfield)")
77 call disp%show( getFieldSep(file, seps = SKG_' ,', form = fld, nfield = nfield) , deliml = SK_"""" )
78 call disp%show("nfield")
79 call disp%show( nfield )
80 call disp%skip
81 call disp%show("call setContentsTo(file, contents = SK_'""a,"",'//getStr([1, 2, 3])//NLC//SK_'""a"",'//getStr([1, 2, 3])//NLC)")
82 call setContentsTo(file, contents = SK_"""a,"","//getStr([1, 2, 3])//NLC//SK_"""a"","//getStr([1, 2, 3])//NLC)
83 call disp%show("getContentsFrom(file)")
84 call disp%show( getContentsFrom(file) )
85 call disp%show("getFieldSep(file, seps = SKG_', ')")
86 call disp%show( getFieldSep(file, seps = SKG_', ') , deliml = SK_"""" )
87 call disp%show("getFieldSep(file, seps = SKG_', ', form = csv) ! quoted strings are respected in csv format.")
88 call disp%show( getFieldSep(file, seps = SKG_', ', form = csv) , deliml = SK_"""" )
89 call disp%show("getFieldSep(file, seps = SKG_' ,')")
90 call disp%show( getFieldSep(file, seps = SKG_' ,') , deliml = SK_"""" )
91 call disp%skip
92 call disp%show("call setContentsTo(file, contents = SK_'""a"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC)")
93 call setContentsTo(file, contents = SK_"""a"" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
94 call disp%show("getContentsFrom(file)")
95 call disp%show( getContentsFrom(file) )
96 call disp%show("getFieldSep(file, seps = SKG_' ')")
97 call disp%show( getFieldSep(file, seps = SKG_' ') , deliml = SK_"""" )
98 call disp%show("getFieldSep(file, seps = SKG_' ', form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
99 call disp%show( getFieldSep(file, seps = SKG_' ', form = fld) , deliml = SK_"""" )
100 call disp%show("getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
101 call disp%show( getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) , deliml = SK_"""" )
102 call disp%show("nfield")
103 call disp%show( nfield )
104 call disp%skip
105 call disp%show("call setContentsTo(file, contents = SK_'""a'//NLC//'"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC) ! double-line csv field")
106 call setContentsTo(file, contents = SK_"""a"//NLC//""" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
107 call disp%show("getContentsFrom(file)")
108 call disp%show( getContentsFrom(file) )
109 call disp%show("getFieldSep(file, seps = SKG_',')")
110 call disp%show( getFieldSep(file, seps = SKG_',') , deliml = SK_"""" )
111 call disp%show("getFieldSep(file, seps = SKG_',', form = csv) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
112 call disp%show( getFieldSep(file, seps = SKG_',', form = csv) , deliml = SK_"""" )
113 call disp%show("getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
114 call disp%show( getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) , deliml = SK_"""" )
115 call disp%show("nfield")
116 call disp%show( nfield )
117 call disp%show("getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
118 call disp%show( getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) , deliml = SK_"""" )
119 call disp%show("nfield")
120 call disp%show( nfield )
121 call disp%skip
122 call disp%show("call setContentsTo(file, contents = SK_'""a'//NLC//NLC//'"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC) ! three-line FLD field")
123 call setContentsTo(file, contents = SK_"""a"//NLC//NLC//""" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
124 call disp%show("getContentsFrom(file)")
125 call disp%show( getContentsFrom(file) )
126 call disp%show("getFieldSep(file, seps = SKG_' ')")
127 call disp%show( getFieldSep(file, seps = SKG_' ') , deliml = SK_"""" )
128 call disp%show("getFieldSep(file, seps = SKG_' ', form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
129 call disp%show( getFieldSep(file, seps = SKG_' ', form = fld) , deliml = SK_"""" )
130 call disp%show("getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
131 call disp%show( getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) , deliml = SK_"""" )
132 call disp%show("nfield")
133 call disp%show( nfield )
134 call disp%show("getFieldSep(file, seps = SKG_',', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
135 call disp%show( getFieldSep(file, seps = SKG_',', form = fld, nfield = nfield) , deliml = SK_"""" )
136 call disp%show("nfield")
137 call disp%show( nfield )
138 call disp%skip
139 end block
140
141 call disp%skip
142 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
143 call disp%show("!Retrieve whole string field separators.")
144 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
145 call disp%skip
146
147 block
148 use pm_io, only: css_type
149 use pm_kind, only: SKG => SK
150 character(2,SKG), allocatable :: table(:,:)
151 type(css_type), allocatable :: seps(:)
152 call disp%skip
153 call disp%show("table = getUnifRand('aa', 'zz', 3_IK, 6_IK)")
154 table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
155 call disp%show("table")
156 call disp%show( table , deliml = SK_"""" )
157 call disp%show("file = 'temp.temp'")
158 file = 'temp.temp'
159 call disp%show("if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'")
160 if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'
161 call disp%show("getContentsFrom(file)")
162 call disp%show( getContentsFrom(file) )
163 call disp%show("seps = [css_type(SK_'|||'), css_type(SK_',')]")
164 seps = [css_type(SK_'|||'), css_type(SK_',')]
165 call disp%show("seps")
166 call disp%show( seps , deliml = SK_"""" )
167 call disp%show("getFieldSep(file, seps)")
168 call disp%show( getFieldSep(file, seps) , deliml = SK_"""" )
169 call disp%show("getFieldSep(file, seps, form = csv)")
170 call disp%show( getFieldSep(file, seps, form = csv) , deliml = SK_"""" )
171 call disp%show("getFieldSep(file, seps, form = csv, nfield = nfield)")
172 call disp%show( getFieldSep(file, seps, form = csv, nfield = nfield) , deliml = SK_"""" )
173 call disp%show("nfield")
174 call disp%show( nfield )
175 call disp%skip
176 call disp%show("call setContentsTo(file, contents = repeat(SK_'""a"", '//getStr([1, 2, 3])//NLC, 2_IK))")
177 call setContentsTo(file, contents = repeat(SK_"""a"", "//getStr([1, 2, 3])//NLC, 2_IK))
178 call disp%show("getContentsFrom(file)")
179 call disp%show( getContentsFrom(file) )
180 call disp%show("seps = css_type([SK_',', SK_' '], trimmed = .true._LK)")
181 seps = css_type([SK_',', SK_' '], trimmed = .true._LK)
182 call disp%show("seps")
183 call disp%show( seps , deliml = SK_"""" )
184 call disp%show("getFieldSep(file, seps)")
185 call disp%show( getFieldSep(file, seps) , deliml = SK_"""" )
186 call disp%show("getFieldSep(file, seps(2:1:-1))")
187 call disp%show( getFieldSep(file, seps(2:1:-1)) , deliml = SK_"""" )
188 call disp%skip
189 call disp%show("call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))")
190 call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))
191 call disp%show("getContentsFrom(file)")
192 call disp%show( getContentsFrom(file) )
193 call disp%show("getFieldSep(file, seps, nfield = nfield)")
194 call disp%show( getFieldSep(file, seps, nfield = nfield) , deliml = SK_"""" )
195 call disp%show("nfield")
196 call disp%show( nfield )
197 call disp%show("getFieldSep(file, seps(2:1:-1), nfield = nfield)")
198 call disp%show( getFieldSep(file, seps(2:1:-1), nfield = nfield) , deliml = SK_"""" )
199 call disp%show("nfield")
200 call disp%show( nfield )
201 call disp%show("getFieldSep(file, seps, form = fld, nfield = nfield)")
202 call disp%show( getFieldSep(file, seps, form = fld, nfield = nfield) , deliml = SK_"""" )
203 call disp%show("nfield")
204 call disp%show( nfield )
205 call disp%show("getFieldSep(file, seps(2:1:-1), form = fld, nfield = nfield)")
206 call disp%show( getFieldSep(file, seps(2:1:-1), form = fld, nfield = nfield) , deliml = SK_"""" )
207 call disp%show("nfield")
208 call disp%show( nfield )
209 call disp%skip
210 call disp%show("call setContentsTo(file, contents = SK_'""a,"",'//getStr([1, 2, 3])//NLC//SK_'""a"",'//getStr([1, 2, 3])//NLC)")
211 call setContentsTo(file, contents = SK_"""a,"","//getStr([1, 2, 3])//NLC//SK_"""a"","//getStr([1, 2, 3])//NLC)
212 call disp%show("getContentsFrom(file)")
213 call disp%show( getContentsFrom(file) )
214 call disp%show("getFieldSep(file, seps)")
215 call disp%show( getFieldSep(file, seps) , deliml = SK_"""" )
216 call disp%show("getFieldSep(file, seps, form = csv) ! quoted strings are respected in csv format.")
217 call disp%show( getFieldSep(file, seps, form = csv) , deliml = SK_"""" )
218 call disp%show("getFieldSep(file, seps(2:1:-1))")
219 call disp%show( getFieldSep(file, seps(2:1:-1)) , deliml = SK_"""" )
220 call disp%skip
221 call disp%show("call setContentsTo(file, contents = SK_'""a"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC)")
222 call setContentsTo(file, contents = SK_"""a"" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
223 call disp%show("getContentsFrom(file)")
224 call disp%show( getContentsFrom(file) )
225 call disp%show("getFieldSep(file, seps(2:2))")
226 call disp%show( getFieldSep(file, seps(2:2)) , deliml = SK_"""" )
227 call disp%show("getFieldSep(file, seps(2:2), form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
228 call disp%show( getFieldSep(file, seps(2:2), form = fld) , deliml = SK_"""" )
229 call disp%show("getFieldSep(file, seps(2:2), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
230 call disp%show( getFieldSep(file, seps(2:2), form = fld, nfield = nfield) , deliml = SK_"""" )
231 call disp%show("nfield")
232 call disp%show( nfield )
233 call disp%skip
234 call disp%show("call setContentsTo(file, contents = SK_'""a'//NLC//'"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC) ! double-line csv field")
235 call setContentsTo(file, contents = SK_"""a"//NLC//""" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
236 call disp%show("getContentsFrom(file)")
237 call disp%show( getContentsFrom(file) )
238 call disp%show("getFieldSep(file, seps(1:1))")
239 call disp%show( getFieldSep(file, seps(1:1)) , deliml = SK_"""" )
240 call disp%show("getFieldSep(file, seps(1:1), form = csv) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
241 call disp%show( getFieldSep(file, seps(1:1), form = csv) , deliml = SK_"""" )
242 call disp%show("getFieldSep(file, seps(1:1), form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
243 call disp%show( getFieldSep(file, seps(1:1), form = csv, nfield = nfield) , deliml = SK_"""" )
244 call disp%show("nfield")
245 call disp%show( nfield )
246 call disp%show("getFieldSep(file, seps(1:1), form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.")
247 call disp%show( getFieldSep(file, seps(1:1), form = csv, nfield = nfield) , deliml = SK_"""" )
248 call disp%show("nfield")
249 call disp%show( nfield )
250 call disp%skip
251 call disp%show("call setContentsTo(file, contents = SK_'""a'//NLC//NLC//'"" '//getStr([1, 2, 3])//NLC//SK_'""a"" '//getStr([1, 2, 3])//NLC) ! three-line FLD field")
252 call setContentsTo(file, contents = SK_"""a"//NLC//NLC//""" "//getStr([1, 2, 3])//NLC//SK_"""a"" "//getStr([1, 2, 3])//NLC)
253 call disp%show("getContentsFrom(file)")
254 call disp%show( getContentsFrom(file) )
255 call disp%show("getFieldSep(file, seps(2:2))")
256 call disp%show( getFieldSep(file, seps(2:2)) , deliml = SK_"""" )
257 call disp%show("getFieldSep(file, seps(2:2), form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
258 call disp%show( getFieldSep(file, seps(2:2), form = fld) , deliml = SK_"""" )
259 call disp%show("getFieldSep(file, seps(2:2), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
260 call disp%show( getFieldSep(file, seps(2:2), form = fld, nfield = nfield) , deliml = SK_"""" )
261 call disp%show("nfield")
262 call disp%show( nfield )
263 call disp%show("getFieldSep(file, seps(1:1), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.")
264 call disp%show( getFieldSep(file, seps(1:1), form = fld, nfield = nfield) , deliml = SK_"""" )
265 call disp%show("nfield")
266 call disp%show( nfield )
267 call disp%skip
268 end block
269
270end program example
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
Generate and return the entire contents of the input unconnected file or the (remaining) contents of ...
Definition: pm_io.F90:1586
Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the spec...
Definition: pm_io.F90:5940
Write the input string contents to the input unconnected file.
Definition: pm_io.F90:1791
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
Generate and return the conversion of the input value to an output Fortran string,...
Definition: pm_val2str.F90:167
This module contains classes and procedures for computing various statistical quantities related to t...
type(fld_type), parameter fld
This is a scalar parameter object of type fld_type that is exclusively used to signify the Fortran-li...
Definition: pm_io.F90:852
type(csv_type), parameter csv
This is a scalar parameter object of type csv_type that is exclusively used to signify the CSV file f...
Definition: pm_io.F90:787
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 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 SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
This module contains classes and procedures for various string manipulations and inquiries.
Definition: pm_str.F90:49
character(*, SK), parameter NLC
The newline character of default kind SK as returned by new_line(SK_"a").
Definition: pm_str.F90:88
This module contains the generic procedures for converting values of different types and kinds to For...
Definition: pm_val2str.F90:58
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
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!Search for single-character field separators.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
8table
9"xh", "sx", "pw", "ti", "xm", "jh"
10"kn", "pr", "gw", "qn", "us", "yy"
11"ni", "gz", "jk", "yf", "es", "bc"
12file = 'temp.temp'
13if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'
15'xh','sx','pw','ti','xm','jh'
16'kn','pr','gw','qn','us','yy'
17'ni','gz','jk','yf','es','bc'
18
19getFieldSep(file, seps = SKG_';|, ')
20","
21getFieldSep(file, seps = SKG_';|, ', form = csv)
22","
23getFieldSep(file, seps = SKG_';|, ', form = csv, nfield = nfield)
24","
25nfield
26+6
27
28call setContentsTo(file, contents = repeat(SK_'"a", '//getStr([1, 2, 3])//NLC, 2_IK))
30"a", 1, 2, 3
31"a", 1, 2, 3
32
33getFieldSep(file, seps = SKG_', ')
34","
35getFieldSep(file, seps = SKG_' ,')
36" "
37
38call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))
40(1, -1), (2, -2), (3, -3)
41(1, -1), (2, -2), (3, -3)
42
43getFieldSep(file, seps = SKG_', ', nfield = nfield)
44","
45nfield
46+6
47getFieldSep(file, seps = SKG_' ,', nfield = nfield)
48" "
49nfield
50+8
51getFieldSep(file, seps = SKG_', ', form = fld, nfield = nfield)
52","
53nfield
54+3
55getFieldSep(file, seps = SKG_' ,', form = fld, nfield = nfield)
56" "
57nfield
58+3
59
60call setContentsTo(file, contents = SK_'"a,",'//getStr([1, 2, 3])//NLC//SK_'"a",'//getStr([1, 2, 3])//NLC)
62"a,",1, 2, 3
63"a",1, 2, 3
64
65getFieldSep(file, seps = SKG_', ')
66" "
67getFieldSep(file, seps = SKG_', ', form = csv) ! quoted strings are respected in csv format.
68","
69getFieldSep(file, seps = SKG_' ,')
70" "
71
72call setContentsTo(file, contents = SK_'"a" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC)
74"a" 1, 2, 3
75"a" 1, 2, 3
76
77getFieldSep(file, seps = SKG_' ')
78""
79getFieldSep(file, seps = SKG_' ', form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
80" "
81getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
82" "
83nfield
84+4
85
86call setContentsTo(file, contents = SK_'"a'//NLC//'" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC) ! double-line csv field
88"a
89" 1, 2, 3
90"a" 1, 2, 3
91
92getFieldSep(file, seps = SKG_',')
93""
94getFieldSep(file, seps = SKG_',', form = csv) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
95","
96getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
97","
98nfield
99+3
100getFieldSep(file, seps = SKG_',', form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
101","
102nfield
103+3
104
105call setContentsTo(file, contents = SK_'"a'//NLC//NLC//'" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC) ! three-line FLD field
106getContentsFrom(file)
107"a
108
109" 1, 2, 3
110"a" 1, 2, 3
111
112getFieldSep(file, seps = SKG_' ')
113""
114getFieldSep(file, seps = SKG_' ', form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
115" "
116getFieldSep(file, seps = SKG_' ', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
117" "
118nfield
119+4
120getFieldSep(file, seps = SKG_',', form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
121","
122nfield
123+3
124
125
126!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127!Retrieve whole string field separators.
128!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
130
131table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
132table
133"gl", "ms", "tp", "zf", "ih", "lg"
134"nm", "hg", "uy", "cg", "eb", "gb"
135"ob", "qh", "ir", "qp", "na", "ry"
136file = 'temp.temp'
137if (0 /= getErrTableWrite(file, table, deliml = SKG_'''')) error stop 'table write failed.'
138getContentsFrom(file)
139'gl','ms','tp','zf','ih','lg'
140'nm','hg','uy','cg','eb','gb'
141'ob','qh','ir','qp','na','ry'
142
143seps = [css_type(SK_'|||'), css_type(SK_',')]
144seps
145"|||", ","
146getFieldSep(file, seps)
147","
148getFieldSep(file, seps, form = csv)
149","
150getFieldSep(file, seps, form = csv, nfield = nfield)
151","
152nfield
153+6
154
155call setContentsTo(file, contents = repeat(SK_'"a", '//getStr([1, 2, 3])//NLC, 2_IK))
156getContentsFrom(file)
157"a", 1, 2, 3
158"a", 1, 2, 3
159
160seps = css_type([SK_',', SK_' '], trimmed = .true._LK)
161seps
162",", " "
163getFieldSep(file, seps)
164","
165getFieldSep(file, seps(2:1:-1))
166" "
167
168call setContentsTo(file, contents = repeat(SK_'(1, -1), (2, -2), (3, -3)'//NLC, 2_IK))
169getContentsFrom(file)
170(1, -1), (2, -2), (3, -3)
171(1, -1), (2, -2), (3, -3)
172
173getFieldSep(file, seps, nfield = nfield)
174","
175nfield
176+6
177getFieldSep(file, seps(2:1:-1), nfield = nfield)
178" "
179nfield
180+8
181getFieldSep(file, seps, form = fld, nfield = nfield)
182","
183nfield
184+3
185getFieldSep(file, seps(2:1:-1), form = fld, nfield = nfield)
186" "
187nfield
188+3
189
190call setContentsTo(file, contents = SK_'"a,",'//getStr([1, 2, 3])//NLC//SK_'"a",'//getStr([1, 2, 3])//NLC)
191getContentsFrom(file)
192"a,",1, 2, 3
193"a",1, 2, 3
194
195getFieldSep(file, seps)
196" "
197getFieldSep(file, seps, form = csv) ! quoted strings are respected in csv format.
198","
199getFieldSep(file, seps(2:1:-1))
200" "
201
202call setContentsTo(file, contents = SK_'"a" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC)
203getContentsFrom(file)
204"a" 1, 2, 3
205"a" 1, 2, 3
206
207getFieldSep(file, seps(2:2))
208""
209getFieldSep(file, seps(2:2), form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
210" "
211getFieldSep(file, seps(2:2), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
212" "
213nfield
214+4
215
216call setContentsTo(file, contents = SK_'"a'//NLC//'" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC) ! double-line csv field
217getContentsFrom(file)
218"a
219" 1, 2, 3
220"a" 1, 2, 3
221
222getFieldSep(file, seps(1:1))
223""
224getFieldSep(file, seps(1:1), form = csv) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
225","
226getFieldSep(file, seps(1:1), form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
227","
228nfield
229+3
230getFieldSep(file, seps(1:1), form = csv, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (csv) format.
231","
232nfield
233+3
234
235call setContentsTo(file, contents = SK_'"a'//NLC//NLC//'" '//getStr([1, 2, 3])//NLC//SK_'"a" '//getStr([1, 2, 3])//NLC) ! three-line FLD field
236getContentsFrom(file)
237"a
238
239" 1, 2, 3
240"a" 1, 2, 3
241
242getFieldSep(file, seps(2:2))
243""
244getFieldSep(file, seps(2:2), form = fld) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
245" "
246getFieldSep(file, seps(2:2), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
247" "
248nfield
249+4
250getFieldSep(file, seps(1:1), form = fld, nfield = nfield) ! multiple adjacent blanks count as a single separator in Fortran-list-directed (fld) format.
251","
252nfield
253+3
254
255
Test:
test_pm_io
Todo:
Normal Priority: An optional input argument maxlenfield must be added to return the maximum inferred length of a field in all records of the table.
This option is potentially useful for parsing tables of string fields, where the proper field lengths is unknown a priori.
Without this option, the read action may fail or otherwise, long fields would be truncated to fit the fixed length of table fields.
Todo:
Normal Priority: The optional input arguments deliml and delimr of rank 1 of type css_type must be added to allow field recognition with arbitrary left/right delimiters within a record.


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, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 9407 of file pm_io.F90.


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