mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-12-22 20:35:44 +01:00
Merge pull request #78 from TREX-CoE/add-inquire-functionality
Add trexio_info function
This commit is contained in:
commit
d46d4adab8
@ -32,8 +32,25 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/config")
|
||||
else()
|
||||
message(FATAL_ERROR "EMACS not found. It is required to produce TREXIO source code from org-mode files.")
|
||||
endif()
|
||||
# in case Git is not available, we default to "unknown"
|
||||
set(GIT_HASH "unknown")
|
||||
# find Git and if available set GIT_HASH variable
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%H -n 1
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
# get the user name from the ${USER} env variable
|
||||
set(TREXIO_USER_NAME $ENV{USER})
|
||||
# replace placeholders in the templace config.h.in file to produce config.h
|
||||
# config.h is needed to insert TREXIO_PACKAGE_VERSION and TREXIO_GIT_HASH into trexio.h
|
||||
configure_file(${CMAKE_SOURCE_DIR}/include/cmake_config.h.in
|
||||
${CMAKE_SOURCE_DIR}/include/config.h)
|
||||
${CMAKE_SOURCE_DIR}/include/config.h
|
||||
@ONLY)
|
||||
endif()
|
||||
|
||||
# Set directories to be included at build time.
|
||||
|
@ -3,3 +3,5 @@
|
||||
#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||
#define VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||
#define VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||
#define GIT_HASH "@GIT_HASH@"
|
||||
#define TREXIO_USER_NAME "@TREXIO_USER_NAME@"
|
||||
|
@ -38,6 +38,8 @@ except:
|
||||
#============ WRITE THE DATA IN THE TEST FILE ============#
|
||||
#=========================================================#
|
||||
|
||||
trexio.info()
|
||||
|
||||
# create TREXIO file and open it for writing
|
||||
test_file = trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND)
|
||||
assert test_file.exists
|
||||
|
@ -1,4 +1,17 @@
|
||||
|
||||
# ============= THREADS SUPPORT ==============
|
||||
|
||||
# the two options below add preference for the pthread library over other system-wide threads implementations
|
||||
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
|
||||
# find thread library
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# ============= STDINT SUPPORT ===============
|
||||
|
||||
include(CheckIncludeFile)
|
||||
check_include_file(stdint.h HAVE_STDINT_H)
|
||||
|
||||
# ========= DEFINE TREXIO C LIBRARY =========
|
||||
|
||||
# Set a list of TREXIO source and header files that are always compiled.
|
||||
|
@ -4,18 +4,22 @@
|
||||
cat prefix_front.c > trexio.c
|
||||
cat prefix_front.h > trexio.h
|
||||
|
||||
# parse the config-defined version attributes to pass them to Fortran module file
|
||||
# parse the config-defined version attributes to pass them to the header files
|
||||
VERSION_VAL=`grep "PACKAGE_VERSION" ../../include/config.h | cut -d " " -f 3`
|
||||
VERSION_MAJOR_VAL=`grep "VERSION_MAJOR" ../../include/config.h | cut -d " " -f 3`
|
||||
VERSION_MINOR_VAL=`grep "VERSION_MINOR" ../../include/config.h | cut -d " " -f 3`
|
||||
VERSION_PATCH_VAL=`grep "VERSION_PATCH" ../../include/config.h | cut -d " " -f 3`
|
||||
|
||||
# parse the config-defined GIT_HASH to pass them to the header files
|
||||
GIT_HASH_STR=`grep "GIT_HASH" ../../include/config.h | cut -d " " -f 3`
|
||||
|
||||
# grep some usefull constants from the config.h
|
||||
echo "" >> trexio.h
|
||||
echo "#define TREXIO_PACKAGE_VERSION ${VERSION_VAL:='0.0.0'}" >> trexio.h
|
||||
echo "#define TREXIO_VERSION_MAJOR ${VERSION_MAJOR_VAL:=0}" >> trexio.h
|
||||
echo "#define TREXIO_VERSION_MINOR ${VERSION_MINOR_VAL:=0}" >> trexio.h
|
||||
echo "#define TREXIO_VERSION_PATCH ${VERSION_PATCH_VAL:=0}" >> trexio.h
|
||||
echo "#define TREXIO_GIT_HASH ${GIT_HASH_STR:='0000'}" >> trexio.h
|
||||
echo "" >> trexio.h
|
||||
|
||||
cat prefix_s_front.h > trexio_s.h
|
||||
@ -24,10 +28,11 @@ cat prefix_python.py > trexio.py
|
||||
|
||||
# append version string and attributes to the Fortran module file
|
||||
echo "" >> trexio_f.f90
|
||||
echo "character(len = 12) :: TREXIO_PACKAGE_VERSION = ${VERSION_VAL}" >> trexio_f.f90
|
||||
echo "character(len = 12) :: TREXIO_PACKAGE_VERSION = ${VERSION_VAL:='0.0.0'}" >> trexio_f.f90
|
||||
echo "integer :: TREXIO_VERSION_MAJOR = ${VERSION_MAJOR_VAL}" >> trexio_f.f90
|
||||
echo "integer :: TREXIO_VERSION_MINOR = ${VERSION_MINOR_VAL}" >> trexio_f.f90
|
||||
echo "integer :: TREXIO_VERSION_PATCH = ${VERSION_PATCH_VAL}" >> trexio_f.f90
|
||||
echo "character(len = 64) :: TREXIO_GIT_HASH = ${GIT_HASH_STR:='0000'}" >> trexio_f.f90
|
||||
echo "" >> trexio_f.f90
|
||||
|
||||
# c front end
|
||||
|
@ -1201,6 +1201,18 @@ def _close(trexio_file):
|
||||
output:
|
||||
~trexio_exit_code~ exit code.
|
||||
|
||||
It returns:
|
||||
|
||||
- ~TREXIO_SUCCESS~ if the ~file_name~ exists and if it correspond to a valid TREXIO file (i.e. a directory OR an HDF5 file)
|
||||
- ~TREXIO_FILE_ERROR~ if ~file_name~ exists but it is not a TREXIO file
|
||||
- ~TREXIO_FAILURE~ otherwise
|
||||
|
||||
Also, there is an implicit way to have the aforementioned functionality.
|
||||
Attempt to open a non-existing file with ~trexio_open~ function will result in a ~TREXIO_OPEN_ERROR~ exit code
|
||||
(see the modified value that has been passed as a 4-th argument to ~trexio_open~).
|
||||
|
||||
You can see examples of both functionalities in =test_f.f90= (search for calls with ~_void~ suffix).
|
||||
|
||||
*** C
|
||||
|
||||
#+begin_src c :tangle prefix_front.h :exports none
|
||||
@ -1387,6 +1399,7 @@ trexio_exit_code
|
||||
trexio_read_$group_num$_64 (trexio_t* const file, $group_num_dtype_double$* const num)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (num == NULL) return TREXIO_INVALID_ARG_2;
|
||||
if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
|
||||
|
||||
switch (file->back_end) {
|
||||
@ -1446,6 +1459,7 @@ trexio_exit_code
|
||||
trexio_read_$group_num$_32 (trexio_t* const file, $group_num_dtype_single$* const num)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (num == NULL) return TREXIO_INVALID_ARG_2;
|
||||
if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
|
||||
|
||||
$group_num_dtype_double$ num_64 = 0;
|
||||
@ -2670,6 +2684,7 @@ trexio_exit_code
|
||||
trexio_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max)
|
||||
{
|
||||
if (file == NULL) return TREXIO_INVALID_ARG_1;
|
||||
if (size_max == NULL) return TREXIO_INVALID_ARG_2;
|
||||
if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
|
||||
|
||||
switch (file->back_end) {
|
||||
@ -3894,6 +3909,70 @@ def has_$group_str$(trexio_file) -> bool:
|
||||
return False
|
||||
#+end_src
|
||||
|
||||
* General helper functions
|
||||
|
||||
This section contains general helper functions like ~trexio_info~.
|
||||
|
||||
~trexio_info~ prints information about the TREXIO configuration (see =config.h= file).
|
||||
In particular:
|
||||
|
||||
1) ~TREXIO_PACKAGE_VERSION~ [string]
|
||||
2) ~HAVE_HDF5~ [bool]
|
||||
3) ~HDF5_VERSION~ [string] (optional, only if ~HAVE_HDF5~ is ~true~)
|
||||
4) ~TREXIO_GIT_HASH~ [string]
|
||||
|
||||
** C
|
||||
|
||||
#+begin_src c :tangle prefix_front.h :exports none
|
||||
trexio_exit_code trexio_info(void);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle prefix_front.c
|
||||
trexio_exit_code
|
||||
trexio_info (void)
|
||||
{
|
||||
printf("TREXIO_PACKAGE_VERSION : %s\n", TREXIO_PACKAGE_VERSION);
|
||||
|
||||
#ifdef TREXIO_GIT_HASH
|
||||
printf("TREXIO_GIT_HASH : %s\n", TREXIO_GIT_HASH);
|
||||
#else
|
||||
printf("GIT_HASH is stored in the config.h file, which is missing.");
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_HDF5
|
||||
printf("HAVE_HDF5 : true\n");
|
||||
printf("%s\n", H5_VERS_INFO);
|
||||
#else
|
||||
printf("HAVE_HDF5 : false\n");
|
||||
printf("TREXIO configured without the HDF5 library\n");
|
||||
#endif
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** Fortran
|
||||
|
||||
#+begin_src f90 :tangle prefix_fortran.f90
|
||||
interface
|
||||
integer function trexio_info () bind(C)
|
||||
use, intrinsic :: iso_c_binding
|
||||
end function trexio_info
|
||||
end interface
|
||||
#+end_src
|
||||
|
||||
** Python
|
||||
|
||||
#+begin_src python :tangle basic_python.py
|
||||
def info():
|
||||
"""Print the info about the installed TREXIO library.
|
||||
"""
|
||||
|
||||
rc = pytr.trexio_info()
|
||||
if rc != TREXIO_SUCCESS:
|
||||
raise Error(rc)
|
||||
#+end_src
|
||||
|
||||
* Fortran helper/wrapper functions
|
||||
|
||||
The function below adapts the original C-based ~trexio_open~ for Fortran.
|
||||
|
@ -14,6 +14,8 @@ int main() {
|
||||
|
||||
int rc;
|
||||
|
||||
trexio_info();
|
||||
|
||||
bool have_hdf5 = trexio_has_backend(TREXIO_HDF5);
|
||||
if(have_hdf5) {
|
||||
rc = system("rm -f -- test_all.h5");
|
||||
@ -223,5 +225,3 @@ int test_read(const char* file_name, const back_end_t backend) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ program test_trexio
|
||||
use, intrinsic :: iso_c_binding
|
||||
implicit none
|
||||
|
||||
integer :: rc
|
||||
logical :: have_hdf5
|
||||
|
||||
print * , "============================================"
|
||||
@ -11,6 +12,8 @@ program test_trexio
|
||||
print'(a,i3)', " TREXIO MINOR VERSION : ", TREXIO_VERSION_MINOR
|
||||
print * , "============================================"
|
||||
|
||||
rc = trexio_info()
|
||||
|
||||
call system('rm -rf -- test_write_f.dir')
|
||||
print *, 'call test_write(''test_write_f.dir'', TREXIO_TEXT)'
|
||||
call test_write('test_write_f.dir', TREXIO_TEXT)
|
||||
|
Loading…
Reference in New Issue
Block a user