-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSYCLIST.f95
6198 lines (5198 loc) · 248 KB
/
SYCLIST.f95
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
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
module DataStructure
! Define the new type DataStructure
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
implicit none
integer,parameter,public::Table_Line_Number_normal = 400
integer,parameter,public::Table_Line_Number_PMS = 500
integer,public,save::Table_Line_Number = 400
integer,parameter,private::Data_Number_GE = 42 ! WARNING : adapt this value to the number of data hereafter:
integer,public::Data_Number = -1
integer,parameter,private::i_time_GE=1,i_mass_GE=2,i_logL_GE=3,i_logTeff_corr_GE=4, &
i_H1_Surf_GE=5,i_He4_surf_GE=6,i_C12_surf_GE=7,i_C13_surf_GE=8,i_N14_surf_GE=9, &
i_O16_surf_GE=10,i_O17_surf_GE=11,i_O18_surf_GE=12,i_Ne20_surf_GE=13,i_Ne22_surf_GE=14, &
i_Al26_surf_GE=15,i_Mcc_GE=16,i_logTeff_GE=17,i_Mdot_GE=18,i_rhoc_GE=19,i_Tc_GE=20, &
i_H1_cen_GE=21,i_He4_cen_GE=22,i_C12_cen_GE=23,i_C13_cen_GE=24,i_N14_cen_GE=25, &
i_O16_cen_GE=26,i_O17_cen_GE=27,i_O18_cen_GE=28,i_Ne20_cen_GE=29,i_Ne22_cen_GE=30, &
i_Al26_cen_GE=31,i_Omega_surf_GE=32,i_Omega_cen_GE=33,i_oblat_GE=34,i_Mdot_enhencement_GE=35, &
i_v_crit1_GE=36,i_v_crit2_GE=37,i_v_equa_GE=38,i_Omega_Omcrit_GE=39,i_Gamma_Ed_GE=40, &
i_Mdot_mec_GE=41,i_L_tot_GE=42
integer,public::i_time=-1,i_mass=-1,i_logL=-1,i_logTeff_corr=-1, &
i_H1_Surf=-1,i_He4_surf=-1,i_C12_surf=-1,i_C13_surf=-1,i_N14_surf=-1, &
i_O16_surf=-1,i_O17_surf=-1,i_O18_surf=-1,i_Ne20_surf=-1,i_Ne22_surf=-1, &
i_Al26_surf=-1,i_Mcc=-1,i_logTeff=-1,i_Mdot=-1,i_rhoc=-1,i_Tc=-1, &
i_H1_cen=-1,i_He4_cen=-1,i_C12_cen=-1,i_C13_cen=-1,i_N14_cen=-1, &
i_O16_cen=-1,i_O17_cen=-1,i_O18_cen=-1,i_Ne20_cen=-1,i_Ne22_cen=-1, &
i_Al26_cen=-1,i_Omega_surf=-1,i_Omega_cen=-1,i_oblat=-1,i_Mdot_enhencement=-1, &
i_v_crit1=-1,i_v_crit2=-1,i_v_equa=-1,i_Omega_Omcrit=-1,i_Gamma_Ed=-1, &
i_Mdot_mec=-1,i_L_tot=-1
integer,parameter,public::Additional_Data_Number = 24 !WARNING : adapt this value to the number of data
!hereafter:
integer,parameter,public::i_MBol=1,i_MV=2,i_UB=3,i_BV=4,i_B2V1=5,i_VR=6,i_VI=7,i_JK=8,i_HK=9,i_VK=10, &
i_GV=11,i_GbpV=12,i_GrpV=13,i_Gflag=14,i_PolarRadius=15,i_polar_gravity=16,i_MV_noisy=17,i_BV_noisy=18, &
i_BC=19,i_logL_gd=20,i_logTeff_gd=21,i_logL_lgd=22,i_logTeff_lgd=23,i_mean_gravity=24
character(*),parameter,public::ReadFormat = '(i3,1x,e22.15,1x,f11.6,2(1x,f9.6),2(1x,e14.7),1p,8(1x,e14.7),1x,e10.3,&
&1x,0pf7.4,1x,f9.6,1x,f8.3,2(1x,f9.6),2(1x,e14.7),1p,8(1x,e14.7),5(1x,e10.3),3(1x,e9.2),&
&0p,2(1x,f9.6),1x,1pe14.7,1x,e17.10)'
logical,public,save:: verbose
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
type type_DataStructure
real(kind=8)::Metallicity,mass_ini,Omega_Omcrit_ini
character(512)::FileName
integer,dimension(:),allocatable::line
real(kind=8),dimension(:,:),allocatable::Data_Table
end type type_DataStructure
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
type type_TimeModel
integer::star_ID,Is_a_Binary
real(kind=8)::Metallicity,mass_ini,Omega_Omcrit_ini,Current_Time,mass_ratio,Angle_of_View
real(kind=8),dimension(:),allocatable::Data_Line
real(kind=8),dimension(Additional_Data_Number)::Additional_Data_Line
end type type_TimeModel
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
public::FillData
public::Init_DataStructure
public::Del_DataStructure
public::Init_Indices
public::Init_TimeModel
contains
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Init_DataStructure(Number_of_lines,Number_of_data,MyDataStructure)
! Initiate the dimension of the DataStructure dynamically.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
integer, intent(in):: Number_of_lines,Number_of_data
type(type_DataStructure),intent(out)::MyDataStructure
integer::i,j
allocate(MyDataStructure%line(Number_of_lines))
allocate(MyDataStructure%Data_Table(Number_of_lines,Number_of_data))
do i=1,Number_of_lines
MyDataStructure%line(i) = -1
enddo
do i=1,Number_of_lines
do j=1,Number_of_data
MyDataStructure%Data_Table(i,j) = -10.d0
enddo
enddo
return
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end subroutine Init_DataStructure
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Del_DataStructure(MyDataStructure)
! Delete DataStructure arrays.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
type(type_DataStructure),intent(inout)::MyDataStructure
deallocate(MyDataStructure%line)
deallocate(MyDataStructure%Data_Table)
end subroutine Del_DataStructure
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Init_Indices(MyFormat)
! Delete DataStructure arrays.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
integer,intent(in):: MyFormat
if (MyFormat == 1) then
! GENEC format
Data_Number = Data_Number_GE
i_time = i_time_GE
i_mass = i_mass_GE
i_logL = i_logL_GE
i_logTeff_corr = i_logTeff_corr_GE
i_H1_Surf = i_H1_Surf_GE
i_He4_surf = i_He4_surf_GE
i_C12_surf = i_C12_surf_GE
i_C13_surf = i_C13_surf_GE
i_N14_surf = i_N14_surf_GE
i_O16_surf = i_O16_surf_GE
i_O17_surf = i_O17_surf_GE
i_O18_surf = i_O18_surf_GE
i_Ne20_surf = i_Ne20_surf_GE
i_Ne22_surf = i_Ne22_surf_GE
i_Al26_surf = i_Al26_surf_GE
i_Mcc = i_Mcc_GE
i_logTeff = i_logTeff_GE
i_Mdot = i_Mdot_GE
i_rhoc = i_rhoc_GE
i_Tc = i_Tc_GE
i_H1_cen = i_H1_cen_GE
i_He4_cen = i_He4_cen_GE
i_C12_cen = i_C12_cen_GE
i_C13_cen = i_C13_cen_GE
i_N14_cen = i_N14_cen_GE
i_O16_cen = i_O16_cen_GE
i_O17_cen = i_O17_cen_GE
i_O18_cen = i_O18_cen_GE
i_Ne20_cen = i_Ne20_cen_GE
i_Ne22_cen = i_Ne22_cen_GE
i_Al26_cen = i_Al26_cen_GE
i_Omega_surf = i_Omega_surf_GE
i_Omega_cen = i_Omega_cen_GE
i_oblat = i_oblat_GE
i_Mdot_enhencement = i_Mdot_enhencement_GE
i_v_crit1 = i_v_crit1_GE
i_v_crit2 = i_v_crit2_GE
i_v_equa = i_v_equa_GE
i_Omega_Omcrit = i_Omega_Omcrit_GE
i_Gamma_Ed = i_Gamma_Ed_GE
i_Mdot_mec = i_Mdot_mec_GE
i_L_tot = i_L_tot_GE
else if (MyFormat == 2) then
! Starevol format
write(*,*) 'Done'
else
write(*,*) 'Problems with the requested format, aborting...'
stop
endif
end subroutine Init_Indices
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Init_TimeModel(Number_of_data,MyTimeModel)
! Initiate the dimension of the TimeModel dynamically.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
integer, intent(in):: Number_of_data
type(type_TimeModel),intent(out)::MyTimeModel
integer::i
allocate(MyTimeModel%Data_Line(Number_of_data))
do i=1,Number_of_data
MyTimeModel%Data_Line(i) = -1
enddo
return
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end subroutine Init_TimeModel
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine FillData(Z,Mini,Omini,FileNameIn,Structure)
! Read the evolution file and fill the structure.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8),intent(in)::Z,Mini,Omini
character(512),intent(in)::FileNameIn
type(type_DataStructure),intent(inout)::Structure
integer::LineNumber,error=0,i,j
integer,parameter::ReadUnit=30,Line_to_Remove = 3
open(unit=ReadUnit,file=trim(FileNameIn),iostat=error,status='old')
if (error /= 0) then
write(*,*) 'Error opening file ',trim(FileNameIn),'. Aborting...'
stop
endif
! The table files have 18 lines at the beginning to remove.
do i=1,Line_to_Remove
read(ReadUnit,*)
enddo
! Determine the number of lines
LineNumber = 0
do while (error == 0)
read(ReadUnit,*,iostat=error)
if (error /= 0) then
exit
endif
LineNumber = LineNumber+1
enddo
! Check if the input file has the right format.
if (LineNumber /= Table_Line_Number) then
write(*,*) 'The file ',trim(FileNameIn),' is not at the .grids format: not enough or too much lines.'
stop
endif
! Fill the structure
Structure%Metallicity = Z
Structure%mass_ini = Mini
Structure%Omega_Omcrit_ini = Omini
Structure%FileName = FileNameIn
if (verbose) then
write(*,*) 'Reading ',trim(Structure%FileName),'...'
endif
rewind(ReadUnit)
! The table files have 18 lines at the beginning to remove.
do i=1,Line_to_Remove
read(ReadUnit,*)
enddo
! Read the data, and check the number of different lines.
do i=1,LineNumber
read(ReadUnit,ReadFormat,iostat=error)Structure%line(i),(Structure%Data_Table(i,j),j=1,Data_Number)
if (error /= 0) then
write(*,*) 'Problem reading file ',trim(FileNameIn),'. Aborting...'
stop
endif
! To perform a better interpolation, the null mass loss rate (in log) are put to -32.
if (abs(Structure%Data_Table(i,i_Mdot)) < 1.d-30) then
Structure%Data_Table(i,i_Mdot) = -32.d0
endif
if (abs(Structure%Data_Table(i,i_Mdot_mec)) < 1.d-30) then
Structure%Data_Table(i,i_Mdot_mec) = -32.d0
endif
enddo
! Set the time on the ZAMS to 1 yr (to avoid complication due to log interpolation).
if (Structure%Data_Table(1,i_time) /= 0.d0) then
Structure%Data_Table(:,i_time) = Structure%Data_Table(:,i_time) - Structure%Data_Table(1,i_time) + 1.d0
else
Structure%Data_Table(1,i_time) = 1.d0
endif
if (verbose) then
write(*,*) ' done !'
endif
close(ReadUnit)
return
end subroutine FillData
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end module DataStructure
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
module Constant
! Contains constants
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
implicit none
real(kind=8),parameter::pi = 3.1415926535897932384626433d0, & ! Pi
L_sun = 3.846d33, & ! Solar luminosity
sigma_SB = 5.670373d-5, & ! Stefan-Boltzman constant
G_Newton = 6.67384d-8, & ! Gravitational constant
M_sun = 1.9891d33, & ! Solar mass
Z_sun = 0.014d0, & ! Solar metallicity
R_sun = 6.961d10, & ! Solar radius
sL_sun = 10.61d0 ! Solar log spectroscopic luminosity
end module Constant
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
module VariousParameters
! Contains various parameters (among of them, some can be changed later
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
use DataStructure, only: type_DataStructure
implicit none
integer,public,save:: star_number=1000 ! Current numbe of star in the cluster.
integer,public,save:: table_format = 1 ! Table format (1) GENEC, (2) Starevol
integer,public,save::i_metallicity=0 ! Metallicity distribution: dirac (0)
integer,public,save::ivdist=1 ! Velocity distribution: uniform (0),
! huang(1), huang-gies(2), dirac_om(3)
integer,public,save::iangle=2 ! uniforme dist. (1), vsini (2), Dirac (3)
! or not (0) of the angle of view
integer,public,save::inoise=1 ! noise adjunction (1) or not (0)
! (data without noise are saved whatever
! the case)
integer,public,save::grav_dark=2 ! gravity darkening law: (1) vonZeipel (1924),
! (2) Espinosa-Lara & Reutord (2011)
integer,public,save::limb_dark=1 ! no limb-darkening (0), with LD (1)
integer,public,save::Current_Number ! Current star number
integer,public,save::SN_Number ! SN number (star more massive than m_norm_sup)
integer,public,save::Small_Number ! small mass star number (< m_norm_inf).
integer,public,save::Cepheid_Number ! Cepheid number
integer,public,save::FastRot_Number ! Fast rotators number
integer,public,save::Z_Number ! Metallicity number
integer,public,save::IMF_type = 1 ! IMF. For now, only Salpeter (1) is allowed
integer,public,save::Comp_Mode = 0 ! Various computation mode : (1) cluster, (2)
! isochrone, (3) Population mode, (4) Single model
integer,public,save::Colour_Calibration_mode = 2 ! Colour-Teff calibration (1) as in Paper I 2011,
! (2) Worthey & Lee, ApJS 193 1 (2011).
integer,pointer::mass_Number_array(:) ! Array containing the number of mass for each Z.
integer,pointer::omega_Number_array(:,:) ! Array containg for each Z and mass the number
! of different rotation velocities
real(kind=8),public,save::Fixed_AoV_latitude=22.d0 ! Fixed angle of view from pole to equator
real(kind=8),public,save::Fixed_AoV ! Same angle, in colatitude.
real(kind=8),public,parameter::m_IMF_inf_Grids2012=0.8d0, m_IMF_sup_Grids2012=120.d0
real(kind=8),public,parameter::m_IMF_inf_BeGrids=1.7d0, m_IMF_sup_BeGrids=15.d0
real(kind=8),public,parameter::m_IMF_inf_NamiGrids=0.5d0, m_IMF_sup_NamiGrids=3.5d0
real(kind=8),public,save::m_IMF_inf=m_IMF_inf_BeGrids, m_IMF_sup=m_IMF_sup_BeGrids ! IMF min and max mass
real(kind=8),public,save::fixed_metallicity = 0.014d0 ! Metallicity used in case of Dirac distribution
real(kind=8),public,save::om_ivdist=0.40d0 ! In case of Dirac omega-distribution
real(kind=8),public,save::binary_prob=0.30d0 ! Binarity probability
real(kind=8),public,save::Star_Z ! Current stellar metallicity
real(kind=8),public,save::Star_mass ! Current stellar mass
real(kind=8),public,save::Star_omega ! Current stellar velocity
real(kind=8),public,save::Star_AoV ! Current stellar angle of view
real(kind=8),public,parameter::log_age_max=11.0d0 ! Maximal log(age) for cluster allowed with the
real(kind=8),public,save::sigma_mv=0.150d0, sigma_bv=0.10d0 ! standard deviation in MV et B-V
! current tables.
real(kind=8),public,save::age_log ! wanted log(age).
real(kind=8),public,save::Cluster_mass ! Total cluster mass
real(kind=8),dimension(:,:,:),public,pointer,save::omega_List=>null() ! List of the rotation velocities.
real(kind=8),dimension(:,:),public,pointer,save::mass_List=>null() ! List of the masses.
real(kind=8),dimension(:),public,pointer,save::Z_List=>null() ! List of the metallicities.
logical,public,save::PMS=.false.
logical,public,save::Compute ! Used in the main loop
type(type_DataStructure),dimension(:,:,:),public,pointer,save::All_Data_Array=>null() ! Array containing
! in each coordinate (ie, Z,m and omega)
! the data structure.
character(9),public:: grid = "BeGrids"
character(256),public::Std_Path,Std_Path_tables
! directory of following files:
character(*),parameter,public::HuangFile = 'HuangDist.dat', & ! File of the Huang distribution
HGFile = 'HGDist.dat', & ! File of the Huang & Gies distribution
LumFileVZ = 'CorrLumVZ.dat', & ! File of the luminosity corrections according to von Zeipel 1924
TeffFileVZ = 'CorrTeffVZ.dat', & ! File of the Teff corrections according to von Zeipel 1924
LumFileELR = 'CorrLumELR.dat', & ! File of the luminosity corrections according to ELR 2011
TeffFileELR = 'CorrTeffELR.dat', & ! File of the Teff corrections according to ELR 2011
GravFileVZ = 'CorrGravVZ.dat', & ! File of the Teff corrections according to von Zeipel 1924
GravFileELR = 'CorrGravELR.dat', & ! File of the Teff corrections according to ELR 2011
LumGridVZ = 'CorrLumVZ_LD.dat', & !new! Grid of files for lum corrections (vZ with LD)
TeffGridVZ = 'CorrTeffVZ_LD.dat', & !new! Grid of files for Teff corrections (vZ with LD)
LumGridELR = 'CorrLumELR_LD.dat', & !new! Grid of files for lum corrections (ELR with LD)
TeffGridELR = 'CorrTeffELR_LD.dat', & !new! Grid of files for Teff corrections (ELR with LD)
VCrit_to_Omega_File = 'Vcrit2omega.dat', & ! Vcrit to omega translation
OmegaSurface_File = 'Surface_Omega.dat', & ! S vs omega/omega_crit data file.
DataColor = 'DataColours.dat' ! File of the data for color corrections.
character(*),parameter,public::ListFileGrids2012='ListFileL.txt', & ! File containing the path of the large grid files
ListFileBeGrids='ListFileB.txt', & ! File containing the path of the Be grid files
ListFileFastBe='ListFileF.txt',& ! File containing the path of the fast Be grid files
ListFileNamiGrids='ListFileN.txt' ! File containing the path of the Nami grid files
character(*),parameter,public::GridsFormat = '(i3,1x,e22.15,1x,f11.6,2(1x,f9.6),2(1x,e14.7),1p,&
&8(1x,e14.7),1x,e10.3,1x,0pf7.4,1x,f9.6,1x,f8.3,2(1x,f9.6),2(1x,e14.7),1p,8(1x,e14.7),&
&5(1x,e10.3),3(1x,e9.2),0p,2(1x,f9.6),1x,1pe14.7,1x,e17.10)'
public:: init_AoV
contains
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine init_AoV()
! Transforms the given angle of view in colatitudinal angle.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
use Constant, only:pi
implicit none
Fixed_AoV = pi/2.d0-Fixed_AoV_latitude*(pi/180.d0)
return
end subroutine init_AoV
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end module VariousParameters
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
module LoopVariables
! Module containing variables used only in the main loop, not useful elsewhere
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
use DataStructure, only: type_DataStructure,type_TimeModel
implicit none
integer, dimension(2,2), public, save::omega_Position ! Position of the current velocity in the
! table.
integer, dimension(2), public, save::mass_Position ! Position of the current mass in the
! table.
integer, public, save::Z_Position ! Position of the current metallicity in the
! table.
real(kind=8), dimension(2,2), public, save::omega_factor ! Interpolation factor in omega.
real(kind=8), dimension(2), public, save::mass_factor ! Interpolation factor in mass.
real(kind=8), public, save::Z_factor ! Interpolation factor in metllicity.
type(type_DataStructure), public, save::Interpolated_Model
type(type_TimeModel), dimension(:),public, pointer, save:: CurrentTime_Model=>null() ! Array containing
! the data of the model at the given time.
end module LoopVariables
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
module interpolmod
! Module containing routines useful for interpolation purpose.
! &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
public:: Linear_Interp
public:: indice
public:: give_factor
public:: give_factorLog
public:: All_Positions_and_factors
public:: Make_InterpolatedModel
public:: Make_TimeModel
public:: Bilin_Interpol
private:: Interpol_factor
private:: Interpol_factor_array
private:: Interpolate_Model
private:: Fill_Data_ZAMS
private:: Time_Interpolation
private:: Interpol_Mass
private:: Interpol_Omega
private:: omega_Position_and_factor
private:: mass_Position_and_factor
private:: Z_Position_and_factor
contains
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function Linear_Interp(x,n,a,b)
! Linear interpolation routine
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8),intent(in)::x
integer,intent(in)::n
integer::k
real(kind=8), dimension(n),intent(in):: a,b
k=indice(x,a,n)
Linear_Interp=b(k)+(b(k+1)-b(k))*(x-a(k))/(a(k+1)-a(k))
return
end function Linear_Interp
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
integer function indice(x0,x,m)
! Quick search of the position d of a value xo in a monotic table of m numbers x(i)
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8),intent(in):: x0
integer,intent(in):: m
integer:: i=0,k,n
real(kind=8), intent(in),dimension(m):: x
! si k = indice(x0,x,m) on aura x0 compris entre x(k) et x(k+1)
! ou x0 = x(k).
! si x0 exterieur a la table indice=1 si x0 du cote de x(1)
! indice = m-1 si x0 du cote de x(m)
n = m
k = 1
do while (n-k-1 /= 0)
i=(k+n)/2
if((x(i)-x0)*(x(n)-x(1)) <= 0) then
k = i
else
n = i
endif
enddo
indice = k
return
end function indice
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function give_factor(x_Current,x_i,x_ip1)
! Compute the fraction of the current position in the intervale of interpolation
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8), intent(in)::x_Current,x_i,x_ip1
give_factor = (x_Current-x_i)/(x_ip1-x_i)
return
end function give_factor
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function give_factorLog(x_Current,x_i,x_ip1)
! Compute the fraction of the current position in the intervale of interpolation
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8), intent(in)::x_Current,x_i,x_ip1
give_factorLog = (log10(x_Current)-log10(x_i))/(log10(x_ip1)-log10(x_i))
return
end function give_factorLog
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function Interpol_factor(in_1,in_2,factor)
! Simple linear function : out = in_1 + factor*(in_2 - in_1)
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8),intent(in)::in_1,in_2,factor
if (factor == 0.d0) then
Interpol_factor = in_1
else if (factor == 1.d0) then
Interpol_factor = in_2
else
Interpol_factor = in_1 + factor*(in_2 - in_1)
endif
return
end function Interpol_factor
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Interpol_factor_array(in_1,in_2,factor,Number_dim1,Number_dim2,Array_out)
! Simple linear function : out = in_1 + factor*(in_2 - in_1), but for the data array.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
integer, intent(in)::Number_dim1,Number_dim2
real(kind=8), intent(in)::factor
real(kind=8),dimension(Number_dim1,Number_dim2),intent(in)::in_1,in_2
real(kind=8),dimension(Number_dim1,Number_dim2),intent(out)::Array_out
if (factor == 0.d0) then
Array_out(:,:) = in_1(:,:)
else if (factor == 1.d0) then
Array_out(:,:) = in_2(:,:)
else
Array_out(:,:) = in_1(:,:) + factor*(in_2(:,:) - in_1(:,:))
endif
return
end subroutine Interpol_factor_array
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function Bilin_Interpol(P1,P2,P3,P4,fact1,fact2)
! Perform a bilinear interpolation between 4 points. The disposition is:
! P4-----------P3
! . .
! . .
! . . fact2
! . . ^
! . . !
! P1-----------P2 !
! ---> fact1
! The first interpolation is done along fact1, and then along fact2.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
implicit none
real(kind=8),intent(in)::P1,P2,P3,P4,fact1,fact2
real(kind=8):: PA,PB
PA = Interpol_factor(P1,P2,fact1)
PB = Interpol_factor(P4,P3,fact1)
Bilin_Interpol = Interpol_factor(PA,PB,fact2)
return
end function Bilin_Interpol
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
real(kind=8) function Plane_Interpol(x1,y1,P1,x2,y2,P2,x3,y3,P3,x,y)
!
!Esta funcion encuentra el plano que pasa por 3 vertices, para interpolar un valor intermedio.
!
implicit none
real(kind=8),intent(in)::x1,y1,P1,x2,y2,P2,x3,y3,P3,x,y
real(kind=8):: M1,M2,M3,D
!
M1 = (y2 * P3) - (y3 * P2) - ((y1 * P3) - (y3 * P1)) + (y1 * P2) - (y2 * P1)
M2 = -((x2 * P3) - (x3 * P2)) + (x1 * P3) - (x3 * P1) - ((x1 * P2) - (x2 * P1))
M3 = (x2 * y3) - (x3 * y2) - ((x1 * y3) - (x3 * y1)) + (x1 * y2) - (x2 * y1)
D = x1 *((y2 * P3) - (y3 * P2)) - x2 * ((y1 * P3) - (y3 * P1)) + x3 *((y1*P2) -(y2* P1))
!
Plane_Interpol = (D - M1 * x - M2 * y)/ M3
!
return
end function Plane_Interpol
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine omega_Position_and_factor(omega,Position_stage1,Position_stage2,Position,factor)
! Compute the fraction of the current position in the intervale of interpolation
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
use VariousParameters, only: omega_Number_array, omega_List
implicit none
integer, intent(in)::Position_stage1,Position_stage2
integer, intent(out)::Position
real(kind=8), intent(in)::omega
real(kind=8), intent(out)::factor
logical:: Test_List
Test_List = .false.
if (omega_Number_array(Position_stage1,Position_stage2) == 1) then
if (omega_List(Position_stage1,Position_stage2,1) == 0.d0) then
if (omega < 1.d-9) then
Test_List = .true.
endif
else
if (abs(omega/omega_List(Position_stage1,Position_stage2,1)-1.d0) < 1.d-9) then
Test_List = .true.
endif
endif
if (Test_List) then
Position = 1
factor = 0.d0
else
write(*,*) 'Not enough velocities to perform interpolation...'
stop
endif
else
! In case where the velocity is above the largest tabulated velocity, extrapolation instead of
! interpolation.
if (omega <= omega_List(Position_stage1,Position_stage2,omega_Number_array(Position_stage1,Position_stage2))) then
Position = indice(omega,omega_List(Position_stage1,Position_stage2,:), &
omega_Number_array(Position_stage1,Position_stage2))
factor = give_factor(omega,omega_List(Position_stage1,Position_stage2,Position), &
omega_List(Position_stage1,Position_stage2,Position+1))
else
Position = omega_Number_array(Position_stage1,Position_stage2)-1
factor = give_factor(omega,omega_List(Position_stage1,Position_stage2,Position), &
omega_List(Position_stage1,Position_stage2,Position+1))
endif
endif
return
end subroutine omega_Position_and_factor
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine mass_Position_and_factor(mass,Above_Position,Position,factor)
! Compute the fraction of the current position in the intervale of interpolation
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
use VariousParameters, only: mass_Number_array, mass_List
implicit none
integer, intent(in)::Above_Position
integer, intent(out)::Position
real(kind=8), intent(in)::mass
real(kind=8), intent(out)::factor
if (mass_Number_array(Above_Position) == 1) then
if (abs(mass/mass_List(Above_Position,1)-1.d0) < 1.d-9) then
Position = 1
factor = 0.d0
else
write(*,*) 'Not enough mass to perform interpolation...'
stop
endif
else
! Due to the binary treatment, we allow the companion mass to be smaller than the minimal mass
! of the model grid. In this case : extrapolation.
if (mass >= mass_List(Above_Position,1)) then
Position = indice(mass,mass_List(Above_Position,:),mass_Number_array(Above_Position))
factor = give_factorLog(mass,mass_List(Above_Position,Position),mass_List(Above_Position,Position+1))
else
Position = 1
factor = give_factorLog(mass,mass_List(Above_Position,Position),mass_List(Above_Position,Position+1))
endif
endif
return
end subroutine mass_Position_and_factor
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Z_Position_and_factor(Z,Position,factor)
! While we have only one metallicity, trivial routine
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
use VariousParameters, only: Z_Number, Z_List
implicit none
integer, intent(out)::Position
real(kind=8), intent(in)::Z
real(kind=8), intent(out)::factor
if (Z_Number == 1) then
if (abs(Z/Z_List(1)-1.d0) < 1.d-9) then
Position = 1
factor = 0.d0
else
write(*,*) 'Not enough metallicities to perform interpolation...'
stop
endif
else
if (Z >= Z_List(1) .and. Z <= Z_List(Z_Number)) then
Position = indice(Z,Z_List,Z_Number)
factor = give_factorLog(Z,Z_List(Position),Z_List(Position+1))
else
write(*,*) 'Metallicity out of the models metallicities. Aborting...'
stop
endif
endif
return
end subroutine Z_Position_and_factor
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine All_Positions_and_factors(Star_Z,Z_Position,Z_factor,Star_mass,mass_Position,mass_factor, &
Star_omega,omega_Position,omega_factor)
! Responsible for managing the determination of the model in the tables.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! use VariousParameters, only: IMF_type,Star_Z,Star_mass,Star_omega,Star_AoV,ivdist,age_log,fixed_metallicity, &
! om_ivdist,star_number,Comp_Mode,iangle,Z_Number,mass_Number_array,Fixed_AoV
use VariousParameters, only: Z_Number,mass_Number_array
implicit none
integer:: i,Real_Z_Position
integer, intent(out)::Z_Position
integer, dimension(2),intent(out)::mass_Position
integer, dimension(2,2), intent(out)::omega_Position
real(kind=8), intent(in)::Star_Z,Star_mass,Star_omega
real(kind=8), intent(out)::Z_factor
real(kind=8), dimension(2),intent(out)::mass_factor
real(kind=8), dimension(2,2),intent(out)::omega_factor
call Z_Position_and_factor(Star_Z,Z_Position,Z_factor)
if (Z_Number > 1) then
! In case where the table contains several Z, find the mass position for the nearest 2.
if (Z_factor == 1.d0) then
! Case where we are at the upper limit of the Z table. As the function ...Position_and_factor return the final
! position - 1 in that case, we have to look for the mass at the position Z_Position+1.
Real_Z_Position = Z_Position+1
call mass_Position_and_factor(Star_mass,Real_Z_Position,mass_Position(1),mass_factor(1))
else if (Z_factor == 0.d0) then
! In that case, no interpolation in Z will be needed, only one mass position is mandatory.
Real_Z_Position = Z_Position
call mass_Position_and_factor(Star_mass,Real_Z_Position,mass_Position(1),mass_factor(1))
else
! Standard case.
Real_Z_Position = Z_Position
call mass_Position_and_factor(Star_mass,Real_Z_Position,mass_Position(1),mass_factor(1))
call mass_Position_and_factor(Star_mass,Real_Z_Position+1,mass_Position(2),mass_factor(2))
endif
else
Real_Z_Position = Z_Position
call mass_Position_and_factor(Star_mass,Real_Z_Position,mass_Position(1),mass_factor(1))
endif
! Same procedure for determining the position in the omega table.
do i=1,2
! If the mass position is not set, cycle.
if (mass_Position(i) < 0) then
cycle
endif
if (mass_Number_array(Real_Z_Position-1+i) > 1) then
! In case where the table contains several mass, find the omega position for the nearest 2.
if (mass_factor(i) == 1.d0) then
! Case where we are at the upper limit of the mass table. As the function ...Position_and_factor return the final
! position - 1 in that case, we have to look for the mass at the position Z_Position+1.
call omega_Position_and_factor(Star_omega,Real_Z_Position-1+i,mass_Position(i)+1, &
omega_Position(i,1),omega_factor(i,1))
else if (mass_factor(i) == 0.d0) then
! In that case, no interpolation in omega will be needed, only one mass position is mandatory.
call omega_Position_and_factor(Star_omega,Real_Z_Position-1+i,mass_Position(i), &
omega_Position(i,1),omega_factor(i,1))
else
! Standard case.
call omega_Position_and_factor(Star_omega,Real_Z_Position-1+i,mass_Position(i), &
omega_Position(i,1),omega_factor(i,1))
call omega_Position_and_factor(Star_omega,Real_Z_Position-1+i,mass_Position(i)+1, &
omega_Position(i,2),omega_factor(i,2))
endif
else
call omega_Position_and_factor(Star_omega,Real_Z_Position-1+i,mass_Position(i), &
omega_Position(i,1),omega_factor(i,1))
endif
enddo
end subroutine All_Positions_and_factors
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subroutine Make_InterpolatedModel(Position_z,factor_z,Position_m,factor_m,Position_o,factor_o,New_Structure)
! Compute the interpolated model (given mass and omega). The interpolation factor and the position in
! the table are passed by arguments.
! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
use DataStructure, only:type_DataStructure,i_mass,Table_Line_Number,i_H1_Surf,i_He4_surf,i_C12_surf,i_C13_surf, &
i_N14_surf,i_O16_surf,i_O17_surf,i_O18_surf,i_Ne20_surf,i_Ne22_surf,i_Al26_surf,i_Mcc, &
i_H1_cen,i_He4_cen,i_C12_cen,i_C13_cen,i_N14_cen,i_O16_cen,i_O17_cen,i_O18_cen,i_Ne20_cen, &
i_Ne22_cen,i_Al26_cen,i_Omega_Omcrit,i_Gamma_Ed,i_Omega_surf,i_Mcc,i_oblat,i_v_equa,i_v_crit1,i_v_crit2, &
Init_DataStructure,Del_DataStructure,Data_Number,Table_Line_Number
use VariousParameters, only:All_Data_Array,Z_Number
implicit none
integer, intent(in)::Position_z
integer, dimension(2), intent(in)::Position_m
integer, dimension(2,2), intent(in):: Position_o
real(kind=8), intent(in)::factor_z
real(kind=8), dimension(2), intent(in)::factor_m
real(kind=8), dimension(2,2), intent(in)::factor_o
type(type_DataStructure),intent(out)::New_Structure
type(type_DataStructure)::Structure_Below,Structure_Above
integer::i
! Initialisation of the intermediate structures used here:
call Init_DataStructure(Table_Line_Number,Data_Number,New_Structure)
call Init_DataStructure(Table_Line_Number,Data_Number,Structure_Below)
call Init_DataStructure(Table_Line_Number,Data_Number,Structure_Above)
! The interpolation is done in the order: 1. omega interpolation, 2. mass interpolation (log) and 3. metallicity
! interpolation (log). If only one m/z/omega is present, no interpolation is needed (the check of the values
! between the reqested one one the existence in the table is done previously).
if (Z_Number > 1) then
! Enough metallicities to perform interpolation.
if (factor_z == 1.d0) then
! If the metallicity is the last one in the metallicity list, no interpolation in metallicity is performed.
call Interpol_Mass(Position_z+1,Position_m(1),factor_m(1),Position_o(1,:),factor_o(1,:), &
New_Structure)
else if (factor_z == 0.d0) then
! If we are close to an existing metallicity, no interpolation is needed.
call Interpol_Mass(Position_z,Position_m(1),factor_m(1),Position_o(1,:),factor_o(1,:), &
New_Structure)
else
! Normal case.
call Interpol_Mass(Position_z,Position_m(1),factor_m(1),Position_o(1,:),factor_o(1,:),Structure_Below)
call Interpol_Mass(Position_z+1,Position_m(2),factor_m(2),Position_o(2,:),factor_o(2,:),Structure_Above)
! The interpolation is done according to the log of the metallicity, we need to convert the initial and current
! metallicity into log scale.
Structure_Below%Metallicity = log10(Structure_Below%Metallicity)
Structure_Above%Metallicity = log10(Structure_Above%Metallicity)
call Interpolate_Model(Structure_Below,Structure_Above,factor_z,New_Structure)
! Convert back into non log scale.
New_Structure%Metallicity = 10.d0**New_Structure%Metallicity
endif
else
call Interpol_Mass(Position_z,Position_m(1),factor_m(1),Position_o(1,:),factor_o(1,:),New_Structure)
endif
! Among the interpolated variables, some of them cannot physically overcome 1 or be negative. They are corrected here.
do i=1,Table_Line_Number
if (New_Structure%Data_Table(i,i_H1_surf) > 1.d0) then
New_Structure%Data_Table(i,i_H1_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_He4_surf) > 1.d0) then
New_Structure%Data_Table(i,i_He4_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_C12_surf) > 1.d0) then
New_Structure%Data_Table(i,i_C12_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_C13_surf) > 1.d0) then
New_Structure%Data_Table(i,i_C13_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_N14_surf) > 1.d0) then
New_Structure%Data_Table(i,i_N14_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_O16_surf) > 1.d0) then
New_Structure%Data_Table(i,i_O16_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_O17_surf) > 1.d0) then
New_Structure%Data_Table(i,i_O17_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_O18_surf) > 1.d0) then
New_Structure%Data_Table(i,i_O18_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_Ne20_surf) > 1.d0) then
New_Structure%Data_Table(i,i_Ne20_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_Ne22_surf) > 1.d0) then
New_Structure%Data_Table(i,i_Ne22_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_Al26_surf) > 1.d0) then
New_Structure%Data_Table(i,i_Al26_surf) = 1.d0
endif
if (New_Structure%Data_Table(i,i_Mcc) > 1.d0) then
New_Structure%Data_Table(i,i_Mcc) = 1.d0
endif
if (New_Structure%Data_Table(i,i_H1_cen) > 1.d0) then
New_Structure%Data_Table(i,i_H1_cen) = 1.d0
endif
if (New_Structure%Data_Table(i,i_He4_cen) > 1.d0) then
New_Structure%Data_Table(i,i_He4_cen) = 1.d0
endif
if (New_Structure%Data_Table(i,i_C12_cen) > 1.d0) then
New_Structure%Data_Table(i,i_C12_cen) = 1.d0
endif
if (New_Structure%Data_Table(i,i_C13_cen) > 1.d0) then
New_Structure%Data_Table(i,i_C13_cen) = 1.d0
endif
if (New_Structure%Data_Table(i,i_N14_cen) > 1.d0) then
New_Structure%Data_Table(i,i_N14_cen) = 1.d0
endif
if (New_Structure%Data_Table(i,i_O16_cen) > 1.d0) then
New_Structure%Data_Table(i,i_O16_cen) = 1.d0