source: palm/trunk/SOURCE/progress_bar.f90 @ 1634

Last change on this file since 1634 was 1469, checked in by maronga, 10 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1 MODULE progress_bar
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: progress_bar.f90 1469 2014-09-24 14:09:56Z hoffmann $
27!
28! 1468 2014-09-24 14:06:57Z maronga
29! Added support for progress file PROGRESS which is used in case of batch jobs
30!
31! Description:
32! ------------
33! This routine prints either a progress bar on the standard output in case of
34! interactive runs, or it prints the progress in a separate file called
35! PROGRESS.
36!------------------------------------------------------------------------------!
37
38    USE control_parameters,                                                    &
39        ONLY : end_time, run_identifier, simulated_time,                       &
40               simulated_time_at_begin, time_restart
41
42    USE, INTRINSIC ::  ISO_FORTRAN_ENV,                                        &
43        ONLY :  OUTPUT_UNIT
44
45    USE kinds
46
47    IMPLICIT NONE
48
49    PRIVATE
50    PUBLIC   batch_job, finish_progress_bar, output_progress_bar
51
52    CHARACTER(LEN=60) ::  bar      !: progress bar, initially filled with "_"
53    CHARACTER(LEN=60) ::  crosses  !: filled with "X"
54
55    INTEGER(iwp) ::  ilength !: length of progress bar filled with "X"
56
57    LOGICAL ::  batch_job = .FALSE.   !: switch to determine the run mode
58
59    REAL(wp) ::  time_to_be_simulated !: in sec
60
61    LOGICAL ::  initialized = .FALSE. !: switch to determine if bar is initialized
62
63    SAVE
64
65 CONTAINS
66
67    SUBROUTINE init_progress_bar
68!------------------------------------------------------------------------------!
69! Description:
70! ------------
71! Initialize the progress bar/file
72!------------------------------------------------------------------------------!
73
74       IMPLICIT NONE
75
76!
77!--    Calculate the time to be simulated in this job
78!--    (in case of automatic restarts the calculated time will probably be
79!--    larger than the time which will actually be simulated)
80       IF ( time_restart /= 9999999.9_wp  .AND.  time_restart < end_time  .AND.&
81            time_restart > simulated_time_at_begin )  THEN
82          time_to_be_simulated = time_restart - simulated_time_at_begin
83       ELSE
84          time_to_be_simulated = end_time     - simulated_time_at_begin
85       ENDIF
86
87       IF ( batch_job )  THEN
88
89          CALL check_open ( 117 )
90          WRITE ( 117, FMT='(A20,/)' ) run_identifier
91
92       ELSE
93          bar = '____________________________________________________________'
94          crosses = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
95!
96!--       Line feed on stdout to seperate the progress bar from previous messages
97          WRITE ( OUTPUT_UNIT, '(1X)' )
98#if defined( __intel_compiler )
99!
100!--       The Intel compiler does not allow to immediately flush the output buffer
101!--       in case that option ADVANCE='NO' is used in the write statement.
102!--       A workaround is to set a special carriage control feature and use "+" as
103!--       first output character, but this non-standard and only available with the
104!--       Intel compiler
105          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='FORTRAN' )
106#endif
107
108       ENDIF
109
110       initialized = .TRUE.
111
112    END SUBROUTINE init_progress_bar
113
114
115    SUBROUTINE output_progress_bar
116!------------------------------------------------------------------------------!
117! Description:
118! ------------
119! Print progress data to standard output (interactive) or to file (batch jobs)
120!------------------------------------------------------------------------------!
121
122       IMPLICIT NONE
123
124       REAL(wp) ::  remaining_time_in_percent  !: remaining time to be simulated
125                                               !: in the job
126       REAL(wp) ::  remaining_time_in_percent_total !: total remaining time of
127                                                    !: the job chain
128
129       IF ( .NOT. initialized )  CALL init_progress_bar
130
131
132       remaining_time_in_percent =                                             &
133          ( simulated_time - simulated_time_at_begin ) / time_to_be_simulated
134
135       remaining_time_in_percent_total = ( simulated_time / end_time )
136
137!
138!--    In batch mode, use a file (PROGRESS), otherwise use progress bar
139       IF ( batch_job )  THEN
140
141          BACKSPACE ( 117 )
142          WRITE ( 117, FMT='(F5.2,1X,F5.2)' ) remaining_time_in_percent,       &
143                                              remaining_time_in_percent_total
144          CALL local_flush( 117 )
145
146       ELSE
147
148!
149!--       Calculate length of progress bar
150          ilength = remaining_time_in_percent * 60.0_wp
151          ilength = MIN( ilength, 60 )
152
153          bar(1:ilength) = crosses(1:ilength)
154
155#if defined( __intel_compiler )
156          WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')' )        &
157                  '+', bar,                                                    &
158                   MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) *       &
159                                  100.0_wp )
160#else
161          WRITE ( OUTPUT_UNIT, '(A,6X,''['',A,''] '',F5.1,'' left'')',         &
162                  ADVANCE='NO' )  CHAR( 13 ), bar,                             &
163                   MAX( 0.0_wp, ( 1.0_wp - remaining_time_in_percent ) *       &
164                                  100.0_wp )
165#endif
166          CALL local_flush( OUTPUT_UNIT )
167
168       ENDIF
169
170    END SUBROUTINE output_progress_bar
171
172    SUBROUTINE finish_progress_bar
173!------------------------------------------------------------------------------!
174! Description:
175! ------------
176! Finalization of the progress bar/file
177!------------------------------------------------------------------------------!
178
179       IMPLICIT NONE
180
181       IF ( batch_job )  THEN
182
183          CALL close_file ( 117 )
184
185       ELSE
186       
187#if defined( __intel_compiler )
188!
189!--       Reset to the default carriage control
190          OPEN ( OUTPUT_UNIT, CARRIAGECONTROL='LIST' )
191#endif
192!
193!--       Line feed when simulation has finished
194          WRITE ( OUTPUT_UNIT, '(1X)' )
195
196       ENDIF
197
198    END SUBROUTINE finish_progress_bar
199
200
201 END MODULE progress_bar
Note: See TracBrowser for help on using the repository browser.