\chapter{User manuel}

\section{Generalities}

\subsection{Data and Log Files}

\class{} uses two files of data; one for input and one for output, which
may be the same actual file. The input file is only used to read. An
observation contains several independent subsections. These file are defined
by the command \index{FILE} {\tt FILE (IN,OUT,BOTH) Filename}, possibly
followed by {\tt NEW} if a new file is to be initialized. The default
extension of files is {\tt .30m}. This can be changed with \com{SET
  EXTENSION .my\_extension}.

\class{} also keeps two log files, named {\tt class.log} and {\tt
  class.mes}. They are created at \class{} start in the default directory
{\tt \$HOME/.gag/logs}. This directory is defined in the \sic{} logical
{\tt gag\_log:} which can be customized in the user customization file: {\tt
  \$HOME/.gag.dico}. The log files may be used to keep track of a batch or
interactive work.

\subsection{Observation and Version Number}

Within \class{}, an \emph{observation} should represent a single observing
configuration, \eg{} a single direction observed at a single central
frequency with a single spectral resolution and in one polarization only
(\ie{} a single sky position, front-end and back-end combination). Each
observation is given a number, named \emph{observation number} at the time
of creation of the \class{} data file. This number is then carried out in
further manipulations.

Several version of a given observation may be stored in the same data file.
Each version of a given observation thus represent different stages of the
data reduction and all the versions of a given observation gives the
history of the data processing. Each version of an observation is given a
number (starting at 1), named \emph{version number} at the time of creation
of the \class{} data file. The version number increases automatically, each
time the observation is modified (using \com{WRITE}). By default, only the
last version of a given observation is relevant, \ie{} \com{GET} reads the
last version of an observation. It is possible (but not recommended) to
store an observation without incrementing the version number with the
\com{UPDATE} command so that you can go back to previous stages of
reduction in case of big mistakes.

Provided you respect this use of the version number, data reduction can be
largely automated. Failing to do this, \ie{} using the same observation
number for very different things at time of creation of the \class{} data
file, implies that you have to remember yourself which version corresponds
to which configuration. 

\subsection{Scan and Subscan Number}

For bookkeeping purpose, \class{} keeps track of a Scan and a Subscan
number, which can be used as a selection criterium. The Scan number is
attributed at observing time which is carried out in the \class{} data
format. Moreover, two different observing mode are nowdays in common use in
single-dish telescope:
\begin{itemize}
\item The pointed observing mode for which the telescope is pointed toward
  the source direction during all the integration to obtain only one
  spectrum.  The scan is made of only one spectrum whose intensity is
  accumulated during the scan duration. Hence the Subscan number is always
  1. 
\item The On--The--Fly (OTF) observing mode for which the telescope drift
  on source during the integration to make a small map. The scan is here
  composed of a collection of spectra dumped regularly (typically every 1
  second) during a contiguous portion of time. Each dumped spectrum is also
  tagged by a subscan number whose value is incremented for each new OTF
  line (both to enable easy selection of a single line inside one OTF scan,
  and to ensure consistency with the 30m numbering). This subscan number is
  foreseen to always be greater than 1. There is one exception: when
  \class{} read data in old format, the subscan number is zero and a
  warning is issued.
\end{itemize}

\subsection{Entry Number and Index}

The \com{FIND} command offers the possibility to build an index of the
observations matching several given selection criteria. The user can then
easily process consistently only those observations. Each time a new index
is formed using the \com{FIND} command, all the selected observations
(which will belong to this index) are sequentially attributed a number,
named \emph{entry} number. This number goes from 1 to {\tt found}, the
number of observations in the current index. The entry number is never
saved. It is just used as a number to process the current index in a loop.

Default selection criteria are defined by the \com{SET} command. For most
selection criteria, an option to the \com{FIND} command exists, with the
same name, which may be used to impose temporary values to the {\tt FIND}
command; the default values are unchanged by the {\tt FIND} options.
\begin{itemize}
\item \comm{SET}{LINE} {\tt Name} for the line name to be used. A
  line name of the form {\tt ABC*} indicates that all lines beginning by
  {\tt ABC} are to be selected.  The default is {\tt *}, \ie{} any line
  name.
\item \comm{SET}{NUMBER} {\tt n1 n2} for the range of observation
  numbers. Default is {\tt * *}, \ie{} any observation number; {\tt * n2}
  specifies all observation numbers smaller than n2.
\item \comm{SET}{OBSERVED} {\tt d1 d2} for the range of observing
  dates. A date is specified in the format {\tt dd-mmm-yyyy}, \eg{}
  19-jan-1985. Default is {\tt * *}, \ie{} any date; {\tt 19-JAN-1985 *}
  means any date later than January 19th, 1985.
\item \comm{SET}{OFFSET} {\tt o1 o2} for offsets of the position
  to be used (in the system and units specified by \comm{SET}{COORDINATE} and
  \comm{SET}{ANGLE}).  Default is {\tt * *}.
\item \comm{SET}{RANGE} {\tt w e s n} is a less restrictive way to
  specify position offsets. A rectangular area of sky is defined by its
  west, east, south and north limits (in current angle units).
\item \comm{SET}{REDUCED} {\tt d1 d2} for a range in reduction
  dates; same specifications and defaults as for \comm{SET}{OBSERVED}.
\item \comm{SET}{SOURCE} {\tt Name} for the source name; same
  specifications as {\tt SET LINE}.
\item \comm{SET}{SCAN} {\tt s1 s2} for a range of original scan numbers.
  Scan numbers should not be confused with Observation numbers (the numbers
  by which an observation is uniquely identified). They are essentially
  ``history'' numbers defined by the acquisition system, but usually with
  different ``observations'' (in the \class{} meaning) for a single scan.
  The scan number is kept only for bookkeeping purpose.
\item \comm{SET}{TELESCOPE} {\tt Name} for the Telescope name.
  For the IRAM 30-m telescope, the telescope name contains coded into the
  last 3 letters the backend used for the observations. Similar conventions
  are used for spectra coming from Plateau de Bure Interferometer.
\item \comm{SET}{TYPE} {\tt Name} specifies on which type of observations
  you deal with: ``Continuum'', ``Line'' or ``Skydip''.
\end{itemize}
The tolerance parameter defined by \comm{SET}{MATCH} also influences on the
position searches, since this parameter (in the current angle unit) is used
to check agreement with the specified limits.  \index{FIND!/ALL} Another
option to the {\tt FIND} command is {\tt /ALL} which enables to find
all the versions of all observations satisfying the selection criteria
(otherwise only the most recent version is selected). Note that the system
is intended to work only with the last version of observations, so that the
use of the {\tt /ALL} option should remain exceptional.

Finally, the \comm{SET}{SORT} force the {\tt FIND} command to sort all the
entries of an index in ascending order of a key parameter (\eg{} lambda or
beta offsets). {\tt SET SORT number} implies the default order.

\subsection{R and T Memories}

\class{} keeps 2 observations in memory, in two different buffers, called
{\tt R} and {\tt T}. The {\tt R} memory is the only one that may be
accessed directly; the {\tt T} memory is only used for operations on
spectra (additions,...). The \com{GET n} command places the spectrum
corresponding to entry number {\tt n} in the {\tt R} buffer, while the
previous {\tt R} content is stored in the {\tt T} buffer. The command
\com{SWAP} exchanges both memories.

\subsection{Large Set of Spectra}

It is today possible with the IRAM--30~m to map a square degree field in
CO~(2-1). As an order of magnitude, this gives a final spectra cube of
about $10^6$ spectra with a slightly oversampling of $4''$.  An observer
who has just spent a few hours observing the same source in OTF mode may
want to process all the dumped spectra at once even though they do not
belong to the same scan.

The \com{LOAD} command gathers all the individual spectra currently in the
index as a 2D array for future work, in particular visualization. This
requires that all the spectra currently in the index are coherent, \ie{}
same source name, same line name and above all exactly the same frequency
sampling. The latter can easily be achieved just by resampling. No checking
is currently done about this, \ie{} this is currently the responsibility of
the observer to ensure a coherent frequency axis. The {\tt /INDEX} option
of commands like {\tt PLOT} or {\tt BASE} modifies there behavior to
directly work on the 2D array defined with the {\tt LOAD} command.

Nota Bene: The \com{STRIP} command which is producing a Velocity-Position
plots, is \emph{obsolescent}. Indeed the same functionality can be achived
by the combination {\tt LOAD; PLOT /INDEX} if the index is correctly
choosen. And the {\tt LOAD} command is much more powerful.

\subsection{Variables}

\subsubsection{The Rope to Hang Yourself}

\class{} makes use of \sic{} variables to allow more flexibility in the
processing, in particular in procedures. \sic{} variables are extremely
powerful, with the side effect that if you want, you can corrupt your data
by overwriting some information.  \class{} attempts to prevent the most
disastrous errors by defining some of the most critical variables as {\tt
  READONLY}. They cannot be overwritten by the user, but their values can
be used in expressions, either arithmetic or logical.  However, an
unprotected mode is available for specific processing using the command
\comm{SET}{VARIABLE}.

\subsubsection{Index Variables}

The variable {\tt FOUND} refers to the number of observations in the index.
It is declared Read-Only of course. Its main use is either to write a
\sic{} loop that goes through the index or to test for actions which should
be performed only if something exists in the index.  The \com{FIND} command
does not return an error, but set {\tt FOUND = 0}, if it finds nothing. A
second variable related to the index is the {\tt INDEX} array, of dimension
{\tt FOUND}, which contains the observation numbers of all observations in
the index.

\subsubsection{Header Variables}

The most important header parameters are defined by default as \sic{} 
variables in a protected mode. The others, of less frequent use, can be
accessed if required by the user (see ``Advanced Processing''). The default
variables are (RW means Read-Write variable, RO, Read-Only).
\begin{verbatim}
      TELESCOPE       Character*12, RW, Telescope name
      NUMBER          Integer,      RW, Observation number
      VERSION         Integer,      RO, Version number
      DATATYPE        Integer,      RO, Type of observation 
                                        0 Line, 1 Continuum, 2 Skydip
      QUALITY         Integer,      RO, Quality of data
      SCAN            Integer,      RO, Original scan number
      UTOBS           Double,       RO, UT of observation (Radians)
      LSTOBS          Double,       RO, LST of observation (Radians)
      AZIMUTH         Real,         RW, Azimuth of observation (Radians)
      ELEVATION       Real,         RW, Elevation of observation (Radians)
      TSYS            Real,         RW, System temperature
      TIME            Real,         RW, Integration time (Seconds)

      SOURCE          Character*12, RW, Source name
      LAMBDA          Double,       RW, Longitude of source (Radians)
      BETA            Double,       RW, Latitude of source (Radians)
      OFF_LAMBDA      Double,       RW, Offset in longitude (Radians)
      OFF_BETA        Double,       RW, Offset in latitude (Radians)
      EQUINOX         Real,         RW, Equinox of coordinates (Years)

      LINE            Character*12  RW, Line name
      CHANNELS        Integer,      RO, Number of channels
      REFERENCE       Real,         RW, Reference channel
      FREQ_STEP       Real,         RW, Frequency step by channel (MHz)
      VELO_STEP       Real,         RW, Velocity step by channel (km/s)
      VELOCITY        Real,         RW, Velocity of reference channel
      FREQUENCY       Double,       RW, Rest frequency at reference channel
      IMAGE           Double,       RW, Image frequency "   "   "   "

      BEAM_EFF        Real,         RW, Telescope beam efficiency
      FORWARD_EFF     Real,         RW, Telescope forward efficiency
      GAIN_IMAGE      Real,         RW, Image to signal band ratio
      WATER           Real,         RO, Water vapor content (mm)
      PRESSURE        Real,         RO, External pressure (hPa)
      AMBIENT_T       Real,         RO, External temperature (K)
      CHOPPER_T       Real,         RO, Chopper temperature (K)
      COLD_T          Real,         RO, Cold load temperature (K)
      TAU_SIGNAL      Real,         RO, Opacity in signal band
      TAU_IMAGE       Real,         RO, Opacity in image band
      ATM_SIGNAL      Real,         RO, Atmospheric temperature 
                                        in signal band
      ATM_IMAGE       Real,         RO, Atmospheric temperature 
                                        in image band

      RX              Real[8192]    RO, X values of data points
      RY              Real[8192]    RW, Y values of data points
\end{verbatim}
8192 is currently the maximum size of the spectra, but the variables RX and
RY are redimensioned to the effective number of channels for each spectrum.

\subsubsection{Advanced Processing}

All header parameters can be defined as \sic{} variables for specific
processing of the data, either as Read-Only or as Read-Write, using the
command {\tt SET VARIABLE}. Read-Write mode is to be used with caution,
since even critical variables (\eg{} the number of channels) can be
modified. Refer to command \comm{SET}{VARIABLE} for more details.

By using the appropriate variables and the \sic{} mathematical and logical
facilities, customized data processing becomes possible, as well as
complete data editing.

\section{Spectra Line Processing}

\subsection{Plotting Spectra}

Plotting spectra is controlled by several parameters:
\begin{itemize}
\item \comm{SET}{UNIT} {\tt Type} defines the unit of the X axis, which may
  be C (for Channel number), V (for Velocity), F (for Frequency) or I (for
  Image).
\item \comm{SET}{PLOT} {\tt Type} defines the plotting type {\tt PLOT}
  (Normal or Histogram); Normal gives straight lines connecting the data
  points (this is the default since it is faster). Histogram gives a more
  realistic representation of spectroscopic data.
\item \comm{SET}{MODE} {\tt X (or Y) Type} defines the plotting limits in X
  or Y, where type stands for {\tt TOTAL} (all channels plotted in X,
  complete scale in Y), {\tt AUTO} (take the plotting limits in use when
  the spectrum was last written), or two numbers for fixed limits; X or Y
  specify the axis on which the type is to apply. For X axis, the limits
  are in the current units (C, V or F).  For F, specify the offset from the
  rest frequency in MHz (note: the caption and the numbers on the axis will
  refer to absolute rest frequencies).
\end{itemize}

\subsubsection{Single spectrum}

Single spectrum are usually plotted using the following commands:
\begin{itemize}
\item \com{BOX}, which plots the frame. The Y axes are labelled in
  temperature units; the X axes may be in the following units: Velocity,
  Frequency, Image frequency, or Channel number. The upper X axis may be
  labelled in a different unit than that of the lower axis. Units for both
  axes are entered by the command \comm{SET}{UNIT} {\tt L U}, where L and U
  stand for the units of lower and upper axes and may be any of V, F, I, or
  C. The second parameter U is optional; if not entered, it defaults to L.
  
  \index{BOX!/UNIT} {\tt BOX} accepts the option {\tt /UNIT} which
  specifies a unit temporarily different from the current one (given by the
  {\tt SET UNIT} command). The parameter {\tt UPPER} will modify only the
  unit for the upper axis of the frame.  For instance: {\tt BOX /UNIT F
    UPPER} will give velocities on the lower axis (if this is the current
  unit specified by {\tt SET UNIT V}) and rest frequencies on the upper
  axis.
\item \com{SPECTRUM}, which plots the spectrum, in the current mode,
  clipped into the current box. An offset may be given as argument to plot
  two spectra above each other for comparison.
\item \com{TITLE}, which writes a header above the frame. The title format
  is controlled by the \comm{SET}{FORMAT} command.
\item \com{PLOT}, which performs all of {\tt CLEAR; BOX; SPECTRUM; TITLE}
  in a single operation.
\end{itemize}

\subsubsection{Spectra map}

Using the \com{MAP} command, it is possible to produce a plot of spectra in
the current index, arranged in a map.  Use the option {\tt /CELL Size\_x
  Size\_y}\index{MAP!/CELL} to specify the size of a spectrum, in current
angle units. Without this option a default is taken (the actual separation
of the spectra). Option {\tt /GRID} \index{MAP!/GRID} will produce frames
around the spectra. The argument {\tt MATCH} can be given to fix the aspect
ratio of the boxes to the cell sizes.

The map size can be controlled using commands {\tt SET PAGE} and {\tt SET
  BOX\_LOCATION}. Labels can be suppressed by option {\tt /NOLABEL}
\index{MAP!/NOLABEL} (and ticks will not be drawn if of size 0.0).  Option
{\tt /NUMBER} \index{MAP!/NUMBER} will add the observation number with each
spectrum.

After the {\tt MAP} command has been used, the \com{POPUP} command may be
used to display in another window a spectrum selected either from its
observation number or from its offsets. {\tt POPUP} can also be used after
the \com{STAMP} command. The {\tt STAMP} command allows to display many
observations at once, without requesting the X and Y axis scales to be
fixed.

\subsubsection{Large set of spectra}

An efficient way to look at a large set of coherent spectra (\eg{} observed
in OTF mode) is to plot them as a 2-D image where the intensity is colour
coded. The image is formed by applying the {\tt LOAD} on the current index.
Then the {\tt /INDEX} option modify the single spectra plotting commands as
follow:
\begin{itemize}
\item \comm{BOX}{/INDEX}, which plots the frame, \ie{} the entry number (Y axis) as
  a function of the velocity and/or frequency (X axis). The ranges of X and
  Y axes are controlled by the \com{SET MODE} command. {\tt SET MODE Y}
  always control the intensity range.
\item \comm{SPECTRUM}{/INDEX}, which plots the image.
\item \comm{TITLE}{/INDEX}, which writes a header above the frame. Range of
  parameters (\eg{} scan number, beta and lambda offsets, ...) are written.
\item \comm{PLOT}{/INDEX}, which performs all of {\tt CLEAR; BOX /INDEX;
    SPECTRUM /INDEX; TITLE /INDEX} in a single operation.
\end{itemize}

\subsection{Removing Baselines}

The \com{BASE} command subtracts polynomial baselines of degree $< 30$.
The fitting algorithm uses Chebyshev polynomials, and does not allow any
extrapolation outside the fitting range. It is thus important to fit the
baseline out to the maximum extension of the wanted spectrum. If
extrapolation is needed, a constant value will be used outside the fitting
range, equal to the polynom value at the boundary. The algorithm warns if
the polynomial degree is too high. See section~\ref{cook6} for a typical
baseline fitting session.

The user first defines line windows by the command \comm{SET}{WINDOW} with
the following syntax:
\begin{verbatim}
  SET WINDOW [wl1 wu1 [wl2 wu2 [...]]] [/VAR array]
             [/POLYGON [N] [filename1...filenameN]]
             [/NOCURSOR]
\end{verbatim}
The {\tt POLYGON} option enable the definition of 2D polygons on
images obtain with {\tt LOAD; PLOT /INDEX} when working on all the
index.  Line window values may be entered numerically as arguments,
red from variables and line polygons may be red from input files. If
available, the cursor may be used to define the windows or polygons.
In the window case, enter the values in the same order as above by
typing ``N'' or ``{} '' (space bar); ``C'' cancels the last value
entered; ``H'' types a help message and ``E'' terminates the
operation. In the case of polygons, each left clic defines a gon and a
right clic terminates the operations. The polygons may leak out of the
image. Several polygons may be defined in case the line appear at very
different velocities.

Up to 100 windows or 5 polygons may be defined. \com{BASE} then fits a
polynomial to the part of the spectrum outside the line windows. However,
only the ``visible'' parts of the spectrum are used and bad channels are
taken out.  The degree of the polynomial is defined by \comm{SET}{BASE}
{\tt n}, or temporarily by the {\tt BASE} command itself with its argument.

Sinusoidal baselines may also be subtracted, using the command
\comm{BASE}{SINUS} {\tt Amplitude Period Phase} where {\tt Amplitude}, {\tt
  Period} and {\tt Phase} are initial guesses for a minimization routine.
A linear baseline is added to the sinusoid in any case.

\index{BASE!/PLOT} When working on an individual spectrum (not the index),
the {\tt /PLOT} option plots the fitted baseline in the current box. The
area in the windows as well as the rms noise, are computed.
A baseline can be computed for one spectrum, and then subtracted from a
different one using \comm{BASE}{LAST}. This may be helpful for example at
Pico-Veleta where you may remove from the 100 kHz backend the baseline
determined from the 1 MHz one. Be sure that you do not change the X-unit
between the time you computed the baseline and the time you remove it...

When working on the whole index, the baseline are fitted spectrum per
spectrum and the baseline--corrected spectra are stored in the 2D array
ready for plotting with the next {\tt PLOT /INDEX} command. However,
baseline fitting results are lost and an explicit loop on the index entry
must be use including a new baseline computation) to store the results with
the {\tt WRITE} command.
% JP: BASE /INDEX /PLOT could directly plot the results.

\subsection{Folding Frequency Switched Spectra}

Spectra obtained by Frequency Switching need to be folded to obtain the
source spectra. It is usually a good idea to remove a baseline before the
spectra are folded in order to use as much baseline as possible.  The
folding is done by command \com{FOLD} which reads from the corresponding
section all the necessary parameters. {\tt FOLD} only operates on the {\tt
  R} buffer.  The number of channels is decreased to keep only the relevant
part of the resulting spectrum.

\subsection{Adding Spectra}

Four parameters define the way spectra are added. These are the align mode,
the combination mode, the integration weighting, and the behaviour with
respect to bad channels.

Four alignment modes are available, by the means of the command
\comm{SET}{ALIGN} {\tt Mode}:
\begin{itemize}
\item{\tt CHANNEL} in which spectra are added channel by channel. This is
  only useful when the spectra have been obtained in strictly identic
  conditions.  Warning messages are given when this is not the case.
\item{\tt VELOCITY} in which the velocity scale is used to align the
  spectra.  This enables you to add spectra of different origin. An
  interpolation is performed if needed. If individual spectra have
  differing spectral resolutions, the lowest spectral resolution is used
  for the result.
\item{\tt FREQUENCY} in which the rest frequency is used to align the
  spectra.
\item{\tt POSITION}, in which continuum drifts are aligned regarding to the
  position along the drift.
\end{itemize}
{\tt CHANNEL, VELOCITY} and {\tt FREQUENCY} are relevant for Line
observations, while {\tt POSITION} is relevant only for Continuum
observations. Two combination modes are possible with the command {\tt SET
  ALIGN MODE Combination}:
\begin{itemize}
\item{\tt INTERSECT} where only the intersection of individual spectra is
  kept.
\item{\tt COMPOSITE} where the reunion of the individual spectra is kept
  (as in a spectral scan for example).
\end{itemize}
Three weighting types may be used, with the command \comm{SET}{WEIGHT} {\tt
  Type}:
\begin{itemize}
\item{\tt TIME} for weights proportional to the observing time, divided by
  the square of the system noise.
\item{\tt SIGMA} for weighting by the inverse square of the rms noise of
  each individual spectrum.
\item{\tt NONE or EQUAL} for equal weighting. Caution: equal weighting
  behaves differently in \com{AVERAGE} and \com{ACCUMULATE}
  commands. {\tt AVERAGE} produces the average of spectra, while {\tt
  ACCUMULATE} gives the sum of the two spectra.  After division by the
  number of added spectra, {\tt ACCUMULATE} will thus give the same
  result as {\tt AVERAGE}.
\end{itemize}
Bad channels are dealt with in two possible ways, defined by the command
\comm{SET}{BAD Mode}:
\begin{itemize}
\item{\tt OR} where resulting channels are declared bad if they were
  declared as such in at least one of the individual spectra.
\item{\tt AND} where resulting channels are declared bad if they were bad
  in all individual spectra.
\end{itemize}
Default values are {\tt ALIGN CHANNEL INTERSECT}, {\tt WEIGHT TIME}, and
{\tt BAD OR}.

Two other parameters control whether summing spectra is allowed or not.
Positions are checked according to \comm{SET}{MATCH} {\tt Tolerance} or
\comm{SET}{NOMATCH}. If (absolute) positions differ by more than the
tolerance parameter, an error message is generated. The tolerance is
specified in current angle units. The homogeneity of the calibration is
checked according to the \comm{SET}{CALIBRATION} {\tt Beam\_Tolerance
  Gain\_Tolerance} or {\tt SET CALIBRATION OFF} \index{SET!CALIBRATION}
commands. Beam\_Tolerance is the maximum difference allowed in the beam
efficiencies to add spectra (default 0.02) and Gain\_Tolerance the maximum
difference between the gains in the image band (default 0, which means not
checked).

There are two ways of adding spectra: the commands \com{AVERAGE} and
\com{ACCUMULATE}. {\tt AVERAGE} operates globally on all the spectra
in the index, while {\tt ACCUMULATE} adds the {\tt R} and {\tt T}
buffers into {\tt R}. {\tt AVERAGE} is generally better for systematic
methods, {\tt ACCUMULATE} for special cases. The drawback of {\tt
ACCUMULATE} is in the need for initialization; one needs a spectrum in
{\tt T} and a spectrum in {\tt R} to begin with...

\subsection{Analyzing profiles}

The \class{} user may analyse spectra by fitting profiles. The fitting
commands are available from the \fit{} language. The minimization method is
taken from the MINUIT system of CERN, modified and optimized for this
purpose. Reliability proved to be good. Five types of profiles are
presently available, and can be selected by the \com{METHOD} command:
\begin{itemize}
\item \comm{METHOD}{GAUSS} This is the default type of profile. One may use
  up to 10 Gaussians, which might depend on each other as specified by a
  system of control codes associated with each variable. For each of these
  Gaussians, the primary parameters are: 1) Area, 2) Position, and 3) Width
  (FWHM). The current X unit (for the lower axis) is used. Code 0 means
  that the parameter is adjustable; 1 that it is fixed; 2 that the
  parameter (head of group) is adjustable and that another parameter, coded
  3, is fixed with respect to it; 4 that the parameter is a fixed head of
  group.
\item \comm{METHOD}{SHELL} (see details below) Profiles are like those
  encountered in envelopes of stars. The primary parameters are Area,
  Position, Width and Horn to Center ratio. The aspect of the profile
  varies from parabola (as obtain in optically thick lines) for
  Horn/Center = -1 to flat-topped lines (unresolved optically thin
  lines) for Horn/Center = 0 and double peaked profiles (resolved
  optically thin lines) for Horn/Center {\tt >} 0. The profile is
  symmetric.  Presently only code 0 and 1 can be used, and up to 10
  independent lines can be fitted in a single spectrum. The X unit
  must be frequency.
\item \comm{METHOD}{NH3}{\tt(1,1) or NH3(2,2) or NH3(3,3)}\\
  Profiles taking into account hyperfine structure of ammonia with a
  Gaussian distribution of velocity are fitted. Primary variables are 1)
  The product (Main Group Opacity) times (Excitation Temperature minus
  Background Temperature) 2) Velocity 3) Line Width (FWHM) and 4) Main
  Group Opacity.  Up to 10 independent lines can be fitted, and only codes
  0 and 1 are allowed. The X unit must be Velocity.
\item \comm{METHOD}{HFS} {\tt FileName} This method is similar to the
  previous one, but the HyperFine Structure parameters are read from a file
  instead of being known by \class{} .  The first line of this file must
  contain the number of hyperfine components ($< 40$). The other lines must
  contain, for each component, the velocity offset and the relative
  intensity. The parameters are the same as for NH3 method.
\item \comm{METHOD}{CONTINUUM} This method is used for continuum drifts. It
  fits a Gaussian and a linear baseline in the drift. If beam-switching was
  used and the reference beam is along the drift direction, two dependent
  Gaussian are used to optimize signal to noise. The method does not
  require any user input.
\end{itemize}

\comm{METHOD}{SHELL} in details. The fitted function is:

\def\area{\ensuremath{{\cal A}}}
\def\fwhm{\ensuremath{\Delta \nu}}
\def\kms{km.s\ensuremath{^{-1}}}

$$ f(\nu) = \frac{\area}{\fwhm}\,
\frac{1+4H\,[(\nu-\nu_0)/\fwhm]^2}{1+H/3}
$$ where the fitted parameters are:
\begin{enumerate}
  \item \area: the area under the profile (in K MHz),
  \item $\nu_0$: the middle frequency (in MHz),
  \item \fwhm/2: the half width at zero level (in MHz),
  \item $H$: the Horn/Center parameter (dimensionless, see below)
\end{enumerate}

The central value is $f(\nu_0) = \frac{\area}{\fwhm}\frac{1}{1+H/3}$
whilst the value at the edge is $f(\nu_0+\fwhm/2) =
\frac{\area}{\fwhm}\frac{1+H}{1+H/3}$. The edge-to-center intensity
ratio value is thus dictated by the Horn/Center parameter $H$
according to $$\frac{f(\fwhm/2)}{f(0)} = 1 + H$$

The center-to-edge frequency shift corresponds to an expanding
velocity
$$
v_{\rm exp} = c\,\frac{\fwhm /2}{\nu_0}
$$

Figure~\ref{fig:shell} shows synthetic shell-like profiles, for which
the area takes values $\area=5$ to 20 by 5~K~MHz. The full width at
zero level is $\fwhm=3.83$~MHz in all cases, which corresponds to
$v_{\rm exp}=2.49$~\kms at 230.537~GHz. The Horn/Center parameter is
$H=5$ (top) or $H=-1$ (bottom, for which the intensity at the edge is
zero).

\begin{figure}
  \centering
  \includegraphics[height=0.6\hsize]{class-shell-1}\bigskip\\
  \includegraphics[height=0.6\hsize]{class-shell-2}
  \caption{Four synthetic shell-like profiles, corresponding to
           increasing areas $\area=5$ to 20 by 5~K~MHz, a \fwhm\ of
           3.83~MHz or $v_{\rm exp}=2.49$~\kms at 230.537~GHz. The
           results of fitted shell profiles are indicated at the
           top. The upper scale is \kms. {\textit Top}: The
           Horn/Center parameter is $H=5$. {\textit Bottom}: Same as
           above for $H=-1$. }
  \label{fig:shell}
\end{figure}

\bigskip
The \fit{} commands are:
\begin{itemize}
\item \com{LINES} {\tt N} defines the number of components and prompts for
  the initial values of the parameters for each component. This command has
  no effect for method {\tt CONTINUUM}.  Parameters are read in list
  directed format in the following order:
\begin{verbatim}
    Code, Intensity, Code, Position, Code, Width, [Code, Parameter 4]
\end{verbatim}
  The code is an integer number between 0 and 4. Note that, though the
  program works on the area (or other quantities as for {\tt NH3} methods),
  you have to give the intensity, since this quantity is more intuitive
  than area. The use of the list directed format makes things easier when
  only one parameter has to be modified (cf Fortran norms). The number of
  lines N may be zero; in this case the program finds out reasonable
  starting values by itself.
  
  Values may be also entered graphically if the cursor is
  available. After entering {\tt LINES N}, first point the cursor to
  one side of the line, strike one key, point the cursor the other
  side, strike another key. The program computes the moment of the
  spectrum between these boundaries and use it to set up starting
  values.  Proceed like this for all components. One drawback of this
  way of entering values is that you cannot change the control
  codes. It should be used only for entirely independent and free
  lines.
\item \com{MINIMIZE} activates minimization, then prints out the results
  after convergence. A Simplex method is first used to ensure convergence,
  then a Gradient method to refine the results, and compute the errors.
\item \com{ITERATE} is similar to {\tt MINIMIZE}, but starts from the
  previous minimization results. Only the Gradient method is used.
  Consequently, this command is only useful close to the minimum.
\item \com{VISUALIZE} {\tt [N] [/PEN]} plots the $N$th component obtained
  by fitting; if $N$ is not given, the sum of all components is plotted.
\item \com{RESIDUAL} {\tt N} subtracts the Nth component from the current
  spectrum, or the sum of all components is N is not given). In this
  process, the {\tt R} spectrum is first copied into {\tt T}, then the
  difference is done in {\tt R}.
\item \com{DISPLAY} Prints the results of fitting from the current
  spectrum, without recomputing it ...
\item \com{KEEP} Saves the fit results in the input file, which must be
  opened also for output. {\tt KEEP} is in fact a reduced version of {\tt
    UPDATE}, and to be used with the same care as {\tt UPDATE}.
\item \comm{SET}{MASK} {\tt ...} Defines masks in the spectrum for the fit.
  This commands has the same syntax and behaviour as {\tt SET WINDOW}.
  Masked regions will not be used for the fit.
\end{itemize}
Fit results are always saved by a {\tt WRITE} command and made available
through the corresponding variable section (see {\tt SET VARIABLE} help).

\subsection{Gridding Spectra on a 3-D Data Cube}

See memo IRAM 2005-1 (CLASS evolution: I. Improved OFT support) available here 

\texttt{http://iram-institute.org/medias/uploads/class-evol1.pdf}

\subsection{Miscellaneous}

\begin{itemize}
\item \com{DIVIDE} makes the ratio of the {\tt R} and {\tt T} spectra. The two spectra
  must have the same velocity scale.
\item \com{FFT} plots the power spectrum of the current observation.  It
  might help identify spurious ripples. Editing of the fourier transform is
  possible, so that these ripples may be suppressed.
\item \com{NOISE} generates a Gaussian noise as intense as in the current
  spectrum using the rms value determined by the \com{BASE} command, or
  using a rms value given as an argument. {\tt NOISE Value NEW} will create
  a noisy spectrum of given noise level into {\tt R}, after copying {\tt R} in {\tt T}.
\item \com{RESAMPLE} resamples the {\tt R} spectrum on the specified grid. If the
  final sampling is coarser than the original one, a smoothing occurs to
  the final sampling.
\item \com{SMOOTH} operates a Hanning smoothing by default and divide the
  number of channels by two. Other arguments can be specified to use other
  methods.  \comm{SMOOTH}{AUTO} uses a sophisticated variable-resolution
  algorithm, but it requires the channels to be really independent and this
  is apparently seldom the case in radio astronomy. {\tt SMOOTH GAUSS
    Width} convolves the spectrum by Gaussian of given Width in current
  units; it does not take care of bad channels. {\tt SMOOTH BOX N} make
  the average of N adjacent channels and divides the number of channels by
  N.
\end{itemize}

\section{Continuum and Skydip Processing}

\subsection{Continuum}

So far, we have handled only Spectroscopic data, but Continuum data can be
processed by \class{} . Currently, only continuum drifts can be reduced. The
basic idea is to treat continuum drifts as spectra would be. Accordingly,
very few commands behave differently in Continuum and Spectroscopy modes.

Continuum mode is accessed by typing the \comm{SET}{TYPE} {\tt CONTINUUM}
command.  The prompt then changes to {\tt CAS>} (Continuum Analysis
System). You can return to Spectroscopy mode later on typing the {\tt SET
  TYPE SPECTROSCOPY or LINE} command and the prompt changes to {\tt LAS>}
(Line Analysis System).

Some commands have slightly different behaviour in Spectroscopy and
Continuum modes.
\begin{itemize}
\item{\tt SET UNIT} has no effect in Continuum mode.
\item{\tt SET ANGLE} also controls the plotting units in Continuum mode.
\item{\tt METHOD}: only {\tt GAUSS} and {\tt CONTINUUM} methods are allowed
  in Continuum mode.
\item{\tt LINES} has no effect with {\tt CONTINUUM} method.
\item{\tt HEADER} uses a different format for Continuum and Spectroscopy
  modes.
\item{\tt STRIP} produces a map from a set of parallel drifts. The index
  must define such a set of drifts.
\item FITS format support is experimental for continuum data.
\item With {\tt CONTINUUM} method, {\tt PRINT FIT} command only outputs a
  single component, and the component number is not written.
\item {\tt SET ALIGN CHANNELS} and {\tt SET ALIGN POSITION} are the only
  available alignment modes in Continuum mode.
\end{itemize}
Except for these restrictions, the behaviour of other commands is similar.
Note that command {\tt FIND} only selects data of the current type.

\subsection{Skydip Processing}

\class{} is able to reduce skydip data. Skydip mode must be selected using
command \comm{SET}{MODE} {\tt SKYDIP} which also changes the prompt to {\tt
  SAS>} (Skydip Analysis System).  Commands {\tt FIND, HEADER, GET, PLOT}
and {\tt WRITE} may be used as for Continuum and Line modes, but the only
other valid command is \com{REDUCE} which fits the sky emission using
atmospheric information available in the data, and displays the results.

\section{Communication with the outer world}

\subsection{Listing Scientifically Valuable Results}

Command \com{PRINT} offers a way to list a number of valuable information
on screen or in an ASCII/binary file:
\begin{itemize}
\item \comm{PRINT}{FIT}, which prints the results of profile fits. For each
  spectrum, N lines are written (N being the number of fitted components),
  and each line contains in the following order (1) the component number,
  (2) then observation number, (3,4) the two cartography offsets, (5,6)
  area of Gaussian and corresponding error, (7,8) same for position, (9,10)
  same for width, (11) intensity, (12,13) rms on the baseline and on the
  line. Offset are in the current coordinate system and units. The current
  method is used.
  
  For Continuum method, only a single Gaussian is written. The written
  information is oriented towards pointing measurements: (1) the
  observation number (2,3) Azimuth and elevation (4,5) area of Gaussian and
  error, (6,7) position, (8,9) width, (10) intensity, (11,12) rms on
  baseline and signal, (13,14) collimations.  All angular values are in the
  current angle unit. The values are followed by the source name.
\item \comm{PRINT}{AREA}, prints the area of the line computed by the {\tt
    BASE} command. Each line contains (1,2) offsets, (3) area, (4) rms
  noise. {\tt PRINT AREA V1 V2 V3 V4 ...}, prints areas within velocity
  slices (if such is the current X unit, but one could use channels or
  frequencies).  Ranges are V1-V2, V2-V3, V3-V4, ... etc. Each line will
  contain (1,2) the offsets, followed by the areas in order.
\item \comm{PRINT}{CHANNEL} {\tt List}, prints values of channels in the
  list. The list is specified in the FOR n1 TO n2 BY n3 format.  Total
  number of channels is however limited to 15.
\item \comm{PRINT}{MOMENT} {\tt V1 V2 V3 V4 ...}, prints moments (area,
  position, width), of the data within the velocity (or channels or
  frequencies, depending on the current units) V1-V2, V3-V4, etc... Each
  line contains (1,2) the offsets, (3,4,5) the moments for V1-V2, (6,7,8)
  for V3-V4 etc...
\item \comm{PRINT}{POINTING}, prints results of CONTINUUM method fits
  printed in a format adapted to pointing constants measurements.  The
  output is suited for further processing and determination of pointing
  constants using the \point{} program.
\item \comm{PRINT}{FLUX}, prints results of CONTINUUM method fits printed
  in a format adapted to flux determination. The output is suited for
  further processing using the \flux{} program.
\end{itemize}
\index{PRINT!/OUTPUT} As all commands using a set of spectra, {\tt PRINT}
works on the whole current index. Output is by default printed on the
screen, but may be directed onto a file by the {\tt /OUTPUT Filename}
option.

Alternatively, the same information may be written to a ``Table'' (a
special kind of \gildas{} image). The Table format is much faster and
suppresses some of the limitations of the formatted output on the number of
columns written.  \index{PRINT!/TABLE} Table format is obtained using
option {\tt /TABLE Tablename}.

\subsection{Making Publishable Quality Figures}

\class{} has many functionalities to directly produce publishable quality
Figures. All the \greg{} commands are imported in \class{} to fully annotate
plots, superpose spectra with related data, stack various plots and then
make hardcopy (like Post-Scripts files). A few guidelines are given here on
essential \greg{} commands. For more details, users are advised to read the
\greg{} manual.

Moreover, \class{} commands like \com{DRAW} and \com{GREG} implements fancy
functionalities of common use when producing figures around spectra.

\subsubsection{\greg{} functionalities}

\class{} is mainly used for interactive look at spectra, hence its default
values are all oriented towards fast plotting on screen. These defaults can
be changed by command {\tt SET}. If the value of a parameter is not
controlled by \class{}, the command will be passed on to \greg{} for
processing.

The following \greg{} presentation parameters are useful:
\begin{itemize}
\item {\tt SET BOX\_LOCATION} It can be set {\tt to LANDSCAPE, PORTRAIT,
    SQUARE} or 4 numbers indicating the position of the box in the plot
  page (in centimeters).
\item {\tt SET CHARACTER Size} Control the size of characters in
  centimeters.
\item {\tt SET FONT Quality} Select the character quality to be used, {\tt
    SIMPLEX} or {\tt DUPLEX}.  The fonts are identical to the ones used by
  \greg{} , and the character handling is the same (in command {\tt DRAW
    TEXT}).
\item {\tt SET PLOT\_PAGE ...} Define the page size. Warning: You will get
  into trouble if you want to abreviate this command to {\tt SET PLOT} as
  {\tt SET PLOT} is a valid \class{} command used to indicate whether
  spectra are broken lines of histograms. A way out of this is to
  abbreviate the \greg{} command as {\tt G$\backslash$SET PLOT}.
\item{\tt SET TICK Size} Define the tick size in centimeters.
\end{itemize}

Note that you do not need to open a plotting window to produce a hardcopy
through the {\tt HARDCOPY} command. It is only much more convenient, but
the plot (\eg{} sequence of commands) and the way it is displayed (\eg{} PS
format, bitmap on a computer screen) are two completely independent things.

\subsubsection{Bridge toward \greg{} functionalities}

The spectra and the results of their analysis (like the fits) are in
\class{} internal buffers not always easily accessible for plotting with
the \greg{} commands. \class{} thus implements the \com{GREG} command which
is intended to produce a direct interface with \greg{} for plots of
spectra.  It creates a \gildas{} table which can be read using the standard
\greg{} commands for further plotting. The table contains the following
columns for Spectra:
\begin{verbatim}
1. Intensity
2. Channel number
3. Velocity
4. Offset frequency
5. Rest frequency
6. Image frequency
7. Fitted profiles if any - fit(i),i=0,nline - in column 7+i, 
   for the current method.
\end{verbatim}
The output table can be put later in a formatted way using \gildas{} task
{\tt LIST} if needed. For continuum data, the table contains
\begin{verbatim}
1. Intensity
2. Channel number
3. Angular offset (radian)
4. Fitted profile if any.
\end{verbatim}

The table may be used as input to \greg{} to produce fancy plots, or by the
\gildas{} software for other applications. In particular, the \sic{}
monitor (command {\tt LET}) is able to subtract any of the fits from the
spectrum to produce residuals if needed.  It is possible to merge different
tables, add columns to a table, etc...  For example, from two spectra at
the same velocity resolution it is possible to merge the two tables and
compute the ratio of the spectra, as well as the errors on this ratio.

\subsubsection{Annotations}

\class{} has two \com{DRAW} commands to annotate plots: \emph{i)} The
standard \greg{} {\tt DRAW} command which can be accessed by typing {\tt
  G$\backslash$DRAW} (please look at the \greg{} manual) and \emph{ii} a
special flavor of {\tt DRAW} customized for annotating spectra. The
\class{} flavor is the default one used when typing just {\tt DRAW} The
basic operations performed by this flavor of the {\tt DRAW} command are:
\begin{itemize}
\item \comm{DRAW}{TEXT} {\tt Xpos Ypos "Text" Centering} to draw a text at
  position (Xpos,Ypos) (in current units) with the specified centering
  code. This command works more or less like the \greg{} command of same
  name. Please refer to the \greg{} manual for details.  In particular, you
  can include Greek letters and Symbols in the text using the escape
  character $\backslash$. A strange thing may appear on the screen, but it
  is O.K. on the plot.
\item \comm{DRAW}{UPPER} {\tt Xpos "Text"} to draw a vertically
  oriented text at position Xpos, with a vertical line connecting the
  beginning of the text to the current spectrum. This text and line are
  written at position Xpos, in units of the upper axis.  Typically, this
  command is used to mark spectral line identifications.
\item \comm{DRAW}{LOWER} {\tt Xpos "Text"} same as above, but with Xpos in
  units of the lower axis.
\item \comm{DRAW}{WINDOW} {\tt[Level]} shows the current line
  windows by marks on the graphic plot. Level is an optional arguments
  indicating at what Y value the marker should be put (Default 0).
\item \comm{DRAW}{MASK} {\tt [Level]} same as above but for the
  current masks.
\item \comm{DRAW}{KILL} {\tt [Channel]} kills the specified
  channel (current one if using the cursor) by attributing it the
  ``blanking'' or ``undefined'' value.
\item \comm{DRAW}{FILL} {\tt [Channel]} Fills the specified
  channel (current one if using the cursor) by interpolation between the
  nearest non-blanked channels. The channel must have been killed before.
\end{itemize}
Any other character will not draw anything, but simply returns the cursor
position, with corresponding values of the velocity, frequency, image
frequency, channel number.

\subsection{Importing and Exporting Spectra From and To FITS}

No data reduction package has all the functionalities any user dream about.
But a user may know that the functionality he needs is available in a very
specific package. Here comes the need to exchange data between packages.
The current standard answer to this problem is FITS. \class{} to FITS
conversion (and vice-versa) is done by command {\tt FITS}. In addition, all
functionalities provided by the \sic{} command {\tt DEFINE FITS} are of
course available.  For a description of the FITS format see the original
paper by Wells et al.  (Astron. and Astrophys. Suppl.).

The \class{} {\tt FITS} command has the following syntax:
\begin{verbatim}
   FITS READ Filename[.fits]
\end{verbatim}
to read a FITS file and create \class{} data from it, or
\begin{verbatim}
   FITS WRITE Filename[.fits] [/BITS Nbits] [/MODE SPECTRUM|INDEX]
\end{verbatim}
to write a FITS file from \class{} data.

In addition, default values can be supplied by the {\tt SET FITS} command.
\begin{verbatim}
    SET FITS BITS Nbits
    SET FITS MODE Spectrum|Index|None
\end{verbatim}

\subsubsection{From FITS to CLASS}

\begin{verbatim}
   FITS READ Filename[.fits]
\end{verbatim}
will read a FITS file and create \class{} data from it. It is expected to
work under the following conditions:
\begin{enumerate}
\item The \texttt{Filename.fits} file contains one spectrum, with (a subset
  of) the FITS keywords which are described in the previous section.  FITS
  Keyword redefinition is possible.
\item \textbf{OR} The \texttt{Filename.fits} contains a BINTABLE, also with
  recognized FITS keywords.
\item \textbf{No more, no less}
\end{enumerate}
This may look akwardly restrictive, but is already powerful if you have
thought about your data destination when creating the FITS file.

%% \textbf{Moreover}, \class{} offers a very general way to read \textbf{any}
%% FITS file and create a \class{} data file from it. This can be done using
%% the \texttt{DEFINE FITS} command of \sic, combined with the \texttt{MODEL}
%% command of \class . An example of a simple \class{} procedure to do so is
%% given below

%% \begin{verbatim}
%% ! Usage: @ fits_to_class Fits_DataCube_file_name 
%% define fits a &1  
%% sic\let num 0 /new integer 
%% set priv on 
%% ! 
%% sic\for m 1 to a%dim[3] 
%%   sic\for l 1 to a%dim[2] 
%%     let num = num+1             ! Load the data array 
%%     if (a%ndim.eq.3) then 
%%       analyse\model a[l,m] 
%%     else if (a%ndim.eq.4.and.a%dim[4].eq.1) then 
%%       analyse\model a[l,m,1] 
%%     else 
%%       say "Cube is not a cube. Please check dimensions in header" 
%%       set priv off 
%%       pause 
%%     endif 
%% ! Produce a meaningful header 
%%     let lambda = a%convert[2,2] 
%%     let off_lambda = (l-a%convert[1,2])*a%convert[3,2] 
%%     let beta = a%convert[2,3] 
%%     let off_beta = (m-a%convert[1,3])*a%convert[3,3] 
%%     let source = a%source 
%%     let line = a%line 
%% ! Assume a velocity axis, would have to be changed for a frequency axis 
%%     let velocity = a%convert[2,1] 
%%     let velo_step = a%convert[3,1] 
%%     let reference = a%convert[1,1]    ! reference pixel of velocity axis 
%%     let frequency = a%restfre   ! Presumably undefined for a foreign cube ... 
%%     let freq_step = a%freqres   ! 
%%     las\modify teles "Edit_procedure" 
%%     las\write num 
%%   sic\next 
%% sic\next 
%% set priv off
%% \end{verbatim}

\subsubsection{FITS Keyword redefinition}

A minimal number of keywords has been defined as part of the FITS standard,
but additional ones can be (and have been) added by various groups to
support their own needs.  Thus, several ``flavors'' of FITS coexist. A
detailed description of the \class{} FITS flavors is given in
chapter~\ref{sec:developer}. Unknown keywords are normally ignored, but
\class{} supports FITS keyword redefinition. If you receive a file with
scan number coded as {\tt NUMBER} (instead of {\tt SCAN-NUM}), all you need
to do is to define a SIC symbol named {\tt NUMBER} with translation {\tt
  SCAN-NUM}. This is done by typing {\tt SIC$\backslash$SYMBOL NUMBER
  SCAN-NUM}.

\subsubsection{From \class{} to FITS}

To write a FITS file from \class{} data, use the following command:
\begin{verbatim}
   FITS WRITE Filename[.fits] [/BITS Nbits] [/MODE SPECTRUM|INDEX]
\end{verbatim}

The command will create a simple FITS file from the current Spectrum (in
\texttt{SPECTRUM} mode), or a FITS BINTABLE from the current Index (in
\texttt{INDEX} mode). The number of bits can be controlled.  Default values
for the mode and the number of bits can be supplied by the {\tt SET FITS}
command.
\begin{verbatim}
    SET FITS BITS Nbits
    SET FITS MODE Spectrum|Index|None
\end{verbatim}
In \texttt{INDEX} mode, it is up to the user to make sure that the index is
consistent (same number of channels, etc..., for all spectra in index).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
