- DMC McStas simulation working
SKIPPED: psi/amorstat.c psi/nxamor.c psi/pimotor.c psi/polterwrite.c
This commit is contained in:
111
mcreader.c
111
mcreader.c
@@ -10,6 +10,7 @@
|
||||
#include "mcreader.h"
|
||||
#include "counter.h"
|
||||
#include "HistMem.h"
|
||||
#include "sicsdata.h"
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static void KillMcReader(void *pData){
|
||||
pMcStasReader self = (pMcStasReader)pData;
|
||||
@@ -127,7 +128,8 @@ static int insertMonitor(pMcStasReader self, SConnection *pCon,
|
||||
SicsInterp *pSics, int argc, char *argv[]){
|
||||
char pBueffel[512], *pPtr, pNumber[80];
|
||||
pCounter pCount = NULL;
|
||||
int status, mon, monValue, type, rank, iDim[NX_MAXRANK];
|
||||
int status, mon, type, rank, iDim[NX_MAXRANK];
|
||||
float monValue, scale = 1.;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,\
|
||||
@@ -157,6 +159,10 @@ static int insertMonitor(pMcStasReader self, SConnection *pCon,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argc > 5) {
|
||||
scale = atof(argv[5]);
|
||||
}
|
||||
|
||||
status = NXgetinfo(self->handle,&rank,iDim,&type);
|
||||
if(status != NX_OK){
|
||||
snprintf(pBueffel,511,"ERROR: Nexus error %s while reading %s",
|
||||
@@ -187,7 +193,40 @@ static int insertMonitor(pMcStasReader self, SConnection *pCon,
|
||||
pPtr = getNextMCNumber(pPtr,pNumber);
|
||||
pPtr = getNextMCNumber(pPtr,pNumber);
|
||||
pPtr = getNextMCNumber(pPtr,pNumber);
|
||||
monValue = atoi(pNumber);
|
||||
monValue = atof(pNumber);
|
||||
monValue *= scale;
|
||||
|
||||
if(pCount != NULL){
|
||||
SetMonitorValue(pCount,mon,(long)monValue);
|
||||
}
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int insertMonitorDirect(pMcStasReader self, SConnection *pCon,
|
||||
SicsInterp *pSics, int argc, char *argv[]){
|
||||
char pBueffel[512], *pPtr, pNumber[80];
|
||||
pCounter pCount = NULL;
|
||||
int status, mon;
|
||||
float monValue;
|
||||
|
||||
if(argc < 5){
|
||||
SCWrite(pCon,\
|
||||
"ERROR: insufficient number of arguments to mcreader insertmondirect",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCount = FindCommandData(pSics,argv[2],"SingleCounter");
|
||||
if(pCount == NULL){
|
||||
snprintf(pBueffel,511,
|
||||
"ERROR: %s is no counter object",
|
||||
argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
mon = atoi(argv[3]);
|
||||
monValue = atof(argv[4]);
|
||||
|
||||
if(pCount != NULL){
|
||||
SetMonitorValue(pCount,mon,(long)monValue);
|
||||
@@ -203,6 +242,8 @@ static int insertHM(pMcStasReader self, SConnection *pCon,
|
||||
int status, type, rank, iDim[NX_MAXRANK];
|
||||
int length, i;
|
||||
HistInt *lData = NULL;
|
||||
float scale = 1.;
|
||||
double val;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,\
|
||||
@@ -230,6 +271,9 @@ static int insertHM(pMcStasReader self, SConnection *pCon,
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
if(argc > 4){
|
||||
scale = atof(argv[4]);
|
||||
}
|
||||
|
||||
status = NXgetinfo(self->handle,&rank,iDim,&type);
|
||||
if(status != NX_OK){
|
||||
@@ -266,7 +310,9 @@ static int insertHM(pMcStasReader self, SConnection *pCon,
|
||||
pPtr = pData;
|
||||
for(i = 0; i < length && pPtr != NULL; i++){
|
||||
pPtr = getNextMCNumber(pPtr,pNumber);
|
||||
lData[i] = atoi(pNumber);
|
||||
val = atof(pNumber);
|
||||
val *= scale;
|
||||
lData[i] = (HistInt)val;
|
||||
}
|
||||
|
||||
SetHistogram(pHM,pCon,0,0,length,lData);
|
||||
@@ -275,6 +321,61 @@ static int insertHM(pMcStasReader self, SConnection *pCon,
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static int insertHMFromData(pMcStasReader self, SConnection *pCon,
|
||||
SicsInterp *pSics, int argc, char *argv[]){
|
||||
char pBueffel[512];
|
||||
pHistMem pHM = NULL;
|
||||
int length, i;
|
||||
HistInt *lData = NULL;
|
||||
pSICSData data = NULL;
|
||||
|
||||
if(argc < 4){
|
||||
SCWrite(pCon,\
|
||||
"ERROR: insufficient number of arguments to mcreader inserthmfromdata",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
pHM = FindCommandData(pSics,argv[2],"HistMem");
|
||||
if(pHM == NULL){
|
||||
snprintf(pBueffel,511,
|
||||
"ERROR: %s is no histogram memory object",
|
||||
argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
data = FindCommandData(pSics,argv[3],"SICSData");
|
||||
if(data == NULL){
|
||||
snprintf(pBueffel,511,
|
||||
"ERROR: %s is no SICSData object",
|
||||
argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
length = GetHistLength(pHM);
|
||||
if(data->currentDataSize < length){
|
||||
snprintf(pBueffel,511,"WARNING: data in %s to short for HM %s",
|
||||
argv[3],argv[2]);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
}
|
||||
lData = (HistInt *)malloc(length*sizeof(HistInt));
|
||||
if(lData== NULL){
|
||||
SCWrite(pCon,"ERROR: out of memory in mcreader inserthm",eError);
|
||||
return 0;
|
||||
}
|
||||
memset(lData,0,length*sizeof(HistInt));
|
||||
if(data->currentDataSize < length){
|
||||
length = data->currentDataSize;
|
||||
}
|
||||
for(i = 0; i < length; i++){
|
||||
lData[i] = (HistInt)data->data[i];
|
||||
}
|
||||
SetHistogram(pHM,pCon,0,0,length,lData);
|
||||
free(lData);
|
||||
SCSendOK(pCon);
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int McStasReaderWrapper(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[]){
|
||||
@@ -296,8 +397,12 @@ int McStasReaderWrapper(SConnection *pCon, SicsInterp *pSics,
|
||||
return closeMcStasFile(self,pCon);
|
||||
} else if(strcmp(argv[1],"insertmon") == 0){
|
||||
return insertMonitor(self,pCon, pSics,argc,argv);
|
||||
} else if(strcmp(argv[1],"insertmondirect") == 0){
|
||||
return insertMonitorDirect(self,pCon, pSics,argc,argv);
|
||||
} else if(strcmp(argv[1],"inserthm") == 0){
|
||||
return insertHM(self,pCon, pSics,argc,argv);
|
||||
} else if(strcmp(argv[1],"inserthmfromdata") == 0){
|
||||
return insertHMFromData(self,pCon, pSics,argc,argv);
|
||||
} else {
|
||||
snprintf(pBueffel,511,"ERROR: invalid subcommand %s to %s",
|
||||
argv[1],argv[0]);
|
||||
|
||||
Reference in New Issue
Block a user