Commit bd9738fd authored by Gonzalez, Miguel's avatar Gonzalez, Miguel
Browse files

Modifications to improve the handling of Salsa files after 2014 (Issue 27)

parent e66b8d78
function salsa_combine_ws, wks_list
; get array with list of workspaces
wks_list = fix(strsplit(wks_list, ',', /extract))
nwks = n_elements(wks_list)
; first go through all workspaces, check that they are 3D (Salsa scans),
; and create list of unique Z parameters
zpar = []
for i = 0, nwks-1 do begin
take_w, wtmp, w = wks_list[i]
sz = size(wtmp)
if sz[0] ne 3 then begin
txterr = 'This routine operates only with 3D numors. Exiting!'
print, txterr
lamp_message, txterr
lamp_journal, txterr
return, 0
endif else begin
take_datp, pstruct, w = wks_list[i]
zpar = [zpar, pstruct.z]
endelse
endfor
; convert float values to integer (after multiplying by 1000) to search unique values
; z_out contains the output values, zcomp the values to compare (integers or strings)
if typename(zpar) eq 'FLOAT' then begin
zpar = fix(zpar*1000)
zcomp = zpar[uniq(zpar, sort(zpar))]
z_out = zpar[uniq(zpar, sort(zpar))] / 1000.
endif else begin
z_out = zpar[uniq(zpar, sort(zpar))]
zcomp = z_out
endelse
; set dimensions of output arrays
npts = n_elements(z_out)
w_out = fltarr(sz[1], sz[2], npts)
n_out = fltarr(1, 1, npts)
pv_out = fltarr(n_elements(pstruct.pv[*,0]), npts)
counter = intarr(npts)
; re-read all workspaces and sum them
for i = 0, nwks-1 do begin
take_w, wtmp, w = wks_list[i]
take_datp, pstruct, w = wks_list[i]
if i eq 0 then begin ; set non-scan variables from 1st workspace
x_out = pstruct.x
endif else begin ; check that 2-theta angles are the same for all workspaces
if n_elements(x_out) ne n_elements(pstruct.x) then begin
txterr = 'Different X dimensions. Exiting!'
print, txterr
lamp_message, txterr
lamp_journal, txterr
return, 0
endif
diff = abs(x_out - pstruct.x)
if max(diff) gt 1.e-3 then begin
txterr = 'X values in workspace ' + strtrim(wks_list[i], 2) + $
' are different from those in workspace ' + strtrim(wks_list[0], 2) + $
'. Exiting!'
print, txterr
lamp_message, txterr
lamp_journal, txterr
return, 0
endif
endelse
; check Z values and sum together equivalent points
zval = pstruct.z
if typename(zval) eq 'FLOAT' then begin
zval = fix(zval*1000)
zval = zval[uniq(zval, sort(zval))]
endif
for j = 0, n_elements(zval)-1 do begin
idx = where(zcomp eq zval[j])
w_out[*,*,idx] += wtmp[*,*,j]
n_out[*,*,idx] += pstruct.n[*,*,j]
pv_out[*,idx] += pstruct.pv[*,j]
counter[idx] += 1
endfor
endfor
; list with PV parameters that should be added
; 0: time
; 1: monitor1
; 2: Total cts
; 19: monitor 2
additive_params = [0, 1, 2, 19]
for i = 0, n_elements(pv_out[*,0]) - 1 do begin
test = where(additive_params eq i, count)
if count eq 0 then pv_out[i,*] /= counter ;non-additive parameter, calculate average
endfor
; set errors as sqrt(counts)
e_out = sqrt(w_out)
; return combined workspace and parameters
pstruct.other_tit = 'Combined wks. Last: ' + pstruct.other_tit
mod_datp, pstruct, 'Z', z_out
mod_datp, pstruct, 'N', n_out
mod_datp, pstruct, 'E', e_out
mod_datp, pstruct, 'PV', pv_out
give_datp, pstruct
return, w_out
end
\ No newline at end of file
This diff is collapsed.
......@@ -8638,11 +8638,11 @@ if strpos(ptxt[0],'#F ') eq 0 then begin
endelse
endif
;SALSA
if strpos(ptxt[0],'2*Th') eq 0 then begin
;SALSA --> Firt parameter written either as 2*Theta (before 2019) or 0) 2*Theta
if strpos(ptxt[0],'2*Th') eq 0 or strpos(ptxt[0],'2*Th') eq 3 then begin
idx=0 & ido=1 & idt=0
for i=0,n_elements(ptxt)-1 do begin
if strpos(ptxt[i],'X_translation') eq 0 then idx=i
if strpos(ptxt[i],'X_translation') eq 0 or strpos(ptxt[i],'X_translation') eq 3 then idx=i
if idx gt 0 then inst='SALSA'
endfor
if idx gt 0 then if (size(datp.pv))[1] eq n_elements(datp.p) then begin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment