function cvec= diag_to_class_vec(dd)

%Finds a class vector cvec(1:3)
%and global phase cvec(4) from the 
%diagonal entries dd(1:4) of a 
%diagonal unitary matrix. 

t1 = angle(dd(1));
t2 = angle(dd(2));
t3 = angle(dd(3));
t4 = angle(dd(4));

k0 = ( t1+t2+t3+t4)/4;
kx = ( t1+t2-t3-t4)/4;
ky = (-t1+t2-t3+t4)/4;
kz = ( t1-t2-t3+t4)/4;

cvec=[kx;ky;kz;k0];