\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:

@d nxtrics @{
    typedef struct __NexTrics *pNexTrics;

/*----------------------------- live & death -----------------------------*/
  pNexTrics CreateNexTrics(pDataNumber pNum, char *pRoot, char *pDict,
                           SicsInterp *pSics);
  void      DeleteNexTrics(void *pData);

  int NexTricsFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
                      int argc, char *argv[]);
/*----------------------------- interaction ------------------------------*/

  int StartFile(pNexTrics self, SConnection *pCon);
 
  int ReopenFile(pNexTrics self, char *filename);

  int DumpFrame(pNexTrics self, SConnection *pCon);

  int NexTricsAction(SConnection *pCon, SicsInterp *pSics, void *pData,
                      int argc, char *argv[]);
 
@}

\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}

@o nextrics.h @{
/*----------------------------------------------------------------------------
                           N E X T R I C S
 
  An object for writing NeXus data files for the four ciclre diffractometer
  TRICS at PSI. Can be used as basis for writing files for other four
  circles equiped with a PSD as well.

  copyright: see copyright.h

  Mark Koennecke, April 1998
------------------------------------------------------------------------------*/
#ifndef NEXTRICS
#define NEXTRICS
@<nxtrics@>
#endif
@}
