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

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

New flag files allow to force unscheduled termination/restarts of batch jobs, progress output is made for batch runs, small adjustments for lxce6 and lccrayh/lccrayb

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