function hplotleg = dataleg(hplotleg,nds,respDOF,refDOF,descrip,lnst,lnco)
%
%  Name:   dataleg
%
%  Usage:  
%
%  Purpose: Adds Legend to Data Plot 
%
%    nds=1 ; primary data set
%    nds=2 ; secondary data set
%
%
%  Version SWD970703
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%             Erik G. Straser, estraser@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%               ESA-EA
%
%  Copyright (c) 1996, The Regents of the University
%       of California. (See top level of code for
%       full copyright statement.)
%

%
%  Clear out legend if this is primary data set
%

if nds == 1,

  oldlegtxt = get(hplotleg,'children');

  if ~isempty(oldlegtxt), delete(oldlegtxt), end

end

%  Construct Text

if nds == 1,
  legstr1 = descrip;
  if (respDOF) ~= -1,
    legstr1 = [legstr1,'   Response DOF: ',num2str(respDOF)];
  end
  if (refDOF) ~= -1,
    legstr1 = [legstr1,'   Reference DOF: ',num2str(refDOF)];
  end
elseif nds == 2,
  legstr2 = descrip;
  if (respDOF) ~= -1,
    legstr2 = [legstr2,'   Response DOF: ',num2str(respDOF)];
  end
  if (refDOF) ~= -1,
    legstr2 = [legstr2,'   Reference DOF: ',num2str(refDOF)];
  end
elseif nds == 3,
  legstr3 = descrip;
  if (respDOF) ~= -1,
    legstr3 = [legstr3,'   Response DOF: ',num2str(respDOF)];
  end
  if (refDOF) ~= -1,
    legstr3 = [legstr3,'   Reference DOF: ',num2str(refDOF)];
  end
end

%  Apply text and properties to legend

top = 1.1;
spc = 0.1;

axes(hplotleg)
set(hplotleg,'visible','off')

if nds == 1,

  axes(hplotleg)
  axis([0 1 0 1])
  hplttext(1) = text(0.1,top-spc,legstr1);
  set(hplttext(1),'fontsize',9)
  set(hplttext(1),'interpreter','none')

  hplttextln(1) = line(linspace(0,0.08,10),(top-spc)*ones(1,10));
  set(hplttextln(1),'LineStyle',lnst(1,:));
  set(hplttextln(1),'Color',lnco(1));

elseif nds==2,

  axes(hplotleg)
  axis([0 1 0 1])
  hplttext(2) = text(0.1,top-3*spc,legstr2);
  set(hplttext(2),'fontsize',9)
  set(hplttext(2),'interpreter','none')
  
  hplttextln(2) = line(linspace(0,0.08,10),(top-3*spc)*ones(1,10));
  set(hplttextln(2),'LineStyle',lnst(2,:));
  set(hplttextln(2),'Color',lnco(2));

elseif nds ==3,

  axes(hplotleg)
  axis([0 1 0 1])
  hplttext(3) = text(0.1,top-5*spc,legstr3);
  set(hplttext(3),'fontsize',9)
  set(hplttext(3),'interpreter','none')

  hplttextln(3) = line(linspace(0,0.08,10),(top-5*spc)*ones(1,10));
  set(hplttextln(3),'LineStyle',lnst(3,:));
  set(hplttextln(3),'Color',lnco(3));

end

return

