Added putgenarray command so that we can write 2D arrays for the polar_angle
r1537 | ffr | 2007-02-22 16:07:22 +1100 (Thu, 22 Feb 2007) | 2 lines
This commit is contained in:
committed by
Douglas Clowes
parent
f298787518
commit
26df992672
92
nxscript.c
92
nxscript.c
@@ -715,6 +715,95 @@ static void putTimeBinning(SConnection *pCon, SicsInterp *pSics,
|
||||
return;
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void putGenArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
float *data = NULL;
|
||||
int length, i, status;
|
||||
char num[20];
|
||||
char buffer[256], defString[512], *varData;
|
||||
Tcl_Interp *tcl = NULL;
|
||||
double dVal;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to array",
|
||||
eError);
|
||||
return;
|
||||
}
|
||||
tcl = InterpGetTcl(pSics);
|
||||
assert(tcl != NULL);
|
||||
|
||||
/*
|
||||
get array length
|
||||
*/
|
||||
status = Tcl_GetInt(tcl,argv[4],&length);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to integer",argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
allocate
|
||||
*/
|
||||
if(length > 0){
|
||||
data = (float *)malloc(length*sizeof(float));
|
||||
}
|
||||
if(data == NULL){
|
||||
snprintf(buffer,255,
|
||||
"ERROR: out of memory or invalid length at %s, length = %s",
|
||||
argv[2],argv[4]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
return;
|
||||
}
|
||||
memset(data,0,length*sizeof(float));
|
||||
|
||||
/*
|
||||
try getting data
|
||||
*/
|
||||
for(i = 0; i < length; i++){
|
||||
sprintf(num,"%d",i);
|
||||
varData = (char *)Tcl_GetVar2(tcl,argv[3],num,0);
|
||||
if(varData != NULL){
|
||||
status = Tcl_GetDouble(tcl,varData,&dVal);
|
||||
if(status != TCL_OK){
|
||||
sprintf(buffer,"ERROR: failed to convert %s to double",
|
||||
varData);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
data[i] = (float)dVal;
|
||||
} else {
|
||||
snprintf(buffer,254,"WARNING: failed to find array element %d", i);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/*
|
||||
build definition string
|
||||
*/
|
||||
status = NXDdefget(self->dictHandle,argv[2],buffer,254);
|
||||
if(!status){
|
||||
sprintf(buffer,"ERROR: alias %s for array not found",
|
||||
argv[2]);
|
||||
SCWrite(pCon,buffer,eError);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
snprintf(defString,511,"%s -dim {%d} ",buffer,length);
|
||||
/*
|
||||
write it!
|
||||
*/
|
||||
status = NXDputdef(self->fileHandle,self->dictHandle,defString,data);
|
||||
#endif
|
||||
status = NXDputalias(self->fileHandle, self->dictHandle,argv[2],data);
|
||||
if(status != NX_OK){
|
||||
sprintf(buffer,"ERROR: failed to write array");
|
||||
SCWrite(pCon,buffer,eError);
|
||||
}
|
||||
free(data);
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void putArray(SConnection *pCon, SicsInterp *pSics,
|
||||
pNXScript self,
|
||||
int argc, char *argv[]){
|
||||
@@ -1012,6 +1101,9 @@ static int handlePut(SConnection *pCon, SicsInterp *pSics, pNXScript self,
|
||||
}else if(strcmp(argv[1],"putarray") == 0){
|
||||
/*================*/
|
||||
putArray(pCon,pSics,self,argc,argv);
|
||||
}else if(strcmp(argv[1],"putgenarray") == 0){
|
||||
/*================*/
|
||||
putGenArray(pCon,pSics,self,argc,argv);
|
||||
}else if(strcmp(argv[1],"putintarray") == 0){
|
||||
/*================*/
|
||||
putIntArray(pCon,pSics,self,argc,argv);
|
||||
|
||||
Reference in New Issue
Block a user