-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodpk_io.f90
More file actions
152 lines (125 loc) · 4.09 KB
/
modpk_io.f90
File metadata and controls
152 lines (125 loc) · 4.09 KB
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
module modpk_io
!Behold the beauty that is Fortran IO.
!Controls output options for the run.
implicit none
private
public :: out_opt
type :: print_options
!Verbosity
logical :: modpkoutput
logical :: output_reduced
!Things to print
logical :: save_traj
logical :: output_badic
logical :: fields_horiz
logical :: fields_end_infl
logical :: spectra
logical :: modes
!File unit numbers for output
integer :: trajout
integer :: spectraout
integer :: fields_h_out
integer :: fields_end_out
integer :: outsamp
integer :: outsamp_SR
integer :: outsamp_N_iso
integer :: outsamp_N_iso_SR
integer, dimension(4) :: modeout
!If first write, then make column headers
logical :: first_trajout = .true.
logical :: first_spectraout = .true.
logical :: first_fields_h_out = .true.
logical :: first_fields_end_out = .true.
logical :: first_outsamp = .true.
logical :: first_outsamp_SR = .true.
logical :: first_outsamp_N_iso = .true.
logical :: first_outsamp_N_iso_SR = .true.
logical :: first_modeout = .true.
!Writing fmts
character(16) :: e_fmt = '(a25, 900es12.4)'
character(36) :: e2_fmt = '(a25, es17.9, a3, es16.9, a1)'
character(16) :: i_fmt = '(a25,I3)'
character(16) :: array_fmt
character(len=2) :: ci
contains
procedure, public :: open_files => output_file_open
procedure, public :: close_files => output_file_close
procedure, public :: formatting => make_formatting
end type
!Main global instance for printing options
type(print_options) :: out_opt
contains
!Open output files
subroutine output_file_open(self,ICs,SR)
class(print_options) :: self
logical, intent(in), optional :: ICs, SR
if (self%save_traj) &
open(newunit=self%trajout, &
file="out_trajectory.csv")
if (self%spectra) &
open(newunit=self%spectraout, &
file="out_powerspectra.csv")
if (self%fields_horiz) &
open(newunit=self%fields_h_out, &
file="out_fields_horizon_cross.csv")
if (self%fields_end_infl) &
open(newunit=self%fields_end_out, &
file="out_fields_infl_end.csv")
if (self%modes) then
open(newunit=self%modeout(1), &
file="out_modes_1.csv")
open(newunit=self%modeout(2), &
file="out_modes_2.csv")
open(newunit=self%modeout(3), &
file="out_modes_3.csv")
open(newunit=self%modeout(4), &
file="out_modes_4.csv")
end if
if (present(ICs) .and. ICs) then
open(newunit=self%outsamp,&
file="out_ic_eqen.csv")
open(newunit=self%outsamp_N_iso,&
file="out_ic_isoN.csv")
end if
if (present(SR) .and. SR) then
open(newunit=self%outsamp_SR,&
file="out_ic_eqen_SR.csv")
open(newunit=self%outsamp_N_iso_SR,&
file="out_ic_isoN_SR.csv")
end if
end subroutine output_file_open
!Close output files
subroutine output_file_close(self,ICs,SR)
class(print_options) :: self
logical, intent(in), optional :: ICs, SR
if (self%save_traj) &
close(self%trajout)
if (self%spectra) &
close(self%spectraout)
if (self%fields_horiz) &
close(self%fields_h_out)
if (self%fields_end_infl) &
close(self%fields_end_out)
if (self%modes) then
close(self%modeout(1))
close(self%modeout(2))
close(self%modeout(3))
close(self%modeout(4))
end if
if (present(ICs) .and. ICs) then
close(self%outsamp)
close(self%outsamp_N_iso)
end if
if (present(SR) .and. SR) then
close(self%outsamp_SR)
close(self%outsamp_N_iso_SR)
end if
end subroutine output_file_close
subroutine make_formatting(self, num_inflaton)
class(print_options) :: self
integer, intent(in) :: num_inflaton
write(self%ci, '(I2)'), num_inflaton
self%ci = adjustl(self%ci)
self%array_fmt = '(a25,'//trim(self%ci)//'es10.3)'
end subroutine make_formatting
end module modpk_io