From 49a73b6d7597a41beaf6b8a5f354e5d33b28411b Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 2 Mar 2021 13:56:30 +0100 Subject: [PATCH] Renamed trio in trexio --- src/Makefile | 18 +- src/test.c | 76 ++-- src/trexio.c | 254 +++++++++++++ src/trexio.h | 40 ++ src/{trio.org => trexio.org} | 586 ++++++++++++++--------------- src/{trio_hdf5.c => trexio_hdf5.c} | 84 ++--- src/{trio_hdf5.h => trexio_hdf5.h} | 30 +- src/{trio_s.h => trexio_s.h} | 12 +- src/{trio_text.c => trexio_text.c} | 98 ++--- src/trexio_text.h | 50 +++ src/trio.c | 254 ------------- src/trio.h | 40 -- src/trio_text.h | 50 --- 13 files changed, 796 insertions(+), 796 deletions(-) create mode 100644 src/trexio.c create mode 100644 src/trexio.h rename src/{trio.org => trexio.org} (61%) rename src/{trio_hdf5.c => trexio_hdf5.c} (80%) rename src/{trio_hdf5.h => trexio_hdf5.h} (54%) rename src/{trio_s.h => trexio_s.h} (59%) rename src/{trio_text.c => trexio_text.c} (64%) create mode 100644 src/trexio_text.h delete mode 100644 src/trio.c delete mode 100644 src/trio.h delete mode 100644 src/trio_text.h diff --git a/src/Makefile b/src/Makefile index ad5ba14..c06347f 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,7 +6,7 @@ ifeq ($(COMPILER),GNU) CC=gcc -g CFLAGS=-fPIC -fexceptions -Wall -Werror -Wpedantic -Wextra -LIBS= -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lz -lm -lhdf5 -lhdf5_hl #-lgfortran +LIBS= -L/usr/lib/x86_64-linux-gnu/hdf5/serial/ -lz -lm -lhdf5 -lhdf5_hl #-lgfortran INCLUDE = -I/usr/include/hdf5/serial endif @@ -17,7 +17,7 @@ CFLAGS=-fPIC -g -O2 FC=ifort -xHost FFLAGS=-fPIC -g -O2 -LIBS= #-lm +LIBS= #-lm endif #TODO @@ -32,21 +32,21 @@ LIBS=-lm endif -OBJECT_FILES= trio.o trio_text.o trio_hdf5.o -HEADER_FILES= trio.h trio_text.h trio_hdf5.h trio_s.h +OBJECT_FILES= trexio.o trexio_text.o trexio_hdf5.o +HEADER_FILES= trexio.h trexio_text.h trexio_hdf5.h trexio_s.h export CC CFLAGS LIBS .PHONY: clean -libtrio.so: $(OBJECT_FILES) $(HEADER_FILES) - $(CC) -shared $(OBJECT_FILES) -o libtrio.so +libtrexio.so: $(OBJECT_FILES) $(HEADER_FILES) + $(CC) -shared $(OBJECT_FILES) -o libtrexio.so -test: libtrio.so test.c - $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrio $(LIBS) -o test +test: libtrexio.so test.c + $(CC) $(CFLAGS) $(INCLUDE) -Wl,-rpath,$(PWD) -L. test.c -ltrexio $(LIBS) -o test clean: - rm -f *.o libtrio.so test test_write.h5 + rm -f *.o libtrexio.so test test_write.h5 %.o: %.c $(HEADER_FILES) $(CC) $(CFLAGS) $(INCLUDE) -c $*.c -o $*.o diff --git a/src/test.c b/src/test.c index 5e0256e..80e6bdb 100644 --- a/src/test.c +++ b/src/test.c @@ -1,4 +1,4 @@ -#include "trio.h" +#include "trexio.h" #include #include #include @@ -22,10 +22,10 @@ int main() { int test_h5write() { const char* file_name = "test_write.h5"; - trio_t* file = NULL; - trio_exit_code rc; + trexio_t* file = NULL; + trexio_exit_code rc; - rc = TRIO_SUCCESS; + rc = TREXIO_SUCCESS; uint64_t num = 12; @@ -44,27 +44,27 @@ int test_h5write() { 0.00000000 , 2.47304151 , 0.00000000 , }; - file = trio_create(file_name, TRIO_HDF5); + file = trexio_create(file_name, TREXIO_HDF5); // works: try writing info in an empty file - rc = trio_write_nucleus_num(file,num); - rc = trio_write_nucleus_coord(file,coord); + rc = trexio_write_nucleus_num(file,num); + rc = trexio_write_nucleus_coord(file,coord); // should not work: try to rewrite the nucleus_num - rc = trio_write_nucleus_num(file,25); + rc = trexio_write_nucleus_num(file,25); - // works: try to rewrite the nucleus_coord + // works: try to rewrite the nucleus_coord coord[0] = 666.666; - rc = trio_write_nucleus_coord(file,coord); + rc = trexio_write_nucleus_coord(file,coord); - if (rc == TRIO_SUCCESS) { + if (rc == TREXIO_SUCCESS) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } - trio_close(file); + trexio_close(file); return 0; } @@ -72,20 +72,20 @@ int test_h5write() { int test_h5read() { const char* file_name = "test_write.h5"; - trio_t* file = NULL; - trio_exit_code rc; + trexio_t* file = NULL; + trexio_exit_code rc; uint64_t num; double* coord; - file = trio_create(file_name, TRIO_HDF5); + file = trexio_create(file_name, TREXIO_HDF5); - rc = trio_read_nucleus_num(file,&num); + rc = trexio_read_nucleus_num(file,&num); assert (num == 12); coord = (double*) calloc(3*num, sizeof(double)); - rc = trio_read_nucleus_coord(file,coord); - + rc = trexio_read_nucleus_coord(file,coord); + /*for (size_t i=0; i<3*num; i++){ printf("%lf \n", coord[i]); }*/ @@ -93,14 +93,14 @@ int test_h5read() { double x = coord[30] - 2.14171677; assert( x*x < 1.e-12); - if (rc == TRIO_SUCCESS) { + if (rc == TREXIO_SUCCESS) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } - trio_close(file); + trexio_close(file); free(coord); return 0; @@ -108,10 +108,10 @@ int test_h5read() { int test_write() { - const char* file_name = "trio_test"; + const char* file_name = "trexio_test"; - trio_t* file = NULL; - trio_exit_code rc; + trexio_t* file = NULL; + trexio_exit_code rc; uint64_t num = 12; @@ -133,54 +133,54 @@ int test_write() { 0.00000000 , 2.47304151 , 0.00000000 , }; - file = trio_create(file_name, TRIO_TEXT); + file = trexio_create(file_name, TREXIO_TEXT); - rc = trio_write_nucleus_num(file,num); - rc = trio_write_nucleus_charge(file,charge); - rc = trio_write_nucleus_coord(file,coord); + rc = trexio_write_nucleus_num(file,num); + rc = trexio_write_nucleus_charge(file,charge); + rc = trexio_write_nucleus_coord(file,coord); - if (rc == TRIO_SUCCESS) { + if (rc == TREXIO_SUCCESS) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } - trio_close(file); + trexio_close(file); return 0; } int test_read() { - const char* file_name = "trio_test"; + const char* file_name = "trexio_test"; - trio_t* file = NULL; - trio_exit_code rc; + trexio_t* file = NULL; + trexio_exit_code rc; uint64_t num; double* charge; double* coord; - file = trio_create(file_name, TRIO_TEXT); + file = trexio_create(file_name, TREXIO_TEXT); - rc = trio_read_nucleus_num(file,&num); + rc = trexio_read_nucleus_num(file,&num); assert (num == 12); charge = (double*) calloc(num, sizeof(double)); - rc = trio_read_nucleus_charge(file,charge); + rc = trexio_read_nucleus_charge(file,charge); assert(charge[10] == 1.); coord = (double*) calloc(3*num, sizeof(double)); - rc = trio_read_nucleus_coord(file,coord); + rc = trexio_read_nucleus_coord(file,coord); double x = coord[30] - 2.14171677; assert( x*x < 1.e-12); - if (rc == TRIO_SUCCESS) { + if (rc == TREXIO_SUCCESS) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } - trio_close(file); + trexio_close(file); free(charge); free(coord); diff --git a/src/trexio.c b/src/trexio.c new file mode 100644 index 0000000..4c13d42 --- /dev/null +++ b/src/trexio.c @@ -0,0 +1,254 @@ +/* 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 +*/ + + + +#include +#include +#include +#include +#include + +#include "trexio.h" +#include "trexio_s.h" +#include "trexio_text.h" +#include "trexio_hdf5.h" +/* +#include "trexio_json.h" +*/ + +trexio_t* trexio_create(const char* file_name, back_end_t back_end) { + + /* Check that file name is not NULL or empty */ + assert (file_name != NULL); + assert (file_name[0] != '\0'); + + /* Check that back_end is valid */ + assert (back_end < TREXIO_INVALID_BACK_END); + + trexio_t* result = NULL; + + 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; +*/ + default: + assert (1 == 0); /* Impossible case */ + } + + /* TODO: Error handling */ + assert (result != NULL); + + result->file_name = (char*) calloc(strlen(file_name)+1,sizeof(char)); + strcpy(result->file_name, file_name); + result->back_end = back_end; + result->mode = 'w'; /* Upon creation, mode=write */ + int irc = pthread_mutex_init ( &(result->thread_lock), NULL); + assert (irc == 0); + + trexio_exit_code 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; +*/ + default: + assert (1 == 0); /* Impossible case */ + } + assert (rc == TREXIO_SUCCESS); + + return result; +} + +trexio_exit_code trexio_close(trexio_t* file) { + + assert (file != NULL); + + trexio_exit_code rc; + + 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) { + return TREXIO_FAILURE; + } + + free(file->file_name); + file->file_name = NULL; + + int irc = pthread_mutex_destroy( &(file->thread_lock) ); + assert (irc == 0); + + free(file); + + return TREXIO_SUCCESS; +} + +trexio_exit_code trexio_read_nucleus_num(trexio_t* file, uint64_t* num) { + if (file == NULL) return TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_nucleus_num(file, num); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_num(file, num); + break; +/* + case TREXIO_JSON: + return trexio_json_read_nucleus_num(file, num); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} + +trexio_exit_code trexio_write_nucleus_num(trexio_t* file, uint64_t num) { + if (file == NULL) return TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_nucleus_num(file, num); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_num(file, num); + break; +/* + case TREXIO_JSON: + return trexio_json_write_nucleus_num(file, num); + break; +*/ + default: + return TREXIO_FAILURE; /* Impossible case */ + } +} + +trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord) { + if (file == NULL) return TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_nucleus_coord(file, coord); + break; + + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_coord(file, coord); + 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, double* coord) { + if (file == NULL) return TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_nucleus_coord(file, coord); + break; + + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_coord(file, coord); + 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_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_read_nucleus_charge(file, charge); + 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, double* charge) { + if (file == NULL) return TREXIO_FAILURE; + + switch (file->back_end) { + + case TREXIO_TEXT: + return trexio_text_write_nucleus_charge(file, charge); + 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 */ + } +} diff --git a/src/trexio.h b/src/trexio.h new file mode 100644 index 0000000..0c898e2 --- /dev/null +++ b/src/trexio.h @@ -0,0 +1,40 @@ +/* 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 + +typedef int32_t trexio_exit_code; + +#define TREXIO_SUCCESS ( (trexio_exit_code) 0 ) +#define TREXIO_FAILURE ( (trexio_exit_code) 1 ) + +typedef uint32_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_create(const char* file_name, back_end_t back_end); + +trexio_exit_code trexio_close(trexio_t* file); + +trexio_exit_code trexio_read_nucleus_num(trexio_t* file, uint64_t* num); +trexio_exit_code trexio_write_nucleus_num(trexio_t* file, uint64_t num); + +trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord); +trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, double* coord); + +trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge); +trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, double* charge); + +#endif diff --git a/src/trio.org b/src/trexio.org similarity index 61% rename from src/trio.org rename to src/trexio.org index ab674af..2bb124e 100644 --- a/src/trio.org +++ b/src/trexio.org @@ -1,11 +1,11 @@ -#+Title: TREX Input/Ouput library (TRIO) +#+Title: TREX Input/Ouput library (TREXIO) * File prefixes :noxport: #+NAME:header #+begin_src c -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute +/* 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 */ @@ -13,16 +13,16 @@ #+end_src - #+begin_src c :tangle trio.h :noweb yes + #+begin_src c :tangle trexio.h :noweb yes <
> -#ifndef _TRIO_H -#define _TRIO_H +#ifndef _TREXIO_H +#define _TREXIO_H #include #+end_src - #+begin_src c :tangle trio.c :noweb yes + #+begin_src c :tangle trexio.c :noweb yes <
> #include #include @@ -30,34 +30,34 @@ #include #include -#include "trio.h" -#include "trio_s.h" -#include "trio_text.h" -#include "trio_hdf5.h" +#include "trexio.h" +#include "trexio_s.h" +#include "trexio_text.h" +#include "trexio_hdf5.h" /* -#include "trio_json.h" +#include "trexio_json.h" ,*/ #+end_src - #+begin_src c :tangle trio_s.h :noweb yes + #+begin_src c :tangle trexio_s.h :noweb yes <
> -#ifndef _TRIO_S_H -#define _TRIO_S_H +#ifndef _TREXIO_S_H +#define _TREXIO_S_H -#include "trio.h" +#include "trexio.h" #include #include #+end_src - #+begin_src c :tangle trio_text.h :noweb yes + #+begin_src c :tangle trexio_text.h :noweb yes <
> -#ifndef _TRIO_TEXT_H -#define _TRIO_TEXT_H +#ifndef _TREXIO_TEXT_H +#define _TREXIO_TEXT_H -#include "trio.h" -#include "trio_s.h" +#include "trexio.h" +#include "trexio_s.h" #include #include #include @@ -67,18 +67,18 @@ #+end_src - #+begin_src c :tangle trio_text.c :noweb yes + #+begin_src c :tangle trexio_text.c :noweb yes <
> -#include "trio_text.h" +#include "trexio_text.h" #+end_src - #+begin_src c :tangle trio_hdf5.h :noweb yes + #+begin_src c :tangle trexio_hdf5.h :noweb yes <
> -#ifndef _TRIO_HDF5_H -#define _TRIO_HDF5_H +#ifndef _TREXIO_HDF5_H +#define _TREXIO_HDF5_H -#include "trio.h" -#include "trio_s.h" +#include "trexio.h" +#include "trexio_s.h" #include #include #include @@ -90,9 +90,9 @@ #include "hdf5_hl.h" // needed for high-level APIs like H5LT, requires additional linking in Makefile #+end_src - #+begin_src c :tangle trio_hdf5.c :noweb yes + #+begin_src c :tangle trexio_hdf5.c :noweb yes <
> -#include "trio_hdf5.h" +#include "trexio_hdf5.h" #+end_src @@ -109,26 +109,26 @@ * Front end - All calls to TRIO are thread-safe. + All calls to TREXIO are thread-safe. ** Error handling - #+begin_src c :tangle trio.h -typedef int32_t trio_exit_code; + #+begin_src c :tangle trexio.h +typedef int32_t trexio_exit_code; -#define TRIO_SUCCESS ( (trio_exit_code) 0 ) -#define TRIO_FAILURE ( (trio_exit_code) 1 ) +#define TREXIO_SUCCESS ( (trexio_exit_code) 0 ) +#define TREXIO_FAILURE ( (trexio_exit_code) 1 ) #+end_src ** Back ends - #+begin_src c :tangle trio.h + #+begin_src c :tangle trexio.h typedef uint32_t back_end_t; -#define TRIO_HDF5 ( (back_end_t) 0 ) -#define TRIO_TEXT ( (back_end_t) 1 ) -#define TRIO_JSON ( (back_end_t) 2 ) -#define TRIO_INVALID_BACK_END ( (back_end_t) 3 ) +#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 @@ -137,36 +137,36 @@ typedef uint32_t back_end_t; disk. If data needs to be cached, this is left to the user of the library. - Writing to TRIO files is done with transactions (all-or-nothing + 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 TRIO file is + 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 TRIO files are supposed to be opened by only one program at a - time: if the same TRIO file is modified simultaneously by multiple + 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. -** TRIO file type +** TREXIO file type - ~trio_s~ is the the main type for TRIO files, visible to the users + ~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 /TRIO file handles/, - namely pointers to ~trio_s~ types. All functions accessing to the - TRIO files will have as a first argument the TRIO file handle. + 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 trio.h -typedef struct trio_s trio_t; + #+begin_src c :tangle trexio.h +typedef struct trexio_s trexio_t; #+end_src - #+begin_src c :tangle trio_s.h -struct trio_s { + #+begin_src c :tangle trexio_s.h +struct trexio_s { char* file_name; pthread_mutex_t thread_lock; back_end_t back_end; @@ -177,49 +177,49 @@ struct trio_s { ** Polymorphism of the file handle - Polymorphism of the ~trio_t~ type is handled by ensuring that the + Polymorphism of the ~trexio_t~ type is handled by ensuring that the corresponding types for all back ends can be safely casted to - ~trio_t~. This is done by making the back end structs start with - ~struct trio_s~: + ~trexio_t~. This is done by making the back end structs start with + ~struct trexio_s~: #+begin_src c -struct trio_back_end_s { - trio_t parent ; +struct trexio_back_end_s { + trexio_t parent ; /* add below specific back end data */ } #+end_src ** File creation and opening - #+begin_src c :tangle trio.h -trio_t* trio_create(const char* file_name, back_end_t back_end); + #+begin_src c :tangle trexio.h +trexio_t* trexio_create(const char* file_name, back_end_t back_end); #+end_src - #+begin_src c :tangle trio.c -trio_t* trio_create(const char* file_name, back_end_t back_end) { + #+begin_src c :tangle trexio.c +trexio_t* trexio_create(const char* file_name, back_end_t back_end) { /* Check that file name is not NULL or empty */ assert (file_name != NULL); assert (file_name[0] != '\0'); /* Check that back_end is valid */ - assert (back_end < TRIO_INVALID_BACK_END); + assert (back_end < TREXIO_INVALID_BACK_END); - trio_t* result = NULL; + trexio_t* result = NULL; switch (back_end) { - case TRIO_TEXT: - result = (trio_t*) malloc (sizeof(trio_text_t)); + case TREXIO_TEXT: + result = (trexio_t*) malloc (sizeof(trexio_text_t)); break; - case TRIO_HDF5: - result = (trio_t*) malloc (sizeof(trio_hdf5_t)); + case TREXIO_HDF5: + result = (trexio_t*) malloc (sizeof(trexio_hdf5_t)); break; /* - case TRIO_JSON: - result = (trio_t*) malloc (sizeof(trio_json_t)); + case TREXIO_JSON: + result = (trexio_t*) malloc (sizeof(trexio_json_t)); break; ,*/ default: @@ -236,26 +236,26 @@ trio_t* trio_create(const char* file_name, back_end_t back_end) { int irc = pthread_mutex_init ( &(result->thread_lock), NULL); assert (irc == 0); - trio_exit_code rc = TRIO_FAILURE; + trexio_exit_code rc = TREXIO_FAILURE; switch (back_end) { - case TRIO_TEXT: - rc = trio_text_init(result); + case TREXIO_TEXT: + rc = trexio_text_init(result); break; - case TRIO_HDF5: - rc = trio_hdf5_init(result); + case TREXIO_HDF5: + rc = trexio_hdf5_init(result); break; /* - case TRIO_JSON: - rc = trio_json_init(result); + case TREXIO_JSON: + rc = trexio_json_init(result); break; ,*/ default: assert (1 == 0); /* Impossible case */ } - assert (rc == TRIO_SUCCESS); + assert (rc == TREXIO_SUCCESS); return result; } @@ -264,37 +264,37 @@ trio_t* trio_create(const char* file_name, back_end_t back_end) { ** File closing - #+begin_src c :tangle trio.h -trio_exit_code trio_close(trio_t* file); + #+begin_src c :tangle trexio.h +trexio_exit_code trexio_close(trexio_t* file); #+end_src - #+begin_src c :tangle trio.c -trio_exit_code trio_close(trio_t* file) { + #+begin_src c :tangle trexio.c +trexio_exit_code trexio_close(trexio_t* file) { assert (file != NULL); - trio_exit_code rc; + trexio_exit_code rc; switch (file->back_end) { - case TRIO_TEXT: - rc = trio_text_finalize(file); + case TREXIO_TEXT: + rc = trexio_text_finalize(file); break; - case TRIO_HDF5: - rc = trio_hdf5_finalize(file); + case TREXIO_HDF5: + rc = trexio_hdf5_finalize(file); break; /* - case TRIO_JSON: - rc = trio_json_finalize(file); + case TREXIO_JSON: + rc = trexio_json_finalize(file); break; ,*/ default: assert (1 == 0); /* Impossible case */ } - if (rc != TRIO_SUCCESS) { - return TRIO_FAILURE; + if (rc != TREXIO_SUCCESS) { + return TREXIO_FAILURE; } free(file->file_name); @@ -305,169 +305,169 @@ trio_exit_code trio_close(trio_t* file) { free(file); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src ** Reading/writing data - #+begin_src c :tangle trio.h -trio_exit_code trio_read_nucleus_num(trio_t* file, uint64_t* num); -trio_exit_code trio_write_nucleus_num(trio_t* file, uint64_t num); + #+begin_src c :tangle trexio.h +trexio_exit_code trexio_read_nucleus_num(trexio_t* file, uint64_t* num); +trexio_exit_code trexio_write_nucleus_num(trexio_t* file, uint64_t num); #+end_src - #+begin_src c :tangle trio.c -trio_exit_code trio_read_nucleus_num(trio_t* file, uint64_t* num) { - if (file == NULL) return TRIO_FAILURE; + #+begin_src c :tangle trexio.c +trexio_exit_code trexio_read_nucleus_num(trexio_t* file, uint64_t* num) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_read_nucleus_num(file, num); + case TREXIO_TEXT: + return trexio_text_read_nucleus_num(file, num); break; - case TRIO_HDF5: - return trio_hdf5_read_nucleus_num(file, num); + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_num(file, num); break; /* - case TRIO_JSON: - return trio_json_read_nucleus_num(file, num); + case TREXIO_JSON: + return trexio_json_read_nucleus_num(file, num); break; */ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } -trio_exit_code trio_write_nucleus_num(trio_t* file, uint64_t num) { - if (file == NULL) return TRIO_FAILURE; +trexio_exit_code trexio_write_nucleus_num(trexio_t* file, uint64_t num) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_write_nucleus_num(file, num); + case TREXIO_TEXT: + return trexio_text_write_nucleus_num(file, num); break; - case TRIO_HDF5: - return trio_hdf5_write_nucleus_num(file, num); + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_num(file, num); break; /* - case TRIO_JSON: - return trio_json_write_nucleus_num(file, num); + case TREXIO_JSON: + return trexio_json_write_nucleus_num(file, num); break; */ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } #+end_src - #+begin_src c :tangle trio.h -trio_exit_code trio_read_nucleus_coord(trio_t* file, double* coord); -trio_exit_code trio_write_nucleus_coord(trio_t* file, double* 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, double* coord); #+end_src - #+begin_src c :tangle trio.c -trio_exit_code trio_read_nucleus_coord(trio_t* file, double* coord) { - if (file == NULL) return TRIO_FAILURE; + #+begin_src c :tangle trexio.c +trexio_exit_code trexio_read_nucleus_coord(trexio_t* file, double* coord) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_read_nucleus_coord(file, coord); + case TREXIO_TEXT: + return trexio_text_read_nucleus_coord(file, coord); break; - case TRIO_HDF5: - return trio_hdf5_read_nucleus_coord(file, coord); + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_coord(file, coord); break; /* - case TRIO_JSON: - return trio_json_read_nucleus_coord(file, coord); + case TREXIO_JSON: + return trexio_json_read_nucleus_coord(file, coord); break; ,*/ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } -trio_exit_code trio_write_nucleus_coord(trio_t* file, double* coord) { - if (file == NULL) return TRIO_FAILURE; +trexio_exit_code trexio_write_nucleus_coord(trexio_t* file, double* coord) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_write_nucleus_coord(file, coord); + case TREXIO_TEXT: + return trexio_text_write_nucleus_coord(file, coord); break; - case TRIO_HDF5: - return trio_hdf5_write_nucleus_coord(file, coord); + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_coord(file, coord); break; /* - case TRIO_JSON: - return trio_json_write_nucleus_coord(file, coord); + case TREXIO_JSON: + return trexio_json_write_nucleus_coord(file, coord); break; ,*/ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } #+end_src - #+begin_src c :tangle trio.h -trio_exit_code trio_read_nucleus_charge(trio_t* file, double* charge); -trio_exit_code trio_write_nucleus_charge(trio_t* file, double* 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, double* charge); #+end_src - #+begin_src c :tangle trio.c -trio_exit_code trio_read_nucleus_charge(trio_t* file, double* charge) { - if (file == NULL) return TRIO_FAILURE; + #+begin_src c :tangle trexio.c +trexio_exit_code trexio_read_nucleus_charge(trexio_t* file, double* charge) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_read_nucleus_charge(file, charge); + case TREXIO_TEXT: + return trexio_text_read_nucleus_charge(file, charge); break; /* - case TRIO_HDF5: - return trio_hdf5_read_nucleus_charge(file, charge); + case TREXIO_HDF5: + return trexio_hdf5_read_nucleus_charge(file, charge); break; - case TRIO_JSON: - return trio_json_read_nucleus_charge(file, charge); + case TREXIO_JSON: + return trexio_json_read_nucleus_charge(file, charge); break; */ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } -trio_exit_code trio_write_nucleus_charge(trio_t* file, double* charge) { - if (file == NULL) return TRIO_FAILURE; +trexio_exit_code trexio_write_nucleus_charge(trexio_t* file, double* charge) { + if (file == NULL) return TREXIO_FAILURE; switch (file->back_end) { - case TRIO_TEXT: - return trio_text_write_nucleus_charge(file, charge); + case TREXIO_TEXT: + return trexio_text_write_nucleus_charge(file, charge); break; /* - case TRIO_HDF5: - return trio_hdf5_write_nucleus_charge(file, charge); + case TREXIO_HDF5: + return trexio_hdf5_write_nucleus_charge(file, charge); break; - case TRIO_JSON: - return trio_json_write_nucleus_charge(file, charge); + case TREXIO_JSON: + return trexio_json_write_nucleus_charge(file, charge); break; ,*/ default: - return TRIO_FAILURE; /* Impossible case */ + return TREXIO_FAILURE; /* Impossible case */ } } #+end_src * Back ends - TRIO has multiple possible 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 @@ -475,7 +475,7 @@ trio_exit_code trio_write_nucleus_charge(trio_t* file, double* charge) { ** TEXT Back end - #+begin_src c :tangle trio_text.h + #+begin_src c :tangle trexio_text.h typedef struct nucleus_s { double* coord; double* charge; @@ -487,23 +487,23 @@ typedef struct electron_s { uint64_t beta_num; } electron_t; -typedef struct trio_text_s { - trio_t parent ; +typedef struct trexio_text_s { + trexio_t parent ; char* nucleus_file_name; char* electron_file_name; -} trio_text_t; +} trexio_text_t; #+end_src - #+begin_src c :tangle trio_text.h -trio_exit_code trio_text_init(trio_t* file); + #+begin_src c :tangle trexio_text.h +trexio_exit_code trexio_text_init(trexio_t* file); #+end_src - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_init(trio_t* file) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_init(trexio_t* file) { - trio_text_t* f = (trio_text_t*) file; + trexio_text_t* f = (trexio_text_t*) file; /* If directory doesn't exist, create it */ struct stat st; @@ -512,7 +512,7 @@ trio_exit_code trio_text_init(trio_t* file) { /* Do nothing */ } else { if (mkdir(file->file_name, 0777) != 0) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } } @@ -534,20 +534,20 @@ trio_exit_code trio_text_init(trio_t* file) { strcpy (f->electron_file_name, file->file_name); strcat (f->electron_file_name, electron_file_name); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src - #+begin_src c :tangle trio_text.h -trio_exit_code trio_text_finalize(trio_t* file); + #+begin_src c :tangle trexio_text.h +trexio_exit_code trexio_text_finalize(trexio_t* file); #+end_src - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_finalize(trio_t* file) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_finalize(trexio_t* file) { - trio_text_t* f = (trio_text_t*) file; + trexio_text_t* f = (trexio_text_t*) file; free (f->nucleus_file_name); f->nucleus_file_name = NULL; @@ -555,7 +555,7 @@ trio_exit_code trio_text_finalize(trio_t* file) { free (f->electron_file_name); f->electron_file_name = NULL; - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -563,8 +563,8 @@ trio_exit_code trio_text_finalize(trio_t* file) { *** Read/write the nucleus struct - #+begin_src c :tangle trio_text.c -nucleus_t* trio_text_read_nucleus(const trio_text_t* file) { + #+begin_src c :tangle trexio_text.c +nucleus_t* trexio_text_read_nucleus(const trexio_text_t* file) { /* Allocate the data structure */ nucleus_t* nucleus = (nucleus_t*) malloc(sizeof(nucleus_t)); @@ -620,7 +620,7 @@ nucleus_t* trio_text_read_nucleus(const trio_text_t* file) { } -trio_exit_code trio_text_write_nucleus(const trio_text_t* file, nucleus_t* nucleus) { +trexio_exit_code trexio_text_write_nucleus(const trexio_text_t* file, nucleus_t* nucleus) { assert (nucleus != NULL); FILE* f = fopen(file->nucleus_file_name,"w"); @@ -641,7 +641,7 @@ trio_exit_code trio_text_write_nucleus(const trio_text_t* file, nucleus_t* nucle } fclose(f); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -649,11 +649,11 @@ trio_exit_code trio_text_write_nucleus(const trio_text_t* file, nucleus_t* nucle Memory is allocated when reading. The followig function frees memory. - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_free_nucleus(nucleus_t* nucleus) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_free_nucleus(nucleus_t* nucleus) { if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } if (nucleus->coord != NULL) { @@ -667,42 +667,42 @@ trio_exit_code trio_text_free_nucleus(nucleus_t* nucleus) { nucleus->charge = NULL; free (nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src *** Read/Write the num attribute - #+begin_src c :tangle trio_text.h -trio_exit_code trio_text_read_nucleus_num(const trio_t* file, uint64_t* num); -trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t num); + #+begin_src c :tangle trexio_text.h +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); #+end_src - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_read_nucleus_num(const trio_t* file, uint64_t* num) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num) { assert (file != NULL); assert (num != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } /**/ *num = nucleus->num; - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t num) { +trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num) { assert (num > 0L); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); assert (nucleus != NULL); @@ -726,12 +726,12 @@ trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t nu nucleus->num = num; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -739,20 +739,20 @@ trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t nu The ~coord~ array is assumed allocated with the appropriate size. - #+begin_src c :tangle trio_text.h -trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord); -trio_exit_code trio_text_write_nucleus_coord(const trio_t* file, const double* coord); + #+begin_src c :tangle trexio_text.h +trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord); +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord); #+end_src - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord) { assert (file != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } assert (coord != NULL); @@ -761,49 +761,49 @@ trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord) { coord[i] = nucleus->coord[i]; } - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_coord(const trio_t* file, const double* coord) { +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord) { assert (coord != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); assert (nucleus != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { nucleus->coord[i] = coord[i]; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src *** Read/Write the charge attribute The ~charge~ array is assumed allocated with the appropriate size. - #+begin_src c :tangle trio_text.h -trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* coord); -trio_exit_code trio_text_write_nucleus_charge(const trio_t* file, const double* coord); + #+begin_src c :tangle trexio_text.h +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* coord); +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* coord); #+end_src - #+begin_src c :tangle trio_text.c -trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* charge) { + #+begin_src c :tangle trexio_text.c +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge) { assert (file != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*)file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*)file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } assert (charge != NULL); @@ -812,36 +812,36 @@ trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* charge) charge[i] = nucleus->charge[i]; } - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_charge(const trio_t* file, const double* charge) { +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge) { assert (charge != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*)file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*)file); assert (nucleus != NULL); for (size_t i=0 ; inum ; i++) { nucleus->charge[i] = charge[i]; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src ** HDF5 Back end *** HDF5 definitions -#+begin_src c :tangle trio_hdf5.c +#+begin_src c :tangle trexio_hdf5.c #define NUCLEUS_GROUP_NAME "nucleus" #define NUCLEUS_NUM_NAME "nucleus_num" #define NUCLEUS_CHARGE_NAME "nucleus_charge" @@ -851,7 +851,7 @@ trio_exit_code trio_text_write_nucleus_charge(const trio_t* file, const double* *** HDF5 structures - #+begin_src c :tangle trio_hdf5.h + #+begin_src c :tangle trexio_hdf5.h typedef struct slab_s { uint64_t a; @@ -882,32 +882,32 @@ typedef struct h5electron_s { uint64_t beta_num; } h5electron_t; -typedef struct trio_hdf5_s { - trio_t parent ; +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; -} trio_hdf5_t; +} trexio_hdf5_t; #+end_src *** HDF5 basic functions - #+begin_src c :tangle trio_hdf5.h -trio_exit_code trio_hdf5_init(trio_t* file); + #+begin_src c :tangle trexio_hdf5.h +trexio_exit_code trexio_hdf5_init(trexio_t* file); #+end_src - #+begin_src c :tangle trio_hdf5.c + #+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* trio_hdf5_read_dset_low(const trio_hdf5_t* file, const char *dset_name, void *buf) { +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); @@ -954,9 +954,9 @@ dset_t* trio_hdf5_read_dset_low(const trio_hdf5_t* file, const char *dset_name, } -trio_exit_code trio_hdf5_init(trio_t* file) { +trexio_exit_code trexio_hdf5_init(trexio_t* file) { - trio_hdf5_t* f = (trio_hdf5_t*) file; + trexio_hdf5_t* f = (trexio_hdf5_t*) file; /* If file doesn't exist, create it */ int f_ishere = 0; @@ -983,20 +983,20 @@ trio_exit_code trio_hdf5_init(trio_t* file) { assert (f->nucleus_group > 0L); //assert (f->electron_group > 0L); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src - #+begin_src c :tangle trio_hdf5.h -trio_exit_code trio_hdf5_finalize(trio_t* file); + #+begin_src c :tangle trexio_hdf5.h +trexio_exit_code trexio_hdf5_finalize(trexio_t* file); #+end_src - #+begin_src c :tangle trio_hdf5.c -trio_exit_code trio_hdf5_finalize(trio_t* file) { + #+begin_src c :tangle trexio_hdf5.c +trexio_exit_code trexio_hdf5_finalize(trexio_t* file) { - trio_hdf5_t* f = (trio_hdf5_t*) file; + trexio_hdf5_t* f = (trexio_hdf5_t*) file; H5Gclose(f->nucleus_group); f->nucleus_group = 0; @@ -1009,7 +1009,7 @@ trio_exit_code trio_hdf5_finalize(trio_t* file) { H5Fclose(f->file_id); f->file_id = 0; - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -1017,8 +1017,8 @@ trio_exit_code trio_hdf5_finalize(trio_t* file) { *** Read/write the nucleus struct - #+begin_src c :tangle trio_hdf5.c -h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { + #+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 = (h5nucleus_t*) malloc(sizeof(h5nucleus_t)); @@ -1068,7 +1068,7 @@ h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { * when not used anymore, see below. Note how this function is similar to H5LTread_dataset_double */ /* - nucleus->h5_coord = trio_hdf5_read_dset_low(file, NUCLEUS_COORD_NAME, + nucleus->h5_coord = trexio_hdf5_read_dset_low(file, NUCLEUS_COORD_NAME, nucleus->coord); H5Sclose(nucleus->h5_coord->dspace_id); @@ -1082,7 +1082,7 @@ h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { } -trio_exit_code trio_hdf5_write_nucleus(const trio_hdf5_t* file, h5nucleus_t* nucleus) { +trexio_exit_code trexio_hdf5_write_nucleus(const trexio_hdf5_t* file, h5nucleus_t* nucleus) { assert (file != NULL); assert (nucleus != NULL); @@ -1192,7 +1192,7 @@ trio_exit_code trio_hdf5_write_nucleus(const trio_hdf5_t* file, h5nucleus_t* nuc } - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -1201,10 +1201,10 @@ trio_exit_code trio_hdf5_write_nucleus(const trio_hdf5_t* file, h5nucleus_t* nuc Memory is allocated when reading. The followig function frees memory. - #+begin_src c :tangle trio_hdf5.c -trio_exit_code trio_hdf5_free_nucleus(h5nucleus_t* nucleus) { + #+begin_src c :tangle trexio_hdf5.c +trexio_exit_code trexio_hdf5_free_nucleus(h5nucleus_t* nucleus) { - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; if (nucleus->coord != NULL) free (nucleus->coord); nucleus->coord = NULL; @@ -1220,42 +1220,42 @@ trio_exit_code trio_hdf5_free_nucleus(h5nucleus_t* nucleus) { free (nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src *** Read/Write the num attribute - #+begin_src c :tangle trio_hdf5.h -trio_exit_code trio_hdf5_read_nucleus_num(const trio_t* file, uint64_t* num); -trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t num); + #+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 trio_hdf5.c -trio_exit_code trio_hdf5_read_nucleus_num(const trio_t* file, uint64_t* num) { + #+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); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } /**/ *num = nucleus->num; - trio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t num) { +trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint64_t num) { assert (file != NULL); assert (num > 0L); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); assert (nucleus != NULL); @@ -1264,8 +1264,8 @@ trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t nu if (nucleus->num != 0) { printf("%ld -> %ld %s \n", num, nucleus->num, "This variable alreasy exists. Overwriting it is not supported"); - trio_hdf5_free_nucleus(nucleus); - return TRIO_FAILURE; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_FAILURE; } nucleus->num = num; @@ -1286,12 +1286,12 @@ trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t nu nucleus->num = num; } - trio_exit_code rc = trio_hdf5_write_nucleus((trio_hdf5_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_hdf5_write_nucleus((trexio_hdf5_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_hdf5_free_nucleus(nucleus); + trexio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -1300,51 +1300,51 @@ trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t nu The ~coord~ array is assumed allocated with the appropriate size. - #+begin_src c :tangle trio_hdf5.h -trio_exit_code trio_hdf5_read_nucleus_coord(const trio_t* file, double* coord); -trio_exit_code trio_hdf5_write_nucleus_coord(const trio_t* file, const double* coord); + #+begin_src c :tangle trexio_hdf5.h +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord); +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord); #+end_src - #+begin_src c :tangle trio_hdf5.c -trio_exit_code trio_hdf5_read_nucleus_coord(const trio_t* file, double* coord) { + #+begin_src c :tangle trexio_hdf5.c +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord) { assert (file != NULL); assert (coord != NULL); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; assert (nucleus->coord != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { coord[i] = nucleus->coord[i]; } - trio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_write_nucleus_coord(const trio_t* file, const double* coord) { +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord) { assert (file != NULL); assert (coord != NULL); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; assert (nucleus->coord != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { nucleus->coord[i] = coord[i]; } - trio_exit_code rc = trio_hdf5_write_nucleus((trio_hdf5_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_hdf5_write_nucleus((trexio_hdf5_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_hdf5_free_nucleus(nucleus); + trexio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } #+end_src @@ -1352,19 +1352,19 @@ trio_exit_code trio_hdf5_write_nucleus_coord(const trio_t* file, const double* c * File suffixes :noxport: - #+begin_src c :tangle trio.h + #+begin_src c :tangle trexio.h #endif #+end_src - #+begin_src c :tangle trio_s.h + #+begin_src c :tangle trexio_s.h #endif #+end_src - #+begin_src c :tangle trio_text.h + #+begin_src c :tangle trexio_text.h #endif #+end_src - #+begin_src c :tangle trio_hdf5.h + #+begin_src c :tangle trexio_hdf5.h #endif #+end_src diff --git a/src/trio_hdf5.c b/src/trexio_hdf5.c similarity index 80% rename from src/trio_hdf5.c rename to src/trexio_hdf5.c index 34df2e1..c401e06 100644 --- a/src/trio_hdf5.c +++ b/src/trexio_hdf5.c @@ -1,11 +1,11 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute +/* 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 */ -#include "trio_hdf5.h" +#include "trexio_hdf5.h" #define NUCLEUS_GROUP_NAME "nucleus" #define NUCLEUS_NUM_NAME "nucleus_num" @@ -16,7 +16,7 @@ * 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* trio_hdf5_read_dset_low(const trio_hdf5_t* file, const char *dset_name, void *buf) { +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); @@ -63,9 +63,9 @@ dset_t* trio_hdf5_read_dset_low(const trio_hdf5_t* file, const char *dset_name, } -trio_exit_code trio_hdf5_init(trio_t* file) { +trexio_exit_code trexio_hdf5_init(trexio_t* file) { - trio_hdf5_t* f = (trio_hdf5_t*) file; + trexio_hdf5_t* f = (trexio_hdf5_t*) file; /* If file doesn't exist, create it */ int f_ishere = 0; @@ -92,12 +92,12 @@ trio_exit_code trio_hdf5_init(trio_t* file) { assert (f->nucleus_group > 0L); //assert (f->electron_group > 0L); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_finalize(trio_t* file) { +trexio_exit_code trexio_hdf5_finalize(trexio_t* file) { - trio_hdf5_t* f = (trio_hdf5_t*) file; + trexio_hdf5_t* f = (trexio_hdf5_t*) file; H5Gclose(f->nucleus_group); f->nucleus_group = 0; @@ -110,10 +110,10 @@ trio_exit_code trio_hdf5_finalize(trio_t* file) { H5Fclose(f->file_id); f->file_id = 0; - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { +h5nucleus_t* trexio_hdf5_read_nucleus(const trexio_hdf5_t* file) { /* Allocate the data structure */ h5nucleus_t* nucleus = (h5nucleus_t*) malloc(sizeof(h5nucleus_t)); @@ -163,7 +163,7 @@ h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { * when not used anymore, see below. Note how this function is similar to H5LTread_dataset_double */ /* - nucleus->h5_coord = trio_hdf5_read_dset_low(file, NUCLEUS_COORD_NAME, + nucleus->h5_coord = trexio_hdf5_read_dset_low(file, NUCLEUS_COORD_NAME, nucleus->coord); H5Sclose(nucleus->h5_coord->dspace_id); @@ -177,7 +177,7 @@ h5nucleus_t* trio_hdf5_read_nucleus(const trio_hdf5_t* file) { } -trio_exit_code trio_hdf5_write_nucleus(const trio_hdf5_t* file, h5nucleus_t* nucleus) { +trexio_exit_code trexio_hdf5_write_nucleus(const trexio_hdf5_t* file, h5nucleus_t* nucleus) { assert (file != NULL); assert (nucleus != NULL); @@ -287,12 +287,12 @@ trio_exit_code trio_hdf5_write_nucleus(const trio_hdf5_t* file, h5nucleus_t* nuc } - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_free_nucleus(h5nucleus_t* nucleus) { +trexio_exit_code trexio_hdf5_free_nucleus(h5nucleus_t* nucleus) { - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; if (nucleus->coord != NULL) free (nucleus->coord); nucleus->coord = NULL; @@ -308,33 +308,33 @@ trio_exit_code trio_hdf5_free_nucleus(h5nucleus_t* nucleus) { free (nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_read_nucleus_num(const trio_t* file, uint64_t* num) { +trexio_exit_code trexio_hdf5_read_nucleus_num(const trexio_t* file, uint64_t* num) { assert (file != NULL); assert (num != NULL); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } /**/ *num = nucleus->num; - trio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t num) { +trexio_exit_code trexio_hdf5_write_nucleus_num(const trexio_t* file, const uint64_t num) { assert (file != NULL); assert (num > 0L); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); assert (nucleus != NULL); @@ -343,8 +343,8 @@ trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t nu if (nucleus->num != 0) { printf("%ld -> %ld %s \n", num, nucleus->num, "This variable alreasy exists. Overwriting it is not supported"); - trio_hdf5_free_nucleus(nucleus); - return TRIO_FAILURE; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_FAILURE; } nucleus->num = num; @@ -365,51 +365,51 @@ trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t nu nucleus->num = num; } - trio_exit_code rc = trio_hdf5_write_nucleus((trio_hdf5_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_hdf5_write_nucleus((trexio_hdf5_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_hdf5_free_nucleus(nucleus); + trexio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_read_nucleus_coord(const trio_t* file, double* coord) { +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord) { assert (file != NULL); assert (coord != NULL); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; assert (nucleus->coord != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { coord[i] = nucleus->coord[i]; } - trio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_hdf5_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_hdf5_write_nucleus_coord(const trio_t* file, const double* coord) { +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord) { assert (file != NULL); assert (coord != NULL); - h5nucleus_t* nucleus = trio_hdf5_read_nucleus((trio_hdf5_t*) file); + h5nucleus_t* nucleus = trexio_hdf5_read_nucleus((trexio_hdf5_t*) file); - if (nucleus == NULL) return TRIO_FAILURE; + if (nucleus == NULL) return TREXIO_FAILURE; assert (nucleus->coord != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { nucleus->coord[i] = coord[i]; } - trio_exit_code rc = trio_hdf5_write_nucleus((trio_hdf5_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_hdf5_write_nucleus((trexio_hdf5_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_hdf5_free_nucleus(nucleus); + trexio_hdf5_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } diff --git a/src/trio_hdf5.h b/src/trexio_hdf5.h similarity index 54% rename from src/trio_hdf5.h rename to src/trexio_hdf5.h index aac83dd..a6503d1 100644 --- a/src/trio_hdf5.h +++ b/src/trexio_hdf5.h @@ -1,15 +1,15 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute +/* 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 _TRIO_HDF5_H -#define _TRIO_HDF5_H +#ifndef _TREXIO_HDF5_H +#define _TREXIO_HDF5_H -#include "trio.h" -#include "trio_s.h" +#include "trexio.h" +#include "trexio_s.h" #include #include #include @@ -49,23 +49,23 @@ typedef struct h5electron_s { uint64_t beta_num; } h5electron_t; -typedef struct trio_hdf5_s { - trio_t parent ; +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; -} trio_hdf5_t; +} trexio_hdf5_t; -trio_exit_code trio_hdf5_init(trio_t* file); +trexio_exit_code trexio_hdf5_init(trexio_t* file); -trio_exit_code trio_hdf5_finalize(trio_t* file); +trexio_exit_code trexio_hdf5_finalize(trexio_t* file); -trio_exit_code trio_hdf5_read_nucleus_num(const trio_t* file, uint64_t* num); -trio_exit_code trio_hdf5_write_nucleus_num(const trio_t* file, const uint64_t num); +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); -trio_exit_code trio_hdf5_read_nucleus_coord(const trio_t* file, double* coord); -trio_exit_code trio_hdf5_write_nucleus_coord(const trio_t* file, const double* coord); +trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* coord); +trexio_exit_code trexio_hdf5_write_nucleus_coord(const trexio_t* file, const double* coord); #endif diff --git a/src/trio_s.h b/src/trexio_s.h similarity index 59% rename from src/trio_s.h rename to src/trexio_s.h index 6c59256..4810d10 100644 --- a/src/trio_s.h +++ b/src/trexio_s.h @@ -1,18 +1,18 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute +/* 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 _TRIO_S_H -#define _TRIO_S_H +#ifndef _TREXIO_S_H +#define _TREXIO_S_H -#include "trio.h" +#include "trexio.h" #include #include -struct trio_s { +struct trexio_s { char* file_name; pthread_mutex_t thread_lock; back_end_t back_end; diff --git a/src/trio_text.c b/src/trexio_text.c similarity index 64% rename from src/trio_text.c rename to src/trexio_text.c index 6a2313d..d09020f 100644 --- a/src/trio_text.c +++ b/src/trexio_text.c @@ -1,15 +1,15 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute +/* 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 */ -#include "trio_text.h" +#include "trexio_text.h" -trio_exit_code trio_text_init(trio_t* file) { +trexio_exit_code trexio_text_init(trexio_t* file) { - trio_text_t* f = (trio_text_t*) file; + trexio_text_t* f = (trexio_text_t*) file; /* If directory doesn't exist, create it */ struct stat st; @@ -18,7 +18,7 @@ trio_exit_code trio_text_init(trio_t* file) { /* Do nothing */ } else { if (mkdir(file->file_name, 0777) != 0) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } } @@ -40,12 +40,12 @@ trio_exit_code trio_text_init(trio_t* file) { strcpy (f->electron_file_name, file->file_name); strcat (f->electron_file_name, electron_file_name); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_text_finalize(trio_t* file) { +trexio_exit_code trexio_text_finalize(trexio_t* file) { - trio_text_t* f = (trio_text_t*) file; + trexio_text_t* f = (trexio_text_t*) file; free (f->nucleus_file_name); f->nucleus_file_name = NULL; @@ -53,10 +53,10 @@ trio_exit_code trio_text_finalize(trio_t* file) { free (f->electron_file_name); f->electron_file_name = NULL; - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -nucleus_t* trio_text_read_nucleus(const trio_text_t* file) { +nucleus_t* trexio_text_read_nucleus(const trexio_text_t* file) { /* Allocate the data structure */ nucleus_t* nucleus = (nucleus_t*) malloc(sizeof(nucleus_t)); @@ -112,7 +112,7 @@ nucleus_t* trio_text_read_nucleus(const trio_text_t* file) { } -trio_exit_code trio_text_write_nucleus(const trio_text_t* file, nucleus_t* nucleus) { +trexio_exit_code trexio_text_write_nucleus(const trexio_text_t* file, nucleus_t* nucleus) { assert (nucleus != NULL); FILE* f = fopen(file->nucleus_file_name,"w"); @@ -133,13 +133,13 @@ trio_exit_code trio_text_write_nucleus(const trio_text_t* file, nucleus_t* nucle } fclose(f); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_text_free_nucleus(nucleus_t* nucleus) { +trexio_exit_code trexio_text_free_nucleus(nucleus_t* nucleus) { if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } if (nucleus->coord != NULL) { @@ -153,33 +153,33 @@ trio_exit_code trio_text_free_nucleus(nucleus_t* nucleus) { nucleus->charge = NULL; free (nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_text_read_nucleus_num(const trio_t* file, uint64_t* num) { +trexio_exit_code trexio_text_read_nucleus_num(const trexio_t* file, uint64_t* num) { assert (file != NULL); assert (num != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } /**/ *num = nucleus->num; - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t num) { +trexio_exit_code trexio_text_write_nucleus_num(const trexio_t* file, const uint64_t num) { assert (num > 0L); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); assert (nucleus != NULL); @@ -203,22 +203,22 @@ trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t nu nucleus->num = num; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord) { +trexio_exit_code trexio_text_read_nucleus_coord(const trexio_t* file, double* coord) { assert (file != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } assert (coord != NULL); @@ -227,39 +227,39 @@ trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord) { coord[i] = nucleus->coord[i]; } - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_coord(const trio_t* file, const double* coord) { +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord) { assert (coord != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*) file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*) file); assert (nucleus != NULL); for (size_t i=0 ; i<3*nucleus->num ; i++) { nucleus->coord[i] = coord[i]; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } -trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* charge) { +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* charge) { assert (file != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*)file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*)file); if (nucleus == NULL) { - return TRIO_FAILURE; + return TREXIO_FAILURE; } assert (charge != NULL); @@ -268,27 +268,27 @@ trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* charge) charge[i] = nucleus->charge[i]; } - trio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + trexio_text_free_nucleus(nucleus); + return TREXIO_SUCCESS; } -trio_exit_code trio_text_write_nucleus_charge(const trio_t* file, const double* charge) { +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* charge) { assert (charge != NULL); assert (file != NULL); - nucleus_t* nucleus = trio_text_read_nucleus((trio_text_t*)file); + nucleus_t* nucleus = trexio_text_read_nucleus((trexio_text_t*)file); assert (nucleus != NULL); for (size_t i=0 ; inum ; i++) { nucleus->charge[i] = charge[i]; } - trio_exit_code rc = trio_text_write_nucleus((trio_text_t*) file, nucleus); - assert (rc == TRIO_SUCCESS); + trexio_exit_code rc = trexio_text_write_nucleus((trexio_text_t*) file, nucleus); + assert (rc == TREXIO_SUCCESS); - trio_text_free_nucleus(nucleus); + trexio_text_free_nucleus(nucleus); - return TRIO_SUCCESS; + return TREXIO_SUCCESS; } diff --git a/src/trexio_text.h b/src/trexio_text.h new file mode 100644 index 0000000..78de672 --- /dev/null +++ b/src/trexio_text.h @@ -0,0 +1,50 @@ +/* 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_s.h" +#include +#include +#include +#include +#include +#include + +typedef struct nucleus_s { + double* coord; + double* charge; + uint64_t num; +} nucleus_t; + +typedef struct electron_s { + uint64_t alpha_num; + uint64_t beta_num; +} electron_t; + +typedef struct trexio_text_s { + trexio_t parent ; + char* nucleus_file_name; + char* electron_file_name; +} trexio_text_t; + +trexio_exit_code trexio_text_init(trexio_t* file); + +trexio_exit_code trexio_text_finalize(trexio_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); +trexio_exit_code trexio_text_write_nucleus_coord(const trexio_t* file, const double* coord); + +trexio_exit_code trexio_text_read_nucleus_charge(const trexio_t* file, double* coord); +trexio_exit_code trexio_text_write_nucleus_charge(const trexio_t* file, const double* coord); + +#endif diff --git a/src/trio.c b/src/trio.c deleted file mode 100644 index 6ca20f8..0000000 --- a/src/trio.c +++ /dev/null @@ -1,254 +0,0 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute - M-x org-babel-tangle -*/ - - - -#include -#include -#include -#include -#include - -#include "trio.h" -#include "trio_s.h" -#include "trio_text.h" -#include "trio_hdf5.h" -/* -#include "trio_json.h" -*/ - -trio_t* trio_create(const char* file_name, back_end_t back_end) { - - /* Check that file name is not NULL or empty */ - assert (file_name != NULL); - assert (file_name[0] != '\0'); - - /* Check that back_end is valid */ - assert (back_end < TRIO_INVALID_BACK_END); - - trio_t* result = NULL; - - switch (back_end) { - - case TRIO_TEXT: - result = (trio_t*) malloc (sizeof(trio_text_t)); - break; - - case TRIO_HDF5: - result = (trio_t*) malloc (sizeof(trio_hdf5_t)); - break; -/* - case TRIO_JSON: - result = (trio_t*) malloc (sizeof(trio_json_t)); - break; -*/ - default: - assert (1 == 0); /* Impossible case */ - } - - /* TODO: Error handling */ - assert (result != NULL); - - result->file_name = (char*) calloc(strlen(file_name)+1,sizeof(char)); - strcpy(result->file_name, file_name); - result->back_end = back_end; - result->mode = 'w'; /* Upon creation, mode=write */ - int irc = pthread_mutex_init ( &(result->thread_lock), NULL); - assert (irc == 0); - - trio_exit_code rc = TRIO_FAILURE; - - switch (back_end) { - - case TRIO_TEXT: - rc = trio_text_init(result); - break; - - case TRIO_HDF5: - rc = trio_hdf5_init(result); - break; -/* - case TRIO_JSON: - rc = trio_json_init(result); - break; -*/ - default: - assert (1 == 0); /* Impossible case */ - } - assert (rc == TRIO_SUCCESS); - - return result; -} - -trio_exit_code trio_close(trio_t* file) { - - assert (file != NULL); - - trio_exit_code rc; - - switch (file->back_end) { - - case TRIO_TEXT: - rc = trio_text_finalize(file); - break; - - case TRIO_HDF5: - rc = trio_hdf5_finalize(file); - break; -/* - case TRIO_JSON: - rc = trio_json_finalize(file); - break; -*/ - default: - assert (1 == 0); /* Impossible case */ - } - - if (rc != TRIO_SUCCESS) { - return TRIO_FAILURE; - } - - free(file->file_name); - file->file_name = NULL; - - int irc = pthread_mutex_destroy( &(file->thread_lock) ); - assert (irc == 0); - - free(file); - - return TRIO_SUCCESS; -} - -trio_exit_code trio_read_nucleus_num(trio_t* file, uint64_t* num) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_read_nucleus_num(file, num); - break; - - case TRIO_HDF5: - return trio_hdf5_read_nucleus_num(file, num); - break; -/* - case TRIO_JSON: - return trio_json_read_nucleus_num(file, num); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} - -trio_exit_code trio_write_nucleus_num(trio_t* file, uint64_t num) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_write_nucleus_num(file, num); - break; - - case TRIO_HDF5: - return trio_hdf5_write_nucleus_num(file, num); - break; -/* - case TRIO_JSON: - return trio_json_write_nucleus_num(file, num); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} - -trio_exit_code trio_read_nucleus_coord(trio_t* file, double* coord) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_read_nucleus_coord(file, coord); - break; - - case TRIO_HDF5: - return trio_hdf5_read_nucleus_coord(file, coord); - break; -/* - case TRIO_JSON: - return trio_json_read_nucleus_coord(file, coord); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} - -trio_exit_code trio_write_nucleus_coord(trio_t* file, double* coord) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_write_nucleus_coord(file, coord); - break; - - case TRIO_HDF5: - return trio_hdf5_write_nucleus_coord(file, coord); - break; -/* - case TRIO_JSON: - return trio_json_write_nucleus_coord(file, coord); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} - -trio_exit_code trio_read_nucleus_charge(trio_t* file, double* charge) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_read_nucleus_charge(file, charge); - break; -/* - case TRIO_HDF5: - return trio_hdf5_read_nucleus_charge(file, charge); - break; - - case TRIO_JSON: - return trio_json_read_nucleus_charge(file, charge); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} - -trio_exit_code trio_write_nucleus_charge(trio_t* file, double* charge) { - if (file == NULL) return TRIO_FAILURE; - - switch (file->back_end) { - - case TRIO_TEXT: - return trio_text_write_nucleus_charge(file, charge); - break; -/* - case TRIO_HDF5: - return trio_hdf5_write_nucleus_charge(file, charge); - break; - - case TRIO_JSON: - return trio_json_write_nucleus_charge(file, charge); - break; -*/ - default: - return TRIO_FAILURE; /* Impossible case */ - } -} diff --git a/src/trio.h b/src/trio.h deleted file mode 100644 index 46f9538..0000000 --- a/src/trio.h +++ /dev/null @@ -1,40 +0,0 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute - M-x org-babel-tangle -*/ - - - -#ifndef _TRIO_H -#define _TRIO_H - -#include - -typedef int32_t trio_exit_code; - -#define TRIO_SUCCESS ( (trio_exit_code) 0 ) -#define TRIO_FAILURE ( (trio_exit_code) 1 ) - -typedef uint32_t back_end_t; - -#define TRIO_HDF5 ( (back_end_t) 0 ) -#define TRIO_TEXT ( (back_end_t) 1 ) -#define TRIO_JSON ( (back_end_t) 2 ) -#define TRIO_INVALID_BACK_END ( (back_end_t) 3 ) - -typedef struct trio_s trio_t; - -trio_t* trio_create(const char* file_name, back_end_t back_end); - -trio_exit_code trio_close(trio_t* file); - -trio_exit_code trio_read_nucleus_num(trio_t* file, uint64_t* num); -trio_exit_code trio_write_nucleus_num(trio_t* file, uint64_t num); - -trio_exit_code trio_read_nucleus_coord(trio_t* file, double* coord); -trio_exit_code trio_write_nucleus_coord(trio_t* file, double* coord); - -trio_exit_code trio_read_nucleus_charge(trio_t* file, double* charge); -trio_exit_code trio_write_nucleus_charge(trio_t* file, double* charge); - -#endif diff --git a/src/trio_text.h b/src/trio_text.h deleted file mode 100644 index c52f8de..0000000 --- a/src/trio_text.h +++ /dev/null @@ -1,50 +0,0 @@ -/* This file was generated from the trio.org org-mode file. - To generate it, open trio.org in Emacs and execute - M-x org-babel-tangle -*/ - - - -#ifndef _TRIO_TEXT_H -#define _TRIO_TEXT_H - -#include "trio.h" -#include "trio_s.h" -#include -#include -#include -#include -#include -#include - -typedef struct nucleus_s { - double* coord; - double* charge; - uint64_t num; -} nucleus_t; - -typedef struct electron_s { - uint64_t alpha_num; - uint64_t beta_num; -} electron_t; - -typedef struct trio_text_s { - trio_t parent ; - char* nucleus_file_name; - char* electron_file_name; -} trio_text_t; - -trio_exit_code trio_text_init(trio_t* file); - -trio_exit_code trio_text_finalize(trio_t* file); - -trio_exit_code trio_text_read_nucleus_num(const trio_t* file, uint64_t* num); -trio_exit_code trio_text_write_nucleus_num(const trio_t* file, const uint64_t num); - -trio_exit_code trio_text_read_nucleus_coord(const trio_t* file, double* coord); -trio_exit_code trio_text_write_nucleus_coord(const trio_t* file, const double* coord); - -trio_exit_code trio_text_read_nucleus_charge(const trio_t* file, double* coord); -trio_exit_code trio_text_write_nucleus_charge(const trio_t* file, const double* coord); - -#endif