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

Generate and return the entire contents of the input unconnected file or the (remaining) contents of an already-connected file associated with the input unit.
More...

Detailed Description

Generate and return the entire contents of the input unconnected file or the (remaining) contents of an already-connected file associated with the input unit.

Parameters
[in]unit: The input scalar integer of default kind IK containing the unit of an already-connected (opened) file whose (partial) contents will be returned.
(optional. It must be present if and only if the input argument file is missing.)
[in]file: The input scalar character of default kind SK containing the path of an unconnected (unopened) file whose entire contents will be returned.
(optional. It must be present if and only if the input argument unit is missing.)
[in]del: See the documentation for the corresponding argument of setContentsFrom().
(optional. The default behavior is set by setContentsFrom())
Returns
contents : The output allocatable scalar character of default kind SK that will contain the file contents.
The allocation status of contents or its value remain undefined if an error occurs.


Possible calling interfaces

character(:, SK), allocatable :: contents
contents = getContentsFrom(unit, del = del)
contents = getContentsFrom(file, del = del)
Generate and return the entire contents of the input unconnected file or the (remaining) contents of ...
Definition: pm_io.F90:1586
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
Warning
All warnings associated with setContentsFrom also apply to the procedures under this generic interface.
If the procedure fails to fetch the contents of the file, the program may stop by signaling the occurrence of an error.
Use setContentsFrom for graceful error handling.
Remarks
The procedures under discussion are impure.
See also
getFileUnit
isPreconnected
setContentsFrom


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: getContentsFrom
7
8 implicit none
9
10 integer :: unit
11 character(:, SK), allocatable :: contents
12
13 type(display_type) :: disp
14 disp = display_type(file = "main.out.F90")
15
16 call disp%skip
17 call disp%show("contents = getContentsFrom('main.F90')")
18 contents = getContentsFrom('main.F90')
19 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
20 call disp%show( contents )
21 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
22 call disp%skip
23
24 ! Intel ifort Windows bug?
25 ! @file(pm_io@routines.inc.F90)@line(235)@pm_io@setContentsFrom(): A non-advancing READ immediately following a non-advancing WRITE on the same unit number is not allowed, unit -129.
26#if !__INTEL_COMPILER || !_WIN32
27 call disp%skip
28 call disp%show("open(newunit = unit, file = 'main.F90')")
29 open(newunit = unit, file = 'main.F90')
30 call disp%show("contents = getContentsFrom(unit)")
31 contents = getContentsFrom(unit)
32 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
33 call disp%show( contents )
34 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
35 call disp%skip
36#endif
37
38end program example
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.
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 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.
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
2contents = getContentsFrom('main.F90')
3_____________________________________________________________ contents _____________________________________________________________
4program example
5
6 use pm_kind, only: SK, IK, LK
7 use pm_io, only: display_type
8 use pm_io, only: getContentsFrom
10
11 implicit none
12
13 integer :: unit
14 character(:, SK), allocatable :: contents
15
16 type(display_type) :: disp
17 disp = display_type(file = "main.out.F90")
18
19 call disp%skip
20 call disp%show("contents = getContentsFrom('main.F90')")
21 contents = getContentsFrom('main.F90')
22 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
23 call disp%show( contents )
24 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
25 call disp%skip
26
27 ! Intel ifort Windows bug?
28 ! @file(pm_io@routines.inc.F90)@line(235)@pm_io@setContentsFrom(): A non-advancing READ immediately following a non-advancing WRITE on the same unit number is not allowed, unit -129.
29#if !__INTEL_COMPILER || !_WIN32
30 call disp%skip
31 call disp%show("open(newunit = unit, file = 'main.F90')")
32 open(newunit = unit, file = 'main.F90')
33 call disp%show("contents = getContentsFrom(unit)")
34 contents = getContentsFrom(unit)
35 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
36 call disp%show( contents )
37 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
38 call disp%skip
39#endif
40
41end program example
42_________________________________________________________ end of contents __________________________________________________________
43
44
45open(newunit = unit, file = 'main.F90')
46contents = getContentsFrom(unit)
47_____________________________________________________________ contents _____________________________________________________________
48program example
49
50 use pm_kind, only: SK, IK, LK
51 use pm_io, only: display_type
52 use pm_io, only: getContentsFrom
54
55 implicit none
56
57 integer :: unit
58 character(:, SK), allocatable :: contents
59
60 type(display_type) :: disp
61 disp = display_type(file = "main.out.F90")
62
63 call disp%skip
64 call disp%show("contents = getContentsFrom('main.F90')")
65 contents = getContentsFrom('main.F90')
66 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
67 call disp%show( contents )
68 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
69 call disp%skip
70
71 ! Intel ifort Windows bug?
72 ! @file(pm_io@routines.inc.F90)@line(235)@pm_io@setContentsFrom(): A non-advancing READ immediately following a non-advancing WRITE on the same unit number is not allowed, unit -129.
73#if !__INTEL_COMPILER || !_WIN32
74 call disp%skip
75 call disp%show("open(newunit = unit, file = 'main.F90')")
76 open(newunit = unit, file = 'main.F90')
77 call disp%show("contents = getContentsFrom(unit)")
78 contents = getContentsFrom(unit)
79 call disp%show( getCentered(SK_" contents ", size = 132_IK, fill = SK_"_") )
80 call disp%show( contents )
81 call disp%show( getCentered(SK_" end of contents ", size = 132_IK, fill = SK_"_") )
82 call disp%skip
83#endif
84
85end program example
86_________________________________________________________ end of contents __________________________________________________________
87
88
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 1586 of file pm_io.F90.


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