From d4a37b1874ac4849ec3a9ba85fa90754ea0e5feb Mon Sep 17 00:00:00 2001 From: Tobias Richter Date: Mon, 15 Aug 2016 11:24:48 +0200 Subject: [PATCH] refs #426 this fixes the tests properly The tests do not exercise all routes to the unsupported API in the leagcy backends, so some more work required to fix all client applications. --- bindings/cpp/NeXusFile.cpp | 18 +++--------------- src/napi4.c | 15 +++++++++++---- src/nxxml.c | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/bindings/cpp/NeXusFile.cpp b/bindings/cpp/NeXusFile.cpp index b2da59c7..174bd07c 100644 --- a/bindings/cpp/NeXusFile.cpp +++ b/bindings/cpp/NeXusFile.cpp @@ -1102,16 +1102,6 @@ AttrInfo File::getNextAttr() { char name[NX_MAXNAMELEN]; int type; -#if defined(WITH_HDF4) || defined(WITH_MXML) - int length; - NXstatus status = NXgetnextattr(this->m_file_id, name, &length, &type); - if (status == NX_OK) { - AttrInfo info; - info.type = static_cast(type); - info.length = length; - info.name = string(name); - return info; -#else int rank; int dim[NX_MAXRANK]; NXstatus status = NXgetnextattra(this->m_file_id, name, &rank, dim, &type); @@ -1145,15 +1135,13 @@ AttrInfo File::getNextAttr() { // TODO - AttrInfo cannot handle more complex ranks/dimensions, we need to throw an error std::cerr << "ERROR iterating through attributes found array attribute not understood by this api" << std::endl; throw Exception("getNextAttr failed", NX_ERROR); -#endif - } - else if (status == NX_EOD) { + + } else if (status == NX_EOD) { AttrInfo info; info.name = NULL_STR; info.length = 0; return info; - } - else { + } else { throw Exception("NXgetnextattra failed", status); } } diff --git a/src/napi4.c b/src/napi4.c index e8c51390..9e03123f 100644 --- a/src/napi4.c +++ b/src/napi4.c @@ -1953,15 +1953,22 @@ static int findNapiClass(pNexusFile pFile, int groupRef, NXname nxclass) /*--------------------------------------------------------------------*/ NXstatus NX4putattra(NXhandle handle, CONSTCHAR* name, const void* data, const int rank, const int dim[], const int iType) { - NXReportError("This is a HDF4 file, attribute array API is not supported here"); - return NX_ERROR; + if (rank > 1) { + NXReportError("This is a HDF4 file, there is only rudimentary support for attribute arrays wirh rank <=1"); + return NX_ERROR; + } + + return NX4putattr(handle, name, data, dim[0], iType); } /*--------------------------------------------------------------------*/ NXstatus NX4getnextattra(NXhandle handle, NXname pName, int *rank, int dim[], int *iType) { - NXReportError("This is a HDF4 file, attribute array API is not supported here"); - return NX_ERROR; + NXstatus ret = NX4getnextattr(handle, pName, dim, iType); + if (ret != NX_OK) return ret; + (*rank) = 1; + if (dim[0] <= 1 ) (*rank) = 0; + return NX_OK; } /*--------------------------------------------------------------------*/ diff --git a/src/nxxml.c b/src/nxxml.c index 55b09b95..230c6044 100644 --- a/src/nxxml.c +++ b/src/nxxml.c @@ -1968,15 +1968,22 @@ int NXXcompress(NXhandle fid, int comp){ /*--------------------------------------------------------------------*/ NXstatus NXXputattra(NXhandle handle, CONSTCHAR* name, const void* data, const int rank, const int dim[], const int iType) { - NXReportError("This is an XML file, attribute array API is not supported here"); - return NX_ERROR; + if (rank > 1) { + NXReportError("This is an XML file, there is only rudimentary support for attribute arrays wirh rank <=1"); + return NX_ERROR; + } + + return NXXputattr(handle, name, data, dim[0], iType); } /*--------------------------------------------------------------------*/ NXstatus NXXgetnextattra(NXhandle handle, NXname pName, int *rank, int dim[], int *iType) { - NXReportError("This is an XML file, attribute array API is not supported here"); - return NX_ERROR; + NXstatus ret = NXXgetnextattr(handle, pName, dim, iType); + if (ret != NX_OK) return ret; + (*rank) = 1; + if (dim[0] <= 1 ) (*rank) = 0; + return NX_OK; } /*--------------------------------------------------------------------*/ @@ -1996,7 +2003,7 @@ NXstatus NXXgetattrainfo(NXhandle handle, NXname pName, int *rank, int dim[], i /*----------------------------------------------------------------------*/ void NXXassignFunctions(pNexusFunction fHandle){ fHandle->nxclose=NXXclose; - fHandle->nxreopen=NULL; + fHandle->nxreopen=NULL; fHandle->nxflush=NXXflush; fHandle->nxmakegroup=NXXmakegroup; fHandle->nxopengroup=NXXopengroup; @@ -2027,10 +2034,10 @@ void NXXassignFunctions(pNexusFunction fHandle){ fHandle->nxsetnumberformat=NXXsetnumberformat; fHandle->nxprintlink=NXXprintlink; fHandle->nxnativeexternallink=NULL; - fHandle->nxputattra = NXXputattra; - fHandle->nxgetnextattra = NXXgetnextattra; - fHandle->nxgetattra = NXXgetattra; - fHandle->nxgetattrainfo = NXXgetattrainfo; + fHandle->nxputattra = NXXputattra; + fHandle->nxgetnextattra = NXXgetnextattra; + fHandle->nxgetattra = NXXgetattra; + fHandle->nxgetattrainfo = NXXgetattrainfo; } #endif /*NXXML*/