diff --git a/nxscript.c b/nxscript.c index 1857b78e..1e1bd1a3 100644 --- a/nxscript.c +++ b/nxscript.c @@ -668,6 +668,7 @@ static int listToArray(SicsInterp *pSics, char *list, return TCL_OK; } /*----------------------------------------------------------------------*/ +#define HANUM 3 static void putSlab(SConnection *pCon, SicsInterp *pSics, pNXScript self, int argc, char *argv[]){ int start[NX_MAXRANK], size[NX_MAXRANK]; @@ -675,6 +676,9 @@ static void putSlab(SConnection *pCon, SicsInterp *pSics, pNXScript self, pHistMem mem = NULL; HistInt *histData = NULL; pSICSData data = NULL; + char buffer[256]; + enum histargs {haStart, haLength, haBank}; + int i, haIndex, hpars[HANUM], haFirst=6; if(argc < 6){ SCWrite(pCon,"ERROR: insufficient number of arguments to putslab", @@ -705,7 +709,29 @@ static void putSlab(SConnection *pCon, SicsInterp *pSics, pNXScript self, */ mem = (pHistMem)FindCommandData(pSics,argv[5],"HistMem"); if(mem != NULL){ + if (argc == 6) { histData = GetHistogramPointer(mem,pCon); + } else if (argc > 6) { + for (i=0, haIndex=haFirst; i < HANUM; i++, haIndex++) { + status = Tcl_GetInt(InterpGetTcl(pSics),argv[haIndex],&hpars[i]); + if(status != TCL_OK){ + sprintf(buffer,"ERROR: failed to convert %s to integer", + argv[haIndex]); + SCWrite(pCon,buffer,eError); + return; + } + } + histData = (HistInt *)malloc(hpars[haLength]*sizeof(HistInt)); + if(!histData){ + SCWrite(pCon,"ERROR: out of memory for reading histogram memory", + eError); + return; + } + memset(histData,0,hpars[haLength]*sizeof(HistInt)); + status = GetHistogramDirect(mem,pCon,hpars[haBank], + hpars[haStart],hpars[haStart]+hpars[haLength],histData, + hpars[haLength]*sizeof(HistInt)); + } if(histData){ status = NXputslab(self->fileHandle, histData, start, size); if(status == NX_OK){