Line data Source code
1 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
3 : !!!!
4 : !!!! MIT License
5 : !!!!
6 : !!!! ParaMonte: plain powerful parallel Monte Carlo library.
7 : !!!!
8 : !!!! Copyright (C) 2012-present, The Computational Data Science Lab
9 : !!!!
10 : !!!! This file is part of the ParaMonte library.
11 : !!!!
12 : !!!! Permission is hereby granted, free of charge, to any person obtaining a
13 : !!!! copy of this software and associated documentation files (the "Software"),
14 : !!!! to deal in the Software without restriction, including without limitation
15 : !!!! the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : !!!! and/or sell copies of the Software, and to permit persons to whom the
17 : !!!! Software is furnished to do so, subject to the following conditions:
18 : !!!!
19 : !!!! The above copyright notice and this permission notice shall be
20 : !!!! included in all copies or substantial portions of the Software.
21 : !!!!
22 : !!!! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 : !!!! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 : !!!! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 : !!!! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
26 : !!!! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
27 : !!!! OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
28 : !!!! OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 : !!!!
30 : !!!! ACKNOWLEDGMENT
31 : !!!!
32 : !!!! ParaMonte is an honor-ware and its currency is acknowledgment and citations.
33 : !!!! As per the ParaMonte library license agreement terms, if you use any parts of
34 : !!!! this library for any purposes, kindly acknowledge the use of ParaMonte in your
35 : !!!! work (education/research/industry/development/...) by citing the ParaMonte
36 : !!!! library as described on this page:
37 : !!!!
38 : !!!! https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
39 : !!!!
40 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41 : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 :
43 : !> \brief
44 : !> This module contains the classes and procedures for setting up the `restartFileFormat` attribute of ParaMonte samplers.
45 : !> For more information, see the description of this attribute in the body of the module.
46 : !> \author Amir Shahmoradi
47 :
48 : module SpecBase_RestartFileFormat_mod
49 :
50 : use Constants_mod, only: IK
51 : implicit none
52 :
53 : character(*), parameter :: MODULE_NAME = "@SpecBase_RestartFileFormat_mod"
54 :
55 : integer(IK), parameter :: MAX_LEN_RESTART_FILE_FORMAT = 63
56 :
57 : character(MAX_LEN_RESTART_FILE_FORMAT) :: restartFileFormat
58 :
59 : type :: RestartFileFormat_type
60 : logical :: isBinary
61 : logical :: isAscii
62 : character(6) :: binary
63 : character(5) :: ascii
64 : character(:), allocatable :: def
65 : character(:), allocatable :: val
66 : character(:), allocatable :: null
67 : character(:), allocatable :: desc
68 : contains
69 : procedure, pass :: set => setRestartFileFormat, checkForSanity, nullifyNameListVar
70 : end type RestartFileFormat_type
71 :
72 : interface RestartFileFormat_type
73 : module procedure :: constructRestartFileFormat
74 : end interface RestartFileFormat_type
75 :
76 : private :: constructRestartFileFormat, setRestartFileFormat, checkForSanity, nullifyNameListVar
77 :
78 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 :
80 : contains
81 :
82 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83 :
84 1047 : function constructRestartFileFormat(methodName) result(RestartFileFormatObj)
85 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
86 : !DEC$ ATTRIBUTES DLLEXPORT :: constructRestartFileFormat
87 : #endif
88 : use Constants_mod, only: NULL_SK, FILE_EXT, FILE_TYPE
89 : use String_mod, only: num2str
90 : implicit none
91 : character(*), intent(in) :: methodName
92 : type(RestartFileFormat_type) :: RestartFileFormatObj
93 :
94 1047 : RestartFileFormatObj%isBinary = .false.
95 1047 : RestartFileFormatObj%isAscii = .false.
96 1047 : RestartFileFormatObj%binary = FILE_TYPE%binary
97 1047 : RestartFileFormatObj%ascii = FILE_TYPE%ascii
98 1047 : RestartFileFormatObj%def = RestartFileFormatObj%binary
99 :
100 1047 : RestartFileFormatObj%null = repeat(NULL_SK, MAX_LEN_RESTART_FILE_FORMAT)
101 :
102 : RestartFileFormatObj%desc = &
103 : "restartFileFormat is a string variable that represents the format of the output restart file(s) which are used to restart &
104 : &an interrupted "// methodName //" simulation. The string value must be enclosed by either single or double quotation &
105 : &marks when provided as input. Two values are possible:\n\n&
106 : & restartFileFormat = '" // RestartFileFormatObj%binary // "'\n\n&
107 : & This is the binary file format which is not human-readable, but preserves the exact values of the &
108 : &specification variables required for the simulation restart. This full accuracy representation is required &
109 : &to exactly reproduce an interrupted simulation. The binary format is also normally the fastest mode of restart file &
110 : &generation. Binary restart files will have the " // FILE_EXT%binary // " file extensions.\n\n&
111 : & restartFileFormat = '" // RestartFileFormatObj%ascii // "'\n\n&
112 : & This is the ASCII (text) file format which is human-readable but does not preserve the full accuracy of &
113 : &the specification variables required for the simulation restart. It is also a significantly slower mode of &
114 : &restart file generation, compared to the binary format. Therefore, its usage should be limited to situations where &
115 : &the user wants to track the dynamics of simulation specifications throughout the simulation time. &
116 : &ASCII restart file(s) will have the " // FILE_EXT%ascii //" file extensions.\n\n&
117 1047 : &The default value is restartFileFormat = '" // RestartFileFormatObj%def // "'. Note that the input values are case-insensitive."
118 1047 : end function constructRestartFileFormat
119 :
120 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 :
122 1047 : subroutine nullifyNameListVar(RestartFileFormatObj)
123 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
124 : !DEC$ ATTRIBUTES DLLEXPORT :: nullifyNameListVar
125 : #endif
126 : implicit none
127 : class(RestartFileFormat_type), intent(in) :: RestartFileFormatObj
128 1047 : restartFileFormat = RestartFileFormatObj%null
129 1047 : end subroutine nullifyNameListVar
130 :
131 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132 :
133 1107 : subroutine setRestartFileFormat(RestartFileFormatObj,restartFileFormat)
134 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
135 : !DEC$ ATTRIBUTES DLLEXPORT :: setRestartFileFormat
136 : #endif
137 1047 : use String_mod, only: getLowerCase
138 : implicit none
139 : class(RestartFileFormat_type), intent(inout) :: RestartFileFormatObj
140 : character(*), intent(in) :: restartFileFormat
141 1107 : character(:), allocatable :: restartFileFormatLowerCase
142 1107 : RestartFileFormatObj%val = trim(adjustl(restartFileFormat))
143 1107 : if ( RestartFileFormatObj%val==trim(adjustl(RestartFileFormatObj%null)) ) then
144 1023 : RestartFileFormatObj%val = trim(adjustl(RestartFileFormatObj%def))
145 : end if
146 1107 : restartFileFormatLowerCase = getLowerCase(RestartFileFormatObj%val)
147 1107 : RestartFileFormatObj%isBinary = restartFileFormatLowerCase == getLowerCase(RestartFileFormatObj%binary)
148 1107 : RestartFileFormatObj%isAscii = restartFileFormatLowerCase == getLowerCase(RestartFileFormatObj%ascii)
149 1107 : end subroutine setRestartFileFormat
150 :
151 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 :
153 1035 : subroutine checkForSanity(RestartFileFormat,Err,methodName)
154 : #if INTEL_COMPILER_ENABLED && defined DLL_ENABLED && (OS_IS_WINDOWS || defined OS_IS_DARWIN)
155 : !DEC$ ATTRIBUTES DLLEXPORT :: checkForSanity
156 : #endif
157 1107 : use Err_mod, only: Err_type
158 : use String_mod, only: num2str
159 : implicit none
160 : class(RestartFileFormat_type), intent(in) :: RestartFileFormat
161 : character(*), intent(in) :: methodName
162 : type(Err_type), intent(inout) :: Err
163 : character(*), parameter :: PROCEDURE_NAME = "@checkForSanity()"
164 1035 : if ( .not.(RestartFileFormat%isBinary .or. RestartFileFormat%isAscii) ) then
165 6 : Err%occurred = .true.
166 : Err%msg = Err%msg // &
167 : MODULE_NAME // PROCEDURE_NAME // ": Error occurred. &
168 : &The input requested restart file format ('" // RestartFileFormat%val // &
169 : "') represented by the variable restartFileFormat cannot be anything other than '" // &
170 : RestartFileFormat%binary // "' or '" // RestartFileFormat%ascii // "'. If you don't know an appropriate &
171 : &value for RestartFileFormat, drop it from the input list. " // methodName // &
172 6 : " will automatically assign an appropriate value to it.\n\n"
173 : end if
174 2070 : end subroutine checkForSanity
175 :
176 : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 :
178 : end module SpecBase_RestartFileFormat_mod ! LCOV_EXCL_LINE
|