; --------------------------------------------------------------------------------
;
; @singlecrystal
;
;
; Data reduction for single crystals.
; Output the data in .spe format for use with , e.g., mSlice
; or Homer suite.
;
; Essentially no corrections on the data ( no empty substraction
; and no energy detector efficiency corrections - rather of low interest
; for low temperature inelastic scattering on the Stokes side)
;
;
;
; Reduction of the data size (745Mb) since run an out of memory
; with this data size- to ~ 200Mb only.
;
;
;
; Last revised: JOR (ollivier@ill.eu) Mon Aug 31 14:42:58 CEST 2009
; --------------------------------------------------------------------------------
rdset, base="Current Cycle"
; --------------------------------------------------------------------------------
; b and e must be defined as the first and last run to add
; in the spectrum.
; Can be defined here or anywhere else under lamp (global variable)
; --------------------------------------------------------------------------------
; b = 64215
; e = 64220
; --------------------------------------------------------------------------------
; 0) Define the graining ratio [f, g, h] = [E, Phi, Z]
; --------------------------------------------------------------------------------
f = 1
g = 2
h = 2
; --------------------------------------------------------------------------------
; 1) Load the data:
;
; 1 run rdrun, 1.2) if more than one run: rdsum
; Wed Dec 10 18:13:33 CET 2008: Normalise works fine now after rdsum
; (data since Tuesday dec 09 2008)
; --------------------------------------------------------------------------------
print, "FULL3D: Load No ",strtrim(b,2)," to ",strtrim(e,2)," ..."
; --------------------------------------------------------------------------------
if e eq b then w1 = rdrun(b) else w1 = rdsum(b,e)
; --------------------------------------------------------------------------------
; 1) Correction for the distance (average = 4.0 m)
; --------------------------------------------------------------------------------
w1 = in5_distanceCorrection(w1, /verbose)
; --------------------------------------------------------------------------------
; 2) Vanadium normalisation
; --------------------------------------------------------------------------------
w1 = in5_normalise(w1, /verbose)
; --------------------------------------------------------------------------------
; 3) Regularise scattering angles Phi
; not requested for single Xtals
; --------------------------------------------------------------------------------
; w2 = regularise(w1, /verbose)
; --------------------------------------------------------------------------------
; 4) Transforme in energy
; in: [Phi,z,ToF] ---> out: [E,Phi,z]
; --------------------------------------------------------------------------------
w3 = in5_t2epsd(w2, /verbose)
; --------------------------------------------------------------------------------
; 5) Reduce the energy scale to the useful one
; in order to have an integer divisor for the rebin, use this:
; (240 channels in Z instead of 241)
; --------------------------------------------------------------------------------
i = where(x3 gt -1.0)
w4 = w3(i,*,1:*) & e4 = e3(i,*,1:*)
x4 = x3(i)
z4 = z3(1:*)
; --------------------------------------------------------------------------------
; 4) Rebin the data
; To use the rebin function , numbers of elements should be an interger
; ratio.
; WARNING: congrid doesn't average properly: statistics is not conserved but
; rebin do.
; --------------------------------------------------------------------------------
s = size(w4)
w5 = rebin(w4, s(1)/f,s(2)/g,s(3)/h)
e5 = rebin(e4, s(1)/f,s(2)/g,s(3)/h)
; x5 = rebin(x4,s(1)/f) ; unusefull
y5 = rebin(y4,s(2)/g)
z5 = rebin(z4,s(3)/h)
s = size(w5)
; --------------------------------------------------------------------------------
; 5) Save the data and create the phx file accordingly
; --------------------------------------------------------------------------------
c = 'sqw_'+strtrim(string(b),2)+'_'+strtrim(string(e),2)+'_'+strtrim(string(s(1)),2)+'_'+strtrim(string(s(2)),2)+'_'+strtrim(string(s(3)),2)
in5_outputspe, w5, file=c, /phx, /verbose
; --------------------------------------------------------------------------------
; Gzip the files to spare space (must be unzipped for use with mSlice)
; --------------------------------------------------------------------------------
; spawn,"gzip "+c+".spe"