-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathpgstar_support.f90
2097 lines (1831 loc) · 73 KB
/
pgstar_support.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! ***********************************************************************
!
! Copyright (C) 2010-2019 The MESA Team
!
! MESA is free software; you can use it and/or modify
! it under the combined terms and restrictions of the MESA MANIFESTO
! and the GNU General Library Public License as published
! by the Free Software Foundation; either version 2 of the License,
! or (at your option) any later version.
!
! You should have received a copy of the MESA MANIFESTO along with
! this software; if not, it is available at the mesa website:
! http://mesa.sourceforge.net/
!
! MESA is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
! See the GNU Library General Public License for more details.
!
! You should have received a copy of the GNU Library General Public License
! along with this software; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
!
! ***********************************************************************
module pgstar_support
use star_private_def
use const_def
use rates_def, only : i_rate
use utils_lib
use star_pgstar
implicit none
integer, parameter :: category_offset = 1000
integer, parameter :: abundance_offset = 2000
integer, parameter :: extras_offset = 3000
logical :: have_initialized_pgstar = .false.
real :: sum_dHR_since_last_file_write
! lines for TRho profile
real, dimension(:), allocatable :: hydrogen_burn_logT, hydrogen_burn_logRho
real, dimension(:), allocatable :: helium_burn_logT, helium_burn_logRho
real, dimension(:), allocatable :: carbon_burn_logT, carbon_burn_logRho
real, dimension(:), allocatable :: oxygen_burn_logT, oxygen_burn_logRho
real, dimension(:), allocatable :: psi4_logT, psi4_logRho
real, dimension(:), allocatable :: elect_data_logT, elect_data_logRho
real, dimension(:), allocatable :: gamma_4_thirds_logT, gamma_4_thirds_logRho
real, dimension(:), allocatable :: kap_rad_cond_eq_logT, kap_rad_cond_eq_logRho
real, dimension(:), allocatable :: opal_clip_logT, opal_clip_logRho
real, dimension(:), allocatable :: scvh_clip_logT, scvh_clip_logRho
integer :: clr_no_mixing, clr_convection, clr_leftover_convection, clr_semiconvection, &
clr_thermohaline, clr_overshoot, clr_rotation, clr_minimum, clr_rayleigh_taylor, &
clr_anonymous, colormap_offset, colormap_last, colormap_size
real :: colormap(3, 101)
! Tioga line types
integer, parameter :: Line_Type_Solid = 1
integer, parameter :: Line_Type_Dash = 2
integer, parameter :: Line_Type_Dot_Dash = 3
integer, parameter :: Line_Type_Dash_Dot = Line_Type_Dot_Dash
integer, parameter :: Line_Type_Dot = 4
contains
subroutine add_to_pgstar_hist(s, pg_hist_new)
type (star_info), pointer :: s
type (pgstar_hist_node), pointer :: pg_hist_new
type (pgstar_hist_node), pointer :: pg_hist => null(), next => null()
integer :: step
step = pg_hist_new% step
do
if (.not. associated(s% pg% pgstar_hist)) then
s% pg% pgstar_hist => pg_hist_new
nullify(pg_hist_new% next)
return
end if
if (step > s% pg% pgstar_hist% step) then
pg_hist_new% next => s% pg% pgstar_hist
s% pg% pgstar_hist => pg_hist_new
return
end if
! discard item
next => s% pg% pgstar_hist% next
deallocate(s% pg% pgstar_hist% vals)
deallocate(s% pg% pgstar_hist)
s% pg% pgstar_hist => next
end do
end subroutine add_to_pgstar_hist
subroutine pgstar_clear(s)
type (star_info), pointer :: s
integer :: i, id, num
type (pgstar_win_file_data), pointer :: p
type (pgstar_hist_node), pointer :: pg_hist => null(), next => null()
pg_hist => s% pg% pgstar_hist
do while(associated(pg_hist))
if (associated(pg_hist% vals)) deallocate(pg_hist% vals)
next => pg_hist% next
deallocate(pg_hist)
pg_hist => next
end do
nullify(s% pg% pgstar_hist)
if (have_initialized_pgstar) return
do i = 1, num_pgstar_plots
p => s% pg% pgstar_win_file_ptr(i)
p% id_win = 0
p% have_called_mkdir = .false.
p% file_dir_for_previous_mkdir = ''
end do
end subroutine pgstar_clear
subroutine init_pgstar(ierr)
integer, intent(out) :: ierr
if (have_initialized_pgstar) return
call read_support_info(ierr)
if (failed('read_support_info')) return
have_initialized_pgstar = .true.
sum_dHR_since_last_file_write = 0
contains
logical function failed(str)
character (len = *), intent(in) :: str
failed = (ierr /= 0)
if (failed) then
write(*, *) trim(str) // ' ierr', ierr
end if
end function failed
end subroutine init_pgstar
subroutine check_window(s, p, ierr)
type (star_info), pointer :: s
type (pgstar_win_file_data), pointer :: p
integer, intent(out) :: ierr
ierr = 0
if (p% do_win .and. (.not. p% win_flag)) then
p% do_win = .false.
if (p% id_win > 0) then
call pgslct(p% id_win)
call pgclos
p% id_win = 0
endif
else if (p% win_flag .and. (.not. p% do_win)) then
if (p% id_win == 0) &
call open_device(s, p, .false., '/xwin', p% id_win, ierr)
if (ierr == 0 .and. p% id_win > 0) p% do_win = .true.
end if
if (p% do_win .and. p% id_win > 0 .and. &
(p% win_width /= p% prev_win_width .or. &
p% win_aspect_ratio /= p% prev_win_aspect_ratio)) then
call pgslct(p% id_win)
call pgpap(p% win_width, p% win_aspect_ratio)
p% prev_win_width = p% win_width
p% prev_win_aspect_ratio = p% win_aspect_ratio
end if
end subroutine check_window
subroutine check_file(s, p, ierr)
use utils_lib, only : mkdir
type (star_info), pointer :: s
type (pgstar_win_file_data), pointer :: p
integer, intent(out) :: ierr
character (len = strlen) :: name
ierr = 0
if (p% do_file .and. (.not. p% file_flag)) then
p% do_file = .false.
else if (p% file_flag .and. (.not. p% do_file)) then
if (p% id_file == 0) then
if (.not. p% have_called_mkdir .or. &
p% file_dir /= p% file_dir_for_previous_mkdir) then
if(.not. folder_exists(trim(p% file_dir))) call mkdir(trim(p% file_dir))
p% have_called_mkdir = .true.
p% file_dir_for_previous_mkdir = p% file_dir
end if
call create_file_name(s, p% file_dir, p% file_prefix, name)
name = trim(name) // '/' // trim(s% pg% file_device)
call open_device(s, p, .true., name, p% id_file, ierr)
if (ierr /= 0) return
p% most_recent_filename = name
end if
p% do_file = .true.
end if
end subroutine check_file
subroutine create_file_name(s, dir, prefix, name)
use star_utils, only : get_string_for_model_number
type (star_info), pointer :: s
character (len = *), intent(in) :: dir, prefix
character (len = *), intent(out) :: name
character (len = strlen) :: num_str, fstring
write(fstring, '( "(i",i2.2,".",i2.2,")" )') s% pg% file_digits, s% pg% file_digits
write(num_str, fstring) s% model_number
if (len_trim(dir) > 0) then
name = trim(dir) // '/' // trim(prefix)
else
name = prefix
end if
name = trim(name) // trim(num_str) // '.' // trim(s% pg% file_extension)
end subroutine create_file_name
subroutine write_plot_to_file(s, p, filename, ierr)
type (star_info), pointer :: s
type (pgstar_win_file_data), pointer :: p
character (len = *), intent(in) :: filename
integer, intent(out) :: ierr
character (len = strlen) :: name
ierr = 0
!name = trim(filename) // '/' // trim(s% pg% file_device)
name = trim(filename) // '/png'
write(*, '(a)') 'write_plot_to_file device: ' // trim(name)
call open_device(s, p, .true., trim(name), p% id_file, ierr)
if (ierr /= 0) then
write(*, *) 'failed in open_device'
return
end if
call p% plot(s% id, p% id_file, ierr)
call pgclos
p% id_file = 0
p% do_file = .false.
end subroutine write_plot_to_file
subroutine open_device(s, p, is_file, dev, id, ierr)
type (star_info), pointer :: s
type (pgstar_win_file_data), pointer :: p
logical, intent(in) :: is_file
character (len = *), intent(in) :: dev
integer, intent(out) :: id
integer, intent(out) :: ierr
integer :: pgopen, system
character (len = strlen) :: dir, cmd
logical :: white_on_black_flag
real :: width, ratio
if (is_file) then
dir = p% file_dir
white_on_black_flag = s% pg% file_white_on_black_flag
else
dir = ''
white_on_black_flag = s% pg% win_white_on_black_flag
end if
ierr = 0
id = -1
id = pgopen(trim(dev))
if (id <= 0) return
!write(*,*) 'open device <' // trim(dev) // '> ' // trim(p% name), id
if (is_file) then
width = p% file_width; if (width < 0) width = p% win_width
ratio = p% file_aspect_ratio; if (ratio < 0) ratio = p% win_aspect_ratio
call pgpap(width, ratio)
else
call pgpap(p% win_width, p% win_aspect_ratio)
p% prev_win_width = p% win_width
p% prev_win_aspect_ratio = p% win_aspect_ratio
end if
call Set_Colours(white_on_black_flag, ierr)
end subroutine open_device
subroutine read_support_info(ierr)
integer, intent(out) :: ierr
ierr = 0
call read_TRho_data(&
'hydrogen_burn.data', hydrogen_burn_logT, hydrogen_burn_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading hydrogen burn data'
return
end if
call read_TRho_data(&
'helium_burn.data', helium_burn_logT, helium_burn_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading helium burn data'
return
end if
call read_TRho_data(&
'carbon_burn.data', carbon_burn_logT, carbon_burn_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading carbon burn data'
return
end if
call read_TRho_data(&
'oxygen_burn.data', oxygen_burn_logT, oxygen_burn_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading oxygen burn data'
return
end if
call read_TRho_data(&
'psi4.data', psi4_logT, psi4_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading psi4 data'
return
end if
call read_TRho_data(&
'elect.data', elect_data_logT, elect_data_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading elect data'
return
end if
call read_TRho_data(&
'gamma_4_thirds.data', gamma_4_thirds_logT, gamma_4_thirds_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading gamma_4_thirds data'
return
end if
call read_TRho_data(&
'kap_rad_cond_eq.data', kap_rad_cond_eq_logT, kap_rad_cond_eq_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading kap_rad_cond_eq data'
return
end if
call read_TRho_data(&
'opal_clip.data', opal_clip_logT, opal_clip_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading opal_clip data'
return
end if
call read_TRho_data(&
'scvh_clip.data', scvh_clip_logT, scvh_clip_logRho, ierr)
if (ierr /= 0) then
write(*, *) 'PGSTAR failed in reading scvh_clip data'
return
end if
end subroutine read_support_info
! remaining routines for setting colours in PGPLOT
! by X11 name
subroutine Set_Colours(white_on_black_flag, ierr)
implicit none
logical, intent(in) :: white_on_black_flag
integer, intent(out) :: ierr
integer :: index, i, k
include 'formats'
index = 0
ierr = 0
if (white_on_black_flag) then
index = setcolour(index, "black", ierr)
if (ierr /= 0) return
index = setcolour(index, "white", ierr)
if (ierr /= 0) return
else
index = setcolour(index, "white", ierr)
if (ierr /= 0) return
index = setcolour(index, "black", ierr)
if (ierr /= 0) return
end if
index = setcolour(index, "red", ierr)
if (ierr /= 0) return
index = setcolour(index, "green", ierr)
if (ierr /= 0) return
index = setcolour(index, "blue", ierr)
if (ierr /= 0) return
index = setcolour(index, "cyan", ierr)
if (ierr /= 0) return
index = setcolour(index, "magenta", ierr)
if (ierr /= 0) return
index = setcolour(index, "yellow", ierr)
if (ierr /= 0) return
index = setcolour(index, "orange", ierr)
if (ierr /= 0) return
index = setcolour(index, "lime green", ierr)
if (ierr /= 0) return
index = setcolour(index, "green yellow", ierr)
if (ierr /= 0) return
index = setcolour(index, "dodger blue", ierr)
if (ierr /= 0) return
index = setcolour(index, "magenta4", ierr)
if (ierr /= 0) return
index = setcolour(index, "plum", ierr)
if (ierr /= 0) return
index = setcolour(index, "sandy brown", ierr)
if (ierr /= 0) return
index = setcolour(index, "salmon", ierr)
if (ierr /= 0) return
index = setcolour(index, "grey59", ierr)
if (ierr /= 0) return
index = setcolour(index, "grey30", ierr)
if (ierr /= 0) return
! Tioga colors
index = set_c(index, clr_Black, 0.0, 0.0, 0.0)
index = set_c(index, clr_Blue, 0.0, 0.0, 1.0)
index = set_c(index, clr_BrightBlue, 0.0, 0.4, 1.0)
index = set_c(index, clr_LightSkyBlue, 0.53, 0.808, 0.98)
index = set_c(index, clr_LightSkyGreen, 0.125, 0.698, 0.668)
index = set_c(index, clr_MediumSpringGreen, 0.0, 0.98, 0.604)
index = set_c(index, clr_Goldenrod, 0.855, 0.648, 0.125)
index = set_c(index, clr_Lilac, 0.8, 0.6, 1.0)
index = set_c(index, clr_Coral, 1.0, 0.498, 0.312)
index = set_c(index, clr_FireBrick, 0.698, 0.132, 0.132)
index = set_c(index, clr_RoyalPurple, 0.4, 0.0, 0.6)
index = set_c(index, clr_Gold, 1.0, 0.844, 0.0)
index = set_c(index, clr_Crimson, 0.8, 0.0, 0.2)
index = set_c(index, clr_SlateGray, 0.44, 0.5, 0.565)
index = set_c(index, clr_SeaGreen, 0.18, 0.545, 0.34)
index = set_c(index, clr_Teal, 0.0, 0.5, 0.5)
index = set_c(index, clr_LightSteelBlue, 0.69, 0.77, 0.87)
index = set_c(index, clr_MediumSlateBlue, 0.484, 0.408, 0.932)
index = set_c(index, clr_MediumBlue, 0.0, 0.0, 0.804)
index = set_c(index, clr_RoyalBlue, 0.255, 0.41, 0.884)
index = set_c(index, clr_LightGray, 0.828, 0.828, 0.828)
index = set_c(index, clr_Silver, 0.752, 0.752, 0.752)
index = set_c(index, clr_DarkGray, 0.664, 0.664, 0.664)
index = set_c(index, clr_Gray, 0.5, 0.5, 0.5)
index = set_c(index, clr_IndianRed, 0.804, 0.36, 0.36)
index = set_c(index, clr_Tan, 0.824, 0.705, 0.55)
index = set_c(index, clr_LightOliveGreen, 0.6, 0.8, 0.6)
index = set_c(index, clr_CadetBlue, 0.372, 0.62, 0.628)
index = set_c(index, clr_Beige, 0.96, 0.96, 0.864)
clr_no_mixing = clr_SeaGreen
clr_convection = clr_LightSkyBlue
clr_leftover_convection = clr_BrightBlue
clr_semiconvection = clr_SlateGray
clr_thermohaline = clr_Lilac
clr_overshoot = clr_Beige
clr_rotation = clr_LightSkyGreen
clr_rayleigh_taylor = clr_IndianRed
clr_minimum = clr_Coral
clr_anonymous = clr_Tan
colormap(1:3, 1) = (/ 0.0, 0.0, 1.0 /)
colormap(1:3, 2) = (/ 0.0196078431372549, 0.0196078431372549, 1.0 /)
colormap(1:3, 3) = (/ 0.0352941176470588, 0.0352941176470588, 1.0 /)
colormap(1:3, 4) = (/ 0.0588235294117647, 0.0588235294117647, 1.0 /)
colormap(1:3, 5) = (/ 0.0705882352941176, 0.0705882352941176, 1.0 /)
colormap(1:3, 6) = (/ 0.0941176470588235, 0.0941176470588235, 1.0 /)
colormap(1:3, 7) = (/ 0.105882352941176, 0.105882352941176, 1.0 /)
colormap(1:3, 8) = (/ 0.129411764705882, 0.129411764705882, 1.0 /)
colormap(1:3, 9) = (/ 0.141176470588235, 0.141176470588235, 1.0 /)
colormap(1:3, 10) = (/ 0.164705882352941, 0.164705882352941, 1.0 /)
colormap(1:3, 11) = (/ 0.184313725490196, 0.184313725490196, 1.0 /)
colormap(1:3, 12) = (/ 0.2, 0.2, 1.0 /)
colormap(1:3, 13) = (/ 0.219607843137255, 0.219607843137255, 1.0 /)
colormap(1:3, 14) = (/ 0.235294117647059, 0.235294117647059, 1.0 /)
colormap(1:3, 15) = (/ 0.254901960784314, 0.254901960784314, 1.0 /)
colormap(1:3, 16) = (/ 0.270588235294118, 0.270588235294118, 1.0 /)
colormap(1:3, 17) = (/ 0.294117647058824, 0.294117647058824, 1.0 /)
colormap(1:3, 18) = (/ 0.305882352941176, 0.305882352941176, 1.0 /)
colormap(1:3, 19) = (/ 0.329411764705882, 0.329411764705882, 1.0 /)
colormap(1:3, 20) = (/ 0.341176470588235, 0.341176470588235, 1.0 /)
colormap(1:3, 21) = (/ 0.364705882352941, 0.364705882352941, 1.0 /)
colormap(1:3, 22) = (/ 0.384313725490196, 0.384313725490196, 1.0 /)
colormap(1:3, 23) = (/ 0.4, 0.4, 1.0 /)
colormap(1:3, 24) = (/ 0.419607843137255, 0.419607843137255, 1.0 /)
colormap(1:3, 25) = (/ 0.435294117647059, 0.435294117647059, 1.0 /)
colormap(1:3, 26) = (/ 0.454901960784314, 0.454901960784314, 1.0 /)
colormap(1:3, 27) = (/ 0.470588235294118, 0.470588235294118, 1.0 /)
colormap(1:3, 28) = (/ 0.490196078431373, 0.490196078431373, 1.0 /)
colormap(1:3, 29) = (/ 0.505882352941176, 0.505882352941176, 1.0 /)
colormap(1:3, 30) = (/ 0.529411764705882, 0.529411764705882, 1.0 /)
colormap(1:3, 31) = (/ 0.549019607843137, 0.549019607843137, 1.0 /)
colormap(1:3, 32) = (/ 0.564705882352941, 0.564705882352941, 1.0 /)
colormap(1:3, 33) = (/ 0.584313725490196, 0.584313725490196, 1.0 /)
colormap(1:3, 34) = (/ 0.6, 0.6, 1.0 /)
colormap(1:3, 35) = (/ 0.619607843137255, 0.619607843137255, 1.0 /)
colormap(1:3, 36) = (/ 0.635294117647059, 0.635294117647059, 1.0 /)
colormap(1:3, 37) = (/ 0.654901960784314, 0.654901960784314, 1.0 /)
colormap(1:3, 38) = (/ 0.670588235294118, 0.670588235294118, 1.0 /)
colormap(1:3, 39) = (/ 0.690196078431373, 0.690196078431373, 1.0 /)
colormap(1:3, 40) = (/ 0.705882352941177, 0.705882352941177, 1.0 /)
colormap(1:3, 41) = (/ 0.725490196078431, 0.725490196078431, 1.0 /)
colormap(1:3, 42) = (/ 0.749019607843137, 0.749019607843137, 1.0 /)
colormap(1:3, 43) = (/ 0.764705882352941, 0.764705882352941, 1.0 /)
colormap(1:3, 44) = (/ 0.784313725490196, 0.784313725490196, 1.0 /)
colormap(1:3, 45) = (/ 0.8, 0.8, 1.0 /)
colormap(1:3, 46) = (/ 0.831372549019608, 0.831372549019608, 1.0 /)
colormap(1:3, 47) = (/ 0.854901960784314, 0.854901960784314, 1.0 /)
colormap(1:3, 48) = (/ 0.890196078431372, 0.890196078431372, 1.0 /)
colormap(1:3, 49) = (/ 0.913725490196078, 0.913725490196078, 1.0 /)
colormap(1:3, 50) = (/ 0.949019607843137, 0.949019607843137, 1.0 /)
colormap(1:3, 51) = (/ 1.0, 0.972549019607843, 0.972549019607843 /)
colormap(1:3, 52) = (/ 1.0, 0.949019607843137, 0.949019607843137 /)
colormap(1:3, 53) = (/ 1.0, 0.913725490196078, 0.913725490196078 /)
colormap(1:3, 54) = (/ 1.0, 0.890196078431372, 0.890196078431372 /)
colormap(1:3, 55) = (/ 1.0, 0.854901960784314, 0.854901960784314 /)
colormap(1:3, 56) = (/ 1.0, 0.831372549019608, 0.831372549019608 /)
colormap(1:3, 57) = (/ 1.0, 0.8, 0.8 /)
colormap(1:3, 58) = (/ 1.0, 0.784313725490196, 0.784313725490196 /)
colormap(1:3, 59) = (/ 1.0, 0.764705882352941, 0.764705882352941 /)
colormap(1:3, 60) = (/ 1.0, 0.749019607843137, 0.749019607843137 /)
colormap(1:3, 61) = (/ 1.0, 0.725490196078431, 0.725490196078431 /)
colormap(1:3, 62) = (/ 1.0, 0.705882352941177, 0.705882352941177 /)
colormap(1:3, 63) = (/ 1.0, 0.690196078431373, 0.690196078431373 /)
colormap(1:3, 64) = (/ 1.0, 0.670588235294118, 0.670588235294118 /)
colormap(1:3, 65) = (/ 1.0, 0.654901960784314, 0.654901960784314 /)
colormap(1:3, 66) = (/ 1.0, 0.635294117647059, 0.635294117647059 /)
colormap(1:3, 67) = (/ 1.0, 0.619607843137255, 0.619607843137255 /)
colormap(1:3, 68) = (/ 1.0, 0.6, 0.6 /)
colormap(1:3, 69) = (/ 1.0, 0.584313725490196, 0.584313725490196 /)
colormap(1:3, 70) = (/ 1.0, 0.564705882352941, 0.564705882352941 /)
colormap(1:3, 71) = (/ 1.0, 0.541176470588235, 0.541176470588235 /)
colormap(1:3, 72) = (/ 1.0, 0.529411764705882, 0.529411764705882 /)
colormap(1:3, 73) = (/ 1.0, 0.505882352941176, 0.505882352941176 /)
colormap(1:3, 74) = (/ 1.0, 0.490196078431373, 0.490196078431373 /)
colormap(1:3, 75) = (/ 1.0, 0.470588235294118, 0.470588235294118 /)
colormap(1:3, 76) = (/ 1.0, 0.454901960784314, 0.454901960784314 /)
colormap(1:3, 77) = (/ 1.0, 0.435294117647059, 0.435294117647059 /)
colormap(1:3, 78) = (/ 1.0, 0.419607843137255, 0.419607843137255 /)
colormap(1:3, 79) = (/ 1.0, 0.4, 0.4 /)
colormap(1:3, 80) = (/ 1.0, 0.384313725490196, 0.384313725490196 /)
colormap(1:3, 81) = (/ 1.0, 0.364705882352941, 0.364705882352941 /)
colormap(1:3, 82) = (/ 1.0, 0.341176470588235, 0.341176470588235 /)
colormap(1:3, 83) = (/ 1.0, 0.329411764705882, 0.329411764705882 /)
colormap(1:3, 84) = (/ 1.0, 0.305882352941176, 0.305882352941176 /)
colormap(1:3, 85) = (/ 1.0, 0.294117647058824, 0.294117647058824 /)
colormap(1:3, 86) = (/ 1.0, 0.270588235294118, 0.270588235294118 /)
colormap(1:3, 87) = (/ 1.0, 0.254901960784314, 0.254901960784314 /)
colormap(1:3, 88) = (/ 1.0, 0.235294117647059, 0.235294117647059 /)
colormap(1:3, 89) = (/ 1.0, 0.219607843137255, 0.219607843137255 /)
colormap(1:3, 90) = (/ 1.0, 0.2, 0.2 /)
colormap(1:3, 91) = (/ 1.0, 0.176470588235294, 0.176470588235294 /)
colormap(1:3, 92) = (/ 1.0, 0.164705882352941, 0.164705882352941 /)
colormap(1:3, 93) = (/ 1.0, 0.141176470588235, 0.141176470588235 /)
colormap(1:3, 94) = (/ 1.0, 0.129411764705882, 0.129411764705882 /)
colormap(1:3, 95) = (/ 1.0, 0.105882352941176, 0.105882352941176 /)
colormap(1:3, 96) = (/ 1.0, 0.0941176470588235, 0.0941176470588235 /)
colormap(1:3, 97) = (/ 1.0, 0.0705882352941176, 0.0705882352941176 /)
colormap(1:3, 98) = (/ 1.0, 0.0588235294117647, 0.0588235294117647 /)
colormap(1:3, 99) = (/ 1.0, 0.0352941176470588, 0.0352941176470588 /)
colormap(1:3, 100) = (/ 1.0, 0.0196078431372549, 0.0196078431372549 /)
colormap(1:3, 101) = (/ 1.0, 0.0, 0.0 /)
colormap_offset = index - 1
!write(*,2) 'colormap_offset', colormap_offset
do i = 1, 101, 2
!write(*,3) 'colormap clr', i, &
! index, colormap(1,i), colormap(2,i), colormap(3,i)
index = set_c(index, k, colormap(1, i), colormap(2, i), colormap(3, i))
end do
colormap_last = index - 1
colormap_size = colormap_last - colormap_offset
contains
integer function set_c(index, clr_i, r, g, b)
integer :: index, clr_i
real :: r, g, b
call pgscr(index, r, g, b)
clr_i = index
set_c = index + 1
end function set_c
integer function setcolour(i, name, ierr)
integer :: i
character (len = *) :: name
integer, intent(out) :: ierr
call Set_Pgplot_Colour(i, name, ierr)
setcolour = i + 1
end function setcolour
end subroutine Set_Colours
subroutine Set_Pgplot_Colour(index, name, ierr)
use utils_lib
integer :: index
character (len = *) :: name
integer, intent(out) :: ierr
logical, save :: have_colour_list = .false.
real, allocatable, dimension(:), save :: red, green, blue
character (len = 64), allocatable, dimension(:), save :: colournames
integer, save :: nrgbcolours, low, hi
integer :: i
ierr = 0
if (.not.have_colour_list) then
call loadRGBtxt(ierr)
if (ierr /= 0) return
have_colour_list = .true.
call pgqcol(low, hi)
end if
if (.not. (low<=index .and. index<=hi)) then
write(*, '(a,i4,a,i3,a,i3)') "Set_Pgplot_Colour: requested index of ", index, &
" not in ", low, " to ", hi
return
endif
do i = 1, nrgbcolours
if (colournames(i) == name) exit
end do
if (i>nrgbcolours) then
write(*, *) "Set_Pgplot_Colour: colour ", trim(name), " not found"
ierr = -1
return
end if
call pgscr(index, red(i), green(i), blue(i))
contains
subroutine loadRGBtxt(ierr)
integer, intent(out) :: ierr
logical :: fexist
integer :: iounit, i, j, r, g, b, len
character (len = 1024) :: msg, fname, pgplotdir, line
ierr = 0
call GET_ENVIRONMENT_VARIABLE("PGPLOT_DIR", pgplotdir)
if (len_trim(pgplotdir)==0) then
write(*, *) "PGPLOT_DIR is not set in your shell"
ierr = -1
return
end if
fname = trim(pgplotdir) // "/rgb.txt"
inquire(file = trim(fname), exist = fexist)
if (.not.fexist) then
write(*, *) 'loadRGBtxt: pgplot ', trim(fname), " does not exist"
write(*, *) 'loadRGBtxt: pgplot rgb.txt file does not exist'
ierr = -1
return
end if
open(newunit = iounit, file = trim(fname), status = "old", iostat = ierr, iomsg = msg)
if (ierr/=0) then
write(*, *) trim(msg)
write(*, *) 'loadRGBtxt: cannot open the pgplot rgb.txt file'
ierr = -1
return
end if
! count colours
len = 0
do while(.true.)
read(iounit, *, iostat = ierr) i
if (ierr/=0) exit
len = len + 1
end do
nrgbcolours = len
close(iounit)
allocate(red(nrgbcolours), green(nrgbcolours), blue(nrgbcolours))
allocate(colournames(nrgbcolours))
open(newunit = iounit, file = trim(fname), status = "old", iostat = ierr, iomsg = msg)
do i = 1, nrgbcolours
read(iounit, '(a)') line
read(line, *) r, g, b
j = 1
do while(line(j:j)==char(32) .or. &
(line(j:j)>=char(48) .and. line(j:j)<=char(57)))
j = j + 1
end do
read(line(j:), '(a)') colournames(i)
red(i) = r / 255.0
green(i) = g / 255.0
blue(i) = b / 255.0
end do
close(iounit)
end subroutine loadRGBtxt
end subroutine Set_Pgplot_Colour
subroutine read_TRho_data(fname, logTs, logRhos, ierr)
use utils_lib
use const_def, only : mesa_data_dir
character (len = *), intent(in) :: fname
real, dimension(:), allocatable :: logTs, logRhos ! will allocate
integer, intent(out) :: ierr
character (len = strlen) :: filename
real :: logT, logRho
integer :: iounit, i, sz, cnt
filename = trim(mesa_data_dir) // '/star_data/plot_info/' // trim(fname)
open(newunit = iounit, file = trim(filename), status = 'old', action = 'read', iostat = ierr)
if (ierr/=0) then
write(*, *) 'failed to open ' // trim(filename)
call done
return
end if
sz = 0
do
read(iounit, *, iostat = ierr)
if(ierr/=0) exit
sz = sz + 1
end do
rewind(iounit)
allocate(logTs(sz), logRhos(sz))
cnt = 0
do i = 1, sz
read(iounit, *, iostat = ierr) logRho, logT
if (ierr /= 0) then
ierr = 0; exit
end if
logRhos(i) = logRho
logTs(i) = logT
cnt = i
end do
call done
contains
subroutine done
close(iounit)
end subroutine done
end subroutine read_TRho_data
integer function write_info_line_str(cnt, ypos, xpos0, dxpos, str)
integer, intent(in) :: cnt
real, intent(in) :: ypos, xpos0, dxpos
character (len = *), intent(in) :: str
real :: xpos
xpos = cnt * dxpos + xpos0
call pgptxt(xpos, ypos, 0.0, 0.5, trim(adjustl(str)))
write_info_line_str = cnt + 1
end function write_info_line_str
integer function write_info_line_int(cnt, ypos, xpos0, dxpos, dxval, label, val)
integer, intent(in) :: cnt, val
real, intent(in) :: ypos, xpos0, dxpos, dxval
character (len = *), intent(in) :: label
character (len = 128) :: str
real :: xpos
write(str, '(a)') trim(label)
xpos = cnt * dxpos + xpos0
call pgptxt(xpos, ypos, 0.0, 1.0, trim(adjustl(str)))
write(str, '(i9)') val
xpos = xpos + dxval
call pgptxt(xpos, ypos, 0.0, 0.0, trim(adjustl(str)))
write_info_line_int = cnt + 1
end function write_info_line_int
integer function write_info_line_flt(&
cnt, ypos, xpos0, dxpos, dxval, label, val)
integer, intent(in) :: cnt
real, intent(in) :: ypos, xpos0, dxpos, dxval
real(dp), intent(in) :: val
character (len = *), intent(in) :: label
character (len = 128) :: str
real :: xpos
integer :: ierr
write_info_line_flt = cnt + 1
write(str, '(a)') trim(label)
xpos = cnt * dxpos + xpos0
call pgptxt(xpos, ypos, 0.0, 1.0, trim(adjustl(str)))
ierr = 0
write(str, '(f12.7)', iostat = ierr) val
if (ierr /= 0) then
ierr = 0
write(str, '(e10.3)', iostat = ierr) val
if (ierr /= 0) then
write(*, *) trim(label), val
write(*, *) 'problem in write_info_line_flt'
return
end if
end if
xpos = xpos + dxval
call pgptxt(xpos, ypos, 0.0, 0.0, trim(adjustl(str)))
end function write_info_line_flt
integer function write_info_line_flt2(cnt, ypos, xpos0, dxpos, dxval, label, val)
integer, intent(in) :: cnt
real, intent(in) :: ypos, xpos0, dxpos, dxval
real(dp), intent(in) :: val
character (len = *), intent(in) :: label
character (len = 128) :: str
real :: xpos
integer :: ierr
write_info_line_flt2 = cnt + 1
write(str, '(a)') trim(label)
xpos = cnt * dxpos + xpos0
call pgptxt(xpos, ypos, 0.0, 1.0, trim(adjustl(str)))
ierr = 0
write(str, '(f12.3)', iostat = ierr) val
if (ierr /= 0) then
ierr = 0
write(str, '(e10.3)', iostat = ierr) val
if (ierr /= 0) then
write(*, *) trim(label), val
write(*, *) 'problem in write_info_line_flt2'
return
end if
end if
xpos = xpos + dxval
call pgptxt(xpos, ypos, 0.0, 0.0, trim(adjustl(str)))
end function write_info_line_flt2
integer function write_info_line_exp(cnt, ypos, xpos0, dxpos, dxval, label, val)
integer, intent(in) :: cnt
real, intent(in) :: ypos, xpos0, dxpos, dxval
real(dp), intent(in) :: val
character (len = *), intent(in) :: label
character (len = 128) :: str
real :: xpos
write(str, '(a)') trim(label)
xpos = cnt * dxpos + xpos0
call pgptxt(xpos, ypos, 0.0, 1.0, trim(adjustl(str)))
write(str, '(1pe10.3)') val
xpos = xpos + dxval
call pgptxt(xpos, ypos, 0.0, 0.0, trim(adjustl(str)))
write_info_line_exp = cnt + 1
end function write_info_line_exp
integer function count_hist_points(&
s, step_min, step_max) result(numpts)
type (star_info), pointer :: s
integer, intent(in) :: step_min, step_max
type (pgstar_hist_node), pointer :: pg
include 'formats'
numpts = 0
pg => s% pg% pgstar_hist
do ! recall that hist list is decreasing by age (and step)
if (.not. associated(pg)) return
if (pg% step < step_min) return
if (pg% step <= step_max .or. step_max <= 0) numpts = numpts + 1
pg => pg% next
end do
end function count_hist_points
logical function get1_hist_yvec(s, step_min, step_max, n, name, vec)
use utils_lib, only : integer_dict_lookup
type (star_info), pointer :: s
integer, intent(in) :: step_min, step_max, n ! n = count_hist_points
character (len = *) :: name
real, dimension(:), allocatable :: vec
integer :: i, cnt, ierr
character (len = 64) :: key_name
include 'formats'
cnt = 0
ierr = 0
do i = 1, len(key_name)
key_name(i:i) = ' '
end do
do i = 1, len_trim(name)
if (name(i:i) == ' ') then
cnt = cnt + 1
key_name(i:i) = '_'
else
key_name(i:i) = name(i:i)
end if
end do
call integer_dict_lookup(s% history_names_dict, key_name, i, ierr)
if (ierr /= 0 .or. i <= 0) then ! didn't find it
get1_hist_yvec = .false.
return
end if
call get_hist_points(s, step_min, step_max, n, i, vec, ierr)
if (ierr /= 0) then ! didn't get them
get1_hist_yvec = .false.
return
end if
get1_hist_yvec = .true.
end function get1_hist_yvec
subroutine set_hist_points_steps(&
s, step_min, step_max, numpts, vec, ierr)
type (star_info), pointer :: s
integer, intent(in) :: step_min, step_max, numpts
real, intent(out) :: vec(:)
integer, intent(out) :: ierr
integer :: i, n
type (pgstar_hist_node), pointer :: pg
ierr = 0
if (numpts == 0) return
pg => s% pg% pgstar_hist
i = numpts
do ! recall that hist list is decreasing by age (and step)
if (.not. associated(pg)) then
ierr = -1
return
end if
if (pg% step < step_min) then
ierr = -1
return
end if
if (pg% step <= step_max) then
vec(i) = real(pg% step)
i = i - 1
if (i == 0) return
end if
pg => pg% next
end do
end subroutine set_hist_points_steps
integer function get_hist_index(s, spec) result(index)
type (star_info), pointer :: s
integer, intent(in) :: spec
integer :: i, num
! note: this doesn't include "extra" columns
num = size(s% history_column_spec, dim = 1)
do i = 1, num
if (s% history_column_spec(i) == spec) then
index = i
return
end if
end do
index = -1
end function get_hist_index
subroutine get_hist_points(&
s, step_min, step_max, numpts, index, vec, ierr)
type (star_info), pointer :: s
integer, intent(in) :: step_min, step_max, numpts, index
real, intent(out) :: vec(:)
integer, intent(out) :: ierr
integer :: i, n
type (pgstar_hist_node), pointer :: pg => null()
include 'formats'
if (numpts == 0) return
pg => s% pg% pgstar_hist
i = numpts
vec = 0
ierr = 0
do ! recall that hist list is decreasing by age (and step)
if (.not. associated(pg)) return
if (pg% step < step_min) then
! this will not happen if have correct numpts
return
end if
if (pg% step <= step_max .or. step_max <= 0) then
if (.not. associated(pg% vals)) then
!ierr = -1
!write(*,6) 'failed in get_hist_points: not associated', &
! s% model_number, index, numpts, step_min, step_max
!call mesa_error(__FILE__,__LINE__,'get_hist_points')
return
end if
if (size(pg% vals, dim = 1) < index) then
!ierr = -1
!write(*,7) 'failed in get_hist_points: size < index', &
! s% model_number, size(pg% vals,dim=1), index, numpts, step_min, step_max
!call mesa_error(__FILE__,__LINE__,'get_hist_points')
return
end if