- Fixed a couple of bugs
This commit is contained in:
92
sicsdata.c
92
sicsdata.c
@ -185,7 +185,7 @@ void clearSICSData(pSICSData self){
|
||||
memset(self->dataType,0,self->currentDataSize*sizeof(char));
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int dumpSICSData(pSICSData self, char *filename, SConnection *pCon){
|
||||
static int dumpSICSDataXY(pSICSData self, char *filename, SConnection *pCon){
|
||||
FILE *fd = NULL;
|
||||
char pBueffel[132];
|
||||
int i;
|
||||
@ -210,6 +210,32 @@ static int dumpSICSData(pSICSData self, char *filename, SConnection *pCon){
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int dumpSICSData(pSICSData self, char *filename, SConnection *pCon){
|
||||
FILE *fd = NULL;
|
||||
char pBueffel[132];
|
||||
int i;
|
||||
float fVal;
|
||||
|
||||
fd = fopen(filename,"w");
|
||||
if(fd == NULL){
|
||||
snprintf(pBueffel,131,"ERROR: cannot open %s", filename);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
for(i = 0; i < self->dataUsed; i++){
|
||||
if(self->dataType[i] == INTTYPE){
|
||||
fprintf(fd," %d", self->data[i]);
|
||||
}
|
||||
if(self->dataType[i] == FLOATTYPE){
|
||||
memcpy(&fVal,self->data + i,sizeof(float));
|
||||
fprintf(fd," %.5f",fVal);
|
||||
}
|
||||
}
|
||||
fclose(fd);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------*/
|
||||
static int putInt(pSICSData self, int argc, char *argv[],
|
||||
SConnection *pCon, SicsInterp *pSics){
|
||||
@ -588,6 +614,58 @@ static int copyHM(pSICSData self, int argc, char *argv[],
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------*/
|
||||
static int copyHMBank(pSICSData self, int argc, char *argv[],
|
||||
SConnection *pCon, SicsInterp *pSics){
|
||||
int status, pos, i, bank, dataLength;
|
||||
pHistMem pHist = NULL;
|
||||
const float *fTimeBin = NULL;
|
||||
int *iData = NULL;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,"ERROR: not enough arguments to SICSData copyhm",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[0],&pos);
|
||||
if(status != TCL_OK){
|
||||
SCWrite(pCon,
|
||||
"ERROR: failed to convert copyhmbank position to integer",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pHist = (pHistMem)FindCommandData(pSics,argv[1],"HistMem");
|
||||
if(!pHist){
|
||||
SCWrite(pCon,"ERROR: histogram memory not found in copyhmbank",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[2],&bank);
|
||||
if(status != TCL_OK){
|
||||
SCWrite(pCon,
|
||||
"ERROR: failed to convert copyhmbank bank to integer",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&dataLength);
|
||||
if(status != TCL_OK){
|
||||
SCWrite(pCon,
|
||||
"ERROR: failed to convert copyhmbank dataLength to integer",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iData = getSICSDataPointer(self,pos,pos+dataLength);
|
||||
if(!iData){
|
||||
SCWrite(pCon,"ERROR: out of memory in SICSData copyhmbank",eError);
|
||||
return 0;
|
||||
}
|
||||
GetHistogramDirect(pHist,pCon,bank,0,dataLength,iData,
|
||||
dataLength*sizeof(int));
|
||||
assignType(self,pos,pos+dataLength,INTTYPE);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int copyData(pSICSData self,SicsInterp *pSics,
|
||||
SConnection *pCon,int argc, char *argv[]){
|
||||
@ -645,6 +723,13 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
snprintf(pBueffel,131,"%s = %d", argv[0], self->dataUsed);
|
||||
SCWrite(pCon,pBueffel,eValue);
|
||||
return 1;
|
||||
} else if(strcmp(argv[1],"dumpxy") == 0){
|
||||
/* --------- dump */
|
||||
if(argc < 3){
|
||||
SCWrite(pCon,"ERROR: need a file name to dump to",eError);
|
||||
return 0;
|
||||
}
|
||||
return dumpSICSDataXY(self,argv[2],pCon);
|
||||
} else if(strcmp(argv[1],"dump") == 0){
|
||||
/* --------- dump */
|
||||
if(argc < 3){
|
||||
@ -686,8 +771,11 @@ int SICSDataAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
/*--------- copytimebin */
|
||||
return copyTimeBin(self,argc-2,&argv[2],pCon,pSics);
|
||||
} else if(strcmp(argv[1],"copyhm") == 0){
|
||||
/*--------- copytimebin */
|
||||
/*--------- copyhm */
|
||||
return copyHM(self,argc-2,&argv[2],pCon,pSics);
|
||||
} else if(strcmp(argv[1],"copyhmbank") == 0){
|
||||
/*--------- copyhmbank */
|
||||
return copyHMBank(self,argc-2,&argv[2],pCon,pSics);
|
||||
} else if(strcmp(argv[1],"writezipped") == 0){
|
||||
/*--------- writezipped */
|
||||
if(argc < 3){
|
||||
|
Reference in New Issue
Block a user