- Removed napi from SICS

- Added error fields to hwardware objects: motor, counter, histmem
- Optimised sinqhttpopt
- Added haddcheck which adds checks to hipadaba nodes. The current implementation
  only checks for selctions agaisnt the values property. Expand when more checks are
  required.


SKIPPED:
	psi/polterwrite.c
	psi/sinqhttpopt.c
	psi/tasinit.c
This commit is contained in:
koennecke
2013-08-14 09:50:22 +00:00
parent 255b83665c
commit 5a06bb9b90
35 changed files with 255 additions and 10598 deletions

View File

@ -668,7 +668,7 @@ Ascon *AsconMake(SConnection * con, int argc, char *argv[])
free(args); free(args);
return NULL; return NULL;
} }
a->rdBuffer = CreateDynString(60, 63); a->rdBuffer = CreateDynString(60, 65536);
a->wrBuffer = CreateDynString(60, 63); a->wrBuffer = CreateDynString(60, 63);
a->errmsg = CreateDynString(60, 63); a->errmsg = CreateDynString(60, 63);

View File

@ -395,7 +395,7 @@ void ANETprocess(void)
{ {
int i, status, count = 0, socke = 0, length; int i, status, count = 0, socke = 0, length;
fd_set readMask, writeMask; fd_set readMask, writeMask;
struct timeval tmo = { 0, 10 }; struct timeval tmo = { 0, 20 };
FD_ZERO(&readMask); FD_ZERO(&readMask);
FD_ZERO(&writeMask); FD_ZERO(&writeMask);

View File

@ -71,7 +71,19 @@ static int Halt(void *pData)
return self->pDriv->Halt(self->pDriv); return self->pDriv->Halt(self->pDriv);
} }
/*-------------------------------------------------------------------------*/
static void SetCounterError(void *pData, char *text)
{
pCounter self = NULL;
assert(pData);
self = (pCounter) pData;
if(self->error != NULL){
free(self->error);
}
self->error = strdup(text);
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static void SetCountParameters(void *pData, float fPreset, static void SetCountParameters(void *pData, float fPreset,
CounterMode eMode) CounterMode eMode)
@ -103,6 +115,7 @@ static int StartCount(void *pData, SConnection * pCon)
return 0; return 0;
} }
SetCounterError(pData,"None");
/* try at least three times to do it */ /* try at least three times to do it */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
iRet = self->pDriv->Start(self->pDriv); iRet = self->pDriv->Start(self->pDriv);
@ -122,6 +135,7 @@ static int StartCount(void *pData, SConnection * pCon)
eError); eError);
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
ReleaseCountLock(self->pCountInt); ReleaseCountLock(self->pCountInt);
SetCounterError(pData,pError);
return HWFault; return HWFault;
} }
} }
@ -233,6 +247,7 @@ static int TransferData(void *pData, SConnection * pCon)
SCWrite(pCon, "ERROR: Cannot fix counter problem, aborting", SCWrite(pCon, "ERROR: Cannot fix counter problem, aborting",
eError); eError);
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
SetCounterError(pData,pError);
return HWFault; return HWFault;
} }
} }
@ -269,6 +284,7 @@ static int CheckCountStatus(void *pData, SConnection * pCon)
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
InvokeCallBack(self->pCall, COUNTEND, NULL); InvokeCallBack(self->pCall, COUNTEND, NULL);
ReleaseCountLock(self->pCountInt); ReleaseCountLock(self->pCountInt);
SetCounterError(pData,pError);
return eCt; return eCt;
} else { } else {
return HWBusy; return HWBusy;
@ -695,7 +711,7 @@ static int isAuthorised(SConnection * pCon, int iCode)
} }
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
static int CounterInterest(int iEvent, void *pEvent, void *pUser) int CounterInterest(int iEvent, void *pEvent, void *pUser)
{ {
SConnection *pCon = NULL; SConnection *pCon = NULL;
pMonEvent pMon = NULL; pMonEvent pMon = NULL;
@ -775,6 +791,7 @@ pCounter CreateCounter(char *name, pCounterDriver pDriv)
pRes->isUpToDate = 1; pRes->isUpToDate = 1;
pRes->iExponent = 0; pRes->iExponent = 0;
pRes->name = strdup(name); pRes->name = strdup(name);
pRes->error = strdup("None");
return pRes; return pRes;
} }
@ -816,7 +833,8 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
{"setpar", 3, {FUPATEXT, FUPAINT, FUPAFLOAT}}, {"setpar", 3, {FUPATEXT, FUPAINT, FUPAFLOAT}},
{"getpar", 2, {FUPATEXT, FUPAOPT}}, {"getpar", 2, {FUPATEXT, FUPAOPT}},
{"getnmon", 0, {0, 0}}, {"getnmon", 0, {0, 0}},
{"state", 0, {0, 0}} {"state", 0, {0, 0}},
{"error", 0, {0, 0}}
}; };
char *pMode[] = { char *pMode[] = {
"timer", "timer",
@ -833,7 +851,7 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
argtolower(argc, argv); argtolower(argc, argv);
argx = &argv[1]; argx = &argv[1];
iRet = iRet =
EvaluateFuPa((pFuncTemplate) & ActionTemplate, 24, argc - 1, argx, EvaluateFuPa((pFuncTemplate) & ActionTemplate, 25, argc - 1, argx,
&PaRes); &PaRes);
if (iRet < 0) { if (iRet < 0) {
snprintf(pBueffel, 255,"%s", PaRes.pError); snprintf(pBueffel, 255,"%s", PaRes.pError);
@ -1150,6 +1168,11 @@ int CountAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCWrite(pCon, pBueffel, eValue); SCWrite(pCon, pBueffel, eValue);
return 1; return 1;
break; break;
case 24: /* error */
snprintf(pBueffel, 131, "%s.error = %s", argv[0],self->error);
SCWrite(pCon, pBueffel, eValue);
return 1;
break;
default: default:
assert(0); /* internal error */ assert(0); /* internal error */
} }

View File

@ -32,6 +32,7 @@ typedef struct __Counter{
int haltFixFlag; /* solely here to prevent multiple calls to the halt function on overrun timers in countersec.c*/ int haltFixFlag; /* solely here to prevent multiple calls to the halt function on overrun timers in countersec.c*/
int tbLength; /* These two for caching float time bins in second generation HM's */ int tbLength; /* These two for caching float time bins in second generation HM's */
float *timeBinning; float *timeBinning;
char *error;
int (*setMode)(struct __Counter *self, CounterMode eMode); int (*setMode)(struct __Counter *self, CounterMode eMode);
CounterMode (*getMode)(struct __Counter *self); CounterMode (*getMode)(struct __Counter *self);
int (*getNMonitor)(struct __Counter *self); int (*getNMonitor)(struct __Counter *self);

View File

@ -83,7 +83,15 @@ static int Resize(pDynString self, int iRequested)
self->iBufferSize = iNewSize; self->iBufferSize = iNewSize;
return 1; return 1;
} }
/*--------------------------------------------------------------------------*/
int DynStringCapacity(pDynString self, int length)
{
if(self->iBufferSize < length){
return Resize(self,length);
} else {
return 1;
}
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void DeleteDynString(pDynString self) void DeleteDynString(pDynString self)
{ {

View File

@ -109,4 +109,9 @@ char *Dyn2Cstring(pDynString self);
/* /*
convert to C string and delete dynstring. The result must be freed when no longer used. convert to C string and delete dynstring. The result must be freed when no longer used.
*/ */
/*
Ensures that the DynString has the capacity length. In order to avoid unnecessary
concatenation when the length is already known.
*/
int DynStringCapacity(pDynString self, int length);
#endif #endif

View File

@ -303,6 +303,10 @@ static pHdb locateChild(pHdb root, char *name)
{ {
pHdb current = NULL; pHdb current = NULL;
if(root == NULL){
return NULL;
}
current = root->child; current = root->child;
while (current != NULL) { while (current != NULL) {
if (strcmp(current->name, name) == 0) { if (strcmp(current->name, name) == 0) {

View File

@ -18,6 +18,10 @@
Mark Koennecke, March 2009 Mark Koennecke, March 2009
Added an error field in the options stringdict
Mark Koennecke, June 2013
Copyright: Copyright:
Labor fuer Neutronenstreuung Labor fuer Neutronenstreuung
@ -204,6 +208,7 @@ static int HistStartCount(void *pData, SConnection * pCon)
} }
/* try at least three times to do it */ /* try at least three times to do it */
StringDictUpdate(self->pDriv->pOption, "error", "None");
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
iRet = self->pDriv->Start(self->pDriv, pCon); iRet = self->pDriv->Start(self->pDriv, pCon);
if (iRet == OKOK) { if (iRet == OKOK) {
@ -221,6 +226,7 @@ static int HistStartCount(void *pData, SConnection * pCon)
eLogError); eLogError);
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
ReleaseCountLock(self->pCountInt); ReleaseCountLock(self->pCountInt);
StringDictUpdate(self->pDriv->pOption, "error", pError);
return HWFault; return HWFault;
} }
} }
@ -344,6 +350,7 @@ static int HistCountStatus(void *pData, SConnection * pCon)
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
InvokeCallBack(self->pCall, COUNTEND, NULL); InvokeCallBack(self->pCall, COUNTEND, NULL);
ReleaseCountLock(self->pCountInt); ReleaseCountLock(self->pCountInt);
StringDictUpdate(self->pDriv->pOption, "error", pError);
return eCt; return eCt;
} else { } else {
updateHMData(self->pDriv->data); updateHMData(self->pDriv->data);
@ -399,6 +406,7 @@ static int HistTransfer(void *pData, SConnection * pCon)
SCWrite(pCon, "ERROR: failed to fix histogram memory problem", SCWrite(pCon, "ERROR: failed to fix histogram memory problem",
eError); eError);
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
StringDictUpdate(self->pDriv->pOption, "error", pError);
iStatus = HWFault; iStatus = HWFault;
} }
} }
@ -465,6 +473,7 @@ pHistMem CreateHistMemory(char *driver)
} }
StringDictAddPair(pOption, "driver", driver); StringDictAddPair(pOption, "driver", driver);
StringDictAddPair(pOption, "update", "0"); StringDictAddPair(pOption, "update", "0");
StringDictAddPair(pOption, "error", "None");
/* initialise driver */ /* initialise driver */
if (strcmp(driver, "sim") == 0) { if (strcmp(driver, "sim") == 0) {
@ -912,6 +921,7 @@ int GetHistogramDirect(pHistMem self, SConnection * pCon,
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
if (iRet == COTERM) { if (iRet == COTERM) {
StringDictUpdate(self->pDriv->pOption, "error", pError);
return 0; return 0;
} }
} }
@ -963,6 +973,7 @@ int PresetHistogram(pHistMem self, SConnection * pCon, HistInt lVal)
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr); iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
if (iRet == COTERM) { if (iRet == COTERM) {
StringDictUpdate(self->pDriv->pOption, "error", pError);
return 0; return 0;
} }
} }
@ -1790,6 +1801,12 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
} }
/* error */
else if (strcmp(argv[1], "error") == 0) {
StringDictGet(self->pDriv->pOption, "error", pBueffel, sizeof(pBueffel));
SCPrintf(pCon,eValue,"%s.error = %s", argv[0], pBueffel);
return 1;
}
/*-------- sum */ /*-------- sum */
else if (strcmp(argv[1], "sum") == 0) { else if (strcmp(argv[1], "sum") == 0) {
/* read following arguments as ints and put them /* read following arguments as ints and put them

29
macro.c
View File

@ -172,19 +172,22 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter,
} }
/* check for endless loop */ /* check for endless loop */
Arg2Text(margc, myarg, comBuffer, 131); /* Arg2Text(margc, myarg, comBuffer, 131); */
if (lastCommand != NULL) { /* if (lastCommand != NULL) { */
if (strcmp(lastCommand, comBuffer) == 0) { /* if (strcmp(lastCommand, comBuffer) == 0) { */
Tcl_AppendResult(pInter, "ERROR: Never ending loop in unknown\n", /* Tcl_AppendResult(pInter, "ERROR: Never ending loop in unknown\n", */
"Offending command: ", comBuffer, /* "Offending command: ", comBuffer, */
" Probably Tcl command not found", NULL); /* " Probably Tcl command not found", NULL); */
SCSetInterrupt(pCon, eAbortBatch); /* /\* SCSetInterrupt(pCon, eAbortBatch); */
return TCL_ERROR; /* The interrupt cause me a problem in a race condition at BOA. */
} /* Try to understand why this check is necessary in the first place. */
} /* *\/ */
if (pSics->lastUnknown[pSics->iStack]) /* return TCL_ERROR; */
free(pSics->lastUnknown[pSics->iStack]); /* } */
pSics->lastUnknown[pSics->iStack] = strdup(comBuffer); /* } */
/* if (pSics->lastUnknown[pSics->iStack]) */
/* free(pSics->lastUnknown[pSics->iStack]); */
/* pSics->lastUnknown[pSics->iStack] = strdup(comBuffer); */
/* invoke */ /* invoke */
pCon->sicsError = 0; pCon->sicsError = 0;

View File

@ -13,9 +13,9 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
sicsexit.o costa.o task.o $(FORTIFYOBJ) testprot.o\ sicsexit.o costa.o task.o $(FORTIFYOBJ) testprot.o\
macro.o ofac.o obpar.o obdes.o drive.o status.o intserv.o \ macro.o ofac.o obpar.o obdes.o drive.o status.o intserv.o \
devexec.o mumo.o mumoconf.o selector.o selvar.o fupa.o lld.o \ devexec.o mumo.o mumoconf.o selector.o selvar.o fupa.o lld.o \
lld_blob.o strrepl.o lin2ang.o fomerge.o napi5.o napi4.o\ lld_blob.o strrepl.o lin2ang.o fomerge.o \
script.o o2t.o alias.o napi.o stringdict.o sdynar.o \ script.o o2t.o alias.o stringdict.o sdynar.o \
histmem.o histdriv.o histsim.o interface.o callback.o nxio.o \ histmem.o histdriv.o histsim.o interface.o callback.o \
event.o emon.o evcontroller.o evdriver.o simev.o perfmon.o \ event.o emon.o evcontroller.o evdriver.o simev.o perfmon.o \
danu.o nxdict.o varlog.o stptok.o nread.o trigd.o cell.o\ danu.o nxdict.o varlog.o stptok.o nread.o trigd.o cell.o\
scan.o fitcenter.o telnet.o token.o wwildcard.o hklmot.o\ scan.o fitcenter.o telnet.o token.o wwildcard.o hklmot.o\
@ -25,7 +25,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
simchop.o choco.o chadapter.o trim.o scaldate.o tasub.o\ simchop.o choco.o chadapter.o trim.o scaldate.o tasub.o\
xytable.o exebuf.o exeman.o ubfour.o ubcalc.o\ xytable.o exebuf.o exeman.o ubfour.o ubcalc.o\
circular.o maximize.o sicscron.o scanvar.o tasublib.o\ circular.o maximize.o sicscron.o scanvar.o tasublib.o\
d_sign.o d_mod.o tcldrivable.o stdscan.o diffscan.o nxxml.o\ d_sign.o d_mod.o tcldrivable.o stdscan.o diffscan.o \
synchronize.o definealias.o oscillate.o tasdrive.o \ synchronize.o definealias.o oscillate.o tasdrive.o \
hmcontrol.o userscan.o rs232controller.o lomax.o tasscanub.o \ hmcontrol.o userscan.o rs232controller.o lomax.o tasscanub.o \
fourlib.o motreg.o motreglist.o anticollider.o nxdataset.o \ fourlib.o motreg.o motreglist.o anticollider.o nxdataset.o \
@ -38,7 +38,7 @@ SOBJ = network.o ifile.o conman.o SCinter.o splitter.o passwd.o \
moregress.o multicounter.o regresscter.o histregress.o \ moregress.o multicounter.o regresscter.o histregress.o \
sicshdbadapter.o polldriv.o sicspoll.o statemon.o hmslave.o \ sicshdbadapter.o polldriv.o sicspoll.o statemon.o hmslave.o \
nwatch.o asyncqueue.o asyncprotocol.o sicsobj.o frame.o syncedprot.o\ nwatch.o asyncqueue.o asyncprotocol.o sicsobj.o frame.o syncedprot.o\
nxcopy.o nxinterhelper.o nxinter_wrap.o nxstack.o arrayutil.o \ nxcopy.o nxinterhelper.o nxinter_wrap.o arrayutil.o \
sctdriveadapter.o sctdriveobj.o reflist.o singlex.o fourmess.o \ sctdriveadapter.o sctdriveobj.o reflist.o singlex.o fourmess.o \
sgclib.o sgfind.o sgio.o sgsi.o sghkl.o singlediff.o singlebi.o \ sgclib.o sgfind.o sgio.o sgsi.o sghkl.o singlediff.o singlebi.o \
singlenb.o simindex.o simidx.o uselect.o singletas.o motorsec.o \ singlenb.o simindex.o simidx.o uselect.o singletas.o motorsec.o \

View File

@ -26,7 +26,7 @@ EXTRA=nintf.o
SUBLIBS = psi/libpsi.a psi/hardsup/libhlib.a matrix/libmatrix.a \ SUBLIBS = psi/libpsi.a psi/hardsup/libhlib.a matrix/libmatrix.a \
psi/tecs/libtecsl.a psi/tecs/libtecsl.a
LIBS = -L$(HDFROOT)/lib $(SUBLIBS) $(NILIB) $(EPICSLIBS) \ LIBS = -L$(HDFROOT)/lib $(SUBLIBS) $(NILIB) $(EPICSLIBS) \
-ltcl $(HDFROOT)/lib/libhdf5.a \ -ltcl -lNeXus $(HDFROOT)/lib/libhdf5.a \
$(HDFROOT)/lib/libsz.a \ $(HDFROOT)/lib/libsz.a \
$(HDFROOT)/lib/libjson.a \ $(HDFROOT)/lib/libjson.a \
-ldl -lz $(HDFROOT)/lib/libmxml.a $(HDFROOT)/lib/libghttp.a -lm -lc -lpthread -ldl -lz $(HDFROOT)/lib/libmxml.a $(HDFROOT)/lib/libghttp.a -lm -lc -lpthread

25
motor.c
View File

@ -81,7 +81,14 @@
#define IGNOREFAULT 10 #define IGNOREFAULT 10
#define MOVECOUNT 11 #define MOVECOUNT 11
/*-------------------------------------------------------------------------*/
static void SetMotorError(pMotor self, char *text)
{
if(self->error != NULL){
free(self->error);
}
self->error = strdup(text);
}
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void *MotorGetInterface(void *pData, int iID) static void *MotorGetInterface(void *pData, int iID)
{ {
@ -378,17 +385,18 @@ static int reportAndFixError(pMotor self, SConnection * pCon)
switch (iRet) { switch (iRet) {
case MOTFAIL: case MOTFAIL:
snprintf(pBueffel, 255, "ERROR: %s on %s", pError, self->name); snprintf(pBueffel, 255, "ERROR: %s on %s", pError, self->name);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eLogError);
newStatus = HWFault; newStatus = HWFault;
SetMotorError(self,pError);
break; break;
case MOTREDO: case MOTREDO:
snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name); snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name);
SCWrite(pCon, pBueffel, eWarning); SCWrite(pCon, pBueffel, eLog);
newStatus = statusRunTo(self, pCon); newStatus = statusRunTo(self, pCon);
break; break;
case MOTOK: case MOTOK:
snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name); snprintf(pBueffel, 255, "WARNING: %s on %s", pError, self->name);
SCWrite(pCon, pBueffel, eWarning); SCWrite(pCon, pBueffel, eLog);
newStatus = HWIdle; newStatus = HWIdle;
break; break;
default: default:
@ -702,6 +710,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
return 0; return 0;
} }
SetMotorError(self,"None");
/* check boundaries first */ /* check boundaries first */
iRet = MotorCheckBoundaryImpl(self, fNew, &fHard, pError, 131); iRet = MotorCheckBoundaryImpl(self, fNew, &fHard, pError, 131);
@ -709,6 +718,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
snprintf(pBueffel, 511, "ERROR: %s", pError); snprintf(pBueffel, 511, "ERROR: %s", pError);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
SCSetInterrupt(pCon, eAbortOperation); SCSetInterrupt(pCon, eAbortOperation);
SetMotorError(self,pError);
return 0; return 0;
} }
@ -731,6 +741,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
ServerWriteGlobal(pBueffel, eError); ServerWriteGlobal(pBueffel, eError);
SCSetInterrupt(pCon, eAbortBatch); SCSetInterrupt(pCon, eAbortBatch);
self->pDrivInt->iErrorCount = 0; self->pDrivInt->iErrorCount = 0;
SetMotorError(self,"Motor ALARM!!!!");
return 0; return 0;
} }
@ -753,6 +764,7 @@ static long MotorRunImpl(void *sulf, SConnection * pCon, float fNew)
SCWrite(pCon, pError, eError); SCWrite(pCon, pError, eError);
SCWrite(pCon, "\n", eError); SCWrite(pCon, "\n", eError);
SCSetInterrupt(pCon, (int) ObVal(self->ParArray, INT)); SCSetInterrupt(pCon, (int) ObVal(self->ParArray, INT));
SetMotorError(self,pError);
return HWFault; return HWFault;
case MOTREDO: case MOTREDO:
iRet = self->pDriver->RunTo(self->pDriver, fHard); iRet = self->pDriver->RunTo(self->pDriver, fHard);
@ -821,6 +833,7 @@ pMotor MotorInit(char *drivername, char *name, MotorDriver * pDriv)
pM->pDriver = pDriv; pM->pDriver = pDriv;
pM->drivername = strdup(drivername); pM->drivername = strdup(drivername);
pM->name = strdup(name); pM->name = strdup(name);
pM->error = strdup("None");
/* initialise object descriptor */ /* initialise object descriptor */
@ -1286,6 +1299,10 @@ int MotorAction(SConnection * pCon, SicsInterp * pSics, void *pData,
DeleteTokenList(pList); DeleteTokenList(pList);
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
} /* check for error */
else if (strcmp(pCurrent->text, "error") == 0) {
SCPrintf(pCon,eValue,"%s.error = %s", argv[0], self->error);
return 1;
} else if (strcmp(pCurrent->text, "interest") == 0) { /* interest */ } else if (strcmp(pCurrent->text, "interest") == 0) { /* interest */
pMoti = (pMotInfo) malloc(sizeof(MotInfo)); pMoti = (pMotInfo) malloc(sizeof(MotInfo));
if (!pMoti) { if (!pMoti) {

View File

@ -28,6 +28,7 @@ typedef struct __Motor {
float *fVal); float *fVal);
char *drivername; char *drivername;
char *name; char *name;
char *error;
MotorDriver *pDriver; MotorDriver *pDriver;
float fTarget; float fTarget;
float fPosition; float fPosition;

2133
napi.c

File diff suppressed because it is too large Load Diff

959
napi.h
View File

@ -1,959 +0,0 @@
/*---------------------------------------------------------------------------
NeXus - Neutron & X-ray Common Data Format
Application Program Interface Header File
Copyright (C) 2000-2011 Mark Koennecke, Uwe Filges
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information, see <http://www.nexusformat.org>
$Id: napi.h,v 1.14 2012/03/29 08:41:06 koennecke Exp $
----------------------------------------------------------------------------*/
/** \file
* Documentation for the NeXus-API version 4.3
* 2000-2011, the NeXus International Advisory Commitee
* \defgroup c_main C API
* \defgroup c_types Data Types
* \ingroup c_main
* \defgroup c_init General Initialisation and shutdown
* \ingroup c_main
* \defgroup c_group Reading and Writing Groups
* \ingroup c_main
* \defgroup c_readwrite Reading and Writing Data
* \ingroup c_main
* \defgroup c_navigation General File navigation
* \ingroup c_main
* \defgroup c_metadata Meta data routines
* \ingroup c_main
* \defgroup c_linking Linking
* \ingroup c_main
* \defgroup c_memory Memory allocation
* \ingroup c_main
* \defgroup c_external External linking
* \ingroup c_main
*/
#ifndef NEXUSAPI
#define NEXUSAPI
#include <stdint.h>
/* NeXus HDF45 */
#define NEXUS_VERSION "4.3.0" /* major.minor.patch */
#define CONSTCHAR const char
typedef void* NXhandle; /* really a pointer to a NexusFile structure */
typedef int NXstatus;
typedef char NXname[128];
/*
* Any new NXaccess_mode options should be numbered in 2^n format
* (8, 16, 32, etc) so that they can be bit masked and tested easily.
*
* To test older non bit masked options (values below 8) use e.g.
*
* if ( (mode & NXACCMASK_REMOVEFLAGS) == NXACC_CREATE )
*
* To test new (>=8) options just use normal bit masking e.g.
*
* if ( mode & NXACC_NOSTRIP )
*
*/
#define NXACCMASK_REMOVEFLAGS (0x7) /* bit mask to remove higher flag options */
/** \enum NXaccess_mode
* NeXus file access codes.
* \li NXACC_READ read-only
* \li NXACC_RDWR open an existing file for reading and writing.
* \li NXACC_CREATE create a NeXus HDF-4 file
* \li NXACC_CREATE4 create a NeXus HDF-4 file
* \li NXACC_CREATE5 create a NeXus HDF-5 file.
* \li NXACC_CREATEXML create a NeXus XML file.
* \li NXACC_CHECKNAMESYNTAX Check names conform to NeXus allowed characters.
*/
typedef enum {NXACC_READ=1, NXACC_RDWR=2, NXACC_CREATE=3, NXACC_CREATE4=4,
NXACC_CREATE5=5, NXACC_CREATEXML=6, NXACC_TABLE=8, NXACC_NOSTRIP=128, NXACC_CHECKNAMESYNTAX=256 } NXaccess_mode;
/**
* A combination of options from #NXaccess_mode
*/
typedef int NXaccess;
typedef struct {
char *iname;
int type;
}info_type, *pinfo;
#define NX_OK 1
#define NX_ERROR 0
#define NX_EOD -1
#define NX_UNLIMITED -1
#define NX_MAXRANK 32
#define NX_MAXNAMELEN 64
#define NX_MAXPATHLEN 1024
/**
* \ingroup c_types
* \def NX_FLOAT32
* 32 bit float
* \def NX_FLOAT64
* 64 bit float == double
* \def NX_INT8
* 8 bit integer == byte
* \def NX_UINT8
* 8 bit unsigned integer
* \def NX_INT16
* 16 bit integer
* \def NX_UINT16
* 16 bit unsigned integer
* \def NX_INT32
* 32 bit integer
* \def NX_UINT32
* 32 bit unsigned integer
* \def NX_CHAR
* 8 bit character
* \def NX_BINARY
* lump of binary data == NX_UINT8
*/
/*--------------------------------------------------------------------------*/
/* Map NeXus to HDF types */
#define NX_FLOAT32 5
#define NX_FLOAT64 6
#define NX_INT8 20
#define NX_UINT8 21
#define NX_BOOLEAN NX_UINT
#define NX_INT16 22
#define NX_UINT16 23
#define NX_INT32 24
#define NX_UINT32 25
#define NX_INT64 26
#define NX_UINT64 27
#define NX_CHAR 4
#define NX_BINARY 21
/* Map NeXus compression methods to HDF compression methods */
#define NX_CHUNK 0
#define NX_COMP_NONE 100
#define NX_COMP_LZW 200
#define NX_COMP_RLE 300
#define NX_COMP_HUF 400
/* to test for these we use ((value / 100) == NX_COMP_LZW) */
#define NX_COMP_LZW_LVL0 (100*NX_COMP_LZW + 0)
#define NX_COMP_LZW_LVL1 (100*NX_COMP_LZW + 1)
#define NX_COMP_LZW_LVL2 (100*NX_COMP_LZW + 2)
#define NX_COMP_LZW_LVL3 (100*NX_COMP_LZW + 3)
#define NX_COMP_LZW_LVL4 (100*NX_COMP_LZW + 4)
#define NX_COMP_LZW_LVL5 (100*NX_COMP_LZW + 5)
#define NX_COMP_LZW_LVL6 (100*NX_COMP_LZW + 6)
#define NX_COMP_LZW_LVL7 (100*NX_COMP_LZW + 7)
#define NX_COMP_LZW_LVL8 (100*NX_COMP_LZW + 8)
#define NX_COMP_LZW_LVL9 (100*NX_COMP_LZW + 9)
typedef struct {
long iTag; /* HDF4 variable */
long iRef; /* HDF4 variable */
char targetPath[1024]; /* path to item to link */
int linkType; /* HDF5: 0 for group link, 1 for SDS link */
} NXlink;
#define NXMAXSTACK 50
#define CONCAT(__a,__b) __a##__b /* token concatenation */
# ifdef __VMS
# define MANGLE(__arg) __arg
# else
# define MANGLE(__arg) CONCAT(__arg,_)
# endif
# define NXopen MANGLE(nxiopen)
# define NXreopen MANGLE(nxireopen)
# define NXclose MANGLE(nxiclose)
# define NXmakegroup MANGLE(nximakegroup)
# define NXopengroup MANGLE(nxiopengroup)
# define NXopenpath MANGLE(nxiopenpath)
# define NXgetpath MANGLE(nxigetpath)
# define NXopengrouppath MANGLE(nxiopengrouppath)
# define NXclosegroup MANGLE(nxiclosegroup)
# define NXmakedata MANGLE(nximakedata)
# define NXmakedata64 MANGLE(nximakedata64)
# define NXcompmakedata MANGLE(nxicompmakedata)
# define NXcompmakedata64 MANGLE(nxicompmakedata64)
# define NXcompress MANGLE(nxicompress)
# define NXopendata MANGLE(nxiopendata)
# define NXclosedata MANGLE(nxiclosedata)
# define NXputdata MANGLE(nxiputdata)
# define NXputslab MANGLE(nxiputslab)
# define NXputslab64 MANGLE(nxiputslab64)
# define NXputattr MANGLE(nxiputattr)
# define NXgetdataID MANGLE(nxigetdataid)
# define NXmakelink MANGLE(nximakelink)
# define NXmakenamedlink MANGLE(nximakenamedlink)
# define NXopensourcegroup MANGLE(nxiopensourcegroup)
# define NXmalloc MANGLE(nximalloc)
# define NXmalloc64 MANGLE(nximalloc64)
# define NXfree MANGLE(nxifree)
# define NXflush MANGLE(nxiflush)
# define NXgetinfo MANGLE(nxigetinfo)
# define NXgetinfo64 MANGLE(nxigetinfo64)
# define NXgetrawinfo MANGLE(nxigetrawinfo)
# define NXgetrawinfo64 MANGLE(nxigetrawinfo64)
# define NXgetnextentry MANGLE(nxigetnextentry)
# define NXgetdata MANGLE(nxigetdata)
# define NXgetslab MANGLE(nxigetslab)
# define NXgetslab64 MANGLE(nxigetslab64)
# define NXgetnextattr MANGLE(nxigetnextattr)
# define NXgetattr MANGLE(nxigetattr)
# define NXgetattrinfo MANGLE(nxigetattrinfo)
# define NXgetgroupID MANGLE(nxigetgroupid)
# define NXgetgroupinfo MANGLE(nxigetgroupinfo)
# define NXsameID MANGLE(nxisameid)
# define NXinitgroupdir MANGLE(nxiinitgroupdir)
# define NXinitattrdir MANGLE(nxiinitattrdir)
# define NXsetnumberformat MANGLE(nxisetnumberformat)
# define NXsetcache MANGLE(nxisetcache)
# define NXinquirefile MANGLE(nxiinquirefile)
# define NXisexternalgroup MANGLE(nxiisexternalgroup)
# define NXisexternaldataset MANGLE(nxiisexternaldataset)
# define NXlinkexternal MANGLE(nxilinkexternal)
# define NXlinkexternaldataset MANGLE(nxilinkexternaldataset)
# define NXgetversion MANGLE(nxigetversion)
/*
* FORTRAN helpers - for NeXus internal use only
*/
# define NXfopen MANGLE(nxifopen)
# define NXfclose MANGLE(nxifclose)
# define NXfflush MANGLE(nxifflush)
# define NXfmakedata MANGLE(nxifmakedata)
# define NXfcompmakedata MANGLE(nxifcompmakedata)
# define NXfcompress MANGLE(nxifcompress)
# define NXfputattr MANGLE(nxifputattr)
# define NXfgetpath MANGLE(nxifgetpath)
/*
* Standard interface
*
* Functions added here are not automatically exported from
* a shared library/dll - the symbol name must also be added
* to the file src/nexus_symbols.txt
*
*/
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/**
* Open a NeXus file.
* NXopen honours full path file names. But it also searches
* for files in all the paths given in the NX_LOAD_PATH environment variable.
* NX_LOAD_PATH is supposed to hold a list of path string separated by the platform
* specific path separator. For unix this is the : , for DOS the ; . Please note
* that crashing on an open NeXus file will result in corrupted data. Only after a NXclose
* or a NXflush will the data file be valid.
* \param filename The name of the file to open
* \param access_method The file access method. This can be:
* \li NXACC__READ read access
* \li NXACC_RDWR read write access
* \li NXACC_CREATE, NXACC_CREATE4 create a new HDF-4 NeXus file
* \li NXACC_CREATE5 create a new HDF-5 NeXus file
* \li NXACC_CREATEXML create an XML NeXus file.
* see #NXaccess_mode
* Support for HDF-4 is deprecated.
* \param pHandle A file handle which will be initialized upon successfull completeion of NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_init
*/
extern NXstatus NXopen(CONSTCHAR * filename, NXaccess access_method, NXhandle* pHandle);
/**
* Opens an existing NeXus file a second time for e.g. access from another thread.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_init
*/
extern NXstatus NXreopen(NXhandle pOrigHandle, NXhandle* pNewHandle);
/**
* close a NeXus file
* \param pHandle A NeXus file handle as returned from NXopen. pHandle is invalid after this
* call.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_init
*/
extern NXstatus NXclose(NXhandle* pHandle);
/**
* flush data to disk
* \param pHandle A NeXus file handle as initialized by NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXflush(NXhandle* pHandle);
/**
* NeXus groups are NeXus way of structuring information into a hierarchy.
* This function creates a group but does not open it.
* \param handle A NeXus file handle as initialized NXopen.
* \param name The name of the group
* \param NXclass the class name of the group. Should start with the prefix NX
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_group
*/
extern NXstatus NXmakegroup (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
/**
* Step into a group. All further access will be within the opened group.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the group
* \param NXclass the class name of the group. Should start with the prefix NX
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_group
*/
extern NXstatus NXopengroup (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
/**
* Open the NeXus object with the path specified
* \param handle A NeXus file handle as returned from NXopen.
* \param path A unix like path string to a NeXus group or dataset. The path string
* is a list of group names and SDS names separated with / (slash).
* Example: /entry1/sample/name
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_navigation
*/
extern NXstatus NXopenpath (NXhandle handle, CONSTCHAR *path);
/**
* Opens the group in which the NeXus object with the specified path exists
* \param handle A NeXus file handle as initialized by NXopen.
* \param path A unix like path string to a NeXus group or dataset. The path string
* is a list of group names and SDS names separated with / (slash).
* Example: /entry1/sample/name
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_navigation
*/
extern NXstatus NXopengrouppath (NXhandle handle, CONSTCHAR *path);
/**
* Retrieve the current path in the NeXus file
* \param handle a NeXus file handle
* \param path A buffer to copy the path too
* \param pathlen The maximum number of characters to copy into path
* \return NX_OK or NX_ERROR
* \ingroup c_navigation
*/
extern NXstatus NXgetpath(NXhandle handle, char *path, int pathlen);
/**
* Closes the currently open group and steps one step down in the NeXus file
* hierarchy.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_group
*/
extern NXstatus NXclosegroup(NXhandle handle);
/**
* Create a multi dimensional data array or dataset. The dataset is NOT opened.
* \param handle A NeXus file handle as initialized by NXopen.
* \param label The name of the dataset
* \param datatype The data type of this data set.
* \param rank The number of dimensions this dataset is going to have
* \param dim An array of size rank holding the size of the dataset in each dimension. The first dimension
* can be NX_UNLIMITED. Data can be appended to such a dimension using NXputslab.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXmakedata (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int dim[]);
/**
* @copydoc NXmakedata()
*/
extern NXstatus NXmakedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[]);
/**
* Create a compressed dataset. The dataset is NOT opened. Data from this set will automatically be compressed when
* writing and decompressed on reading.
* \param handle A NeXus file handle as initialized by NXopen.
* \param label The name of the dataset
* \param datatype The data type of this data set.
* \param rank The number of dimensions this dataset is going to have
* \param comp_typ The compression scheme to use. Possible values:
* \li NX_COMP_NONE no compression
* \li NX_COMP_LZW lossless Lempel Ziv Welch compression (recommended)
* \li NX_COMP_RLE run length encoding (only HDF-4)
* \li NX_COMP_HUF Huffmann encoding (only HDF-4)
* \param dim An array of size rank holding the size of the dataset in each dimension. The first dimension
* can be NX_UNLIMITED. Data can be appended to such a dimension using NXputslab.
* \param bufsize The dimensions of the subset of the data which usually be writen in one go.
* This is a parameter used by HDF for performance optimisations. If you write your data in one go, this
* should be the same as the data dimension. If you write it in slabs, this is your preferred slab size.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXcompmakedata (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int dim[], int comp_typ, int bufsize[]);
/**
* @copydoc NXcompmakedata()
*/
extern NXstatus NXcompmakedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[], int comp_typ, int64_t chunk_size[]);
/**
* Switch compression on. This routine is superseeded by NXcompmakedata and thus
* is deprecated.
* \param handle A NeXus file handle as initialized by NXopen.
* \param compr_type The compression scheme to use. Possible values:
* \li NX_COMP_NONE no compression
* \li NX_COMP_LZW lossless Lempel Ziv Welch compression (recommended)
* \li NX_COMP_RLE run length encoding (only HDF-4)
* \li NX_COMP_HUF Huffmann encoding (only HDF-4)
* \ingroup c_readwrite
*/
extern NXstatus NXcompress (NXhandle handle, int compr_type);
/**
* Open access to a dataset. After this call it is possible to write and read data or
* attributes to and from the dataset.
* \param handle A NeXus file handle as initialized by NXopen.
* \param label The name of the dataset
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXopendata (NXhandle handle, CONSTCHAR* label);
/**
* Close access to a dataset.
* \param handle A NeXus file handle as initialized by NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXclosedata(NXhandle handle);
/**
* Write data to a datset which has previouly been opened with NXopendata.
* This writes all the data in one go. Data should be a pointer to a memory
* area matching the datatype and dimensions of the dataset.
* \param handle A NeXus file handle as initialized by NXopen.
* \param data Pointer to data to write.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXputdata(NXhandle handle, const void* data);
/**
* Write an attribute. The kind of attribute written depends on the
* poistion in the file: at root level, a global attribute is written, if
* agroup is open but no dataset, a group attribute is written, if a dataset is
* open, a dataset attribute is written.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the attribute.
* \param data A pointer to the data to write for the attribute.
* \param iDataLen The length of the data in data in bytes.
* \param iType The NeXus data type of the attribute.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXputattr(NXhandle handle, CONSTCHAR* name, const void* data, int iDataLen, int iType);
/**
* Write a subset of a multi dimensional dataset.
* \param handle A NeXus file handle as initialized by NXopen.
* \param data A pointer to a memory area holding the data to write.
* \param start An array holding the start indices where to start the data subset.
* \param size An array holding the size of the data subset to write in each dimension.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXputslab(NXhandle handle, const void* data, const int start[], const int size[]);
/**
* @copydoc NXputdata()
*/
extern NXstatus NXputslab64(NXhandle handle, const void* data, const int64_t start[], const int64_t size[]);
/**
* Retrieve link data for a dataset. This link data can later on be used to link this
* dataset into a different group.
* \param handle A NeXus file handle as initialized by NXopen.
* \param pLink A link data structure which will be initialized with the required information
* for linking.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_linking
*/
extern NXstatus NXgetdataID(NXhandle handle, NXlink* pLink);
/**
* Create a link to the group or dataset described by pLink in the currently open
* group.
* \param handle A NeXus file handle as initialized by NXopen.
* \param pLink A link data structure describing the object to link. This must have been initialized
* by either a call to NXgetdataID or NXgetgroupID.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_linking
*/
extern NXstatus NXmakelink(NXhandle handle, NXlink* pLink);
/**
* Create a link to the group or dataset described by pLink in the currently open
* group. But give the linked item a new name.
* \param handle A NeXus file handle as initialized by NXopen.
* \param newname The new name of the item in the currently open group.
* \param pLink A link data structure describing the object to link. This must have been initialized
* by either a call to NXgetdataID or NXgetgroupID.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_linking
*/
extern NXstatus NXmakenamedlink(NXhandle handle, CONSTCHAR* newname, NXlink* pLink);
/**
* Open the source group of a linked group or dataset. Returns an error when the item is
* not a linked item.
* \param handle A NeXus file handle as initialized by NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_navigation
*/
extern NXstatus NXopensourcegroup(NXhandle handle);
/**
* Read a complete dataset from the currently open dataset into memory.
* \param handle A NeXus file handle as initialized by NXopen.
* \param data A pointer to the memory area where to read the data, too. Data must point to a memory
* area large enough to accomodate the data read. Otherwise your program may behave in unexpected
* and unwelcome ways.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXgetdata(NXhandle handle, void* data);
/**
* Retrieve information about the curretly open dataset.
* \param handle A NeXus file handle as initialized by NXopen.
* \param rank A pointer to an integer which will be filled with the rank of
* the dataset.
* \param dimension An array which will be initialized with the size of the dataset in any of its
* dimensions. The array must have at least the size of rank.
* \param datatype A pointer to an integer which be set to the NeXus data type code for this dataset.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_metadata
*/
extern NXstatus NXgetinfo(NXhandle handle, int* rank, int dimension[], int* datatype);
/**
* @copydoc NXgetinfo()
*/
extern NXstatus NXgetinfo64(NXhandle handle, int* rank, int64_t dimension[], int* datatype);
/**
* Get the next entry in the currently open group. This is for retrieving infromation about the
* content of a NeXus group. In order to search a group #NXgetnextentry is called in a loop until
* #NXgetnextentry returns NX_EOD which indicates that there are no further items in the group.
* Reset search using #NXinitgroupdir
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the object
* \param nxclass The NeXus class name for a group or the string SDS for a dataset.
* \param datatype The NeXus data type if the item is a SDS.
* \return NX_OK on success, NX_ERROR in the case of an error, NX_EOD when there are no more items.
* \ingroup c_navigation
*/
extern NXstatus NXgetnextentry(NXhandle handle, NXname name, NXname nxclass, int* datatype);
/**
* Read a subset of data from file into memory.
* \param handle A NeXus file handle as initialized by NXopen.
* \param data A pointer to the memory data where to copy the data too. The pointer must point
* to a memory area large enough to accomodate the size of the data read.
* \param start An array holding the start indices where to start reading the data subset.
* \param size An array holding the size of the data subset to read for each dimension.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXgetslab(NXhandle handle, void* data, int start[], int size[]);
/**
* @copydoc NXgetslab()
*/
extern NXstatus NXgetslab64(NXhandle handle, void* data, const int64_t start[], const int64_t size[]);
/**
* Iterate over global, group or dataset attributes depending on the currently open group or
* dataset. In order to search attributes multiple calls to #NXgetnextattr are performed in a loop
* until #NXgetnextattr returns NX_EOD which indicates that there are no further attributes.
* reset search using #NXinitattrdir
* \param handle A NeXus file handle as initialized by NXopen.
* \param pName The name of the attribute
* \param iLength A pointer to an integer which be set to the length of the attribute data.
* \param iType A pointer to an integer which be set to the NeXus data type of the attribute.
* \return NX_OK on success, NX_ERROR in the case of an error, NX_EOD when there are no more items.
* \ingroup c_readwrite
*/
extern NXstatus NXgetnextattr(NXhandle handle, NXname pName, int *iLength, int *iType);
/**
* Read an attribute.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the atrribute to read.
* \param data A pointer to a memory area large enough to hold the attributes value.
* \param iDataLen The length of data in bytes.
* \param iType A pointer to an integer which will had been set to the NeXus data type of the attribute.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXgetattr(NXhandle handle, char* name, void* data, int* iDataLen, int* iType);
/**
* Get the count of attributes in the currently open dataset, group or global attributes when at root level.
* \param handle A NeXus file handle as initialized by NXopen.
* \param no_items A pointer to an integer which be set to the number of attributes available.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_metadata
*/
extern NXstatus NXgetattrinfo(NXhandle handle, int* no_items);
/**
* Retrieve link data for the currently open group. This link data can later on be used to link this
* group into a different group.
* \param handle A NeXus file handle as initialized by NXopen.
* \param pLink A link data structure which will be initialized with the required information
* for linking.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_linking
*/
extern NXstatus NXgetgroupID(NXhandle handle, NXlink* pLink);
/**
* Retrieve information about the currently open group.
* \param handle A NeXus file handle as initialized by NXopen.
* \param no_items A pointer to an integer which will be set to the count
* of group elements available. This is the count of other groups and
* data sets in this group.
* \param name The name of the group.
* \param nxclass The NeXus class name of the group.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_metadata
*/
extern NXstatus NXgetgroupinfo(NXhandle handle, int* no_items, NXname name, NXname nxclass);
/**
* Tests if two link data structures describe the same item.
* \param handle A NeXus file handle as initialized by NXopen.
* \param pFirstID The first link data for the test.
* \param pSecondID The second link data structure.
* \return NX_OK when both link data structures describe the same item, NX_ERROR else.
* \ingroup c_linking
*/
extern NXstatus NXsameID(NXhandle handle, NXlink* pFirstID, NXlink* pSecondID);
/**
* Resets a pending group search to the start again. To be called in a #NXgetnextentry loop when
* a group search has to be restarted.
* \param handle A NeXus file handle as initialized by NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_navigation
*/
extern NXstatus NXinitgroupdir(NXhandle handle);
/**
* Resets a pending attribute search to the start again. To be called in a #NXgetnextattr loop when
* an attribute search has to be restarted.
* \param handle A NeXus file handle as initialized by NXopen.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_navigation
*/
extern NXstatus NXinitattrdir(NXhandle handle);
/**
* Sets the format for number printing. This call has only an effect when using the XML physical file
* format.
* \param handle A NeXus file handle as initialized by NXopen.
* \param type The NeXus data type to set the format for.
* \param format The C-language format string to use for this data type.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_readwrite
*/
extern NXstatus NXsetnumberformat(NXhandle handle, int type, char *format);
/**
* Inquire the filename of the currently open file. FilenameBufferLength of the file name
* will be copied into the filename buffer.
* \param handle A NeXus file handle as initialized by NXopen.
* \param filename The buffer to hold the filename.
* \param filenameBufferLength The length of the filename buffer.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_metadata
*/
extern NXstatus NXinquirefile(NXhandle handle, char *filename, int filenameBufferLength);
/**
* Test if a group is actually pointing to an external file. If so, retrieve the URL of the
* external file.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the group to test.
* \param nxclass The class name of the group to test.
* \param url A buffer to copy the URL too.
* \param urlLen The length of the Url buffer. At maximum urlLen bytes will be copied to url.
* \return NX_OK when the group is pointing to an external file, NX_ERROR else.
* \ingroup c_external
*/
extern NXstatus NXisexternalgroup(NXhandle handle, CONSTCHAR *name, CONSTCHAR *nxclass, char *url, int urlLen);
/**
* Test if a dataset is actually pointing to an external file. If so, retrieve the URL of the
* external file.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the dataset to test.
* \param url A buffer to copy the URL too.
* \param urlLen The length of the Url buffer. At maximum urlLen bytes will be copied to url.
* \return NX_OK when the dataset is pointing to an external file, NX_ERROR else.
* \ingroup c_external
*/
extern NXstatus NXisexternaldataset(NXhandle handle, CONSTCHAR *name, char *url, int urlLen);
/**
* Create a link to a group in an external file. This works by creating a NeXus group under the current level in
* the hierarchy which actually points to a group in another file.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the group which points to the external file.
* \param nxclass The class name of the group which points to the external file.
* \param url The URL of the external file. Currently only one URL format is supported: nxfile://path-tofile\#path-in-file.
* This consists of two parts: the first part is of course the path to the file. The second part, path-in-file, is the
* path to the group in the external file which appears in the first file.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_external
*/
extern NXstatus NXlinkexternal(NXhandle handle, CONSTCHAR *name, CONSTCHAR *nxclass, CONSTCHAR *url);
/**
* Create a link to a dataset in an external file. This works by creating a dataset under the current level in
* the hierarchy which actually points to a dataset in another file.
* \param handle A NeXus file handle as initialized by NXopen.
* \param name The name of the dataset which points to the external file.
* \param url The URL of the external file. Currently only one URL format is supported: nxfile://path-tofile\#path-in-file.
* This consists of two parts: the first part is of course the path to the file. The second part, path-in-file, is the
* path to the dataset in the external file which appears in the first file.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_external
*/
extern NXstatus NXlinkexternaldataset(NXhandle handle, CONSTCHAR *name, CONSTCHAR *url);
/**
* Utility function which allocates a suitably sized memory area for the dataset characteristics specified.
* \param data A pointer to a pointer which will be initialized with a pointer to a suitably sized memory area.
* \param rank the rank of the data.
* \param dimensions An array holding the size of the data in each dimension.
* \param datatype The NeXus data type of the data.
* \return NX_OK when allocation succeeds, NX_ERROR in the case of an error.
* \ingroup c_memory
*/
extern NXstatus NXmalloc(void** data, int rank, int dimensions[], int datatype);
/**
* @copydoc NXmalloc()
*/
extern NXstatus NXmalloc64(void** data, int rank, int64_t dimensions[], int datatype);
/**
* Utility function to return NeXus version
* \return pointer to string in static storage. Version in
* same format as NEXUS_VERSION string in napi.h i.e. "major.minor.patch"
* \ingroup c_metadata
*/
extern const char* NXgetversion();
/**
* Utility function to release the memory for data.
* \param data A pointer to a pointer to free.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_memory
*/
extern NXstatus NXfree(void** data);
/*-----------------------------------------------------------------------
NAPI internals
------------------------------------------------------------------------*/
/**
* Retrieve information about the currently open dataset. In contrast to the main function below,
* this function does not try to find out about the size of strings properly.
* \param handle A NeXus file handle as initialized by NXopen.
* \param rank A pointer to an integer which will be filled with the rank of
* the dataset.
* \param dimension An array which will be initialized with the size of the dataset in any of its
* dimensions. The array must have at least the size of rank.
* \param datatype A pointer to an integer which be set to the NeXus data type code for this dataset.
* \return NX_OK on success, NX_ERROR in the case of an error.
* \ingroup c_metadata
*/
extern NXstatus NXgetrawinfo(NXhandle handle, int* rank, int dimension[], int* datatype);
/**
* @copydoc NXgetrawinfo
*/
extern NXstatus NXgetrawinfo64(NXhandle handle, int* rank, int64_t dimension[], int* datatype);
/** \typedef void (*ErrFunc)(void *data, char *text)
* All NeXus error reporting happens through this special function, the
* ErrFunc. The NeXus-API allows to replace this error reporting function
* through a user defined implementation. The default error function prints to stderr. User
* defined ones may pop up dialog boxes or whatever.
* \param data A pointer to some user defined data structure
* \param text The text of the error message to display.
*/
typedef void (*ErrFunc)(void *data, char *text);
/**
* Set a global error function.
* Not threadsafe.
* \param pData A pointer to a user defined data structure which be passed to
* the error display function.
* \param newErr The new error display function.
*/
extern void NXMSetError(void *pData, ErrFunc newErr);
/**
* Set an error function for the current thread.
* When used this overrides anything set in NXMSetError (for the current thread).
* Use this method in threaded applications.
* \param pData A pointer to a user defined data structure which be passed to
* the error display function.
* \param newErr The new error display function.
*/
extern void NXMSetTError(void *pData, ErrFunc newErr);
/**
* Retrieve the current error display function
* \return The current error display function.
*/
extern ErrFunc NXMGetError();
/**
* Suppress error reports from the NeXus-API
*/
extern void NXMDisableErrorReporting();
/**
* Enable error reports from the NeXus-API
*/
extern void NXMEnableErrorReporting();
/**
* Dispatches the error message to the error function defined by NXMSetTError
*/
extern void NXReportError(char *text);
/**
* Do not use, first parameter should be set by NXMSetTError
*/
extern void NXIReportError(void *pData,char *text);
/* extern void *NXpData; */
extern char *NXIformatNeXusTime();
extern NXstatus NXIprintlink(NXhandle fid, NXlink* link);
/**
* A function for setting the default cache size for HDF-5
* \ingroup c_init
*/
extern NXstatus NXsetcache(long newVal);
typedef struct {
NXhandle pNexusData;
NXstatus ( *nxreopen)(NXhandle pOrigHandle, NXhandle* pNewHandle);
NXstatus ( *nxclose)(NXhandle* pHandle);
NXstatus ( *nxflush)(NXhandle* pHandle);
NXstatus ( *nxmakegroup) (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
NXstatus ( *nxopengroup) (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
NXstatus ( *nxclosegroup)(NXhandle handle);
NXstatus ( *nxmakedata64) (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[]);
NXstatus ( *nxcompmakedata64) (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[], int comp_typ, int64_t bufsize[]);
NXstatus ( *nxcompress) (NXhandle handle, int compr_type);
NXstatus ( *nxopendata) (NXhandle handle, CONSTCHAR* label);
NXstatus ( *nxclosedata)(NXhandle handle);
NXstatus ( *nxputdata)(NXhandle handle, const void* data);
NXstatus ( *nxputattr)(NXhandle handle, CONSTCHAR* name, const void* data, int iDataLen, int iType);
NXstatus ( *nxputslab64)(NXhandle handle, const void* data, const int64_t start[], const int64_t size[]);
NXstatus ( *nxgetdataID)(NXhandle handle, NXlink* pLink);
NXstatus ( *nxmakelink)(NXhandle handle, NXlink* pLink);
NXstatus ( *nxmakenamedlink)(NXhandle handle, CONSTCHAR *newname, NXlink* pLink);
NXstatus ( *nxgetdata)(NXhandle handle, void* data);
NXstatus ( *nxgetinfo64)(NXhandle handle, int* rank, int64_t dimension[], int* datatype);
NXstatus ( *nxgetnextentry)(NXhandle handle, NXname name, NXname nxclass, int* datatype);
NXstatus ( *nxgetslab64)(NXhandle handle, void* data, const int64_t start[], const int64_t size[]);
NXstatus ( *nxgetnextattr)(NXhandle handle, NXname pName, int *iLength, int *iType);
NXstatus ( *nxgetattr)(NXhandle handle, char* name, void* data, int* iDataLen, int* iType);
NXstatus ( *nxgetattrinfo)(NXhandle handle, int* no_items);
NXstatus ( *nxgetgroupID)(NXhandle handle, NXlink* pLink);
NXstatus ( *nxgetgroupinfo)(NXhandle handle, int* no_items, NXname name, NXname nxclass);
NXstatus ( *nxsameID)(NXhandle handle, NXlink* pFirstID, NXlink* pSecondID);
NXstatus ( *nxinitgroupdir)(NXhandle handle);
NXstatus ( *nxinitattrdir)(NXhandle handle);
NXstatus ( *nxsetnumberformat)(NXhandle handle, int type, char *format);
NXstatus ( *nxprintlink)(NXhandle handle, NXlink* link);
NXstatus ( *nxnativeexternallink)(NXhandle handle, CONSTCHAR* name, CONSTCHAR* externalfile, CONSTCHAR* remotetarget);
NXstatus ( *nxnativeinquirefile)(NXhandle handle, char* externalfile, const int filenamelength);
NXstatus ( *nxnativeisexternallink)(NXhandle handle, CONSTCHAR* name, char* url, int urllen);
int stripFlag;
int checkNameSyntax;
} NexusFunction, *pNexusFunction;
/*---------------------*/
extern long nx_cacheSize;
/* FORTRAN internals */
extern NXstatus NXfopen(char * filename, NXaccess* am,
NXhandle pHandle);
extern NXstatus NXfclose (NXhandle pHandle);
extern NXstatus NXfputattr(NXhandle fid, const char *name, const void *data,
int *pDatalen, int *pIType);
extern NXstatus NXfcompress(NXhandle fid, int *compr_type);
extern NXstatus NXfcompmakedata(NXhandle fid, char *name,
int *pDatatype,
int *pRank, int dimensions[],
int *compression_type, int chunk[]);
extern NXstatus NXfmakedata(NXhandle fid, char *name, int *pDatatype,
int *pRank, int dimensions[]);
extern NXstatus NXfflush(NXhandle pHandle);
extern NXstatus NXfgetpath(NXhandle fid, char *path, int *pathlen);
#ifdef __cplusplus
}
#endif /* __cplusplus */
/**
* Freddie Akeroyd 11/8/2009
* Add NeXus schema support - this uses BASE.xsd as the initial file
*/
#define NEXUS_SCHEMA_VERSION "3.1" /**< version of NeXus definition schema */
#define NEXUS_SCHEMA_ROOT "http://definition.nexusformat.org/schema/" /**< XML schema namespace specified by xmlns */
#define NEXUS_SCHEMA_NAMESPACE NEXUS_SCHEMA_ROOT NEXUS_SCHEMA_VERSION /**< XML schema namespace specified by xmlns */
#define NEXUS_SCHEMA_BASE "BASE"
#define NEXUS_SCHEMA_FILE NEXUS_SCHEMA_BASE ".xsd" /**< default schema file for namespace */
#define NEXUS_SCHEMA_URL NEXUS_SCHEMA_NAMESPACE "/" NEXUS_SCHEMA_FILE /**< location of default schema file for namespace */
#endif /*NEXUSAPI*/

1983
napi4.c

File diff suppressed because it is too large Load Diff

60
napi4.h
View File

@ -1,60 +0,0 @@
#ifndef NAPI4_H
#define NAPI4_H
#define NXSIGNATURE 959697
#include "mfhdf.h"
/* #include "napi4.c" */
/*
* HDF4 interface
*/
extern NXstatus NX4open(CONSTCHAR *filename, NXaccess access_method, NXhandle* pHandle);
extern NXstatus NX4close(NXhandle* pHandle);
extern NXstatus NX4flush(NXhandle* pHandle);
extern NXstatus NX4makegroup (NXhandle handle, CONSTCHAR* Vgroup, CONSTCHAR* NXclass);
extern NXstatus NX4opengroup (NXhandle handle, CONSTCHAR* Vgroup, CONSTCHAR* NXclass);
extern NXstatus NX4closegroup(NXhandle handle);
extern NXstatus NX4makedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[]);
extern NXstatus NX4compmakedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[], int comp_typ, int64_t bufsize[]);
extern NXstatus NX4compress (NXhandle handle, int compr_type);
extern NXstatus NX4opendata (NXhandle handle, CONSTCHAR* label);
extern NXstatus NX4closedata(NXhandle handle);
extern NXstatus NX4getdata(NXhandle handle, void* data);
extern NXstatus NX4getslab64(NXhandle handle, void* data, const int64_t start[], const int64_t size[]);
extern NXstatus NX4getattr(NXhandle handle, char* name, void* data, int* iDataLen, int* iType);
extern NXstatus NX4putdata(NXhandle handle, const void* data);
extern NXstatus NX4putslab64(NXhandle handle, const void* data, const int64_t start[], const int64_t size[]);
extern NXstatus NX4putattr(NXhandle handle, CONSTCHAR* name, const void* data, int iDataLen, int iType);
extern NXstatus NX4getinfo64(NXhandle handle, int* rank, int64_t dimension[], int* datatype);
extern NXstatus NX4getgroupinfo(NXhandle handle, int* no_items, NXname name, NXname nxclass);
extern NXstatus NX4initgroupdir(NXhandle handle);
extern NXstatus NX4getnextentry(NXhandle handle, NXname name, NXname nxclass, int* datatype);
extern NXstatus NX4getattrinfo(NXhandle handle, int* no_items);
extern NXstatus NX4initattrdir(NXhandle handle);
extern NXstatus NX4getnextattr(NXhandle handle, NXname pName, int *iLength, int *iType);
extern NXstatus NX4getgroupID(NXhandle handle, NXlink* pLink);
extern NXstatus NX4getdataID(NXhandle handle, NXlink* pLink);
extern NXstatus NX4makelink(NXhandle handle, NXlink* pLink);
extern NXstatus NX4printlink(NXhandle handle, NXlink* pLink);
void NX4assignFunctions(pNexusFunction fHandle);
/*
* HDF changed from MAX_VAR_DIMS to H4_MAX_VAR_DIMS aronud 9/5/2007
* to avoid potential conflicts with NetCDF-3 library
*/
#ifndef H4_MAX_VAR_DIMS
#define H4_MAX_VAR_DIMS MAX_VAR_DIMS
#endif
#endif /* NAPI4_H */

2301
napi5.c

File diff suppressed because it is too large Load Diff

54
napi5.h
View File

@ -1,54 +0,0 @@
#ifndef NAPI5_H
#define NAPI5_H
#define NX5SIGNATURE 959695
#include <hdf5.h>
/* HDF5 interface */
extern NXstatus NX5open(CONSTCHAR *filename, NXaccess access_method, NXhandle* pHandle);
extern NXstatus NX5reopen(NXhandle pOrigHandle, NXhandle* pNewHandle);
extern NXstatus NX5close(NXhandle* pHandle);
extern NXstatus NX5flush(NXhandle* pHandle);
extern NXstatus NX5makegroup (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
extern NXstatus NX5opengroup (NXhandle handle, CONSTCHAR *name, CONSTCHAR* NXclass);
extern NXstatus NX5closegroup(NXhandle handle);
extern NXstatus NX5makedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[]);
extern NXstatus NX5compmakedata64 (NXhandle handle, CONSTCHAR* label, int datatype, int rank, int64_t dim[], int comp_typ, int64_t bufsize[]);
extern NXstatus NX5compress (NXhandle handle, int compr_type);
extern NXstatus NX5opendata (NXhandle handle, CONSTCHAR* label);
extern NXstatus NX5closedata(NXhandle handle);
extern NXstatus NX5putdata(NXhandle handle, const void* data);
extern NXstatus NX5putattr(NXhandle handle, CONSTCHAR* name, const void* data, int iDataLen, int iType);
extern NXstatus NX5putslab64(NXhandle handle, const void* data, const int64_t start[], const int64_t size[]);
extern NXstatus NX5getdataID(NXhandle handle, NXlink* pLink);
extern NXstatus NX5makelink(NXhandle handle, NXlink* pLink);
extern NXstatus NX5printlink(NXhandle handle, NXlink* pLink);
extern NXstatus NX5getdata(NXhandle handle, void* data);
extern NXstatus NX5getinfo64(NXhandle handle, int* rank, int64_t dimension[], int* datatype);
extern NXstatus NX5getnextentry(NXhandle handle, NXname name, NXname nxclass, int* datatype);
extern NXstatus NX5getslab64(NXhandle handle, void* data, const int64_t start[], const int64_t size[]);
extern NXstatus NX5getnextattr(NXhandle handle, NXname pName, int *iLength, int *iType);
extern NXstatus NX5getattr(NXhandle handle, char* name, void* data, int* iDataLen, int* iType);
extern NXstatus NX5getattrinfo(NXhandle handle, int* no_items);
extern NXstatus NX5getgroupID(NXhandle handle, NXlink* pLink);
extern NXstatus NX5getgroupinfo(NXhandle handle, int* no_items, NXname name, NXname nxclass);
extern NXstatus NX5initgroupdir(NXhandle handle);
extern NXstatus NX5initattrdir(NXhandle handle);
void NX5assignFunctions(pNexusFunction fHandle);
herr_t attr_info(hid_t loc_id, const char *name, const H5A_info_t *unused, void *opdata);
herr_t group_info(hid_t loc_id, const char *name, const H5L_info_t *unused, void *opdata);
herr_t nxgroup_info(hid_t loc_id, const char *name, const H5L_info_t *unused, void *op_data);
#endif /* NAPI5_H */

747
nxio.c
View File

@ -1,747 +0,0 @@
/**
* This file contains functions necessary to perform XML-I/O for
* NeXus with the mxml-library.
*
* Most notably it contains the callback function for reading and
* writing data
*
* Copyright (C) 2004 Mark Koennecke
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information, see <http://www.nexusformat.org>
*/
#ifdef NXXML
#include <mxml.h>
#include <assert.h>
#include "napi.h"
#include "nxio.h"
#include "nxdataset.h"
#include "napiconfig.h"
/* fix for mxml-2.3 */
#ifndef MXML_WRAP
#define MXML_WRAP 79
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif /* _MSC_VER */
/* #define TESTMAIN 1 */
/*=================== type code handling ================================= */
typedef struct {
char name[30];
char format[30];
int nx_type;
}type_code;
#define NTYPECODE 11
static type_code typecode[NTYPECODE];
/*-----------------------------------------------------------------------*/
void initializeNumberFormats(){
type_code myCode;
strcpy(myCode.name,"NX_FLOAT32");
strcpy(myCode.format,"%12.4f");
myCode.nx_type = NX_FLOAT32;
typecode[0] = myCode;
strcpy(myCode.name,"NX_FLOAT64");
strcpy(myCode.format,"%16.5f");
myCode.nx_type = NX_FLOAT64;
typecode[1] = myCode;
strcpy(myCode.name,"NX_INT8");
strcpy(myCode.format,"%5d");
myCode.nx_type = NX_INT8;
typecode[2] = myCode;
strcpy(myCode.name,"NX_UINT8");
strcpy(myCode.format,"%5d");
myCode.nx_type = NX_UINT8;
typecode[3] = myCode;
strcpy(myCode.name,"NX_INT16");
strcpy(myCode.format,"%8d");
myCode.nx_type = NX_INT16;
typecode[4] = myCode;
strcpy(myCode.name,"NX_UINT16");
strcpy(myCode.format,"%8d");
myCode.nx_type = NX_UINT16;
typecode[5] = myCode;
strcpy(myCode.name,"NX_INT32");
strcpy(myCode.format,"%12d");
myCode.nx_type = NX_INT32;
typecode[6] = myCode;
strcpy(myCode.name,"NX_UINT32");
strcpy(myCode.format,"%12d");
myCode.nx_type = NX_UINT32;
typecode[7] = myCode;
strcpy(myCode.name,"NX_INT64");
strcpy(myCode.format,"%24lld");
myCode.nx_type = NX_INT64;
typecode[8] = myCode;
strcpy(myCode.name,"NX_UINT64");
strcpy(myCode.format,"%24llu");
myCode.nx_type = NX_UINT64;
typecode[9] = myCode;
strcpy(myCode.name,"NX_CHAR");
strcpy(myCode.format,"%c");
myCode.nx_type = NX_CHAR;
typecode[10] = myCode;
}
/*----------------------------------------------------------------------*/
void setNumberFormat(int nx_type, char *format){
int i;
for(i = 0; i < NTYPECODE; i++){
if(typecode[i].nx_type == nx_type){
strncpy(typecode[i].format,format,29);
}
}
}
/*------------------------------------------------------------------*/
static void getNumberFormat(int nx_type, char format[30]){
int i;
for(i = 0; i < NTYPECODE; i++){
if(typecode[i].nx_type == nx_type){
strncpy(format,typecode[i].format,29);
}
}
}
/*----------------------------------------------------------------*/
void getNumberText(int nx_type, char *typestring, int typeLen){
int i;
for(i = 0; i < NTYPECODE; i++){
if(typecode[i].nx_type == nx_type){
strncpy(typestring,typecode[i].name,typeLen);
}
}
}
/*
* 'mxml_add_char()' - Add a character to a buffer, expanding as needed.
* copied here from mxml-file.c to achieve compatibility with mxml-2.1
* standard
*/
static int /* O - 0 on success, -1 on error */
myxml_add_char(int ch, /* I - Character to add */
char **bufptr, /* IO - Current position in buffer */
char **buffer, /* IO - Current buffer */
size_t *bufsize) /* IO - Current buffer size */
{
char *newbuffer; /* New buffer value */
if (*bufptr >= (*buffer + *bufsize - 4))
{
/*
* Increase the size of the buffer...
*/
if (*bufsize < 1024)
{
(*bufsize) *= 2;
}
else
{
(*bufsize) *= 3;
(*bufsize) /= 2;
}
newbuffer = (char *)malloc(*bufsize*sizeof(char));
if(!newbuffer){
free(*buffer);
mxml_error("Unable to expand string buffer to %d bytes!", *bufsize);
return (-1);
}
memset(newbuffer,0,*bufsize*sizeof(char));
memcpy(newbuffer,*buffer,*bufptr - *buffer);
free(*buffer);
*bufptr = newbuffer + (*bufptr - *buffer);
*buffer = newbuffer;
}
if (ch < 128)
{
/*
* Single byte ASCII...
*/
*(*bufptr)++ = ch;
}
else if (ch < 2048)
{
/*
* Two-byte UTF-8...
*/
*(*bufptr)++ = 0xc0 | (ch >> 6);
*(*bufptr)++ = 0x80 | (ch & 0x3f);
}
else if (ch < 65536)
{
/*
* Three-byte UTF-8...
*/
*(*bufptr)++ = 0xe0 | (ch >> 12);
*(*bufptr)++ = 0x80 | ((ch >> 6) & 0x3f);
*(*bufptr)++ = 0x80 | (ch & 0x3f);
}
else
{
/*
* Four-byte UTF-8...
*/
*(*bufptr)++ = 0xf0 | (ch >> 18);
*(*bufptr)++ = 0x80 | ((ch >> 12) & 0x3f);
*(*bufptr)++ = 0x80 | ((ch >> 6) & 0x3f);
*(*bufptr)++ = 0x80 | (ch & 0x3f);
}
return (0);
}
/*------------------------------------------------------------------*/
extern char *stptok(char *s, char *tok, size_t toklen, char *brk);
/*=====================================================================
actual stuff for implementing the callback functions
=====================================================================*/
/*
* if passed NX_CHAR, then returns dimension of -1 and the caller
* needs to do a strlen() or equivalent
*/
void analyzeDim(const char *typeString, int *rank,
int64_t *iDim, int *type){
char dimString[132];
char dim[20];
const char *dimStart, *dimEnd;
char* dimTemp;
int myRank;
if(strchr(typeString,(int)'[') == NULL){
*rank = 1;
switch(*type){
case NX_INT8:
case NX_UINT8:
case NX_INT16:
case NX_UINT16:
case NX_INT32:
case NX_UINT32:
case NX_INT64:
case NX_UINT64:
case NX_FLOAT32:
case NX_FLOAT64:
iDim[0] = 1;
break;
case NX_CHAR:
iDim[0] = -1; /* length unknown, caller needs to determine later */
break;
default:
mxml_error("ERROR: (analyzeDim) unknown type code %d for typeString %s", *type, typeString);
break;
}
} else {
/*
we have to determine rank and the dims.
Start by extracting the dimension string.
*/
dimStart = strchr(typeString,(int)'[') + 1;
dimEnd = strchr(typeString,(int)']');
if(!dimStart || !dimEnd) {
mxml_error("ERROR: malformed dimension string in %s",typeString);
return;
}
if((dimEnd - dimStart) > 131){
mxml_error("ERROR: run away dimension definition in %s",typeString);
return;
}
memset(dimString,0,132);
memcpy(dimString,dimStart,(dimEnd-dimStart)*sizeof(char));
dimTemp = stptok(dimString,dim,19,",");
myRank = 0;
while(dimTemp != NULL){
iDim[myRank] = atoi(dim);
dimTemp = stptok(dimTemp,dim,19,",");
myRank++;
}
*rank = myRank;
}
}
/*--------------------------------------------------------------------*/
int translateTypeCode(const char *code){
int i, result = -1;
for(i = 0; i < NTYPECODE; i++){
if(strstr(code,typecode[i].name) != NULL){
result = typecode[i].nx_type;
break;
}
}
return result;
}
/*
* This is used to locate an Idims node from the new style table data layout
*/
static mxml_node_t* findDimsNode(mxml_node_t *node)
{
mxml_node_t *tnode = NULL;
const char* name = node->value.element.name;
if ( (node->parent != NULL) && !strcmp(node->parent->value.element.name, DATA_NODE_NAME) )
{
tnode = mxmlFindElement(node->parent->parent, node->parent->parent, DIMS_NODE_NAME, NULL, NULL, MXML_DESCEND_FIRST);
if (tnode != NULL)
{
tnode = mxmlFindElement(tnode,tnode,name,NULL,NULL,MXML_DESCEND_FIRST);
}
}
return tnode;
}
/*---------------------------------------------------------------------*/
/*return 1 if in table mode , 0 if not */
static void analyzeDataType(mxml_node_t *parent, int *rank, int *type,
int64_t *iDim){
const char *typeString;
mxml_node_t* tnode;
int nx_type = -1;
int table_mode = 0;
*rank = 1;
*type = NX_CHAR;
iDim[0] = -1;
/*
get the type attribute. No attribute means: plain text
*/
tnode = findDimsNode(parent);
if (tnode != NULL)
{
table_mode = 1;
parent = tnode;
}
typeString = mxmlElementGetAttr(parent,TYPENAME);
if(typeString == NULL){
return;
}
nx_type = translateTypeCode((char *)typeString);
/*
assign type
*/
if(nx_type == -1){
mxml_error(
"ERROR: %s is an invalid NeXus type, I try to continue but may fail",
typeString);
*type =NX_CHAR;
return;
}
*type = nx_type;
analyzeDim(typeString, rank, iDim, type);
if (table_mode)
{
*rank = 1;
iDim[0] = 1;
}
return;
}
/*-------------------------------------------------------------------*/
void destroyDataset(void *data){
if(data != NULL){
dropNXDataset((pNXDS)data);
}
}
/*-------------------------------------------------------------------*/
static char *getNextNumber(char *pStart, char pNumber[80]){
int charCount = 0;
pNumber[0] = '\0';
/* advance to first digit */
while(isspace(*pStart) && *pStart != '\0'){
pStart++;
}
if(*pStart == '\0'){
return NULL;
}
/* copy */
while(!isspace(*pStart) && *pStart != '\0' && charCount < 78){
pNumber[charCount] = *pStart;
pStart++;
charCount++;
}
pNumber[charCount] = '\0';
return pStart;
}
/*--------------------------------------------------------------------*/
mxml_type_t nexusTypeCallback(mxml_node_t *parent){
const char *typeString;
if(strstr(parent->value.element.name,"?xml") != NULL ||
!strncmp(parent->value.element.name,"NX",2) ||
!strcmp(parent->value.element.name,DATA_NODE_NAME) ||
!strcmp(parent->value.element.name,DIMS_NODE_NAME)){
return MXML_ELEMENT;
} else {
/* data nodes do not habe TYPENAME in table style but are always CUSTOM */
if (parent->parent != NULL && !strcmp(parent->parent->value.element.name, DATA_NODE_NAME))
{
return MXML_CUSTOM;
}
if (parent->parent != NULL && !strcmp(parent->parent->value.element.name, DIMS_NODE_NAME))
{
return MXML_OPAQUE;
}
typeString = mxmlElementGetAttr(parent,TYPENAME);
if(typeString == NULL){
/*
MXML_TEXT seems more appropriate here. But mxml hacks text into
single words which is not what NeXus wants.
*/
return MXML_OPAQUE;
} else{
if(strstr(typeString,"NX_CHAR") != NULL){
return MXML_OPAQUE;
} else {
return MXML_CUSTOM;
}
}
}
}
/*----------------------------------------------------------------------*/
int nexusLoadCallback(mxml_node_t *node, const char *buffer){
mxml_node_t *parent = NULL;
int rank, type;
int64_t iDim[NX_MAXRANK];
char pNumber[80], *pStart;
long address, maxAddress;
pNXDS dataset = NULL;
parent = node->parent;
analyzeDataType(parent,&rank,&type,iDim);
if(iDim[0] == -1 || !strcmp(parent->parent->value.element.name, DIMS_NODE_NAME)){
iDim[0] = strlen(buffer);
node->value.custom.data = strdup(buffer);
node->value.custom.destroy = free;
return 0;
} else {
node->value.custom.data = createNXDataset(rank,type,iDim);
dataset = (pNXDS)node->value.custom.data;
if(dataset == NULL){
mxml_error("Failed to allocate custom dataset");
return 1;
}
node->value.custom.destroy = destroyDataset;
}
/*
load data
*/
pStart = (char *)buffer;
maxAddress = getNXDatasetLength(dataset);
address = 0;
while( (pStart = getNextNumber(pStart,pNumber)) != NULL &&
address < maxAddress){
putNXDatasetValueAt(dataset,address,atof(pNumber));
address++;
}
return 0;
}
/*---------------------------------------------------------------------*/
static void stringIntoBuffer(char **buffer, char **bufPtr, size_t *bufSize,
char *string){
size_t i;
for(i = 0; i < strlen(string); i++){
myxml_add_char(string[i],bufPtr,buffer,bufSize);
}
}
/*--------------------------------------------------------------------*/
static void formatNumber(double value, char *txt, int txtLen,
char *format, int type){
switch(type){
case NX_INT8:
case NX_UINT8:
case NX_INT16:
case NX_UINT16:
case NX_INT32:
case NX_UINT32:
snprintf(txt,txtLen,format,(int)value);
break;
case NX_INT64:
snprintf(txt,txtLen,format,(int64_t)value);
break;
case NX_UINT64:
snprintf(txt,txtLen,format,(uint64_t)value);
break;
case NX_FLOAT32:
case NX_FLOAT64:
snprintf(txt,txtLen,format,value);
break;
default:
/*assert(0); something is very wrong here */
printf("Problem\n");
break;
}
}
/*--------------------------------------------------------------------*/
static int countDepth(mxml_node_t *node){
int count = 0;
mxml_node_t *cur;
cur = node;
while(cur != NULL){
count++;
cur = cur->parent;
}
count--;
return count;
}
/*---------------------------------------------------------------------*/
char *nexusWriteCallback(mxml_node_t *node){
int type, col;
char pNumber[80], indent[80], format[30];
char *buffer, *bufPtr;
pNXDS dataset;
int currentLen, table_style = 0;
size_t i, bufsize, length;
int is_definition = 0;
/* this is set by nxconvert when making a definiton */
is_definition = (getenv("NX_IS_DEFINITION") != NULL);
if (!strcmp(node->parent->parent->value.element.name, DATA_NODE_NAME))
{
table_style = 1;
}
/*
allocate output buffer
*/
buffer = (char *)malloc(1024*sizeof(char));
if(buffer == NULL){
mxml_error("Unable to allocate buffer");
return NULL;
}
memset(buffer,0,1024);
bufPtr = buffer;
bufsize = 1024;
dataset = (pNXDS)node->value.custom.data;
/*
prepare indentation level
*/
col = countDepth(node)*2;
memset(indent,0,80);
for(i = 0; i < col; i++){
indent[i] = ' ';
}
/*
get dataset info
*/
type = getNXDatasetType(dataset);
if (is_definition) {
length = 1;
} else {
length = getNXDatasetLength(dataset);
}
if(dataset->format != NULL){
strcpy(format,dataset->format);
} else {
getNumberFormat(type,format);
}
/*
actually get the data out
*/
if (table_style)
{
for(i = 0; i < length; i++){
formatNumber(getNXDatasetValueAt(dataset,i),pNumber,79,format,type);
stringIntoBuffer(&buffer,&bufPtr,&bufsize,pNumber);
}
}
else
{
currentLen = col;
myxml_add_char('\n',&bufPtr,&buffer,&bufsize);
stringIntoBuffer(&buffer,&bufPtr,&bufsize,indent);
for(i = 0; i < length; i++){
formatNumber(getNXDatasetValueAt(dataset,i),pNumber,79,format,type);
if(currentLen + strlen(pNumber) > MXML_WRAP){
/*
wrap line
*/
myxml_add_char('\n',&bufPtr,&buffer,&bufsize);
stringIntoBuffer(&buffer,&bufPtr,&bufsize,indent);
currentLen = col;
}
stringIntoBuffer(&buffer,&bufPtr,&bufsize,pNumber);
myxml_add_char(' ',&bufPtr,&buffer,&bufsize);
currentLen += strlen(pNumber) + 1;
}
}
myxml_add_char('\0',&bufPtr,&buffer,&bufsize);
return (char *)buffer;
}
/*------------------------------------------------------------------*/
int isDataNode(mxml_node_t *node){
if(mxmlElementGetAttr(node,"name") != NULL){
return 0;
}
if(strcmp(node->value.element.name,"NXroot") == 0){
return 0;
}
if(strcmp(node->value.element.name,DIMS_NODE_NAME) == 0){
return 0;
}
if(strcmp(node->value.element.name,DATA_NODE_NAME) == 0){
return 0;
}
if(strcmp(node->value.element.name,"NAPIlink") == 0){
return 0;
}
return 1;
}
/*--------------------------------------------------------------------*/
static int isTextData(mxml_node_t *node){
const char *attr = NULL;
if(!isDataNode(node)){
return 0;
}
/*
test datasets
*/
attr = mxmlElementGetAttr(node,TYPENAME);
if(attr == NULL){
return 1;
}
if(strstr(attr,"NX_CHAR") != NULL){
return 1;
} else {
return 0;
}
}
/*---------------------------------------------------------------------*/
/*
* note: not reentrant or thead safe; returns pointer to static storage
*/
const char *NXwhitespaceCallback(mxml_node_t *node, int where){
static char *indent = NULL;
int len;
if(strstr(node->value.element.name,"?xml") != NULL){
return NULL;
}
if (node->parent != NULL && !strcmp(node->parent->value.element.name, DATA_NODE_NAME))
{
return NULL;
}
if (where == MXML_WS_BEFORE_CLOSE && !strcmp(node->value.element.name, DATA_NODE_NAME))
{
return NULL;
}
if(isTextData(node)){
if(where == MXML_WS_BEFORE_OPEN){
len = countDepth(node)*2 + 2;
if (indent != NULL)
{
free(indent);
indent = NULL;
}
indent = (char *)malloc(len*sizeof(char));
if(indent != NULL){
memset(indent,' ',len);
indent[0]= '\n';
indent[len-1] = '\0';
return (const char*)indent;
}
}
return NULL;
}
if(where == MXML_WS_BEFORE_OPEN || where == MXML_WS_BEFORE_CLOSE){
len = countDepth(node)*2 + 2;
if (indent != NULL)
{
free(indent);
indent = NULL;
}
indent = (char *)malloc(len*sizeof(char));
if(indent != NULL){
memset(indent,' ',len);
indent[0]= '\n';
indent[len-1] = '\0';
return (const char*)indent;
}
}
return NULL;
}
/*-----------------------------------------------------------------------*/
#ifdef TESTMAIN
#include <stdio.h>
int main(int argc, char *argv[]){
mxml_node_t *root = NULL;
FILE *f;
mxmlSetCustomHandlers(nexusLoadCallback, nexusWriteCallback);
initializeNumberFormats();
/*
read test
*/
f = fopen("dmc.xml","r");
root = mxmlLoadFile(NULL,f,nexusTypeCallback);
fclose(f);
/*
write test
*/
setNumberFormat(NX_INT32,"%8d");
setNumberFormat(NX_FLOAT32,"%8.2f");
f = fopen("dmc2.xml","w");
mxmlSaveFile(root,f,NXwhitespaceCallback);
fclose(f);
}
#endif
#endif /*NXXML*/

50
nxio.h
View File

@ -1,50 +0,0 @@
/**
* This file contains functions necessary to perform XML-I/O for
* NeXus with the mxml-library.
*
* Most notably it contains the callback function for reading data
*
* Copyright (C) 2004 Mark Koennecke
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information, see <http://www.nexusformat.org>
*/
#ifndef __NXIO
#define __NXIO
#include <mxml.h>
#define TYPENAME "NAPItype"
#define DIMS_NODE_NAME "columns"
#define DATA_NODE_NAME "row"
mxml_type_t nexusTypeCallback(mxml_node_t *parent);
const char *NXwhitespaceCallback(mxml_node_t *node, int where);
int nexusLoadCallback(mxml_node_t *node, const char *buffer);
char *nexusWriteCallback(mxml_node_t *node);
void setNumberFormat(int dataType, char *formatString);
void initializeNumberFormats();
void getNumberText(int nx_type, char *typestring, int typeLen);
void destroyDataset(void *data);
int translateTypeCode(const char *code);
int isDataNode(mxml_node_t *node);
void analyzeDim(const char *typeString, int *rank,
int64_t *iDim, int *type);
#endif

View File

@ -926,6 +926,7 @@ static void putSlab(SConnection * pCon, SicsInterp * pSics, pNXScript self,
pSICSData data = NULL; pSICSData data = NULL;
pCounter memsec = NULL; pCounter memsec = NULL;
pHdb node = NULL; pHdb node = NULL;
double dVal;
if (argc < 6) { if (argc < 6) {
SCWrite(pCon, "ERROR: insufficient number of arguments to putslab", SCWrite(pCon, "ERROR: insufficient number of arguments to putslab",
@ -991,6 +992,24 @@ static void putSlab(SConnection * pCon, SicsInterp * pSics, pNXScript self,
written = 1; written = 1;
} }
} }
/**
* try to look for a single double. This is a hack to make absolute_time
* work at BOA. A cleaner solution should be devised in a later stage.
* MK, June 2013
*/
if(written == 0) {
status = Tcl_GetDouble(InterpGetTcl(pSics), argv[5], &dVal);
if (status != TCL_OK) {
written = 0;
} else {
status = NXputslab(self->fileHandle, &dVal, start, size);
if (status == NX_OK) {
written = 1;
}
}
}
/* /*
* drop out of hierarchy * drop out of hierarchy
*/ */

145
nxstack.c
View File

@ -1,145 +0,0 @@
/*
This is some code to handle a stack of NeXus files. This is used to implement
external linking within the NeXus-API
Copyright (C) 1997-2006 Mark Koennecke
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information, see <http://www.nexusformat.org>
Added code to support the path stack for NXgetpath,
Mark Koennecke, October 2009
*/
#include <stdlib.h>
#include <string.h>
#include <napi.h>
#include "nxstack.h"
/*-----------------------------------------------------------------------
Data definitions
---------------------------------------------------------------------*/
typedef struct {
pNexusFunction pDriver;
NXlink closeID;
char filename[1024];
}fileStackEntry;
typedef struct __fileStack {
int fileStackPointer;
fileStackEntry fileStack[MAXEXTERNALDEPTH];
int pathPointer;
char pathStack[NXMAXSTACK][NX_MAXNAMELEN];
}fileStack;
/*---------------------------------------------------------------------*/
pFileStack makeFileStack(){
pFileStack pNew = NULL;
pNew = (pFileStack)malloc(sizeof(fileStack));
if(pNew == NULL){
return NULL;
}
memset(pNew,0,sizeof(fileStack));
pNew->fileStackPointer = -1;
pNew->pathPointer = -1;
return pNew;
}
/*---------------------------------------------------------------------*/
void killFileStack(pFileStack self){
if(self != NULL){
free(self);
}
}
/*---------------------------------------------------------------------*/
int getFileStackSize(){
return sizeof(fileStack);
}
/*----------------------------------------------------------------------*/
void pushFileStack(pFileStack self, pNexusFunction pDriv, char *file){
size_t length;
self->fileStackPointer++;
self->fileStack[self->fileStackPointer].pDriver = pDriv;
memset(&self->fileStack[self->fileStackPointer].closeID,0,sizeof(NXlink));
length = strlen(file);
if(length >= 1024){
length = 1023;
}
memcpy(&self->fileStack[self->fileStackPointer].filename,file,length);
}
/*----------------------------------------------------------------------*/
void popFileStack(pFileStack self){
self->fileStackPointer--;
if(self->fileStackPointer < -1){
self->fileStackPointer = -1;
}
}
/*----------------------------------------------------------------------*/
pNexusFunction peekFileOnStack(pFileStack self){
return self->fileStack[self->fileStackPointer].pDriver;
}
/*---------------------------------------------------------------------*/
char *peekFilenameOnStack(pFileStack self){
return self->fileStack[self->fileStackPointer].filename;
}
/*----------------------------------------------------------------------*/
void peekIDOnStack(pFileStack self, NXlink *id){
memcpy(id, &self->fileStack[self->fileStackPointer].closeID, sizeof(NXlink));
}
/*---------------------------------------------------------------------*/
void setCloseID(pFileStack self, NXlink id){
memcpy(&self->fileStack[self->fileStackPointer].closeID, &id, sizeof(NXlink));
}
/*----------------------------------------------------------------------*/
int fileStackDepth(pFileStack self){
return self->fileStackPointer;
}
/*----------------------------------------------------------------------*/
void pushPath(pFileStack self, const char *name){
self->pathPointer++;
strncpy(self->pathStack[self->pathPointer],name,NX_MAXNAMELEN-1);
}
/*-----------------------------------------------------------------------*/
void popPath(pFileStack self){
self->pathPointer--;
if(self->pathPointer < -1){
self->pathPointer = -1;
}
}
/*-----------------------------------------------------------------------*/
int buildPath(pFileStack self, char *path, int pathlen){
int i;
size_t totalPathLength;
char *totalPath;
for(i = 0, totalPathLength = 5; i <= self->pathPointer; i++){
totalPathLength += strlen(self->pathStack[i]) + 1;
}
totalPath = (char*)malloc(totalPathLength*sizeof(char));
if(totalPath == NULL){
return 0;
}
memset(totalPath,0,totalPathLength*sizeof(char));
for(i = 0; i <= self->pathPointer; i++){
strcat(totalPath,"/");
strcat(totalPath,self->pathStack[i]);
}
strncpy(path,totalPath,pathlen-1);
free(totalPath);
return 1;
}

View File

@ -1,52 +0,0 @@
/*
This is some code to handle a stack of NeXus files. This is used to implement
external linking within the NeXus-API
Copyright (C) 1997-2006 Mark Koennecke
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
For further information, see <http://www.nexusformat.org>
Added functions to deal with the path stack for NXgetpath
Mark Koennecke, October 2009
*/
#ifndef NEXUSFILESTACK
#define NEXUSFILESTACK
typedef struct __fileStack *pFileStack;
#define MAXEXTERNALDEPTH 16
pFileStack makeFileStack();
void killFileStack(pFileStack self);
int getFileStackSize();
void pushFileStack(pFileStack self, pNexusFunction pDriv, char *filename);
void popFileStack(pFileStack self);
pNexusFunction peekFileOnStack(pFileStack self);
char *peekFilenameOnStack(pFileStack self);
void peekIDOnStack(pFileStack self, NXlink *id);
void setCloseID(pFileStack self, NXlink id);
int fileStackDepth(pFileStack self);
void pushPath(pFileStack self, const char *name);
void popPath(pFileStack self);
int buildPath(pFileStack self, char *path, int pathlen);
#endif

1992
nxxml.c

File diff suppressed because it is too large Load Diff

78
nxxml.h
View File

@ -1,78 +0,0 @@
/*
* This is the header file for the NeXus XML file driver.
*
* Copyright (C) 2004 Mark Koennecke
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For further information, see <http://www.nexusformat.org>
*/
#ifndef NEXUSXML
#define NEXUSXML
extern NXstatus NXXopen(CONSTCHAR *filename,
NXaccess access_method,
NXhandle* pHandle);
extern NXstatus NXXclose(NXhandle* pHandle);
extern NXstatus NXXflush(NXhandle* pHandle);
NXstatus NXXmakegroup (NXhandle fid, CONSTCHAR *name,
CONSTCHAR *nxclass);
NXstatus NXXopengroup (NXhandle fid, CONSTCHAR *name,
CONSTCHAR *nxclass);
NXstatus NXXclosegroup (NXhandle fid);
NXstatus NXXcompmakedata64 (NXhandle fid, CONSTCHAR *name,
int datatype,
int rank,
int64_t dimensions[],
int compress_type, int64_t chunk_size[]);
NXstatus NXXmakedata64 (NXhandle fid,
CONSTCHAR *name, int datatype,
int rank, int64_t dimensions[]);
NXstatus NXXopendata (NXhandle fid, CONSTCHAR *name);
NXstatus NXXclosedata (NXhandle fid);
NXstatus NXXputdata (NXhandle fid, void *data);
NXstatus NXXgetdata (NXhandle fid, void *data);
NXstatus NXXgetinfo64 (NXhandle fid, int *rank,
int64_t dimension[], int *iType);
NXstatus NXXputslab64 (NXhandle fid, void *data,
int64_t iStart[], int64_t iSize[]);
NXstatus NXXgetslab64 (NXhandle fid, void *data,
const int64_t iStart[], const int64_t iSize[]);
NXstatus NXXputattr (NXhandle fid, CONSTCHAR *name, void *data,
int datalen, int iType);
NXstatus NXXgetattr (NXhandle fid, char *name,
void *data, int* datalen, int* iType);
NXstatus NXXgetnextentry (NXhandle fid,NXname name,
NXname nxclass, int *datatype);
extern NXstatus NXXgetnextattr(NXhandle handle,
NXname pName, int *iLength, int *iType);
extern NXstatus NXXinitgroupdir(NXhandle handle);
extern NXstatus NXXinitattrdir(NXhandle handle);
extern NXstatus NXXgetattrinfo (NXhandle fid, int *iN);
extern NXstatus NXXgetgroupinfo (NXhandle fid, int *iN,
NXname pName, NXname pClass);
extern NXstatus NXXgetdataID (NXhandle fid, NXlink* sRes);
extern NXstatus NXXgetgroupID (NXhandle fid, NXlink* sRes);
extern NXstatus NXXmakelink (NXhandle fid, NXlink* sLink);
extern NXstatus NXXprintlink (NXhandle fid, NXlink* sLink);
extern NXstatus NXXsameID (NXhandle fileid,
NXlink* pFirstID, NXlink* pSecondID);
void NXXassignFunctions(pNexusFunction fHandle);
#endif

View File

@ -148,8 +148,6 @@ static long SCTDRIVSetValue(void *data, SConnection * pCon, float val)
} }
pPriv->pCon = SCCopyConnection(pCon); pPriv->pCon = SCCopyConnection(pCon);
/* StopByData(pServ->pExecutor, data); */
v = MakeHdbFloat(val); v = MakeHdbFloat(val);
SetHdbProperty(self->objectNode, "writestatus", "start"); SetHdbProperty(self->objectNode, "writestatus", "start");
status = SetHipadabaPar(self->objectNode, v, pCon); status = SetHipadabaPar(self->objectNode, v, pCon);

View File

@ -19,6 +19,10 @@
* Refactored to new callback system, Markus Zolliker, Mark Koennecke, March 2008 * Refactored to new callback system, Markus Zolliker, Mark Koennecke, March 2008
* *
* Added start and finished messages to commands. Mark Koennecke, November 2008 * Added start and finished messages to commands. Mark Koennecke, November 2008
*
* Added SicsValueCheckCallback and implemented first version of haddcheck.
* Mark Koennecke, July 2013
*
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -238,6 +242,51 @@ pHdbCallback MakeReadOnlyCallback()
{ {
return MakeHipadabaCallback(SICSReadOnlyCallback, NULL, NULL); return MakeHipadabaCallback(SICSReadOnlyCallback, NULL, NULL);
} }
/*------------------------------------------------------------------------------------*/
static hdbCallbackReturn SICSValueCheckCallback(pHdb node, void *userData,
pHdbMessage message)
{
SConnection *pCon = NULL;
pHdbDataMessage mm = NULL;
char values[1024], *pPtr, pToken[80];
int status;
hdbValue v;
mm = GetHdbSetMessage(message);
if (mm == NULL) {
return hdbContinue;
}
pCon = (SConnection *) mm->callData;
v = *(mm->v);
status = GetHdbProperty(node,"values",values,sizeof(values));
if(status != 1 && pCon != NULL){
SCPrintf(pCon,eLogError,"ERROR: configuration error, no values on node %s",
node->name);
return hdbAbort;
}
if(v.dataType != HIPTEXT && pCon != NULL){
SCPrintf(pCon,eLogError,"ERROR: need text data for node %s",
node->name);
return hdbAbort;
}
pPtr = values;
while((pPtr = stptok(pPtr,pToken,sizeof(pToken),",")) != NULL){
if(strcmp(pToken,v.v.text) == 0) {
return hdbContinue;
}
}
if(pCon != NULL){
SCPrintf(pCon,eLogError,"ERROR: %s not allowed as value for %s, allowed are: %s",
v.v.text, node->name, values);
}
return hdbAbort;
}
/*-------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------*/
static hdbCallbackReturn SICSDriveCallback(pHdb node, void *userData, static hdbCallbackReturn SICSDriveCallback(pHdb node, void *userData,
@ -3767,7 +3816,38 @@ static int MatchHdbProperty(SConnection * pCon, SicsInterp * pSics,
} }
return 1; return 1;
} }
/*---------------------------------------------------------------------------*/
static int AddCheck(SConnection * pCon, SicsInterp * pSics,
void *pData, int argc, char *argv[])
{
pHdb node = NULL;
if(argc < 3) {
SCPrintf(pCon,eLogError, "ERROR: need at least node and key argument for %s",
argv[0]);
return 0;
}
node = FindHdbNode(NULL, argv[1],pCon);
if (node == NULL) {
SCPrintf(pCon,eLogError, "ERROR: node %s to add check to not found", argv[1]);
return 0;
}
strtolower(argv[2]);
if(strcmp(argv[2],"values") == 0) {
PrependHipadabaCallback(node,MakeHipadabaCallback(SICSValueCheckCallback,
NULL,NULL));
SCSendOK(pCon);
return 1;
} else {
SCPrintf(pCon,eLogError,"ERROR: key %s for %s not recognized",
argv[2], argv[0]);
return 0;
}
return 1;
}
/*======================= Factory Functions =================================*/ /*======================= Factory Functions =================================*/
void killSICSHipadaba() void killSICSHipadaba()
{ {
@ -3810,6 +3890,7 @@ int InstallSICSHipadaba(SConnection * pCon, SicsInterp * pSics,
AddCommand(pSics, "hmatchprop", MatchHdbProperty, NULL, NULL); AddCommand(pSics, "hmatchprop", MatchHdbProperty, NULL, NULL);
AddCommand(pSics, "hlistprop", ListSICSHdbProperty, NULL, NULL); AddCommand(pSics, "hlistprop", ListSICSHdbProperty, NULL, NULL);
AddCommand(pSics, "hcallnotify",CallNotify, NULL, NULL); AddCommand(pSics, "hcallnotify",CallNotify, NULL, NULL);
AddCommand(pSics, "haddcheck",AddCheck, NULL, NULL);
InstallSICSPoll(pCon, pSics, pData, argc, argv); InstallSICSPoll(pCon, pSics, pData, argc, argv);
poller = (pSicsPoll) FindCommandData(pSics, "sicspoll", "SicsPoll"); poller = (pSicsPoll) FindCommandData(pSics, "sicspoll", "SicsPoll");

View File

@ -474,6 +474,12 @@ int InvokeSICSOBJ(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc == 1) { if (argc == 1) {
parNode = self->objectNode; parNode = self->objectNode;
if (parNode != NULL && isNodePrintable(parNode)) { if (parNode != NULL && isNodePrintable(parNode)) {
status = GetHdbProperty(parNode,"geterror",buffer,sizeof(buffer));
if (status == 1 && strstr(buffer,"none") == NULL){
SCPrintf(pCon,eValue,"ERROR: %s on last read of %s", buffer, argv[0]);
SCPrintf(pCon,eValue,"%s = -99999", argv[0]);
return 0;
}
status = GetHipadabaPar(parNode, &data, pCon); status = GetHipadabaPar(parNode, &data, pCon);
if (status != 1) { if (status != 1) {
return 0; return 0;

View File

@ -58,6 +58,11 @@ static int VarSave(void *pData, char *name, FILE * fd)
if (pVar->iAccessCode == usInternal) { if (pVar->iAccessCode == usInternal) {
return 1; return 1;
} }
if(pVar->iLock == 1) {
return 1;
}
snprintf(pBueffel,sizeof(pBueffel)-1, "# Variable %s\n", name); snprintf(pBueffel,sizeof(pBueffel)-1, "# Variable %s\n", name);
switch (pVar->eType) { switch (pVar->eType) {
case veText: case veText:

View File

@ -1,3 +1,5 @@
exe batchpath ./ exe batchpath ./
exe syspath ./ exe syspath ./
@ -218,15 +220,17 @@ tasub r2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
tasub update tasub update
#----- MultiMotor sa #----- MultiMotor sa
sa recovernampos noeff a3 24 a4 48 sa recovernampos noeff a3 24 a4 48
ref anglesheader stt,om,chi,phi ref anglesheader stt,om,chi,phi
ref clear ref clear
singlex cell 0 0 0 0 0 0 singlex cell { 0 0 0 0 0 0}
singlex oldub 0 0 0 0 0 0 0 0 0 singlex oldub { 0 0 0 0 0 0 0 0 0}
singlex ub 0 0 0 0 0 0 0 0 0 singlex ub { 0 0 0 0 0 0 0 0 0}
singlex planenormal 0 0 0 singlex planenormal { 0 0 0}
singlex mode bi singlex mode bi
singlex spacegroup P singlex spacegroup P
singlex peaksearch singlex peaksearch {}
singlex peaksearch/min2t 5 singlex peaksearch/min2t 5
singlex peaksearch/step2t 1 singlex peaksearch/step2t 1
singlex peaksearch/max2t 15 singlex peaksearch/max2t 15
@ -238,6 +242,7 @@ singlex peaksearch/phimin 0
singlex peaksearch/phimax 180 singlex peaksearch/phimax 180
singlex peaksearch/chimin 90 singlex peaksearch/chimin 90
singlex peaksearch/chimax 180 singlex peaksearch/chimax 180
#HKL Settings #HKL Settings
hkl scantolerance 2.500000 hkl scantolerance 2.500000
ubcalcint difftheta 0.300000 ubcalcint difftheta 0.300000
@ -249,16 +254,20 @@ messref clear
fmess weak 0 fmess weak 0
fmess weakthreshold 20 fmess weakthreshold 20
fmess fast 0 fmess fast 0
fmess hkllim -10 -10 10 10 10 10 fmess hkllim { -10 -10 10 10 10 10}
fmess sttlim 5 180 fmess sttlim { 5 180}
fmess table clear fmess table clear
cone target 0 0 0 cone target { 0 0 0}
cone qscale 1 cone qscale 1
cone center unknown cone center unknown
simidx sttlim 0.2 simidx sttlim 0.2
simidx anglim 0.5 simidx anglim 0.5
simi preset 0 simi preset 0
simi mode monitor simi mode monitor
eva targetposition 0 eva targetposition 0
eva sign 1 eva sign 1
eva softzero 0 eva softzero 0
@ -273,3 +282,8 @@ eva maxretry 3
eva ignorefault 0 eva ignorefault 0
eva movecount 10 eva movecount 10
eva staticoffset 0 eva staticoffset 0

View File

@ -833,3 +833,12 @@ if {$secmot == 1} {
MakeSecSim eva -40 40 .3 MakeSecSim eva -40 40 .3
} }
set zwickroll 1
if {$zwickroll == 1} {
source ../tcl/zwickroll.tcl
# makesctcontroller zwro std pc8977:50370 \r\n 5 \r\n
makesctcontroller zwro std localhost:8080 \r\n 5 \n
zwickroll::makezwickroll zwro
}

View File

@ -43,7 +43,7 @@ int traceActive()
static char *GetTracePath(pHdb node) static char *GetTracePath(pHdb node)
{ {
pHdb nodeStack[64]; pHdb nodeStack[64];
int depth = 0, length = 0, i; int depth = 0, length = 1, i;
pHdb current = NULL; pHdb current = NULL;
char *pPtr = NULL; char *pPtr = NULL;
char sicsdev[80]; char sicsdev[80];
@ -53,7 +53,7 @@ static char *GetTracePath(pHdb node)
*/ */
current = node; current = node;
while (current != NULL && GetHdbProperty(current,"sicsdev",sicsdev,sizeof(sicsdev)) == 0) { while (current != NULL && GetHdbProperty(current,"sicsdev",sicsdev,sizeof(sicsdev)) == 0) {
length += strlen(current->name) + 1; length += strlen(current->name) + 2;
nodeStack[depth] = current; nodeStack[depth] = current;
depth++; depth++;
assert(depth < 64); assert(depth < 64);