function cost_update( t, vnum)
%
% update Viterbi cost function
%
% R. Perry, June 2001
%
% disp(sprintf( '\ncost_update: t = %g, vnum = %g\n', t, vnum));

global USE_GGqq_tmp;
global G;
global q;

global FIR_length;
global Nusers;
global Nchips;

global TYPE;

global GG_tmp;
global qq_tmp;
global GG;
global qq;

global V;        % main state array
global Vl;       % array for L-best indices
global Vparam;   % parameters


if( TYPE == 30) % multi-user, Gauss-Markov, known channel

  % do nothing

elseif( TYPE == 31) % multi-user, Gauss-Markov cost

  % get Viterbi parameters
  %
  L  = Vparam(1);
  M  = Vparam(2);

  if( ~USE_GGqq_tmp)
    GG_new = zeros(FIR_length*Nusers, FIR_length*Nusers, L, M);
    qq_new = zeros(FIR_length*Nusers, Nchips, L, M);
  end
  
  for j = 1:M    % for each state
     for i = 1:L  %  and each of the L-best
      prev = V(i,j,t,1);                              
      el = Vl(i,j,t,1);                              
      if( USE_GGqq_tmp)
        GG(:,:,i,j) = GG_tmp(:,:,el,prev,j);
        qq(:,:,i,j) = qq_tmp(:,:,el,prev,j);
      else
        get_Gq(t, prev, j, el, vnum);
        GG_new(:,:,i,j) = G;
        qq_new(:,:,i,j) = q;
      end
    end
  end

  if( ~USE_GGqq_tmp)
    GG = GG_new;
    qq = qq_new;
  end

elseif( TYPE == 40) % multi-user, Gauss-Markov, known channel, separate trellises

  % do nothing

else

  error( 'get_cost: unknown TYPE');

end
