mirror of
https://github.com/TREX-CoE/trexio.git
synced 2025-04-26 10:24:44 +02:00
remove old files
This commit is contained in:
parent
3428657560
commit
c0f2bd3106
1526
src/trexio.c
1526
src/trexio.c
File diff suppressed because it is too large
Load Diff
69
src/trexio.h
69
src/trexio.h
@ -1,69 +0,0 @@
|
||||
/* This file was generated from the trexio.org org-mode file.
|
||||
To generate it, open trexio.org in Emacs and execute
|
||||
M-x org-babel-tangle
|
||||
*/
|
||||
|
||||
#ifndef _TREXIO_H
|
||||
#define _TREXIO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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 )
|
||||
|
||||
typedef int32_t back_end_t;
|
||||
|
||||
#define TREXIO_HDF5 ( (back_end_t) 0 )
|
||||
#define TREXIO_TEXT ( (back_end_t) 1 )
|
||||
#define TREXIO_JSON ( (back_end_t) 2 )
|
||||
#define TREXIO_INVALID_BACK_END ( (back_end_t) 3 )
|
||||
|
||||
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_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
|
708
src/trexio.org
708
src/trexio.org
@ -1,708 +0,0 @@
|
||||
#+Title: TREX Input/Ouput library (TREXIO)
|
||||
|
||||
* File prefixes :noxport:
|
||||
|
||||
#+NAME:header
|
||||
#+begin_src c
|
||||
/* This file was generated from the trexio.org org-mode file.
|
||||
To generate it, open trexio.org in Emacs and execute
|
||||
M-x org-babel-tangle
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.h :noweb yes
|
||||
<<header>>
|
||||
#ifndef _TREXIO_H
|
||||
#define _TREXIO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c :noweb yes
|
||||
<<header>>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "trexio.h"
|
||||
#include "trexio_s.h"
|
||||
#include "trexio_text.h"
|
||||
#include "trexio_hdf5.h"
|
||||
/*
|
||||
#include "trexio_json.h"
|
||||
,*/
|
||||
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_s.h :noweb yes
|
||||
<<header>>
|
||||
#ifndef _TREXIO_S_H
|
||||
#define _TREXIO_S_H
|
||||
|
||||
#include "trexio.h"
|
||||
#include "trexio_private.h"
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
#+end_src
|
||||
|
||||
* Coding conventions
|
||||
|
||||
- integer types will be defined using types given in ~stdint.h~
|
||||
- pointers are always initialized to ~NULL~
|
||||
- when memory is freed, the pointer is set to ~NULL~
|
||||
- ~assert.h~ should be used extensively
|
||||
- variable names are in lower case
|
||||
- ~#define~ constants are in upper case
|
||||
- structs are suffixed by ~_s~
|
||||
- types are suffixed by ~_t~
|
||||
|
||||
** Memory allocation
|
||||
|
||||
Memory allocation of structures can be facilitated by using the
|
||||
following macro, which ensures that the size of the allocated
|
||||
object is the same as the size of the data type pointed by the pointer.
|
||||
|
||||
#+begin_src c :tangle trexio_private.h
|
||||
#define MALLOC(T) (T*) malloc (sizeof(T));
|
||||
#define CALLOC(N,T) (T*) calloc ((N),sizeof(T));
|
||||
#+end_src
|
||||
|
||||
When a pointer is freed, it should be set to ~NULL~.
|
||||
This can be facilitated by the use of the following macro:
|
||||
|
||||
#+begin_src c :tangle trexio_private.h
|
||||
#define FREE(X) { free(X) ; (X)=NULL; }
|
||||
#+end_src
|
||||
|
||||
* Front end
|
||||
|
||||
All calls to TREXIO are thread-safe.
|
||||
|
||||
** Error handling
|
||||
#+begin_src c :tangle trexio.h
|
||||
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 )
|
||||
#+end_src
|
||||
|
||||
** Back ends
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
typedef int32_t back_end_t;
|
||||
|
||||
#define TREXIO_HDF5 ( (back_end_t) 0 )
|
||||
#define TREXIO_TEXT ( (back_end_t) 1 )
|
||||
#define TREXIO_JSON ( (back_end_t) 2 )
|
||||
#define TREXIO_INVALID_BACK_END ( (back_end_t) 3 )
|
||||
#+end_src
|
||||
|
||||
** Read/write behavior
|
||||
|
||||
Every time a reading function is called, the data is read from the
|
||||
disk. If data needs to be cached, this is left to the user of the
|
||||
library.
|
||||
|
||||
Writing to TREXIO files is done with transactions (all-or-nothing
|
||||
effect) in a per-group fashion. File writes are attempted by
|
||||
calling explicitly the flush function, or when the TREXIO file is
|
||||
closed. If writing is impossible because the data is not valid, no
|
||||
data is written.
|
||||
|
||||
The order in which the data is written is not necessarily consistent
|
||||
with the order in which the function calls were made.
|
||||
|
||||
The TREXIO files are supposed to be opened by only one program at a
|
||||
time: if the same TREXIO file is modified simultaneously by multiple
|
||||
concurrent programs, the behavior is not specified.
|
||||
|
||||
** TREXIO file type
|
||||
|
||||
~trexio_s~ is the the main type for TREXIO files, visible to the users
|
||||
of the library. This type is kept opaque, and all modifications to
|
||||
the files will be necessarily done through the use of functions,
|
||||
taking such a type as argument.
|
||||
|
||||
File creation and opening functions will return /TREXIO file handles/,
|
||||
namely pointers to ~trexio_s~ types. All functions accessing to the
|
||||
TREXIO files will have as a first argument the TREXIO file handle.
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
typedef struct trexio_s trexio_t;
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_s.h
|
||||
struct trexio_s {
|
||||
char* file_name;
|
||||
pthread_mutex_t thread_lock;
|
||||
back_end_t back_end;
|
||||
char mode;
|
||||
char padding[7]; /* Ensures the proper alignment of back-ends */
|
||||
};
|
||||
#+end_src
|
||||
|
||||
** Polymorphism of the file handle
|
||||
|
||||
Polymorphism of the ~trexio_t~ type is handled by ensuring that the
|
||||
corresponding types for all back ends can be safely casted to
|
||||
~trexio_t~. This is done by making the back end structs start with
|
||||
~struct trexio_s~:
|
||||
|
||||
#+begin_src c
|
||||
struct trexio_back_end_s {
|
||||
trexio_t parent ;
|
||||
/* add below specific back end data */
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** File opening
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t back_end) {
|
||||
|
||||
if (file_name == NULL) return NULL;
|
||||
if (file_name[0] == '\0') return NULL;
|
||||
|
||||
if (back_end < 0) return NULL;
|
||||
if (back_end >= TREXIO_INVALID_BACK_END) return NULL;
|
||||
|
||||
if (mode != 'r' && mode != 'w' && mode != 'a') return NULL;
|
||||
|
||||
trexio_t* result = NULL;
|
||||
|
||||
/* Allocate data structures */
|
||||
switch (back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
result = (trexio_t*) malloc (sizeof(trexio_text_t));
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
result = (trexio_t*) malloc (sizeof(trexio_hdf5_t));
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
result = (trexio_t*) malloc (sizeof(trexio_json_t));
|
||||
break;
|
||||
,*/
|
||||
}
|
||||
|
||||
assert (result != NULL); /* TODO: Error handling */
|
||||
|
||||
|
||||
/* Data for the parent type */
|
||||
|
||||
result->file_name = CALLOC(strlen(file_name)+1,char);
|
||||
strcpy(result->file_name, file_name);
|
||||
result->back_end = back_end;
|
||||
result->mode = mode;
|
||||
int irc = pthread_mutex_init ( &(result->thread_lock), NULL);
|
||||
assert (irc == 0);
|
||||
|
||||
trexio_exit_code rc;
|
||||
|
||||
/* Back end initialization */
|
||||
|
||||
rc = TREXIO_FAILURE;
|
||||
|
||||
switch (back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_init(result);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = trexio_hdf5_init(result);
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_init(result);
|
||||
break;
|
||||
,*/
|
||||
}
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
FREE(result->file_name);
|
||||
FREE(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* File locking */
|
||||
|
||||
rc = TREXIO_FAILURE;
|
||||
|
||||
switch (back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_lock(result);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = TREXIO_SUCCESS;
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_lock(result);
|
||||
break;
|
||||
*/
|
||||
}
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
FREE(result->file_name);
|
||||
FREE(result);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** File closing
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
trexio_exit_code trexio_close(trexio_t* file);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
trexio_exit_code trexio_close(trexio_t* file) {
|
||||
|
||||
if (file == NULL) return TREXIO_FAILURE;
|
||||
|
||||
trexio_exit_code rc;
|
||||
|
||||
/* Terminate the back end */
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_finalize(file);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = trexio_hdf5_finalize(file);
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_finalize(file);
|
||||
break;
|
||||
,*/
|
||||
default:
|
||||
assert (1 == 0); /* Impossible case */
|
||||
}
|
||||
|
||||
if (rc != TREXIO_SUCCESS) {
|
||||
FREE(file->file_name);
|
||||
FREE(file);
|
||||
return TREXIO_FAILURE;
|
||||
}
|
||||
|
||||
/* File unlocking */
|
||||
|
||||
rc = TREXIO_FAILURE;
|
||||
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_unlock(file);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = TREXIO_SUCCESS;
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_unlock(file);
|
||||
break;
|
||||
*/
|
||||
}
|
||||
|
||||
/* Terminate front end */
|
||||
|
||||
FREE(file->file_name);
|
||||
|
||||
int irc = pthread_mutex_destroy( &(file->thread_lock) );
|
||||
|
||||
FREE(file);
|
||||
|
||||
if (irc != 0) return TREXIO_ERRNO;
|
||||
if (rc != TREXIO_SUCCESS) return TREXIO_FAILURE;
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
#+end_src
|
||||
** Reading/writing data
|
||||
*** nucleus
|
||||
**** num
|
||||
#+begin_src c :tangle trexio.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
trexio_exit_code trexio_read_nucleus_num(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_nucleus_num(file, &u_num);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = trexio_hdf5_read_nucleus_num(file, &u_num);
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc =trexio_json_read_nucleus_num(file, &u_num);
|
||||
break;
|
||||
,*/
|
||||
}
|
||||
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
/**/ *num = (int64_t) u_num;
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
trexio_exit_code rc = TREXIO_FAILURE;
|
||||
|
||||
switch (file->back_end) {
|
||||
|
||||
case TREXIO_TEXT:
|
||||
rc = trexio_text_write_nucleus_num(file, (uint64_t) num);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
rc = trexio_hdf5_write_nucleus_num(file, (uint64_t) num);
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
rc = trexio_json_write_nucleus_num(file, (uint64_t) num);
|
||||
break;
|
||||
,*/
|
||||
}
|
||||
if (rc != TREXIO_SUCCESS) return rc;
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
**** coord
|
||||
#+begin_src c :tangle trexio.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
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;
|
||||
|
||||
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_read_nucleus_coord(file, coord, rank, dims);
|
||||
break;
|
||||
|
||||
case TREXIO_HDF5:
|
||||
return trexio_hdf5_read_nucleus_coord(file, coord, rank, dims);
|
||||
break;
|
||||
/*
|
||||
case TREXIO_JSON:
|
||||
return trexio_json_read_nucleus_coord(file, coord);
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
|
||||
**** charge
|
||||
#+begin_src c :tangle trexio.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
|
||||
*** rdm
|
||||
**** one_e
|
||||
#+begin_src c :tangle trexio.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
|
||||
**** two_e
|
||||
|
||||
~buffered_read~ functions return ~TREXIO_SUCCESS~ if the complete
|
||||
buffer was read or written. If the read data is smaller than the
|
||||
buffer because the end is reached, the function returns ~TREXIO_END~.
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio.c
|
||||
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 */
|
||||
}
|
||||
}
|
||||
#+end_src
|
||||
|
||||
* Back ends
|
||||
|
||||
TREXIO has multiple possible back ends:
|
||||
|
||||
- HDF5: The most efficient back-end, by default
|
||||
- Text files: not to be used for production, but useful for debugging
|
||||
- JSON: for portability
|
||||
|
||||
* File suffixes :noxport:
|
||||
|
||||
#+begin_src c :tangle trexio.h
|
||||
#endif
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_s.h
|
||||
#endif
|
||||
#+end_src
|
||||
|
||||
* TODO Things to be done :noexport:
|
||||
- [ ] Thread safety
|
||||
- [ ] Error handling with errno
|
||||
- [ ] HDF5 back-end
|
||||
- [ ] JSON back-end
|
||||
- [ ] Caching of the struct saving last modification date in structs
|
1369
src/trexio_hdf5.c
1369
src/trexio_hdf5.c
File diff suppressed because it is too large
Load Diff
@ -1,60 +0,0 @@
|
||||
/* 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_s.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h" // needed for high-level APIs like H5LT, requires additional linking in Makefile
|
||||
typedef struct trexio_hdf5_s {
|
||||
trexio_t parent ;
|
||||
hid_t file_id;
|
||||
hid_t nucleus_group;
|
||||
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);
|
||||
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
|
@ -1,673 +0,0 @@
|
||||
#+Title: HDF5 back end for the TREX Input/Ouput library (TREXIO)
|
||||
|
||||
* File prefixes :noxport:
|
||||
|
||||
#+NAME:header
|
||||
#+begin_src c
|
||||
/* This file was generated from the trexio.org org-mode file.
|
||||
To generate it, open trexio.org in Emacs and execute
|
||||
M-x org-babel-tangle
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h :noweb yes
|
||||
<<header>>
|
||||
#ifndef _TREXIO_HDF5_H
|
||||
#define _TREXIO_HDF5_H
|
||||
|
||||
#include "trexio.h"
|
||||
#include "trexio_private.h"
|
||||
#include "trexio_s.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "hdf5_hl.h" // needed for high-level APIs like H5LT, requires additional linking in Makefile
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c :noweb yes
|
||||
<<header>>
|
||||
#include "trexio_hdf5.h"
|
||||
#+end_src
|
||||
|
||||
|
||||
* HDF5 Back end
|
||||
|
||||
** HDF5 definitions
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
#define NUCLEUS_GROUP_NAME "nucleus"
|
||||
#define NUCLEUS_NUM_NAME "nucleus_num"
|
||||
#define NUCLEUS_CHARGE_NAME "nucleus_charge"
|
||||
#define NUCLEUS_COORD_NAME "nucleus_coord"
|
||||
|
||||
#+end_src
|
||||
|
||||
** HDF5 structures
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
|
||||
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
|
||||
const char* file_name;
|
||||
} trexio_hdf5_t;
|
||||
|
||||
#+end_src
|
||||
|
||||
** HDF5 basic functions
|
||||
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
trexio_exit_code trexio_hdf5_init(trexio_t* file);
|
||||
#+end_src
|
||||
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
|
||||
/*
|
||||
* 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<rank; i++){
|
||||
assert (dims[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;
|
||||
|
||||
}
|
||||
|
||||
trexio_exit_code trexio_hdf5_init(trexio_t* file) {
|
||||
|
||||
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
||||
|
||||
/* If file doesn't exist, create it */
|
||||
int f_exists = 0;
|
||||
struct stat st;
|
||||
|
||||
if (stat(file->file_name, &st) == 0) f_exists = 1;
|
||||
|
||||
if (f_exists == 1) {
|
||||
|
||||
switch (file->mode) {
|
||||
case 'r':
|
||||
// reading the existing file -> open as RDONLY
|
||||
f->file_id = H5Fopen(file->file_name, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
break;
|
||||
case 'a':
|
||||
// appending the existing file -> open as RDWR
|
||||
f->file_id = H5Fopen(file->file_name, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
break;
|
||||
case 'w':
|
||||
// writing the existing file -> overwrite it (_TRUNC) [_EXCL | H5F_ACC_DEBUG as an alternative]
|
||||
f->file_id = H5Fcreate(file->file_name, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
switch (file->mode) {
|
||||
case 'r':
|
||||
case 'a':
|
||||
// reading or appending non-existing file -> error
|
||||
return TREXIO_FAILURE;
|
||||
case 'w':
|
||||
// writing non-existing file -> create it
|
||||
f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Create or open groups in the hdf5 file assuming that they exist if file exists */
|
||||
switch (file->mode) {
|
||||
// the switch for 'r'/'a' is reached only if file exists
|
||||
case 'r':
|
||||
case 'a':
|
||||
f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_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->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
break;
|
||||
}
|
||||
assert (f->nucleus_group > 0L);
|
||||
//assert (f->electron_group > 0L);
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
|
||||
#+end_src
|
||||
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
trexio_exit_code trexio_hdf5_finalize(trexio_t* file);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
trexio_exit_code trexio_hdf5_finalize(trexio_t* file) {
|
||||
|
||||
trexio_hdf5_t* f = (trexio_hdf5_t*) file;
|
||||
|
||||
H5Gclose(f->nucleus_group);
|
||||
f->nucleus_group = 0;
|
||||
|
||||
/*
|
||||
H5Gclose(f->electron_group);
|
||||
f->electron_group = 0;
|
||||
*/
|
||||
|
||||
H5Fclose(f->file_id);
|
||||
f->file_id = 0;
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
|
||||
|
||||
** Structs for sparse data structures
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
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;
|
||||
|
||||
#+end_src
|
||||
|
||||
** Read/write the nucleus struct
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
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) {
|
||||
|
||||
assert (file != NULL);
|
||||
assert (nucleus != NULL);
|
||||
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
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; i<rrank; i++){
|
||||
assert (dims[i] == charge_dims[i]);
|
||||
}
|
||||
|
||||
status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, nucleus->charge);
|
||||
assert (status >= 0);
|
||||
|
||||
H5Sclose(dspace);
|
||||
H5Tclose(dtype);
|
||||
H5Dclose(dset_id);
|
||||
|
||||
}
|
||||
|
||||
int coord_rank = 2;
|
||||
const hsize_t coord_dims[2] = {nucleus->num, 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; i<rrank; i++){
|
||||
assert (dims[i] == coord_dims[i]);
|
||||
}
|
||||
|
||||
status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, nucleus->coord);
|
||||
assert (status >= 0);
|
||||
|
||||
H5Sclose(dspace);
|
||||
H5Tclose(dtype);
|
||||
H5Dclose(dset_id);
|
||||
|
||||
}
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
|
||||
#+end_src
|
||||
|
||||
** Free memory
|
||||
|
||||
Memory is allocated when reading. The followig function frees memory.
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
trexio_exit_code trexio_hdf5_free_nucleus(h5nucleus_t* nucleus) {
|
||||
|
||||
if (nucleus == NULL) return TREXIO_FAILURE;
|
||||
|
||||
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);
|
||||
|
||||
FREE (nucleus);
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
#+end_src
|
||||
|
||||
** Read/Write the num attribute
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
trexio_exit_code trexio_hdf5_read_nucleus_num(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->nucleus_group, NUCLEUS_NUM_NAME) == 0) return TREXIO_FAILURE;
|
||||
|
||||
/* Read the nucleus_num attribute of nucleus group */
|
||||
hid_t num_id = H5Aopen(f->nucleus_group, NUCLEUS_NUM_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_num(const trexio_t* file, const uint64_t num) {
|
||||
|
||||
assert (file != NULL);
|
||||
assert (num > 0L);
|
||||
|
||||
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->nucleus_group, NUCLEUS_NUM_NAME) == 0) {
|
||||
|
||||
hid_t dspace = H5Screate(H5S_SCALAR);
|
||||
|
||||
num_id = H5Acreate(f->nucleus_group, NUCLEUS_NUM_NAME, dtype, dspace,
|
||||
H5P_DEFAULT, H5P_DEFAULT);
|
||||
assert (num_id > 0);
|
||||
|
||||
status = H5Awrite(num_id, dtype, &(num));
|
||||
assert (status >= 0);
|
||||
|
||||
H5Sclose(dspace);
|
||||
|
||||
} else {
|
||||
|
||||
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 != num) {
|
||||
|
||||
if (nucleus_num != 0) {
|
||||
printf("%ld -> %ld %s \n", num, nucleus_num,
|
||||
"This variable already exists. Overwriting it is not supported");
|
||||
H5Tclose(dtype);
|
||||
return TREXIO_FAILURE;
|
||||
|
||||
} else {
|
||||
|
||||
num_id = H5Aopen(f->nucleus_group, NUCLEUS_NUM_NAME, H5P_DEFAULT);
|
||||
assert (num_id > 0);
|
||||
|
||||
status = H5Awrite(num_id, dtype, &(num));
|
||||
assert (status >= 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
H5Aclose(num_id);
|
||||
H5Tclose(dtype);
|
||||
return TREXIO_SUCCESS;
|
||||
|
||||
}
|
||||
#+end_src
|
||||
** Read/Write the coord attribute
|
||||
|
||||
The ~coord~ array is assumed allocated with the appropriate size.
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
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);
|
||||
#+end_src
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.c
|
||||
trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord, const uint32_t rank, const uint64_t* dims) {
|
||||
|
||||
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; i<rank; i++){
|
||||
if (ddims[i] != dims[i]) {
|
||||
FREE(ddims);
|
||||
return TREXIO_INVALID_ARG_4;
|
||||
}
|
||||
}
|
||||
FREE(ddims);
|
||||
|
||||
/* High-level H5LT API. No need to deal with dataspaces and datatypes */
|
||||
status = H5LTread_dataset_double(f->nucleus_group,
|
||||
NUCLEUS_COORD_NAME,
|
||||
coord);
|
||||
if (status < 0) return TREXIO_FAILURE;
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord, const uint32_t rank, const uint64_t* dims) {
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
} 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, coord);
|
||||
|
||||
H5Dclose(dset_id);
|
||||
if (status < 0) return TREXIO_FAILURE;
|
||||
|
||||
}
|
||||
|
||||
return TREXIO_SUCCESS;
|
||||
}
|
||||
|
||||
#+end_src
|
||||
|
||||
* File suffixes :noxport:
|
||||
|
||||
#+begin_src c :tangle trexio_hdf5.h
|
||||
#endif
|
||||
#+end_src
|
@ -1,20 +0,0 @@
|
||||
/* This file was generated from the trexio.org org-mode file.
|
||||
To generate it, open trexio.org in Emacs and execute
|
||||
M-x org-babel-tangle
|
||||
*/
|
||||
|
||||
#ifndef _TREXIO_S_H
|
||||
#define _TREXIO_S_H
|
||||
|
||||
#include "trexio.h"
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
struct trexio_s {
|
||||
char* file_name;
|
||||
pthread_mutex_t thread_lock;
|
||||
back_end_t back_end;
|
||||
char mode;
|
||||
char padding[7]; /* Ensures the proper alignment of back-ends */
|
||||
};
|
||||
#endif
|
2636
src/trexio_text.c
2636
src/trexio_text.c
File diff suppressed because it is too large
Load Diff
@ -1,139 +0,0 @@
|
||||
/* This file was generated from the trexio.org org-mode file.
|
||||
To generate it, open trexio.org in Emacs and execute
|
||||
M-x org-babel-tangle
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _TREXIO_TEXT_H
|
||||
#define _TREXIO_TEXT_H
|
||||
|
||||
#include "trexio.h"
|
||||
#include "trexio_private.h"
|
||||
#include "trexio_s.h"
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
typedef struct nucleus_s {
|
||||
FILE* file;
|
||||
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 ecp_s {
|
||||
FILE* file;
|
||||
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;
|
||||
double* one_e;
|
||||
char* two_e_file_name;
|
||||
int to_flush;
|
||||
} rdm_t;
|
||||
|
||||
typedef struct trexio_text_s {
|
||||
trexio_t parent ;
|
||||
int lock_file;
|
||||
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);
|
||||
|
||||
trexio_exit_code trexio_text_finalize(trexio_t* file);
|
||||
|
||||
trexio_exit_code trexio_text_unlock(trexio_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_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);
|
||||
|
||||
trexio_exit_code trexio_text_free_rdm(trexio_text_t* file);
|
||||
|
||||
trexio_exit_code trexio_text_read_rdm_one_e(const trexio_t* file, double* one_e, const uint64_t dim_one_e);
|
||||
trexio_exit_code trexio_text_write_rdm_one_e(const trexio_t* file, const double* one_e, const uint64_t dim_one_e);
|
||||
|
||||
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
|
1068
src/trexio_text.org
1068
src/trexio_text.org
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user