-
Notifications
You must be signed in to change notification settings - Fork 2
/
diff_pat.f90
485 lines (436 loc) · 16.7 KB
/
diff_pat.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
!C
!C This program calculates the diffraction pattern of a crystal.
!C
!C
!C MSR/94/03/25 first version hacked from Shadow code
!C MSR/97/10/07 Adapts for xop 1.9 (embedded version)
!C MSR/00/06/13 Adapts for xop 1.0
!C renamed from diff_pattern to diff_pat
!C MSR/08/09/05 Updated TOCM,TOANGS
!C Changed by Eric.Lebigot@normalesup.org
!C MSR/09/04/14 Updated TOCM,TOANGS everywhere.
!C srio@esrf.eu 2011-08-18 Ported to f90. Lots of modifications.
!C
!C 2012-12-07 srio@esrf.eu
!C Added Bent crystal models. Work done with Nicolas Perez-Bocanegra
!C Xianbo Shi and Veijo Honkimaki
!C 2014-01-22 srio@esrf.eu New cleaning.
!C
PROGRAM diff_pat
use shadow_globaldefinitions
use stringio
use shadow_math, only: dot, norm , cross !, rotvector
use elasticity
use crystal3
implicit none
integer(kind=ski):: scan_mode,scanunit,scanpoints,i
real(kind=skr) :: phot,q_phot
real(kind=skr) :: r_s, r_p,phase_s, phase_p, depht_mfp_s
real(kind=skr) :: theta_b, depht_mfp_p
real(kind=skr) :: scanmin,scanmax,scanstep,theta_energy,graze,graze0
real(kind=skr) :: scanval,scanval2
real(kind=skr) :: sin_ref,theta_b_ref,scanval_ref,graze_ref
real(kind=skr) :: tmp
real(kind=skr) :: a_braggDeg
Real(kind=skr) :: inp_flag,bent_phot,bent_geo,bent_rm,bent_rs, bent_method
Real(kind=skr) :: bent_alph, bent_thick, bent_ymax, bent_ymin, bent_dy0
Integer :: ierror,itmp
character(len=sklen) ::ans
!vectors
real(kind=skr),dimension(3) :: vvin, vvout, bh, bh0, vnor, axis
real(kind=skr),dimension(3) :: vin_bragg,vin_bragg_uncorr
real(kind=skr),dimension(3) :: vpar, vin_bragg_energy, vtmp
type(oeSetup) :: oe1
integer(kind=ski):: iplotangles=0 !plot angles with gle
!debug variables
real(kind=skr) :: gamma_0,gamma_h
integer(kind=ski):: i_debug= 0 !11 !debug: set the flag to the fort unit
!C
!C Version number also in another place!!!!!!
!C
write(6,*) ' '
write(6,*) ' '
write(6,*) ' '
write(6,*) '*****************************************************'
write(6,*) '* DIFF_PAT v1.8 (18 Oct 2016) *'
write(6,*) '*Calculation of a single crystal diffraction profile*'
write(6,*) '* *'
write(6,*) '*****************************************************'
write(6,*) ' '
oe1%file_refl = rstring(' Name of file with crystal data (from BRAGG): ')
!C
!C Inquires about perfect or mosaic crystal
!C
write (6,*) 'What kind of crystal you want to use ?: '
write (6,*) ' [0] Perfect crystal '
write (6,*) ' [1] Mosaic crystal '
Write (6,*) ' [2] Bent Multilamellar (ML)'
Write (6,*) ' [3] Bent Penning-Polder (PP)'
! Write (6,*) ' [4] Bent Takagi-Taupin'
oe1%f_mosaic = irint(' <?> ')
!C
!C Inquires about Reflection (Bragg) or Transmission (Laue) geometry.
!C If the crystal is perfect we also allow to calculate the transmitted
!C (not diffracted beams.
!C
write (6,*) 'What do you want to calculate ?: '
if (oe1%f_mosaic.eq.0) then
write (6,*) '[0] Diffracted beam in Reflection (Bragg) geometry'
write (6,*) '[1] Diffracted beam in Transmission (Laue) geometry'
write (6,*) '[2] Transmitted beam in Bragg case'
write (6,*) '[3] Transmitted beam in Laue case'
else if (oe1%f_mosaic.gt.0) then
write (6,*) '[0] Diffracted beam in Reflection (Bragg) geometry'
write (6,*) '[1] Diffracted beam in Transmission (Laue) geometry'
endif
oe1%f_refrac = irint(' <?> ')
!C
!C Inquires about mosaic crystal values.
!C
if (oe1%f_mosaic.eq.1) then
oe1%spread_mos = RNUMBER('mosaic angle spread (FWHM) [deg] ? ')
oe1%spread_mos = torad*oe1%spread_mos/2.35
else
oe1%spread_mos = 0.0d0
end if
!C
!C Inquires crystal Thickness. In the Perfect crystal case, we allow
!C to use the thick crystal approximation. In such case, the user must
!C input any negative value.
!C
WRITE(6,*) 'Input the thickness of the crystal [cm] '
if (oe1%f_mosaic.eq.0) then
write(6,*) ' [Type a negative value for using the thick crystal approximation] '
endif
oe1%thickness = RNUMBER(' <?> ')
!C
!C Inquires about asymmetrical diffraction
!C
oe1%f_bragg_a = 0
IF (oe1%F_MOSAIC.NE.1) THEN
WRITE(6,*) 'Asymmetric cut angle (deg) between face and bragg planes (CW)= '
READ(*,*) A_BRAGGDEG
if (a_braggDeg.eq.0.0) then
oe1%f_bragg_a = 0
else
oe1%f_bragg_a = 1
endif
ELSE ! mosaic case
if (oe1%f_refrac.EQ.1) a_braggDeg = 90.0
if (oe1%f_refrac.EQ.0) a_braggDeg = 0.0
ENDIF
oe1%a_bragg = a_braggDeg*torad
if ((oe1%f_mosaic.eq.3).and.(oe1%f_refrac.eq.0) ) then
print*,'DIFF_PATT: Error in Bragg Geometry: Penning Polder method only for Laue'
print*,' ** aborting run **'
stop
endif
if ((oe1%f_mosaic.eq.3).and.(oe1%f_refrac.eq.2) ) then
print*,'DIFF_PATT: Error in Bragg Geometry: Penning Polder method only for Laue'
print*,' ** aborting run **'
stop
endif
!C
!C Inquires about the scanning variable
!C
write (6,*) 'Please select scanning variable: '
write (6,*) ' [1] Incident/Reflected angle [absolute] '
write (6,*) ' [2] Incident/Reflected angle minus theta Bragg corrected'
write (6,*) ' [3] Incident/Reflected angle minus theta Bragg'
write (6,*) ' [4] Photon energy '
write (6,*) ' [5] y variable [Zachariasen] '
!C
!C Call CRYSTAL to read the file with the crystal data (kwhat<0)
!C
call crystal(-1, oe1, & ! we only need thes inputs, the
! following ones are not used here.
q_phot, vvin, vvout, bh, vnor, &
r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p)
! , theta_b, ssr, spr)
! alternatively we can use:
!Call crystal_loadCrystalData (oe1%FILE_REFL,oe1%crystalData)
!C
!C Define scan mode (Theta or Energy)
!C
scan_mode = irint('<?> ')
if (scan_mode.lt.4) then
PHOT = RNUMBER ('... at what energy (eV) ? ')
Q_PHOT = PHOT*TWOPI/TOCM ! 2 pi / lambda
else if (scan_mode.eq.4) then
theta_energy = RNUMBER ('... at what grazing angle [deg]: ')
IF (theta_energy.LE.0) THEN
PHOT = -1.0D0*theta_energy
Q_PHOT = PHOT*TWOPI/TOCM ! 2 pi / lambda
theta_energy = 0
ELSE
theta_energy = theta_energy*torad
PHOT = 2.0D0*oe1%crystalData%D_SPACING*SIN(theta_energy) ! lambda (cm)
PHOT = TOCM/PHOT ! energy [eV]
Q_PHOT = PHOT*TWOPI/TOCM ! 2 pi / lambda
ENDIF
else if (scan_mode.eq.5) then
PHOT = RNUMBER ('... at what energy (eV) ? ')
Q_PHOT = PHOT*TWOPI/TOCM ! 2 pi / lambda
endif
!C
!C Call CRYSTAL to calculate useful parameters
!C
OPEN (23,FILE='diff_pat.par',STATUS='UNKNOWN')
REWIND (23)
! call crystal in set mode (kwhat=0)
call crystal(0, oe1, q_phot, vvin, vvout, bh, vnor, &
r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p)
!, theta_b, ssr, spr)
! moved ahead to include elasticity
!! call crystal in info mode (kwhat=1)
! call crystal (1, oe1, q_phot, vvin, vvout, bh, vnor, &
!r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p, theta_b, &
!ssr, spr)
!
! check for impossible geometry
!
if ((oe1%f_refrac.eq.0).or.(oe1%f_refrac.eq.2) ) then
if (abs(oe1%a_bragg).gt.abs(oe1%graze)) then
print*,'DIFF_PATT: WARNING in Bragg Geometry: Bragg angle is usually larger than asymmetry angle'
print*,' Bragg angle [deg]: ',oe1%graze*todeg
print*,' Asymmetry angle [deg]: ',oe1%a_bragg*todeg
!print*,' ** aborting run **'
!stop
endif
endif
if ((oe1%vin_bragg_uncorr(3).gt.0)) then
print*,'DIFF_PATT: WARNING in Geometry: incident beam is pointing outwards the cystal surface (0,0,1)'
endif
!!call plotgle(oe1%vin_bragg_uncorr,oe1%vout_bragg_uncorr,oe1%bh0,oe1,iplotangles)
graze0 = asin(pi/q_phot/oe1%crystalData%d_spacing)
graze = graze0 + oe1%a_bragg
graze_ref = graze0 - oe1%a_bragg
!C
!C Units for the scanning variable
!C
if (scan_mode.lt.4) then
write(6,*) 'Select units for the scanning variable (angle):'
write(6,*) '[0] radians'
write(6,*) '[1] microradians'
write(6,*) '[2] degrees'
write(6,*) '[3] arcsec'
scanunit = irint(' <?>')
endif
write(6,*) 'Input scanning variable limits in the chosen units.'
scanmin = rnumber('Minimum ? ')
scanmax = rnumber('Maximum ? ')
scanpoints = irint('Number of points ? ')
scanstep = (scanmax - scanmin) / (scanpoints - 1)
If(oe1%f_mosaic .gt. 1)then
Write(6,*)'Input sagittal bending radius [cm].'
READ(*,*) oe1%bent_rs
Write(6,*)'Input meridional radius [cm].'
READ(*,*) oe1%bent_rm
!Write(6,*)'Input Poisson Ratio.'
!READ(*,*) oe1%kstar
!todo: remove, bent_pol is not used.
!Write(6,*)'Polarisation factor:'
!Write(6,*)'[0] s'
!Write(6,*)'[1] p'
!Write(6,*)'[2] unpolarised'
tmp = irint(' <?>')
!
! elasticity inputs
!
call elasticity_prompt(oe1%crystalElasticity)
ENdIF
!
! elasticity calculations
!
If(oe1%f_mosaic .gt. 1)then
call elasticity_calc(oe1%crystalElasticity)
itmp = 6
call elasticity_report(oe1%crystalElasticity,itmp)
endif
! call crystal in info mode (kwhat=1)
WRITE(*,*) ' '
WRITE(*,*) 'So far, we are working with:'
call crystal(1, oe1, q_phot, vvin, vvout, bh, vnor, &
r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p)
!, theta_b, ssr, spr)
! make graphical sketches
call plotgle(oe1%vin_bragg_uncorr,oe1%vout_bragg_uncorr,oe1%bh0,oe1,iplotangles)
call plotidl(oe1%vin_bragg_uncorr,oe1%vout_bragg_uncorr,oe1%bh0)
!
!todo: rm these variables, make direct call
vnor = oe1%vnor
vpar = oe1%vpar
axis = oe1%axis
bh = oe1%bh
bh0 = oe1%bh0
vin_bragg = oe1%vin_bragg
vin_bragg_uncorr = oe1%vin_bragg_uncorr
vin_bragg_energy = oe1%vin_bragg_energy
vvout = oe1%vout_bragg
!------------------------------------------------------------------------------
!write(99,*) 'calling crystal with exact Bragg angle: '
!write(99,*) 'vin_bragg: ',vin_bragg
!write(99,*) 'vvout: ',vvout
call crystal (2, oe1, q_phot, vin_bragg, vvout, bh, vnor, &
r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p)
!, theta_b, ssr, spr)
!Write(99,*) 'reflectivities at y=0: ', r_s,r_p
!C
!C write output file
!C
OPEN (20,FILE='diff_pat.dat',STATUS='UNKNOWN')
REWIND (20)
write(20,'(a)') '#F diff_pat.dat'
write(20,'(a)') '#S 1 diff_pat run'
write(20,'(a)') '#C results of diff_pat run'
write(20,'(a)') '#N 7'
if (scan_mode.EQ.4) then
write(20,'(a)') '#L E[eV] Lambda[A] phase_p[rad] phase_s[rad] Circ Polariz p-polarized-profile s-polarized-profile'
else
if (scan_mode.eq.1) then
if (scanunit.eq.1) then
write(20,'(a)') '#L Theta{in} [microrad] Theta{out} [microrad] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.2) then
write(20,'(a)') '#L Theta{in} [deg] Theta{out} [deg] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.3) then
write(20,'(a)') '#L Theta{in} [arcsec] Theta{out} [arcsec] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
endif
else if (scan_mode.eq.2) then
if (scanunit.eq.1) then
write(20,'(a)') '#L Th-ThBc{in} [microrad] Th-ThBc{out} [microrad] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.2) then
write(20,'(a)') '#L Th-ThBc{in} [deg] Th-ThBc{out} [deg] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.3) then
write(20,'(a)') '#L Th-ThBc{in} [arcsec] Th-ThBc{out} [arcsec] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
endif
else if (scan_mode.eq.3) then
if (scanunit.eq.1) then
write(20,'(a)') '#L Th-ThB{in} [microrad] Th-ThB{out} [microrad] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.2) then
write(20,'(a)') '#L Th-ThB{in} [deg] Th-ThB{out} [deg] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
else if (scanunit.eq.3) then
write(20,'(a)') '#L Th-ThB{in} [arcsec] Th-ThB{out} [arcsec] phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
endif
else if (scan_mode.eq.5) then
write(20,'(a)') '#L y y phase_p[rad] phase_s[rad] Circ Polariz p-polarized s-polarized'
endif
endif
!C
!C
!C
do i=1,scanpoints !C main loop over the scanning points ===== starts ====
scanval = scanmin + scanstep*(i-1)
scanval2 = scanval
!C
!C convert user unit to shadow units (rads, eV)
!C
If(scan_mode.lt.4) then
if (scanunit.eq.1) then
scanval2 = scanval*1D-6
else if (scanunit.eq.2) then
scanval2 = (90+scanval)*torad
else if (scanunit.eq.3) then
scanval2 = scanval*torad/3600D0
else
scanval2 = scanval
end if
end IF
select case (scan_mode) !scanmode is case type
! minus sign in angle is to perform cw rotation when
! scanval increses
case (1) ! angle scan absolute
!call rotvector(vnor, axis, scanval2,vvin)
call rodrigues(vnor, axis, -scanval2,vvin)
Case(2) ! angle scan (theta-theta_B_corr)
!call rotvector(vin_bragg, axis, scanval2, vvin)
call rodrigues(vin_bragg, axis, -scanval2, vvin)
case(3) ! angle scan (theta-thetaBragg)
!call rotvector(vin_bragg_uncorr, axis, scanval2, vvin)
call rodrigues(vin_bragg_uncorr, axis, -scanval2, vvin)
case(4) ! energy scan
vvin = vin_bragg_energy
q_phot = scanval2*twopi/tocm
case(5) ! y scan
if ((oe1%f_refrac.eq.0).or.(oe1%f_refrac.eq.2)) then ! bragg
!TODO: check this minus sign!!!! DONE
call rodrigues(vin_bragg,axis,-scanval2*abs(oe1%ssr),vvin)
else ! laue
call rodrigues(vin_bragg,axis,scanval2*abs(oe1%ssr),vvin)
endif
end select
!C
!C calculate output direction
!C
call scat_direction(vvin,bh,vnor,q_phot,vvout)
call dot (vvout,vnor,sin_ref)
call dot (vvin,vnor,tmp)
!C
!C calculate reflectivity
!C
!C
!srio debugging
! write(99,*) ' '
! write(99,*) '---- '
! write(99,*) 'ssr: ',ssr
if (i_debug .ge. 1) then
Call dot (vnor,vvin,gamma_0)
Call dot (vnor,vvout,gamma_h)
write(11,*) ' '
write(11,*) '-----'
!note the change of sign because Zachariasen normal is pointing
!into the crystal, and we point outside.
write(i_debug,*) 'Zac gamma_0,gamma_h (diff_pat): ',-gamma_0,-gamma_h
write(11,*) 'scanval: ',scanval
endif
call crystal(2, oe1, q_phot, vvin, vvout, bh, vnor, &
r_s, r_p,phase_s, phase_p, depht_mfp_s, depht_mfp_p)
!, theta_b, ssr, spr)
!C
!C if asymmetric is selected, calculate and write down
!C the output angle
!C
if (oe1%f_bragg_a.EQ.1) then
call dot (vvout,vnor,sin_ref)
if (scan_mode.EQ.1) then
scanval_ref = asin(sin_ref)
else if (scan_mode.EQ.2) then
scanval_ref = - theta_b_ref + asin(sin_ref)
else if (scan_mode.EQ.3) then
scanval_ref = - graze_ref + asin(sin_ref)
else if (scan_mode.EQ.4) then
!C scanval_ref = scanval
else if (scan_mode.EQ.5) then
scanval_ref = scanval
endif
if (scanunit.eq.1) then
scanval_ref = scanval_ref/1D-6
else if (scanunit.eq.2) then
scanval_ref = scanval_ref/torad
else if (scanunit.eq.3) then
scanval_ref = scanval_ref/torad*3600D0
else
scanval_ref = scanval_ref
end if
else
scanval_ref = scanval
endif
if (scan_mode.EQ.4) scanval_ref = TOANGS/scanval
WRITE (20,'(7(g15.8,1x))') scanval,scanval_ref, &
phase_p,phase_s, r_p*r_s*sin(phase_p-phase_s), &
r_p**2,r_s**2
enddo !C main loop over the scanning points ===== ends ====
!C
!C close files and exit
!C
close(23)
close(20)
write (*,*) '>> '
write (*,*) '>> Files diff_pat.par (parameters) and '
if (scan_mode.EQ.4) then
write (*,*) '>> diff_pat.dat (E [eV],Lambda [A],...,p-pol,s-pol)'
else
write (*,*) '>> diff_pat.dat (Scan in,Scan out,...,p-pol,s-pol)'
endif
write (*,*) '>> written to disk.'
write (*,*) '>> '
END PROGRAM diff_pat