source: palm/trunk/SOURCE/progress_bar_mod.f90 @ 2718

Last change on this file since 2718 was 2718, checked in by maronga, 3 years ago

deleting of deprecated files; headers updated where needed

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1!> @file progress_bar_mod.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: progress_bar_mod.f90 2718 2018-01-02 08:49:38Z maronga $
27! Corrected "Former revisions" section
28!
29! 2696 2017-12-14 17:12:51Z kanani
30! Change in file header (GPL part)
31!
32! 2101 2017-01-05 16:42:31Z suehring
33!
34! 2000 2016-08-20 18:09:15Z knoop
35! Forced header and separation lines into 80 columns
36!
37! 1850 2016-04-08 13:29:27Z maronga
38! Module renamed
39!
40!
41! 1808 2016-04-05 19:44:00Z raasch
42! routine local_flush replaced by FORTRAN statement
43!
44! 1682 2015-10-07 23:56:08Z knoop
45! Code annotations made doxygen readable
46!
47! 1468 2014-09-24 14:06:57Z maronga
48! Added support for progress file PROGRESS which is used in case of batch jobs
49!
50! Description:
51! ------------
52!> This routine prints either a progress bar on the standard output in case of
53!> interactive runs, or it prints the progress in a separate file called
54!> PROGRESS.
55!------------------------------------------------------------------------------!
56 MODULE progress_bar
57 
58
59    USE control_parameters,                                                    &
60        ONLY : end_time, run_identifier, simulated_time,                       &
61               simulated_time_at_begin, time_restart
62
63    USE, INTRINSIC ::  ISO_FORTRAN_ENV,                                        &
64        ONLY :  OUTPUT_UNIT
65
66    USE kinds
67
68    IMPLICIT NONE
69
70    PRIVATE
71    PUBLIC   batch_job, finish_progress_bar, output_progress_bar
72
73    CHARACTER(LEN=60) ::  bar      !< progress bar, initially filled with "_"
74    CHARACTER(LEN=60) ::  crosses  !< filled with "X"
75
76    INTEGER(iwp) ::  ilength !< length of progress bar filled with "X"
77
78    LOGICAL ::  batch_job = .FALSE.   !< switch to determine the run mode
79
80    REAL(wp) ::  time_to_be_simulated !< in sec
81
82    LOGICAL ::  initialized = .FALSE. !< switch to determine if bar is initialized
83
84    SAVE
85
86 CONTAINS
87
88!------------------------------------------------------------------------------!
89! Description:
90! ------------
91!> Initialize the progress bar/file
92!------------------------------------------------------------------------------!
93 
94    SUBROUTINE init_progress_bar
95
96       IMPLICIT NONE
97
98!
99!--    Calculate the time to be simulated in this job
100!--    (in case of automatic restarts the calculated time will probably be
101!--    larger than the time which will actually be simulated)
102       IF ( time_restart /= 9999999.9_wp  .AND.  time_restart < end_time  .AND.&
103            time_restart > simulated_time_at_begin )  THEN
104          time_to_be_simulated = time_restart - simulated_time_at_begin
105       ELSE
106          time_to_be_simulated = end_time     - simulated_time_at_begin
107       ENDIF
108
109       IF ( batch_job )  THEN
110
111          CALL check_open ( 117 )
112          WRITE ( 117, FMT='(A20,/)' ) run_identifier
113
114       ELSE
115          bar = '____________________________________________________________'
116          crosses = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
117!
118!--       Line feed on stdout to seperate the progress bar from previous messages
119          WRITE ( OUTPUT_UNIT, '(1X)' )
120#if defined( __intel_compiler )
121!
122!--       The Intel compiler does not allow to immediately flush the output buffer
123!--       in case that option ADVANCE='NO' is used in the write statement.
124!--       A workaround is to set a special carriage control feature and use "+" as
125!--       first output character, but this non-standard and only available with the
126!--       Intel compiler
127          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='FORTRAN' )
128#endif
129
130       ENDIF
131
132       initialized = .TRUE.
133
134    END SUBROUTINE init_progress_bar
135
136
137!------------------------------------------------------------------------------!
138! Description:
139! ------------
140!> Print progress data to standard output (interactive) or to file (batch jobs)
141!------------------------------------------------------------------------------!
142 
143    SUBROUTINE output_progress_bar
144
145       IMPLICIT NONE
146
147       REAL(wp) ::  remaining_time_in_percent  !< remaining time to be simulated
148                                               !< in the job
149       REAL(wp) ::  remaining_time_in_percent_total !< total remaining time of
150                                                    !< the job chain
151
152       IF ( .NOT. initialized )  CALL init_progress_bar
153
154
155       remaining_time_in_percent =                                             &
156          ( simulated_time - simulated_time_at_begin ) / time_to_be_simulated
157
158       remaining_time_in_percent_total = ( simulated_time / end_time )
159
160!
161!--    In batch mode, use a file (PROGRESS), otherwise use progress bar
162       IF ( batch_job )  THEN
163
164          BACKSPACE ( 117 )
165          WRITE ( 117, FMT='(F5.2,1X,F5.2)' ) remaining_time_in_percent,       &
166                                              remaining_time_in_percent_total
167          FLUSH( 117 )
168
169       ELSE
170
171!
172!--       Calculate length of progress bar
173          ilength = remaining_time_in_percent * 60.0_wp
174          ilength = MIN( ilength, 60 )
175
176          bar(1:ilength) = crosses(1:ilength)
177
178#if defined( __intel_compiler )
179          WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')' )        &
180                  '+', bar,                                                    &
181                   MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) *       &
182                                  100.0_wp )
183#else
184          WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')',         &
185                  ADVANCE='NO' )  CHAR( 13 ), bar,                             &
186                   MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) *       &
187                                  100.0_wp )
188#endif
189          FLUSH( OUTPUT_UNIT )
190
191       ENDIF
192
193    END SUBROUTINE output_progress_bar
194
195!------------------------------------------------------------------------------!
196! Description:
197! ------------
198!> Finalization of the progress bar/file
199!------------------------------------------------------------------------------!
200 
201    SUBROUTINE finish_progress_bar
202
203       IMPLICIT NONE
204
205       IF ( batch_job )  THEN
206
207          CALL close_file ( 117 )
208
209       ELSE
210       
211#if defined( __intel_compiler )
212!
213!--       Reset to the default carriage control
214          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' )
215#endif
216!
217!--       Line feed when simulation has finished
218          WRITE ( OUTPUT_UNIT, '(1X)' )
219
220       ENDIF
221
222    END SUBROUTINE finish_progress_bar
223
224
225 END MODULE progress_bar
Note: See TracBrowser for help on using the repository browser.