FUNCTION Q_make,thin,vin,deg=deg
th = [thin]
sth = size(th)
sv = size(vin)
nth = sth(1)
nv = (sv(0) eq 1) + (sv(0) eq 2)*sv(2)
err = bytarr(3)
err(0) = sth(0) ne 1
err(1) = sv(1) ne 3 or nv eq 0
err(2) = not (nth eq 1 or nv eq 1 or (nth eq nv and nth ne 1 and nv ne 1) )
err = err mod 2
if (where(err))(0) ne -1 then begin
print,"Q_MAKE : error, wrong argument size..."
print," Use : Q_MAKE,thin,vin,[/deg]"
if err(0) then print," > angle (thin) must be a scalar (1) or a vector (n)"
if err(1) then print," > vector (vin) must be a vector (3) or a vector of vector (3,n)"
if err(2) then print," > in case of vector of angles thin(4,nth) and vectors vin(4,nv), nth=nv is required"
return,-1
endif
nq = max([nth,nv])
th = rebin(reform(double(th),1,nth),1,nq)
v = rebin(reform(double(vin),3,nv),3,nq)
if keyword_set(deg) then th = th/!radeg
Q = dblarr(4,nq)
Q(0,*) = cos(th/2.)
Q(1,*) = v(0,*) * sin(th/2.)
Q(2,*) = v(1,*) * sin(th/2.)
Q(3,*) = v(2,*) * sin(th/2.)
return,reform(Q)
end