From ef1de4589c5bb1c63cbf0142ebfaa07a43b287d8 Mon Sep 17 00:00:00 2001
From: koennecke
Date: Wed, 12 Jan 2005 08:42:39 +0000
Subject: [PATCH] - 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
---
SCinter.c | 1 +
conman.c | 41 +-
conman.h | 30 +-
counter.c | 2 +-
devexec.c | 1 +
doc/manager/iscan.htm | 146 +++-
evcontroller.c | 9 +-
exeman.c | 2 +-
interface.c | 27 +-
interface.h | 26 +-
interface.tex | 6 +
interface.w | 6 +
macro.c | 6 +-
make_gen | 4 +-
mesure.c | 8 +-
motor.c | 142 +---
network.c | 1 -
nread.c | 1 +
nserver.c | 3 +
obdes.h | 4 +-
ofac.c | 4 +
optimise.c | 2 +-
oscillate.c | 10 +
scan.c | 1627 ++++++++++++++++++-----------------------
scan.h | 4 +-
scan.i | 24 +-
scan.tex | 344 ++++++++-
scan.w | 284 ++++++-
scanvar.c | 154 ++++
scanvar.h | 100 +++
servlog.c | 4 +-
stdscan.c | 749 +++++++++++++++++++
stdscan.h | 83 +++
tclev.c | 5 +-
telnet.c | 2 +-
35 files changed, 2659 insertions(+), 1203 deletions(-)
create mode 100644 scanvar.c
create mode 100644 scanvar.h
create mode 100644 stdscan.c
create mode 100644 stdscan.h
diff --git a/SCinter.c b/SCinter.c
index e494c6d0..29daf5e9 100644
--- a/SCinter.c
+++ b/SCinter.c
@@ -77,6 +77,7 @@
SICSLogWrite("Error allocating memory for Interpreter",eInternal);
return NULL;
}
+ memset(pInter,0,sizeof(SicsInterp));
pInter->pCList = NULL;
pInter->AList.pFirst = NULL; /* M.Z. */
pInter->pTcl = (void *)MacroInit(pInter);
diff --git a/conman.c b/conman.c
index afb22b83..8f8e3c4a 100644
--- a/conman.c
+++ b/conman.c
@@ -35,6 +35,10 @@
Introduced SCPrintf to avoid many of these pBueffel.
Markus Zolliker, Sept 2004.
+ Cleaned up conman data structure. Removed left over and unused
+ fields.
+ Mark Koennecke, December 2004
+
Copyright: see copyright.h
-----------------------------------------------------------------------------*/
#include "fortify.h"
@@ -167,7 +171,6 @@ extern pServer pServ;
pRes->inUse = 0;
pRes->iMacro = 0;
pRes->iTelnet = 0;
- pRes->pSics = pSics;
pRes->eInterrupt = eContinue;
pRes->lMagic = CONMAGIC;
pRes->iLogin = 0;
@@ -179,7 +182,7 @@ extern pServer pServ;
}
/* install command */
- AddCommand(pRes->pSics, ConName(pRes->ident), ConSicsAction, NULL,pRes);
+ AddCommand(pSics, ConName(pRes->ident), ConSicsAction, NULL,pRes);
return pRes;
}
@@ -411,7 +414,7 @@ extern pServer pServ;
fclose(pVictim->pFiles[i]);
}
- RemoveCommand(pVictim->pSics,ConName(pVictim->ident));
+ RemoveCommand(pServ->pSics,ConName(pVictim->ident));
if(pVictim->pDes)
{
@@ -428,14 +431,6 @@ extern pServer pServ;
}
LLDdelete(pVictim->iList);
- /* remove standing data connections */
- if(pVictim->pDataSock)
- {
- NETClosePort(pVictim->pDataSock);
- free(pVictim->pDataSock);
- free(pVictim->pDataComp);
- }
-
/* remove command stack */
if(pVictim->pStack)
{
@@ -549,7 +544,9 @@ extern pServer pServ;
l = vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
if (l >= sizeof buf) {
- /* we have probably a C99 conforming snprintf and need a larger buffer */
+ /* we have probably a C99 conforming snprintf and
+ need a larger buffer
+ */
dyn = malloc(l+1);
if (dyn != NULL) {
va_start(ap, fmt);
@@ -662,7 +659,7 @@ static void writeToLogFiles(SConnection *self, char *buffer)
/* put it into the interpreter if present */
if(SCinMacro(self))
{
- InterpWrite(self->pSics,buffer);
+ InterpWrite(pServ->pSics,buffer);
/* print it to client if error message */
if((iOut== eError) || (iOut == eWarning) )
{
@@ -742,7 +739,7 @@ static void writeToLogFiles(SConnection *self, char *buffer)
/* put it into the interpreter if present */
if(SCinMacro(self))
{
- InterpWrite(self->pSics,buffer);
+ InterpWrite(pServ->pSics,buffer);
/* print it to client if error message */
if((iOut== eError) || (iOut == eWarning) )
{
@@ -793,7 +790,7 @@ static void writeToLogFiles(SConnection *self, char *buffer)
/* put it into the interpreter if present */
if(SCinMacro(self))
{
- InterpWrite(self->pSics,buffer);
+ InterpWrite(pServ->pSics,buffer);
}
else /* not in interpreter, normal logic */
{
@@ -861,7 +858,7 @@ static void writeToLogFiles(SConnection *self, char *buffer)
/* put it into the interpreter if present */
if(SCinMacro(self))
{
- InterpWrite(self->pSics,buffer);
+ InterpWrite(pServ->pSics,buffer);
}
else /* not in interpreter, normal logic */
{
@@ -1641,7 +1638,7 @@ static void writeToLogFiles(SConnection *self, char *buffer)
if(self->pAction)
{
- InterpExecute(self->pSics,self->pCon,self->pAction);
+ InterpExecute(pServ->pSics,self->pCon,self->pAction);
}
return 1;
}
@@ -1799,9 +1796,8 @@ static void writeToLogFiles(SConnection *self, char *buffer)
}
/* invoke command */
CostaLock(self->pStack);
- SCInvoke(self,self->pSics,pPtr);
+ SCInvoke(self,pServ->pSics,pPtr);
CostaUnlock(self->pStack);
- /* SCWrite(self,"\b",eError); */
}
else
{
@@ -1897,9 +1893,12 @@ int SCActive(SConnection *self)
{
return 1;
}
- if(GetExeOwner(pServ->pExecutor) == self)
+ if(pServ->pExecutor != NULL)
{
- return 1;
+ if(GetExeOwner(pServ->pExecutor) == self)
+ {
+ return 1;
+ }
}
return 0;
}
diff --git a/conman.h b/conman.h
index 09b4a96f..3b4d76d0 100644
--- a/conman.h
+++ b/conman.h
@@ -12,6 +12,8 @@
Mark Koennecke, Aprl 2003
+ Mark Koennecke, December 2004
+
copyright: see copyright.h
----------------------------------------------------------------------------*/
#ifndef SICSCONNECT
@@ -30,34 +32,32 @@ typedef int (*writeFunc)(struct __SConnection *pCon,
typedef struct __SConnection {
/* object basics */
pObjectDescriptor pDes;
- /* char *pName; now generated on the fly from ident */
long lMagic;
long ident;
struct __SConnection *next;
/* I/O control */
+ /* our socket */
mkChannel *pSock;
+
+ /* per connection log files */
FILE *pFiles[MAXLOGFILES];
- int iMacro;
- int iTelnet;
- int iOutput;
int iFiles;
- writeFunc write;
- mkChannel *pDataSock;
- char *pDataComp;
- int iDataPort;
+
+ int iMacro; /* suppress I/O in macro*/
+ int iTelnet; /* telnet flag */
+ int iOutput;
+ writeFunc write; /* function doing
+ writing */
/* execution context */
- int eInterrupt;
+ int eInterrupt;
int iUserRights;
- int inUse;
- int iDummy;
- int iGrab;
- int iErrCode;
+ int inUse;
+ int iGrab; /* grab flag for token*/
int parameterChange;
int sicsError;
- SicsInterp *pSics;
-
+
/* a FIFO */
pCosta pStack;
diff --git a/counter.c b/counter.c
index cfaa37a9..b5feb33e 100644
--- a/counter.c
+++ b/counter.c
@@ -654,7 +654,7 @@
{
self->pCountInt->TransferData(self,pCon);
}
- if( (iNum < 0) || (iNum > self->pDriv->iNoOfMonitors) )
+ if( (iNum < 0) || (iNum >= self->pDriv->iNoOfMonitors) )
{
return -1L;
}
diff --git a/devexec.c b/devexec.c
index 9367bb55..a7500d6c 100644
--- a/devexec.c
+++ b/devexec.c
@@ -159,6 +159,7 @@
DeleteCallBackInterface(self->pCall);
free(self);
+ pServ->pExecutor = NULL;
}
/*--------------------------------------------------------------------------*/
void ExeInterest(pExeList self, pDevEntry pDev, char *text) {
diff --git a/doc/manager/iscan.htm b/doc/manager/iscan.htm
index 1c085062..b80c10d4 100644
--- a/doc/manager/iscan.htm
+++ b/doc/manager/iscan.htm
@@ -3,7 +3,7 @@
The Internal Scan Command
-The Internal Scan Command
+The Internal Scan Commands
Scans are preformed from a variety of commands in SICS. All these commands
are just Tcl--wrappers around an internal scan object implemented in C. This
@@ -13,6 +13,29 @@ command in the initialisation file. This command install the internal
scan object under a user defined name. For the rest of this document it is
assumed that this name is xxscan.
+Scan Concepts2>
+
+Scanning in SICS evolved a little over time. It turned out that scans
+are a demanding job for a programmer because of the plethora of
+special scans people wish to perform and the many data file formats which
+have to be supported. This requires a very high degree of
+configurability. Under several refactorings the internal scan command
+has grown to become:
+
+- A controller for the scan process.
+
- A container to store scanned variables and counts during the
+process of a scan. This includes commands to store and retrieve such
+values.
+
- A container for the configuration of the scan. A scan is
+configured by specifying functions to be called at the various steps
+during the scan. These are preconfigured to the standard scan
+functions. An API is provided to replace some or all of the scan
+functions by user defined ones.
+
+The internal scan object is augmented by a library of standard scan
+functions. The transition to the new model is not yet clean in order
+not to break to much old code.
+
The scan object (named here xxscan, but may have another name) understands
the following commands:
@@ -28,6 +51,8 @@ different parameters.
the counter mode to use (this can be either timer or monitor) and preset
which is the preset value for the counter. Scan data is written to an output
file.
+- xxscan continue NP mode preset
+
- Continues an interrupted scan. Used by the recovery feauture.
- xxscan silent NP mode preset
- Executes a scan. The arguments are: NP the number of scan points, mode
the counter mode to use (this can be either timer or monitor) and preset
@@ -47,16 +72,33 @@ command sets the channel to collect data from. The argument n is an integer
ID for the channel to use.
- xxscan getcounts
- Retrieves the counst collected during the scan.
+
- xxscan getmonitor i
+
- Prints the monitor values collected during the scan for the
+monitor number i
+
- xxscan gettime
+
- Prints the counting times for the scan points in the current scan.
+
- xxscan np
+
- Prints the number of points in the current scan.
- xxscan getvardata n
- This command retrieves the values of a scan variable during the scan
(the x axis). The argument n is the ID of the scan variable to retrieve data
for. ID is 0 for the first scan variable added, 1 for the second etc.
+
- xxscan noscanvar
+
- Prints the number of scan variables
+
- xxscan getvarpar i
+
- Prints the name , start and step of the scan variable number i
- xxscan interest
- A SICS client can be automatically notified about scan progress. This is
switched on with this command. Three types of messages are sent: A string
NewScan on start of the scan, a string ScanEnd after the scan has finished
and a string scan.Counts = {109292 8377 ...} with the scan values after each
finished scan point.
+
- xxscan uuinterest
+
- As above but the array of counts is transferred in UU encoded
+format.
+
- xxscan dyninterest
+
- As above but scan points are printed one by one as a list
+containing: point number first_scan_var_pos counts.
- xxscan uninterest
- Uninterest switches automatic notification about scan progress off.
- xxscan integrate
@@ -87,10 +129,70 @@ object. Currently there are two:
- amor, a special mode the reflectometer AMOR which writes
NeXus files.
+
- xxscan storecounts counts time mon1 mon2 ...
+
- This stores an entry of count values into the scan data
+structure. To be used from user defined scan functions. The scan
+pointer is incremented by one.
+
- xxscan storecounter
+
- Store the counts and monitors in the counter object configured for
+the scan into the scan data structure. Increments the scan pointer by
+one.
+
- xxscan appendvarpos i pos
+
- Append pos to the array of positions for scan variable i. To be
+used from user defined scan functions.
+
- xxscan callback scanstart | scanpoint | scanend
+
- Triggers callbacks configured on the scan object. May be used by
+user functions implementing own scan loops.
+
- xxscan function list
+
- Lists the available configurable function names. The calling style
+of these functions is described in the next section about stdscan.
+
- xxscan function functionname
+
- Returns the currently configured function for functionname.
+
- xxscan function functionname newfunctionname
+
- Sets a new function to be called for the function functionname in
+the scan.
-
-
User Defined Scans
+User Definable Scan Functions
+The last commands in the last section allowed to overload the
+functions implementing various operations during the scan with user
+defined methods. This section is the reference for these
+functions. The following operations during a scan be configured:
+
+- writeheader
+
- Is supposed to write the header of the data file
+
- prepare
+
- Prepare does all the necessary operations necessary before a scan
+starts.
+
- drive
+
- Is called to drive to the next scan point
+
- count
+
- Is called at each scan point to perform the counting operation
+
- collect
+
- Is called for each scan point. This function is supposed to store
+the scan data into the scan data structure.
+
- writepoint
+
- Is called for each scan point and is meant to print information
+about the scan point to the data file and to the user.
+
- userdata
+
- This is the name of a user defined object which may be used to
+store user data for the scan.
+
+The exact invocations of the functions:
+
+- writeheader scanobjectname userobjectname
+
- prepare scanobjectname userobjectname
+
- drive scanobjectname userobjectname point
+
- count scanobjectname userobjectname point
+
- collect scanobjectname userobjectname point
+
- writepoint scanobjectname userobjectname point
+
+scanobjectname is the name of the scan object invoking the
+function. This can be used for querying the scan
+object. userobjectname is the name of a entity as specified as
+userdata in the configuration. point is the number of the current scan point.
+
+User Defined Scans(Old Style)
In some cases users wish to control the scan more closely, i.e. do
multiple counting operations at the same point etc. This is especially
@@ -133,6 +235,44 @@ command:
In all this replace xxxscan with the name of the internal scan
command.
+Differential Scans
+
+When aligning or when searching peaks a very fast scan is
+required. This is the differential scan. It starts a motor and
+collects counts while the motor is running. The counts collected are
+the monitor normalized difference to the previous reading. This
+functionality can be configured into SICS with the command:
+
+MakeDiffScan
+
in the configuration file. An optional parameter defines
+another name then diffscan (the default) for this object. Differential
+scans can only be run against one motor as it cannot be guaranteed that
+motors in a coordinated movement operate at the same speed. The
+procedure to use diffscan is:
+
+- Configure a scan variable into a SICS scan object: xxscan add var
+start step
+
- Run diffscan as: diffscan scanobjectname end_position_of_scan
+This runs the differential scan. Scanobjectname is the name of a SICS
+internal scan object. It will be used to store the results of the
+scan. While the scan is running some basic information is printed. The
+scan will range from the start given in the xxscan add command to the
+end position given in this call.
+
+The diffscan object has two configurable parameters:
+
+- monitor
+
- The monitor number to normalize against. For maximum precision
+this should be a monitor with a lot of intensity on it.
+
- skip
+
- The number of SICS main loop cycles to skip between readings. This
+can be used to control the amount of data generated during a
+differential scan. This may become a problem if there is fast hardware.
+
+A word of warning: positions found in differential scans may not be
+totally correct. The differential scan might even miss peaks when the
+relationship between motor speed and sampling rate is bad.
+