PSI sics-cvs-psi-2008-10-02

This commit is contained in:
2008-10-02 00:00:00 +00:00
committed by Douglas Clowes
parent 6e926b813f
commit 4baffb9b7a
304 changed files with 77527 additions and 3612 deletions

283
stdscan.c
View File

@@ -64,8 +64,240 @@ static char *fixExtension(char *filename)
}
return fixExtension(pRes);
}
/*-------------------------------------------------------------------------*/
void WriteTemplate(FILE *fd, FILE *temp, char *filename, pScanData pScan,
SConnection *pCon, SicsInterp *pSics)
{
char pBuffer[512], pError[512], *pPtr, *pName;
CommandList *pCom = NULL;
pSicsVariable pVar = NULL;
pDummy pDum = NULL;
pIDrivable pDriv = NULL;
pMotor pMot = NULL;
pVarEntry pScanVar = NULL;
void *pVoid = NULL;
float fVal;
int iRet;
/* loop through description file and act along the way */
while(fgets(pBuffer,511,temp) != NULL)
{
pPtr = strstr(pBuffer,"!!VAR(");
if(pPtr) /* handle a Sics variable */
{
/* extract the name */
pName = pPtr + 6; /* first char of name */
*pPtr = '\0'; /* this is the starter of the line */
pPtr = pName;
while( (*pPtr != '\0') && (*pPtr != ')') )
{
pPtr++;
}
*pPtr = '\0';
/* find the variable */
pCom = FindCommand(pSics,pName);
if(!pCom)
{
sprintf(pError,"ERROR: variable %s NOT found",pName);
SCWrite(pCon,pError,eError);
continue;
}
pVar = (pSicsVariable)pCom->pData;
if(!pVar)
{
sprintf(pError,"ERROR: variable %s NOT found",pName);
SCWrite(pCon,pError,eError);
continue;
}
switch(pVar->eType)
{
case veFloat:
sprintf(pError,"%f",pVar->fVal);
break;
case veInt:
sprintf(pError,"%d",pVar->iVal);
break;
case veText:
sprintf(pError,"%s",pVar->text);
break;
}
/* finally write */
fprintf(fd,"%s %s\n",pBuffer,pError);
continue;
}/* end variable */
/*------- Drivable */
pPtr = strstr(pBuffer,"!!DRIV(");
if(pPtr)
{
/* extract the name */
pName = pPtr + 7; /* first char of name */
*pPtr = '\0'; /* this is the starter of the line */
pPtr = pName;
while( (*pPtr != '\0') && (*pPtr != ')') )
{
pPtr++;
}
*pPtr = '\0';
/* find the variable */
pCom = FindCommand(pSics,pName);
if(!pCom)
{
sprintf(pError,"ERROR: variable %s NOT found",pName);
SCWrite(pCon,pError,eError);
continue;
}
pDum = (pDummy)pCom->pData;
if(!pDum)
{
sprintf(pError,"ERROR: variable %s is NOT drivable",pName);
SCWrite(pCon,pError,eError);
continue;
}
pDriv = (pIDrivable)pDum->pDescriptor->GetInterface(pDum,DRIVEID);
if(!pDriv)
{
sprintf(pError,"ERROR: variable %s is NOT drivable",pName);
SCWrite(pCon,pError,eError);
continue;
}
fVal = pDriv->GetValue(pDum,pCon);
fprintf(fd,"%s %f\n",pBuffer,fVal);
continue;
} /* end drive */
/*------- zero point */
pPtr = strstr(pBuffer,"!!ZERO(");
if(pPtr)
{
/* extract the name */
pName = pPtr + 7; /* first char of name */
*pPtr = '\0'; /* this is the starter of the line */
pPtr = pName;
while( (*pPtr != '\0') && (*pPtr != ')') )
{
pPtr++;
}
*pPtr = '\0';
/* find the motor */
pMot = FindMotor(pSics,pName);
if(!pMot)
{
sprintf(pError,"ERROR: motor %s NOT found",pName);
SCWrite(pCon,pError,eError);
continue;
}
iRet = MotorGetPar(pMot,"softzero",&fVal);
if(!iRet)
{
SCWrite(pCon,"ERROR: failed to read zero point",eError);
continue;
}
fprintf(fd,"%s %f\n",pBuffer,fVal);
continue;
} /* end zero point */
/*---------- scripted info */
pPtr = strstr(pBuffer,"!!SCRIPT(");
if(pPtr)
{
/* extract the name */
pName = pPtr + 9; /* first char of name */
*pPtr = '\0'; /* this is the starter of the line */
pPtr = pName;
while( (*pPtr != '\0') && (*pPtr != ')') )
{
pPtr++;
}
*pPtr = '\0';
if(Tcl_Eval(InterpGetTcl(pSics),pName) == TCL_OK)
{
fprintf(fd,"%s\n",Tcl_GetStringResult(InterpGetTcl(pSics)));
}
else
{
SCWrite(pCon,"ERROR: failed to execute Tcl command",eError);
strncpy(pBuffer, Tcl_GetStringResult(InterpGetTcl(pSics)), 511);
SCWrite(pCon,pBuffer,eError);
continue;
}
}
/* ------- date */
pPtr = strstr(pBuffer,"!!DATE!!");
if(pPtr)
{
*pPtr = '\0';
SNXFormatTime(pError,511);
fprintf(fd,"%s %s\n",pBuffer,pError);
continue;
}
/*-------- filename */
pPtr = strstr(pBuffer,"!!FILE!!");
if(pPtr)
{
*pPtr = '\0';
fprintf(fd,"%s %s\n",pBuffer,filename);
continue;
}
/*------------ scanzero */
pPtr = strstr(pBuffer,"!!SCANZERO!!");
if(pPtr && pScan != NULL)
{
*pPtr = '\0';
/* write zero point of first scan variable if motor */
DynarGet(pScan->pScanVar,0,&pVoid);
pScanVar = (pVarEntry)pVoid;
if(pScanVar)
{
pMot = NULL;
pMot = FindMotor(pSics,ScanVarName(pScanVar));
if(pMot != NULL)
{
MotorGetPar(pMot,"softzero",&fVal);
fprintf(fd,"%s zero = %8.3f\n",ScanVarName(pScanVar),
fVal);
}
}
}
/* --------- plain text */
fprintf(fd,"%s",pBuffer);
} /* end while */
}
/*---------------------------------------------------------------------------*/
int WriteHeader(pScanData self)
{
int i, iRet;
FILE *fd;
assert(self->pSics);
assert(self->pCon);
/* open data file */
self->fd = fopen(self->pFile,"w");
if(!self->fd)
{
SCWrite(self->pCon,"ERROR: cannot write data file",eError);
return 0;
}
/* open header description file */
fd = fopen(self->pHeaderFile,"r");
if(!fd)
{
SCWrite(self->pCon,"ERROR: cannot open header description file",eError);
return 0;
}
WriteTemplate(self->fd,fd,self->pFile,
self, self->pCon, self->pSics);
/* remember position for seeking to it for writing data */
self->lPos = ftell(self->fd);
fclose(fd);
fclose(self->fd);
self->fd = NULL;
return 1;
}
/*---------------------------------------------------------------------------*/
int WriteHeaderOld(pScanData self)
{
int i, iRet;
FILE *fd;
@@ -378,7 +610,7 @@ int prepareDataFile(pScanData self){
char pBueffel[512];
/* allocate a new data file */
pPtr = ScanMakeFileName(self->pSics,self->pCon);
pPtr = ScanMakeFileName(pServ->pSics,self->pCon);
if(!pPtr)
{
SCWrite(self->pCon,
@@ -405,7 +637,6 @@ int prepareDataFile(pScanData self){
char pMessage[1024];
assert(self);
assert(self->iNP > 0);
assert(self->pCon);
/* check boundaries of scan variables and allocate storage */
@@ -534,8 +765,8 @@ int prepareDataFile(pScanData self){
pVarEntry pVar = NULL;
void *pDings;
int i, iRet, status;
char pStatus[512], pItem[20];
char pHead[512];
char pStatus[2024], pItem[20];
char pHead[2024];
float fVal;
CountEntry sCount;
@@ -555,16 +786,8 @@ int prepareDataFile(pScanData self){
pVar = (pVarEntry)pDings;
if(pVar)
{
if(jochenFlag == 1 &&
strcmp(pVar->pObject->pDescriptor->name, "Motor") == 0)
{
MotorGetSoftPosition((pMotor)pVar->pObject,self->pCon,&fVal);
}
else
{
fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon);
}
AppendScanVar(pVar,fVal);
fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon);
AppendScanVar(pVar,fVal);
sprintf(pItem,"%-9.9s ",ScanVarName(pVar));
strcat(pHead,pItem);
sprintf(pItem,"%-9.3f ",fVal);
@@ -597,8 +820,10 @@ int prepareDataFile(pScanData self){
strcat(pStatus,pItem);
/* write progress */
strcat(pHead,"\n");
strcat(pStatus,"\n");
/*
strcat(pHead,"\r\n");
strcat(pStatus,"\r\n");
*/
SCWrite(self->pCon,pHead,eWarning);
SCWrite(self->pCon,pStatus,eWarning);
@@ -609,13 +834,8 @@ int prepareDataFile(pScanData self){
{
return CollectScanDataIntern(self,iPoint,0);
}
/*--------------------------------------------------------------------------*/
int CollectScanDataJochen(pScanData self, int iPoint)
{
return CollectScanDataIntern(self,iPoint,1);
}
/*------------------------------------------------------------------------*/
static int CollectSilent(pScanData self, int iPoint)
int CollectSilent(pScanData self, int iPoint)
{
pVarEntry pVar = NULL;
void *pDings;
@@ -635,15 +855,7 @@ int prepareDataFile(pScanData self){
pVar = (pVarEntry)pDings;
if(pVar)
{
if(jochenFlag == 1 &&
strcmp(pVar->pObject->pDescriptor->name, "Motor") == 0)
{
MotorGetSoftPosition((pMotor)pVar->pObject,self->pCon,&fVal);
}
else
{
fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon);
}
fVal = pVar->pInter->GetValue(pVar->pObject,self->pCon);
AppendScanVar(pVar,fVal);
}
}
@@ -908,7 +1120,14 @@ int StandardScanWrapper(SConnection *pCon, SicsInterp *pSics, void *pData,
}
strtolower(argv[1]);
self = (pScanData)FindCommandData(pSics,argv[2],"ScanObject");
assert(self);
if(self == NULL){
SCWrite(pCon,"ERROR: scan object not found",eError);
return 0;
}
if(self->pCon == NULL){
self->pCon = pCon;
}
if(strcmp(argv[1],"writeheader") == 0){
return WriteHeader(self);