-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpypowder.for
393 lines (370 loc) · 11.2 KB
/
pypowder.for
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
Subroutine PYPSVFCJ(NPTS,DTT,TTHETA,CDSIG,CDGAM,SPH,PRFUNC)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C CDSIG Gaussian variance,centidegrees squared
C CDGAM Lorenzian FWHM, centidegrees
C RETURNS FUNCTION ONLY
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) CDSIG
Cf2py intent(in) CDGAM
Cf2py intent(in) SPH
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
REAL*4 DTT(0:NPTS-1),PRFUNC(0:NPTS-1)
REAL*4 TTHETA,SIG,CDSIG,CDGAM,SPH,DPRDT,DPRDG,DPRDD,DPRDLZ,DPRDS
REAL*4 GAM
INTEGER*4 NPTS,I
C CDSIG is in centidegrees squared, we must change to normal degrees
SIG = CDSIG/10000.0
GAM = CDGAM/100.0
DO I=0,NPTS-1
CALL GET_PROF_VAL(SIG,GAM,SPH,0.0,DTT(I)+TTHETA,TTHETA,DPRDT,
1 DPRDG,DPRDD,DPRDS,DPRDLZ,PRFUNC(I))
PRFUNC(I)=PRFUNC(I)/100. !Calling code expects peak normalised in centidegrees
END DO
RETURN
END
SUBROUTINE PYDPSVFCJ(NPTS,DTT,TTHETA,CDSIG,CDGAM,SPH,PRFUNC,
1 DPRDT,SIGPART,GAMPART,SLPART)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C RETURNS FUNCTION & DERIVATIVES
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) CDSIG
Cf2py intent(in) CDGAM
Cf2py intent(in) SPH
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
Cf2py intent(out) DPRDT
Cf2py depend(NPTS) DPRDT
Cf2py intent(out) SIGPART
Cf2py depend(NPTS) SIGPART
Cf2py intent(out) GAMPART
Cf2py depend(NPTS) GAMPART
Cf2py intent(out) SLPART
Cf2py depend(NPTS) SLPART
INTEGER*4 NPTS,I
REAL*4 TTHETA,CDSIG,SIG,CDGAM,SPH,LPART
REAL*4 GAM
REAL*4 DTT(0:NPTS-1),DPRDT(0:NPTS-1),SIGPART(0:NPTS-1)
REAL*4 GAMPART(0:NPTS-1),SLPART(0:NPTS-1),PRFUNC(0:NPTS-1)
SIG = CDSIG/10000.
GAM = CDGAM/100.
DO I=0,NPTS-1
CALL GET_PROF_VAL(SIG,GAM,SPH,0.0,DTT(I)+TTHETA,TTHETA,
1 DPRDT(I),SIGPART(I),GAMPART(I),SLPART(I),LPART, PRFUNC(I))
! Calling code expects all values to be for a peak normalised in centidegrees
SIGPART(I)=SIGPART(I)/1.0e6
GAMPART(I)=GAMPART(I)/1.0e4
SLPART(I)=SLPART(I)/100.
PRFUNC(I)=PRFUNC(I)/100.
DPRDT(I)=DPRDT(I)/100.
END DO
RETURN
END
SUBROUTINE PYPSVOIGT(NPTS,DTT,SIG,GAM,PRFUNC)
C DTT in degrees
C RETURNS FUNCTION ONLY
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
REAL*4 DTT(0:NPTS-1),PRFUNC(0:NPTS-1)
REAL*4 SIG,GAM
INTEGER*4 NPTS,I
DO I=0,NPTS-1
CALL PSVOIGT(DTT(I)*100.,SIG,GAM,
1 PRFUNC(I),DPRDT,SIGPART,GAMPART)
END DO
RETURN
END
SUBROUTINE PYDPSVOIGT(NPTS,DTT,SIG,GAM,PRFUNC,
1 DPRDT,SIGPART,GAMPART)
C DTT in degrees
C RETURNS FUNCTION & DERIVATIVES
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
Cf2py intent(out) DPRDT
Cf2py depend(NPTS) DPRDT
Cf2py intent(out) SIGPART
Cf2py depend(NPTS) SIGPART
Cf2py intent(out) GAMPART
Cf2py depend(NPTS) GAMPART
INTEGER*4 NPTS
REAL*4 SIG,GAM
REAL*4 DTT(0:NPTS-1),DPRDT(0:NPTS-1),SIGPART(0:NPTS-1),
1 GAMPART(0:NPTS-1),PRFUNC(0:NPTS-1)
DO I=0,NPTS-1
CALL PSVOIGT(DTT(I)*100.,SIG,GAM,
1 PRFUNC(I),DPRDT(I),SIGPART(I),GAMPART(I))
DPRDT(I) = DPRDT(I)*100.
END DO
RETURN
END
SUBROUTINE PYPSVFCJO(NPTS,DTT,TTHETA,SIG,GAM,SPH,PRFUNC)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C RETURNS FUNCTION ONLY
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(in) SPH
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
INTEGER*4 NPTS
REAL*4 TTHETA,SIG,GAM,SPH
REAL*4 DTT(0:NPTS-1),PRFUNC(0:NPTS-1)
DO I=0,NPTS-1
CALL PSVFCJO(DTT(I)*100.,TTHETA*100.,SIG,GAM,SPH/2.0,SPH/2.0,
1 PRFUNC(I),DPRDT,SIGPART,GAMPART,SLPART,HLPART)
END DO
RETURN
END
SUBROUTINE PYDPSVFCJO(NPTS,DTT,TTHETA,SIG,GAM,SPH,PRFUNC,
1 DPRDT,SIGPART,GAMPART,SLPART)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C RETURNS FUNCTION & DERIVATIVES
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(in) SPH
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
Cf2py intent(out) DPRDT
Cf2py depend(NPTS) DPRDT
Cf2py intent(out) SIGPART
Cf2py depend(NPTS) SIGPART
Cf2py intent(out) GAMPART
Cf2py depend(NPTS) GAMPART
Cf2py intent(out) SLPART
Cf2py depend(NPTS) SLPART
INTEGER*4 NPTS
REAL*4 TTHETA,SIG,GAM,SPH
REAL*4 DTT(0:NPTS-1),DPRDT(0:NPTS-1),SIGPART(0:NPTS-1),
1 GAMPART(0:NPTS-1),SLPART(0:NPTS-1),PRFUNC(0:NPTS-1)
DO I=0,NPTS-1
CALL PSVFCJO(DTT(I)*100.,TTHETA*100.,SIG,GAM,SPH/2.,SPH/2.,
1 PRFUNC(I),DPRDT(I),SIGPART(I),GAMPART(I),SPART,HPART)
SLPART(I) = SPART
DPRDT(I) = DPRDT(I)*100.
END DO
RETURN
END
SUBROUTINE PYPSVFCJEXPO(NPTS,DTT,TTHETA,ALP,BET,SIG,GAM,
1 SPH,PRFUNC)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C RETURNS FUNCTION ONLY
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) ALP
Cf2py intent(in) BET
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(in) SPH
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
INTEGER*4 NPTS
REAL*4 TTHETA,ALP,BET,SIG,GAM,SPH,PFUNC
REAL*4 DTT(0:NPTS-1),PRFUNC(0:NPTS-1),DPRDT,ALPART,BEPART,SIGPART
1 GAMPART,SLPART,HLPART
DO I=0,NPTS-1
CALL PSVFCJEXPO(DTT(I),TTHETA,ALP,BET,SIG/1.e4,GAM/100.,SPH/2.0,
1 SPH/2.0,PFUNC,DPRDT,ALPART,BEPART,SIGPART,GAMPART,
1 SLPART,HLPART)
PRFUNC(I) = PFUNC/100.
END DO
RETURN
END
SUBROUTINE PYDPSVFCJEXPO(NPTS,DTT,TTHETA,ALP,BET,SIG,GAM,SHL,
1 PRFUNC,DPRDT,ALPART,BEPART,SIGPART,GAMPART,SLPART)
C DTT in degrees
C TTHETA in degrees
C SPH is S/L + H/L
C RETURNS FUNCTION & DERIVATIVES
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) TTHETA
Cf2py intent(in) ALP
Cf2py intent(in) BET
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(in) SHL
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
Cf2py intent(out) DPRDT
Cf2py depend(NPTS) DPRDT
Cf2py intent(out) ALPART
Cf2py depend(NPTS) ALPART
Cf2py intent(out) BEPART
Cf2py depend(NPTS) BEPART
Cf2py intent(out) SIGPART
Cf2py depend(NPTS) SIGPART
Cf2py intent(out) GAMPART
Cf2py depend(NPTS) GAMPART
Cf2py intent(out) SLPART
Cf2py depend(NPTS) SLPART
INTEGER*4 NPTS
REAL*4 TTHETA,ALP,BET,SIG,GAM,SHL,HPART,SGPART,GAPART,PFUNC
REAL*4 DTT(0:NPTS-1),DPRDT(0:NPTS-1),ALPART(0:NPTS-1),
1 BEPART(0:NPTS-1),SIGPART(0:NPTS-1),GAMPART(0:NPTS-1),
1 SLPART(0:NPTS-1),PRFUNC(0:NPTS-1),APART,BPART,DPDT
DO I=0,NPTS-1
CALL PSVFCJEXPO(DTT(I),TTHETA,ALP,BET,SIG/1.e4,GAM/100.,SHL/2.,
1 SHL/2.,PFUNC,DPDT,APART,BPART,SGPART,
1 GAPART,SPART,HPART)
PRFUNC(I) = PFUNC/100.
ALPART(I) = APART/100.
BEPART(I) = BPART/100.
SIGPART(I) = SGPART/1.E6
GAMPART(I) = GAPART/1.E4
SLPART(I) = SPART/100.
DPRDT(I) = DPDT/100.
END DO
RETURN
END
SUBROUTINE PYEPSVOIGT(NPTS,DTT,ALP,BET,SIG,GAM,PRFUNC)
C DTT in microsec
C RETURNS FUNCTION
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) ALP
Cf2py intent(in) BET
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
INTEGER*4 NPTS
REAL*4 ALP,BET,SIG,GAM,SHL
REAL*4 DTT(0:NPTS-1),PRFUNC(0:NPTS-1),DPRDT,ALPPART,
1 BETPART,SIGPART,GAMPART
DO I=0,NPTS-1
CALL EPSVOIGT(DTT(I),ALP,BET,SIG,GAM,PRFUNC(I),DPRDT,
1 ALPPART,BETPART,SIGPART,GAMPART)
END DO
RETURN
END
SUBROUTINE PYDEPSVOIGT(NPTS,DTT,ALP,BET,SIG,GAM,PRFUNC,
1 DPRDT,ALPPART,BETPART,SIGPART,GAMPART)
C DTT in microsec
C RETURNS FUNCTION & DERIVATIVES
Cf2py intent(in) NPTS
Cf2py intent(in) DTT
Cf2py depend(NPTS) DTT
Cf2py intent(in) ALP
Cf2py intent(in) BET
Cf2py intent(in) SIG
Cf2py intent(in) GAM
Cf2py intent(out) PRFUNC
Cf2py depend(NPTS) PRFUNC
Cf2py intent(out) DPRDT
Cf2py depend(NPTS) DPRDT
Cf2py intent(out) ALPPART
Cf2py depend(NPTS) ALPPART
Cf2py intent(out) BETPART
Cf2py depend(NPTS) BETPART
Cf2py intent(out) SIGPART
Cf2py depend(NPTS) SIGPART
Cf2py intent(out) GAMPART
Cf2py depend(NPTS) GAMPART
INTEGER*4 NPTS
REAL*4 ALP,BET,SIG,GAM,SHL
REAL*4 DTT(0:NPTS-1),DPRDT(0:NPTS-1),ALPPART(0:NPTS-1),
1 BETPART(0:NPTS-1),SIGPART(0:NPTS-1),
1 GAMPART(0:NPTS-1),PRFUNC(0:NPTS-1)
DO I=0,NPTS-1
CALL EPSVOIGT(DTT(I),ALP,BET,SIG,GAM,PRFUNC(I),DPRDT(I),
1 ALPPART(I),BETPART(I),SIGPART(I),GAMPART(I))
END DO
RETURN
END
C python interface to gauleg
SUBROUTINE PYGAULEG(X1,X2,N,GL,WT)
Cf2py intent(in) X1
Cf2py intent(in) X2
Cf2py intent(in) N
Cf2py intent(out) GL
Cf2py depend(N) GL
Cf2py intent(out) WT
Cf2py depends(N) WT
INTEGER*4 N
REAL*4 X1,X2,GL(0:N-1),WT(0:N-1)
CALL GAULEG(X1,X2,GL,WT,N)
RETURN
END
C Fortran (fast) linear interpolation -- B.H. Toby 9/2011
SUBROUTINE PYFINTERP(NIN,XIN,YIN,NOUT,XOUT,YOUT)
C XIN(1:NIN) and YIN(1:NIN) are arrays of (x,y) points to be interpolated
C Values must be sorted increasing in XIN
C XOUT(1:NOUT) is an array of x values, must also be sorted increasing in x
C XOUT may contain values smaller than XIN(1) or larger than XIN(NIN)
C RETURNS interpolated y values corresponding to XOUT. Values outside the
C range of XIN are set to zero.
C Needs a way to signal an error if XIN or XOUT is not sorted -- for now stops
Cf2py intent(in) NIN
Cf2py intent(in) XIN
Cf2py depend(NIN) XIN
Cf2py intent(in) YIN
Cf2py depend(NIN) YIN
Cf2py intent(in) NOUT
Cf2py intent(in) XOUT
Cf2py depend(NOUT) XOUT
Cf2py intent(out) YOUT
Cf2py depend(NOUT) YOUT
INTEGER NIN,NOUT
REAL XIN(NIN),YIN(NIN)
REAL XOUT(NOUT),YOUT(NOUT)
INTEGER IERROR
REAL X,F
INTEGER IIN,I
IERROR = 1
IIN = 1
X = XOUT(1)
DO I=1,NOUT
IF (X .GT. XOUT(I)) STOP ! test if Xout not sorted
X = XOUT(I)
IF (X .LT. XIN(1) .OR. X .GT. XIN(NIN) ) THEN
YOUT(I) = 0.0
ELSE
DO WHILE (X .GT. XIN(IIN+1))
IF (XIN(IIN) .GT. XIN(IIN+1)) STOP ! test if Xin not sorted
IIN = IIN + 1
ENDDO
F = (X - XIN(IIN)) / (XIN(IIN+1) - XIN(IIN))
YOUT(I) = (1.-F)*YIN(IIN) + F*YIN(IIN+1)
ENDIF
!write (*,*) xout(i),iin,f,yout(i)
END DO
IERROR = 0
RETURN
END