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

Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the specified output.
More...

Detailed Description

Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the specified output.

Parameters
[in]file: The input scalar character of default kind SK representing the path to the external file to which the table must be written.
If the specified file does not exist, it will be created.
If it exists or is already connected, it will repositioned before the beginning of its first record.
(optional. It must be present only if the input argument unit is missing.)
[in]unit: The input scalar integer of default kind IK representing the preconnected (opened) file unit to which the table must be written.
The writing will begin from the current file position plus the input roff.
To write to stdout, use iso_fortran_env, only: unit => output_unit.
(optional. It must be present only if the input argument file is missing.)
[in]table: The input array of shape (:) or (:,:) of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU), or
  2. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64), or
  3. type logical of kind any supported by the processor (e.g., LK), or
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128), or
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
representing the data table to write to the specified output.
By default a table of rank 1 is considered to be a single column unless the input optional argument operation is set to trans in which case table is considered as a row of fields.
By default, if the input argument operation is missing, each column of table corresponds to each column of data in the file.
[in]operation: The input scalar constant that can be:
  1. the scalar constant trans or a scalar object of type trans_type, implying that the input table must be transposed before being written to the output file.
    This option is particularly useful for outputting table that is in Fortran column-major storage mode but has to be written in regular row-major format to the output.
(optional, default = nothing, implying that the table must be output as is.)
[in]header: The input scalar character of default kind SK of arbitrary length type parameter containing the table header.
It is recommended to delimit the header fields with the same input separator sep to this generic interface to minimize difficulties with reading the table in the future.
(optional, If missing, no header will be written to the specified output. The generic interface setSplit() can be used to readily generate a array of header field containers split at by the user-specified separator.)
[in]sep: The input scalar character of default kind SK of arbitrary length type parameter containing the separator of the fields of each of row of the table in the output file.
(optional, default = , corresponding to an output CSV file.)
[in]deliml: The input scalar of type character of default kind SK, of arbitrary length type parameter, containing the left-delimiter to be used for delimiting (quoting) the left-side of the elements of table in the output file.
The symbols \(\texttt{"}\) and \(\texttt{'}\) are the two most popular quotation mark choices that are recognized by both CSV and Fortran list-directed output forms.
Unless there is a good reason, the use of delimiters for table of type other than character is not advised.
(optional. default = delimr or if missing, no left-delimiter will be used.)
[in]delimr: The input scalar of type character of default kind SK, of arbitrary length type parameter, containing the right-delimiter to be used for delimiting (quoting) the right-side of the elements of table in the output file.
The symbols \(\texttt{"}\) and \(\texttt{'}\) are the two most popular quotation mark choices that are recognized by both CSV and Fortran list-directed output forms.
Unless there is a good reason, the use of delimiters for table of type other than character is not advised.
(optional. default = deliml or if missing, no right-delimiter will be used.)
[in]roff: The input scalar integer of default kind IK representing the row offset, that is, the number of rows in the external file or unit to skip before beginning to read the output variables header and table.
(optional. default = 0)
[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 the output error code err will be returned.)
Returns
err : The output scalar integer of default kind IK containing the iostat error code returned by the Fortran intrinsic write() statement.
On return, err is set to 0 if and only if the table is successfully written to the output.
See the Fortran standard and specific compiler documentations for the possible meanings of the output err.


Possible calling interfaces

use pm_kind, only: IK
integer(IK) :: err
err = getErrTableWrite(unit, table(1..2) , header = header, sep = sep, deliml, delimr = deliml, delimr = delimr, roff = roff, iomsg = iomsg)
err = getErrTableWrite(file, table(1..2) , header = header, sep = sep, deliml, delimr = deliml, delimr = delimr, roff = roff, iomsg = iomsg)
err = getErrTableWrite(unit, table(1..2), operation, header = header, sep = sep, deliml, delimr = deliml, delimr = delimr, roff = roff, iomsg = iomsg)
err = getErrTableWrite(file, table(1..2), operation, header = header, sep = sep, deliml, delimr = deliml, delimr = delimr, roff = roff, iomsg = iomsg)
!
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
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
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
Warning
The condition isOpen(unit) must hold for the corresponding input arguments.
This condition is verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.
See also
getRecordFrom
setRecordFrom
getContentsFrom
setContentsFrom
getErrTableRead
getErrTableWrite


Example usage

1program example
2
3 use iso_fortran_env, only: output_unit, input_unit, error_unit
4 use pm_kind, only: SK, IK, LK
5 use pm_io, only: display_type
6 use pm_io, only: getErrTableWrite, trans
7 use pm_io, only: getContentsFrom
8 use pm_distUnif, only: getUnifRand
9
10 implicit none
11
12 character(:, SK), allocatable :: file
13 type(display_type) :: disp
14
15 disp = display_type(file = "main.out.F90")
16
17 block
18 use pm_kind, only: SKG => SK
19 character(2,SKG), allocatable :: table(:,:)
20 call disp%skip
21 call disp%show("table = getUnifRand('aa', 'zz', 3_IK, 6_IK)")
22 table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
23 call disp%show("table")
24 call disp%show( table , deliml = SK_"""" )
25 call disp%show("file = 'temp.temp'")
26 file = 'temp.temp'
27 call disp%show("if (0 /= getErrTableWrite(file, table, deliml = SK_'''')) error stop 'table write failed.'")
28 if (0 /= getErrTableWrite(file, table, deliml = SK_'''')) error stop 'table write failed.'
29 call disp%show("getContentsFrom(file, del = .true._LK)")
30 call disp%show( getContentsFrom(file, del = .true._LK) )
31 call disp%skip
32 end block
33
34 block
35 use pm_kind, only: IKG => IK
36 integer(IKG), allocatable :: table(:,:)
37 call disp%skip
38 call disp%show("table = getUnifRand(-1, 1, 4_IK, 2_IK)")
39 table = getUnifRand(-1, 1, 4_IK, 2_IK)
40 call disp%show("table")
41 call disp%show( table )
42 call disp%show("file = 'temp.temp'")
43 file = 'temp.temp'
44 call disp%show("if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'")
45 if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
46 call disp%show("getContentsFrom(file, del = .true._LK)")
47 call disp%show( getContentsFrom(file, del = .true._LK) )
48 call disp%show("if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'")
49 if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
50 call disp%show("getContentsFrom(file, del = .true._LK)")
51 call disp%show( getContentsFrom(file, del = .true._LK) )
52 call disp%skip
53 end block
54
55 block
56 use pm_kind, only: LKG => LK
57 logical(LKG), allocatable :: table(:,:)
58 call disp%skip
59 call disp%show("table = getUnifRand(.false., .true., 4_IK, 2_IK)")
60 table = getUnifRand(.false., .true., 4_IK, 2_IK)
61 call disp%show("table")
62 call disp%show( table )
63 call disp%show("file = 'temp.temp'")
64 file = 'temp.temp'
65 call disp%show("if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'")
66 if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
67 call disp%show("getContentsFrom(file, del = .true._LK)")
68 call disp%show( getContentsFrom(file, del = .true._LK) )
69 call disp%show("if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'")
70 if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
71 call disp%show("getContentsFrom(file, del = .true._LK)")
72 call disp%show( getContentsFrom(file, del = .true._LK) )
73 call disp%skip
74 end block
75
76 block
77 use pm_kind, only: CKG => CKS
78 complex(CKG), allocatable :: table(:,:)
79 call disp%skip
80 call disp%show("table = getUnifRand((-1., -1.), (+1., +1.), 4_IK, 2_IK)")
81 table = getUnifRand((-1., -1.), (+1., +1.), 4_IK, 2_IK)
82 call disp%show("table")
83 call disp%show( table )
84 call disp%show("file = 'temp.temp'")
85 file = 'temp.temp'
86 call disp%show("if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'")
87 if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
88 call disp%show("getContentsFrom(file, del = .true._LK)")
89 call disp%show( getContentsFrom(file, del = .true._LK) )
90 call disp%show("if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'")
91 if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
92 call disp%show("getContentsFrom(file, del = .true._LK)")
93 call disp%show( getContentsFrom(file, del = .true._LK) )
94 call disp%skip
95 end block
96
97 block
98 use pm_kind, only: RKG => RKS
99 real(RKG), allocatable :: table(:,:)
100 call disp%skip
101 call disp%show("table = getUnifRand(-1, 1, 4_IK, 2_IK)")
102 table = getUnifRand(-1, 1, 4_IK, 2_IK)
103 call disp%show("table")
104 call disp%show( table )
105 call disp%show("file = 'temp.temp'")
106 file = 'temp.temp'
107 call disp%show("if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'")
108 if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
109 call disp%show("getContentsFrom(file, del = .true._LK)")
110 call disp%show( getContentsFrom(file, del = .true._LK) )
111 call disp%show("if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'")
112 if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
113 call disp%show("getContentsFrom(file, del = .true._LK)")
114 call disp%show( getContentsFrom(file, del = .true._LK) )
115 call disp%skip
116 end block
117
118end 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
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 computing various statistical quantities related to t...
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
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 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 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
2table = getUnifRand('aa', 'zz', 3_IK, 6_IK)
3table
4"lb", "ir", "fp", "qy", "uh", "zz"
5"ge", "cf", "xj", "rd", "kr", "lu"
6"cy", "jt", "ri", "uw", "wo", "pz"
7file = 'temp.temp'
8if (0 /= getErrTableWrite(file, table, deliml = SK_'''')) error stop 'table write failed.'
9getContentsFrom(file, del = .true._LK)
10'lb','ir','fp','qy','uh','zz'
11'ge','cf','xj','rd','kr','lu'
12'cy','jt','ri','uw','wo','pz'
13
14
15
16table = getUnifRand(-1, 1, 4_IK, 2_IK)
17table
18+1, +1
19-1, -1
20+0, +0
21+1, +1
22file = 'temp.temp'
23if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
24getContentsFrom(file, del = .true._LK)
25col1 col2
261 1
27-1 -1
280 0
291 1
30
31if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
32getContentsFrom(file, del = .true._LK)
33
34
351|-1|0|1
361|-1|0|1
37
38
39
40table = getUnifRand(.false., .true., 4_IK, 2_IK)
41table
42T, F
43T, T
44T, T
45T, T
46file = 'temp.temp'
47if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
48getContentsFrom(file, del = .true._LK)
49col1 col2
50T F
51T T
52T T
53T T
54
55if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
56getContentsFrom(file, del = .true._LK)
57
58
59T|T|T|T
60F|T|T|T
61
62
63
64table = getUnifRand((-1., -1.), (+1., +1.), 4_IK, 2_IK)
65table
66(-0.687768459E-1, +0.113092065), (+0.974854350, +0.222588539)
67(+0.340295911, +0.770389915), (-0.789327621, -0.476577044)
68(+0.740171313, -0.922627449E-1), (+0.607153654, +0.652903914)
69(+0.100135803E-1, -0.678184271), (+0.546377778, +0.649173737)
70file = 'temp.temp'
71if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
72getContentsFrom(file, del = .true._LK)
73col1 col2
74-0.687768459E-1 0.113092065 0.974854350 0.222588539
750.340295911 0.770389915 -0.789327621 -0.476577044
760.740171313 -0.922627449E-1 0.607153654 0.652903914
770.100135803E-1 -0.678184271 0.546377778 0.649173737
78
79if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
80getContentsFrom(file, del = .true._LK)
81
82
83-0.687768459E-1|0.113092065|0.340295911|0.770389915|0.740171313|-0.922627449E-1|0.100135803E-1|-0.678184271
840.974854350|0.222588539|-0.789327621|-0.476577044|0.607153654|0.652903914|0.546377778|0.649173737
85
86
87
88table = getUnifRand(-1, 1, 4_IK, 2_IK)
89table
90-1.00000000, -1.00000000
91+0.00000000, -1.00000000
92+0.00000000, +0.00000000
93-1.00000000, +1.00000000
94file = 'temp.temp'
95if (0 /= getErrTableWrite(file, table, header = SK_'col1 col2', sep = SK_' ')) error stop 'table write failed.'
96getContentsFrom(file, del = .true._LK)
97col1 col2
98-1.00000000 -1.00000000
990.00000000 -1.00000000
1000.00000000 0.00000000
101-1.00000000 1.00000000
102
103if (0 /= getErrTableWrite(file, table, trans, sep = SK_'|', roff = 2_IK)) error stop 'table write failed.'
104getContentsFrom(file, del = .true._LK)
105
106
107-1.00000000|0.00000000|0.00000000|-1.00000000
108-1.00000000|-1.00000000|0.00000000|1.00000000
109
110
111
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.

  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 Austin

Definition at line 5940 of file pm_io.F90.


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