\subsection{TRICS NeXus Data Files}
This section describes the data file handling for the four circle
diffractometer TRICS at SinQ. TRICS collects a lot of detector frames in
time intervalls of days or weeks. The data writing scheme has to adress the
issue, that the HDF routines  cannot ensure that there is no data corruption
when writing data files. 

Thus the following scheme is implemented: With a special command, the user
enforces a new file. At that time header information is written. After that
the file is closed. With another command, the file is reopened and a frame
is added to it. Each frame data group will hold a flag which decides if the
frame is valid or not. After writing the frame, the file is closed again.
This scheme minimises the danger of data corruption.

The current frame number is kept in a non NeXus standard field in the data file
itself. This allows to reopen files and append data to it. 

The interface to this object looks like this:

\begin{flushleft} \small
\begin{minipage}{\linewidth} \label{scrap1}
$\langle$nxtrics {\footnotesize ?}$\rangle\equiv$
\vspace{-1ex}
\begin{list}{}{} \item
\mbox{}\verb@@\\
\mbox{}\verb@    typedef struct __NexTrics *pNexTrics;@\\
\mbox{}\verb@@\\
\mbox{}\verb@/*----------------------------- live & death -----------------------------*/@\\
\mbox{}\verb@  pNexTrics CreateNexTrics(pDataNumber pNum, char *pRoot, char *pDict,@\\
\mbox{}\verb@                           SicsInterp *pSics);@\\
\mbox{}\verb@  void      DeleteNexTrics(void *pData);@\\
\mbox{}\verb@@\\
\mbox{}\verb@  int NexTricsFactory(SConnection *pCon, SicsInterp *pSics, void *pData,@\\
\mbox{}\verb@                      int argc, char *argv[]);@\\
\mbox{}\verb@/*----------------------------- interaction ------------------------------*/@\\
\mbox{}\verb@@\\
\mbox{}\verb@  int StartFile(pNexTrics self, SConnection *pCon);@\\
\mbox{}\verb@ @\\
\mbox{}\verb@  int ReopenFile(pNexTrics self, char *filename);@\\
\mbox{}\verb@@\\
\mbox{}\verb@  int DumpFrame(pNexTrics self, SConnection *pCon);@\\
\mbox{}\verb@@\\
\mbox{}\verb@  int NexTricsAction(SConnection *pCon, SicsInterp *pSics, void *pData,@\\
\mbox{}\verb@                      int argc, char *argv[]);@\\
\mbox{}\verb@ @\\
\mbox{}\verb@@$\diamond$
\end{list}
\vspace{-1ex}
\footnotesize\addtolength{\baselineskip}{-1ex}
\begin{list}{}{\setlength{\itemsep}{-\parsep}\setlength{\itemindent}{-\leftmargin}}
\item Macro referenced in scrap ?.
\end{list}
\end{minipage}\\[4ex]
\end{flushleft}
\begin{description}
\item[CreateNexTrics] creates a new TRICS NeXus data file writing object.
Parameters are a data number object for the automatic creation of file names
and the directory name where the data files ought to live. The next
parameter is the name of the NeXus dictionary file to use for writing.
\item[DeleteNexTrics] deletes a NexTrics object. The last parameter is the
name of the SICS interpreter to search for objects. NexTrics will maintain a
cache of frequently used SICS objects for writing. 
\item[NexTricsFactory] is the interpreter wrapper function for the command
to install the nexus data writing object for Trics into the system.
\item[StartFile] will automatically create a new file and write the header
information to it.
\item[DumpFrame] will dump a frame worth of data to the file. Thereby
reopening and closing it. This will be called for each detector shot, i.e.
in the end three frames will be written when all three detectors have been
installed at TRICS.
\item[NexTricsAction] is the command interface to the TRICS NeXus data file
writing object.
\end{description}

\begin{flushleft} \small
\begin{minipage}{\linewidth} \label{scrap2}
\verb@"nextrics.h"@ {\footnotesize ? }$\equiv$
\vspace{-1ex}
\begin{list}{}{} \item
\mbox{}\verb@@\\
\mbox{}\verb@/*----------------------------------------------------------------------------@\\
\mbox{}\verb@                           N E X T R I C S@\\
\mbox{}\verb@ @\\
\mbox{}\verb@  An object for writing NeXus data files for the four ciclre diffractometer@\\
\mbox{}\verb@  TRICS at PSI. Can be used as basis for writing files for other four@\\
\mbox{}\verb@  circles equiped with a PSD as well.@\\
\mbox{}\verb@@\\
\mbox{}\verb@  copyright: see copyright.h@\\
\mbox{}\verb@@\\
\mbox{}\verb@  Mark Koennecke, April 1998@\\
\mbox{}\verb@------------------------------------------------------------------------------*/@\\
\mbox{}\verb@#ifndef NEXTRICS@\\
\mbox{}\verb@#define NEXTRICS@\\
\mbox{}\verb@@$\langle$nxtrics {\footnotesize ?}$\rangle$\verb@@\\
\mbox{}\verb@#endif@\\
\mbox{}\verb@@$\diamond$
\end{list}
\vspace{-2ex}
\end{minipage}\\[4ex]
\end{flushleft}
