- Switched motor to hdb
- Changes to Hipadaba - Added project to histogram memory code - Started regression testing code - Added hill climbing as optimization method to optimise
This commit is contained in:
84
sicsdata.c
84
sicsdata.c
@ -17,7 +17,7 @@
|
||||
#include "scan.h"
|
||||
#include "HistMem.h"
|
||||
#include "sicsdata.h"
|
||||
|
||||
#define ABS(x) (x < 0 ? -(x) : (x))
|
||||
/*--------------------------------------------------------------------*/
|
||||
static void KillSICSData(void *pData){
|
||||
pSICSData self = NULL;
|
||||
@ -236,6 +236,74 @@ static int putFloat(pSICSData self, int argc, char *argv[],
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int getPos(pSICSData self, char *name,
|
||||
SConnection *pCon, int pos){
|
||||
char pBueffel[512];
|
||||
float value;
|
||||
|
||||
if(pos >= self->dataUsed){
|
||||
SCWrite(pCon,"ERROR: requested position out of range",eError);
|
||||
return 0;
|
||||
}
|
||||
if(self->dataType[pos] == FLOATTYPE){
|
||||
memcpy(&value,&self->data[pos],sizeof(float));
|
||||
snprintf(pBueffel,511,"%s = %f", name, value);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
if(self->dataType[pos] == INTTYPE){
|
||||
snprintf(pBueffel,511,"%s = %d", name, self->data[pos]);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static float getDataPos(pSICSData self, int pos){
|
||||
float value;
|
||||
|
||||
assert(pos < self->dataUsed);
|
||||
if(self->dataType[pos] == FLOATTYPE){
|
||||
memcpy(&value,&self->data[pos],sizeof(float));
|
||||
} else {
|
||||
value = (float)self->data[pos];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/*------------------------------------------------------------------*/
|
||||
static int divideSicsData(pSICSData self, SicsInterp *pSics,
|
||||
SConnection *pCon, char *name){
|
||||
int i;
|
||||
pSICSData other = NULL;
|
||||
float val, div;
|
||||
|
||||
other = (pSICSData)FindCommandData(pSics,name,"SICSData");
|
||||
if(other == NULL){
|
||||
SCWrite(pCon,"ERROR: requested SICSData object to divide not found",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
if(other->dataUsed < self->dataUsed){
|
||||
SCWrite(pCon,"ERROR: not enough data in SICSData for division",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < self->dataUsed; i++){
|
||||
div = getDataPos(other,i);
|
||||
if(ABS(div) > .00001){
|
||||
val = getDataPos(self,i)/div;
|
||||
} else {
|
||||
val = .0;
|
||||
}
|
||||
if(self->dataType[i] == INTTYPE){
|
||||
self->data[i] = (int)val;
|
||||
} else {
|
||||
memcpy(&self->data[i],&val,sizeof(float));
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int copyScanCounts(pSICSData self, int argc, char *argv[],
|
||||
SConnection *pCon, SicsInterp *pSics){
|
||||
@ -482,6 +550,7 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[]){
|
||||
pSICSData self = NULL;
|
||||
char pBueffel[132];
|
||||
int pos;
|
||||
|
||||
self = (pSICSData)pData;
|
||||
assert(self);
|
||||
@ -509,6 +578,19 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
return dumpSICSData(self,argv[2],pCon);
|
||||
} else if(strcmp(argv[1],"get") == 0){
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: need a position to read",eError);
|
||||
return 0;
|
||||
}
|
||||
pos = atoi(argv[2]);
|
||||
return getPos(self,argv[0],pCon,pos);
|
||||
} else if(strcmp(argv[1],"divideby") == 0){
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: need a SICSdata to divide by",eError);
|
||||
return 0;
|
||||
}
|
||||
return divideSicsData(self,pSics,pCon,argv[2]);
|
||||
} else if(strcmp(argv[1],"putint") == 0){
|
||||
/*---------- putint */
|
||||
return putInt(self,argc-2,&argv[2],pCon, pSics);
|
||||
|
Reference in New Issue
Block a user