-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmod_io.f90
316 lines (221 loc) · 9.67 KB
/
mod_io.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
MODULE Mod_IO
!############################################################################
!# This section contains the IO routines for Aura
!############################################################################
!### Modules to be Included ###
USE Mod_Emis
USE Mod_Info
IMPLICIT NONE
CONTAINS
!### This routine will output the results to text files. ###
!### Current output units are j=[ergs/cm^3/s/Hz/str], n=[particles/cm^3/s/erg] ###
SUBROUTINE IO_Emis(emiso,info)
TYPE(Emis), INTENT(IN) :: emiso
TYPE(Infoc), INTENT(IN) :: info
INTEGER i
CHARACTER*20 ofile
!### Synchrotron ###
if (emiso%synco%synchrotron) then
if (info%verbose) write(*,*) 'Writing Synchrotron Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A8)') info%oroot, 'sync.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%nphbins
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%synco%j(i),1d-100))
enddo
CLOSE(12)
endif
!### IC ###
if (emiso%ico%ic) then
if (info%verbose) write(*,*) 'Writing IC Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A6)') info%oroot, 'ic.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%nphbins
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%ico%j(i),1d-100))
enddo
CLOSE(12)
endif
!### Bremsstrahlung ###
if (emiso%bremo%bremsstrahlung) then
if (info%verbose) write(*,*) 'Writing Bremsstrahlung Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A8)') info%oroot, 'brem.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%nphbins
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%bremo%j(i),1d-100))
enddo
CLOSE(12)
endif
!### Proton-Proton Interactions ###
if (emiso%ppo%pp) then
if (info%verbose) write(*,*) 'Writing Proton-Proton Interaction Data'
!### Gamma Rays ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A7)') info%oroot, 'ppg.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%nphbins
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%ppo%j(i),1d-100))
enddo
CLOSE(12)
!### Electrons ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A7)') info%oroot, 'ppe.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%eo%e(i)), log10(MAX(emiso%ppo%eo%n(i),1d-100))
enddo
CLOSE(12)
!### Electron Neutrinos ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A9)') info%oroot, 'ppnue.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%ecr(i)), log10(MAX(emiso%ppo%nue(i),1d-100))
enddo
CLOSE(12)
!### Muon Neutrinos ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A9)') info%oroot, 'ppnum.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%ecr(i)), log10(MAX(emiso%ppo%num(i),1d-100))
enddo
CLOSE(12)
endif
END SUBROUTINE IO_Emis
!### Testing Routines ###
!### This routine contains useful formulas for testing and will output the results to text files. ###
SUBROUTINE IO_EmisTest(emiso,info)
TYPE(Emis), INTENT(IN) :: emiso
TYPE(Infoc), INTENT(IN) :: info
REAL*8 k, p, a, j, T, nion, sigma, delta
INTEGER i
CHARACTER*20 ofile
!### Synchrotron ###
if (emiso%synco%synchrotron) then
if (info%verbose) write(*,*) 'Writing Synchrotron Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A8)') info%oroot, 'sync.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
!### For testing uses Eq. 4.59 from Blumenthal & Gould RMP 42 (1970) 237 ###
! p=2d0
! a=0.103d0
! k=4d0*info%physo%pi*info%physo%me*info%physo%c**2/(8d0*info%physo%pi/3d0)
do i=1,emiso%nphbins
!### For testing uses Eq. 4.59 from Blumenthal & Gould RMP 42 (1970) 237 ###
! j=4d0*info%physo%pi*k*info%physo%q**3*info%envo%B**((p+1d0)/2d0)/(info%physo%me*info%physo%c**2) &
! *(3d0*info%physo%q/(4d0*info%physo%pi*info%physo%me*info%physo%c))**((p-1d0)/2d0)*a*emiso%nuph(i)**(-(p-1d0)/2d0)
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%synco%j(i),1d-100))!, log10(j)
enddo
CLOSE(12)
endif
!### IC ###
if (emiso%ico%ic) then
if (info%verbose) write(*,*) 'Writing IC Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A6)') info%oroot, 'ic.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
!### For testing uses Eq. 2.65 from Blumenthal & Gould RMP 42 (1970) 237 ###
! p=2d0
! a=5.25d0
! k=info%physo%me*info%physo%c**2/(4d0*info%physo%pi)*info%physo%h
! T=2.73d0
do i=1,emiso%nphbins
!### For testing uses Eq. 2.65 from Blumenthal & Gould RMP 42 (1970) 237 ###
! j=1d0/info%physo%pi*(info%physo%r0**2*(2d0*info%physo%pi)**3/(info%physo%h**3*info%physo%c**2)) &
! *k*(info%physo%kb*T)**((p+5d0)/2d0)*a*(info%physo%h*emiso%nuph(i))**(-(p-1d0)/2d0)
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%ico%j(i),1d-100))!, log10(j)
enddo
CLOSE(12)
endif
!### Bremsstrahlung ###
if (emiso%bremo%bremsstrahlung) then
if (info%verbose) write(*,*) 'Writing Bremsstrahlung Data'
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A8)') info%oroot, 'brem.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
!### For testing uses Eq. 3.59 in the weak shielding limit from Blumenthal & Gould RMP 42 (1970) 237 ###
! p=2d0
! a=info%physo%h/(4d0*info%physo%pi)!info%physo%me*info%physo%c**2/(4d0*info%physo%pi)
! nion=info%envo%ne+info%envo%np
do i=1,emiso%nphbins
!### For testing uses Eq. 3.59 in the weak shielding limit from Blumenthal & Gould RMP 42 (1970) 237 ###
!### Weak Shielding (fully ionized case) ###
! k=info%physo%h*emiso%nuph(i)/(info%physo%me*info%physo%c**2)
!
! if (k .LT. info%cro%g(1)) then
! j=info%physo%alpha*info%physo%r0**2*info%physo%c*a/k*nion &
! *(4d0/3d0*info%cro%g(1)**(-(p-1d0))/(p-1d0)-4d0/3d0*k*info%cro%g(1)**(-p)/p+k**2*info%cro%g(1)**(-(p+1d0))/(p+1d0)) &
! *4d0*(dlog(2d0*info%cro%g(1)*(info%cro%g(1)-k)/k)-0.5d0)*info%physo%h*emiso%nuph(i)
! else
! j=info%physo%alpha*info%physo%r0**2*info%physo%c*a/k*nion &
! *(4d0/3d0*info%cro%g(1)**(-(p-1d0))/(p-1d0)-4d0/3d0*k*info%cro%g(1)**(-p)/p+k**2*info%cro%g(1)**(-(p+1d0))/(p+1d0)) &
! *4d0*(dlog(4d0*k)-0.5d0)*info%physo%h*emiso%nuph(i)
! endif
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%bremo%j(i),1d-100))!, log10(j)
enddo
CLOSE(12)
endif
!### Proton-Proton Interactions ###
if (emiso%ppo%pp) then
if (info%verbose) write(*,*) 'Writing Proton-Proton Interaction Data'
!### Gamma Rays ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A7)') info%oroot, 'ppg.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
!### For Testing using Eq. 23 from Edmon et.al. MNRAS 414 (2011) 3521 ###
! p=2d0
! a=info%physo%h/(4d0*info%physo%pi)*(info%physo%mp*info%physo%c**2)**(p-1d0)
! nion=info%envo%np+info%envo%nH
! delta=0.14d0*p**(-1.6d0)+0.44d0
! sigma=3.2d-26*(0.96d0+dexp(4.4d0-2.4*p))
do i=1,emiso%nphbins
!### For Testing using Eq. 23 from Edmon et.al. MNRAS 414 (2011) 3521 ###
! j=a*nion*sigma*info%physo%c/(info%physo%mp*info%physo%c**2)*2d0**(2d0-p)*4d0/(3d0*p)*(info%physo%mpi0/info%physo%mp)**(-p) &
! *((2d0*info%physo%h*emiso%nuph(i)/(info%physo%mpi0*info%physo%c**2))**delta &
! +(2d0*info%physo%h*emiso%nuph(i)/(info%physo%mpi0*info%physo%c**2))**(-delta))**(-p/delta)*info%physo%h*emiso%nuph(i)
write(12,*) log10(emiso%nuph(i)), log10(MAX(emiso%ppo%j(i),1d-100))!, log10(MAX(j,1d-100))
enddo
CLOSE(12)
!### Electrons ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A7)') info%oroot, 'ppe.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%eo%e(i)), log10(MAX(emiso%ppo%eo%n(i),1d-100))
enddo
CLOSE(12)
!### Electron Neutrinos ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A9)') info%oroot, 'ppnue.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%ecr(i)), log10(MAX(emiso%ppo%nue(i),1d-100))
enddo
CLOSE(12)
!### Muon Neutrinos ###
!### define the file we'll write to ###
WRITE(ofile, '(A5, "_", A9)') info%oroot, 'ppnum.dat'
!### Open and write to file ###
OPEN(UNIT=12, FILE=ofile, DEFAULTFILE=info%odump_path, FORM="FORMATTED", STATUS="UNKNOWN")
do i=1,emiso%ppo%ncrbins
write(12,*) log10(emiso%ppo%ecr(i)), log10(MAX(emiso%ppo%num(i),1d-100))
enddo
CLOSE(12)
endif
END SUBROUTINE IO_EmisTest
END MODULE Mod_IO