Read a full record (line) of arbitrary length as a string from the current position of the record-oriented and formatted file connected to the specified input unit
.
More...
Read a full record (line) of arbitrary length as a string from the current position of the record-oriented and formatted file connected to the specified input unit
.
- Parameters
-
[in] | unit | : The input scalar integer of default kind IK representing the unit of the connected file to read the line from.
|
[in,out] | record | : The input/output allocatable scalar character of default kind SK that will contain the requested line in full.
On input,
-
The argument
record can be preallocated to the best-guess length for the record to be read.
Preallocating record to the right size can improve the runtime performance of the procedure.
-
If the optional input argument
lb is specified, any old contents record(1 : lb - 1) will remain intact on return.
-
The argument
record can be unallocated, in which case, it will be allocated to the proper size within the algorithm.
On output,
-
The argument
record will potentially be resized to contain the full record from the specified unit.
-
If the optional output argument
ub is specified, then the output record will not be trimmed (i.e., reallocated) on return.
Specifying ub will eliminate one redundant final reallocation and copy action, which can in return boost the runtime performance.
|
[out] | iostat | : The output scalar integer of default kind IK.
-
If present and no error occurs, it is set to
0 on output.
-
If present and an end-of-file condition occurs, it is set to
iostat_end from Fortran intrinsic module iso_fortran_env .
-
If present and an error occurs (e.g., if the input argument values are wrong or inconsistent), it is set to a positive non-zero value.
-
If missing and an error occurs (including end-of-file condition), then the program halts by calling
error stop followed by the relevant error message.
(optional. It must be present if and only if the output argument iomsg is also present.) |
[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. It must be present if and only if the output argument iostat is also present.) |
[in] | lb | : The input scalar integer of default kind IK, containing the lower starting bound (index) of record from which the writing must begin.
Specifying this argument will keep the segment record(1 : lb - 1) intact on return.
This behavior is extremely useful for consecutively reading a series of lines of a unit .
(optional, default = 1 ) |
[out] | ub | : The output scalar integer of default kind IK, containing the upper bound (index) of record up to which the record from the specified unit was read.
Specifying this argument leads to faster runtime performance since it prevents an extra final reallocation and string copy.
By definition, if the line in the file is empty, ub is set to 0 , unless linefed is set to .true. , in which case ub is the length of the linefeed character(s).
(optional. If missing, record will be reallocated to size record(1 : ub) , otherwise, record will not be trimmed.) |
[in] | linefed | : The input scalar logical of default kind LK.
If .true. , then the output record will end with the new line character(s) as specified by the Fortran intrinsic new_line("a") .
If .false. , then the output record will not end with the new line character(s).
In either case, only one record will be read from the specified unit, but will or will not end with a new line character if linefed is .true. or .false. respectively.
This behavior is extremely useful for,
-
reading records from a CSV file potentially containing new line characters in its fields.
-
consecutively reading a series of lines of a
unit into a single string by repeated calls to this generic interface while preserving the linefeed characters as record separators.
(optional, default = .false. ) |
Possible calling interfaces ⛓
call setRecordFrom(unit, record, lb
= lb, ub
= ub, linefed
= linefed)
call setRecordFrom(unit, record, iostat, iomsg, lb
= lb, ub
= ub, linefed
= linefed)
Read a full record (line) of arbitrary length as a string from the current position of the record-ori...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
- Warning
- The condition
0 < lb
must hold for the corresponding input arguments. This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1
.
- Note
- This generic interface can be readily used to read a certain number or all of the lines of a specified
unit
.
For example, the following code snippet,
use iso_fortran_env, only: iostat_end
open(unit, file, status = "old")
lb = 1_IK
do
call setRecordFrom(unit, record, iostat, iomsg, lb, ub, linefed
= .true._LK)
if (iostat /= iostat_end) exit
if (iostat /= 0_IK) error stop trim(iomsg)
lb = ub + 1_IK
end do
close(unit)
record = record(1:ub)
will store the entire contents of the specified file
associated with unit
in the allocatable
string record
, within which lines are separated by new_line("a")
instances.
-
Note that setting
linefed = .true.
leads to each record being padded with a newline character, including the last line in the file.
As such, reading an entire file using the above code snippet will lead to a final output that an has extra final newline character compared to the output of getContentsFrom() or setContentsFrom().
- See also
- getRecordFrom
getContentsFrom
setContentsFrom
isPreconnected
getFileUnit
Example usage ⛓
12 character(
255, SK) :: iomsg
13 character( :, SK),
allocatable :: record
15 type(display_type) :: disp
20 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
21 call disp%show(
"!Read the record-oriented (sequential access) `main.F90` file, line by line to the end.")
22 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
25 iomsg
= repeat(
" ",
len(iomsg))
27 open(newunit
= unit, file
= "main.F90", status
= "old")
31 call disp%show(
"call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg)")
32 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
33 if (iostat
== 0_IK)
then
35 call disp%show( record , deliml
= SK_
"""" )
39 call disp%show(
"trim(adjustl(iomsg))")
40 call disp%show(
trim(
adjustl(iomsg)) , deliml
= SK_
"""" )
49 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
50 call disp%show(
"!Read a record-oriented (sequential access) `main.F90` file, line by line to the end, faster without redundant reallocations and copies.")
51 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
54 iomsg
= repeat(
" ",
len(iomsg))
56 call disp%show(
'open(newunit = unit, file = "main.F90", status = "old")')
57 open(newunit
= unit, file
= "main.F90", status
= "old")
60 call disp%show(
"call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, ub = ub)")
61 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
62 if (iostat
== 0_IK)
then
64 call disp%show( record(
1:ub) , deliml
= SK_
"""" )
68 call disp%show(
"trim(adjustl(iomsg))")
69 call disp%show(
trim(
adjustl(iomsg)) , deliml
= SK_
"""" )
78 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
79 call disp%show(
"!Read a record-oriented (sequential access) `main.F90` file line by line to the end in a single string, each line separated by linefeed (see the end of contents for the source code).")
80 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
84 use iso_fortran_env,
only:
iostat_end
87 open(newunit
= unit, file
= "main.F90", status
= "old")
88 iomsg
= repeat(
" ",
len(iomsg))
91 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, lb
= lb, ub
= ub, linefed
= .true._LK)
92 if (iostat
== 0_IK)
then
95 elseif (iostat
== iostat_end)
then
98 error stop SK_
"Unknown IO error occurred: "//trim(iomsg)
Generate and return a resized and centered copy of the input array within the newly allocated arrayCe...
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 procedures and generic interfaces for resizing an input array and centering the ...
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 IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
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 ⛓
7call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
12call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
17call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
19" use pm_kind, only: SK, IK, LK"
22call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
24" use pm_io, only: display_type"
27call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
29" use pm_io, only: setRecordFrom"
32call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
37call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
42call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
47call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
52call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
57call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
59" integer(IK) :: iostat"
62call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
64" character(255, SK) :: iomsg"
67call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
69" character( :, SK), allocatable :: record"
72call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
77call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
79" type(display_type) :: disp"
82call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
87call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
89" disp = display_type(file = "main.out.F90
")"
92call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
97call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
102call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
107call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
112call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
117call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
122call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
127call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
129" iomsg = repeat(" ", len(iomsg))"
132call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
137call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
139" open(newunit = unit, file = "main.F90
", status = "old
")"
142call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
147call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
152call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
157call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
159" call disp%show("call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
")"
162call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
164" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg)"
167call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
169" if (iostat == 0_IK) then"
172call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
174" call disp%show("record
")"
177call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
179" call disp%show( record , deliml = SK_"""" )"
182call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
187call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
189" call disp%show("iostat
")"
192call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
194" call disp%show( iostat )"
197call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
199" call disp%show("trim(
adjustl(iomsg))
")"
202call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
204" call disp%show( trim(adjustl(iomsg)) , deliml = SK_"""" )"
207call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
212call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
217call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
222call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
227call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
232call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
237call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
242call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
247call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
252call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
257call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
262call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
267call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
272call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
274" iomsg = repeat(" ", len(iomsg))"
277call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
282call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
284" call disp%show('open(newunit = unit, file = "main.F90
", status = "old
")')"
287call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
289" open(newunit = unit, file = "main.F90
", status = "old
")"
292call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
297call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
302call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
304" call disp%show("call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
")"
307call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
309" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, ub = ub)"
312call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
314" if (iostat == 0_IK) then"
317call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
319" call disp%show("record(
1:ub)
")"
322call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
324" call disp%show( record(1:ub) , deliml = SK_"""" )"
327call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
332call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
334" call disp%show("iostat
")"
337call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
339" call disp%show( iostat )"
342call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
344" call disp%show("trim(
adjustl(iomsg))
")"
347call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
349" call disp%show( trim(adjustl(iomsg)) , deliml = SK_"""" )"
352call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
357call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
362call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
367call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
372call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
377call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
382call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
387call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
392call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
397call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
402call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
407call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
412call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
417call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
422call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
424" use iso_fortran_env, only: iostat_end"
427call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
429" use pm_arrayCenter, only: getCentered"
432call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
434" integer(IK) :: lb, ub"
437call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
439" open(newunit = unit, file = "main.F90
", status = "old
")"
442call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
444" iomsg = repeat(" ", len(iomsg))"
447call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
452call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
457call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
459" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, lb = lb, ub = ub, linefed = .true._LK)"
462call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
464" if (iostat == 0_IK) then"
467call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
472call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
477call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
479" elseif (iostat == iostat_end) then"
482call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
487call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
492call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
494" error stop SK_"Unknown IO error occurred:
"//trim(iomsg)"
497call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
502call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
507call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
509" call disp%show( getCentered(SK_" records
", size = 132_IK, fill = SK_"_
") )"
512call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
514" call disp%show( record(1:ub) )"
517call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
519" call disp%show( getCentered(SK_" end of records
", size = 132_IK, fill = SK_"_
") )"
522call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
527call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
532call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
537call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
542call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
552open(newunit
= unit, file
= "main.F90", status
= "old")
554call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
559call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
564call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
566" use pm_kind, only: SK, IK, LK"
569call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
571" use pm_io, only: display_type"
574call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
576" use pm_io, only: setRecordFrom"
579call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
584call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
589call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
594call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
599call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
601" integer(IK) :: unit"
604call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
606" integer(IK) :: iostat"
609call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
611" character(255, SK) :: iomsg"
614call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
616" character( :, SK), allocatable :: record"
619call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
624call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
626" type(display_type) :: disp"
629call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
634call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
636" disp = display_type(file = "main.out.F90
")"
639call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
644call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
649call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
654call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
659call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
664call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
669call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
674call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
676" iomsg = repeat(" ", len(iomsg))"
679call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
684call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
686" open(newunit = unit, file = "main.F90
", status = "old
")"
689call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
694call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
699call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
704call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
706" call disp%show("call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
")"
709call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
711" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg)"
714call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
716" if (iostat == 0_IK) then"
719call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
721" call disp%show("record
")"
724call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
726" call disp%show( record , deliml = SK_"""" )"
729call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
734call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
736" call disp%show("iostat
")"
739call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
741" call disp%show( iostat )"
744call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
746" call disp%show("trim(
adjustl(iomsg))
")"
749call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
751" call disp%show( trim(adjustl(iomsg)) , deliml = SK_"""" )"
754call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
759call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
764call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
769call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
774call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
779call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
784call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
789call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
794call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
799call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
804call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
809call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
814call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
819call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
821" iomsg = repeat(" ", len(iomsg))"
824call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
829call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
831" call disp%show('open(newunit = unit, file = "main.F90
", status = "old
")')"
834call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
836" open(newunit = unit, file = "main.F90
", status = "old
")"
839call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
844call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
849call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
851" call disp%show("call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
")"
854call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
856" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, ub = ub)"
859call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
861" if (iostat == 0_IK) then"
864call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
866" call disp%show("record(
1:ub)
")"
869call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
871" call disp%show( record(1:ub) , deliml = SK_"""" )"
874call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
879call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
881" call disp%show("iostat
")"
884call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
886" call disp%show( iostat )"
889call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
891" call disp%show("trim(
adjustl(iomsg))
")"
894call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
896" call disp%show( trim(adjustl(iomsg)) , deliml = SK_"""" )"
899call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
904call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
909call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
914call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
919call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
924call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
929call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
934call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
939call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
944call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
949call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
954call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
959call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
964call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
969call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
971" use iso_fortran_env, only: iostat_end"
974call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
976" use pm_arrayCenter, only: getCentered"
979call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
981" integer(IK) :: lb, ub"
984call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
986" open(newunit = unit, file = "main.F90
", status = "old
")"
989call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
991" iomsg = repeat(" ", len(iomsg))"
994call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
999call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1004call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1006" call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, lb = lb, ub = ub, linefed = .true._LK)"
1009call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1011" if (iostat == 0_IK) then"
1014call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1019call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1024call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1026" elseif (iostat == iostat_end) then"
1029call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1034call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1039call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1041" error stop SK_"Unknown IO error occurred:
"//trim(iomsg)"
1044call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1049call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1054call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1056" call disp%show( getCentered(SK_" records
", size = 132_IK, fill = SK_"_
") )"
1059call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1061" call disp%show( record(1:ub) )"
1064call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1066" call disp%show( getCentered(SK_" end of records
", size = 132_IK, fill = SK_"_
") )"
1069call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1074call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1079call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1084call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1086"end program example"
1089call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1099_____________________________________________________________ records ______________________________________________________________
1110 integer(IK) :: iostat
1111 character(
255, SK) :: iomsg
1112 character( :, SK),
allocatable :: record
1114 type(display_type) :: disp
1119 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1120 call disp%show(
"!Read the record-oriented (sequential access) `main.F90` file, line by line to the end.")
1121 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1124 iomsg
= repeat(
" ",
len(iomsg))
1126 open(newunit
= unit, file
= "main.F90", status
= "old")
1130 call disp%show(
"call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg)")
1131 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg)
1132 if (iostat
== 0_IK)
then
1134 call disp%show( record , deliml
= SK_
"""" )
1138 call disp%show(
"trim(adjustl(iomsg))")
1139 call disp%show(
trim(
adjustl(iomsg)) , deliml
= SK_
"""" )
1148 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1149 call disp%show(
"!Read a record-oriented (sequential access) `main.F90` file, line by line to the end, faster without redundant reallocations and copies.")
1150 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1153 iomsg
= repeat(
" ",
len(iomsg))
1155 call disp%show(
'open(newunit = unit, file = "main.F90", status = "old")')
1156 open(newunit
= unit, file
= "main.F90", status
= "old")
1159 call disp%show(
"call setRecordFrom(unit, record, iostat = iostat, iomsg = iomsg, ub = ub)")
1160 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, ub
= ub)
1161 if (iostat
== 0_IK)
then
1163 call disp%show( record(
1:ub) , deliml
= SK_
"""" )
1167 call disp%show(
"trim(adjustl(iomsg))")
1168 call disp%show(
trim(
adjustl(iomsg)) , deliml
= SK_
"""" )
1177 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1178 call disp%show(
"!Read a record-oriented (sequential access) `main.F90` file line by line to the end in a single string, each line separated by linefeed (see the end of contents for the source code).")
1179 call disp%show(
"!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
1183 use iso_fortran_env,
only:
iostat_end
1185 integer(IK) :: lb, ub
1186 open(newunit
= unit, file
= "main.F90", status
= "old")
1187 iomsg
= repeat(
" ",
len(iomsg))
1190 call setRecordFrom(unit, record,
iostat = iostat,
iomsg = iomsg, lb
= lb, ub
= ub, linefed
= .true._LK)
1191 if (iostat
== 0_IK)
then
1194 elseif (iostat
== iostat_end)
then
1197 error stop SK_
"Unknown IO error occurred: "//trim(iomsg)
1208__________________________________________________________
end of records __________________________________________________________
program main
This is main entry to the tests of the ParaMonte kernel library.
- Test:
- test_pm_io
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, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin
Definition at line 2114 of file pm_io.F90.