diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4c50538d..4603eadc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,7 +69,7 @@ endif()
#-----------------------------------------------------------------------------
set (API_VERSION_MAJOR 4)
set (API_VERSION_MINOR 4)
-set (API_VERSION_PATCH 2)
+set (API_VERSION_PATCH 3)
set (API_VERSION "${API_VERSION_MAJOR}.${API_VERSION_MINOR}.${API_VERSION_PATCH}")
set (ABI_CURRENT 1)
set (ABI_REVISION 0)
@@ -78,7 +78,7 @@ set (ABI_VERSION "${ABI_CURRENT}.${ABI_REVISION}.${ABI_AGE}")
set (NEXUS_VERSION_MAJOR 4)
set (NEXUS_VERSION_MINOR 4)
-set (NEXUS_VERSION_PATCH 2)
+set (NEXUS_VERSION_PATCH 3)
set (NEXUS_SONAME 4)
set (NAPI_VERSION "${NEXUS_VERSION_MAJOR}.${NEXUS_VERSION_MINOR}.${NEXUS_VERSION_PATCH}")
set (NXLTVERSINFO "${NEXUS_VERSION_MAJOR}:${NEXUS_VERSION_MINOR}:${NEXUS_VERSION_PATCH}")
@@ -254,7 +254,9 @@ add_subdirectory (test) #build the tests
add_subdirectory (bindings) #build the language bindings
add_subdirectory (scripts) #install pkg-config files
-#on user request utility applications will be built
+#------------------------------------------------------------------------------
+# on user request utility applications will be built
+#------------------------------------------------------------------------------
if(ENABLE_APPS)
add_subdirectory (applications)
endif()
@@ -262,6 +264,9 @@ endif()
add_subdirectory (doc)
#add_subdirectory (config)
+#------------------------------------------------------------------------------
+# on user request contributed applications will be built
+#------------------------------------------------------------------------------
if(ENABLE_CONTRIB)
add_subdirectory (contrib)
endif()
@@ -290,7 +295,9 @@ if(WIN32)
file(GLOB HDF4_DLLS "${HDF4_LIBRARY_DIRS}/../bin/*.dll")
# for some reason HDF5_LIBRARY_DIRS is blank
file(GLOB HDF5_DLLS "${HDF5_INCLUDE_DIRS}/../bin/*.dll")
- file(GLOB_RECURSE MXML_DLLS "${MXML_LIBRARY_DIRS}/*.dll")
+ if(WITH_MXML)
+ file(GLOB_RECURSE MXML_DLLS "${MXML_LIBRARY_DIRS}/*.dll")
+ endif()
install(FILES ${HDF4_DLLS} ${HDF5_DLLS} ${MXML_DLLS} DESTINATION bin COMPONENT Runtime)
INSTALL(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin COMPONENT Runtime)
endif()
@@ -314,6 +321,8 @@ elseif(CYGWIN)
set (CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_GENERATOR};CygwinSource)
elseif(UNIX)
set (CPACK_GENERATOR ${CPACK_GENERATOR};DEB;RPM)
+ set (CPACK_DEBIAN_PACKAGE_DEPENDS "libhdf5-103, libhdf5-dev")
+ set (CPACK_RPM_PACKAGE_REQUIRES "hdf5, hdf5-devel")
endif()
# Include of CPack must always be last
include(CPack)
diff --git a/README.rst b/README.rst
index c3e8403f..0d5c9dc2 100644
--- a/README.rst
+++ b/README.rst
@@ -83,7 +83,7 @@ Program Description
``nxbrowse`` browse a NeXus file
``nxdir`` list the contents of a NeXus file
``nxconvert`` convert a NeXus file to whatever?
-``nxtraverse`` no idea what this is good for
+``nxtraverse`` list the contents of a NeXus file
``nxdump``
``nxingest``
``nxsummary``
@@ -109,9 +109,12 @@ To build the library and program binaries simply use
.. code-block:: bash
+ $ mkdir build
+ $ cd build
+ $ cmake -DENABLE_APPS=ON .. # building with tools as example config option
$ make
-and for installation
+from the source directoy. For installation run
.. code-block:: bash
diff --git a/README.versions b/README.versions
deleted file mode 100644
index f719739c..00000000
--- a/README.versions
+++ /dev/null
@@ -1,4 +0,0 @@
-To increment the NeXus version you need to:
-- change the argument to AC_INIT in configure.ac
-- update NEXUS_VERSION in include/napi.h
-- change version number printed in test output contained in test/testsuite.at
diff --git a/applications/CMakeLists.txt b/applications/CMakeLists.txt
index 0f8d0d4e..2b5b61ab 100644
--- a/applications/CMakeLists.txt
+++ b/applications/CMakeLists.txt
@@ -66,15 +66,22 @@ include_directories("../include")
# proceed with building the programs
#-----------------------------------------------------------------------------
-add_subdirectory (NXbrowse)
-#add_subdirectory(c-nxvalidate)
+if (HAVE_LIBREADLINE)
+ add_subdirectory (NXbrowse)
+else()
+ message(WARNING "libreadline not found, not building: nxbrowse")
+endif()
if (ENABLE_CXX)
- add_subdirectory (NXdir)
- add_subdirectory (NXconvert)
- add_subdirectory (NXtraverse)
+ add_subdirectory (NXdir)
+ add_subdirectory (NXconvert)
+else()
+ message(WARNING "C++ bindings not enabled, not building: NXdri, NXconvert")
endif()
+#depends only in Nexus C API
+add_subdirectory (NXtraverse)
+
if (ENABLE_FORTRAN90 AND CMAKE_Fortran_COMPILER_WORKS)
add_subdirectory (NXdump)
endif()
@@ -83,10 +90,14 @@ endif()
if(LIBXML2_FOUND)
add_subdirectory (NXsummary)
add_subdirectory (NXtranslate)
+else()
+ message(WARNING "LIBXML2 library not found, not building: NXsummary, NXtranslate")
endif(LIBXML2_FOUND)
if (WITH_MXML)
add_subdirectory (nxingest)
+else()
+ message(WARNING "MXML not enabled, not building: nxingest")
endif()
#-----------------------------------------------------------------------------
diff --git a/applications/NXconvert/nxconvert.cpp b/applications/NXconvert/nxconvert.cpp
index 204283d8..aa5a5f0c 100644
--- a/applications/NXconvert/nxconvert.cpp
+++ b/applications/NXconvert/nxconvert.cpp
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
false);
ValueArgNeXus Programmers Reference
void NXIReportError(void *pData, char *errorText);
A NeXus-API user now can replace the default error reporting function through an own implementation with the
-function NXMSetError. NXMSetError also allows to pass in a pointer to a user defined data structure which is
+function NXMSetError. NXMSetError also allows one to pass in a pointer to a user defined data structure which is
passed as pData to the error reporting function.
The NeXus file drivers for the HDF file formats HDF-4 and HDF-5 share common features. I recall that NeXus uses a hierarchy in order to organize information storage. But both HDF-API's are not tree based -but use an interface which allows to open and close groups and datasets. This is sensible as HDF is designed +but use an interface which allows one to open and close groups and datasets. This is sensible as HDF is designed to support very large data sets which may not necessarily fit into a computers memory in one go. But this also implies that the current position in the hierarchy of a given NeXus file has to be maintained by the NeXus-API. Such information is maintained in a stack which is pushed an popped while moving through the hierarchy. This diff --git a/doc/api/NeXusIntern.radi b/doc/api/NeXusIntern.radi index d9d90240..0f8cb830 100755 --- a/doc/api/NeXusIntern.radi +++ b/doc/api/NeXusIntern.radi @@ -137,7 +137,7 @@ the signature: void NXIReportError(void *pData, char *errorText); }}} A NeXus-API user now can replace the default error reporting function through an own implementation with the -function NXMSetError. NXMSetError also allows to pass in a pointer to a user defined data structure which is +function NXMSetError. NXMSetError also allows one to pass in a pointer to a user defined data structure which is passed as pData to the error reporting function. = NeXus File Drivers = @@ -145,7 +145,7 @@ passed as pData to the error reporting function. == NeXus HDF File Drivers == The NeXus file drivers for the HDF file formats HDF-4 and HDF-5 share common features. I recall that NeXus uses a hierarchy in order to organize information storage. But both HDF-API's are not tree based -but use an interface which allows to open and close groups and datasets. This is sensible as HDF is designed +but use an interface which allows one to open and close groups and datasets. This is sensible as HDF is designed to support very large data sets which may not necessarily fit into a computers memory in one go. But this also implies that the current position in the hierarchy of a given NeXus file has to be maintained by the NeXus-API. Such information is maintained in a stack which is pushed an popped while moving through the hierarchy. This diff --git a/doc/api/NeXusIntern.tex b/doc/api/NeXusIntern.tex index 827b5765..a1daca0a 100644 --- a/doc/api/NeXusIntern.tex +++ b/doc/api/NeXusIntern.tex @@ -149,7 +149,7 @@ \section{The Top Level NeXus API } void NXIReportError(void *pData, char *errorText); \end{verbatim} A NeXus-API user now can replace the default error reporting function through an own implementation with the -function NXMSetError. NXMSetError also allows to pass in a pointer to a user defined data structure which is +function NXMSetError. NXMSetError also allows one to pass in a pointer to a user defined data structure which is passed as pData to the error reporting function. @@ -157,7 +157,7 @@ \section{NeXus File Drivers } \subsection{NeXus HDF File Drivers } The NeXus file drivers for the HDF file formats HDF-4 and HDF-5 share common features. I recall that NeXus uses a hierarchy in order to organize information storage. But both HDF-API's are not tree based -but use an interface which allows to open and close groups and datasets. This is sensible as HDF is designed +but use an interface which allows one to open and close groups and datasets. This is sensible as HDF is designed to support very large data sets which may not necessarily fit into a computers memory in one go. But this also implies that the current position in the hierarchy of a given NeXus file has to be maintained by the NeXus-API. Such information is maintained in a stack which is pushed an popped while moving through the hierarchy. This diff --git a/doc/api/napi.tex b/doc/api/napi.tex index 74d08343..7266ed0d 100644 --- a/doc/api/napi.tex +++ b/doc/api/napi.tex @@ -1167,7 +1167,7 @@ \subsubsection{NXgetnextentry} \end{flushleft} \subsubsection{NXgetnextattr} NXgetnextattr works very much like NXgetnextentry except, that it works on -SDS attributes and not on Vgroup entries. This function allows to scan the +SDS attributes and not on Vgroup entries. This function allows one to scan the names of attributes available. iLength will be filled with the length of the attributes data in byte. iType will be filled with the HDF type of the attribute. Be warned: this routine returns global attributes when no SDS is @@ -1407,7 +1407,7 @@ \subsubsection{NX error handling} because stdout is supported only in a very strange way. Think about operating system like MS-Windows, MAC-OS (going to die anyway) or other windowing systems. In order to cater for this there is an inofficial support -function which allows to set both a pointer to a datastructure and a new +function which allows one to set both a pointer to a datastructure and a new function for error reporting. This is called NXMSetError. \begin{flushleft} \small diff --git a/include/napi.h.in b/include/napi.h.in index 29725231..76f5e206 100644 --- a/include/napi.h.in +++ b/include/napi.h.in @@ -259,9 +259,9 @@ typedef struct { */ #if (defined(__GNUC__) || defined(__clang__)) -#define NEXUS_DEPRECATED_FUNCTION __attribute__((deprecated)) +#define NEXUS_DEPRECATED_FUNCTION(msg) __attribute__((deprecated(msg))) #else -#define NEXUS_DEPRECATED_FUNCTION +#define NEXUS_DEPRECATED_FUNCTION(msg) #endif #ifdef __cplusplus @@ -435,7 +435,7 @@ extern NXstatus NXcompmakedata64 (NXhandle handle, CONSTCHAR* label, int dataty * \li NX_COMP_HUF Huffmann encoding (only HDF-4) * \ingroup c_readwrite */ -extern NXstatus NXcompress (NXhandle handle, int compr_type) NEXUS_DEPRECATED_FUNCTION; +extern NXstatus NXcompress (NXhandle handle, int compr_type) NEXUS_DEPRECATED_FUNCTION(); /** * Open access to a dataset. After this call it is possible to write and read data or @@ -632,7 +632,7 @@ extern NXstatus NXgetslab64(NXhandle handle, void* data, const int64_t start[] * \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) NEXUS_DEPRECATED_FUNCTION; +extern NXstatus NXgetnextattr(NXhandle handle, NXname pName, int *iLength, int *iType) NEXUS_DEPRECATED_FUNCTION("Use NXgetnextattra instead"); /** * Read an attribute containing a single string or numerical value. @@ -878,7 +878,7 @@ extern NXstatus NXgetrawinfo64(NXhandle handle, int* rank, int64_t dimension[] /** \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 + * ErrFunc. The NeXus-API allows this error reporting function to be replaced * 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 diff --git a/src/napi4.c b/src/napi4.c index 9e03123f..63dbfa92 100644 --- a/src/napi4.c +++ b/src/napi4.c @@ -452,36 +452,47 @@ static int findNapiClass(pNexusFile pFile, int groupRef, NXname nxclass) * need to create global attributes file_name file_time NeXus_version * at some point for new files */ - if (am != NXACC_READ) { - if (SDsetattr(pNew->iSID, "NeXus_version", DFNT_CHAR8, strlen(NEXUS_VERSION), NEXUS_VERSION) < 0) { - NXReportError( "ERROR: HDF failed to store NeXus_version attribute "); - return NX_ERROR; - } - Hgetlibversion(&lmajor, &lminor, &lrelease, HDF_VERSION); - if (SDsetattr(pNew->iSID, "HDF_version", DFNT_CHAR8, strlen(HDF_VERSION), HDF_VERSION) < 0) { - NXReportError( "ERROR: HDF failed to store HDF_version attribute "); - return NX_ERROR; - } - } - - time_puffer = NXIformatNeXusTime(); if (am == NXACC_CREATE || am == NXACC_CREATE4) { - if (SDsetattr(pNew->iSID, "file_name", DFNT_CHAR8, strlen(filename), (char*)filename) < 0) { - NXReportError( "ERROR: HDF failed to store file_name attribute "); - return NX_ERROR; - } - if(time_puffer != NULL){ - if (SDsetattr(pNew->iSID, "file_time", DFNT_CHAR8, - strlen(time_puffer), time_puffer) < 0) { - NXReportError( - "ERROR: HDF failed to store file_time attribute "); - free(time_puffer); - return NX_ERROR; - } - } - } - if (time_puffer != NULL) { - free(time_puffer); + /* set the NeXus_version attribute*/ + if (SDsetattr(pNew->iSID, "NeXus_version", DFNT_CHAR8, + strlen(NEXUS_VERSION), NEXUS_VERSION) < 0) + { + NXReportError( "ERROR: HDF failed to store NeXus_version attribute "); + return NX_ERROR; + } + + /* set the HDF4 version attribute */ + Hgetlibversion(&lmajor, &lminor, &lrelease, HDF_VERSION); + if (SDsetattr(pNew->iSID, "HDF_version", DFNT_CHAR8, strlen(HDF_VERSION),HDF_VERSION) < 0) + { + NXReportError( "ERROR: HDF failed to store HDF_version attribute "); + return NX_ERROR; + } + + /* set the filename attribute */ + if (SDsetattr(pNew->iSID, "file_name", DFNT_CHAR8, strlen(filename), (char*)filename) < 0) + { + NXReportError( "ERROR: HDF failed to store file_name attribute "); + return NX_ERROR; + } + + /* set the file_time attribute */ + time_puffer = NXIformatNeXusTime(); + if(time_puffer != NULL){ + if (SDsetattr(pNew->iSID, "file_time", DFNT_CHAR8,strlen(time_puffer),time_puffer) < 0) + { + NXReportError("ERROR: HDF failed to store file_time attribute "); + free(time_puffer); + return NX_ERROR; + } + free(time_puffer); + } + + if (SDsetattr(pNew->iSID,"NX_class",DFNT_CHAR8,7,"NXroot")<0) + { + NXReportError("ERROR: HDF failed to store NX_class attribute "); + return NX_ERROR; + } } /* diff --git a/src/napi5.c b/src/napi5.c index fd4a1322..f7d43b31 100644 --- a/src/napi5.c +++ b/src/napi5.c @@ -233,28 +233,127 @@ NXstatus NX5reopen(NXhandle pOrigHandle, NXhandle * pNewHandle) return NX_OK; } + +/*--------------------------------------------------------------------- + * private functions used in NX5open + */ + +pNexusFile5 create_file_struct() +{ + pNexusFile5 pNew = (pNexusFile5) malloc(sizeof(NexusFile5)); + if (!pNew) { + NXReportError + ("ERROR: not enough memory to create file structure"); + } + else{ + memset(pNew, 0, sizeof(NexusFile5)); + } + + return pNew; +} + +hid_t create_file_access_plist(CONSTCHAR *filename) +{ + char pBuffer[512]; + hid_t fapl = -1; + + /* create file access property list - required in all cases*/ + if((fapl = H5Pcreate(H5P_FILE_ACCESS))<0){ + sprintf(pBuffer,"Error: failed to create file access property " + "list for file %s",filename); + NXReportError(pBuffer); + return fapl; + } + + /* set file close policy - need this in all cases*/ + if(H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG)<0){ + sprintf(pBuffer,"Error: cannot set close policy for file " + "%s",filename); + NXReportError(pBuffer); + return fapl; + } + + return fapl; +} + + +herr_t set_file_cache(hid_t fapl,CONSTCHAR *filename) +{ + char pBuffer[512]; + int mdc_nelmts; + size_t rdcc_nelmts; + size_t rdcc_nbytes; + double rdcc_w0; + herr_t error = -1; + + error = H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, + &rdcc_nbytes,&rdcc_w0); + + if(error < 0){ + sprintf(pBuffer,"Error: cannot obtain HDF5 cache size" + " for file %s",filename); + NXReportError(pBuffer); + return error; + } + + rdcc_nbytes = (size_t) nx_cacheSize; + error = H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes,rdcc_w0); + if(error < 0){ + sprintf(pBuffer,"Error: cannot set cache size " + "for file %s",filename); + NXReportError(pBuffer); + return error; + } + return error; +} + +herr_t set_str_attribute(hid_t parent_id,CONSTCHAR *name,CONSTCHAR *buffer) +{ + char pBuffer[512]; + hid_t attr_id; + hid_t space_id = H5Screate(H5S_SCALAR); + hid_t type_id = H5Tcopy(H5T_C_S1); + + H5Tset_size(type_id, strlen(buffer)); + + attr_id = H5Acreate(parent_id,name,type_id,space_id,H5P_DEFAULT, + H5P_DEFAULT); + if (attr_id < 0) { + sprintf(pBuffer,"ERROR: failed to create %s attribute",name); + NXReportError(pBuffer); + return -1; + } + + if(H5Awrite(attr_id,type_id,buffer) < 0) { + sprintf(pBuffer,"ERROR: failed writting %s attribute"); + NXReportError(pBuffer); + return -1; + } + + H5Tclose(type_id); + H5Sclose(space_id); + H5Aclose(attr_id); + + return 0; +} + NXstatus NX5open(CONSTCHAR * filename, NXaccess am, NXhandle * pHandle) { - hid_t attr1, aid1, aid2, iVID; + hid_t root_id; pNexusFile5 pNew = NULL; char pBuffer[512]; char *time_buffer = NULL; char version_nr[10]; unsigned int vers_major, vers_minor, vers_release, am1; hid_t fapl = -1; - int mdc_nelmts; - size_t rdcc_nelmts; - size_t rdcc_nbytes; - double rdcc_w0; - unsigned hdf5_majnum, hdf5_minnum, hdf5_relnum; *pHandle = NULL; - if (H5get_libversion(&hdf5_majnum, &hdf5_minnum, &hdf5_relnum) < 0) { + if (H5get_libversion(&vers_major, &vers_minor, &vers_release) < 0) { NXReportError("ERROR: cannot determine HDF5 library version"); return NX_ERROR; } - if (hdf5_majnum == 1 && hdf5_minnum < 8) { + if (vers_major == 1 && vers_minor < 8) { NXReportError("ERROR: HDF5 library 1.8.0 or higher required"); return NX_ERROR; } @@ -263,54 +362,26 @@ NXstatus NX5open(CONSTCHAR * filename, NXaccess am, NXhandle * pHandle) am = (NXaccess) (am & NXACCMASK_REMOVEFLAGS); /* turn off the automatic HDF error handling */ - H5Eset_auto(H5E_DEFAULT, NULL, NULL); + H5Eset_auto(H5E_DEFAULT, NULL, NULL); #ifdef USE_FTIME struct timeb timeb_struct; #endif - pNew = (pNexusFile5) malloc(sizeof(NexusFile5)); - if (!pNew) { - NXReportError - ("ERROR: not enough memory to create file structure"); - return NX_ERROR; - } - memset(pNew, 0, sizeof(NexusFile5)); - - /* create file access property list - required in all cases*/ - if((fapl = H5Pcreate(H5P_FILE_ACCESS))<0){ - sprintf(pBuffer,"Error: failed to create file access property " - "list for file %s",filename); - NXReportError(pBuffer); - free(pNew); - return NX_ERROR; - } - - /* set file close policy - need this in all cases*/ - if(H5Pset_fclose_degree(fapl, H5F_CLOSE_STRONG)<0){ - sprintf(pBuffer,"Error: cannot set close policy for file " - "%s",filename); - NXReportError(pBuffer); + /* create the new file structure */ + if(!(pNew = create_file_struct())) return NX_ERROR; + + /* create the file access property list*/ + if((fapl = create_file_access_plist(filename))<0) + { free(pNew); return NX_ERROR; } /* start HDF5 interface */ if (am == NXACC_CREATE5) { - if(H5Pget_cache(fapl, &mdc_nelmts, &rdcc_nelmts, &rdcc_nbytes, - &rdcc_w0) < 0){ - sprintf(pBuffer,"Error: cannot obtain HDF5 cache size" - " for file %s",filename); - NXReportError(pBuffer); - free(pNew); - return NX_ERROR; - } - - rdcc_nbytes = (size_t) nx_cacheSize; - if(H5Pset_cache(fapl, mdc_nelmts, rdcc_nelmts, rdcc_nbytes, - rdcc_w0) < 0){ - sprintf(pBuffer,"Error: cannot set cache size " - "for file %s",filename); - NXReportError(pBuffer); + + /* set the cache size for the file */ + if(set_file_cache(fapl,filename)<0) { free(pNew); return NX_ERROR; } @@ -327,7 +398,7 @@ NXstatus NX5open(CONSTCHAR * filename, NXaccess am, NXhandle * pHandle) if (fapl != -1) H5Pclose(fapl); /*close file access property list*/ if (pNew->iFID <= 0) { - sprintf(pBuffer, "ERROR: cannot open file: %s", filename); + snprintf(pBuffer,sizeof(pBuffer)-1, "ERROR: cannot open file: %s", filename); NXReportError(pBuffer); free(pNew); return NX_ERROR; @@ -337,108 +408,55 @@ NXstatus NX5open(CONSTCHAR * filename, NXaccess am, NXhandle * pHandle) * need to create global attributes file_name file_time NeXus_version * at some point for new files */ - if (am1 != H5F_ACC_RDONLY) { - iVID = H5Gopen(pNew->iFID, "/", H5P_DEFAULT); - aid2 = H5Screate(H5S_SCALAR); - aid1 = H5Tcopy(H5T_C_S1); - H5Tset_size(aid1, strlen(NEXUS_VERSION)); - if (am1 == H5F_ACC_RDWR) { - H5Adelete(iVID, "NeXus_version"); - } - attr1 = - H5Acreate(iVID, "NeXus_version", aid1, aid2, H5P_DEFAULT, - H5P_DEFAULT); - if (attr1 < 0) { - NXReportError - ("ERROR: failed to store NeXus_version attribute "); - return NX_ERROR; - } - if (H5Awrite(attr1, aid1, NEXUS_VERSION) < 0) { - NXReportError - ("ERROR: failed to store NeXus_version attribute "); - return NX_ERROR; - } - /* Close attribute dataspace */ - H5Tclose(aid1); - H5Sclose(aid2); - /* Close attribute */ - H5Aclose(attr1); - H5Gclose(iVID); - } - if (am1 == H5F_ACC_TRUNC) { - iVID = H5Gopen(pNew->iFID, "/", H5P_DEFAULT); - aid2 = H5Screate(H5S_SCALAR); - aid1 = H5Tcopy(H5T_C_S1); - H5Tset_size(aid1, strlen(filename)); - attr1 = - H5Acreate(iVID, "file_name", aid1, aid2, H5P_DEFAULT, - H5P_DEFAULT); - if (attr1 < 0) { - NXReportError - ("ERROR: failed to store file_name attribute "); - return NX_ERROR; - } - if (H5Awrite(attr1, aid1, (char *)filename) < 0) { - NXReportError - ("ERROR: failed to store file_name attribute "); - return NX_ERROR; - } - H5Tclose(aid1); - H5Sclose(aid2); - H5Aclose(attr1); - /* ------- library version ------ */ - H5get_libversion(&vers_major, &vers_minor, &vers_release); - sprintf(version_nr, "%d.%d.%d", vers_major, vers_minor, - vers_release); - aid2 = H5Screate(H5S_SCALAR); - aid1 = H5Tcopy(H5T_C_S1); - H5Tset_size(aid1, strlen(version_nr)); - attr1 = - H5Acreate(iVID, "HDF5_Version", aid1, aid2, H5P_DEFAULT, - H5P_DEFAULT); - if (attr1 < 0) { - NXReportError - ("ERROR: failed to store file_name attribute "); - return NX_ERROR; - } - if (H5Awrite(attr1, aid1, (char *)version_nr) < 0) { - NXReportError - ("ERROR: failed to store file_name attribute "); - return NX_ERROR; - } - H5Tclose(aid1); - H5Sclose(aid2); - H5Aclose(attr1); - /*----------- file time */ - time_buffer = NXIformatNeXusTime(); - if (time_buffer != NULL) { - aid2 = H5Screate(H5S_SCALAR); - aid1 = H5Tcopy(H5T_C_S1); - H5Tset_size(aid1, strlen(time_buffer)); - attr1 = - H5Acreate(iVID, "file_time", aid1, aid2, - H5P_DEFAULT, H5P_DEFAULT); - if (attr1 < 0) { - NXReportError - ("ERROR: failed to store file_time attribute "); - free(time_buffer); - return NX_ERROR; - } - if (H5Awrite(attr1, aid1, time_buffer) < 0) { - NXReportError - ("ERROR: failed to store file_time attribute "); - free(time_buffer); - return NX_ERROR; - } - /* Close attribute dataspace */ - H5Tclose(aid1); - H5Sclose(aid2); - /* Close attribute */ - H5Aclose(attr1); - free(time_buffer); - } - H5Gclose(iVID); - } + + if(am == NXACC_CREATE5) + { + root_id = H5Gopen(pNew->iFID,"/",H5P_DEFAULT); + if(set_str_attribute(root_id,"NeXus_version",NEXUS_VERSION)<0) { + H5Gclose(root_id); + H5Fclose(pNew->iFID); + free(pNew); + return NX_ERROR; + } + + if(set_str_attribute(root_id,"file_name",filename)<0) { + H5Gclose(root_id); + H5Fclose(pNew->iFID); + free(pNew); + return NX_ERROR; + } + + sprintf(version_nr,"%d.%d.%d",vers_major,vers_minor,vers_release); + if(set_str_attribute(root_id,"HDF5_Version",version_nr)<0) { + H5Gclose(root_id); + H5Fclose(pNew->iFID); + free(pNew); + return NX_ERROR; + } + + time_buffer = NXIformatNeXusTime(); + if (time_buffer != NULL){ + if(set_str_attribute(root_id,"file_time",time_buffer)<0) { + H5Gclose(root_id); + H5Fclose(pNew->iFID); + free(pNew); + free(time_buffer); + return NX_ERROR; + } + free(time_buffer); + } + + /*finally we set the NXroot NX_class attribute*/ + if(set_str_attribute(root_id,"NX_class","NXroot")<0) { + H5Gclose(root_id); + H5Fclose(pNew->iFID); + free(pNew); + return NX_ERROR; + } + + H5Gclose(root_id); + } + /* Set HDFgroup access mode */ if (am1 == H5F_ACC_RDONLY) { strcpy(pNew->iAccess, "r"); @@ -1067,7 +1085,7 @@ static hid_t getAttVID(pNexusFile5 pFile) } /*---------------------------------------------------------------*/ -static void killAttVID(pNexusFile5 pFile, int vid) +static void killAttVID(pNexusFile5 pFile, hid_t vid) { if (pFile->iCurrentG == 0 && pFile->iCurrentD == 0) { H5Gclose(vid); @@ -1082,7 +1100,6 @@ NXstatus NX5putattr(NXhandle fid, CONSTCHAR * name, const void *data, pNexusFile5 pFile; hid_t attr1, aid1, aid2; hid_t type; - hid_t attr_id; herr_t iRet; hid_t vid, attRet; @@ -1520,7 +1537,7 @@ static int countObjectsInGroup(hid_t loc_id) status = H5Gget_info(loc_id, &numobj); if (status < 0) { NXReportError - ("Internal error, failed to retrive no of objects"); + ("Internal error, failed to retrieve no of objects"); return 0; } @@ -2173,7 +2190,7 @@ NXstatus NX5getattr(NXhandle fid, const char *name, NXstatus NX5getattrinfo(NXhandle fid, int *iN) { pNexusFile5 pFile; - hid_t idx; + int idx; hid_t vid; H5O_info_t oinfo; @@ -2184,7 +2201,7 @@ NXstatus NX5getattrinfo(NXhandle fid, int *iN) vid = getAttVID(pFile); H5Oget_info(vid, &oinfo); - idx = (hid_t) oinfo.num_attrs; + idx = oinfo.num_attrs; if (idx > 0) { if (pFile->iCurrentG > 0 && pFile->iCurrentD == 0) { *iN = idx - 1; @@ -2492,6 +2509,8 @@ NXstatus NX5getnextattra(NXhandle handle, NXname pName, int *rank, int dim[], i /* skip NXclass attribute which is internal */ + free(iname); + iname = NULL; killAttVID(pFile, vid); return NX5getnextattra(handle, pName, rank, dim, iType); } diff --git a/src/nxxml.c b/src/nxxml.c index 230c6044..95318d98 100644 --- a/src/nxxml.c +++ b/src/nxxml.c @@ -182,6 +182,7 @@ NXstatus NXXopen(CONSTCHAR *filename, NXaccess am, current = mxmlNewElement(xmlHandle->root,"NXroot"); mxmlElementSetAttr(current,"NeXus_version",NEXUS_VERSION); mxmlElementSetAttr(current,"XML_version","mxml"); + mxmlElementSetAttr(current,"NX_class","NXroot"); mxmlElementSetAttr(current,"file_name",filename); mxmlElementSetAttr(current,"xmlns", NEXUS_SCHEMA_NAMESPACE); mxmlElementSetAttr(current,"xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); diff --git a/test/testsuite.at b/test/testsuite.at index 1de55ff6..d14f6a60 100644 --- a/test/testsuite.at +++ b/test/testsuite.at @@ -2222,55 +2222,55 @@ AT_BANNER([[Testing the NeXus File Converter.]]) AT_SETUP([Checking nxconvert HDF5 -> HDF5 ]) AT_CHECK([$HAVE_HDF5 && nxconvert --hdf 5 NXtest.h5 a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.h5 to HDF5 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert HDF5 -> HDF4 ]) AT_CHECK([skip_test && $HAVE_HDF5 && $HAVE_HDF4 && nxconvert --hdf 4 NXtest.h5 a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.h5 to HDF4 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert HDF5 -> XML ]) AT_CHECK([$HAVE_HDF5 && $HAVE_XML && nxconvert -x NXtest.h5 a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.h5 to XML NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert HDF4 -> HDF5 ]) AT_CHECK([$HAVE_HDF4 && $HAVE_HDF5 && nxconvert --hdf 5 NXtest.hdf a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.hdf to HDF5 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert HDF4 -> HDF4 ]) AT_CHECK([skip_test && $HAVE_HDF4 && nxconvert --hdf 4 NXtest.hdf a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.hdf to HDF4 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert HDF4 -> XML ]) AT_CHECK([$HAVE_HDF4 && $HAVE_XML && nxconvert -x NXtest.hdf a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.hdf to XML NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert XML -> HDF5 ]) AT_CHECK([$HAVE_XML && $HAVE_HDF5 && nxconvert --hdf 5 NXtest.xml a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.xml to HDF5 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert XML -> HDF4 ]) AT_CHECK([skip_test && $HAVE_XML && $HAVE_HDF4 && nxconvert --hdf 4 NXtest.xml a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.xml to HDF4 NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP AT_SETUP([Checking nxconvert XML -> XML ]) AT_CHECK([$HAVE_XML && nxconvert -x NXtest.xml a.a | sed -e 's/\r$//' ],[], [[Converting NXtest.xml to XML NeXus file a.a -Convertion successful. +Conversion successful. ]]) AT_CLEANUP