- A couple of small fixes for memory and initialization problems.

This is to make valgrind happy


SKIPPED:
	psi/amorscan.c
	psi/el734hp.c
	psi/psi.c
	psi/tasscan.c
This commit is contained in:
koennecke
2005-01-12 08:42:39 +00:00
parent 5e05be17e0
commit ef1de4589c
35 changed files with 2659 additions and 1203 deletions

284
scan.w
View File

@ -1,35 +1,44 @@
\subsection{Scan}
The first version of the scan command was implemented in Tcl. This prooved
to be inefficient. Therefore the main loop for scan was reimplemented in
C. A scan is in principle simple. However some complications are due to the
fact that data files need to be written. Disk files need to be updated after
each scan point. It must be possible to create derivations of the scan
command which create other data formats or scan strategies. This
configurability is catered for the function pointers in the ScanData
structure. Individual functions can be exchanged and thus differently
behaving scans created.
to be inefficient. Therefore scan was reimplemented in C. Scanning
seems to be simple but is not because of the many special cases
involved:
\begin{itemize}
\item Scans must be interruptable and continuable
\item Data files need to be written in different formats
\item Different output has to be generated at various steps
\item In polarization measurements, several points with different
magnetic field orientations need to be measured at the same instrument
position.
\item Users might want to be specify complex scan paths or scan on
logarithmic axis.
\end{itemize}
I order to cope with all this, the scan module is modifiable in two
ways: For each step of the scanning process there is an overloadable
function in the scan data structure. The first way to modify scan
behavious thus is to write new functions in C and to assign them to
the scan module. In order to support scriptable scans another system
is in place: Stored in a string dictioanary there are the names of
SICS functions which will be called at each scan operation. The scan
functions then invoke the functions specified. In order for this to
work, the scan must be configured "newscan". These two schemes exits
because the scan module is in transition to a refactoring towards the
second scheme.
The principal setup thus is a central scan object which deals with
all the scan management: storing variables, positions, counting
results etc. and the configuration of the scan. This is augmented by
libraries of scan functions which get invoked at the various
steps. There is a standard scan library which is doumented here as well.
Another complication is, that users might want to interrupt scans and
restart from the last safe position. For this purpose
there exists the recover option.
Scan also uses a scheme for creating scan data data files from a
template. For more information about the template file see the SICS Managers
documentation.
There are currently two schemes for modifying scans: The first works
by implementing different scan handling functions and to assign them
to the function pointers in the ScanData structure. The second works
by defining a macro which will be called at each scan point and which
has to return the a list with the counts and monitors collected.
This has grown to be overly complex. A path for a redesign might
follow the idea of configurable functions to be called at various
steps in scan processing which is already partly implemented.
@d scandata @{
\subsubsection{Scan Variables}
Scan variables are held in this data structure:
@d scanvar @{
typedef struct {
char Name[132];
pIDrivable pInter;
@ -37,7 +46,91 @@ steps in scan processing which is already partly implemented.
float fStart;
float fStep;
float *fData;
int dataList;
}VarEntry, *pVarEntry;
@}
The VarEntry structure holds the data for each single scan variable.
These are its name, its object data structures, the start and step
values for the scan and in dataList the positions actually reached
during the scan.
Scan variables have an interface:
@d scanvarint @{
/**
* MakeScanVar creates a scan variable. All the necessary checks are
* performed
* @@param pSics The interpreter in order to locate the variable.
* @@param pCon A connection object for error reporting
* @@param name The name of the variable to scan
* @@param start The start position from which to scan
* @@param step The step width with which to scan.
* @@return A pointer to a new scan variable object on success, NULL
* else
*/
pVarEntry MakeScanVar(SicsInterp *pSics, SConnection *pCon, char
*name, float start, float step);
/**
* InitScanVar clears the list of scan points
* @@param pvar The scna variable to clear
*/
void InitScanVar(pVarEntry pVar);
/**
* DeleteVarEntry deletes a scan variable.
* @@param pData The scan variable entry to delete.
*/
void DeleteVarEntry(void *pData);
/**
* ScanVarName returns the name of the scan variable
* @@param pVar The scan variable to query.
* @@return The name of the scan variable. Do not delete pointer.
*/
char *ScanVarName(pVarEntry pVar);
/**
* ScanVarStart returns the start value for the scan
* @@param pVar The scan variable to query.
* @@return The start point for the scan.
*/
float ScanVarStart(pVarEntry pVar);
/**
* ScanVarStep returns the start value for the scan
* @@param pVar The scan variable to query.
* @@return The step width for the scan.
*/
float ScanVarStep(pVarEntry pVar);
/**
* StartScanVar starts the scan variable to drive to the next
* position.
* @@param pVar The scan variable to start.
* @@param pCon The connection to report errors to.
* @@param i The position number to drive to
* @@return 1 on success, 0 on failure
*/
int StartScanVar(pVarEntry pVar, SConnection *pCon, int i);
/**
* AppendScanVar appends a position to the list of positions
* reached while scanning this variable.
* @@param pVar The scan variable to append to.
* @@param pos The position to append.
*/
void AppendScanVar(pVarEntry pVar, float pos);
/**
* GetScanVarPos returns a position for an index.
* @@param pVar The scan variable to append to.
* @@param i The position number to retrieve
* @@return The positiopn or -99999.99 for an error
*/
float GetScanVarPos(pVarEntry pVar, int i);
/**
* CopyScanVar copies the scan positions to the array given.
* @@param pVar The scan variable to copy from
* @@param fData The array to copy to.
* @@param np The number of slots in fData.
*/
void CopyScanVar(pVarEntry pVar, float *fData, int np);
@}
\subsubsection{The Scan Object}
@d scandata @{
/*--------------------------------------------------------------------------*/
typedef struct {
int i;
@ -50,6 +143,7 @@ steps in scan processing which is already partly implemented.
pObjectDescriptor pDes;
pICallBack pCall;
pDynar pScanVar;
char objectName[132];
int iScanVar;
int iNP;
int iMode;
@ -72,6 +166,7 @@ steps in scan processing which is already partly implemented.
int (*CollectScanData)
(pScanData self,
int iP);
pStringDict scanFunctions;
long lPos;
int posSoft;
void *pCounterData;
@ -86,10 +181,6 @@ steps in scan processing which is already partly implemented.
} ScanData;
@}
The VarEntry structure holds the data for each single scan variable.
These are its name, its object data structures, the start and step
values for the scan and in fData the positions actually reached during
the scan.
The CountEntry structure holds the entries for one counting
operations. These are the lCounts collected, up to 10 monitors and the
@ -146,6 +237,8 @@ This function together with ScanDrive and the data writing functions allow for
\item[CollectScanData] reads all the scan data into the scan's data
structures after any scan point. Overload this if a different storage
scheme is required especiallay for polarising scans.
\item[scanFunctions] A string dictionary holding the names of the
configured functions for the various steps of the scan.
\item[posSoft] is a flag which is true if scan variable are stored with
soft position, i.e. with zeropoints applied.
\item[pCounterData] is a pointer to a counter structure. This defines the
@ -174,7 +267,7 @@ functions:
@d scaninter @{
/*------------------------- live & death ----------------------------------*/
pScanData CreateScanObject(char *pRecover, char *pHeader,
pCounter pCount);
pCounter pCount, char *objName);
void DeleteScanObject(void *self);
/*-------------------------------------------------------------------------*/
int AddScanVar(pScanData self, SicsInterp *pSics, SConnection *pCon,
@ -295,6 +388,105 @@ for the scan object.
\item[ScanWrapper] is the SICS interpreter object function for
interacting with the scan module.
\end{description}
\subsubsection{The Standard Scan Library}
The following functions constitute the standard scan library. Please
note that the scan file data format is driven by a template. The
format of this template is documented in the SICS managers
documentation.
@d stdscan @{
/**
* write the header of the scan file
*/
int WriteHeader(pScanData self);
/**
* WriteScanPoints is called for each point to write the scan data
* to screen and to file.
*/
int WriteScanPoints(pScanData self, int iPoint);
/**
* Called before the scan to prepare. The default implementation
* checks if all scan positions are available and configures the
* counter.
*/
int PrepareScan(pScanData self);
/**
* second version of PrepareScan which does not check scan limits
*/
int NonCheckPrepare(pScanData self);
/**
* ScanDrive handles driving to the scan point iPoint.
*/
int ScanDrive(pScanData self, int iPoint);
/**
* ScanCount is called at each scan step to do the counting.
*/
int ScanCount(pScanData self, int iPoint);
/**
* CollectScanData stores the scans count results into
* the scan data structure and prints the information about the
* scan progress.
*/
int CollectScanData(pScanData self, int iPoint);
int CollectScanDataJochen(pScanData self, int iPoint);
/*===================================================================*/
/**
* Script invocation for writing the scan header.
*/
int ScriptWriteHeader(pScanData self);
/**
* Script writing each scan point
*/
int ScriptWriteScanPoints(pScanData self, int iPoint);
/**
* Script preparation of the scan.
*/
int ScriptPrepareScan(pScanData self);
/**
* Script driving to a scan point
*/
int ScriptScanDrive(pScanData self, int iPoint);
/**
* Script counting a scan point
*/
int ScriptScanCount(pScanData self, int iPoint);
/**
* Script collecting scan data for each scan point
*/
int ScriptScanCollect(pScanData self, int iPoint);
/**
* ConfigureScript assigns the script invocation functions for
* scan
*/
void ConfigureScript(pScanData self);
/*=====================================================================*/
int StandardScanWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
@}
@o scanvar.h @{
/*-----------------------------------------------------------------------
Header file for the SICS ScanVariable. This is a support module for
the SICS scan system.
Evolved during refactoring scan in November 2004
copyright: see file COPYRIGHT
Mark Koennecke, November 2004
-------------------------------------------------------------------------*/
#ifndef SICSSCANVAR
#define SICSSCANVAR
#include "sics.h"
@<scanvar@>
/*---------------------------------------------------------------------*/
@<scanvarint@>
#endif
@}
@o scan.h @{
/*---------------------------------------------------------------------------
S C A N
@ -303,6 +495,8 @@ interacting with the scan module.
Mark Koennecke, October 1997
Extracted scan variable: Mark Koennecke, November 2004
copyright: see copyright.h
-----------------------------------------------------------------------------*/
#ifndef SICSSCAN1
@ -322,9 +516,37 @@ interacting with the scan module.
Mark Koennecke, October 1997
----------------------------------------------------------------------------*/
#include "sdynar.h"
#include "scanvar.h"
#include "stringdict.h"
@<scandata@>
/*
internal helper functions for scan implementations
*/
/*
CollectCounterData collects all the data from the configured counter
ans stows it away
*/
CountEntry CollectCounterData(pScanData self);
void InitCountEntry(pCountEntry pCount);
@}
@o stdscan.h @{
/*--------------------------------------------------------------------------
S T A N D A R D S C A N
This is a library of scan functions for the SICS standard scan.
copyright: see copyright.h
Extracted from scan.c: Mark Koennecke, November 2004
----------------------------------------------------------------------------*/
#ifndef SICSSTDSCAN
#define SICSSTDSCAN
@<stdscan@>
#endif
@}