function [llf,wersuml,rr,dt,k,c]=mmlelike(p,p2snam,gg)
%                IS USED BY MMLE.M  TO  COMPUTE WERSUML
% LLF CALC USES SPECIFIED gg, NOT rr. LLF ONLY TRUE WHEN rr = gg

global uydata
global yest
global inovt
global wapriori
global pref
global rowinq

[a,phi,gam,c,d,q,x0,dt,rowinq]=eval([p2snam,'(p)']); %   GET PLANT MATRICES

[nm,nx]=size(c);[ndp,num]=size(uydata); %       YEST,INOV,LLF FOR NOMINAL P
if sum(diag(q))==0, k=zeros(nx,nm); %  NO KALMAN GAIN
else
   k=lqe(a,eye(nx),c,q*q'/dt/dt,gg)*dt;
end
% YES, THAT IS THE CONT. LQE   [MAINE,ILIFF EQN30, REF. IN MMLESTEP.M]

inovt=-ltitr(phi-phi*k*c,[gam-phi*k*d,phi*k],uydata,x0) * c' +  ...
uydata*[-d,eye(nm)]';%                                        KALMAN FILTER
wersuml=sum(sum((inovt/gg).*inovt))/ndp/nm;
p-pref;wersuml=wersuml+(ans.*wapriori)*ans'/ndp/nm;%   A-PRIORI TERM
rr=(inovt'*inovt)/ndp;
llf=ndp/2*(wersuml*nm+log(det(gg))); %       TRUE LLF USES rr IN PLACE OF gg
yest=uydata(:,num-nm+1:num)-inovt;
%------------------------------------------------------------end mmlelike.m

