; $Id: dcs_daveptr_ops.pro,v 1.4 2005/02/14 17:50:33 azuah Exp $
; Written by J.R.D. Copley.
;************************************************************************************************
;###############################################################################
;
; LICENSE:
;  The software in this file is written by an employee of 
;  National Institute of Standards and Technology 
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;###############################################################################
pro dcs_davePtr_ops_pickop,base=base,operation=operation,message_str=message_str
;************************************************************************************************
;
compile_opt strictarr
;
dcs_multiplechoice,base,decision,$
	"Special_operation",message_str,60,$
	skipdefaultchoices=0
case decision of
	0: operation="ytoQofE"
	1: operation="ytoQcompofE"
	else: operation=""
endcase
;
end


;************************************************************************************************
pro dcs_davePtr_ops,davePtr=davePtr,operation=operation,base=dcs_base,message_str=message_str
;************************************************************************************************
;
compile_opt strictarr
;
if (operation eq "unknown") then begin
	dcs_davePtr_ops_pickop,base=dcs_base,operation=operation,message_str=message_str
	return
endif
;
if (operation eq "ytoQofE" or operation eq "ytoQcompofE") then begin
	xlabel=(*(*davePtr).datastrptr).commonstr.xlabel
	ylabel=(*(*davePtr).datastrptr).commonstr.ylabel
	if (strupcase(xlabel) ne "ENERGY TRANSFER") then return
	if (strupcase(ylabel) ne "MEAN Q") then return
;
	wl=(*(*(*davePtr).dataStrPtr).specificPtr).ch_wl
	e0=!dcs_hsq2mn/wl^2
	etPtr=ptr_new((*(*(*davePtr).datastrptr).commonstr.histptr).x,/no_copy)
	ef=e0-*etPtr
	net=n_elements(ef)
	angles=*(*(*(*davePtr).dataStrPtr).specificPtr).angle_propsPtr
	cosphi=cos(angles[*,0]*!dtor)
	ng=n_elements(cosphi)
;
	uvec=intarr(ng)+1
	e0ef=2.0*sqrt(e0*ef)
;
;	Q itself.
	if (operation eq "ytoQofE") then begin
		qPtr=ptr_new(sqrt(e0+ef#uvec-e0ef#cosphi),/no_copy)
	endif
;
;	Component of Q in direction of k0.
	if (operation eq "ytoQcompofE") then begin
		k0=2.*!pi/wl
		kf=2.*!pi*sqrt(ef/!dcs_hsq2mn)
		qPtr=ptr_new(k0-kf#cosphi,/no_copy)
	endif
;
	qtyPtr=ptr_new((*(*(*davePtr).datastrptr).commonstr.histptr).qty,/no_copy)
	errPtr=ptr_new((*(*(*davePtr).datastrptr).commonstr.histptr).err,/no_copy)
	ptr_free,(*(*davePtr).datastrptr).commonstr.histptr
	(*(*davePtr).datastrptr).commonstr.histptr=$
		ptr_new({qty:*qtyPtr,err:*errPtr,x:*etPtr,y:*qPtr})
	ptr_free,qtyPtr
	ptr_free,errPtr
	ptr_free,etPtr
	ptr_free,qPtr
endif
;
end