diff --git a/README.html b/README.html index 9ca26a8..fd76342 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- +
As the size of the dataset should be extensible, the simplest
@@ -256,8 +256,8 @@ The offset can be used with fseek(69L*offset, SEEK_SET)
We need to declare the number of rows of the dataset as @@ -278,7 +278,7 @@ If the offset+num > nmax, we need to extend the dataset.
stdint.h
Memory allocation of structures can be facilitated by using the @@ -438,8 +483,8 @@ The maximum string size for the filenames is 4096 characters.
All calls to TREXIO are thread-safe. @@ -447,10 +492,10 @@ TREXIO front end is modular, which simplifies implementation of new back ends.
TREXIO_ATTR_ALREADY_EXISTS |
13 | -'Attribute (num/str) already exists' | +'Attribute already exists' |
'Error writing element' | |||
TREXIO_UNSAFE_ARRAY_DIM |
+23 | +'Access to memory beyond allocated' | +|
TREXIO_ATTR_MISSING |
+24 | +'Attribute does not exist in the file' | +|
TREXIO_DSET_MISSING |
+25 | +'Dataset does not exist in the file' | +|
TREXIO_INVALID_STR_LEN |
30 | @@ -620,16 +683,49 @@ TREXIO front end is modular, which simplifies implementation of new back ends.
""" This script generates the C and Fortran constants for the error + codes from the org-mode table. +""" + +result = [ "#+begin_src c :tangle prefix_front.h :exports none" ] +for (text, code,_) in table: + text=text.replace("~","") + result += [ f"#define {text:30s} ((trexio_exit_code) {code:d})" ] +result += [ "#+end_src" ] + +result += [ "" ] + +result += [ "#+begin_src f90 :tangle prefix_fortran.f90 :exports none" ] +for (text, code,_) in table: + text=text.replace("~","") + result += [ f" integer(trexio_exit_code), parameter :: {text:30s} = {code:d}" ] +result += [ "#+end_src" ] + +result += [ "" ] + +result += [ "#+begin_src python :tangle prefix_python.py :exports none" ] +result += [ "# define TREXIO exit codes" ] +for (text, code,_) in table: + text=text.replace("~","") + result += [ f"{text:30s} = {code:d}" ] +result += [ "#+end_src" ] + +return '\n'.join(result) + ++
The trexio_string_of_error
converts an exit code into a string. The
string is assumed to be large enough to contain the error message
(typically 128 characters).
-◉ Decoding errors -
-
To decode the error messages, trexio_string_of_error
converts an
error code into a string.
@@ -643,87 +739,100 @@ error code into a string.
The text strings are extracted from the previous table.
+const char* trexio_string_of_error (const trexio_exit_code error) { switch (error) { case TREXIO_FAILURE: - return "Unknown failure"; - break; + return "Unknown failure"; + break; case TREXIO_SUCCESS: - return "Success"; - break; + return "Success"; + break; case TREXIO_INVALID_ARG_1: - return "Invalid argument 1"; - break; + return "Invalid argument 1"; + break; case TREXIO_INVALID_ARG_2: - return "Invalid argument 2"; - break; + return "Invalid argument 2"; + break; case TREXIO_INVALID_ARG_3: - return "Invalid argument 3"; - break; + return "Invalid argument 3"; + break; case TREXIO_INVALID_ARG_4: - return "Invalid argument 4"; - break; + return "Invalid argument 4"; + break; case TREXIO_INVALID_ARG_5: - return "Invalid argument 5"; - break; + return "Invalid argument 5"; + break; case TREXIO_END: - return "End of file"; - break; + return "End of file"; + break; case TREXIO_READONLY: - return "Read-only file"; - break; + return "Read-only file"; + break; case TREXIO_ERRNO: - return strerror(errno); - break; + return strerror(errno); + break; case TREXIO_INVALID_ID: - return "Invalid ID"; - break; + return "Invalid ID"; + break; case TREXIO_ALLOCATION_FAILED: - return "Allocation failed"; - break; + return "Allocation failed"; + break; case TREXIO_HAS_NOT: - return "Element absent"; - break; + return "Element absent"; + break; case TREXIO_INVALID_NUM: - return "Invalid dimensions"; - break; + return "Invalid dimensions"; + break; case TREXIO_ATTR_ALREADY_EXISTS: - return "Attribute (num/str) already exists"; - break; + return "Attribute already exists"; + break; case TREXIO_DSET_ALREADY_EXISTS: - return "Dataset already exists"; - break; + return "Dataset already exists"; + break; case TREXIO_OPEN_ERROR: - return "Error opening file"; - break; + return "Error opening file"; + break; case TREXIO_LOCK_ERROR: - return "Error locking file"; - break; + return "Error locking file"; + break; case TREXIO_UNLOCK_ERROR: - return "Error unlocking file"; - break; + return "Error unlocking file"; + break; case TREXIO_FILE_ERROR: - return "Invalid file handle"; - break; + return "Invalid file handle"; + break; case TREXIO_GROUP_READ_ERROR: - return "Error reading group"; - break; + return "Error reading group"; + break; case TREXIO_GROUP_WRITE_ERROR: - return "Error writing group"; - break; + return "Error writing group"; + break; case TREXIO_ELEM_READ_ERROR: - return "Error reading element"; - break; + return "Error reading element"; + break; case TREXIO_ELEM_WRITE_ERROR: - return "Error writing element"; - break; + return "Error writing element"; + break; + case TREXIO_UNSAFE_ARRAY_DIM: + return "Access to memory beyond allocated"; + break; + case TREXIO_ATTR_MISSING: + return "Attribute does not exist in the file"; + break; + case TREXIO_DSET_MISSING: + return "Dataset does not exist in the file"; + break; case TREXIO_INVALID_STR_LEN: - return "Invalid max_str_len"; - break; + return "Invalid max_str_len"; + break; } return "Unknown error"; } @@ -735,7 +844,12 @@ The text strings are extracted from the previous table. }
interface subroutine trexio_string_of_error (error, string) bind(C, name='trexio_string_of_error_f') @@ -750,8 +864,48 @@ The text strings are extracted from the previous table.
class Error(Exception): + """Base class for TREXIO errors. + + Attributes: + error: int -- exit code returned by the call to TREXIO library; + message: str -- decoded string corresponding to trexio_exit_code. + + """ + + def __init__(self, trexio_return_code): + self.error = trexio_return_code + self.message = string_of_error(trexio_return_code) + super().__init__(self.message) + + +def string_of_error(return_code: int) -> str: + """Decode the TREXIO exit code. + + Argument is an integer return code that correspond to one of the TREXIO errors. + + Returns string that contains description of TREXIO ~return_code~. + """ + + try: + error_str = pytr.trexio_string_of_error(return_code) + except: + raise + + return error_str ++
TREXIO has several back ends:
@@ -770,6 +924,14 @@ Then the corresponding back-end has/read/write
functions has to be
lines that correspond to the TREXIO_JSON
back end (not implemented yet).
+Note: It is important to increment the value of TREXIOINVALIDBACKEND when a new back end is added. Otherwise, it will not be available. +
+typedef int32_t back_end_t;
@@ -783,8 +945,37 @@ lines that correspond to the TREXIO_JSON
back end (not implemented
integer(trexio_backend), parameter :: TREXIO_HDF5 = 0 + integer(trexio_backend), parameter :: TREXIO_TEXT = 1 +! integer(trexio_backend), parameter :: TREXIO_JSON = 2 + integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2 ++
# define TREXIO back ends +TREXIO_HDF5 = 0 +TREXIO_TEXT = 1 +#TREXIO_JSON = 2 +TREXIO_INVALID_BACK_END = 2 ++
Every time a reading function is called, the data is read from the @@ -812,8 +1003,8 @@ concurrent programs, the behavior is not specified.
trexio_s
is the the main type for TREXIO files, visible to the users
@@ -846,9 +1037,83 @@ TREXIO files will have as a first argument the TREXIO file handle.
class File: + """TREXIO File object. + + General information about the TREXIO file. + + Parameters: + + filename: str + Is a name of the full path to the TREXIO file. + back_end: int + One of the currently supported TREXIO back ends. + For example, TREXIO_HDF5 (0) or TREXIO_TEXT (1). + mode: str + One of the currently supported TREXIO open modes. + For example, 'r' or 'w'. + isOpen: bool + Flag indicating whether the current object is still open for I/O + pytrexio_s: + A PyObject corresponding to SWIG proxy of the trexio_s struct in C. + This argument is in fact a TREXIO file handle, which is required for + communicating with the C back end. + info: dict + Dictionary of key-value pairs with additional information about the file. + """ + + + def __init__(self, filename, mode='r', back_end=TREXIO_HDF5, + pytrexio_s=None, info=None): + """This is a TREXIO File constructor.""" + + self.filename = filename + self.mode = mode + self.back_end = back_end + + self.isOpen = False + if pytrexio_s is None: + self.pytrexio_s = open(filename, mode, back_end) + self.isOpen = True + else: + self.pytrexio_s = pytrexio_s + self.isOpen = None + + self.info = info + + + def close(self): + """Close a TREXIO File.""" + + if self.isOpen: + close(self.pytrexio_s) + self.isOpen = False + else: + raise Exception("TREXIO File object has not been opened.") + + + def __del__(self): + """This is a TREXIO File destructor.""" + + if self.isOpen: + close(self.pytrexio_s) + elif self.isOpen is None: + raise Exception("[WIP]: TREXIO file handle provided but what if the file is already closed?") + else: + pass +
Polymorphism of the trexio_t
type is handled by ensuring that the
@@ -867,8 +1132,8 @@ corresponding types for all back ends can be safely casted to
trexio_open
creates a new TREXIO file or opens existing one.
@@ -905,7 +1170,11 @@ data). These names are populated by the generator.py (i.e. they
are hard-coded), which is why the user should tend to avoid
renaming the .txt
data files.
trexio_t* trexio_open(const char* file_name, const char mode, @@ -963,6 +1232,10 @@ renaming the.txt
data files. result->mode = mode; result->one_based = false; // Need to be flipped in Fortran interface int irc = pthread_mutex_init ( &(result->thread_lock), NULL); + if (irc != 0) { + free(result); + return NULL; + } assert (irc == 0); trexio_exit_code rc; @@ -1051,7 +1324,12 @@ renaming the.txt
data files. }
interface
integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open")
@@ -1064,7 +1342,50 @@ renaming the .txt
data files.
end interface
def open(file_name: str, mode: str, back_end: int): + """Create TREXIO file or open existing one. + + Parameters: + + file_name: str + Name of the TREXIO file + + mode: str + One of the currently supported ~open~ modes (e.g. 'w', 'r') + + back_end: int + One of the currently supported TREXIO back ends (e.g. TREXIO_HDF5, TREXIO_TEXT) + + Return: + SWIG object of type trexio_s. + + Examples: + >>> from trexio import open as tr_open + >>> trex_file = tr_open("example.h5", "w", TREXIO_HDF5) + """ + + try: + trexio_file = pytr.trexio_open(file_name, mode, back_end) + assert trexio_file is not None + except AssertionError: + raise Exception(f"Could not open TREXIO file {file_name} using trexio_open function. Please make sure that there are no typos in the file name.") + + return trexio_file ++
Because arrays are zero-based in Fortran, we need to set a flag to know if we need to shift by 1 arrays of indices. @@ -1094,9 +1415,10 @@ know if we need to shift by 1 arrays of indices.
trexio_close
closes an existing trexio_t
file.
@@ -1111,7 +1433,11 @@ input parameters:
output:
trexio_exit_code
exit code.
trexio_exit_code trexio_close (trexio_t* file) @@ -1178,7 +1504,12 @@ output: }
interface integer function trexio_close (trex_file) bind(C) @@ -1190,14 +1521,36 @@ output:
def close(trexio_file): + """Close TREXIO file. + + Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function. + """ + + try: + rc = pytr.trexio_close(trexio_file) + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise ++
Consider the following block of trex.json
:
@@ -1356,6 +1709,12 @@ each variable can be found below:
(:,:)
$group_dset_py_dtype$
float/int
This section concerns API calls related to dimensioning variables. @@ -1457,8 +1816,8 @@ This section concerns API calls related to dimensioning variables.
The C
templates that correspond to each of the abovementioned
@@ -1477,6 +1836,7 @@ precision (see Table above).
trexio_read_$group_num$_64 (trexio_t* const file, int64_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
+ if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
uint64_t u_num = 0;
trexio_exit_code rc = TREXIO_GROUP_READ_ERROR;
@@ -1539,6 +1899,7 @@ precision (see Table above).
trexio_read_$group_num$_32 (trexio_t* const file, int32_t* const num)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
+ if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
uint64_t u_num = 0;
trexio_exit_code rc = TREXIO_GROUP_READ_ERROR;
@@ -1647,8 +2008,8 @@ precision (see Table above).
The Fortran
templates that provide an access to the C
API calls from Fortran.
@@ -1732,10 +2093,95 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_num$(trexio_file, num_w: int) -> None: + """Write the $group_num$ variable in the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + num_w: int + Value of the $group_num$ variable to be written. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_write_$group_num$(trexio_file.pytrexio_s, num_w) + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise +
def read_$group_num$(trexio_file) -> int: + """Read the $group_num$ variable from the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + ~num_r~: int + Integer value of $group_num$ variable read from ~trexio_file~. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc, num_r = pytr.trexio_read_$group_num$(trexio_file.pytrexio_s) + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + + return num_r ++
def has_$group_num$(trexio_file) -> bool: + """Check that $group_num$ variable exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_has_$group_num$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + except: + raise + + if rc == TREXIO_SUCCESS: + return True + else: + return False ++
This section concerns API calls related to datasets. @@ -1767,45 +2213,57 @@ This section concerns API calls related to datasets.
trexio_read_$group_dset$
trexio_write_$group_dset$
trexio_read_safe_$group_dset$
trexio_write_safe_$group_dset$
trexio_read_$group_dset$_32
trexio_write_$group_dset$_32
trexio_read_$group_dset$_64
trexio_write_$group_dset$_64
The C templates that correspond to each of the abovementioned functions can be found below.
@@ -1814,8 +2272,16 @@ to/from the TREXIO
file (except for trexio_has_
functi
Suffixes _32
and _64
correspond to API calls dealing with single and double precision, respectively.
The basic (non-suffixed) API call on datasets deals with double precision (see Table above).
trexio_exit_code trexio_read_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* const $group_dset$) @@ -1823,13 +2289,13 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T if (file == NULL) return TREXIO_INVALID_ARG_1; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; trexio_exit_code rc; int64_t $group_dset_dim$ = 0; /* Error handling for this call is added by the generator */ rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); - if (rc != TREXIO_SUCCESS) return rc; if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; @@ -1872,6 +2338,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
trexio_exit_code trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_double$* $group_dset$) @@ -1886,7 +2353,6 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T /* Error handling for this call is added by the generator */ rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); - if (rc != TREXIO_SUCCESS) return rc; if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; @@ -1939,7 +2405,12 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T }
trexio_exit_code trexio_read_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* const $group_dset$) @@ -1947,6 +2418,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T if (file == NULL) return TREXIO_INVALID_ARG_1; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; trexio_exit_code rc; int64_t $group_dset_dim$ = 0; @@ -2008,6 +2480,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
trexio_exit_code trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_single$* $group_dset$) @@ -2074,6 +2547,191 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T }
trexio_exit_code rc; +int64_t $group_dset_dim$ = 0; + +/* Error handling for this call is added by the generator */ +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; + +uint32_t rank = $group_dset_rank$; +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + +/* The block below is specific to safe API as it checks the boundaries */ +uint64_t dim_size = 1; +for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; +} ++
trexio_exit_code +trexio_read_safe_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* const dset_out, const int64_t dim_out) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (dset_out == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; + +trexio_exit_code rc; +int64_t $group_dset_dim$ = 0; + +/* Error handling for this call is added by the generator */ +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; + +uint32_t rank = $group_dset_rank$; +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + +/* The block below is specific to safe API as it checks the boundaries */ +uint64_t dim_size = 1; +for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; +} + + if (dim_out > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM; + + return trexio_read_$group_dset$_32(file, dset_out); +} ++
trexio_exit_code +trexio_write_safe_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_single$* dset_in, const int64_t dim_in) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (dset_in == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; + +trexio_exit_code rc; +int64_t $group_dset_dim$ = 0; + +/* Error handling for this call is added by the generator */ +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; + +uint32_t rank = $group_dset_rank$; +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + +/* The block below is specific to safe API as it checks the boundaries */ +uint64_t dim_size = 1; +for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; +} + + if (dim_in > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM; + + return trexio_write_$group_dset$_32(file, dset_in); +} ++
trexio_exit_code +trexio_read_safe_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* const dset_out, const int64_t dim_out) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (dset_out == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; + +trexio_exit_code rc; +int64_t $group_dset_dim$ = 0; + +/* Error handling for this call is added by the generator */ +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; + +uint32_t rank = $group_dset_rank$; +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + +/* The block below is specific to safe API as it checks the boundaries */ +uint64_t dim_size = 1; +for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; +} + + if (dim_out > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM; + + return trexio_read_$group_dset$_64(file, dset_out); +} ++
trexio_exit_code +trexio_write_safe_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_double$* dset_in, const int64_t dim_in) +{ + + if (file == NULL) return TREXIO_INVALID_ARG_1; + if (dset_in == NULL) return TREXIO_INVALID_ARG_2; + if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; + +trexio_exit_code rc; +int64_t $group_dset_dim$ = 0; + +/* Error handling for this call is added by the generator */ +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$)); + +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM; + +uint32_t rank = $group_dset_rank$; +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; + +/* The block below is specific to safe API as it checks the boundaries */ +uint64_t dim_size = 1; +for (uint32_t i=0; i<rank; ++i){ + dim_size *= dims[i]; +} + + if (dim_in > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM; + + return trexio_write_$group_dset$_64(file, dset_in); +} ++
trexio_exit_code +trexio_read_safe_$group_dset$ (trexio_t* const file, $group_dset_dtype_default$* const $group_dset$, const int64_t dim_out) +{ + return trexio_read_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_out); +} ++
trexio_exit_code +trexio_write_safe_$group_dset$ (trexio_t* const file, const $group_dset_dtype_default$* $group_dset$, const int64_t dim_in) +{ + return trexio_write_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_in); +} ++
trexio_exit_code
@@ -2084,6 +2742,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
trexio_exit_code trexio_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype_default$* $group_dset$) @@ -2093,6 +2752,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
trexio_exit_code trexio_has_$group_dset$ (trexio_t* const file) @@ -2123,9 +2783,10 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
The Fortran
templates that provide an access to the C
API calls from Fortran
.
@@ -2209,10 +2870,205 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_dset$(trexio_file, dset_w) -> None: + """Write the $group_dset$ array of numbers in the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + dset_w: list OR numpy.ndarray + Array of $group_dset$ values to be written. If array data type does not correspond to int64 or float64, the conversion is performed. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + import numpy as np + except ImportError: + raise Exception("NumPy cannot be imported.") + + doConversion = False + doFlatten = False + if not isinstance(dset_w, (list, tuple)): + # if input array is not a list or tuple then it is probably a numpy array + if isinstance(dset_w, np.ndarray) and (not dset_w.dtype==np.int64 or not dset_w.dtype==np.float64): + doConversion = True + + if len(dset_w.shape) > 1: + doFlatten = True + if doConversion: + dset_64 = np.$group_dset_py_dtype$64(dset_w).flatten() + else: + dset_flat = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten() + else: + if doConversion: + dset_64 = np.$group_dset_py_dtype$64(dset_w) + + else: + # if input array is a multidimensional list or tuple, we have to convert it + try: + doFlatten = True + ncol = len(dset_w[0]) + dset_flat = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten() + except TypeError: + doFlatten = False + pass + + + if doConversion: + rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_64) + elif doFlatten: + rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_flat) + else: + rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_w) + + if rc != TREXIO_SUCCESS: + raise Error(rc) +
def read_$group_dset$(trexio_file, dim = None, doReshape = None, dtype = None): + """Read the $group_dset$ array of numbers from the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + dim (Optional): int + Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned) + If None, the function will read all necessary array dimensions from the file. + + dtype (Optional): type + NumPy data type of the output (e.g. np.int32|int16 or np.float32|float16). If specified, the output array will be converted from the default double precision. + + doReshape (Optional): bool + Flag to determine whether the output NumPy array has be reshaped or not. Be default, reshaping is performed + based on the dimensions from the ~trex.json~ file. Otherwise, ~shape~ array (list or tuple) is used if provided by the user. + + Returns: + ~dset_64~ if dtype is None or ~dset_converted~ otherwise: numpy.ndarray + 1D NumPy array with ~dim~ elements corresponding to $group_dset$ values read from the TREXIO file. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). +""" + + try: + import numpy as np + except ImportError: + raise Exception("NumPy cannot be imported.") + + if doReshape is None: + doReshape = True + + # if dim is not specified, read dimensions from the TREXIO file + dims_list = None + if dim is None or doReshape: + $group_dset_dim$ = read_$group_dset_dim$(trexio_file) + + dims_list = [$group_dset_dim_list$] + dim = 1 + for i in range($group_dset_rank$): + dim *= dims_list[i] + + + shape = tuple(dims_list) + if shape is None and doReshape: + raise ValueError("Reshaping failure: shape is None.") + + try: + rc, dset_64 = pytr.trexio_read_safe_$group_dset$_64(trexio_file.pytrexio_s, dim) + + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + + + isConverted = False + dset_converted = None + if dtype is not None: + + try: + assert isinstance(dtype, type) + except AssertionError: + raise TypeError("dtype argument has to be an instance of the type class (e.g. np.float32).") + + + if not dtype==np.int64 or not dtype==np.float64: + try: + dset_converted = np.array(dset_64, dtype=dtype) + except: + raise + + isConverted = True + + # additional assert can be added here to check that read_safe functions returns numpy array of proper dimension + + if doReshape: + try: + # in-place reshaping did not work so I have to make a copy + if isConverted: + dset_reshaped = np.reshape(dset_converted, shape, order='C') + else: + dset_reshaped = np.reshape(dset_64, shape, order='C') + except: + raise + + if isConverted: + return dset_converted + elif doReshape: + return dset_reshaped + else: + return dset_64 ++
def has_$group_dset$(trexio_file) -> bool: + """Check that $group_dset$ variable exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + except: + raise + + if rc == TREXIO_SUCCESS: + return True + else: + return False ++
Sparse data structures are used typically for large tensors such as @@ -2353,12 +3209,12 @@ For the values,
This section concerns API calls related to datasets of strings. @@ -2398,8 +3254,8 @@ This section concerns API calls related to datasets of strings.
First parameter is the TREXIO
file handle. Second parameter is the variable to be written/read
@@ -2409,12 +3265,13 @@ to/from the TREXIO
file (except for trexio_has_
functi
trexio_exit_code -trexio_read_$group_dset$_low (trexio_t* const file, char* dset, const uint32_t max_str_len) +trexio_read_$group_dset$_low (trexio_t* const file, char* dset_out, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (dset == NULL) return TREXIO_INVALID_ARG_2; + if (dset_out == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; trexio_exit_code rc; int64_t $group_dset_dim$ = 0; @@ -2431,15 +3288,15 @@ to/from theTREXIO
file (except fortrexio_has_
functi switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_dset$(file, dset, rank, dims, max_str_len); + return trexio_text_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len); break; case TREXIO_HDF5: - return trexio_hdf5_read_$group_dset$(file, dset, rank, dims, max_str_len); + return trexio_hdf5_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len); break; /* case TREXIO_JSON: - rc = trexio_json_read_$group_dset$(file, dset, rank, dims); + rc = trexio_json_read_$group_dset$(file, dset_out, rank, dims); break; */ } @@ -2448,12 +3305,13 @@ to/from theTREXIO
file (except fortrexio_has_
functi } trexio_exit_code -trexio_read_$group_dset$ (trexio_t* const file, char** dset, const uint32_t max_str_len) +trexio_read_$group_dset$ (trexio_t* const file, char** dset_out, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (dset == NULL) return TREXIO_INVALID_ARG_2; + if (dset_out == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; + if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING; assert(file->back_end < TREXIO_INVALID_BACK_END); @@ -2474,17 +3332,17 @@ to/from theTREXIO
file (except fortrexio_has_
functi return rc; } - char * pch; - for (uint64_t i=0; i < dset_dim; i++) { + for (uint64_t i=0; i < (uint64_t) dset_dim; i++) { + char * pch; pch = i == 0 ? strtok(str_compiled, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ; if (pch == NULL) { FREE(str_compiled); return TREXIO_FAILURE; } - strcpy(dset[i], ""); - strcat(dset[i], pch); + strcpy(dset_out[i], ""); + strcat(dset_out[i], pch); } @@ -2497,11 +3355,11 @@ to/from theTREXIO
file (except fortrexio_has_
functitrexio_exit_code -trexio_write_$group_dset$_low (trexio_t* const file, const char* dset, const uint32_t max_str_len) +trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (dset == NULL) return TREXIO_INVALID_ARG_2; + if (dset_in == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; @@ -2521,14 +3379,16 @@ to/from theTREXIO
file (except fortrexio_has_
functi char* tmp_str = CALLOC(dims[0]*(max_str_len+1), char); if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED; char** dset_str = CALLOC(dims[0], char*); - if (dset_str == NULL) return TREXIO_ALLOCATION_FAILED; + if (dset_str == NULL) { + FREE(tmp_str); + return TREXIO_ALLOCATION_FAILED; + } - char* pch; - size_t pch_len; /* parse the string using strtok */ for(uint64_t i=0; i<dims[0]; i++) { - pch = i == 0 ? strtok( (char*) dset, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ; + char* pch; + pch = i == 0 ? strtok( (char*) dset_in, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ; if (pch == NULL) { FREE(dset_str[0]); @@ -2536,9 +3396,9 @@ to/from theTREXIO
file (except fortrexio_has_
functi return TREXIO_FAILURE; } - pch_len = strlen(pch); + size_t pch_len = strlen(pch) + 1; - if (pch_len > max_str_len) { + if (pch_len > (size_t) max_str_len) { FREE(dset_str[0]); FREE(dset_str); return TREXIO_INVALID_STR_LEN; @@ -2574,11 +3434,11 @@ to/from theTREXIO
file (except fortrexio_has_
functi } trexio_exit_code -trexio_write_$group_dset$ (trexio_t* const file, const char** dset, const uint32_t max_str_len) +trexio_write_$group_dset$ (trexio_t* const file, const char** dset_in, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (dset == NULL) return TREXIO_INVALID_ARG_2; + if (dset_in == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; @@ -2596,8 +3456,8 @@ to/from theTREXIO
file (except fortrexio_has_
functi if (str_compiled == NULL) return TREXIO_ALLOCATION_FAILED; strcpy(str_compiled, ""); - for (uint64_t i=0; i < dset_dim; i++) { - strcat(str_compiled, dset[i]); + for (uint64_t i=0; i < (uint64_t) dset_dim; i++) { + strcat(str_compiled, dset_in[i]); strcat(str_compiled, TREXIO_DELIM); } @@ -2642,8 +3502,8 @@ to/from theTREXIO
file (except fortrexio_has_
functi
The Fortran
templates that provide an access to the C
API calls from Fortran
.
@@ -2738,14 +3598,130 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_dset$(trexio_file, dset_w: list) -> None: + """Write the $group_dset$ array of strings in the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + dset_w: list + Array of $group_dset$ strings to be written. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + max_str_length = len(max(dset_w, key=len)) + 1 + + try: + rc = pytr.trexio_write_$group_dset$(trexio_file.pytrexio_s, dset_w, max_str_length) + + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + +
def read_$group_dset$(trexio_file, dim = None) -> list: + """Read the $group_dset$ array of strings from the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + dim (Optional): int + Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned) + If None, the function will read all necessary array dimensions from the file. + + Returns: + ~dset_r~: list + 1D list with ~dim~ elements corresponding to $group_dset$ strings read from the TREXIO file. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + # if dim is not specified, read dimensions from the TREXIO file + if dim is None: + $group_dset_dim$ = read_$group_dset_dim$(trexio_file) + + dims_list = [$group_dset_dim_list$] + dim = 1 + for i in range($group_dset_rank$): + dim *= dims_list[i] + + + try: + rc, dset_1d_r = pytr.trexio_read_$group_dset$_low(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH) + + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + + + try: + dset_full = dset_1d_r.split(pytr.TREXIO_DELIM) + dset_2d_r = [dset_full[i] for i in range(dim) if dset_full[i]] + if not dset_2d_r: + raise ValueError(f"Output of {read_$group_dset$.__name__} function cannot be an empty list.") + except: + raise + + return dset_2d_r ++
def has_$group_dset$(trexio_file) -> bool: + """Check that $group_dset$ variable exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + except: + raise + + if rc == TREXIO_SUCCESS: + return True + else: + return False ++
This section concerns API calls related to string attributes. @@ -2785,28 +3761,27 @@ This section concerns API calls related to string attributes.
trexio_exit_code -trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len) +trexio_read_$group_str$ (trexio_t* const file, char* const str_out, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; - if (str == NULL) return TREXIO_INVALID_ARG_2; + if (str_out == NULL) return TREXIO_INVALID_ARG_2; if (max_str_len <= 0) return TREXIO_INVALID_ARG_3; - - trexio_exit_code rc = TREXIO_FAILURE; + if (trexio_has_$group_str$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; switch (file->back_end) { case TREXIO_TEXT: - return trexio_text_read_$group_str$(file, str, max_str_len); + return trexio_text_read_$group_str$(file, str_out, (uint32_t) max_str_len); break; case TREXIO_HDF5: - return trexio_hdf5_read_$group_str$(file, str, max_str_len); + return trexio_hdf5_read_$group_str$(file, str_out, (uint32_t) max_str_len); break; /* case TREXIO_JSON: @@ -2822,7 +3797,7 @@ This section concerns API calls related to string attributes.trexio_exit_code -trexio_write_$group_str$ (trexio_t* const file, const char* str, const uint32_t max_str_len) +trexio_write_$group_str$ (trexio_t* const file, const char* str, const int32_t max_str_len) { if (file == NULL) return TREXIO_INVALID_ARG_1; @@ -2831,7 +3806,7 @@ This section concerns API calls related to string attributes. if (trexio_has_$group_str$(file) == TREXIO_SUCCESS) return TREXIO_ATTR_ALREADY_EXISTS; size_t len_write = strlen(str); - if (max_str_len < len_write) return TREXIO_INVALID_STR_LEN; + if ((size_t) max_str_len < len_write) return TREXIO_INVALID_STR_LEN; switch (file->back_end) { @@ -2886,8 +3861,8 @@ This section concerns API calls related to string attributes.
The Fortran
templates that provide an access to the C
API calls from Fortran.
@@ -2963,11 +3938,100 @@ These templates are based on the use of iso_c_binding
. Pointers hav
def write_$group_str$(trexio_file, str_w: str) -> None: + """Write the $group_str$ variable in the TREXIO file. + + Parameters: + + trexio_file: + TREXIO File object. + + str_w: str + String corresponding to the $group_str$ variable to be written. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + max_str_length = len(str_w) + 1 + + try: + rc = pytr.trexio_write_$group_str$(trexio_file.pytrexio_s, str_w, max_str_length) + + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise ++
def read_$group_str$(trexio_file) -> str: + """Read the $group_str$ variable from the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + ~str_r~: str + String corresponding to the $group_str$ variable read from ~trexio_file~. + + Raises: + - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc, str_r = pytr.trexio_read_$group_str$(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH) + + if rc != TREXIO_SUCCESS: + raise Error(rc) + except: + raise + + return str_r ++
def has_$group_str$(trexio_file) -> bool: + """Check that $group_str$ variable exists in the TREXIO file. + + Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function. + + Returns: + True if the variable exists, False otherwise + + Raises: + - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error. + - Exception from some other error (e.g. RuntimeError). + """ + + try: + rc = pytr.trexio_has_$group_str$(trexio_file.pytrexio_s) + if rc == TREXIO_FAILURE: + raise Error(rc) + except: + raise + + if rc == TREXIO_SUCCESS: + return True + else: + return False ++
The function below adapts the original C-based trexio_open
for Fortran.
@@ -3101,7 +4165,7 @@ two code are identical, i.e. if the assert
statement pass.
#define $GROUP$_GROUP_NAME "$group$" @@ -343,15 +343,14 @@ for the JavaScript code in this tag.
typedef struct trexio_hdf5_s { trexio_t parent ; - hid_t file_id; - hid_t $group$_group; - const char* file_name; + hid_t file_id; + hid_t $group$_group; } trexio_hdf5_t;
trexio_exit_code
@@ -440,8 +439,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -557,8 +556,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -687,8 +686,8 @@ for the JavaScript code in this tag.
trexio_exit_code @@ -819,15 +818,22 @@ for the JavaScript code in this tag. /* we are going to write variable-length strings */ hid_t memtype = H5Tcopy (H5T_C_S1); + if (memtype <= 0) return TREXIO_INVALID_ID; + status = H5Tset_size (memtype, H5T_VARIABLE); + if (status < 0) return TREXIO_FAILURE; if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) { /* code to create dataset */ hid_t filetype = H5Tcopy (H5T_FORTRAN_S1); + if (filetype <= 0) return TREXIO_INVALID_ID; + status = H5Tset_size (filetype, H5T_VARIABLE); + if (status < 0) return TREXIO_FAILURE; hid_t dspace = H5Screate_simple( (int) rank, (const hsize_t*) dims, NULL); + if (dspace <= 0) return TREXIO_INVALID_ID; dset_id = H5Dcreate (f->$group$_group, $GROUP_DSET$_NAME, filetype, dspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); @@ -892,8 +898,8 @@ for the JavaScript code in this tag.
trexio_exit_code
@@ -1020,7 +1026,7 @@ for the JavaScript code in this tag.
The "file" produced by the text back end is a directory with one @@ -361,8 +361,8 @@ The file is written when closed, or when the flush function is called.
typedef struct $group$_s { @@ -380,8 +380,8 @@ The file is written when closed, or when the flush function is called.
typedef struct rdm_s { @@ -407,8 +407,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code
@@ -509,8 +509,8 @@ The file is written when closed, or when the flush function is called.
trexio_exit_code
@@ -535,8 +535,8 @@ The file is written when closed, or when the flush function is called.
$group$_t* @@ -743,8 +743,6 @@ trexio_text_read_$group$ (trexio_text_t*END REPEAT GROUP_DSET_NUM - size_t tmp_len; - // START REPEAT GROUP_DSET_STR /* Allocate arrays */ $group$->$group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$); @@ -772,7 +770,7 @@ trexio_text_read_$group$ (trexio_text_t**/ char* tmp_$group_dset$; if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char); - tmp_len = 0; + for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) { $group$->$group_dset$[i] = tmp_$group_dset$; /* conventional fcanf with "%s" only return the string before the first space character @@ -788,8 +786,8 @@ trexio_text_read_$group$ (trexio_text_t*return NULL; } - tmp_len = strlen($group$->$group_dset$[i]); - tmp_$group_dset$ += tmp_len + 1; + size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]); + tmp_$group_dset$ += tmp_$group_dset$_len + 1; } // END REPEAT GROUP_DSET_STR @@ -807,8 +805,8 @@ trexio_text_read_$group$ (trexio_text_t*
trexio_exit_code @@ -872,8 +870,8 @@ trexio_text_read_$group$ (trexio_text_t*
Memory is allocated when reading. The following function frees memory. @@ -918,8 +916,8 @@ Memory is allocated when reading. The following function frees memory.
trexio_exit_code
@@ -981,8 +979,8 @@ Memory is allocated when reading. The following function frees memory.
The group_dset
array is assumed allocated with the appropriate size.
@@ -1078,8 +1076,8 @@ The group_dset
array is assumed allocated with the appropriate size
The group_dset
array is assumed allocated with the appropriate size.
@@ -1144,9 +1142,8 @@ The group_dset
array is assumed allocated with the appropriate size
char* tmp_str = CALLOC(dims[0]*32 + 1, char);
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
- size_t tmp_len = 0;
for (uint64_t i=0 ; i<dims[0] ; ++i) {
- tmp_len = strlen(dset[i]);
+ size_t tmp_len = strlen(dset[i]);
$group$->$group_dset$[i] = tmp_str;
strncpy(tmp_str, dset[i], tmp_len);
tmp_str += tmp_len + 1;
@@ -1181,8 +1178,8 @@ The group_dset
array is assumed allocated with the appropriate size
trexio_exit_code
@@ -1256,12 +1253,12 @@ The group_dset
array is assumed allocated with the appropriate size
rdm_t* trexio_text_read_rdm(trexio_text_t* const file);
@@ -1356,8 +1353,8 @@ The group_dset
array is assumed allocated with the appropriate size
trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
@@ -1399,8 +1396,8 @@ The group_dset
array is assumed allocated with the appropriate size
Memory is allocated when reading. The followig function frees memory. @@ -1436,8 +1433,8 @@ Memory is allocated when reading. The followig function frees memory.
The one_e
array is assumed allocated with the appropriate size.
@@ -1503,8 +1500,8 @@ The one_e
array is assumed allocated with the appropriate size.
two_e
is a sparse data structure, which can be too large to fit
@@ -1612,7 +1609,7 @@ file for each sparse float structure.
index
type which is an
1-based int
in the Fortran interface and 0-based otherwise.
-As we expect our files to be archived in open-data repositories, we @@ -397,7 +397,7 @@ which have participated to the creation of the file, a list of authors of the file, and a textual description.
-