\documentclass[12pt]{article}

\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{listings}
\usepackage[colorlinks=true,linkcolor=black,urlcolor=blue]{hyperref} 
\usepackage{dirtree}
\usepackage{courier}


 \lstset{
	 language=Matlab,
         basicstyle=\footnotesize\ttfamily, % Standardschrift
         %numbers=left,               % Ort der Zeilennummern
         numberstyle=\tiny,          % Stil der Zeilennummern
         %stepnumber=2,               % Abstand zwischen den Zeilennummern
         numbersep=5pt,              % Abstand der Nummern zum Text
         tabsize=2,                  % Groesse von Tabs
         extendedchars=true,         %
         breaklines=true,            % Zeilen werden Umgebrochen
         keywordstyle=\color{black},
    		frame=b,         
 %        keywordstyle=[1]\textbf,    % Stil der Keywords
 %        keywordstyle=[2]\textbf,    %
 %        keywordstyle=[3]\textbf,    %
 %        keywordstyle=[4]\textbf,   \sqrt{\sqrt{}} %
         stringstyle=\color{black}\ttfamily, % Farbe der String
         showspaces=false,           % Leerzeichen anzeigen ?
         showtabs=false,             % Tabs anzeigen ?
         xleftmargin=17pt,
         framexleftmargin=17pt,
         framexrightmargin=5pt,
         framexbottommargin=4pt,
         %backgroundcolor=\color{lightgray},
         showstringspaces=false      % Leerzeichen in Strings anzeigen ?        
 }


\title{TD\_xxx:  Matlab code for simulation of floating body motions in the time domain}

\author{Andrew Hamilton \\ Copyright \copyright 2012 MBARI}
\date{}

\begin{document}
\thicklines
\lstset{language=Matlab}
\lstset{numbers=left, numberstyle=\tiny, stepnumber=1, numbersep=5pt}
\lstset{firstnumber=last}

\maketitle
\tableofcontents
\newpage
\section{Listings}
\begin{lstlisting}[frame=single,frameround=tttt]
function F = SpringDamperTether(body1,bodies,n,name,p_a1,p_a2,Spring_Force_Coeffs,Damping_Force_Coeffs)

j = 0;
for i = 1:length(bodies)
name2 = get(bodies{i},'name');
  if(strcmp(name2,name))
    j = i;
  end
end
if(j == 0)
   error('ERROR: Can not find name match in SpringDamperTether');
end

body2 = bodies{j};

\end{lstlisting}

\begin{lstlisting}[frame=single,frameround=tttt,firstnumber=22]
sv1 = get(body1,'sv');
sv2 = get(body2,'sv');

xo1 = get(body1,'x0');
xo2 = get(body2,'x0');
pos1 = sv1(1:6);
vel1 = sv1(7:12);
pos2 = sv2(1:6);
vel2 = sv2(7:12);

[Elongation,ElongationRate,s] = TetherElongations(xo1,pos1,vel1,p_a1,xo2,pos2,vel2,p_a2);

F = zeros(1,6);

if(Elongation > 0)  %If ram is fully retracted, tether is slack and no force is exerted.
  SpringTension = ppval(Spring_Force_Coeffs,Elongation);
  F(1) = SpringTension*s(1);
  F(3) = SpringTension*s(3);
  
  DampingTension = ppval(Damping_Force_Coeffs,ElongationRate);
  F(1) = F(1) + DampingTension*s(1);
  F(3) = F(3) + DampingTension*s(3);
end

\end{lstlisting}

\end{document}




