; --------------------------------------------------------------------------------
;
; @reduce
;
; Reduce data from IN5.
; Does (shoud do) everything from raw data to S(2theta,ToF)
;
;
; b must contain the first run
; e must contain the last run
;
; output are:
;
; w4 is Debye-Scherrer cones in ToF
; w5 is Debye-Scherrer cones in en energy
; file in ToF stored in hdf format
;
;
; IDL>> cat tocompile
;
;
; For debyescherrer data must be in order [phi,Z,ToF]
; phi = scattering angles
; Z = detector height
; ToF = time of fligth channels
;
;
; Fri Nov 7 08:44:17 CEST 2008
; --------------------------------------------------------------------------------
;
; --------------------------------------------------------------------------------
; 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, "REDUCE: Load No ",strtrim(b,2)," to ",strtrim(e,2)," ..."
; --------------------------------------------------------------------------------
if e eq b then w1 = rdrun(b) else w1 = rdsum(b,e)
; --------------------------------------------------------------------------------
; 2) Correction for the distance (average = 4.0 m)
; --------------------------------------------------------------------------------
w1 = in5_distancecorrection(w1, /verbose)
; --------------------------------------------------------------------------------
; 3) Normalise to monitor
; --------------------------------------------------------------------------------
w1 = in5_normalise(w1, /verbose)
; --------------------------------------------------------------------------------
; Reduce the data range in Z
;
; only when required (usually not for a powder)
;
; --------------------------------------------------------------------------------
; w1 = w1(*,110:130,*)
; --------------------------------------------------------------------------------
; 4) Regularise scattering angles Phi
; --------------------------------------------------------------------------------
w2 = in5_regularise(w1, /verbose)
; --------------------------------------------------------------------------------
; 5) Group in Debye-Scherrer cones
; --------------------------------------------------------------------------------
w3 = in5_debyescherrer(w2, distance=400.0, /verbose)
; --------------------------------------------------------------------------------
; 6) Rotate in order [ToF, Phi]
; And remove -1 from the transformed data ( -1 where no data in (i,j) )
; Transformation a bit simpler than reality: at least normalise
; by the number of active cells summed.
; Total n'est correct que si on a meme nombre de chiffres dans les
; columns.
; --------------------------------------------------------------------------------
w4 = transpose(total(w3>0.0,2))
w4 = reverse(w4,2) & y4=reverse(y4)
x4 = z3
e4 = transpose( sqrt( total( e3^2 > 0.0,2) ) ) & e4 = reverse(e4,2)
print, "REDUCE: ToF data in w4"
x_tit(4)='Tof channels'
y_tit(4)='Scattering angles [deg]'
; --------------------------------------------------------------------------------
; 6b) Store resulting S(2Theta, ToF) in the most conservative NeXuS format
; --------------------------------------------------------------------------------
c = "run_"+strtrim(b,2)+"_"+strtrim(e,2)+"_ToF"
print, "REDUCE: Store ToF data in ",c
; --------------------------------------------------------------------------------
WRITE_LAMP,c,w=4,format="hdf"
spawn,"mv "+c+"_LAMP.hdf "+c+".hdf"