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

This is the openArg_type class containing arguments that can be passed to the open() intrinsic Fortran statement. More...

Public Attributes

character(10, SK) access = SK_"sequential"
 A scalar character of default kind SK of length 10 containing the access attribute of the file: "sequential" (default), "direct", "stream" More...
 
character(9, SK) action = SK_"readwrite"
 A scalar character of default kind SK of length 9 containing the action attribute of the file: "readwrite" (default), "read", "write" More...
 
character(3, SK) asynchronous = SK_"no"
 A scalar character of default kind SK of length 3 containing the asynchronous attribute of the file: "no" (default), "yes" More...
 
character(4, SK) blank = SK_"null"
 A scalar character of default kind SK of length 4 containing the blank attribute of the file: "null" (default), "yes" More...
 
character(5, SK) decimal = SK_"point"
 A scalar character of default kind SK of length 5 containing the decimal attribute of the file: "point" (default), "comma" More...
 
character(10, SK) delim = SK_"none"
 A scalar character of default kind SK of length 10 containing the delim attribute of the file: "none" (default), "apostrophe", "quote" More...
 
character(7, SK) encoding = SK_"default"
 A scalar character of default kind SK of length 7 containing the encoding attribute of the file: "default" (default), "utf-8" More...
 
character(11, SK) form = SK_"formatted"
 A scalar character of default kind SK of length 11 containing the delim attribute of the file: "formatted" (default), "unformatted" More...
 
integer(IK) iostat = 0_IK
 A scalar integer of default kind IK containing the iostat attribute of the file: default = 0_IK. The processor sets it to a positive value if a runtime IO error occurs. More...
 
character(3, SK) pad = SK_"yes"
 A scalar character of default kind SK of length 3 containing the pad attribute of the file: "yes" (default), "no" More...
 
character(6, SK) position = SK_"asis"
 A scalar character of default kind SK of length 6 containing the position attribute of the file: "asis" (default), "rewind", "append" More...
 
integer(IK) recl = huge(0_IK)
 A scalar integer of default kind IK containing the recl attribute of the file. It is mandatory for direct access files. More...
 
character(17, SK) round = SK_"processor_defined"
 A scalar character of default kind SK of length 17 containing the round attribute of the file: "processor_defined" (default), "compatible", "nearest", "zero", "down", "up" More...
 
character(17, SK) sign = SK_"processor_defined"
 A scalar character of default kind SK of length 17 containing the sign attribute of the file: "processor_defined" (default), "suppress", "plus" More...
 
character(7, SK) status = SK_"unknown"
 A scalar character of default kind SK of length 7 containing the status attribute of the file: "unkown" (default), "scratch", "replace", "new", "old" More...
 
integer(IK) unit = -1_IK
 A scalar integer of default kind IK containing the unit attribute of the file. It is a negative number if set by the processor, otherwise it must be positive. More...
 
character(:, SK), allocatable iomsg
 A scalar character of default kind SK of length : containing the error message if an error occurs. More...
 
character(:, SK), allocatable file
 A scalar character of default kind SK of length : containing the file path. More...
 

Detailed Description

This is the openArg_type class containing arguments that can be passed to the open() intrinsic Fortran statement.

Generate and return an object of class openArg_type containing arguments that can be passed to the open() intrinsic Fortran statement.

This type is merely meant to provide a convenient storage for file attributes that might be needed at the time of opening files for IO.
This type is overloaded with openArg_typer() to verify the consistency of the structure components values.
The following optional arguments of the open() statement are deliberately excluded from this derived type:

  1. newunit : There is no need for a dedicated component with this name since it is only relevant to calling the open() statement.
  2. err : There is no need for a dedicated component with this name since it is rarely used in modern Fortran.


Possible calling interfaces

use pm_io, only: openArg_type
type(openArg_type) :: openArg
openArg = openArg_type( access = access &
, action = action &
, asynchronous = asynchronous &
, blank = blank &
, decimal = decimal &
, delim = delim &
, encoding = encoding &
, form = form &
, iostat = iostat &
, pad = pad &
, position = position &
, recl = recl &
, round = round &
, sign = sign &
, status = status &
, unit = unit &
, file = file &
, iostat = iostat &
, iomsg = iomsg &
)
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
This is the openArg_type class containing arguments that can be passed to the open() intrinsic Fortra...
Definition: pm_io.F90:1039
Warning
All ASCII English alphabets in the input character arguments to the constructor of the class must be lower-case.
This is critical as the cases of characters are not converted within the constructor before comparisons are made.
The lower-case version of the input arguments can be obtained by calling getStrLower or setStrLower.
Remarks
The default recl for a sequential-access scratch file is
  1. huge(0) under the GNU Fortran compiler.
  2. 132 under the Intel Fortran compiler.
See also
isPreconnected


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: display_type
5 use pm_io, only: openArg_type
6
7 implicit none
8
9 integer(IK) :: iostat
10 type(openArg_type) :: openArg
11
12 type(display_type) :: disp
13
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip
17 call disp%show("openArg = openArg_type(file = 'foo.bar', status = 'new')")
18 openArg = openArg_type(file = 'foo.bar', status = 'new')
19 call disp%skip
20
21 call disp%skip
22 call disp%show("openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)")
23 openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)
24 call disp%show("iostat")
25 call disp%show( iostat )
26 call disp%show("openArg%iomsg")
27 call disp%show( openArg%iomsg , deliml = SK_"""" )
28 call disp%skip
29
30end 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
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
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
2openArg = openArg_type(file = 'foo.bar', status = 'new')
3
4
5openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)
6iostat
7+1
8openArg%iomsg
9"FATAL RUNTIME ERROR: A file name cannot be specified when `status = "scratch"`"
10
11
Test:
test_pm_io
Bug:

Status: Unresolved
Source: Intel Classic Fortran Compiler ifort version < 2021.10.0 20230609
Description: The Intel Classic Fortran Compiler ifort returns a runtime error in Microsoft WSL,
forrtl: severe (173): A pointer passed to DEALLOCATE points to an object that cannot be deallocated

within the submodule procedure isFalseAssertion() which also persisted when the procedure was in the module.
This happens only when the library is built with script flag --mem heap enabling heap allocation and only when specified with --build release.
This implies the cause of the error likely has its roots in the compilers optimizations.
It turns out that the root cause of the runtime error was the optional argument iomsg with intent(inout).

Remedy (as of ParaMonte Library version 2.0.0): The procedure isFalseAssertion() is now commented out and all error handlings are done painfully manually.
However, this did not help as the same error persisted and the root cause was identified to be the iomsg argument.
As such, this optional argument is now removed and the error message, if any, is returned in the output object component iomsg.

Bug:

Status: Unresolved
Source: GNU Fortran Compiler gfortran version < 12
Description: The GNU Fortran Compiler gfortran cannot compile interfaces with dummy arguments character(:), intent(out), allocatable, optional.
This has created a redundancy for error handling in this procedure by requiring also to pass iostat to control the occurrence of an error.
Without this bug, the allocation status of iomsg could have been used to signal no occurrence of error.

Remedy (as of ParaMonte Library version 2.0.0): All iomsg arguments are now assumed-length strings.


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

This is the constructor of the type openArg_type to verify the consistency of the structure components values.
The following optional arguments of the open() statement are deliberately excluded from this derived type:

  1. newunit : There is no need for a dedicated component with this name since it is only relevant to calling the open() statement.
  2. err : There is no need for a dedicated component with this name since it is rarely used in modern Fortran.
Parameters
[in]access: The input scalar character of default kind SK containing the access attribute of the file: "sequential" (default), "direct", "stream".
(optional, default = SK_"sequential")
[in]action: The input scalar character of default kind SK containing the action attribute of the file: "readwrite" (default), "read", "write".
(optional, default = SK_"readwrite")
[in]asynchronous: The input scalar character of default kind SK containing the asynchronous attribute of the file: "no" (default), "yes".
(optional, default = SK_"no")
[in]blank: The input scalar character of default kind SK containing the blank attribute of the file: "null" (default), "yes".
(optional, default = SK_"null")
[in]decimal: The input scalar character of default kind SK containing the decimal attribute of the file: "point" (default), "comma".
(optional, default = SK_"point")
[in]delim: The input scalar character of default kind SK containing the delim attribute of the file: "none" (default), "apostrophe", "quote".
(optional, default = SK_"none")
[in]encoding: The input scalar character of default kind SK containing the encoding attribute of the file: "default" (default), "utf-8".
(optional, default = SK_"default")
[in]form: The input scalar character of default kind SK containing the delim attribute of the file: "formatted" (default), "unformatted".
(optional, default = SK_"formatted")
[in]pad: The input scalar character of default kind SK containing the pad attribute of the file: "yes" (default), "no".
(optional, default = SK_"yes")
[in]position: The input scalar character of default kind SK containing the position attribute of the file: "asis" (default), "rewind", "append".
(optional, default = SK_"asis")
[in]recl: The input scalar integer of default kind IK containing the recl attribute of the file. It is mandatory for direct access files.
(optional, default = `. It can be specified **if and only if** the conditionaccess == SK_"sequential"for the specified input argumentaccess.) \param[in] round : The input scalarcharacterof default kind [SK](@ref pm_kind::SK) containing theroundattribute of the file:"processor_defined"(default),"compatible","nearest","zero","down","up".<br> (**optional**, default =SK_"processor_defined") \param[in] sign : The input scalarcharacterof default kind [SK](@ref pm_kind::SK) containing thesignattribute of the file:"processor_defined"(default),"suppress","plus".<br> (**optional**, default =SK_"processor_defined") \param[in] status : The input scalarcharacterof default kind [SK](@ref pm_kind::SK) containing thestatusattribute of the file:"unkown"(default),"scratch","replace","new","old".<br> (**optional**, default =SK_"unknown") \param[in] unit : The input scalarintegerof default kind [IK](@ref pm_kind::IK) containing theunit` attribute of the file.
It is a negative number if set by the processor, otherwise it must be positive.
As per the Fortran standard, -1 is reserved to represent a file that is not connected.
Therefore, if -1 is specified as input value, it will be overwritten with a random preconnected unit number.
(optional, default = getFileUnit())
[in]file: The input scalar character of default kind SK containing the file path.
(optional. If missing, the file component of the output object remains unallocated.)
[out]iostat: The output scalar integer of default kind IK.
  1. If present and no error occurs, it is set to 0 on output.
  2. 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.
    In such a case, the input optional argument iomsg, or if missing, the component iomsg of the output object of type openArg_type will be set to a descriptive message describing the nature of the error that has occurred.
  3. If missing and an error occurs, then the program halts by calling error stop followed by the relevant error message.
(optional.)
[in,out]iomsg: The input/output scalar character of default kind SK whose length type parameter and its contents will be used to set that of the corresponding component of the output object.
Additionally, if a runtime error occurs while constructing the output object, iomsg will be set to a descriptive message about the nature of the error occurred.
(optional, default = repeat(" ", LEN_IOMSG) where LEN_IOMSG is compile-time constant.)
Returns
openArg : The output scalar object of type openArg_type whose components are set to the corresponding input values or otherwise set to an appropriate default value.


Possible calling interfaces

use pm_io, only: openArg_type
type(openArg_type) :: openArg
openArg = openArg_type( access = access &
, action = action &
, asynchronous = asynchronous &
, blank = blank &
, decimal = decimal &
, delim = delim &
, encoding = encoding &
, form = form &
, pad = pad &
, position = position &
, recl = recl &
, round = round &
, sign = sign &
, status = status &
, unit = unit &
, file = file &
, iostat = iostat &
, iomsg = iomsg &
)
Warning
All ASCII English alphabets in the input character arguments to this procedure must be lower-case.
This is critical as the cases of characters are not converted within the constructor before comparisons are made.
The lower-case version of the input arguments can be obtained by calling getStrLower or setStrLower.
Remarks
If the input argument unit is missing, then the unit component of the output object is set to the unit of the specified file if it is present, exists, and is connected.
Otherwise, the unit component is set to a unique positive number that is not already associated with any other connected file.
The default recl for a sequential-access scratch file is
  1. huge(0) under the GNU Fortran compiler.
  2. 132 under the Intel Fortran compiler.
The procedures under discussion are impure.
The procedures under discussion are elemental.
See also
getFileUnit
isPreconnected


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: display_type
5 use pm_io, only: openArg_type
6
7 implicit none
8
9 integer(IK) :: iostat
10 type(openArg_type) :: openArg
11
12 type(display_type) :: disp
13
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip
17 call disp%show("openArg = openArg_type(file = 'foo.bar', status = 'new')")
18 openArg = openArg_type(file = 'foo.bar', status = 'new')
19 call disp%skip
20
21 call disp%skip
22 call disp%show("openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)")
23 openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)
24 call disp%show("iostat")
25 call disp%show( iostat )
26 call disp%show("openArg%iomsg")
27 call disp%show( openArg%iomsg , deliml = SK_"""" )
28 call disp%skip
29
30end program example

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
2openArg = openArg_type(file = 'foo.bar', status = 'new')
3
4
5openArg = openArg_type(file = 'foo.bar', status = 'scratch', iostat = iostat)
6iostat
7+1
8openArg%iomsg
9"FATAL RUNTIME ERROR: A file name cannot be specified when `status = "scratch"`"
10
11
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, Tuesday March 7, 2017, 3:50 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin

Definition at line 1039 of file pm_io.F90.

Member Data Documentation

◆ access

character(10,SK) pm_io::openArg_type::access = SK_"sequential"

A scalar character of default kind SK of length 10 containing the access attribute of the file: "sequential" (default), "direct", "stream"

Definition at line 1040 of file pm_io.F90.

◆ action

character( 9,SK) pm_io::openArg_type::action = SK_"readwrite"

A scalar character of default kind SK of length 9 containing the action attribute of the file: "readwrite" (default), "read", "write"

Definition at line 1041 of file pm_io.F90.

◆ asynchronous

character( 3,SK) pm_io::openArg_type::asynchronous = SK_"no"

A scalar character of default kind SK of length 3 containing the asynchronous attribute of the file: "no" (default), "yes"

Definition at line 1042 of file pm_io.F90.

◆ blank

character( 4,SK) pm_io::openArg_type::blank = SK_"null"

A scalar character of default kind SK of length 4 containing the blank attribute of the file: "null" (default), "yes"

Definition at line 1043 of file pm_io.F90.

◆ decimal

character( 5,SK) pm_io::openArg_type::decimal = SK_"point"

A scalar character of default kind SK of length 5 containing the decimal attribute of the file: "point" (default), "comma"

Definition at line 1044 of file pm_io.F90.

◆ delim

character(10,SK) pm_io::openArg_type::delim = SK_"none"

A scalar character of default kind SK of length 10 containing the delim attribute of the file: "none" (default), "apostrophe", "quote"

Definition at line 1045 of file pm_io.F90.

◆ encoding

character( 7,SK) pm_io::openArg_type::encoding = SK_"default"

A scalar character of default kind SK of length 7 containing the encoding attribute of the file: "default" (default), "utf-8"

Definition at line 1046 of file pm_io.F90.

◆ file

character(:, SK), allocatable pm_io::openArg_type::file

A scalar character of default kind SK of length : containing the file path.

Definition at line 1057 of file pm_io.F90.

◆ form

character(11,SK) pm_io::openArg_type::form = SK_"formatted"

A scalar character of default kind SK of length 11 containing the delim attribute of the file: "formatted" (default), "unformatted"

Definition at line 1047 of file pm_io.F90.

◆ iomsg

character(:, SK), allocatable pm_io::openArg_type::iomsg

A scalar character of default kind SK of length : containing the error message if an error occurs.

Definition at line 1056 of file pm_io.F90.

◆ iostat

integer(IK) pm_io::openArg_type::iostat = 0_IK

A scalar integer of default kind IK containing the iostat attribute of the file: default = 0_IK. The processor sets it to a positive value if a runtime IO error occurs.

Definition at line 1048 of file pm_io.F90.

◆ pad

character( 3,SK) pm_io::openArg_type::pad = SK_"yes"

A scalar character of default kind SK of length 3 containing the pad attribute of the file: "yes" (default), "no"

Definition at line 1049 of file pm_io.F90.

◆ position

character( 6,SK) pm_io::openArg_type::position = SK_"asis"

A scalar character of default kind SK of length 6 containing the position attribute of the file: "asis" (default), "rewind", "append"

Definition at line 1050 of file pm_io.F90.

◆ recl

integer(IK) pm_io::openArg_type::recl = huge(0_IK)

A scalar integer of default kind IK containing the recl attribute of the file. It is mandatory for direct access files.

Definition at line 1051 of file pm_io.F90.

◆ round

character(17,SK) pm_io::openArg_type::round = SK_"processor_defined"

A scalar character of default kind SK of length 17 containing the round attribute of the file: "processor_defined" (default), "compatible", "nearest", "zero", "down", "up"

Definition at line 1052 of file pm_io.F90.

◆ sign

character(17,SK) pm_io::openArg_type::sign = SK_"processor_defined"

A scalar character of default kind SK of length 17 containing the sign attribute of the file: "processor_defined" (default), "suppress", "plus"

Definition at line 1053 of file pm_io.F90.

◆ status

character( 7,SK) pm_io::openArg_type::status = SK_"unknown"

A scalar character of default kind SK of length 7 containing the status attribute of the file: "unkown" (default), "scratch", "replace", "new", "old"

Definition at line 1054 of file pm_io.F90.

◆ unit

integer(IK) pm_io::openArg_type::unit = -1_IK

A scalar integer of default kind IK containing the unit attribute of the file. It is a negative number if set by the processor, otherwise it must be positive.

Definition at line 1055 of file pm_io.F90.


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