
    \RequirePackage{ifthen}
    \RequirePackage{fancyhdr}
    \RequirePackage{graphicx}

    \newboolean{SANDnumProvided}
    \newboolean{SANDprintDateProvided}
    \newboolean{SANDrePrintDateProvided}
    \newboolean{SANDauthorProvided}
    \newboolean{SANDsupersedProvided}
    \newboolean{SANDmarkingsRequired}
    \newboolean{MarkCover}
    \newboolean{MarkBack}
    \newboolean{MarkTitle}
    \newboolean{MarkBody}
    \newboolean{MarkBottom}

    \newboolean{SANDnoticeOUO}

    \DeclareOption{OUO}{
	\typeout{Option "OUO": Formatting page 2 for OUO reports}
	\setboolean{SANDnoticeOUO}{true}
    }
    \ProcessOptions % We need to do it here so we get "reportSAND", and then again



	% We don't want a head rule
	\renewcommand{\headrulewidth}{0pt}


    % Printed on the cover page
    \newcommand{\MarkCoverVar}{Approved for public release; further dissemination unlimited.} % default




% ******************************************************************************
% Cover pages
%

    % ------------------------------------------------------------------------ %
    % Font selections for the cover page \Coverfont{series}{size}{skip}
    %
    \newcommand{\CoverFont}[3]{
	\fontencoding{OT1}
	\fontfamily{phv}
	\fontseries{#1}
	\fontshape{n}
	\fontsize{#2}{#3}
	\selectfont
    }

    \newcommand{\doCover}{
	%
	% Print the cover pages
	%
	\SANDmarks{cover}
	\newlength{\coverindent}
	\setlength{\coverindent}{1em}
	\newlength{\parindentsave}
	\setlength{\parindentsave}{\parindent}
	\setlength{\parindent}{0em}


	%
	% Front Cover
	%
	%\hspace*{-0.375in}
	\begin{minipage}[t]{6.0in}
	    \CoverFont{b}{18}{20pt}
	    SANDIA REPORT
	    \vspace{0.125in}\\
	    \CoverFont{m}{12}{14pt}
	    \SANDnumVar\\
	    \SANDreleaseTypeVar\\
	    \ifthenelse{\boolean{SANDrePrintDateProvided}}   {
		Printed \SANDrePrintDateVar
	    }{
                \ifdraft
                  Draft Date: \SANDprintDateVar
                \else
                  Printed \SANDprintDateVar
                \fi
	    }
	    \ifthenelse{\boolean{SANDsupersedProvided}}   {
		\vspace{0.125in}\\
		\SANDsupersedVar
	    }{
		\\
	    }

	    \vspace{0.25in}
	    \CoverFont{b}{24}{28pt}
	    \parbox[t]{\textwidth}{
		\raggedright
		\@title
	    }


            % Changed this space from 0.75in to 0.375in to match official SAND covers, and provide more space to prevent
	    % overfilling the page - MJK, 1/12/07
	    \vspace{0.375in}
	    \CoverFont{m}{12}{14pt}
	    \SANDauthorVar

	    \vspace{0.25in}
	    \CoverFont{m}{8}{10pt}
	    \selectfont
	    Prepared by\\
	    Sandia National Laboratories\\
	    Albuquerque, New Mexico 87185 and Livermore, California 94550\\
	    \\
	    Sandia National Laboratories is a multimission laboratory managed and operated by National Technology and\\
   	    Engineering Solutions of Sandia, LLC., a wholly owned subsidiary of Honeywell International, Inc., for the\\
            U.S. Department of Energy's National Nuclear Security Administration under contract DE-NA0003525.\\
	    \\
	    \MarkCoverVar
	\end{minipage}

	\vspace*{\fill} % Move the logo to the bottom of the cover page

	%\hspace*{-0.5in}
	\begin{minipage}[b]{6.0in}
	    \includegraphics{figures/sand/snllineblk}
	\end{minipage}



	%
	% Back cover
	%
	\newpage
	% Added centering and reduced minipage width to match official SAND covers better - MJK, 1/12/07
	\begin{center}
	\begin{minipage}[t]{5.5in}
	    \fontencoding{OT1}
	    \fontfamily{pnc}
	    \fontseries{m}
	    \fontshape{n}
	    \fontsize{9}{11pt}
	    \selectfont

	    Issued by Sandia National Laboratories, operated for the
	    United States Department of Energy by National Technology and Engineering Solutions of Sandia, LLC.
	    \vspace{\baselineskip}

            % Removed \fontsize{11}{13} to make NOTICE simply bold, to match official SAND covers better, MJK - 1/12/07
	    {\fontseries{b}\selectfont NOTICE:}
	    This report was prepared
	    as an account of work sponsored by an agency of
	    the United States Government. Neither the United
	    States Government, nor any agency thereof, nor any
	    of their employees, nor any of their contractors,
	    subcontractors, or their employees, make any warranty,
	    express or implied, or assume any legal liability or
	    responsibility for the accuracy, completeness, or
	    usefulness of any information, apparatus, product,
	    or process disclosed, or represent that its use
	    would not infringe privately owned rights. Reference
	    herein to any specific commercial product, process,
	    or service by trade name, trademark, manufacturer, or
	    otherwise, does not necessarily constitute or imply
	    its endorsement, recommendation, or favoring by the
	    United States Government, any agency thereof, or any
	    of their contractors or subcontractors. The views and
	    opinions expressed herein do not necessarily state
	    or reflect those of the United States Government,
	    any agency thereof, or any of their contractors.
	    \vspace{\baselineskip}

	    % Added 1/11/07 M. Cooper to remove additional text unnecessary for OUO documents on pg 2.
	    \ifthenelse{\boolean{SANDnoticeOUO}}{}{
	    Printed in the United States of America. This report has
	    been reproduced directly from the best available copy.
	    \vspace{\baselineskip}

	    Available to DOE and DOE contractors from\\
	    \begin{tabular}{ll}
		\hspace*{\coverindent} & U.S. Department of Energy \\
		& Office of Scientific and Technical Information \\
		& P.O. Box 62 \\
		& Oak Ridge, TN 37831 \\
		&  \\
	    \end{tabular}
	    \\
	    \begin{tabular}{lll}
		\hspace*{\coverindent} & Telephone: & (865) 576-8401\\
		& Facsimile: & (865) 576-5728\\
		& E-Mail: & 	reports@adonis.osti.gov\\
		& Online ordering: & http://www.osti.gov/bridge\\
	    \end{tabular}
	    \vspace{\baselineskip}
	    \vspace{0.25in}

	    Available to the public from\\
	    \begin{tabular}{ll}
		\hspace*{\coverindent} & U.S. Department of Commerce \\
		& National Technical Information Service \\
		& 5285 Port Royal Rd \\
		& Springfield, VA 22161 \\
		&  \\
	    \end{tabular}
	    \\
	    \begin{tabular}{lll}
		\hspace*{\coverindent} & Telephone: & (800) 553-6847 \\
		& Facsimile: & (703) 605-6900 \\
		& E-Mail: & orders@ntis.fedworld.gov \\
		%& Online ordering: & http://www.ntis.gov/ordering.htm \\
		& Online ordering: & http://www.ntis.gov/help/ordermethods.asp?loc=7-4-0\#online \\
	    \end{tabular}
	    }% end of text for non-OUO reports
	    \vspace{\baselineskip}
	    \vspace{0.125in}

	    \includegraphics[width=0.75in]{figures/sand/DOEbwlogo}
	\end{minipage}
	\end{center}

	% Restore the original paragraph indent
	\setlength{\parindent}{\parindentsave}

	\SANDmarks{back}
    }


% ******************************************************************************
% The user commands
%

    % ------------------------------------------------------------------------ %
    % Here we define the mandatory declarations
    %
    \newcommand{\SANDnum}[1]{
	\newcommand{\SANDnumVar}{#1}
	\setboolean{SANDnumProvided}{true}
    }

    \newcommand{\SANDauthor}[1]{
	\newcommand{\SANDauthorVar}{#1}
	\setboolean{SANDauthorProvided}{true}
    }

    \newcommand{\SANDprintDate}[1]{
	\newcommand{\SANDprintDateVar}{#1}
	\setboolean{SANDprintDateProvided}{true}
    }


	\renewcommand\chapter{%						% \chapter from report.cls
	    \SANDmarks{body}						% new 2
	    \global\@topnum\z@						% \chapter from report.cls
	    \@afterindentfalse						% \chapter from report.cls
	    \secdef\@chapter\@schapter					% \chapter from report.cls
	}								% \chapter from report.cls

    % Printed on the cover and title page below the SANDIA REPORT number
    \newcommand{\SANDreleaseTypeVar}{Unlimited Release} % default


    % Printed on top of cover page
    \newcommand{\MarkTopCoverVar}{} % default

    % Printed on bottom of cover page
    \newcommand{\MarkBotCoverVar}{} % default

    % Printed on top of back cover page
    \newcommand{\MarkTopBackVar}{} % default

    % Printed on bottom of back cover page
    \newcommand{\MarkBotBackVar}{} % default

    % Printed on top of title page
    \newcommand{\MarkTopTitleVar}{} % default

    % Printed on bottom of title page
    \newcommand{\MarkBotTitleVar}{} % default

    % Printed on bottom of all body pages
    \newcommand{\MarkBotBodyVar}{} % default

    % Printed on top of all body pages
    \newcommand{\MarkTopBodyVar}{} % default


    %
    % The user marking commands
    %
    \newcommand{\SANDreleaseType}[1]{
	\renewcommand{\SANDreleaseTypeVar}{#1}
    }
    \newcommand{\SANDmarkTopBottom}[1]{
	\renewcommand{\MarkBotBodyVar}{#1}
	\renewcommand{\MarkTopBodyVar}{#1}
	\renewcommand{\MarkBotBackVar}{#1}
	\renewcommand{\MarkTopBackVar}{#1}
	\renewcommand{\MarkBotTitleVar}{#1}
	\renewcommand{\MarkTopTitleVar}{#1}
	\renewcommand{\MarkBotCoverVar}{#1}
	\renewcommand{\MarkTopCoverVar}{#1}
	\setboolean{MarkTitle}{true}
	\setboolean{MarkBack}{true}
	\setboolean{MarkBody}{true}
	\setboolean{MarkCover}{true}
	\setboolean{SANDmarkingsRequired}{true}
	\setboolean{MarkBottom}{true}
    }

    %
    % Internal command used to activate markings depending on what part of
    % the document we are currently processing; e.g. \SANDmarks{body}
    %
    \newcommand{\SANDmarks}[1]{
	\ifthenelse{\boolean{SANDmarkingsRequired}}   {
	    \fancyfoot{} % Clear all foot markings
	    \fancyhead{} % Clear all head markings

	    % Fancyhdr needs a little room
	    \setlength{\headheight}{\baselineskip}

	    \pagestyle{fancy}
	    \thispagestyle{fancy}

	    \ifthenelse{\equal{#1}{cover}}   {
		% We're on the cover page
		\ifthenelse{\boolean{MarkCover}}   {
		    \chead{\MarkTopCoverVar}
		    \cfoot{\MarkBotCoverVar}
		}{
		    \chead{}
		    \cfoot{}
		}
	    }{
	    }

	    \ifthenelse{\equal{#1}{back}}   {
		% We're on the back cover page
		\ifthenelse{\boolean{MarkBack}}   {
		    \chead{\MarkTopBackVar}
		    \cfoot{\MarkBotBackVar}
		}{
		    \chead{}
		    \cfoot{}
		}

		% We do want a page number on the back cover
		\ifthenelse{\boolean{MarkBottom}}   {
		    \fancyfoot[LE,RO]{\thepage}
		}{% else
		    \fancyfoot[CE,CO]{\thepage}
		}
	    }{
	    }

	    \ifthenelse{\equal{#1}{title}}   {
		% We're on the title page
		\ifthenelse{\boolean{MarkTitle}}   {
		    \chead{\MarkTopTitleVar}
		    \cfoot{\MarkBotTitleVar}
		}{% else
		    \chead{}
		    \cfoot{}
		}

		\ifthenelse{\boolean{MarkBottom}}   {
		    \fancyfoot[LE,RO]{\thepage}
		}{% else
		    \fancyfoot[CE,CO]{\thepage}
		}
	    }{
	    }

	    \ifthenelse{\equal{#1}{body}}   {
		\ifthenelse{\boolean{MarkBody}}   {
		    \chead{\MarkTopBodyVar}
		    \cfoot{\MarkBotBodyVar}
		}{% else
		    \chead{}
		    \cfoot{}
		}

		% We're on a body page. If we're not going to mark the bottom,
		% or body pages at all, then we might as well put the page number
		% at the center
		\ifthenelse{\boolean{MarkBottom} \and \boolean{MarkBody}}   {
		    \fancyfoot[LE,RO]{\thepage}
		}{% else
		    \fancyfoot[CE,CO]{\thepage}
		}
	    }{
	    }
	}{
	    %
	    % If not SANDmarkingsRequired
	    %
	    \pagestyle{plain}% The default when we have no markings

	    \ifthenelse{\equal{#1}{cover}}   {
		% We're on the cover page

		% No page number on cover
		\thispagestyle{empty}
	    }{
	    }

	    \ifthenelse{\equal{#1}{back}}   {
		% We're on the back cover page

		% We do want a page number on the back cover
		\thispagestyle{plain}
	    }{
	    }

	}
    }  % end of \SANDmarks{}

    \newcommand{\SANDmarkCover}[1]{
	\renewcommand{\MarkCoverVar}{{\CoverFont{m}{8}{10pt}}{#1}}
    }
