- Removed automatic loading of status file on startup

- make soft motor values the default all over
- Introduced nxscript putSlab
- Fixed a bug in polldriv
This commit is contained in:
koennecke
2007-02-23 14:31:43 +00:00
parent 8987f54bed
commit 6eb387654e
23 changed files with 710 additions and 439 deletions

191
nxxml.c
View File

@@ -2,7 +2,7 @@
* This is the implementation file for the XML file driver
* for NeXus
*
* Copyright (C) 2004 Mark Koennecke
* Copyright (C) 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
@@ -18,7 +18,7 @@
* 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.neutron.anl.gov/NeXus/>
* For further information, see <http://www.nexusformat.org>
*/
#include <stdio.h>
#include <napi.h>
@@ -243,6 +243,7 @@ static mxml_node_t *searchGroupLinks(pXMLNexus xmlHandle, CONSTCHAR *name,
mxml_node_t *current;
mxml_node_t *test = NULL;
const char *linkTarget;
const char *linkName = NULL;
current = xmlHandle->stack[xmlHandle->stackPointer].current;
linkNode = current;
@@ -257,6 +258,17 @@ static mxml_node_t *searchGroupLinks(pXMLNexus xmlHandle, CONSTCHAR *name,
}
}
}
/*
test for named links
*/
linkName = mxmlElementGetAttr(linkNode,"name");
if(test != NULL && linkName != NULL){
if(strcmp(test->value.element.name,nxclass) == 0){
if(strcmp(linkName, name) == 0){
return test;
}
}
}
}
return NULL;
}
@@ -374,8 +386,10 @@ NXstatus NXXmakedata (NXhandle fid,
return NX_ERROR;
}
if(dimensions[0] < 0){
NXIReportError(NXpData,
"NeXus XML-API does not support unlimited dimensions");
dimensions[0] = 1;
}
if ((datatype == NX_CHAR) && (rank > 1)) {
NXIReportError(NXpData,"NeXus XML-API does not yet support multi-dimensional character arrays");
return NX_ERROR;
}
@@ -419,6 +433,7 @@ static mxml_node_t *searchSDSLinks(pXMLNexus xmlHandle, CONSTCHAR *name){
mxml_node_t *current;
mxml_node_t *test = NULL;
const char *linkTarget;
const char *linkName = NULL;
current = xmlHandle->stack[xmlHandle->stackPointer].current;
linkNode = current;
@@ -431,6 +446,15 @@ static mxml_node_t *searchSDSLinks(pXMLNexus xmlHandle, CONSTCHAR *name){
return test;
}
}
/*
test for named links
*/
linkName = mxmlElementGetAttr(linkNode,"name");
if(test != NULL && linkName != NULL){
if(strcmp(linkName,name) == 0){
return test;
}
}
}
return NULL;
}
@@ -670,6 +694,38 @@ static void putSlabData(pNXDS dataset, pNXDS slabData, int dim,
}
}
}
/*----------------------------------------------------------------------
This is in order to support unlimited dimensions along the first axis
-----------------------------------------------------------------------*/
static int checkAndExtendDataset(mxml_node_t *node, pNXDS dataset,
int start[], int size[]){
int dim0, byteLength;
void *oldData = NULL;
char *typestring = NULL;
dim0 = start[0] + size[0];
if(dim0 > dataset->dim[0]){
byteLength = getNXDatasetByteLength(dataset);
oldData = dataset->u.ptr;
dataset->dim[0] = dim0;
dataset->u.ptr = malloc(getNXDatasetByteLength(dataset));
if(dataset->u.ptr == NULL){
return 0;
}
memset(dataset->u.ptr,0,getNXDatasetByteLength(dataset));
memcpy(dataset->u.ptr,oldData,byteLength);
free(oldData);
typestring = buildTypeString(dataset->type,dataset->rank,dataset->dim);
if(typestring != NULL){
mxmlElementSetAttr(node,TYPENAME,typestring);
free(typestring);
} else {
NXIReportError(NXpData,"Failed to allocate typestring");
return 0;
}
}
return 1;
}
/*----------------------------------------------------------------------*/
NXstatus NXXputslab (NXhandle fid, void *data,
int iStart[], int iSize[]){
@@ -678,7 +734,7 @@ NXstatus NXXputslab (NXhandle fid, void *data,
mxml_node_t *userData = NULL;
mxml_node_t *current = NULL;
pNXDS dataset, slabData;
int sourcePos[NX_MAXRANK], targetPos[NX_MAXRANK];
int sourcePos[NX_MAXRANK], targetPos[NX_MAXRANK], status;
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
@@ -697,11 +753,20 @@ NXstatus NXXputslab (NXhandle fid, void *data,
}
dataset = (pNXDS)userData->value.custom.data;
assert(dataset);
status = checkAndExtendDataset(current,dataset,iStart,iSize);
if(status == 0){
NXIReportError(NXpData,"Out of memory extending dataset");
return NX_ERROR;
}
slabData = makeSlabData(dataset, data, iSize);
if(slabData == NULL){
NXIReportError(NXpData,"Failed to allocate slab data");
return NX_ERROR;
}
putSlabData(dataset,slabData,0,iStart,sourcePos,targetPos);
free(slabData->dim);
free(slabData);
@@ -882,16 +947,8 @@ NXstatus NXXputattr (NXhandle fid, CONSTCHAR *name, void *data,
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(!isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
/*
global attribute
*/
current = xmlHandle->stack[0].current;
} else {
/*
dataset attribute
*/
current = xmlHandle->stack[xmlHandle->stackPointer].current;
current = xmlHandle->stack[xmlHandle->stackPointer].current;
if(isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
if(strcmp(name,TYPENAME) == 0){
NXIReportError(NXpData,"type is a reserved attribute name, rejected");
return NX_ERROR;
@@ -922,17 +979,7 @@ NXstatus NXXgetattr (NXhandle fid, char *name,
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(!isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
/*
global attribute
*/
current = xmlHandle->stack[0].current;
} else {
/*
dataset attribute
*/
current = xmlHandle->stack[xmlHandle->stackPointer].current;
}
current = xmlHandle->stack[xmlHandle->stackPointer].current;
attribute = mxmlElementGetAttr(current,name);
if(!attribute){
@@ -1014,6 +1061,7 @@ NXstatus NXXgetnextentry (NXhandle fid,NXname name,
const char *target = NULL, *attname = NULL;
pNXDS dataset;
char pBueffel[256];
const char *linkName = NULL;
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
@@ -1045,6 +1093,7 @@ NXstatus NXXgetnextentry (NXhandle fid,NXname name,
}
if(strcmp(next->value.element.name,"NAPIlink") == 0){
target = mxmlElementGetAttr(next,"target");
linkName = mxmlElementGetAttr(next,"name");
if(target == NULL){
NXIReportError(NXpData,"Corrupted file, NAPIlink without target");
return NX_ERROR;
@@ -1078,6 +1127,12 @@ NXstatus NXXgetnextentry (NXhandle fid,NXname name,
attname = mxmlElementGetAttr(next,"name");
strcpy(name,attname);
}
/*
this is for named links
*/
if(linkName != NULL){
strcpy(name,linkName);
}
return NX_OK;
}
/*----------------------------------------------------------------------*/
@@ -1108,17 +1163,7 @@ NXstatus NXXgetnextattr (NXhandle fid, NXname pName,
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
/*
dataset attribute
*/
stackPtr = xmlHandle->stackPointer;
} else {
/*
global attribute
*/
stackPtr = 0;
}
stackPtr = xmlHandle->stackPointer;
current = xmlHandle->stack[stackPtr].current;
currentAtt = xmlHandle->stack[stackPtr].currentAttribute;
@@ -1128,10 +1173,20 @@ NXstatus NXXgetnextattr (NXhandle fid, NXname pName,
return NX_EOD;
}
/*
hide group name attribute
*/
if(strcmp(current->value.element.attrs[currentAtt].name,"name") == 0
&& !isDataNode(current) ){
xmlHandle->stack[stackPtr].currentAttribute++;
return NXXgetnextattr(fid,pName,iLength,iType);
}
/*
hide type attribute
*/
if(strcmp(current->value.element.attrs[currentAtt].name,TYPENAME) == 0){
if(strcmp(current->value.element.attrs[currentAtt].name,TYPENAME) == 0
&& isDataNode(current)){
xmlHandle->stack[stackPtr].currentAttribute++;
return NXXgetnextattr(fid,pName,iLength,iType);
}
@@ -1161,18 +1216,7 @@ extern NXstatus NXXinitattrdir(NXhandle fid){
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
/*
dataset attribute
*/
stackPtr = xmlHandle->stackPointer;
} else {
/*
global attribute
*/
stackPtr = 0;
}
stackPtr = xmlHandle->stackPointer;
xmlHandle->stack[stackPtr].currentAttribute = 0;
return NX_OK;
}
@@ -1218,22 +1262,17 @@ NXstatus NXXgetattrinfo (NXhandle fid, int *iN){
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
/*
dataset attribute
*/
stackPtr = xmlHandle->stackPointer;
} else {
/*
global attribute
*/
stackPtr = 0;
}
stackPtr = xmlHandle->stackPointer;
current = xmlHandle->stack[stackPtr].current;
/*
hide type attribute
hide type and group name attributes
*/
if(!isDataNode(current)) {
*iN = current->value.element.num_attrs -1;
return NX_OK;
}
if(mxmlElementGetAttr(current,TYPENAME) != NULL){
*iN = current->value.element.num_attrs -1;
} else {
@@ -1413,6 +1452,34 @@ NXstatus NXXmakelink (NXhandle fid, NXlink* sLink){
}
return NX_OK;
}
/*-----------------------------------------------------------------------*/
NXstatus NXXmakenamedlink (NXhandle fid, char *name, NXlink* sLink){
pXMLNexus xmlHandle = NULL;
mxml_node_t *current = NULL, *linkNode = NULL;
mxml_node_t *linkedNode = NULL;
xmlHandle = (pXMLNexus)fid;
assert(xmlHandle);
if(isDataNode(xmlHandle->stack[xmlHandle->stackPointer].current)){
NXIReportError(NXpData,"No group to link to open");
return NX_ERROR;
}
current = xmlHandle->stack[xmlHandle->stackPointer].current;
linkNode = mxmlNewElement(current,"NAPIlink");
if(!linkNode){
NXIReportError(NXpData,"Failed to allocate new link element");
return NX_ERROR;
}
mxmlElementSetAttr(linkNode,"target",sLink->targetPath);
mxmlElementSetAttr(linkNode,"name",name);
linkedNode = getLinkTarget(xmlHandle,sLink->targetPath);
if(linkedNode != NULL){
mxmlElementSetAttr(linkedNode,"target",sLink->targetPath);
}
return NX_OK;
}
/*----------------------------------------------------------------------*/
NXstatus NXXsameID (NXhandle fileid, NXlink* pFirstID,
NXlink* pSecondID){