%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                              %
% romsaf.cls                                                                   %
% -----------                                                                  %
%                                                                              %
% A LaTeX class for ROM SAF documents, v0.2 [2005/10/20].                      %
%                                                                              %
% C. Marquardt, Met Office, Exeter          #

% Updated S Syndegaard, DMI and H Lewis Met Office [2009/10/20]  v0.3
%      - use of san-serif as font default
%      - some font-size changes on the front-page
%      - inclusion of new ROM SAF logos.
%                                                                              %
%                                                                              %
% Options and default settings                                                 %
% ----------------------------                                                 %
%                                                                              %
% This class is derived from the KOMA Script classes. Thus, (nearly) all       %
% options that can be given to any KOMA class can also be given to this        %
% document class.                                                              %
%                                                                              %
% However, some defaults are different to the KOMA Script classes. In          %
% particular, the document will be two sided; to obtain one sided output,      %
% the option                                                                   %
%                                                                              %
%    oneside                                                                   %
%                                                                              %
% must be specified in the \documentclass command. Also, all headings will     %
% will be produced using the smallheadings option of KOMA Script; any other    %
% choice must be requested by giving either the                                %
%                                                                              %
%    bigheadings                                                               %
%                                                                              %
% or                                                                           %
%                                                                              %
%    normalheadings                                                            %
%                                                                              %
% options to the \documentclass command. As with KOMA, the default page        %
% size is A4 (but can be changed with, e.g., the usual ...paper options).      %
%                                                                              %
%                                                                              %
% KOMA base class                                                              %
% ---------------                                                              %
%                                                                              %
% The default base class used by romsaf is the scrreprt document class,        %
% corresponding to the report document class in plain LaTeX. Instead, the      %
% scrartcl and scrbook classes (corresponding to the article and book classes  %
% of standard LaTeX) can be choosen by specifying the options                  %
%                                                                              %
%    article                                                                   %
%                                                                              %
% and                                                                          %
%                                                                              %
%    book                                                                      %
%                                                                              %
% in the \documentclass command, respectively. Note that the romsaf document   %
% class has been developed with a relatively recent version of the KOMA script %
% document classes. Therefore, it is desireable that the most recent versions  %
% of KOMA script are available in the user's TeX / LaTeX installation.         %
%                                                                              %
%                                                                              %
% Additional packages used                                                     %
% ------------------------                                                     %
%                                                                              %
% This class also uses (and therefore requires) the following LaTeX packages:  %
%                                                                              %
%    geometry                                                                  %
%    ifthen                                                                    %
%    calc                                                                      %
%                                                                              %
% Note that, as with the KOMA script classes, it is sensible to make sure      %
% that the most recent version is installed; otherwise, this document class    %
% might not work properly.                                                     %
%                                                                              %
%                                                                              %
% Page layout, headers and footers                                             %
% --------------------------------                                             %
%                                                                              %
% The page layout is constructed using the geometry package, but not with      %
% KOMA's own layout engine. As a consequence, the DIV and BCORR options        %
% available in KOMA have no effect, and should probably not be specified.      %
%                                                                              %
% Note that the size of the text body (including header and footer) is         %
% hardwired in this document class, and cannot be changed. Similarly, the      %
% layout of the headers and footers is not intended to be changed. The         %
% header's content can be set by the following commands provided by the        %
% romsaf class:                                                                %
%                                                                              %
%    \DocTitle{...}         Title, to appear on the title page                 %
%    \DocShortTitle{...}    Short title, to appear in the header               %
%    \DocReference{...}     Reference ID, to appear in the header              %
%    \DocVersion{...}       Document version, to appear in title and header    %
%    \DocDate{...}          Document date, to appear in title and header       %
%                                                                              %
%                                                                              %
% Signature and document change tables                                         %
% ------------------------------------                                         %
%                                                                              %
% Both a Document Signature Table and a Document Change Record table will be   %
% typeset on the backtitle (i.e., the second page immediately after the        %
% title). The entries for the Document Signature Table are defined using       %
% the following two commands:                                                  %
%                                                                              %
%    \PreparedBy{<name>}{<function>}                                           %
%    \ReviewedBy{<name>}{<function>}                                           %
%    \ApprovedBy{<name>}{<function>}                                           %
%                                                                              %
% where the mandatory arguments <name> and <function> denote the author(s)     %
% or persons being involved in the relevant task (e.g., A.U. Thor) and their   %
% function (e.g., ROM SAF Project Manager).                                    %
%                                                                              %
% The Document Change Record table is generated through a series of the        %
% command                                                                      %
%                                                                              %
%    \DocChange{<version>}{<date>}{<by>}{<description>}                          
%
%                                                                              %
% with the obvious meaning of the mandatory arguments.                         %
%                                                                              %
%                                                                              %
% Continued figures and tables                                                 %
% ----------------------------                                                 %
%                                                                              %
% When typesetting long tables or including several subfigures into one,       %
% the resulting table or figure may spread out over several pages. The         %
% commands                                                                     %
%                                                                              %
%    \continuedtable                                                           %
%    \continuedfigure                                                          %
%                                                                              %
% placed inside a table or figure environment and before the next \caption     %
% will reduce the table or figure counter and therefore allow the creation     %
% of 'continued' tables or figures. However, the caption text itself must      %
% be manually adapted, e.g. to include a '(cont'd)' at the end of the          %
% caption text.                                                                %
%                                                                              %
% Note that the longtable package provides an alternative for multipage        %
% tables, although these are no longer handled as ordinary floats.             %
%                                                                              %
%                                                                              %
% Example                                                                      %
% -------                                                                      %
%                                                                              %
% The ROPP User Guide contains the following declarations:                     %
%                                                                              %
%    \documentclass{romsaf}                                                    %
%                                                                              %
%       ...                                                                    %
%                                                                              %
%    \DocTitle{The Radio Occultation Processing Package (ROPP)\\               %
%              User Guide}                                                     %
%    \DocAuthor{Me and Him} (optional, default the ROM SAF consortium)         %
%    \DocShortTitle{ROPP User Guide}                                           %
%    \DocReference{SAF/ROM/METO/UG/ROPP/01}                                    %
%    \DocVersion{Version 0.1}                                                  %
%    \DocDate{22 October 2004}                                                 %
%                                                                              %
%       ...                                                                    %
%                                                                              %
%    \PreparedBy{C. Marquardt}{Research Scientist}                             %
%    \PreparedBy{D. Offiler}{ROM SAF Project Team}                             %
%    \ApprovedBy{K.--B. Lauritsen}{ROM SAF Project Manager}                    %
%                                                                              %
%       ...                                                                    %
%                                                                              %
%    \DocChange{Version 0.0}{25 Oct 2004}{Him}{Initial structure}              %
%    \DocChange{Version 1.0}{29 Oct 2004}{Me}{Initial revision}                %
%                                                                              %
%       ...                                                                    %
%                                                                              %
%    \begin{document}                                                          %
%                                                                              %
%       ...                                                                    %
%                                                                              %
%    \end{document}                                                            %
%                                                                              %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% 1. Formalities
% --------------

\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesClass{romsaf}[2009/10/20 ROM SAF report class v0.3]

% 2. Options
% ----------

% KOMA base class

\newif\if@chapters\@chapterstrue
\newcommand*{\komaclass}{scrreprt}
\DeclareOption{article}{\renewcommand{\komaclass}{scrartcl}\@chaptersfalse}
\DeclareOption{book}{\renewcommand{\komaclass}{scrbook}}

% 2.0 Use san-serif as font default.

\renewcommand{\familydefault}{\sfdefault}

% 2.1 Make twoside the default (to be switched with oneside)

\newif\if@twoside\@twosidetrue
\DeclareOption{oneside}{\@twosidefalse}

% 2.2 Make smallheadings the default

\newif\if@bigheadings\@bigheadingsfalse
\newif\if@normalheadings\@normalheadingsfalse
\newif\if@smallheadings\@smallheadingstrue
\DeclareOption{bigheadings}{\@smallheadingsfalse\@bigheadingstrue}
\DeclareOption{normalheadings}{\@smallheadingsfalse\@normalheadingstrue}
\DeclareOption{smallheadings}{\@smallheadingstrue}

% 2.3 Userguide layout option

\newif\if@userguide\@userguidefalse
\DeclareOption{userguide}{\@userguidetrue}

% 2.4 Pass everything else to KOMA

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\komaclass}}

% 2.5 Other (hardwired) defaults

\PassOptionsToClass{pointlessnumbers,cleardoublestandard,bibtotoc}{\komaclass}

% 2.6 Process options

\ProcessOptions\relax

% 2.7 Set defaults

\if@twoside
   \PassOptionsToPackage{twoside}{geometry}
\fi
\if@smallheadings
   \PassOptionsToClass{smallheadings}{\komaclass}
\else
   \if@normalheadings
      \PassOptionsToClass{normalheadings}{\komaclass}
   \fi
\fi

% 2.8 Load the KOMA class

\LoadClass{\komaclass}[2004/01/07]

% 2.9 Page layout package

\if@userguide
   \RequirePackage[total={17cm,27.5cm},heightrounded,includemp,
                   includeheadfoot,head=12mm,headsep=8mm,footskip=11mm,
                   dvips,bindingoffset=12mm]{geometry}
\else
   \RequirePackage[total={17cm,27.5cm},heightrounded,
                   includeheadfoot,head=12mm,headsep=8mm,footskip=11mm,
                   dvips,bindingoffset=12mm]{geometry}
\fi

% 2.10 Header package

\RequirePackage[manualmark]{scrpage2}
\PassOptionsToPackage{oneside}{scrpage}

% 2.11 Other packages

\RequirePackage{ifthen}
\RequirePackage{calc}
\RequirePackage{graphicx}
\RequirePackage{colortbl}[2001/02/13]

% 3. Define new commands for headers and footers
% ----------------------------------------------

\newcommand\@DocTitle{UNKNOWN}
\newcommand\@DocAuthor{\textbf{The ROM SAF Consortium} \\
            Danish Meteorological Institute (DMI)\\
            European Centre for Medium-Range Weather Forecasts (ECMWF)\\ 
            Institut d'Estudis Espacials de Catalunya (IEEC)\\   %%% '-hack
            Met Office (MetO)}
\newcommand\@DocShortTitle{UNKNOWN}
\newcommand\@DocReference{UNKNOWN}
\newcommand\@DocVersion{UNKNOWN}
\newcommand\@DocDate{UNKNOWN}

\newcommand\DocTitle[1]{\renewcommand\@DocTitle{#1}}
\newcommand\DocAuthor[1]{\renewcommand\@DocAuthor{#1}}
\newcommand\DocShortTitle[1]{\renewcommand\@DocShortTitle{#1}}
\newcommand\DocReference[1]{\renewcommand\@DocReference{#1}}
\newcommand\DocVersion[1]{\renewcommand\@DocVersion{#1}}
\newcommand\DocDate[1]{\renewcommand\@DocDate{#1}}

% 4. Define ROM SAF headers and footers
% -------------------------------------
%
% Note: By default, the \chapter command resets the pagestyle to plain,
%       so we have to redefine the \chapterpagestyle.

\newlength{\hfwidth}
\if@userguide
   \setheadwidth[0pt]{textwithmarginpar}
   \setfootwidth[0pt]{textwithmarginpar}
   \setlength{\hfwidth}{\textwidth+\marginparwidth+\marginparsep}
\else
   \setheadwidth[0pt]{text}
   \setfootwidth[0pt]{text}
   \setlength{\hfwidth}{\textwidth}
\fi

\deftripstyle{romsaf}[0.0pt][0.4pt]%
             {\parbox[b][10mm][c]{0.27\hfwidth}%
                {\fontsize{9pt}{10pt}\selectfont\normalfont\centering%
                 \@DocReference\\
                 \@DocVersion\\
                 \@DocDate
                }}%
              {\parbox[b][10mm][c]{0.4\hfwidth}%
                {\fontsize{10pt}{11pt}\bf\centering%
                 \@DocShortTitle}\\}%
%              {\includegraphics[height=8mm]{ROMSAF_noName_Colour_Small.eps}}%%%
              {\includegraphics[height=8mm]{ROMSAF_NoName_Colour.eps}}%%%
             {}{\pagemark}{}


\pagestyle{romsaf}


\if@chapters
   \renewcommand*{\chapterpagestyle}{romsaf}
\fi


% 5. Title page
% -------------

% Redefine the "empty" page style (which is used for the title page):
%\deftripstyle{empty}{}{}{}
%             {\fontsize{10pt}{11pt}\selectfont\normalfont Ref: \@DocReference}{}{}%
%%\defpagestyle{empty}{{}{}{}}%
%%                    {{X}{\fontsize{10pt}{11pt}\selectfont\normalfont\@DocReference}{Y}}

% The title page has to be named "empty".
% Redefine using defpagestyle, which is formatted as follows:
%\defpagestyle{empty}%    (ull, ulw)         even page           odd page             all page          (lll, llw)
%                    {(\textwidth,1.0pt){\centering Header X}{\centering Header Y}{\centering Header Z}(\textwidth,0.5pt)}% define header
%                    {(\textwidth,0.5pt){\centering Footer X}{\centering Footer Y}{\centering Footer Z}(\textwidth,1.0pt)}% define footer

\defpagestyle{empty}%
                   {(\textwidth,0pt)%
                    {}%
                    {}%
                    {}%
                    (\textwidth,0pt)%
                   }% define header
                   %
                   {(\textwidth,0.0pt)%
                    {\parbox[b][10mm][c]{\textwidth}{\centering \hfill \\ \hrulefill \\ \fontsize{10pt}{11pt}\selectfont\normalfont 2}\\}%
                    {\fontsize{10pt}{11pt}\selectfont\normalfont Ref: \@DocReference \hfill}%
                    {}%
                    (\textwidth,0pt)%
                   }% define footer

\pagestyle{empty}


\titlehead{}
\subject{\hspace{-1cm}\includegraphics[width=0.77\textwidth]{ROMSAF_Name_Colour.eps} \vspace{2cm}}
%\title{\fontsize{20pt}{20pt}\selectfont\bfseries {\bf EUMETSAT Satellite Application Facility \\ on Radio Occultation Meteorology} \\[2cm] \LARGE {\bf \@DocTitle}}
\title{\fontsize{20pt}{20pt}\selectfont\bfseries \LARGE {\bf \@DocTitle}}
%\author{\@DocVersion\let\footnotemark\relax\thanks{\@DocReference}}
\author{\bf\LARGE \@DocVersion}
\date{\bf\LARGE \@DocDate\\[-1cm] \ }
%\publishers{\@DocAuthor\\[-1cm]
%vspace{2cm}\hspace{14cm}\includegraphics[height=3cm]{romsaf_logo.eps}\vspace{-4cm}}
\publishers{\@DocAuthor\\[-1cm]}


% 6. The backtitle
% ----------------

% 6.1 A strut for the tables

\newlength\lstrutlength
\setlength{\lstrutlength}{\baselineskip/\baselinestretch}
\addtolength{\lstrutlength}{1.5mm}
\newcommand\lstrut{\rule[-2mm]{0mm}{\lstrutlength}}

% 6.2 Document signature table commands

\newcommand\@PreparedBy{UNKNOWN}
\newcommand\@ReviewedBy{UNKNOWN}
\newcommand\@ApprovedBy{UNKNOWN}
\newcommand\@PreparedFunc{UNKNOWN}
\newcommand\@ReviewedFunc{UNKNOWN}
\newcommand\@ApprovedFunc{UNKNOWN}

\newcommand\PreparedBy[2]{%
              \renewcommand\@PreparedBy{#1}
              \renewcommand\@PreparedFunc{#2}
           }
\newcommand\ReviewedBy[2]{%
              \renewcommand\@ReviewedBy{#1}
              \renewcommand\@ReviewedFunc{#2}
           }
\newcommand\ApprovedBy[2]{%
              \renewcommand\@ApprovedBy{#1}
              \renewcommand\@ApprovedFunc{#2}
           }

% \newcommand\PreparedBy[2][Signature file missing]{%
%               \ifthenelse{\equal{#1}{Signature file missing}}%
%                  {\renewcommand{\@PreparedSig}{#1}}%
%                  {\renewcommand{\@PreparedSig}{\raisebox{-0.4\lstrutlength}{\includegraphics[totalheight=\lstrutlength]{#1}}}}
%               \renewcommand\@PreparedBy{#2}
%            }
% \newcommand\ApprovedBy[2][Signature file missing]{%
%               \ifthenelse{\equal{#1}{Signature file missing}}%
%                  {\renewcommand{\@ApprovedSig}{#1}}%
%                  {\renewcommand{\@ApprovedSig}{\raisebox{-0.4\lstrutlength}{\includegraphics[totalheight=\lstrutlength]{#1}}}}
%               \renewcommand\@ApprovedBy{#2}
%            }

% 6.3 Document change record command

\newcounter{dcc}\setcounter{dcc}{0}
\newcommand\DC@rows{}
\newcommand\DocChange[4]{%
              \addtocounter{dcc}{1}
              \@temptokena=\expandafter{\DC@rows}
              \xdef\DC@rows{\the\@temptokena #1\noexpand\lstrut\protect& #2\protect&
                                             #3\protect& #4\protect\tabularnewline
                                \noexpand\hline}
           }

% 6.4 The tables

\uppertitleback{%

  \begin{center}
    \vspace*{-25mm}

%    {{\includegraphics[height=8mm]{ROMSAF_noName_Colour_Small.eps}}\hfill%
    {{\includegraphics[height=8mm]{ROMSAF_NoName_Colour.eps}}\hfill%
     {\parbox[b][10mm][c]{0.4\hfwidth}{\fontsize{10pt}{11pt}\bf\centering \@DocShortTitle}}\hfill%
     {\parbox[b][10mm][c]{0.27\hfwidth}{\fontsize{9pt}{10pt}\selectfont\normalfont\centering \@DocReference\\ \@DocVersion\\ \@DocDate}}}

    \vspace*{-3.5mm}
    \noindent\makebox[\linewidth]{\rule{\textwidth}{0.4pt}}

    \vspace*{1.5cm}

    \begin{tabularx}{\textwidth}[c]{|>{\columncolor[gray]{0.95}}r|l|l|c|X|}
      \multicolumn{5}{c}{\rule[-5mm]{0cm}{5mm}\bf Document Author Table} \\
      \hline
       \multicolumn{1}{|>{\cellcolor[gray]{0.95}}c|}{} & 
       \multicolumn{1}{|>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Name}} & 
       \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Function}} &
       \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Date}} & 
       \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Comment}} \\
      \hline
      {\bf\emph{Prepared by:}} & 
          \@PreparedBy   & 
          \@PreparedFunc &
          \@DocDate      & \\
      \hline
      {\bf\emph{Reviewed by:}} & 
          \@ReviewedBy   & 
          \@ReviewedFunc &
          \@DocDate      & \\
      \hline
      {\bf\emph{Approved by:}} &
          \@ApprovedBy   & 
          \@ApprovedFunc &
          \@DocDate      & \\
      \hline
    \end{tabularx}

    \vspace*{1cm}

    \begin{tabularx}{\textwidth}[c]{|c|r|c|X|}
      \multicolumn{4}{c}{\rule[-5mm]{0cm}{5mm}\bf Document Change Record} \\
      \hline
      \multicolumn{1}{|>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Issue/Revision}} & 
      \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Date}} & 
      \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{By}} &
      \multicolumn{1}{>{\cellcolor[gray]{0.95}}c|}{\bf\emph{Description}} \\
      \hline
      \ifnum\value{dcc}=0
         \lstrut & & \\
      \else
         \DC@rows
      \fi
      \hline
    \end{tabularx}

%    \vfill
%    \hrulefill
%    {\hfill {\parbox[t][10mm][c]{0.27\hfwidth}{\fontsize{9pt}{10pt}\selectfont\normalfont\centering 2}} \hfill}

  \end{center}
}

% 6.5 The blurb

\lowertitleback{%

\vspace*{0.5cm}

\begin{center} {\bf ROM SAF} \\ \end{center}

The Radio Occultation Meteorology Satellite Application Facility (ROM SAF) is a
decentralised processing centre under EUMETSAT which is responsible for operational
processing of radio occultation (RO) data from the Metop and Metop-SG satellites and radio
occultation data from other missions. The ROM SAF delivers bending angle, refractivity,
temperature, pressure, humidity, and other geophysical variables in near real-time for NWP
users, as well as reprocessed Climate Data Records (CDRs) and Interim Climate Data Records
(ICDRs) for users requiring a higher degree of homogeneity of the RO data sets. The CDRs
and ICDRs are further processed into globally gridded monthly-mean data for use in climate
monitoring and climate science applications.\\

The ROM SAF also maintains the Radio Occultation Processing Package (ROPP) which contains
software modules that aid users wishing to process, quality-control and assimilate radio
occultation data from any radio occultation mission into NWP and other models.\\

The ROM SAF Leading Entity is the Danish Meteorological Institute (DMI), with Cooperating
Entities: i) European Centre for Medium-Range Weather Forecasts (ECMWF) in Reading, United
Kingdom, ii) Institut D'Estudis Espacials de Catalunya (IEEC) in Barcelona, Spain, and
iii) Met Office in Exeter, United Kingdom. To get access to our products or to read more
about the ROM SAF please go to: \url{http://www.romsaf.org}.

\vspace*{0.5cm}

\begin{center} {\bf Intellectual Property Rights} \\ \end{center}

All intellectual property rights of the ROM SAF products belong to EUMETSAT. The use of
these products is granted to every interested user, free of charge. If you wish to use
these products, EUMETSAT's copyright credit must be shown by displaying the words
``copyright (year) EUMETSAT'' on each of the products used.
}

\pagestyle{romsaf}  % Go back to the general page layout

% 7. Switch to userguide layout and back
% --------------------------------------

\newcommand*{\userguidelayout}{%
  \changetext{}%
             {-\marginparwidth-\marginparsep}%
             {}%
             {}%
             {}%
 }
\newcommand*{\standardlayout}{\changetext{}{\marginparwidth+\marginparsep}{}{}{}}

% 8. Margin texts
% ---------------

\newcommand{\margintext}[1]{\mbox{}\marginpar{\raggedleft\small\hspace{0pt\emph{\color{cyan}#1}}}}

% 9. Continued figures and tables
% -------------------------------

\providecommand{\continuedtable}{\addtocounter{table}{-1}}
\providecommand{\continuedfigure}{\addtocounter{figure}{-1}}

% 10. More changes to the default behaviour
% -----------------------------------------

\frenchspacing
\setkomafont{sectioning}{\normalcolor\bfseries}
\addtokomafont{caption}{\small}
\newlength{\captionwidth}
\setlength{\captionwidth}{\hsize}
\addtolength{\captionwidth}{-2cc}
\setcapwidth[c]{\captionwidth}
\setcapindent{0pt}
\renewcommand{\figurename}{Fig.}
\renewcommand{\figureformat}{\bfseries\figurename~\thefigure\autodot}
\renewcommand{\tablename}{Tab.}
\renewcommand{\tableformat}{\bfseries\tablename~\thetable\autodot}
