From 241ae3a74a83b23c82064aba294b31e3bc1c3df8 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 18 Mar 2021 17:30:48 +0100 Subject: [PATCH] Little changes in the bash script --- src/build_trex.sh | 28 +- src/trexio.c | 1505 ++++++++++++++++++++++++----- src/trexio.h | 70 +- src/trexio_hdf5.c | 1524 +++++++++++++++++++++++------- src/trexio_hdf5.h | 104 +- src/trexio_s.h | 4 - src/trexio_text.c | 2306 ++++++++++++++++++++++++++++++++++++++++----- src/trexio_text.h | 110 ++- 8 files changed, 4709 insertions(+), 942 deletions(-) mode change 100644 => 100755 src/build_trex.sh diff --git a/src/build_trex.sh b/src/build_trex.sh old mode 100644 new mode 100755 index 7af6989..ccbc06e --- a/src/build_trex.sh +++ b/src/build_trex.sh @@ -1,22 +1,30 @@ #!/bin/bash +if [[ $(basename $PWD) != "src" ]] ; then + echo "This script should run in the src directory" + exit -1 +fi + +# We want the script to crash on the 1st error: +set -e + echo "create populated directories" mkdir -p templates_front/populated mkdir -p templates_text/populated mkdir -p templates_hdf5/populated +# It is important to ad '--' to rm because it tells rm that what follows are +# not options. It is safer. + echo "remove existing templates" -rm templates_front/*.c -rm templates_text/*.c -rm templates_hdf5/*.c -rm templates_front/*.h -rm templates_text/*.h -rm templates_hdf5/*.h +rm -- templates_front/*.{c,h} +rm -- templates_text/*.{c,h} +rm -- templates_hdf5/*.{c,h} echo "clean populated directories" -rm templates_front/populated/* -rm templates_text/populated/* -rm templates_hdf5/populated/* +rm -- templates_front/populated/* +rm -- templates_text/populated/* +rm -- templates_hdf5/populated/* echo "tangle org files to generate templates" cd templates_front @@ -32,7 +40,7 @@ emacs --batch --eval "(require 'org)" --eval '(org-babel-tangle-file "templator_ cd .. echo "run generator script to populate templates" -python generator.py +python3 generator.py sleep 2 diff --git a/src/trexio.c b/src/trexio.c index 9f86ab7..334878f 100644 --- a/src/trexio.c +++ b/src/trexio.c @@ -3,8 +3,6 @@ M-x org-babel-tangle */ - - #include #include #include @@ -53,7 +51,7 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b /* Data for the parent type */ - result->file_name = CALLOC(strlen(file_name)+1,char); + result->file_name = (char*) calloc(strlen(file_name)+1,sizeof(char)); strcpy(result->file_name, file_name); result->back_end = back_end; result->mode = mode; @@ -83,8 +81,8 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b } if (rc != TREXIO_SUCCESS) { - FREE(result->file_name); - FREE(result); + free(result->file_name); + free(result); return NULL; } @@ -109,8 +107,8 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b } if (rc != TREXIO_SUCCESS) { - FREE(result->file_name); - FREE(result); + free(result->file_name); + free(result); return NULL; } @@ -143,8 +141,8 @@ trexio_exit_code trexio_close(trexio_t* file) { } if (rc != TREXIO_SUCCESS) { - FREE(file->file_name); - FREE(file); + free(file->file_name); + free(file); return TREXIO_FAILURE; } @@ -170,18 +168,624 @@ trexio_exit_code trexio_close(trexio_t* file) { /* Terminate front end */ - FREE(file->file_name); + free(file->file_name); + file->file_name = NULL; int irc = pthread_mutex_destroy( &(file->thread_lock) ); - FREE(file); + free(file); if (irc != 0) return TREXIO_ERRNO; if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; return TREXIO_SUCCESS; } +trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* nucleus_charge) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_charge == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_nucleus_charge(file, nucleus_charge, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_charge(file, nucleus_charge, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_nucleus_charge(file, nucleus_charge); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* nucleus_coord) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_coord == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, 3}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_nucleus_coord(file, nucleus_coord, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_coord(file, nucleus_coord, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_nucleus_coord(file, nucleus_coord); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_lmax_plus_1(trexio_t* file, int64_t* ecp_lmax_plus_1) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_lmax_plus_1 == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_lmax_plus_1(file, ecp_lmax_plus_1, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_lmax_plus_1(file, ecp_lmax_plus_1, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_lmax_plus_1(file, ecp_lmax_plus_1); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_z_core(trexio_t* file, int64_t* ecp_z_core) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_z_core == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_z_core(file, ecp_z_core, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_z_core(file, ecp_z_core, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_z_core(file, ecp_z_core); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_local_n(trexio_t* file, int64_t* ecp_local_n) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_n == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_local_n(file, ecp_local_n, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_local_n(file, ecp_local_n, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_local_n(file, ecp_local_n); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_local_exponent(trexio_t* file, double* ecp_local_exponent) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_local_exponent(file, ecp_local_exponent, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_local_exponent(file, ecp_local_exponent, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_local_exponent(file, ecp_local_exponent); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_local_coef(trexio_t* file, double* ecp_local_coef) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_local_coef(file, ecp_local_coef, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_local_coef(file, ecp_local_coef, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_local_coef(file, ecp_local_coef); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_local_power(trexio_t* file, int64_t* ecp_local_power) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_power == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_local_power(file, ecp_local_power, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_local_power(file, ecp_local_power, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_local_power(file, ecp_local_power); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_non_local_n(trexio_t* file, int64_t* ecp_non_local_n) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_n == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_non_local_n(file, ecp_non_local_n, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_non_local_n(file, ecp_non_local_n, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_non_local_n(file, ecp_non_local_n); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_non_local_exponent(trexio_t* file, double* ecp_non_local_exponent) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_non_local_exponent(file, ecp_non_local_exponent, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_non_local_exponent(file, ecp_non_local_exponent, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_non_local_exponent(file, ecp_non_local_exponent); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_non_local_coef(trexio_t* file, double* ecp_non_local_coef) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_non_local_coef(file, ecp_non_local_coef, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_non_local_coef(file, ecp_non_local_coef, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_non_local_coef(file, ecp_non_local_coef); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_read_ecp_non_local_power(trexio_t* file, int64_t* ecp_non_local_power) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_power == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_ecp_non_local_power(file, ecp_non_local_power, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_ecp_non_local_power(file, ecp_non_local_power, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_read_ecp_non_local_power(file, ecp_non_local_power); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} trexio_exit_code trexio_read_nucleus_num(trexio_t* file, int64_t* num) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -209,7 +813,642 @@ trexio_exit_code trexio_read_nucleus_num(trexio_t* file, int64_t* num) { /**/ *num = (int64_t) u_num; return TREXIO_SUCCESS; } +trexio_exit_code trexio_read_ecp_local_num_n_max(trexio_t* file, int64_t* num) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + uint64_t u_num = 0; + trexio_exit_code rc = TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_ecp_local_num_n_max(file, &u_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &u_num); + break; +/* + case TREXIO_JSON: + rc =trexio_json_read_ecp_local_num_n_max(file, &u_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + /**/ *num = (int64_t) u_num; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_read_ecp_non_local_num_n_max(trexio_t* file, int64_t* num) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + + uint64_t u_num = 0; + trexio_exit_code rc = TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_ecp_non_local_num_n_max(file, &u_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &u_num); + break; +/* + case TREXIO_JSON: + rc =trexio_json_read_ecp_non_local_num_n_max(file, &u_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + + /**/ *num = (int64_t) u_num; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* nucleus_charge) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_charge == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_nucleus_charge(file, nucleus_charge, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_charge(file, nucleus_charge, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_nucleus_charge(file, nucleus_charge); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* nucleus_coord) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_coord == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, 3}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_nucleus_coord(file, nucleus_coord, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_coord(file, nucleus_coord, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_nucleus_coord(file, nucleus_coord); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_lmax_plus_1(trexio_t* file, const int64_t* ecp_lmax_plus_1) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_lmax_plus_1 == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_lmax_plus_1(file, ecp_lmax_plus_1, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_lmax_plus_1(file, ecp_lmax_plus_1, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_lmax_plus_1(file, ecp_lmax_plus_1); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_z_core(trexio_t* file, const int64_t* ecp_z_core) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_z_core == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_z_core(file, ecp_z_core, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_z_core(file, ecp_z_core, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_z_core(file, ecp_z_core); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_local_n(trexio_t* file, const int64_t* ecp_local_n) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_n == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_local_n(file, ecp_local_n, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_local_n(file, ecp_local_n, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_local_n(file, ecp_local_n); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_local_exponent(trexio_t* file, const double* ecp_local_exponent) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_local_exponent(file, ecp_local_exponent, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_local_exponent(file, ecp_local_exponent, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_local_exponent(file, ecp_local_exponent); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_local_coef(trexio_t* file, const double* ecp_local_coef) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_local_coef(file, ecp_local_coef, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_local_coef(file, ecp_local_coef, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_local_coef(file, ecp_local_coef); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_local_power(trexio_t* file, const int64_t* ecp_local_power) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_power == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_local_num_n_max(file, &ecp_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_local_power(file, ecp_local_power, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_local_power(file, ecp_local_power, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_local_power(file, ecp_local_power); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_non_local_n(trexio_t* file, const int64_t* ecp_non_local_n) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_n == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 1; + uint64_t dims[1] = {nucleus_num}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_non_local_n(file, ecp_non_local_n, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_non_local_n(file, ecp_non_local_n, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_non_local_n(file, ecp_non_local_n); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_non_local_exponent(trexio_t* file, const double* ecp_non_local_exponent) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_non_local_exponent(file, ecp_non_local_exponent, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_non_local_exponent(file, ecp_non_local_exponent, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_non_local_exponent(file, ecp_non_local_exponent); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_non_local_coef(trexio_t* file, const double* ecp_non_local_coef) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_non_local_coef(file, ecp_non_local_coef, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_non_local_coef(file, ecp_non_local_coef, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_non_local_coef(file, ecp_non_local_coef); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} +trexio_exit_code trexio_write_ecp_non_local_power(trexio_t* file, const int64_t* ecp_non_local_power) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_power == NULL) return TREXIO_INVALID_ARG_2; + + trexio_exit_code rc; + uint64_t nucleus_num = -1; + uint64_t ecp_non_local_num_n_max = -1; + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_read_nucleus_num(file, &nucleus_num); + rc = trexio_text_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_read_nucleus_num(file, &nucleus_num); + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +/* + case TREXIO_JSON: + rc = trexio_json_read_nucleus_num(file, &nucleus_num); + rc = trexio_json_read_ecp_non_local_num_n_max(file, &ecp_non_local_num_n_max); + break; +*/ + } + + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + uint32_t rank = 2; + uint64_t dims[2] = {nucleus_num, ecp_non_local_num_n_max}; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_ecp_non_local_power(file, ecp_non_local_power, rank, dims); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_ecp_non_local_power(file, ecp_non_local_power, rank, dims); + break; +/* + case TREXIO_JSON: + return trexio_json_write_ecp_non_local_power(file, ecp_non_local_power); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} trexio_exit_code trexio_write_nucleus_num(trexio_t* file, const int64_t num) { if (file == NULL) return TREXIO_INVALID_ARG_1; if (num < 0 ) return TREXIO_INVALID_ARG_2; @@ -235,233 +1474,53 @@ trexio_exit_code trexio_write_nucleus_num(trexio_t* file, const int64_t num) { return TREXIO_SUCCESS; } +trexio_exit_code trexio_write_ecp_local_num_n_max(trexio_t* file, const int64_t num) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (num < 0 ) return TREXIO_INVALID_ARG_2; -trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (coord == NULL) return TREXIO_INVALID_ARG_2; + trexio_exit_code rc = TREXIO_FAILURE; - int64_t nucleus_num = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num); + switch (file->back_end) { + + case TREXIO_TEXT: + rc = trexio_text_write_ecp_local_num_n_max(file, (uint64_t) num); + break; + + case TREXIO_HDF5: + rc = trexio_hdf5_write_ecp_local_num_n_max(file, (uint64_t) num); + break; +/* + case TREXIO_JSON: + rc = trexio_json_write_ecp_local_num_n_max(file, (uint64_t) num); + break; +*/ + } if (rc != TREXIO_SUCCESS) return rc; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_write_ecp_non_local_num_n_max(trexio_t* file, const int64_t num) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (num < 0 ) return TREXIO_INVALID_ARG_2; - uint32_t rank = 2; - uint64_t dims[2] = {nucleus_num, 3}; + trexio_exit_code rc = TREXIO_FAILURE; switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_nucleus_coord(file, coord, rank, dims); + rc = trexio_text_write_ecp_non_local_num_n_max(file, (uint64_t) num); break; case TREXIO_HDF5: - return trexio_hdf5_read_nucleus_coord(file, coord, rank, dims); + rc = trexio_hdf5_write_ecp_non_local_num_n_max(file, (uint64_t) num); break; /* case TREXIO_JSON: - return trexio_json_read_nucleus_coord(file, coord); + rc = trexio_json_write_ecp_non_local_num_n_max(file, (uint64_t) num); break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ +*/ } -} - -trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* coord) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (coord == NULL) return TREXIO_INVALID_ARG_2; - - int64_t nucleus_num = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num); if (rc != TREXIO_SUCCESS) return rc; - - uint32_t rank = 2; - uint64_t dims[2] = {nucleus_num, 3}; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_write_nucleus_coord(file, coord, rank, dims); - break; - - case TREXIO_HDF5: - return trexio_hdf5_write_nucleus_coord(file, coord, rank, dims); - break; -/* - case TREXIO_JSON: - return trexio_json_write_nucleus_coord(file, coord); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (charge == NULL) return TREXIO_INVALID_ARG_2; - - int64_t nucleus_num = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num); - if (rc != TREXIO_SUCCESS) return rc; - - uint32_t rank = 1; - uint64_t dims[1] = {nucleus_num}; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_read_nucleus_charge(file, charge, rank, dims); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_read_nucleus_charge(file, charge); - break; - - case TREXIO_JSON: - return trexio_json_read_nucleus_charge(file, charge); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* charge) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (charge == NULL) return TREXIO_INVALID_ARG_2; - - int64_t nucleus_num = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num); - if (rc != TREXIO_SUCCESS) return rc; - - uint32_t rank = 1; - uint64_t dims[1] = {nucleus_num}; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_write_nucleus_charge(file, charge, rank, dims); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_write_nucleus_charge(file, charge); - break; - - case TREXIO_JSON: - return trexio_json_write_nucleus_charge(file, charge); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_read_rdm_one_e(trexio_t* file, double* one_e) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (one_e == NULL) return TREXIO_INVALID_ARG_2; - - int64_t dim_one_e = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &dim_one_e); /* This dimension is wrong. Should be mo_num */ - if (rc != TREXIO_SUCCESS) return rc; - if (dim_one_e < 0) return TREXIO_FAILURE; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_read_rdm_one_e(file, one_e, (uint64_t) dim_one_e); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_read_rdm_one_e(file, one_e); - break; - - case TREXIO_JSON: - return trexio_json_read_rdm_one_e(file, one_e); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_write_rdm_one_e(trexio_t* file, const double* one_e) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (one_e == NULL) return TREXIO_INVALID_ARG_2; - - int64_t nucleus_num = -1; - trexio_exit_code rc = trexio_read_nucleus_num(file, &nucleus_num); - if (rc != TREXIO_SUCCESS) return rc; - - int64_t dim_one_e = nucleus_num * nucleus_num; /* This dimension is wrong. Should be mo_num */ - if (dim_one_e < 0) return TREXIO_FAILURE; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_write_rdm_one_e(file, one_e, (uint64_t) dim_one_e); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_write_rdm_one_e(file, one_e); - break; - - case TREXIO_JSON: - return trexio_json_write_rdm_one_e(file, one_e); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_buffered_read_rdm_two_e(trexio_t* file, const int64_t offset, const int64_t size, int64_t* index, double* value) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (offset <= 0 ) return TREXIO_INVALID_ARG_2; - if (size <= 0 ) return TREXIO_INVALID_ARG_3; - if (index == NULL) return TREXIO_INVALID_ARG_4; - if (value == NULL) return TREXIO_INVALID_ARG_5; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_buffered_read_rdm_two_e(file, (uint64_t) offset, (uint64_t) size, index, value); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_buffered_read_rdm_two_e(file, size); - break; - - case TREXIO_JSON: - return trexio_json_buffered_read_rdm_two_e(file, size); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } -} - -trexio_exit_code trexio_buffered_write_rdm_two_e(trexio_t* file, const int64_t offset, const int64_t size, const int64_t* index, const double* value) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (offset <= 0 ) return TREXIO_INVALID_ARG_2; - if (size <= 0 ) return TREXIO_INVALID_ARG_3; - if (index == NULL) return TREXIO_INVALID_ARG_4; - if (value == NULL) return TREXIO_INVALID_ARG_5; - - switch (file->back_end) { - - case TREXIO_TEXT: - return trexio_text_buffered_write_rdm_two_e(file, (uint64_t) offset, (uint64_t) size, index, value); - break; -/* - case TREXIO_HDF5: - return trexio_hdf5_buffered_write_rdm_two_e(file, size); - break; - - case TREXIO_JSON: - return trexio_json_buffered_write_rdm_two_e(file, size); - break; -*/ - default: - return TREXIO_FAILURE; /* Impossible case */ - } + + return TREXIO_SUCCESS; } diff --git a/src/trexio.h b/src/trexio.h index 79940e6..a8f4b4e 100644 --- a/src/trexio.h +++ b/src/trexio.h @@ -3,8 +3,6 @@ M-x org-babel-tangle */ - - #ifndef _TREXIO_H #define _TREXIO_H @@ -12,19 +10,19 @@ typedef int32_t trexio_exit_code; -#define TREXIO_FAILURE ( (trexio_exit_code) -1 ) -#define TREXIO_SUCCESS ( (trexio_exit_code) 0 ) -#define TREXIO_INVALID_ARG_1 ( (trexio_exit_code) 1 ) -#define TREXIO_INVALID_ARG_2 ( (trexio_exit_code) 2 ) -#define TREXIO_INVALID_ARG_3 ( (trexio_exit_code) 3 ) -#define TREXIO_INVALID_ARG_4 ( (trexio_exit_code) 4 ) -#define TREXIO_INVALID_ARG_5 ( (trexio_exit_code) 5 ) -#define TREXIO_END ( (trexio_exit_code) 10 ) -#define TREXIO_READONLY ( (trexio_exit_code) 11 ) -#define TREXIO_ERRNO ( (trexio_exit_code) 12 ) -#define TREXIO_INVALID_ID ( (trexio_exit_code) 20 ) -#define TREXIO_ALLOCATION_FAILED ( (trexio_exit_code) 21 ) -#define TREXIO_INVALID_NUM ( (trexio_exit_code) 22 ) +#define TREXIO_FAILURE ( (trexio_exit_code) -1 ) +#define TREXIO_SUCCESS ( (trexio_exit_code) 0 ) +#define TREXIO_INVALID_ARG_1 ( (trexio_exit_code) 1 ) +#define TREXIO_INVALID_ARG_2 ( (trexio_exit_code) 2 ) +#define TREXIO_INVALID_ARG_3 ( (trexio_exit_code) 3 ) +#define TREXIO_INVALID_ARG_4 ( (trexio_exit_code) 4 ) +#define TREXIO_INVALID_ARG_5 ( (trexio_exit_code) 5 ) +#define TREXIO_END ( (trexio_exit_code) 10 ) +#define TREXIO_READONLY ( (trexio_exit_code) 11 ) +#define TREXIO_ERRNO ( (trexio_exit_code) 12 ) +#define TREXIO_INVALID_ID ( (trexio_exit_code) 20 ) +#define TREXIO_ALLOCATION_FAILED ( (trexio_exit_code) 21 ) +#define TREXIO_INVALID_NUM ( (trexio_exit_code) 22 ) typedef int32_t back_end_t; @@ -38,20 +36,34 @@ typedef struct trexio_s trexio_t; trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end); trexio_exit_code trexio_close(trexio_t* file); - +trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* nucleus_charge); +trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* nucleus_charge); +trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* nucleus_coord); +trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* nucleus_coord); +trexio_exit_code trexio_read_ecp_lmax_plus_1(trexio_t* file, int64_t* ecp_lmax_plus_1); +trexio_exit_code trexio_write_ecp_lmax_plus_1(trexio_t* file, const int64_t* ecp_lmax_plus_1); +trexio_exit_code trexio_read_ecp_z_core(trexio_t* file, int64_t* ecp_z_core); +trexio_exit_code trexio_write_ecp_z_core(trexio_t* file, const int64_t* ecp_z_core); +trexio_exit_code trexio_read_ecp_local_n(trexio_t* file, int64_t* ecp_local_n); +trexio_exit_code trexio_write_ecp_local_n(trexio_t* file, const int64_t* ecp_local_n); +trexio_exit_code trexio_read_ecp_local_exponent(trexio_t* file, double* ecp_local_exponent); +trexio_exit_code trexio_write_ecp_local_exponent(trexio_t* file, const double* ecp_local_exponent); +trexio_exit_code trexio_read_ecp_local_coef(trexio_t* file, double* ecp_local_coef); +trexio_exit_code trexio_write_ecp_local_coef(trexio_t* file, const double* ecp_local_coef); +trexio_exit_code trexio_read_ecp_local_power(trexio_t* file, int64_t* ecp_local_power); +trexio_exit_code trexio_write_ecp_local_power(trexio_t* file, const int64_t* ecp_local_power); +trexio_exit_code trexio_read_ecp_non_local_n(trexio_t* file, int64_t* ecp_non_local_n); +trexio_exit_code trexio_write_ecp_non_local_n(trexio_t* file, const int64_t* ecp_non_local_n); +trexio_exit_code trexio_read_ecp_non_local_exponent(trexio_t* file, double* ecp_non_local_exponent); +trexio_exit_code trexio_write_ecp_non_local_exponent(trexio_t* file, const double* ecp_non_local_exponent); +trexio_exit_code trexio_read_ecp_non_local_coef(trexio_t* file, double* ecp_non_local_coef); +trexio_exit_code trexio_write_ecp_non_local_coef(trexio_t* file, const double* ecp_non_local_coef); +trexio_exit_code trexio_read_ecp_non_local_power(trexio_t* file, int64_t* ecp_non_local_power); +trexio_exit_code trexio_write_ecp_non_local_power(trexio_t* file, const int64_t* ecp_non_local_power); trexio_exit_code trexio_read_nucleus_num(trexio_t* file, int64_t* num); trexio_exit_code trexio_write_nucleus_num(trexio_t* file, const int64_t num); - -trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord); -trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, const double* coord); - -trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge); -trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, const double* charge); - -trexio_exit_code trexio_read_rdm_one_e(trexio_t* file, double* one_e); -trexio_exit_code trexio_write_rdm_one_e(trexio_t* file, const double* one_e); - -trexio_exit_code trexio_buffered_read_rdm_two_e(trexio_t* file, const int64_t offset, const int64_t size, int64_t* index, double* value); -trexio_exit_code trexio_buffered_write_rdm_two_e(trexio_t* file, const int64_t offset, const int64_t size, const int64_t* index, const double* value); - +trexio_exit_code trexio_read_ecp_local_num_n_max(trexio_t* file, int64_t* num); +trexio_exit_code trexio_write_ecp_local_num_n_max(trexio_t* file, const int64_t num); +trexio_exit_code trexio_read_ecp_non_local_num_n_max(trexio_t* file, int64_t* num); +trexio_exit_code trexio_write_ecp_non_local_num_n_max(trexio_t* file, const int64_t num); #endif diff --git a/src/trexio_hdf5.c b/src/trexio_hdf5.c index 1e1b2dc..07eb411 100644 --- a/src/trexio_hdf5.c +++ b/src/trexio_hdf5.c @@ -1,68 +1,26 @@ -/* This file was generated from the trexio.org org-mode file. - To generate it, open trexio.org in Emacs and execute +/* This file was generated from the org-mode file. + To generate it, open templator_hdf5.org file in Emacs and execute M-x org-babel-tangle */ - - #include "trexio_hdf5.h" - - #define NUCLEUS_GROUP_NAME "nucleus" - #define NUCLEUS_NUM_NAME "nucleus_num" - #define NUCLEUS_CHARGE_NAME "nucleus_charge" - #define NUCLEUS_COORD_NAME "nucleus_coord" - -/* - * Currently H5LTread_dataset_ is used instead of this function - * but keep it for later if we decide to get rid of the H5LT API - */ -dset_t* trexio_hdf5_read_dset_low(const trexio_hdf5_t* file, const char *dset_name, void *buf) { - - assert (file != NULL); - assert (dset_name != NULL); - assert (buf != NULL); - /* - * Low-level implementation. Involves dealing with all HDF5 handles and dimensions - */ - dset_t* dset = MALLOC(dset_t); - assert (dset != NULL); - - dset->dset_id = H5Dopen(file->nucleus_group, - dset_name, - H5P_DEFAULT); - assert (dset->dset_id > 0); - /* - * Get dataspace, datatype and dimensions - * dspace and dtype handles created below have to be closed when not used - */ - dset->dspace_id = H5Dget_space(dset->dset_id); - assert (dset->dspace_id > 0); - - dset->dtype_id = H5Dget_type(dset->dset_id); - assert (dset->dtype_id > 0); - - /* Check dimensions. Usefull, but then additional parameters - * ranks and dims[] have to be passed to the function - int rrank; - const int rank = 1; - hsize_t dims[1] = {0}; - rrank = H5Sget_simple_extent_dims(nucleus->h5_charge->dspace_id, - dims, NULL); - assert (rrank == rank); - for (int i=0; i 0); - } - */ - herr_t status; - status = H5Dread(dset->dset_id, dset->dtype_id, - H5S_ALL, H5S_ALL, H5P_DEFAULT, - buf); - assert (status >= 0); - - return dset; - -} - +#define NUCLEUS_GROUP_NAME "nucleus" +#define ECP_GROUP_NAME "ecp" +#define NUCLEUS_NUM_NAME "nucleus_num" +#define ECP_LOCAL_NUM_N_MAX_NAME "ecp_local_num_n_max" +#define ECP_NON_LOCAL_NUM_N_MAX_NAME "ecp_non_local_num_n_max" +#define NUCLEUS_CHARGE_NAME "nucleus_charge" +#define NUCLEUS_COORD_NAME "nucleus_coord" +#define ECP_LMAX_PLUS_1_NAME "ecp_lmax_plus_1" +#define ECP_Z_CORE_NAME "ecp_z_core" +#define ECP_LOCAL_N_NAME "ecp_local_n" +#define ECP_LOCAL_EXPONENT_NAME "ecp_local_exponent" +#define ECP_LOCAL_COEF_NAME "ecp_local_coef" +#define ECP_LOCAL_POWER_NAME "ecp_local_power" +#define ECP_NON_LOCAL_N_NAME "ecp_non_local_n" +#define ECP_NON_LOCAL_EXPONENT_NAME "ecp_non_local_exponent" +#define ECP_NON_LOCAL_COEF_NAME "ecp_non_local_coef" +#define ECP_NON_LOCAL_POWER_NAME "ecp_non_local_power" trexio_exit_code trexio_hdf5_init(trexio_t* file) { trexio_hdf5_t* f = (trexio_hdf5_t*) file; @@ -111,14 +69,17 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) { case 'r': case 'a': f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT); + f->ecp_group = H5Gopen(f->file_id, ECP_GROUP_NAME, H5P_DEFAULT); //f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT); break; case 'w': f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + f->ecp_group = H5Gcreate(f->file_id, ECP_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); //f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); break; } assert (f->nucleus_group > 0L); + assert (f->ecp_group > 0L); //assert (f->electron_group > 0L); return TREXIO_SUCCESS; @@ -129,7 +90,9 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* file) { trexio_hdf5_t* f = (trexio_hdf5_t*) file; H5Gclose(f->nucleus_group); + H5Gclose(f->ecp_group); f->nucleus_group = 0; + f->ecp_group = 0; /* H5Gclose(f->electron_group); @@ -141,206 +104,607 @@ trexio_exit_code trexio_hdf5_finalize(trexio_t* file) { return TREXIO_SUCCESS; } - -h5nucleus_t* trexio_hdf5_read_nucleus(const trexio_hdf5_t* file) { - - /* Allocate the data structure */ - h5nucleus_t* nucleus = MALLOC(h5nucleus_t); - assert (nucleus != NULL); - - nucleus->num = 0; - nucleus->coord = NULL; - nucleus->charge = NULL; - nucleus->h5_coord = NULL; - nucleus->h5_charge = NULL; - - /* Check that the file was opened/created correctly, return */ - if (file->file_id < 0) return nucleus; - - /* Quit if the dimensioning attribute is missing in the file */ - if (H5Aexists(file->nucleus_group, NUCLEUS_NUM_NAME) == 0) return nucleus; - - herr_t status; - /* Read the nucleus_num attribute of nucleus group */ - hid_t num_id; - num_id = H5Aopen(file->nucleus_group, NUCLEUS_NUM_NAME, H5P_DEFAULT); - assert (num_id > 0); - - status = H5Aread(num_id, H5T_NATIVE_ULLONG, &(nucleus->num)); - assert (status >= 0); - - /* Allocate and read nucleus_charge array */ - nucleus->charge = (double*) calloc(nucleus->num, sizeof(double)); - assert (nucleus->charge != NULL); - - /* High-level H5LT API. No need to deal with dataspaces and datatypes */ - status = H5LTread_dataset_double(file->nucleus_group, - NUCLEUS_CHARGE_NAME, - nucleus->charge); - - /* Allocate and read nucleus_coord array */ - nucleus->coord = (double*) calloc(3 * nucleus->num, sizeof(double)); - assert (nucleus->coord != NULL); - - /* High-level H5LT API. No need to deal with dataspaces and datatypes */ - status = H5LTread_dataset_double(file->nucleus_group, - NUCLEUS_COORD_NAME, - nucleus->coord); - assert (status >= 0); - - /* Low-level read. Do not forget to close the associated IDs (dset,dtype,dspace) - * when not used anymore, see below. Note how this function is similar to H5LTread_dataset_double - */ - /* - nucleus->h5_coord = trexio_hdf5_read_dset_low(file, NUCLEUS_COORD_NAME, - nucleus->coord); - - H5Sclose(nucleus->h5_coord->dspace_id); - H5Tclose(nucleus->h5_coord->dtype_id); - H5Dclose(nucleus->h5_coord->dset_id); - */ - - H5Aclose(num_id); - - return nucleus; -} - - -trexio_exit_code trexio_hdf5_write_nucleus(const trexio_hdf5_t* file, h5nucleus_t* nucleus) { +trexio_exit_code trexio_hdf5_read_nucleus_charge(const trexio_t* file, double* nucleus_charge, const uint32_t rank, const uint64_t* dims) { assert (file != NULL); - assert (nucleus != NULL); - + assert (nucleus_charge != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + herr_t status; - hid_t dspace, dtype; - hid_t attr_id; - - dtype = H5Tcopy(H5T_NATIVE_ULLONG); - /* Write the dimensioning variables */ - if (H5Aexists(file->nucleus_group, NUCLEUS_NUM_NAME) == 0) { - dspace = H5Screate(H5S_SCALAR); - attr_id = H5Acreate(file->nucleus_group, NUCLEUS_NUM_NAME, dtype, dspace, - H5P_DEFAULT, H5P_DEFAULT); - assert (attr_id > 0); + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->nucleus_group, NUCLEUS_CHARGE_NAME, + &rrank); - /* High-level routine does not work for some reason - * status = H5LTset_attribute_ulong (file->nucleus_group, "nucleus", NUCLEUS_NUM_NAME, - * &(nucleus->num), 1); - */ - } else { - attr_id = H5Aopen(file->nucleus_group, NUCLEUS_NUM_NAME, H5P_DEFAULT); - assert (attr_id > 0); + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_CHARGE_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; } - status = H5Awrite(attr_id, dtype, &(nucleus->num)); - assert (status >= 0); - - H5Aclose(attr_id); - - /* Write arrays */ - hid_t dset_id; - int charge_rank = 1; - const hsize_t charge_dims[1] = {nucleus->num}; - - if ( H5LTfind_dataset(file->nucleus_group, NUCLEUS_CHARGE_NAME) != 1) { - - status = H5LTmake_dataset_double (file->nucleus_group, NUCLEUS_CHARGE_NAME, - charge_rank, charge_dims, nucleus->charge); - assert (status >= 0); - - } else { - - dset_id = H5Dopen(file->nucleus_group, NUCLEUS_CHARGE_NAME, H5P_DEFAULT); - assert (dset_id > 0); - - dspace = H5Dget_space(dset_id); - assert (dspace > 0); - - dtype = H5Dget_type(dset_id); - assert (dtype > 0); - - - int rrank; - hsize_t dims[1] = {0}; - rrank = H5Sget_simple_extent_dims(dspace, - dims, NULL); - assert (rrank == charge_rank); - // disabling asserts like this allows to overwrite _num variable - for (int i=0; icharge); - assert (status >= 0); - - H5Sclose(dspace); - H5Tclose(dtype); - H5Dclose(dset_id); - + for (uint32_t i=0; inum, 3}; - if ( H5LTfind_dataset(file->nucleus_group, NUCLEUS_COORD_NAME) != 1) { - status = H5LTmake_dataset_double (file->nucleus_group, NUCLEUS_COORD_NAME, - coord_rank, coord_dims, nucleus->coord); - assert (status >= 0); - - } else { - - dset_id = H5Dopen(file->nucleus_group, NUCLEUS_COORD_NAME, H5P_DEFAULT); - assert (dset_id > 0); - - dspace = H5Dget_space(dset_id); - assert (dspace > 0); - - dtype = H5Dget_type(dset_id); - assert (dtype > 0); - - - int rrank; - hsize_t dims[2] = {0, 0}; - rrank = H5Sget_simple_extent_dims(dspace, - dims, NULL); - assert (rrank == coord_rank); - for (int i=0; icoord); - assert (status >= 0); - - H5Sclose(dspace); - H5Tclose(dtype); - H5Dclose(dset_id); - - } + /* High-level H5LT API. No need to deal with dataspaces and datatypes */ + status = H5LTread_dataset_double(f->nucleus_group, + NUCLEUS_CHARGE_NAME, + nucleus_charge); + if (status < 0) return TREXIO_FAILURE; return TREXIO_SUCCESS; } +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* nucleus_coord, const uint32_t rank, const uint64_t* dims) { -trexio_exit_code trexio_hdf5_free_nucleus(h5nucleus_t* nucleus) { + assert (file != NULL); + assert (nucleus_coord != NULL); - if (nucleus == NULL) return TREXIO_FAILURE; + trexio_hdf5_t* f = (trexio_hdf5_t*) file; - if (nucleus->coord != NULL) - FREE (nucleus->coord); - - if (nucleus->charge != NULL) - FREE (nucleus->charge); - - if (nucleus->h5_coord != NULL) - FREE (nucleus->h5_coord); - - if (nucleus->h5_charge != NULL) - FREE (nucleus->h5_charge); + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->nucleus_group, NUCLEUS_COORD_NAME, + &rrank); - FREE (nucleus); + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_COORD_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; inucleus_group, + NUCLEUS_COORD_NAME, + nucleus_coord); + if (status < 0) return TREXIO_FAILURE; return TREXIO_SUCCESS; } +trexio_exit_code trexio_hdf5_read_ecp_lmax_plus_1(const trexio_t* file, int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims) { -trexio_exit_code trexio_hdf5_read_nucleus_num(const trexio_t* file, uint64_t* num) { + assert (file != NULL); + assert (ecp_lmax_plus_1 != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_LMAX_PLUS_1_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LMAX_PLUS_1_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_LMAX_PLUS_1_NAME, + ecp_lmax_plus_1); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_z_core(const trexio_t* file, int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_z_core != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_Z_CORE_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_Z_CORE_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_Z_CORE_NAME, + ecp_z_core); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_local_n(const trexio_t* file, int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_n != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_LOCAL_N_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_N_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_LOCAL_N_NAME, + ecp_local_n); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_local_exponent(const trexio_t* file, double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_exponent != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_LOCAL_EXPONENT_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_EXPONENT_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_LOCAL_EXPONENT_NAME, + ecp_local_exponent); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_local_coef(const trexio_t* file, double* ecp_local_coef, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_coef != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_LOCAL_COEF_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_COEF_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_LOCAL_COEF_NAME, + ecp_local_coef); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_local_power(const trexio_t* file, int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_power != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_LOCAL_POWER_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_POWER_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_LOCAL_POWER_NAME, + ecp_local_power); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_non_local_n(const trexio_t* file, int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_n != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_NON_LOCAL_N_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_N_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_NON_LOCAL_N_NAME, + ecp_non_local_n); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_non_local_exponent(const trexio_t* file, double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_exponent != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_NON_LOCAL_EXPONENT_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_EXPONENT_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_NON_LOCAL_EXPONENT_NAME, + ecp_non_local_exponent); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_non_local_coef(const trexio_t* file, double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_coef != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_NON_LOCAL_COEF_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_COEF_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_NON_LOCAL_COEF_NAME, + ecp_non_local_coef); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_non_local_power(const trexio_t* file, int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_power != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + int rrank; + // get the rank of the dataset in a file + status = H5LTget_dataset_ndims (f->ecp_group, ECP_NON_LOCAL_POWER_NAME, + &rrank); + + if (status < 0) return TREXIO_FAILURE; + + if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; + + // open the dataset to get its dimensions + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_POWER_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + // allocate space for the dimensions to be read + hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); + if (ddims == NULL) return TREXIO_FAILURE; + + // read dimensions from the existing dataset + status = H5LDget_dset_dims(dset_id, ddims); + + H5Dclose(dset_id); + if (status < 0) { + free(ddims); + return TREXIO_FAILURE; + } + + for (uint32_t i=0; iecp_group, + ECP_NON_LOCAL_POWER_NAME, + ecp_non_local_power); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_nucleus_num (const trexio_t* file, uint64_t* num) { assert (file != NULL); assert (num != NULL); @@ -358,9 +722,487 @@ trexio_exit_code trexio_hdf5_read_nucleus_num(const trexio_t* file, uint64_t* nu return TREXIO_SUCCESS; } +trexio_exit_code trexio_hdf5_read_ecp_local_num_n_max (const trexio_t* file, uint64_t* num) { - -trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint64_t num) { + assert (file != NULL); + assert (num != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + /* Quit if the dimensioning attribute is missing in the file */ + if (H5Aexists(f->ecp_group, ECP_LOCAL_NUM_N_MAX_NAME) == 0) return TREXIO_FAILURE; + + /* Read the nucleus_num attribute of nucleus group */ + hid_t num_id = H5Aopen(f->ecp_group, ECP_LOCAL_NUM_N_MAX_NAME, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + + herr_t status = H5Aread(num_id, H5T_NATIVE_ULLONG, num); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_read_ecp_non_local_num_n_max (const trexio_t* file, uint64_t* num) { + + assert (file != NULL); + assert (num != NULL); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + /* Quit if the dimensioning attribute is missing in the file */ + if (H5Aexists(f->ecp_group, ECP_NON_LOCAL_NUM_N_MAX_NAME) == 0) return TREXIO_FAILURE; + + /* Read the nucleus_num attribute of nucleus group */ + hid_t num_id = H5Aopen(f->ecp_group, ECP_NON_LOCAL_NUM_N_MAX_NAME, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + + herr_t status = H5Aread(num_id, H5T_NATIVE_ULLONG, num); + if (status < 0) return TREXIO_FAILURE; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_nucleus_charge(const trexio_t* file, const double* nucleus_charge, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (nucleus_charge != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->nucleus_group, NUCLEUS_CHARGE_NAME) != 1) { + + status = H5LTmake_dataset_double (f->nucleus_group, NUCLEUS_CHARGE_NAME, + (int) rank, (hsize_t*) dims, nucleus_charge); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_CHARGE_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, nucleus_charge); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* nucleus_coord, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (nucleus_coord != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->nucleus_group, NUCLEUS_COORD_NAME) != 1) { + + status = H5LTmake_dataset_double (f->nucleus_group, NUCLEUS_COORD_NAME, + (int) rank, (hsize_t*) dims, nucleus_coord); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_COORD_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, nucleus_coord); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_lmax_plus_1(const trexio_t* file, const int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_lmax_plus_1 != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_LMAX_PLUS_1_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_LMAX_PLUS_1_NAME, + (int) rank, (hsize_t*) dims, ecp_lmax_plus_1); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LMAX_PLUS_1_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_lmax_plus_1); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_z_core(const trexio_t* file, const int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_z_core != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_Z_CORE_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_Z_CORE_NAME, + (int) rank, (hsize_t*) dims, ecp_z_core); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_Z_CORE_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_z_core); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_local_n(const trexio_t* file, const int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_n != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_LOCAL_N_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_LOCAL_N_NAME, + (int) rank, (hsize_t*) dims, ecp_local_n); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_N_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_local_n); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_local_exponent(const trexio_t* file, const double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_exponent != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &(ecp_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_LOCAL_EXPONENT_NAME) != 1) { + + status = H5LTmake_dataset_double (f->ecp_group, ECP_LOCAL_EXPONENT_NAME, + (int) rank, (hsize_t*) dims, ecp_local_exponent); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_EXPONENT_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_local_exponent); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_local_coef(const trexio_t* file, const double* ecp_local_coef, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_coef != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &(ecp_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_LOCAL_COEF_NAME) != 1) { + + status = H5LTmake_dataset_double (f->ecp_group, ECP_LOCAL_COEF_NAME, + (int) rank, (hsize_t*) dims, ecp_local_coef); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_COEF_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_local_coef); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_local_power(const trexio_t* file, const int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_local_power != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_local_num_n_max(file, &(ecp_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_LOCAL_POWER_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_LOCAL_POWER_NAME, + (int) rank, (hsize_t*) dims, ecp_local_power); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_LOCAL_POWER_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_local_power); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_non_local_n(const trexio_t* file, const int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_n != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_NON_LOCAL_N_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_NON_LOCAL_N_NAME, + (int) rank, (hsize_t*) dims, ecp_non_local_n); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_N_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_non_local_n); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_non_local_exponent(const trexio_t* file, const double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_exponent != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_non_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &(ecp_non_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_NON_LOCAL_EXPONENT_NAME) != 1) { + + status = H5LTmake_dataset_double (f->ecp_group, ECP_NON_LOCAL_EXPONENT_NAME, + (int) rank, (hsize_t*) dims, ecp_non_local_exponent); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_EXPONENT_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_non_local_exponent); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_non_local_coef(const trexio_t* file, const double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_coef != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_non_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &(ecp_non_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_NON_LOCAL_COEF_NAME) != 1) { + + status = H5LTmake_dataset_double (f->ecp_group, ECP_NON_LOCAL_COEF_NAME, + (int) rank, (hsize_t*) dims, ecp_non_local_coef); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_COEF_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_non_local_coef); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_ecp_non_local_power(const trexio_t* file, const int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims) { + + assert (file != NULL); + assert (ecp_non_local_power != NULL); + + trexio_exit_code rc; + uint64_t nucleus_num; + uint64_t ecp_non_local_num_n_max; + // error handling for rc is added by the generator + rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + if (rc != TREXIO_SUCCESS) return rc; + rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &(ecp_non_local_num_n_max)); + if (rc != TREXIO_SUCCESS) return rc; + if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; + if (ecp_non_local_num_n_max <= 0L) return TREXIO_INVALID_NUM; + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + + herr_t status; + if ( H5LTfind_dataset(f->ecp_group, ECP_NON_LOCAL_POWER_NAME) != 1) { + + status = H5LTmake_dataset_long (f->ecp_group, ECP_NON_LOCAL_POWER_NAME, + (int) rank, (hsize_t*) dims, ecp_non_local_power); + if (status < 0) return TREXIO_FAILURE; + + } else { + + hid_t dset_id = H5Dopen(f->ecp_group, ECP_NON_LOCAL_POWER_NAME, H5P_DEFAULT); + if (dset_id <= 0) return TREXIO_INVALID_ID; + + status = H5Dwrite(dset_id, H5T_NATIVE_LONG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ecp_non_local_power); + + H5Dclose(dset_id); + if (status < 0) return TREXIO_FAILURE; + + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_hdf5_write_nucleus_num (const trexio_t* file, const uint64_t num) { assert (file != NULL); assert (num > 0L); @@ -377,34 +1219,34 @@ trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint6 num_id = H5Acreate(f->nucleus_group, NUCLEUS_NUM_NAME, dtype, dspace, H5P_DEFAULT, H5P_DEFAULT); - assert (num_id > 0); + if (num_id <= 0) return TREXIO_INVALID_ID; status = H5Awrite(num_id, dtype, &(num)); - assert (status >= 0); + if (status < 0) return TREXIO_FAILURE; H5Sclose(dspace); } else { - uint64_t nucleus_num; - trexio_exit_code rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); + uint64_t infile_num; + trexio_exit_code rc = trexio_hdf5_read_nucleus_num(file, &(infile_num)); if (rc != TREXIO_SUCCESS) return rc; - if (nucleus_num != num) { + if (infile_num != num) { - if (nucleus_num != 0) { - printf("%ld -> %ld %s \n", num, nucleus_num, + if (infile_num != 0) { + printf("%ld -> %ld %s \n", num, infile_num, "This variable already exists. Overwriting it is not supported"); H5Tclose(dtype); - return TREXIO_FAILURE; + return TREXIO_FAILURE; } else { num_id = H5Aopen(f->nucleus_group, NUCLEUS_NUM_NAME, H5P_DEFAULT); - assert (num_id > 0); + if (num_id <= 0) return TREXIO_INVALID_ID; status = H5Awrite(num_id, dtype, &(num)); - assert (status >= 0); + if (status < 0) return TREXIO_FAILURE; } } @@ -415,89 +1257,113 @@ trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint6 return TREXIO_SUCCESS; } - -trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) { +trexio_exit_code trexio_hdf5_write_ecp_local_num_n_max (const trexio_t* file, const uint64_t num) { assert (file != NULL); - assert (coord != NULL); - - trexio_hdf5_t* f = (trexio_hdf5_t*) file; - - herr_t status; - int rrank; - // get the rank of the dataset in a file - status = H5LTget_dataset_ndims (f->nucleus_group, NUCLEUS_COORD_NAME, - &rrank); - - if (status < 0) return TREXIO_FAILURE; - - if (rrank != (int) rank) return TREXIO_INVALID_ARG_3; - - // open the dataset to get its dimensions - hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_COORD_NAME, H5P_DEFAULT); - if (dset_id <= 0) return TREXIO_INVALID_ID; - - // allocate space for the dimensions to be read - hsize_t* ddims = (hsize_t*) calloc( (int) rank, sizeof(hsize_t)); - if (ddims == NULL) return TREXIO_FAILURE; - - // read dimensions from the existing dataset - status = H5LDget_dset_dims(dset_id, ddims); - - H5Dclose(dset_id); - if (status < 0) { - FREE(ddims); - return TREXIO_FAILURE; - } - - for (uint32_t i=0; inucleus_group, - NUCLEUS_COORD_NAME, - coord); - if (status < 0) return TREXIO_FAILURE; - - return TREXIO_SUCCESS; -} - + assert (num > 0L); -trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims) { + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + hid_t num_id; + herr_t status; + /* Write the dimensioning variables */ + hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG); + + if (H5Aexists(f->ecp_group, ECP_LOCAL_NUM_N_MAX_NAME) == 0) { + + hid_t dspace = H5Screate(H5S_SCALAR); + + num_id = H5Acreate(f->ecp_group, ECP_LOCAL_NUM_N_MAX_NAME, dtype, dspace, + H5P_DEFAULT, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + + status = H5Awrite(num_id, dtype, &(num)); + if (status < 0) return TREXIO_FAILURE; + + H5Sclose(dspace); + + } else { + + uint64_t infile_num; + trexio_exit_code rc = trexio_hdf5_read_ecp_local_num_n_max(file, &(infile_num)); + if (rc != TREXIO_SUCCESS) return rc; + + if (infile_num != num) { + + if (infile_num != 0) { + printf("%ld -> %ld %s \n", num, infile_num, + "This variable already exists. Overwriting it is not supported"); + H5Tclose(dtype); + return TREXIO_FAILURE; + + } else { + + num_id = H5Aopen(f->ecp_group, ECP_LOCAL_NUM_N_MAX_NAME, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + + status = H5Awrite(num_id, dtype, &(num)); + if (status < 0) return TREXIO_FAILURE; + + } + } + } + + H5Aclose(num_id); + H5Tclose(dtype); + return TREXIO_SUCCESS; + +} +trexio_exit_code trexio_hdf5_write_ecp_non_local_num_n_max (const trexio_t* file, const uint64_t num) { assert (file != NULL); - assert (coord != NULL); - - uint64_t nucleus_num; - trexio_exit_code rc = trexio_hdf5_read_nucleus_num(file, &(nucleus_num)); - if (rc != TREXIO_SUCCESS) return rc; - if (nucleus_num <= 0L) return TREXIO_INVALID_NUM; - - trexio_hdf5_t* f = (trexio_hdf5_t*) file; - + assert (num > 0L); + + trexio_hdf5_t* f = (trexio_hdf5_t*) file; + hid_t num_id; herr_t status; - if ( H5LTfind_dataset(f->nucleus_group, NUCLEUS_COORD_NAME) != 1) { - - status = H5LTmake_dataset_double (f->nucleus_group, NUCLEUS_COORD_NAME, - (int) rank, (hsize_t*) dims, coord); - if (status < 0) return TREXIO_FAILURE; + /* Write the dimensioning variables */ + hid_t dtype = H5Tcopy(H5T_NATIVE_ULLONG); - } else { + if (H5Aexists(f->ecp_group, ECP_NON_LOCAL_NUM_N_MAX_NAME) == 0) { + + hid_t dspace = H5Screate(H5S_SCALAR); - hid_t dset_id = H5Dopen(f->nucleus_group, NUCLEUS_COORD_NAME, H5P_DEFAULT); - if (dset_id <= 0) return TREXIO_INVALID_ID; - - status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, coord); - - H5Dclose(dset_id); - if (status < 0) return TREXIO_FAILURE; - - } + num_id = H5Acreate(f->ecp_group, ECP_NON_LOCAL_NUM_N_MAX_NAME, dtype, dspace, + H5P_DEFAULT, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + status = H5Awrite(num_id, dtype, &(num)); + if (status < 0) return TREXIO_FAILURE; + + H5Sclose(dspace); + + } else { + + uint64_t infile_num; + trexio_exit_code rc = trexio_hdf5_read_ecp_non_local_num_n_max(file, &(infile_num)); + if (rc != TREXIO_SUCCESS) return rc; + + if (infile_num != num) { + + if (infile_num != 0) { + printf("%ld -> %ld %s \n", num, infile_num, + "This variable already exists. Overwriting it is not supported"); + H5Tclose(dtype); + return TREXIO_FAILURE; + + } else { + + num_id = H5Aopen(f->ecp_group, ECP_NON_LOCAL_NUM_N_MAX_NAME, H5P_DEFAULT); + if (num_id <= 0) return TREXIO_INVALID_ID; + + status = H5Awrite(num_id, dtype, &(num)); + if (status < 0) return TREXIO_FAILURE; + + } + } + } + + H5Aclose(num_id); + H5Tclose(dtype); return TREXIO_SUCCESS; + } diff --git a/src/trexio_hdf5.h b/src/trexio_hdf5.h index 89106aa..12d5c2d 100644 --- a/src/trexio_hdf5.h +++ b/src/trexio_hdf5.h @@ -1,15 +1,12 @@ -/* This file was generated from the trexio.org org-mode file. - To generate it, open trexio.org in Emacs and execute +/* This file was generated from the org-mode file. + To generate it, open templator_hdf5.org file in Emacs and execute M-x org-babel-tangle */ - - #ifndef _TREXIO_HDF5_H #define _TREXIO_HDF5_H #include "trexio.h" -#include "trexio_private.h" #include "trexio_s.h" #include #include @@ -20,79 +17,44 @@ #include "hdf5.h" #include "hdf5_hl.h" // needed for high-level APIs like H5LT, requires additional linking in Makefile - -typedef struct slab_s { - uint64_t a; - uint64_t b; - uint64_t c; - uint64_t d; -} slab_t; - -typedef struct dset_s { - hid_t dset_id; - hid_t dspace_id; - hid_t dtype_id; - uint64_t* dims; - uint32_t rank; - const char* dset_name; -} dset_t; - -typedef struct h5nucleus_s { - uint64_t num; - double *coord; - double *charge; - dset_t* h5_coord; - dset_t* h5_charge; -} h5nucleus_t; - -typedef struct h5electron_s { - uint64_t alpha_num; - uint64_t beta_num; -} h5electron_t; - typedef struct trexio_hdf5_s { trexio_t parent ; hid_t file_id; hid_t nucleus_group; - hid_t electron_group; - //... other groups' id + hid_t ecp_group; const char* file_name; } trexio_hdf5_t; trexio_exit_code trexio_hdf5_init(trexio_t* file); - trexio_exit_code trexio_hdf5_finalize(trexio_t* file); - -typedef struct one_index_s { - double value; - int64_t i; -} one_index_t; - -typedef struct two_index_s { - double value; - int64_t i; - int64_t j; -} two_index_t; - -typedef struct three_index_s { - double value; - int64_t i; - int64_t j; - int64_t k; -} three_index_t; - -typedef struct four_index_s { - double value; - int64_t i; - int64_t j; - int64_t k; - int64_t l; -} four_index_t; - -trexio_exit_code trexio_hdf5_read_nucleus_num(const trexio_t* file, uint64_t* num); -trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint64_t num); - -trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims); -trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims); - +trexio_exit_code trexio_hdf5_read_nucleus_num (const trexio_t* file, uint64_t* num); +trexio_exit_code trexio_hdf5_write_nucleus_num (const trexio_t* file, const uint64_t num); +trexio_exit_code trexio_hdf5_read_ecp_local_num_n_max (const trexio_t* file, uint64_t* num); +trexio_exit_code trexio_hdf5_write_ecp_local_num_n_max (const trexio_t* file, const uint64_t num); +trexio_exit_code trexio_hdf5_read_ecp_non_local_num_n_max (const trexio_t* file, uint64_t* num); +trexio_exit_code trexio_hdf5_write_ecp_non_local_num_n_max (const trexio_t* file, const uint64_t num); +trexio_exit_code trexio_hdf5_read_nucleus_charge(const trexio_t* file, double* nucleus_charge, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_nucleus_charge(const trexio_t* file, const double* nucleus_charge, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* nucleus_coord, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* nucleus_coord, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_lmax_plus_1(const trexio_t* file, int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_lmax_plus_1(const trexio_t* file, const int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_z_core(const trexio_t* file, int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_z_core(const trexio_t* file, const int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_local_n(const trexio_t* file, int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_local_n(const trexio_t* file, const int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_local_exponent(const trexio_t* file, double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_local_exponent(const trexio_t* file, const double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_local_coef(const trexio_t* file, double* ecp_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_local_coef(const trexio_t* file, const double* ecp_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_local_power(const trexio_t* file, int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_local_power(const trexio_t* file, const int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_non_local_n(const trexio_t* file, int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_non_local_n(const trexio_t* file, const int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_non_local_exponent(const trexio_t* file, double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_non_local_exponent(const trexio_t* file, const double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_non_local_coef(const trexio_t* file, double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_non_local_coef(const trexio_t* file, const double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_read_ecp_non_local_power(const trexio_t* file, int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_hdf5_write_ecp_non_local_power(const trexio_t* file, const int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims); #endif diff --git a/src/trexio_s.h b/src/trexio_s.h index 315c90f..10cf613 100644 --- a/src/trexio_s.h +++ b/src/trexio_s.h @@ -3,13 +3,10 @@ M-x org-babel-tangle */ - - #ifndef _TREXIO_S_H #define _TREXIO_S_H #include "trexio.h" -#include "trexio_private.h" #include #include @@ -20,5 +17,4 @@ struct trexio_s { char mode; char padding[7]; /* Ensures the proper alignment of back-ends */ }; - #endif diff --git a/src/trexio_text.c b/src/trexio_text.c index d13eace..508099b 100644 --- a/src/trexio_text.c +++ b/src/trexio_text.c @@ -4,9 +4,9 @@ */ - #include "trexio_text.h" +#define DEBUG printf("%s : line %d\n", __FILE__, __LINE__); trexio_exit_code trexio_text_init(trexio_t* file) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -69,19 +69,6 @@ trexio_exit_code trexio_text_lock(trexio_t* file) { return TREXIO_SUCCESS; } -trexio_exit_code trexio_text_finalize(trexio_t* file) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - - trexio_exit_code rc; - rc = trexio_text_free_nucleus( (trexio_text_t*) file); - assert (rc == TREXIO_SUCCESS); - - rc = trexio_text_free_rdm( (trexio_text_t*) file); - assert (rc == TREXIO_SUCCESS); - - return TREXIO_SUCCESS; -} - trexio_exit_code trexio_text_unlock(trexio_t* file) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -100,9 +87,126 @@ trexio_exit_code trexio_text_unlock(trexio_t* file) { close(f->lock_file); return TREXIO_SUCCESS; } +trexio_exit_code trexio_text_finalize(trexio_t* file) { + if (file == NULL) return TREXIO_INVALID_ARG_1; -#define DEBUG printf("%s : line %d\n", __FILE__, __LINE__); + trexio_exit_code rc; + //rc = trexio_text_free_nucleus( (trexio_text_t*) file); + //rc = trexio_text_free_ecp( (trexio_text_t*) file); + //assert (rc == TREXIO_SUCCESS); + assert (trexio_text_free_nucleus( (trexio_text_t*) file) == TREXIO_SUCCESS); + assert (trexio_text_free_ecp( (trexio_text_t*) file) == TREXIO_SUCCESS); + + rc = trexio_text_free_rdm( (trexio_text_t*) file); + assert (rc == TREXIO_SUCCESS); + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + + trexio_exit_code rc; + + if (file->parent.mode != 'r') { + rc = trexio_text_flush_nucleus(file); + if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; + } + + nucleus_t* nucleus = file->nucleus; + if (nucleus == NULL) return TREXIO_SUCCESS; + + if (nucleus->file != NULL) { + fclose(nucleus->file); + nucleus->file = NULL; + } + + + if (nucleus->nucleus_charge != NULL) { + FREE (nucleus->nucleus_charge); + } + + + if (nucleus->nucleus_coord != NULL) { + FREE (nucleus->nucleus_coord); + } + + + FREE (nucleus); + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_free_ecp(trexio_text_t* file) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + + trexio_exit_code rc; + + if (file->parent.mode != 'r') { + rc = trexio_text_flush_ecp(file); + if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; + } + + ecp_t* ecp = file->ecp; + if (ecp == NULL) return TREXIO_SUCCESS; + + if (ecp->file != NULL) { + fclose(ecp->file); + ecp->file = NULL; + } + + + if (ecp->ecp_lmax_plus_1 != NULL) { + FREE (ecp->ecp_lmax_plus_1); + } + + + if (ecp->ecp_z_core != NULL) { + FREE (ecp->ecp_z_core); + } + + + if (ecp->ecp_local_n != NULL) { + FREE (ecp->ecp_local_n); + } + + + if (ecp->ecp_local_exponent != NULL) { + FREE (ecp->ecp_local_exponent); + } + + + if (ecp->ecp_local_coef != NULL) { + FREE (ecp->ecp_local_coef); + } + + + if (ecp->ecp_local_power != NULL) { + FREE (ecp->ecp_local_power); + } + + + if (ecp->ecp_non_local_n != NULL) { + FREE (ecp->ecp_non_local_n); + } + + + if (ecp->ecp_non_local_exponent != NULL) { + FREE (ecp->ecp_non_local_exponent); + } + + + if (ecp->ecp_non_local_coef != NULL) { + FREE (ecp->ecp_non_local_coef); + } + + + if (ecp->ecp_non_local_power != NULL) { + FREE (ecp->ecp_non_local_power); + } + + + FREE (ecp); + return TREXIO_SUCCESS; +} nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) { if (file == NULL) return NULL; @@ -128,7 +232,7 @@ nucleus_t* trexio_text_read_nucleus(trexio_text_t* file) { DEBUG return NULL; } - + strcpy (file_name, file->parent.file_name); strcat (file_name, nucleus_file_name); @@ -152,8 +256,9 @@ DEBUG /* Read the dimensioning variables */ int rc; + rc = fscanf(f, "%s", buffer); - if ((rc != 1) || (strcmp(buffer, "rank_charge") != 0)) { + if ((rc != 1) || (strcmp(buffer, "rank_nucleus_charge") != 0)) { FREE(buffer); FREE(file_name); FREE(nucleus); @@ -161,7 +266,7 @@ DEBUG return NULL; } - rc = fscanf(f, "%u", &(nucleus->rank_charge)); + rc = fscanf(f, "%u", &(nucleus->rank_nucleus_charge)); if (rc != 1) { FREE(buffer); FREE(file_name); @@ -169,13 +274,13 @@ DEBUG DEBUG return NULL; } - - uint64_t size_charge = 1; - for (unsigned int i=0; irank_charge; i++){ + + uint64_t size_nucleus_charge = 1; + for (unsigned int i=0; irank_nucleus_charge; i++){ unsigned int j=-1; rc = fscanf(f, "%s %u", buffer, &j); - if ((rc != 2) || (strcmp(buffer, "dims_charge") != 0) || (j!=i)) { + if ((rc != 2) || (strcmp(buffer, "dims_nucleus_charge") != 0) || (j!=i)) { FREE(buffer); FREE(file_name); FREE(nucleus); @@ -183,7 +288,7 @@ DEBUG return NULL; } - rc = fscanf(f, "%lu\n", &(nucleus->dims_charge[i])); + rc = fscanf(f, "%lu\n", &(nucleus->dims_nucleus_charge[i])); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); @@ -193,11 +298,12 @@ DEBUG return NULL; } - size_charge *= nucleus->dims_charge[i]; + size_nucleus_charge *= nucleus->dims_nucleus_charge[i]; } - + + rc = fscanf(f, "%s", buffer); - if ((rc != 1) || (strcmp(buffer, "rank_coord") != 0)) { + if ((rc != 1) || (strcmp(buffer, "rank_nucleus_coord") != 0)) { FREE(buffer); FREE(file_name); FREE(nucleus); @@ -205,8 +311,7 @@ DEBUG return NULL; } - rc = fscanf(f, "%u", &(nucleus->rank_coord)); - assert(!(rc != 1)); + rc = fscanf(f, "%u", &(nucleus->rank_nucleus_coord)); if (rc != 1) { FREE(buffer); FREE(file_name); @@ -214,125 +319,134 @@ DEBUG DEBUG return NULL; } + + uint64_t size_nucleus_coord = 1; + for (unsigned int i=0; irank_nucleus_coord; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_nucleus_coord") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(nucleus); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(nucleus->dims_nucleus_coord[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(nucleus); +DEBUG + return NULL; + } + + size_nucleus_coord *= nucleus->dims_nucleus_coord[i]; + } + + + + /* Read data */ + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "nucleus_num") != 0))); + if ((rc != 1) || (strcmp(buffer, "nucleus_num") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(nucleus); +DEBUG + return NULL; + } - uint64_t size_coord = 1; - for (unsigned int i=0; irank_coord; i++){ - - unsigned int j=-1; - rc = fscanf(f, "%s %u", buffer, &j); - if ((rc != 2) || (strcmp(buffer, "dims_coord") != 0) || (j!=i)) { - FREE(buffer); - FREE(file_name); - FREE(nucleus); -DEBUG - return NULL; - } - - rc = fscanf(f, "%lu", &(nucleus->dims_coord[i])); - assert(!(rc != 1)); - if (rc != 1) { - FREE(buffer); - FREE(file_name); - FREE(nucleus); -DEBUG - return NULL; - } - - size_coord *= nucleus->dims_coord[i]; - } - - /* Allocate arrays */ - nucleus->charge = (double*) calloc(size_charge, sizeof(double)); - assert (!(nucleus->charge == NULL)); - if (nucleus->charge == NULL) { - FREE(buffer); - FREE(file_name); - FREE(nucleus); -DEBUG - return NULL; - } - - nucleus->coord = (double*) calloc(size_coord, sizeof(double)); - assert (!(nucleus->coord == NULL)); - if (nucleus->coord == NULL) { - FREE(buffer); - FREE(file_name); - FREE(nucleus->charge); - FREE(nucleus); -DEBUG - return NULL; - } - - /* Read data */ - rc = fscanf(f, "%s", buffer); - assert(!((rc != 1) || (strcmp(buffer, "num") != 0))); - if ((rc != 1) || (strcmp(buffer, "num") != 0)) { - FREE(buffer); - FREE(file_name); - FREE(nucleus->charge); - FREE(nucleus); -DEBUG - return NULL; - } - - rc = fscanf(f, "%lu", &(nucleus->num)); + rc = fscanf(f, "%lu", &(nucleus->nucleus_num)); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); FREE(file_name); - FREE(nucleus->charge); FREE(nucleus); DEBUG return NULL; } + - rc = fscanf(f, "%s", buffer); - assert(!((rc != 1) || (strcmp(buffer, "charge") != 0))); - if ((rc != 1) || (strcmp(buffer, "charge") != 0)) { + + /* Allocate arrays */ + nucleus->nucleus_charge = (double*) calloc(size_nucleus_charge, sizeof(double)); + assert (!(nucleus->nucleus_charge == NULL)); + if (nucleus->nucleus_charge == NULL) { FREE(buffer); FREE(file_name); - FREE(nucleus->charge); + FREE(nucleus); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "nucleus_charge") != 0))); + if ((rc != 1) || (strcmp(buffer, "nucleus_charge") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(nucleus->nucleus_charge); FREE(nucleus); DEBUG return NULL; } - for (uint64_t i=0 ; icharge[i])); + for (uint64_t i=0 ; inucleus_charge[i])); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); FREE(file_name); - FREE(nucleus->charge); + // TODO: free all dsets + FREE(nucleus->nucleus_charge); FREE(nucleus); DEBUG return NULL; } } - - rc = fscanf(f, "%s", buffer); - assert(!((rc != 1) || (strcmp(buffer, "coord") != 0))); - if ((rc != 1) || (strcmp(buffer, "coord") != 0)) { + + + /* Allocate arrays */ + nucleus->nucleus_coord = (double*) calloc(size_nucleus_coord, sizeof(double)); + assert (!(nucleus->nucleus_coord == NULL)); + if (nucleus->nucleus_coord == NULL) { FREE(buffer); FREE(file_name); - FREE(nucleus->charge); + FREE(nucleus); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "nucleus_coord") != 0))); + if ((rc != 1) || (strcmp(buffer, "nucleus_coord") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(nucleus->nucleus_coord); FREE(nucleus); DEBUG return NULL; } - for (uint64_t i=0 ; icoord[i])); + for (uint64_t i=0 ; inucleus_coord[i])); assert(!(rc != 1)); if (rc != 1) { FREE(buffer); FREE(file_name); - FREE(nucleus->charge); + // TODO: free all dsets + FREE(nucleus->nucleus_coord); FREE(nucleus); DEBUG return NULL; } } + + FREE(buffer); fclose(f); f = NULL; @@ -346,7 +460,9 @@ DEBUG FREE(file_name); assert (!(nucleus->file == NULL)); if (nucleus->file == NULL) { - FREE(nucleus->charge); + // TODO: free all dsets + FREE(nucleus->nucleus_charge); + FREE(nucleus->nucleus_coord); FREE(nucleus); DEBUG return NULL; @@ -356,7 +472,965 @@ DEBUG file->nucleus = nucleus; return nucleus; } +ecp_t* trexio_text_read_ecp(trexio_text_t* file) { + if (file == NULL) return NULL; + /* If the data structure exists, return it */ + if (file->ecp != NULL) { + return file->ecp; + } + + /* Allocate the data structure */ + ecp_t* ecp = MALLOC(ecp_t); + if (ecp == NULL) return NULL; + + memset(ecp,0,sizeof(ecp_t)); + + /* Build the file name */ + const char* ecp_file_name = "/ecp.txt"; + char * file_name = (char*) + calloc( strlen(file->parent.file_name) + strlen(ecp_file_name) + 1, + sizeof(char)); + + if (file_name == NULL) { + FREE(ecp); +DEBUG + return NULL; + } + + strcpy (file_name, file->parent.file_name); + strcat (file_name, ecp_file_name); + + /* If the file exists, read it */ + FILE* f = fopen(file_name,"r"); + if (f != NULL) { + + /* Find size of file to allocate the max size of the string buffer */ + fseek(f, 0L, SEEK_END); + size_t sz = ftell(f); + fseek(f, 0L, SEEK_SET); + + char* buffer = CALLOC(sz,char); + if (buffer == NULL) { + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + /* Read the dimensioning variables */ + int rc; + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_lmax_plus_1") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_lmax_plus_1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_lmax_plus_1 = 1; + for (unsigned int i=0; irank_ecp_lmax_plus_1; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_lmax_plus_1") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_lmax_plus_1[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_lmax_plus_1 *= ecp->dims_ecp_lmax_plus_1[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_z_core") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_z_core)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_z_core = 1; + for (unsigned int i=0; irank_ecp_z_core; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_z_core") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_z_core[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_z_core *= ecp->dims_ecp_z_core[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_local_n") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_local_n)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_local_n = 1; + for (unsigned int i=0; irank_ecp_local_n; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_local_n") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_local_n[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_local_n *= ecp->dims_ecp_local_n[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_local_exponent") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_local_exponent)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_local_exponent = 1; + for (unsigned int i=0; irank_ecp_local_exponent; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_local_exponent") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_local_exponent[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_local_exponent *= ecp->dims_ecp_local_exponent[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_local_coef") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_local_coef)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_local_coef = 1; + for (unsigned int i=0; irank_ecp_local_coef; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_local_coef") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_local_coef[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_local_coef *= ecp->dims_ecp_local_coef[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_local_power") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_local_power)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_local_power = 1; + for (unsigned int i=0; irank_ecp_local_power; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_local_power") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_local_power[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_local_power *= ecp->dims_ecp_local_power[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_non_local_n") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_non_local_n)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_non_local_n = 1; + for (unsigned int i=0; irank_ecp_non_local_n; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_non_local_n") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_non_local_n[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_non_local_n *= ecp->dims_ecp_non_local_n[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_non_local_exponent") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_non_local_exponent)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_non_local_exponent = 1; + for (unsigned int i=0; irank_ecp_non_local_exponent; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_non_local_exponent") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_non_local_exponent[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_non_local_exponent *= ecp->dims_ecp_non_local_exponent[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_non_local_coef") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_non_local_coef)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_non_local_coef = 1; + for (unsigned int i=0; irank_ecp_non_local_coef; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_non_local_coef") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_non_local_coef[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_non_local_coef *= ecp->dims_ecp_non_local_coef[i]; + } + + + rc = fscanf(f, "%s", buffer); + if ((rc != 1) || (strcmp(buffer, "rank_ecp_non_local_power") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%u", &(ecp->rank_ecp_non_local_power)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + uint64_t size_ecp_non_local_power = 1; + for (unsigned int i=0; irank_ecp_non_local_power; i++){ + + unsigned int j=-1; + rc = fscanf(f, "%s %u", buffer, &j); + if ((rc != 2) || (strcmp(buffer, "dims_ecp_non_local_power") != 0) || (j!=i)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu\n", &(ecp->dims_ecp_non_local_power[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + size_ecp_non_local_power *= ecp->dims_ecp_non_local_power[i]; + } + + + + /* Read data */ + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_local_num_n_max") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_local_num_n_max") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu", &(ecp->ecp_local_num_n_max)); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + + /* Read data */ + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_non_local_num_n_max") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_non_local_num_n_max") != 0)) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%lu", &(ecp->ecp_non_local_num_n_max)); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + + + /* Allocate arrays */ + ecp->ecp_lmax_plus_1 = (int64_t*) calloc(size_ecp_lmax_plus_1, sizeof(int64_t)); + assert (!(ecp->ecp_lmax_plus_1 == NULL)); + if (ecp->ecp_lmax_plus_1 == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_lmax_plus_1") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_lmax_plus_1") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_lmax_plus_1); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_lmax_plus_1[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_lmax_plus_1); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_z_core = (int64_t*) calloc(size_ecp_z_core, sizeof(int64_t)); + assert (!(ecp->ecp_z_core == NULL)); + if (ecp->ecp_z_core == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_z_core") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_z_core") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_z_core); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_z_core[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_z_core); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_local_n = (int64_t*) calloc(size_ecp_local_n, sizeof(int64_t)); + assert (!(ecp->ecp_local_n == NULL)); + if (ecp->ecp_local_n == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_local_n") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_local_n") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_n); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_local_n[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_n); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_local_exponent = (double*) calloc(size_ecp_local_exponent, sizeof(double)); + assert (!(ecp->ecp_local_exponent == NULL)); + if (ecp->ecp_local_exponent == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_local_exponent") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_local_exponent") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_exponent); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_local_exponent[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_exponent); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_local_coef = (double*) calloc(size_ecp_local_coef, sizeof(double)); + assert (!(ecp->ecp_local_coef == NULL)); + if (ecp->ecp_local_coef == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_local_coef") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_local_coef") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_coef); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_local_coef[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_coef); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_local_power = (int64_t*) calloc(size_ecp_local_power, sizeof(int64_t)); + assert (!(ecp->ecp_local_power == NULL)); + if (ecp->ecp_local_power == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_local_power") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_local_power") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_power); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_local_power[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_local_power); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_non_local_n = (int64_t*) calloc(size_ecp_non_local_n, sizeof(int64_t)); + assert (!(ecp->ecp_non_local_n == NULL)); + if (ecp->ecp_non_local_n == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_non_local_n") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_non_local_n") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_n); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_non_local_n[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_n); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_non_local_exponent = (double*) calloc(size_ecp_non_local_exponent, sizeof(double)); + assert (!(ecp->ecp_non_local_exponent == NULL)); + if (ecp->ecp_non_local_exponent == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_non_local_exponent") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_non_local_exponent") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_exponent); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_non_local_exponent[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_exponent); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_non_local_coef = (double*) calloc(size_ecp_non_local_coef, sizeof(double)); + assert (!(ecp->ecp_non_local_coef == NULL)); + if (ecp->ecp_non_local_coef == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_non_local_coef") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_non_local_coef") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_coef); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_non_local_coef[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_coef); + FREE(ecp); +DEBUG + return NULL; + } + } + + + /* Allocate arrays */ + ecp->ecp_non_local_power = (int64_t*) calloc(size_ecp_non_local_power, sizeof(int64_t)); + assert (!(ecp->ecp_non_local_power == NULL)); + if (ecp->ecp_non_local_power == NULL) { + FREE(buffer); + FREE(file_name); + FREE(ecp); +DEBUG + return NULL; + } + + rc = fscanf(f, "%s", buffer); + assert(!((rc != 1) || (strcmp(buffer, "ecp_non_local_power") != 0))); + if ((rc != 1) || (strcmp(buffer, "ecp_non_local_power") != 0)) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_power); + FREE(ecp); +DEBUG + return NULL; + } + + for (uint64_t i=0 ; iecp_non_local_power[i])); + assert(!(rc != 1)); + if (rc != 1) { + FREE(buffer); + FREE(file_name); + // TODO: free all dsets + FREE(ecp->ecp_non_local_power); + FREE(ecp); +DEBUG + return NULL; + } + } + + + FREE(buffer); + fclose(f); + f = NULL; + } + + if (file->parent.mode == 'w') { + ecp->file = fopen(file_name,"a"); + } else { + ecp->file = fopen(file_name,"r"); + } + FREE(file_name); + assert (!(ecp->file == NULL)); + if (ecp->file == NULL) { + // TODO: free all dsets + FREE(ecp->ecp_lmax_plus_1); + FREE(ecp->ecp_z_core); + FREE(ecp->ecp_local_n); + FREE(ecp->ecp_local_exponent); + FREE(ecp->ecp_local_coef); + FREE(ecp->ecp_local_power); + FREE(ecp->ecp_non_local_n); + FREE(ecp->ecp_non_local_exponent); + FREE(ecp->ecp_non_local_coef); + FREE(ecp->ecp_non_local_power); + FREE(ecp); +DEBUG + return NULL; + } + + fseek(ecp->file, 0L, SEEK_SET); + file->ecp = ecp; + return ecp; +} trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -373,68 +1447,515 @@ trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file) { rewind(f); /* Write the dimensioning variables */ - fprintf(f, "rank_charge %d\n", nucleus->rank_charge); + + + fprintf(f, "rank_nucleus_charge %d\n", nucleus->rank_nucleus_charge); - uint64_t size_charge = 1; - for (unsigned int i=0; irank_charge; i++){ - fprintf(f, "dims_charge %d %ld\n", i, nucleus->dims_charge[i]); - size_charge *= nucleus->dims_charge[i]; + uint64_t size_nucleus_charge = 1; + for (unsigned int i=0; irank_nucleus_charge; i++){ + fprintf(f, "dims_nucleus_charge %d %ld\n", i, nucleus->dims_nucleus_charge[i]); + size_nucleus_charge *= nucleus->dims_nucleus_charge[i]; } - fprintf(f, "rank_coord %d\n", nucleus->rank_coord); + + fprintf(f, "rank_nucleus_coord %d\n", nucleus->rank_nucleus_coord); - uint64_t size_coord = 1; - for (unsigned int i=0; irank_coord; i++){ - fprintf(f, "dims_coord %d %ld\n", i, nucleus->dims_coord[i]); - size_coord *= nucleus->dims_coord[i]; + uint64_t size_nucleus_coord = 1; + for (unsigned int i=0; irank_nucleus_coord; i++){ + fprintf(f, "dims_nucleus_coord %d %ld\n", i, nucleus->dims_nucleus_coord[i]); + size_nucleus_coord *= nucleus->dims_nucleus_coord[i]; } + + + fprintf(f, "nucleus_num %ld\n", nucleus->nucleus_num); + + + /* Write arrays */ - fprintf(f, "num %ld\n", nucleus->num); - fprintf(f, "charge\n"); - for (uint64_t i=0 ; icharge[i]); + + fprintf(f, "nucleus_charge\n"); + for (uint64_t i=0 ; inucleus_charge[i]); } - fprintf(f, "coord\n"); - for (uint64_t i=0 ; icoord[i]); + + /* Write arrays */ + + fprintf(f, "nucleus_coord\n"); + for (uint64_t i=0 ; inucleus_coord[i]); } + + fflush(f); file->nucleus->to_flush = 0; return TREXIO_SUCCESS; } - -trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file) { +trexio_exit_code trexio_text_flush_ecp(const trexio_text_t* file) { if (file == NULL) return TREXIO_INVALID_ARG_1; + + if (file->parent.mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = file->ecp; - trexio_exit_code rc; + if (ecp == NULL) return TREXIO_SUCCESS; - if (file->parent.mode != 'r') { - rc = trexio_text_flush_nucleus(file); - if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE; - } + if (ecp->to_flush == 0) return TREXIO_SUCCESS; - nucleus_t* nucleus = file->nucleus; - if (nucleus == NULL) return TREXIO_SUCCESS; + FILE* f = ecp->file; + assert (f != NULL); + rewind(f); - if (nucleus->file != NULL) { - fclose(nucleus->file); - nucleus->file = NULL; - } - - if (nucleus->coord != NULL) { - FREE (nucleus->coord); - } + /* Write the dimensioning variables */ - if (nucleus->charge != NULL) { - FREE (nucleus->charge); - } + + fprintf(f, "rank_ecp_lmax_plus_1 %d\n", ecp->rank_ecp_lmax_plus_1); + + uint64_t size_ecp_lmax_plus_1 = 1; + for (unsigned int i=0; irank_ecp_lmax_plus_1; i++){ + fprintf(f, "dims_ecp_lmax_plus_1 %d %ld\n", i, ecp->dims_ecp_lmax_plus_1[i]); + size_ecp_lmax_plus_1 *= ecp->dims_ecp_lmax_plus_1[i]; + } + + + fprintf(f, "rank_ecp_z_core %d\n", ecp->rank_ecp_z_core); + + uint64_t size_ecp_z_core = 1; + for (unsigned int i=0; irank_ecp_z_core; i++){ + fprintf(f, "dims_ecp_z_core %d %ld\n", i, ecp->dims_ecp_z_core[i]); + size_ecp_z_core *= ecp->dims_ecp_z_core[i]; + } + + + fprintf(f, "rank_ecp_local_n %d\n", ecp->rank_ecp_local_n); + + uint64_t size_ecp_local_n = 1; + for (unsigned int i=0; irank_ecp_local_n; i++){ + fprintf(f, "dims_ecp_local_n %d %ld\n", i, ecp->dims_ecp_local_n[i]); + size_ecp_local_n *= ecp->dims_ecp_local_n[i]; + } + + + fprintf(f, "rank_ecp_local_exponent %d\n", ecp->rank_ecp_local_exponent); + + uint64_t size_ecp_local_exponent = 1; + for (unsigned int i=0; irank_ecp_local_exponent; i++){ + fprintf(f, "dims_ecp_local_exponent %d %ld\n", i, ecp->dims_ecp_local_exponent[i]); + size_ecp_local_exponent *= ecp->dims_ecp_local_exponent[i]; + } + + + fprintf(f, "rank_ecp_local_coef %d\n", ecp->rank_ecp_local_coef); + + uint64_t size_ecp_local_coef = 1; + for (unsigned int i=0; irank_ecp_local_coef; i++){ + fprintf(f, "dims_ecp_local_coef %d %ld\n", i, ecp->dims_ecp_local_coef[i]); + size_ecp_local_coef *= ecp->dims_ecp_local_coef[i]; + } + + + fprintf(f, "rank_ecp_local_power %d\n", ecp->rank_ecp_local_power); + + uint64_t size_ecp_local_power = 1; + for (unsigned int i=0; irank_ecp_local_power; i++){ + fprintf(f, "dims_ecp_local_power %d %ld\n", i, ecp->dims_ecp_local_power[i]); + size_ecp_local_power *= ecp->dims_ecp_local_power[i]; + } + + + fprintf(f, "rank_ecp_non_local_n %d\n", ecp->rank_ecp_non_local_n); + + uint64_t size_ecp_non_local_n = 1; + for (unsigned int i=0; irank_ecp_non_local_n; i++){ + fprintf(f, "dims_ecp_non_local_n %d %ld\n", i, ecp->dims_ecp_non_local_n[i]); + size_ecp_non_local_n *= ecp->dims_ecp_non_local_n[i]; + } + + + fprintf(f, "rank_ecp_non_local_exponent %d\n", ecp->rank_ecp_non_local_exponent); + + uint64_t size_ecp_non_local_exponent = 1; + for (unsigned int i=0; irank_ecp_non_local_exponent; i++){ + fprintf(f, "dims_ecp_non_local_exponent %d %ld\n", i, ecp->dims_ecp_non_local_exponent[i]); + size_ecp_non_local_exponent *= ecp->dims_ecp_non_local_exponent[i]; + } + + + fprintf(f, "rank_ecp_non_local_coef %d\n", ecp->rank_ecp_non_local_coef); + + uint64_t size_ecp_non_local_coef = 1; + for (unsigned int i=0; irank_ecp_non_local_coef; i++){ + fprintf(f, "dims_ecp_non_local_coef %d %ld\n", i, ecp->dims_ecp_non_local_coef[i]); + size_ecp_non_local_coef *= ecp->dims_ecp_non_local_coef[i]; + } + + + fprintf(f, "rank_ecp_non_local_power %d\n", ecp->rank_ecp_non_local_power); + + uint64_t size_ecp_non_local_power = 1; + for (unsigned int i=0; irank_ecp_non_local_power; i++){ + fprintf(f, "dims_ecp_non_local_power %d %ld\n", i, ecp->dims_ecp_non_local_power[i]); + size_ecp_non_local_power *= ecp->dims_ecp_non_local_power[i]; + } + + + + fprintf(f, "ecp_local_num_n_max %ld\n", ecp->ecp_local_num_n_max); + + + fprintf(f, "ecp_non_local_num_n_max %ld\n", ecp->ecp_non_local_num_n_max); + + - FREE (nucleus); + /* Write arrays */ + + fprintf(f, "ecp_lmax_plus_1\n"); + for (uint64_t i=0 ; iecp_lmax_plus_1[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_z_core\n"); + for (uint64_t i=0 ; iecp_z_core[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_local_n\n"); + for (uint64_t i=0 ; iecp_local_n[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_local_exponent\n"); + for (uint64_t i=0 ; iecp_local_exponent[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_local_coef\n"); + for (uint64_t i=0 ; iecp_local_coef[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_local_power\n"); + for (uint64_t i=0 ; iecp_local_power[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_non_local_n\n"); + for (uint64_t i=0 ; iecp_non_local_n[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_non_local_exponent\n"); + for (uint64_t i=0 ; iecp_non_local_exponent[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_non_local_coef\n"); + for (uint64_t i=0 ; iecp_non_local_coef[i]); + } + + + /* Write arrays */ + + fprintf(f, "ecp_non_local_power\n"); + for (uint64_t i=0 ; iecp_non_local_power[i]); + } + + + fflush(f); + file->ecp->to_flush = 0; return TREXIO_SUCCESS; } +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* nucleus_charge, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_charge == NULL) return TREXIO_INVALID_ARG_2; + + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); + if (nucleus == NULL) return TREXIO_FAILURE; + + if (rank != nucleus->rank_nucleus_charge) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_nucleus_charge[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; inucleus_charge[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* nucleus_coord, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_coord == NULL) return TREXIO_INVALID_ARG_2; + + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); + if (nucleus == NULL) return TREXIO_FAILURE; + + if (rank != nucleus->rank_nucleus_coord) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_nucleus_coord[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; inucleus_coord[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_lmax_plus_1(const trexio_t* file, int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_lmax_plus_1 == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_lmax_plus_1) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_lmax_plus_1[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_lmax_plus_1[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_z_core(const trexio_t* file, int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_z_core == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_z_core) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_z_core[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_z_core[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_local_n(const trexio_t* file, int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_n == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_local_n) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_local_n[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_local_n[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_local_exponent(const trexio_t* file, double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_local_exponent) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_local_exponent[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_local_exponent[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_local_coef(const trexio_t* file, double* ecp_local_coef, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_local_coef) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_local_coef[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_local_coef[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_local_power(const trexio_t* file, int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_power == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_local_power) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_local_power[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_local_power[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_non_local_n(const trexio_t* file, int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_n == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_non_local_n) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_non_local_n[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_non_local_n[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_non_local_exponent(const trexio_t* file, double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_non_local_exponent) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_non_local_exponent[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_non_local_exponent[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_non_local_coef(const trexio_t* file, double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_non_local_coef) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_non_local_coef[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_non_local_coef[i]; + } + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_non_local_power(const trexio_t* file, int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_power == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (rank != ecp->rank_ecp_non_local_power) return TREXIO_INVALID_ARG_3; + + uint64_t dim_size = 1; + for (unsigned int i=0; idims_ecp_non_local_power[i]) return TREXIO_INVALID_ARG_4; + dim_size *= dims[i]; + } + + for (uint64_t i=0 ; iecp_non_local_power[i]; + } + + return TREXIO_SUCCESS; +} trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -443,12 +1964,394 @@ trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* nu nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) return TREXIO_FAILURE; - /**/ *num = nucleus->num; + /**/ *num = nucleus->nucleus_num; return TREXIO_SUCCESS; } +trexio_exit_code trexio_text_read_ecp_local_num_n_max(const trexio_t* file, uint64_t* num) { - + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (num == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + /**/ *num = ecp->ecp_local_num_n_max; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_read_ecp_non_local_num_n_max(const trexio_t* file, uint64_t* num) { + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (num == NULL) return TREXIO_INVALID_ARG_2; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + /**/ *num = ecp->ecp_non_local_num_n_max; + + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* nucleus_charge, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_charge == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); + if (nucleus == NULL) return TREXIO_FAILURE; + + if (nucleus->nucleus_charge != NULL) { + FREE(nucleus->nucleus_charge); + } + + nucleus->rank_nucleus_charge = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_nucleus_charge; i++){ + nucleus->dims_nucleus_charge[i] = dims[i]; + dim_size *= dims[i]; + } + + nucleus->nucleus_charge = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; inucleus_charge[i] = nucleus_charge[i]; + } + + nucleus->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* nucleus_coord, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (nucleus_coord == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); + if (nucleus == NULL) return TREXIO_FAILURE; + + if (nucleus->nucleus_coord != NULL) { + FREE(nucleus->nucleus_coord); + } + + nucleus->rank_nucleus_coord = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_nucleus_coord; i++){ + nucleus->dims_nucleus_coord[i] = dims[i]; + dim_size *= dims[i]; + } + + nucleus->nucleus_coord = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; inucleus_coord[i] = nucleus_coord[i]; + } + + nucleus->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_lmax_plus_1(const trexio_t* file, const int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_lmax_plus_1 == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_lmax_plus_1 != NULL) { + FREE(ecp->ecp_lmax_plus_1); + } + + ecp->rank_ecp_lmax_plus_1 = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_lmax_plus_1; i++){ + ecp->dims_ecp_lmax_plus_1[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_lmax_plus_1 = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_lmax_plus_1[i] = ecp_lmax_plus_1[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_z_core(const trexio_t* file, const int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_z_core == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_z_core != NULL) { + FREE(ecp->ecp_z_core); + } + + ecp->rank_ecp_z_core = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_z_core; i++){ + ecp->dims_ecp_z_core[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_z_core = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_z_core[i] = ecp_z_core[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_local_n(const trexio_t* file, const int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_n == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_local_n != NULL) { + FREE(ecp->ecp_local_n); + } + + ecp->rank_ecp_local_n = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_local_n; i++){ + ecp->dims_ecp_local_n[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_local_n = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_local_n[i] = ecp_local_n[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_local_exponent(const trexio_t* file, const double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_local_exponent != NULL) { + FREE(ecp->ecp_local_exponent); + } + + ecp->rank_ecp_local_exponent = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_local_exponent; i++){ + ecp->dims_ecp_local_exponent[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_local_exponent = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; iecp_local_exponent[i] = ecp_local_exponent[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_local_coef(const trexio_t* file, const double* ecp_local_coef, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_local_coef != NULL) { + FREE(ecp->ecp_local_coef); + } + + ecp->rank_ecp_local_coef = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_local_coef; i++){ + ecp->dims_ecp_local_coef[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_local_coef = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; iecp_local_coef[i] = ecp_local_coef[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_local_power(const trexio_t* file, const int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_local_power == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_local_power != NULL) { + FREE(ecp->ecp_local_power); + } + + ecp->rank_ecp_local_power = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_local_power; i++){ + ecp->dims_ecp_local_power[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_local_power = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_local_power[i] = ecp_local_power[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_non_local_n(const trexio_t* file, const int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_n == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_non_local_n != NULL) { + FREE(ecp->ecp_non_local_n); + } + + ecp->rank_ecp_non_local_n = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_non_local_n; i++){ + ecp->dims_ecp_non_local_n[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_non_local_n = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_non_local_n[i] = ecp_non_local_n[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_non_local_exponent(const trexio_t* file, const double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_exponent == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_non_local_exponent != NULL) { + FREE(ecp->ecp_non_local_exponent); + } + + ecp->rank_ecp_non_local_exponent = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_non_local_exponent; i++){ + ecp->dims_ecp_non_local_exponent[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_non_local_exponent = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; iecp_non_local_exponent[i] = ecp_non_local_exponent[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_non_local_coef(const trexio_t* file, const double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_coef == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_non_local_coef != NULL) { + FREE(ecp->ecp_non_local_coef); + } + + ecp->rank_ecp_non_local_coef = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_non_local_coef; i++){ + ecp->dims_ecp_non_local_coef[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_non_local_coef = (double*) calloc(dim_size, sizeof(double)); + + for (uint64_t i=0 ; iecp_non_local_coef[i] = ecp_non_local_coef[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} +trexio_exit_code trexio_text_write_ecp_non_local_power(const trexio_t* file, const int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims) { + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (ecp_non_local_power == NULL) return TREXIO_INVALID_ARG_2; + + if (file->mode == 'r') return TREXIO_READONLY; + + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + if (ecp->ecp_non_local_power != NULL) { + FREE(ecp->ecp_non_local_power); + } + + ecp->rank_ecp_non_local_power = rank; + + uint64_t dim_size = 1; + for (unsigned int i=0; irank_ecp_non_local_power; i++){ + ecp->dims_ecp_non_local_power[i] = dims[i]; + dim_size *= dims[i]; + } + + ecp->ecp_non_local_power = (int64_t*) calloc(dim_size, sizeof(int64_t)); + + for (uint64_t i=0 ; iecp_non_local_power[i] = ecp_non_local_power[i]; + } + + ecp->to_flush = 1; + return TREXIO_SUCCESS; +} trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -458,122 +2361,39 @@ trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint6 nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) return TREXIO_FAILURE; - nucleus->num = num; + nucleus->nucleus_num = num; nucleus->to_flush = 1; return TREXIO_SUCCESS; } +trexio_exit_code trexio_text_write_ecp_local_num_n_max(const trexio_t* file, const uint64_t num) { -trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) { - - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (coord == NULL) return TREXIO_INVALID_ARG_2; - - nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); - if (nucleus == NULL) return TREXIO_FAILURE; - - if (rank != nucleus->rank_coord) return TREXIO_INVALID_ARG_3; - - uint64_t dim_size = 1; - for (unsigned int i=0; idims_coord[i]) return TREXIO_INVALID_ARG_4; - dim_size *= dims[i]; - } - - for (uint64_t i=0 ; icoord[i]; - } - - return TREXIO_SUCCESS; -} - - -trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (coord == NULL) return TREXIO_INVALID_ARG_2; + if (file == NULL) return TREXIO_INVALID_ARG_1; if (file->mode == 'r') return TREXIO_READONLY; - - nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); - if (nucleus == NULL) return TREXIO_FAILURE; - if (nucleus->coord != NULL) { - FREE(nucleus->coord); - } - - nucleus->rank_coord = rank; + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; - uint64_t dim_size = 1; - for (unsigned int i=0; irank_coord; i++){ - nucleus->dims_coord[i] = dims[i]; - dim_size *= dims[i]; - } - - nucleus->coord = (double*) calloc(dim_size, sizeof(double)); - - for (uint64_t i=0 ; icoord[i] = coord[i]; - } + ecp->ecp_local_num_n_max = num; + ecp->to_flush = 1; - nucleus->to_flush = 1; return TREXIO_SUCCESS; } +trexio_exit_code trexio_text_write_ecp_non_local_num_n_max(const trexio_t* file, const uint64_t num) { -trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims) { - - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (charge == NULL) return TREXIO_INVALID_ARG_2; - - nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); - if (nucleus == NULL) return TREXIO_FAILURE; - - if (rank != nucleus->rank_charge) return TREXIO_INVALID_ARG_3; - - uint64_t dim_size = 1; - for (unsigned int i=0; idims_charge[i]) return TREXIO_INVALID_ARG_4; - dim_size *= dims[i]; - } - - for (uint64_t i=0 ; icharge[i]; - } - - return TREXIO_SUCCESS; -} - - -trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims) { - if (file == NULL) return TREXIO_INVALID_ARG_1; - if (charge == NULL) return TREXIO_INVALID_ARG_2; + if (file == NULL) return TREXIO_INVALID_ARG_1; if (file->mode == 'r') return TREXIO_READONLY; - - nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); - if (nucleus == NULL) return TREXIO_FAILURE; - if (nucleus->charge != NULL) { - FREE(nucleus->charge); - } - - nucleus->rank_charge = rank; - - uint64_t dim_size = 1; - for (unsigned int i=0; irank_charge; i++){ - nucleus->dims_charge[i] = dims[i]; - dim_size *= dims[i]; - } - - nucleus->charge = (double*) calloc(dim_size, sizeof(double)); - - for (uint64_t i=0 ; icharge[i] = charge[i]; - } + ecp_t* ecp = trexio_text_read_ecp((trexio_text_t*) file); + if (ecp == NULL) return TREXIO_FAILURE; + + ecp->ecp_non_local_num_n_max = num; + ecp->to_flush = 1; - nucleus->to_flush = 1; return TREXIO_SUCCESS; } - rdm_t* trexio_text_read_rdm(trexio_text_t* file) { if (file == NULL) return NULL; diff --git a/src/trexio_text.h b/src/trexio_text.h index abaaa43..fc310d7 100644 --- a/src/trexio_text.h +++ b/src/trexio_text.h @@ -20,26 +20,53 @@ #include #include #include - typedef struct nucleus_s { FILE* file; - double* coord; - double* charge; - uint64_t num; - uint64_t dims_charge[16]; - uint64_t dims_coord[16]; - uint32_t rank_charge; - uint32_t rank_coord; + double* nucleus_charge; + double* nucleus_coord; + uint64_t nucleus_num; + uint64_t dims_nucleus_charge[16]; + uint64_t dims_nucleus_coord[16]; + uint32_t rank_nucleus_charge; + uint32_t rank_nucleus_coord; int to_flush; } nucleus_t; - -typedef struct electron_s { +typedef struct ecp_s { FILE* file; - uint64_t alpha_num; - uint64_t beta_num; - int to_flush; -} electron_t; - + int64_t* ecp_lmax_plus_1; + int64_t* ecp_z_core; + int64_t* ecp_local_n; + double* ecp_local_exponent; + double* ecp_local_coef; + int64_t* ecp_local_power; + int64_t* ecp_non_local_n; + double* ecp_non_local_exponent; + double* ecp_non_local_coef; + int64_t* ecp_non_local_power; + uint64_t ecp_local_num_n_max; + uint64_t ecp_non_local_num_n_max; + uint64_t dims_ecp_lmax_plus_1[16]; + uint64_t dims_ecp_z_core[16]; + uint64_t dims_ecp_local_n[16]; + uint64_t dims_ecp_local_exponent[16]; + uint64_t dims_ecp_local_coef[16]; + uint64_t dims_ecp_local_power[16]; + uint64_t dims_ecp_non_local_n[16]; + uint64_t dims_ecp_non_local_exponent[16]; + uint64_t dims_ecp_non_local_coef[16]; + uint64_t dims_ecp_non_local_power[16]; + uint32_t rank_ecp_lmax_plus_1; + uint32_t rank_ecp_z_core; + uint32_t rank_ecp_local_n; + uint32_t rank_ecp_local_exponent; + uint32_t rank_ecp_local_coef; + uint32_t rank_ecp_local_power; + uint32_t rank_ecp_non_local_n; + uint32_t rank_ecp_non_local_exponent; + uint32_t rank_ecp_non_local_coef; + uint32_t rank_ecp_non_local_power; + int to_flush; +} ecp_t; typedef struct rdm_s { FILE* file; uint64_t dim_one_e; @@ -51,12 +78,10 @@ typedef struct rdm_s { typedef struct trexio_text_s { trexio_t parent ; int lock_file; - - nucleus_t* nucleus; - electron_t* electron; + nucleus_t* nucleus; + ecp_t* ecp; rdm_t* rdm; } trexio_text_t; - trexio_exit_code trexio_text_init(trexio_t* file); trexio_exit_code trexio_text_lock(trexio_t* file); @@ -64,22 +89,42 @@ trexio_exit_code trexio_text_lock(trexio_t* file); trexio_exit_code trexio_text_finalize(trexio_t* file); trexio_exit_code trexio_text_unlock(trexio_t* file); - -nucleus_t* trexio_text_read_nucleus(trexio_text_t* file); - -trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file); - trexio_exit_code trexio_text_free_nucleus(trexio_text_t* file); - +trexio_exit_code trexio_text_free_ecp(trexio_text_t* file); +nucleus_t* trexio_text_read_nucleus(trexio_text_t* file); +ecp_t* trexio_text_read_ecp(trexio_text_t* file); +trexio_exit_code trexio_text_flush_nucleus(const trexio_text_t* file); +trexio_exit_code trexio_text_flush_ecp(const trexio_text_t* file); trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num); trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num); - -trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims); -trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims); - -trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge, const uint32_t rank, const uint64_t* dims); -trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge, const uint32_t rank, const uint64_t* dims); - +trexio_exit_code trexio_text_read_ecp_local_num_n_max(const trexio_t* file, uint64_t* num); +trexio_exit_code trexio_text_write_ecp_local_num_n_max(const trexio_t* file, const uint64_t num); +trexio_exit_code trexio_text_read_ecp_non_local_num_n_max(const trexio_t* file, uint64_t* num); +trexio_exit_code trexio_text_write_ecp_non_local_num_n_max(const trexio_t* file, const uint64_t num); +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* nucleus_charge, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* nucleus_charge, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* nucleus_coord, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* nucleus_coord, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_lmax_plus_1(const trexio_t* file, int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_lmax_plus_1(const trexio_t* file, const int64_t* ecp_lmax_plus_1, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_z_core(const trexio_t* file, int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_z_core(const trexio_t* file, const int64_t* ecp_z_core, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_local_n(const trexio_t* file, int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_local_n(const trexio_t* file, const int64_t* ecp_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_local_exponent(const trexio_t* file, double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_local_exponent(const trexio_t* file, const double* ecp_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_local_coef(const trexio_t* file, double* ecp_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_local_coef(const trexio_t* file, const double* ecp_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_local_power(const trexio_t* file, int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_local_power(const trexio_t* file, const int64_t* ecp_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_non_local_n(const trexio_t* file, int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_non_local_n(const trexio_t* file, const int64_t* ecp_non_local_n, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_non_local_exponent(const trexio_t* file, double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_non_local_exponent(const trexio_t* file, const double* ecp_non_local_exponent, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_non_local_coef(const trexio_t* file, double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_non_local_coef(const trexio_t* file, const double* ecp_non_local_coef, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_read_ecp_non_local_power(const trexio_t* file, int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims); +trexio_exit_code trexio_text_write_ecp_non_local_power(const trexio_t* file, const int64_t* ecp_non_local_power, const uint32_t rank, const uint64_t* dims); rdm_t* trexio_text_read_rdm(trexio_text_t* file); trexio_exit_code trexio_text_flush_rdm(const trexio_text_t* file); @@ -91,5 +136,4 @@ trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double* trexio_exit_code trexio_text_buffered_read_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, int64_t* index, double* value); trexio_exit_code trexio_text_buffered_write_rdm_two_e(const trexio_t* file, const uint64_t offset, const uint64_t size, const int64_t* index, const double* value); - #endif