Line data Source code
1 : ! ***********************************************************************
2 : !
3 : ! Copyright (C) 2010-2022 The MESA Team, Bill Paxton & Matthias Fabry
4 : !
5 : ! This program is free software: you can redistribute it and/or modify
6 : ! it under the terms of the GNU Lesser General Public License
7 : ! as published by the Free Software Foundation,
8 : ! either version 3 of the License, or (at your option) any later version.
9 : !
10 : ! This program is distributed in the hope that it will be useful,
11 : ! but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 : ! See the GNU Lesser General Public License for more details.
14 : !
15 : ! You should have received a copy of the GNU Lesser General Public License
16 : ! along with this program. If not, see <https://www.gnu.org/licenses/>.
17 : !
18 : ! ***********************************************************************
19 :
20 : module pgbinary
21 :
22 : use binary_def
23 : use const_def, only: dp, i8
24 : use chem_def, only : category_name
25 : use rates_def, only : i_rate
26 : use pgbinary_support
27 : use pgstar, only : pgstar_clear, read_pgstar_data
28 :
29 : implicit none
30 :
31 :
32 : contains
33 :
34 : ! pgbinary interface
35 0 : subroutine start_new_run_for_pgbinary(b, ierr) ! reset logs
36 : use binary_def, only : binary_info
37 : type (binary_info), pointer :: b
38 : integer, intent(out) :: ierr
39 0 : call do_start_new_run_for_pgbinary(b, ierr)
40 0 : end subroutine start_new_run_for_pgbinary
41 :
42 :
43 0 : subroutine restart_run_for_pgbinary(b, ierr)
44 0 : use binary_def, only : binary_info
45 : type (binary_info), pointer :: b
46 : integer, intent(out) :: ierr
47 0 : call do_restart_run_for_pgbinary(b, ierr)
48 0 : end subroutine restart_run_for_pgbinary
49 :
50 :
51 0 : subroutine read_pgbinary_controls(b, ierr)
52 0 : use binary_def, only : binary_info
53 : type (binary_info), pointer :: b
54 : integer, intent(out) :: ierr
55 0 : call do_read_pgbinary_controls(b, 'inlist', ierr)
56 0 : end subroutine read_pgbinary_controls
57 :
58 :
59 0 : subroutine read_pgbinary_inlist(b, inlist_fname, ierr)
60 0 : use binary_def, only : binary_info
61 : type (binary_info), pointer :: b
62 : character(*), intent(in) :: inlist_fname
63 : integer, intent(out) :: ierr
64 0 : call do_read_pgbinary_controls(b, inlist_fname, ierr)
65 0 : end subroutine read_pgbinary_inlist
66 :
67 0 : subroutine update_pgbinary_plots(b, must_write_files, ierr)
68 0 : use binary_def, only : binary_info
69 : type (binary_info), pointer :: b
70 : logical, intent(in) :: must_write_files
71 : integer, intent(out) :: ierr
72 : call do_pgbinary_plots(&
73 : b, must_write_files, &
74 0 : ierr)
75 0 : end subroutine update_pgbinary_plots
76 :
77 :
78 0 : subroutine do_create_file_name(b, dir, prefix, name)
79 0 : use pgbinary_support, only : create_file_name
80 : type (binary_info), pointer :: b
81 : character (len = *), intent(in) :: dir, prefix
82 : character (len = *), intent(out) :: name
83 0 : call create_file_name(b, dir, prefix, name)
84 0 : end subroutine do_create_file_name
85 :
86 :
87 0 : subroutine do_write_plot_to_file(b, p, filename, ierr)
88 0 : use binary_def, only : binary_info, pgbinary_win_file_data
89 : use pgbinary_support, only : write_plot_to_file
90 : type (binary_info), pointer :: b
91 : type (pgbinary_win_file_data), pointer :: p
92 : character (len = *), intent(in) :: filename
93 : integer, intent(out) :: ierr
94 0 : call write_plot_to_file(b, p, filename, ierr)
95 0 : end subroutine do_write_plot_to_file
96 :
97 :
98 0 : subroutine do_show_pgbinary_annotations(&
99 : b, show_annotation1, show_annotation2, show_annotation3)
100 0 : use pgbinary_support, only : show_annotations
101 : type (binary_info), pointer :: b
102 : logical, intent(in) :: &
103 : show_annotation1, show_annotation2, show_annotation3
104 : call show_annotations(&
105 0 : b, show_annotation1, show_annotation2, show_annotation3)
106 0 : end subroutine do_show_pgbinary_annotations
107 :
108 :
109 0 : subroutine do_start_new_run_for_pgbinary(b, ierr) ! reset logs
110 0 : use utils_lib
111 : type (binary_info), pointer :: b
112 : integer, intent(out) :: ierr
113 : integer :: iounit
114 : character (len = strlen) :: fname
115 : logical :: fexist
116 0 : ierr = 0
117 0 : fname = trim(b% photo_directory) // '/pgbinary.dat'
118 0 : inquire(file = trim(fname), exist = fexist)
119 0 : if (fexist) then
120 0 : open(newunit = iounit, file = trim(fname), status = 'replace', action = 'write')
121 0 : close(iounit)
122 : end if
123 0 : call pgbinary_clear(b)
124 0 : end subroutine do_start_new_run_for_pgbinary
125 :
126 :
127 0 : subroutine do_restart_run_for_pgbinary(b, ierr)
128 : type (binary_info), pointer :: b
129 : integer, intent(out) :: ierr
130 : logical :: fexists
131 0 : ierr = 0
132 0 : if (.not. b% job% pgbinary_flag) return
133 0 : call pgbinary_clear(b)
134 0 : call read_pgbinary_data(b, ierr)
135 0 : if (ierr /= 0) then
136 0 : write(*, *) 'failed in read_pgbinary_data'
137 0 : ierr = 0
138 : end if
139 : ! read pgstar if present
140 0 : if (b% have_star_1) then
141 0 : inquire(file = trim(b% s1% log_directory) // '/pgstar.dat', exist = fexists)
142 0 : if (fexists) then
143 0 : call pgstar_clear(b% s1)
144 0 : call read_pgstar_data(b% s1, ierr)
145 : end if
146 : end if
147 0 : if (b% have_star_2) then
148 0 : inquire(file = trim(b% s2% log_directory) // '/pgstar.dat', exist = fexists)
149 0 : if (fexists) then
150 0 : call pgstar_clear(b% s2)
151 0 : call read_pgstar_data(b% s2, ierr)
152 : end if
153 : end if
154 : end subroutine do_restart_run_for_pgbinary
155 :
156 :
157 0 : subroutine do_read_pgbinary_controls(b, inlist_fname, ierr)
158 : use pgbinary_ctrls_io, only : read_pgbinary
159 : type (binary_info), pointer :: b
160 : character(*), intent(in) :: inlist_fname
161 : integer, intent(out) :: ierr
162 : ierr = 0
163 0 : call read_pgbinary(b, inlist_fname, ierr)
164 0 : if (ierr /= 0) then
165 0 : write(*, *) 'pgbinary failed in reading ' // trim(inlist_fname)
166 : return
167 : end if
168 0 : call set_win_file_data(b, ierr)
169 0 : end subroutine do_read_pgbinary_controls
170 :
171 :
172 0 : subroutine set_win_file_data(b, ierr)
173 0 : use pgbinary_summary_history, only : summary_history_plot
174 : use pgbinary_grid, only : &
175 : grid1_plot, grid2_plot, grid3_plot, grid4_plot, &
176 : grid5_plot, grid6_plot, grid7_plot, grid8_plot, grid9_plot
177 : use pgbinary_summary, only : &
178 : Text_Summary1_Plot, Text_Summary2_Plot, Text_Summary3_Plot, &
179 : Text_Summary4_Plot, Text_Summary5_Plot, Text_Summary6_Plot, &
180 : Text_Summary7_Plot, Text_Summary8_Plot, Text_Summary9_Plot
181 : use pgbinary_history_panels, only : &
182 : History_Panels1_plot, History_Panels2_plot, History_Panels3_plot, &
183 : History_Panels4_plot, History_Panels5_plot, History_Panels6_plot, &
184 : History_Panels7_plot, History_Panels8_plot, History_Panels9_plot
185 : use pgbinary_hist_track, only : &
186 : History_Track1_plot, History_Track2_plot, History_Track3_plot, &
187 : History_Track4_plot, History_Track5_plot, History_Track6_plot, &
188 : History_Track7_plot, History_Track8_plot, History_Track9_plot
189 : use pgbinary_star, only : &
190 : Star1_plot, Star2_plot
191 : use pgbinary_orbit, only : Orbit_plot
192 : type (binary_info), pointer :: b
193 : integer, intent(out) :: ierr
194 :
195 : type (pgbinary_win_file_data), pointer :: p
196 : integer :: i
197 :
198 : ! store win and file info in records
199 :
200 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary1)
201 0 : p% plot => Text_Summary1_Plot
202 0 : p% id = i_Binary_Text_Summary1
203 0 : p% name = 'Text_Summary1'
204 0 : p% win_flag = b% pg% Text_Summary1_win_flag
205 0 : p% win_width = b% pg% Text_Summary1_win_width
206 0 : p% win_aspect_ratio = b% pg% Text_Summary1_win_aspect_ratio
207 0 : p% file_flag = b% pg% Text_Summary1_file_flag
208 0 : p% file_dir = b% pg% Text_Summary1_file_dir
209 0 : p% file_prefix = b% pg% Text_Summary1_file_prefix
210 0 : p% file_interval = b% pg% Text_Summary1_file_interval
211 0 : p% file_width = b% pg% Text_Summary1_file_width
212 0 : p% file_aspect_ratio = b% pg% Text_Summary1_file_aspect_ratio
213 :
214 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary2)
215 0 : p% plot => Text_Summary2_Plot
216 0 : p% id = i_Binary_Text_Summary2
217 0 : p% name = 'Text_Summary2'
218 0 : p% win_flag = b% pg% Text_Summary2_win_flag
219 0 : p% win_width = b% pg% Text_Summary2_win_width
220 0 : p% win_aspect_ratio = b% pg% Text_Summary2_win_aspect_ratio
221 0 : p% file_flag = b% pg% Text_Summary2_file_flag
222 0 : p% file_dir = b% pg% Text_Summary2_file_dir
223 0 : p% file_prefix = b% pg% Text_Summary2_file_prefix
224 0 : p% file_interval = b% pg% Text_Summary2_file_interval
225 0 : p% file_width = b% pg% Text_Summary2_file_width
226 0 : p% file_aspect_ratio = b% pg% Text_Summary2_file_aspect_ratio
227 :
228 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary3)
229 0 : p% plot => Text_Summary3_Plot
230 0 : p% id = i_Binary_Text_Summary3
231 0 : p% name = 'Text_Summary3'
232 0 : p% win_flag = b% pg% Text_Summary3_win_flag
233 0 : p% win_width = b% pg% Text_Summary3_win_width
234 0 : p% win_aspect_ratio = b% pg% Text_Summary3_win_aspect_ratio
235 0 : p% file_flag = b% pg% Text_Summary3_file_flag
236 0 : p% file_dir = b% pg% Text_Summary3_file_dir
237 0 : p% file_prefix = b% pg% Text_Summary3_file_prefix
238 0 : p% file_interval = b% pg% Text_Summary3_file_interval
239 0 : p% file_width = b% pg% Text_Summary3_file_width
240 0 : p% file_aspect_ratio = b% pg% Text_Summary3_file_aspect_ratio
241 :
242 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary4)
243 0 : p% plot => Text_Summary4_Plot
244 0 : p% id = i_Binary_Text_Summary4
245 0 : p% name = 'Text_Summary4'
246 0 : p% win_flag = b% pg% Text_Summary4_win_flag
247 0 : p% win_width = b% pg% Text_Summary4_win_width
248 0 : p% win_aspect_ratio = b% pg% Text_Summary4_win_aspect_ratio
249 0 : p% file_flag = b% pg% Text_Summary4_file_flag
250 0 : p% file_dir = b% pg% Text_Summary4_file_dir
251 0 : p% file_prefix = b% pg% Text_Summary4_file_prefix
252 0 : p% file_interval = b% pg% Text_Summary4_file_interval
253 0 : p% file_width = b% pg% Text_Summary4_file_width
254 0 : p% file_aspect_ratio = b% pg% Text_Summary4_file_aspect_ratio
255 :
256 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary5)
257 0 : p% plot => Text_Summary5_Plot
258 0 : p% id = i_Binary_Text_Summary5
259 0 : p% name = 'Text_Summary5'
260 0 : p% win_flag = b% pg% Text_Summary5_win_flag
261 0 : p% win_width = b% pg% Text_Summary5_win_width
262 0 : p% win_aspect_ratio = b% pg% Text_Summary5_win_aspect_ratio
263 0 : p% file_flag = b% pg% Text_Summary5_file_flag
264 0 : p% file_dir = b% pg% Text_Summary5_file_dir
265 0 : p% file_prefix = b% pg% Text_Summary5_file_prefix
266 0 : p% file_interval = b% pg% Text_Summary5_file_interval
267 0 : p% file_width = b% pg% Text_Summary5_file_width
268 0 : p% file_aspect_ratio = b% pg% Text_Summary5_file_aspect_ratio
269 :
270 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary6)
271 0 : p% plot => Text_Summary6_Plot
272 0 : p% id = i_Binary_Text_Summary6
273 0 : p% name = 'Text_Summary6'
274 0 : p% win_flag = b% pg% Text_Summary6_win_flag
275 0 : p% win_width = b% pg% Text_Summary6_win_width
276 0 : p% win_aspect_ratio = b% pg% Text_Summary6_win_aspect_ratio
277 0 : p% file_flag = b% pg% Text_Summary6_file_flag
278 0 : p% file_dir = b% pg% Text_Summary6_file_dir
279 0 : p% file_prefix = b% pg% Text_Summary6_file_prefix
280 0 : p% file_interval = b% pg% Text_Summary6_file_interval
281 0 : p% file_width = b% pg% Text_Summary6_file_width
282 0 : p% file_aspect_ratio = b% pg% Text_Summary6_file_aspect_ratio
283 :
284 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary7)
285 0 : p% plot => Text_Summary7_Plot
286 0 : p% id = i_Binary_Text_Summary7
287 0 : p% name = 'Text_Summary7'
288 0 : p% win_flag = b% pg% Text_Summary7_win_flag
289 0 : p% win_width = b% pg% Text_Summary7_win_width
290 0 : p% win_aspect_ratio = b% pg% Text_Summary7_win_aspect_ratio
291 0 : p% file_flag = b% pg% Text_Summary7_file_flag
292 0 : p% file_dir = b% pg% Text_Summary7_file_dir
293 0 : p% file_prefix = b% pg% Text_Summary7_file_prefix
294 0 : p% file_interval = b% pg% Text_Summary7_file_interval
295 0 : p% file_width = b% pg% Text_Summary7_file_width
296 0 : p% file_aspect_ratio = b% pg% Text_Summary7_file_aspect_ratio
297 :
298 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary8)
299 0 : p% plot => Text_Summary8_Plot
300 0 : p% id = i_Binary_Text_Summary8
301 0 : p% name = 'Text_Summary8'
302 0 : p% win_flag = b% pg% Text_Summary8_win_flag
303 0 : p% win_width = b% pg% Text_Summary8_win_width
304 0 : p% win_aspect_ratio = b% pg% Text_Summary8_win_aspect_ratio
305 0 : p% file_flag = b% pg% Text_Summary8_file_flag
306 0 : p% file_dir = b% pg% Text_Summary8_file_dir
307 0 : p% file_prefix = b% pg% Text_Summary8_file_prefix
308 0 : p% file_interval = b% pg% Text_Summary8_file_interval
309 0 : p% file_width = b% pg% Text_Summary8_file_width
310 0 : p% file_aspect_ratio = b% pg% Text_Summary8_file_aspect_ratio
311 :
312 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Text_Summary9)
313 0 : p% plot => Text_Summary9_Plot
314 0 : p% id = i_Binary_Text_Summary9
315 0 : p% name = 'Text_Summary9'
316 0 : p% win_flag = b% pg% Text_Summary9_win_flag
317 0 : p% win_width = b% pg% Text_Summary9_win_width
318 0 : p% win_aspect_ratio = b% pg% Text_Summary9_win_aspect_ratio
319 0 : p% file_flag = b% pg% Text_Summary9_file_flag
320 0 : p% file_dir = b% pg% Text_Summary9_file_dir
321 0 : p% file_prefix = b% pg% Text_Summary9_file_prefix
322 0 : p% file_interval = b% pg% Text_Summary9_file_interval
323 0 : p% file_width = b% pg% Text_Summary9_file_width
324 0 : p% file_aspect_ratio = b% pg% Text_Summary9_file_aspect_ratio
325 :
326 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels1)
327 0 : p% plot => History_Panels1_plot
328 0 : p% id = i_Binary_Hist_Panels1
329 0 : p% name = 'History_Panels1'
330 0 : p% win_flag = b% pg% History_Panels1_win_flag
331 0 : p% win_width = b% pg% History_Panels1_win_width
332 0 : p% win_aspect_ratio = b% pg% History_Panels1_win_aspect_ratio
333 0 : p% file_flag = b% pg% History_Panels1_file_flag
334 0 : p% file_dir = b% pg% History_Panels1_file_dir
335 0 : p% file_prefix = b% pg% History_Panels1_file_prefix
336 0 : p% file_interval = b% pg% History_Panels1_file_interval
337 0 : p% file_width = b% pg% History_Panels1_file_width
338 0 : p% file_aspect_ratio = b% pg% History_Panels1_file_aspect_ratio
339 :
340 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels2)
341 0 : p% plot => History_Panels2_plot
342 0 : p% id = i_Binary_Hist_Panels2
343 0 : p% name = 'History_Panels2'
344 0 : p% win_flag = b% pg% History_Panels2_win_flag
345 0 : p% win_width = b% pg% History_Panels2_win_width
346 0 : p% win_aspect_ratio = b% pg% History_Panels2_win_aspect_ratio
347 0 : p% file_flag = b% pg% History_Panels2_file_flag
348 0 : p% file_dir = b% pg% History_Panels2_file_dir
349 0 : p% file_prefix = b% pg% History_Panels2_file_prefix
350 0 : p% file_interval = b% pg% History_Panels2_file_interval
351 0 : p% file_width = b% pg% History_Panels2_file_width
352 0 : p% file_aspect_ratio = b% pg% History_Panels2_file_aspect_ratio
353 :
354 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels3)
355 0 : p% plot => History_Panels3_plot
356 0 : p% id = i_Binary_Hist_Panels3
357 0 : p% name = 'History_Panels3'
358 0 : p% win_flag = b% pg% History_Panels3_win_flag
359 0 : p% win_width = b% pg% History_Panels3_win_width
360 0 : p% win_aspect_ratio = b% pg% History_Panels3_win_aspect_ratio
361 0 : p% file_flag = b% pg% History_Panels3_file_flag
362 0 : p% file_dir = b% pg% History_Panels3_file_dir
363 0 : p% file_prefix = b% pg% History_Panels3_file_prefix
364 0 : p% file_interval = b% pg% History_Panels3_file_interval
365 0 : p% file_width = b% pg% History_Panels3_file_width
366 0 : p% file_aspect_ratio = b% pg% History_Panels3_file_aspect_ratio
367 :
368 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels4)
369 0 : p% plot => History_Panels4_plot
370 0 : p% id = i_Binary_Hist_Panels4
371 0 : p% name = 'History_Panels4'
372 0 : p% win_flag = b% pg% History_Panels4_win_flag
373 0 : p% win_width = b% pg% History_Panels4_win_width
374 0 : p% win_aspect_ratio = b% pg% History_Panels4_win_aspect_ratio
375 0 : p% file_flag = b% pg% History_Panels4_file_flag
376 0 : p% file_dir = b% pg% History_Panels4_file_dir
377 0 : p% file_prefix = b% pg% History_Panels4_file_prefix
378 0 : p% file_interval = b% pg% History_Panels4_file_interval
379 0 : p% file_width = b% pg% History_Panels4_file_width
380 0 : p% file_aspect_ratio = b% pg% History_Panels4_file_aspect_ratio
381 :
382 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels5)
383 0 : p% plot => History_Panels5_plot
384 0 : p% id = i_Binary_Hist_Panels5
385 0 : p% name = 'History_Panels5'
386 0 : p% win_flag = b% pg% History_Panels5_win_flag
387 0 : p% win_width = b% pg% History_Panels5_win_width
388 0 : p% win_aspect_ratio = b% pg% History_Panels5_win_aspect_ratio
389 0 : p% file_flag = b% pg% History_Panels5_file_flag
390 0 : p% file_dir = b% pg% History_Panels5_file_dir
391 0 : p% file_prefix = b% pg% History_Panels5_file_prefix
392 0 : p% file_interval = b% pg% History_Panels5_file_interval
393 0 : p% file_width = b% pg% History_Panels5_file_width
394 0 : p% file_aspect_ratio = b% pg% History_Panels5_file_aspect_ratio
395 :
396 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels6)
397 0 : p% plot => History_Panels6_plot
398 0 : p% id = i_Binary_Hist_Panels6
399 0 : p% name = 'History_Panels6'
400 0 : p% win_flag = b% pg% History_Panels6_win_flag
401 0 : p% win_width = b% pg% History_Panels6_win_width
402 0 : p% win_aspect_ratio = b% pg% History_Panels6_win_aspect_ratio
403 0 : p% file_flag = b% pg% History_Panels6_file_flag
404 0 : p% file_dir = b% pg% History_Panels6_file_dir
405 0 : p% file_prefix = b% pg% History_Panels6_file_prefix
406 0 : p% file_interval = b% pg% History_Panels6_file_interval
407 0 : p% file_width = b% pg% History_Panels6_file_width
408 0 : p% file_aspect_ratio = b% pg% History_Panels6_file_aspect_ratio
409 :
410 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels7)
411 0 : p% plot => History_Panels7_plot
412 0 : p% id = i_Binary_Hist_Panels7
413 0 : p% name = 'History_Panels7'
414 0 : p% win_flag = b% pg% History_Panels7_win_flag
415 0 : p% win_width = b% pg% History_Panels7_win_width
416 0 : p% win_aspect_ratio = b% pg% History_Panels7_win_aspect_ratio
417 0 : p% file_flag = b% pg% History_Panels7_file_flag
418 0 : p% file_dir = b% pg% History_Panels7_file_dir
419 0 : p% file_prefix = b% pg% History_Panels7_file_prefix
420 0 : p% file_interval = b% pg% History_Panels7_file_interval
421 0 : p% file_width = b% pg% History_Panels7_file_width
422 0 : p% file_aspect_ratio = b% pg% History_Panels7_file_aspect_ratio
423 :
424 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels8)
425 0 : p% plot => History_Panels8_plot
426 0 : p% id = i_Binary_Hist_Panels8
427 0 : p% name = 'History_Panels8'
428 0 : p% win_flag = b% pg% History_Panels8_win_flag
429 0 : p% win_width = b% pg% History_Panels8_win_width
430 0 : p% win_aspect_ratio = b% pg% History_Panels8_win_aspect_ratio
431 0 : p% file_flag = b% pg% History_Panels8_file_flag
432 0 : p% file_dir = b% pg% History_Panels8_file_dir
433 0 : p% file_prefix = b% pg% History_Panels8_file_prefix
434 0 : p% file_interval = b% pg% History_Panels8_file_interval
435 0 : p% file_width = b% pg% History_Panels8_file_width
436 0 : p% file_aspect_ratio = b% pg% History_Panels8_file_aspect_ratio
437 :
438 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Panels9)
439 0 : p% plot => History_Panels9_plot
440 0 : p% id = i_Binary_Hist_Panels9
441 0 : p% name = 'History_Panels9'
442 0 : p% win_flag = b% pg% History_Panels9_win_flag
443 0 : p% win_width = b% pg% History_Panels9_win_width
444 0 : p% win_aspect_ratio = b% pg% History_Panels9_win_aspect_ratio
445 0 : p% file_flag = b% pg% History_Panels9_file_flag
446 0 : p% file_dir = b% pg% History_Panels9_file_dir
447 0 : p% file_prefix = b% pg% History_Panels9_file_prefix
448 0 : p% file_interval = b% pg% History_Panels9_file_interval
449 0 : p% file_width = b% pg% History_Panels9_file_width
450 0 : p% file_aspect_ratio = b% pg% History_Panels9_file_aspect_ratio
451 :
452 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track1)
453 0 : p% plot => History_Track1_plot
454 0 : p% id = i_Binary_Hist_Track1
455 0 : p% name = 'History_Track1'
456 0 : p% win_flag = b% pg% History_Track1_win_flag
457 0 : p% win_width = b% pg% History_Track1_win_width
458 0 : p% win_aspect_ratio = b% pg% History_Track1_win_aspect_ratio
459 0 : p% file_flag = b% pg% History_Track1_file_flag
460 0 : p% file_dir = b% pg% History_Track1_file_dir
461 0 : p% file_prefix = b% pg% History_Track1_file_prefix
462 0 : p% file_interval = b% pg% History_Track1_file_interval
463 0 : p% file_width = b% pg% History_Track1_file_width
464 0 : p% file_aspect_ratio = b% pg% History_Track1_file_aspect_ratio
465 :
466 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track2)
467 0 : p% plot => History_Track2_plot
468 0 : p% id = i_Binary_Hist_Track2
469 0 : p% name = 'History_Track2'
470 0 : p% win_flag = b% pg% History_Track2_win_flag
471 0 : p% win_width = b% pg% History_Track2_win_width
472 0 : p% win_aspect_ratio = b% pg% History_Track2_win_aspect_ratio
473 0 : p% file_flag = b% pg% History_Track2_file_flag
474 0 : p% file_dir = b% pg% History_Track2_file_dir
475 0 : p% file_prefix = b% pg% History_Track2_file_prefix
476 0 : p% file_interval = b% pg% History_Track2_file_interval
477 0 : p% file_width = b% pg% History_Track2_file_width
478 0 : p% file_aspect_ratio = b% pg% History_Track2_file_aspect_ratio
479 :
480 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track3)
481 0 : p% plot => History_Track3_plot
482 0 : p% id = i_Binary_Hist_Track3
483 0 : p% name = 'History_Track3'
484 0 : p% win_flag = b% pg% History_Track3_win_flag
485 0 : p% win_width = b% pg% History_Track3_win_width
486 0 : p% win_aspect_ratio = b% pg% History_Track3_win_aspect_ratio
487 0 : p% file_flag = b% pg% History_Track3_file_flag
488 0 : p% file_dir = b% pg% History_Track3_file_dir
489 0 : p% file_prefix = b% pg% History_Track3_file_prefix
490 0 : p% file_interval = b% pg% History_Track3_file_interval
491 0 : p% file_width = b% pg% History_Track3_file_width
492 0 : p% file_aspect_ratio = b% pg% History_Track3_file_aspect_ratio
493 :
494 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track4)
495 0 : p% plot => History_Track4_plot
496 0 : p% id = i_Binary_Hist_Track4
497 0 : p% name = 'History_Track4'
498 0 : p% win_flag = b% pg% History_Track4_win_flag
499 0 : p% win_width = b% pg% History_Track4_win_width
500 0 : p% win_aspect_ratio = b% pg% History_Track4_win_aspect_ratio
501 0 : p% file_flag = b% pg% History_Track4_file_flag
502 0 : p% file_dir = b% pg% History_Track4_file_dir
503 0 : p% file_prefix = b% pg% History_Track4_file_prefix
504 0 : p% file_interval = b% pg% History_Track4_file_interval
505 0 : p% file_width = b% pg% History_Track4_file_width
506 0 : p% file_aspect_ratio = b% pg% History_Track4_file_aspect_ratio
507 :
508 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track5)
509 0 : p% plot => History_Track5_plot
510 0 : p% id = i_Binary_Hist_Track5
511 0 : p% name = 'History_Track5'
512 0 : p% win_flag = b% pg% History_Track5_win_flag
513 0 : p% win_width = b% pg% History_Track5_win_width
514 0 : p% win_aspect_ratio = b% pg% History_Track5_win_aspect_ratio
515 0 : p% file_flag = b% pg% History_Track5_file_flag
516 0 : p% file_dir = b% pg% History_Track5_file_dir
517 0 : p% file_prefix = b% pg% History_Track5_file_prefix
518 0 : p% file_interval = b% pg% History_Track5_file_interval
519 0 : p% file_width = b% pg% History_Track5_file_width
520 0 : p% file_aspect_ratio = b% pg% History_Track5_file_aspect_ratio
521 :
522 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track6)
523 0 : p% plot => History_Track6_plot
524 0 : p% id = i_Binary_Hist_Track6
525 0 : p% name = 'History_Track6'
526 0 : p% win_flag = b% pg% History_Track6_win_flag
527 0 : p% win_width = b% pg% History_Track6_win_width
528 0 : p% win_aspect_ratio = b% pg% History_Track6_win_aspect_ratio
529 0 : p% file_flag = b% pg% History_Track6_file_flag
530 0 : p% file_dir = b% pg% History_Track6_file_dir
531 0 : p% file_prefix = b% pg% History_Track6_file_prefix
532 0 : p% file_interval = b% pg% History_Track6_file_interval
533 0 : p% file_width = b% pg% History_Track6_file_width
534 0 : p% file_aspect_ratio = b% pg% History_Track6_file_aspect_ratio
535 :
536 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track7)
537 0 : p% plot => History_Track7_plot
538 0 : p% id = i_Binary_Hist_Track7
539 0 : p% name = 'History_Track7'
540 0 : p% win_flag = b% pg% History_Track7_win_flag
541 0 : p% win_width = b% pg% History_Track7_win_width
542 0 : p% win_aspect_ratio = b% pg% History_Track7_win_aspect_ratio
543 0 : p% file_flag = b% pg% History_Track7_file_flag
544 0 : p% file_dir = b% pg% History_Track7_file_dir
545 0 : p% file_prefix = b% pg% History_Track7_file_prefix
546 0 : p% file_interval = b% pg% History_Track7_file_interval
547 0 : p% file_width = b% pg% History_Track7_file_width
548 0 : p% file_aspect_ratio = b% pg% History_Track7_file_aspect_ratio
549 :
550 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track8)
551 0 : p% plot => History_Track8_plot
552 0 : p% id = i_Binary_Hist_Track8
553 0 : p% name = 'History_Track8'
554 0 : p% win_flag = b% pg% History_Track8_win_flag
555 0 : p% win_width = b% pg% History_Track8_win_width
556 0 : p% win_aspect_ratio = b% pg% History_Track8_win_aspect_ratio
557 0 : p% file_flag = b% pg% History_Track8_file_flag
558 0 : p% file_dir = b% pg% History_Track8_file_dir
559 0 : p% file_prefix = b% pg% History_Track8_file_prefix
560 0 : p% file_interval = b% pg% History_Track8_file_interval
561 0 : p% file_width = b% pg% History_Track8_file_width
562 0 : p% file_aspect_ratio = b% pg% History_Track8_file_aspect_ratio
563 :
564 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Hist_Track9)
565 0 : p% plot => History_Track9_plot
566 0 : p% id = i_Binary_Hist_Track9
567 0 : p% name = 'History_Track9'
568 0 : p% win_flag = b% pg% History_Track9_win_flag
569 0 : p% win_width = b% pg% History_Track9_win_width
570 0 : p% win_aspect_ratio = b% pg% History_Track9_win_aspect_ratio
571 0 : p% file_flag = b% pg% History_Track9_file_flag
572 0 : p% file_dir = b% pg% History_Track9_file_dir
573 0 : p% file_prefix = b% pg% History_Track9_file_prefix
574 0 : p% file_interval = b% pg% History_Track9_file_interval
575 0 : p% file_width = b% pg% History_Track9_file_width
576 0 : p% file_aspect_ratio = b% pg% History_Track9_file_aspect_ratio
577 :
578 0 : p => b% pg% pgbinary_win_file_ptr(i_Summary_Binary_History)
579 0 : p% plot => summary_history_plot
580 0 : p% id = i_Summary_Binary_History
581 0 : p% name = 'Summary_History'
582 0 : p% win_flag = b% pg% Summary_History_win_flag
583 0 : p% win_width = b% pg% Summary_History_win_width
584 0 : p% win_aspect_ratio = b% pg% Summary_History_win_aspect_ratio
585 0 : p% file_flag = b% pg% Summary_History_file_flag
586 0 : p% file_dir = b% pg% Summary_History_file_dir
587 0 : p% file_prefix = b% pg% Summary_History_file_prefix
588 0 : p% file_interval = b% pg% Summary_History_file_interval
589 0 : p% file_width = b% pg% Summary_History_file_width
590 0 : p% file_aspect_ratio = b% pg% Summary_History_file_aspect_ratio
591 :
592 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid1)
593 0 : p% plot => grid1_plot
594 0 : p% id = i_Binary_Grid1
595 0 : p% name = 'Grid1'
596 0 : p% win_flag = b% pg% Grid1_win_flag
597 0 : p% win_width = b% pg% Grid1_win_width
598 0 : p% win_aspect_ratio = b% pg% Grid1_win_aspect_ratio
599 0 : p% file_flag = b% pg% Grid1_file_flag
600 0 : p% file_dir = b% pg% Grid1_file_dir
601 0 : p% file_prefix = b% pg% Grid1_file_prefix
602 0 : p% file_interval = b% pg% Grid1_file_interval
603 0 : p% file_width = b% pg% Grid1_file_width
604 0 : p% file_aspect_ratio = b% pg% Grid1_file_aspect_ratio
605 :
606 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid2)
607 0 : p% plot => grid2_plot
608 0 : p% id = i_Binary_Grid2
609 0 : p% name = 'Grid2'
610 0 : p% win_flag = b% pg% Grid2_win_flag
611 0 : p% win_width = b% pg% Grid2_win_width
612 0 : p% win_aspect_ratio = b% pg% Grid2_win_aspect_ratio
613 0 : p% file_flag = b% pg% Grid2_file_flag
614 0 : p% file_dir = b% pg% Grid2_file_dir
615 0 : p% file_prefix = b% pg% Grid2_file_prefix
616 0 : p% file_interval = b% pg% Grid2_file_interval
617 0 : p% file_width = b% pg% Grid2_file_width
618 0 : p% file_aspect_ratio = b% pg% Grid2_file_aspect_ratio
619 :
620 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid3)
621 0 : p% plot => grid3_plot
622 0 : p% id = i_Binary_Grid3
623 0 : p% name = 'Grid3'
624 0 : p% win_flag = b% pg% Grid3_win_flag
625 0 : p% win_width = b% pg% Grid3_win_width
626 0 : p% win_aspect_ratio = b% pg% Grid3_win_aspect_ratio
627 0 : p% file_flag = b% pg% Grid3_file_flag
628 0 : p% file_dir = b% pg% Grid3_file_dir
629 0 : p% file_prefix = b% pg% Grid3_file_prefix
630 0 : p% file_interval = b% pg% Grid3_file_interval
631 0 : p% file_width = b% pg% Grid3_file_width
632 0 : p% file_aspect_ratio = b% pg% Grid3_file_aspect_ratio
633 :
634 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid4)
635 0 : p% plot => grid4_plot
636 0 : p% id = i_Binary_Grid4
637 0 : p% name = 'Grid4'
638 0 : p% win_flag = b% pg% Grid4_win_flag
639 0 : p% win_width = b% pg% Grid4_win_width
640 0 : p% win_aspect_ratio = b% pg% Grid4_win_aspect_ratio
641 0 : p% file_flag = b% pg% Grid4_file_flag
642 0 : p% file_dir = b% pg% Grid4_file_dir
643 0 : p% file_prefix = b% pg% Grid4_file_prefix
644 0 : p% file_interval = b% pg% Grid4_file_interval
645 0 : p% file_width = b% pg% Grid4_file_width
646 0 : p% file_aspect_ratio = b% pg% Grid4_file_aspect_ratio
647 :
648 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid5)
649 0 : p% plot => grid5_plot
650 0 : p% id = i_Binary_Grid5
651 0 : p% name = 'Grid5'
652 0 : p% win_flag = b% pg% Grid5_win_flag
653 0 : p% win_width = b% pg% Grid5_win_width
654 0 : p% win_aspect_ratio = b% pg% Grid5_win_aspect_ratio
655 0 : p% file_flag = b% pg% Grid5_file_flag
656 0 : p% file_dir = b% pg% Grid5_file_dir
657 0 : p% file_prefix = b% pg% Grid5_file_prefix
658 0 : p% file_interval = b% pg% Grid5_file_interval
659 0 : p% file_width = b% pg% Grid5_file_width
660 0 : p% file_aspect_ratio = b% pg% Grid5_file_aspect_ratio
661 :
662 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid6)
663 0 : p% plot => grid6_plot
664 0 : p% id = i_Binary_Grid6
665 0 : p% name = 'Grid6'
666 0 : p% win_flag = b% pg% Grid6_win_flag
667 0 : p% win_width = b% pg% Grid6_win_width
668 0 : p% win_aspect_ratio = b% pg% Grid6_win_aspect_ratio
669 0 : p% file_flag = b% pg% Grid6_file_flag
670 0 : p% file_dir = b% pg% Grid6_file_dir
671 0 : p% file_prefix = b% pg% Grid6_file_prefix
672 0 : p% file_interval = b% pg% Grid6_file_interval
673 0 : p% file_width = b% pg% Grid6_file_width
674 0 : p% file_aspect_ratio = b% pg% Grid6_file_aspect_ratio
675 :
676 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid7)
677 0 : p% plot => grid7_plot
678 0 : p% id = i_Binary_Grid7
679 0 : p% name = 'Grid7'
680 0 : p% win_flag = b% pg% Grid7_win_flag
681 0 : p% win_width = b% pg% Grid7_win_width
682 0 : p% win_aspect_ratio = b% pg% Grid7_win_aspect_ratio
683 0 : p% file_flag = b% pg% Grid7_file_flag
684 0 : p% file_dir = b% pg% Grid7_file_dir
685 0 : p% file_prefix = b% pg% Grid7_file_prefix
686 0 : p% file_interval = b% pg% Grid7_file_interval
687 0 : p% file_width = b% pg% Grid7_file_width
688 0 : p% file_aspect_ratio = b% pg% Grid7_file_aspect_ratio
689 :
690 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid8)
691 0 : p% plot => grid8_plot
692 0 : p% id = i_Binary_Grid8
693 0 : p% name = 'Grid8'
694 0 : p% win_flag = b% pg% Grid8_win_flag
695 0 : p% win_width = b% pg% Grid8_win_width
696 0 : p% win_aspect_ratio = b% pg% Grid8_win_aspect_ratio
697 0 : p% file_flag = b% pg% Grid8_file_flag
698 0 : p% file_dir = b% pg% Grid8_file_dir
699 0 : p% file_prefix = b% pg% Grid8_file_prefix
700 0 : p% file_interval = b% pg% Grid8_file_interval
701 0 : p% file_width = b% pg% Grid8_file_width
702 0 : p% file_aspect_ratio = b% pg% Grid8_file_aspect_ratio
703 :
704 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Grid9)
705 0 : p% plot => grid9_plot
706 0 : p% id = i_Binary_Grid9
707 0 : p% name = 'Grid9'
708 0 : p% win_flag = b% pg% Grid9_win_flag
709 0 : p% win_width = b% pg% Grid9_win_width
710 0 : p% win_aspect_ratio = b% pg% Grid9_win_aspect_ratio
711 0 : p% file_flag = b% pg% Grid9_file_flag
712 0 : p% file_dir = b% pg% Grid9_file_dir
713 0 : p% file_prefix = b% pg% Grid9_file_prefix
714 0 : p% file_interval = b% pg% Grid9_file_interval
715 0 : p% file_width = b% pg% Grid9_file_width
716 0 : p% file_aspect_ratio = b% pg% Grid9_file_aspect_ratio
717 :
718 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Star1)
719 0 : p% plot => Star1_plot
720 0 : p% id = i_Binary_Star1
721 0 : p% name = 'Star1'
722 0 : p% win_flag = b% pg% Star1_win_flag
723 0 : p% win_width = b% pg% Star1_win_width
724 0 : p% win_aspect_ratio = b% pg% Star1_win_aspect_ratio
725 0 : p% file_flag = b% pg% Star1_file_flag
726 0 : p% file_dir = b% pg% Star1_file_dir
727 0 : p% file_prefix = b% pg% Star1_file_prefix
728 0 : p% file_interval = b% pg% Star1_file_interval
729 0 : p% file_width = b% pg% Star1_file_width
730 0 : p% file_aspect_ratio = b% pg% Star1_file_aspect_ratio
731 :
732 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Star2)
733 0 : p% plot => Star2_plot
734 0 : p% id = i_Binary_Star2
735 0 : p% name = 'Star2'
736 0 : p% win_flag = b% pg% Star2_win_flag
737 0 : p% win_width = b% pg% Star2_win_width
738 0 : p% win_aspect_ratio = b% pg% Star2_win_aspect_ratio
739 0 : p% file_flag = b% pg% Star2_file_flag
740 0 : p% file_dir = b% pg% Star2_file_dir
741 0 : p% file_prefix = b% pg% Star2_file_prefix
742 0 : p% file_interval = b% pg% Star2_file_interval
743 0 : p% file_width = b% pg% Star2_file_width
744 0 : p% file_aspect_ratio = b% pg% Star2_file_aspect_ratio
745 :
746 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Orbit)
747 0 : p% plot => Orbit_plot
748 0 : p% id = i_Binary_Orbit
749 0 : p% name = 'Orbit'
750 0 : p% win_flag = b% pg% Orbit_win_flag
751 0 : p% win_width = b% pg% Orbit_win_width
752 0 : p% win_aspect_ratio = b% pg% Orbit_win_aspect_ratio
753 0 : p% file_flag = b% pg% Orbit_file_flag
754 0 : p% file_dir = b% pg% Orbit_file_dir
755 0 : p% file_prefix = b% pg% Orbit_file_prefix
756 0 : p% file_interval = b% pg% Orbit_file_interval
757 0 : p% file_width = b% pg% Orbit_file_width
758 0 : p% file_aspect_ratio = b% pg% Orbit_file_aspect_ratio
759 :
760 0 : do i = 1, max_num_Binary_Other_plots
761 0 : p => b% pg% pgbinary_win_file_ptr(i_Binary_Other + i - 1)
762 0 : p% win_flag = .false.
763 0 : p% file_flag = .false.
764 0 : p% okay_to_call_do_plot_in_binary_grid = .false.
765 : end do
766 :
767 0 : if (b% use_other_pgbinary_plots) &
768 0 : call b% other_pgbinary_plots_info(b% binary_id, ierr)
769 :
770 0 : end subroutine set_win_file_data
771 :
772 :
773 0 : subroutine do_pgbinary_plots(b, must_write_files, ierr)
774 : type (binary_info), pointer :: b
775 : logical, intent(in) :: must_write_files
776 : integer, intent(out) :: ierr
777 :
778 : integer(i8) :: time0, time1, clock_rate
779 : logical ::do_pause
780 :
781 : include 'formats'
782 :
783 0 : ierr = 0
784 :
785 0 : if (b% pg% clear_history) call pgbinary_clear(b)
786 :
787 0 : call update_pgbinary_data(b, ierr)
788 0 : if (failed('update_pgbinary_data')) return
789 0 : call onScreen_Plots(b, must_write_files, ierr)
790 0 : if (failed('onScreen_Plots')) return
791 0 : call update_pgbinary_history_file(b, ierr)
792 0 : if (failed('save_text_data')) return
793 0 : do_pause = b% pg% pause_flag
794 0 : if ((.not. do_pause) .and. b% pg% pause_interval > 0) &
795 0 : do_pause = (mod(b% model_number, b% pg% pause_interval) == 0)
796 0 : if (do_pause) then
797 0 : write(*, *)
798 0 : write(*, *) 'model_number', b% model_number
799 0 : write(*, *) 'pgbinary: paused -- hit RETURN to continue'
800 0 : read(*, *)
801 : end if
802 :
803 0 : if (b% pg% pgbinary_sleep > 0) then
804 0 : time0 = b% system_clock_at_start_of_step
805 0 : do
806 0 : call system_clock(time1, clock_rate)
807 0 : if (dble(time1 - time0) / dble(clock_rate) >= b% pg% pgbinary_sleep) exit
808 : end do
809 : end if
810 :
811 : !write(*,2) 'pgbinary: done', b% model_number
812 :
813 : contains
814 :
815 0 : logical function failed(str)
816 : character (len = *), intent(in) :: str
817 0 : failed = (ierr /= 0)
818 0 : if (failed) then
819 0 : write(*, *) trim(str) // ' ierr', ierr
820 : end if
821 0 : end function failed
822 :
823 : end subroutine do_pgbinary_plots
824 :
825 :
826 : ! pgbinary driver, called after each timestep
827 0 : subroutine onScreen_Plots(b, must_write_files_in, ierr)
828 : use utils_lib
829 :
830 : type (binary_info), pointer :: b
831 : logical :: must_write_files_in
832 : integer, intent(out) :: ierr
833 :
834 : integer :: i
835 : type (pgbinary_win_file_data), pointer :: p
836 : logical, parameter :: dbg = .false.
837 : logical :: must_write_files, show_plot_now, save_plot_now
838 :
839 : include 'formats'
840 0 : ierr = 0
841 :
842 : ! initialize pgbinary
843 0 : if (.not. have_initialized_pgbinary) then
844 0 : call init_pgbinary(ierr)
845 0 : if (failed('init_pgbinary')) return
846 : end if
847 :
848 : ! request files if sufficient movement in HR diagram
849 0 : must_write_files = must_write_files_in
850 :
851 0 : show_plot_now = .false.
852 0 : if (b% pg% pgbinary_interval > 0) then
853 0 : if(mod(b% model_number, b% pg% pgbinary_interval) == 0) then
854 0 : show_plot_now = .true.
855 : end if
856 : end if
857 :
858 : ! loop through all plots
859 0 : do i = 1, num_pgbinary_plots
860 0 : p => b% pg% pgbinary_win_file_ptr(i)
861 0 : if(show_plot_now) then
862 : ! call to check_window opens device
863 0 : call check_window(b, p, ierr)
864 0 : if (failed('check_window')) return
865 :
866 : ! make the plot (window)
867 0 : if (p% do_win) then
868 0 : call p% plot(b% binary_id, p% id_win, ierr)
869 0 : if (failed(p% name)) return
870 : end if
871 : end if
872 :
873 0 : save_plot_now = must_write_files
874 0 : if (p% file_interval > 0) then
875 0 : if(mod(b% model_number, p% file_interval) == 0) then
876 : save_plot_now = .true.
877 : end if
878 : end if
879 :
880 0 : if (save_plot_now) then
881 : ! call to check_file opens device and does mkdir
882 0 : call check_file(b, p, ierr)
883 :
884 : ! make the plot (file)
885 0 : if (p% do_file) then
886 0 : call p% plot(b% binary_id, p% id_file, ierr)
887 0 : if (failed(p% name)) return
888 0 : call pgclos
889 0 : if (b% pg% pgbinary_report_writing_files) &
890 0 : write(*, *) trim(p% most_recent_filename)
891 0 : p% id_file = 0
892 0 : p% do_file = .false.
893 : end if
894 : end if
895 : end do
896 :
897 : contains
898 :
899 0 : logical function failed(str)
900 : character (len = *), intent(in) :: str
901 0 : failed = (ierr /= 0)
902 0 : if (failed) then
903 0 : write(*, *) trim(str) // ' ierr', ierr
904 : end if
905 0 : end function failed
906 :
907 : end subroutine onScreen_Plots
908 :
909 :
910 0 : subroutine update_pgbinary_history_file(b, ierr)
911 : use utils_lib
912 : type (binary_info), pointer :: b
913 : integer, intent(out) :: ierr
914 :
915 : integer :: iounit, n
916 : character (len = 1024) :: fname
917 : type (pgbinary_hist_node), pointer :: pg
918 :
919 : logical, parameter :: dbg = .false.
920 :
921 : include 'formats'
922 :
923 0 : ierr = 0
924 0 : pg => b% pg% pgbinary_hist
925 0 : if (.not. associated(pg)) return
926 :
927 0 : n = b% number_of_binary_history_columns
928 0 : fname = trim(b% photo_directory) // '/pgbinary.dat'
929 :
930 0 : if (associated(pg% next)) then
931 : open(newunit = iounit, file = trim(fname), action = 'write', &
932 0 : position = 'append', form = 'unformatted', iostat = ierr)
933 : else
934 : open(newunit = iounit, file = trim(fname), action = 'write', &
935 0 : status = 'replace', form = 'unformatted', iostat = ierr)
936 0 : if (ierr == 0) write(iounit) n
937 : end if
938 0 : if (ierr /= 0) then
939 0 : write(*, *) 'save_pgbinary_data: cannot open new file'
940 0 : return
941 : end if
942 :
943 0 : if (associated(pg% vals)) then
944 0 : if (size(pg% vals, dim = 1) >= n) then
945 0 : write(iounit) pg% age, pg% step, pg% vals(1:n)
946 : end if
947 : end if
948 :
949 0 : close(iounit)
950 :
951 : end subroutine update_pgbinary_history_file
952 :
953 :
954 0 : subroutine read_pgbinary_data(b, ierr)
955 : use utils_lib
956 : type (binary_info), pointer :: b
957 : integer, intent(out) :: ierr
958 :
959 : logical :: fexist
960 : integer :: iounit, n
961 : character (len = 1024) :: fname
962 : type (pgbinary_hist_node), pointer :: pg
963 :
964 : logical, parameter :: dbg = .false.
965 :
966 : include 'formats'
967 0 : ierr = 0
968 :
969 0 : fname = trim(b% photo_directory) // '/pgbinary.dat'
970 0 : inquire(file = trim(fname), exist = fexist)
971 0 : if (.not.fexist) then
972 : if (dbg) write(*, *) 'failed to find ' // trim(fname)
973 0 : return
974 : end if
975 :
976 : open(newunit = iounit, file = trim(fname), action = 'read', &
977 0 : status = 'old', iostat = ierr, form = 'unformatted')
978 0 : if (ierr /= 0) then
979 : if (dbg) write(*, *) 'failed to open ' // trim(fname)
980 : return
981 : end if
982 :
983 0 : read(iounit, iostat = ierr) n
984 0 : if (ierr == 0) then
985 0 : if (b% number_of_binary_history_columns < 0) then
986 0 : b% number_of_binary_history_columns = n
987 0 : else if (b% number_of_binary_history_columns /= n) then
988 0 : ierr = -1
989 : end if
990 : end if
991 :
992 0 : if (ierr /= 0) then
993 0 : write(*, *) 'failed read pgbinary history ' // trim(fname)
994 : else
995 0 : do ! keep reading until reach end of file so take care of restarts
996 0 : allocate(pg)
997 0 : allocate(pg% vals(n))
998 0 : read(iounit, iostat = ierr) pg% age, pg% step, pg% vals(1:n)
999 0 : if (ierr /= 0) then
1000 0 : ierr = 0
1001 0 : deallocate(pg% vals)
1002 0 : deallocate(pg)
1003 0 : exit
1004 : end if
1005 0 : call add_to_pgbinary_hist(b, pg)
1006 : end do
1007 : end if
1008 :
1009 0 : close(iounit)
1010 :
1011 : end subroutine read_pgbinary_data
1012 :
1013 :
1014 0 : subroutine update_pgbinary_data(b, ierr)
1015 :
1016 : type (binary_info), pointer :: b
1017 : integer, intent(out) :: ierr
1018 :
1019 : integer :: num
1020 : type (pgbinary_hist_node), pointer :: pg
1021 :
1022 : include 'formats'
1023 :
1024 0 : ierr = 0
1025 :
1026 0 : allocate(pg)
1027 0 : pg% step = b% model_number
1028 0 : pg% age = b% binary_age
1029 0 : num = b% number_of_binary_history_columns
1030 0 : allocate(pg% vals(num))
1031 0 : call get_hist_values(num, ierr)
1032 0 : if (ierr /= 0) then
1033 0 : write(*, *) 'failed in get_hist_values'
1034 0 : return
1035 : stop 'pgbinary'
1036 : end if
1037 0 : call add_to_pgbinary_hist(b, pg)
1038 :
1039 : contains
1040 :
1041 :
1042 0 : subroutine get_hist_values(num, ierr)
1043 : use binary_history, only : do_get_data_for_binary_history_columns
1044 : integer, intent(in) :: num
1045 : integer, intent(out) :: ierr
1046 : integer :: i
1047 0 : ierr = 0
1048 0 : if (b% need_to_set_binary_history_names_etc .or. &
1049 : b% model_number_of_binary_history_values /= b% model_number) then
1050 0 : call do_get_data_for_binary_history_columns(b, ierr)
1051 0 : if (ierr /= 0) return
1052 : end if
1053 0 : do i = 1, num
1054 0 : pg% vals(i) = b% binary_history_values(i)
1055 : end do
1056 0 : end subroutine get_hist_values
1057 :
1058 :
1059 : end subroutine update_pgbinary_data
1060 :
1061 0 : subroutine shutdown_pgbinary(b)
1062 : use pgbinary_support
1063 : type (binary_info), pointer :: b
1064 :
1065 0 : call pgbinary_clear(b)
1066 :
1067 0 : have_initialized_pgbinary = .false.
1068 :
1069 0 : end subroutine shutdown_pgbinary
1070 :
1071 : end module pgbinary
|