PSI sics-cvs-psi-complete-tree-post-site-support

This commit is contained in:
2004-03-09 15:18:11 +00:00
committed by Douglas Clowes
parent 6373f6b0fb
commit ae77364de2
196 changed files with 8344 additions and 3485 deletions

201
varlog.c
View File

@@ -6,12 +6,16 @@
Mark Koennecke, September 1997
Substantially revised to calculate running measn and standard deviations
instead of storing data ain a list. The module now supports running
Substantially revised to calculate running means and standard deviations
instead of storing data in a list. The module now supports running
averages and logging to file.
Mark Koennecke, April 2000
Added support for a circular buffer of logged values.
Mark Koennecke, December 2003
Copyright:
Labor fuer Neutronenstreuung
@@ -50,10 +54,17 @@
#include <math.h>
#include "fortify.h"
#include "lld.h"
#include "conman.h"
#include "sics.h"
#include "varlog.h"
#include "commandlog.h"
#include "circular.h"
#include "sicsdata.h"
/*-----------------------------------------------------------------------*/
/*
maximum values in the circular buffer
*/
#define MAXRING 1024
/*------------------------------------------------------------------------*/
typedef struct __VarLog
{
@@ -63,6 +74,7 @@
double dSum;
double dDeviation;
FILE *fd;
pCircular pTail;
}VarLog;
/*------------------------------------------------------------------------*/
@@ -87,6 +99,12 @@
pNew->dSum = 0.;
pNew->dDeviation = 0.;
pNew->fd = NULL;
pNew->pTail = createCircular(MAXRING,free);
if(!pNew->pTail)
{
VarlogDelete(pNew);
return 0;
}
*self = pNew;
return 1;
@@ -98,6 +116,10 @@
{
fclose(self->fd);
}
if(self->pTail != NULL)
{
deleteCircular(self->pTail);
}
return 1;
}
/*--------------------------------------------------------------------------*/
@@ -129,7 +151,8 @@
int iFile = 0;
char pBuffer[80];
double dMean, dTmp;
pLogItem newLog = NULL;
assert(self);
tCurrent = time(NULL);
@@ -161,7 +184,7 @@
return 1;
}
/* if, log time passed, write to file */
/* if, log time passed, write to file and into ring buffer */
if(tCurrent > self->tNext)
{
if(iFile)
@@ -169,6 +192,14 @@
VLFormatTime(tCurrent,pBuffer,79);
fprintf(self->fd," %s %f \n", pBuffer,fVal);
}
newLog = (pLogItem)malloc(sizeof(LogItem));
if(newLog != NULL)
{
newLog->tTime = tCurrent;
newLog->fVal = fVal;
setCircular(self->pTail,newLog);
nextCircular(self->pTail);
}
self->tNext = tCurrent + self->tFrequency;
return 1;
}
@@ -203,6 +234,112 @@
return success;
}
/*-----------------------------------------------------------------------*/
static int VarlogToSicsData(pVarLog self, pSICSData data)
{
int i, length;
int *dataPtr = NULL;
pLogItem log = NULL;
dataPtr = getSICSDataPointer(data,0,2*MAXRING+1);
if(!dataPtr)
{
return 0;
}
dataPtr[0] = MAXRING;
/*
skip back MAXRING steps
*/
for(i = 0; i < MAXRING; i++)
{
previousCircular(self->pTail);
}
/*
forward again and copy data
*/
for(i = 0; i < MAXRING; i++)
{
log = getCircular(self->pTail);
if(log != NULL)
{
dataPtr[i+1] = (int)log->tTime;
memcpy(&dataPtr[i+1+MAXRING],&log->fVal,sizeof(float));
}
nextCircular(self->pTail);
}
/*
assign data types
*/
assignSICSType(data,0,MAXRING+1,INTTYPE);
assignSICSType(data,MAXRING+1,2*MAXRING+1,FLOATTYPE);
return 1;
}
/*-----------------------------------------------------------------------*/
static void VarlogDump(pVarLog self, SConnection *pCon)
{
int i, length;
pLogItem log = NULL;
char timeBuffer[132], pBueffel[256];
/*
skip back MAXRING steps
*/
for(i = 0; i < MAXRING; i++)
{
previousCircular(self->pTail);
}
/*
forward again and print data
*/
for(i = 0; i < MAXRING; i++)
{
log = getCircular(self->pTail);
if(log != NULL)
{
if(log->tTime > 0)
{
VLFormatTime(log->tTime,timeBuffer,131);
snprintf(pBueffel,255,"%s %12.3f",timeBuffer,log->fVal);
SCWrite(pCon,pBueffel,eValue);
}
}
nextCircular(self->pTail);
}
}
/*-----------------------------------------------------------------------*/
static void VarLogDumpFile(pVarLog self, FILE *fd)
{
int i, length;
pLogItem log = NULL;
char timeBuffer[132], pBueffel[256];
/*
skip back MAXRING steps
*/
for(i = 0; i < MAXRING; i++)
{
previousCircular(self->pTail);
}
/*
forward again and print data
*/
for(i = 0; i < MAXRING; i++)
{
log = getCircular(self->pTail);
if(log != NULL)
{
if(log->tTime > 0)
{
VLFormatTime(log->tTime,timeBuffer,131);
fprintf(fd,"%s %12.3f",timeBuffer,log->fVal);
}
}
nextCircular(self->pTail);
}
}
/*--------------------------------------------------------------------------*/
int VarlogWrapper(pVarLog self, SConnection *pCon,
char *subcommand, char *sub2, char *pVarName)
@@ -213,6 +350,8 @@
char pBueffel[256];
char *pData = NULL;
long lNew;
pSICSData data = NULL;
FILE *fd = NULL;
strtolower(subcommand);
@@ -314,7 +453,55 @@
SCWrite(pCon,pBueffel,eValue);
return 1;
}
}
}
/*-------------- tosicsdata */
else if(strcmp(subcommand,"tosicsdata") == 0)
{
if(!sub2)
{
SCWrite(pCon,"ERROR: tosicsdata needs an argument",eError);
return 0;
}
data = FindCommandData(pServ->pSics,sub2,"SICSData");
if(!data)
{
snprintf(pBueffel,255,"ERROR: %s is no sicsdata object",sub2);
SCWrite(pCon,pBueffel,eError);
return 0;
}
iRet = VarlogToSicsData(self,data);
if(iRet == 0)
{
SCWrite(pCon,"ERROR: out of memory in VarlogToSicsData",eError);
return 0;
}
SCSendOK(pCon);
return 1;
}
/* ---------------- dumpring */
else if(strcmp(subcommand,"dump") == 0)
{
VarlogDump(self,pCon);
return 1;
}
/*---------------- dumptofile */
else if(strcmp(subcommand,"dumptofile") == 0)
{
if(sub2 != NULL)
{
fd = fopen(sub2,"w");
}
if(fd == NULL)
{
snprintf(pBueffel,255,"ERROR: failed to open %s",sub2);
SCWrite(pCon,pBueffel,eError);
return 0;
}
VarLogDumpFile(self,fd);
fclose(fd);
SCSendOK(pCon);
return 1;
}
/* command not recognized */
else
{
@@ -323,3 +510,5 @@
return 0;
}
}