function stVect = ens_map_vars2stVect(d, stateInfo, normFlag)
%stVect = ens_map_vars2stVect(d,stateInfo,[normFlag])
% maps vars (d.*) to normalized state vector stVect
% stateInfo 	- holds info on indexes to stVect and normalization coefficients
% normFlag	- normalization flag, if (normFlag = 1) state vector is normalized by stateInfo.std.all
%	and units of stVest is in std units.
%	otherwise (normFlag=0) stVect is just a concatination and varaibles are in their physical units
%	default (normFlag = 1)
%
% Sergey Frolov, August 2004
% SF, APRIL 2005, normalization by the vector + normFlag
% SF May, major change only single ouput for stVect is supported

if nargin<3
  normFlag = 1;
end
%keyboard

stVect = zeros([stateInfo.idx.fin.all,1],'single');
for i=1:length(stateInfo.varList)
  stVect(eval(stateInfo.idx.str.(stateInfo.varList{i})),1) = d.(stateInfo.varList{i});
end

if normFlag
  stVect = stVect./(stateInfo.std.all);
end

