1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-23 04:43:57 +01:00

Error messages

This commit is contained in:
Anthony Scemama 2021-05-06 18:25:51 +02:00
commit 1cfa313d07
6 changed files with 60 additions and 42 deletions

View File

@ -40,7 +40,7 @@ AC_PROG_CC_C99
# Checks for basic libraries.
AC_CHECK_LIB([m], [sqrt])
# Checks for basic header files.
AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h unistd.h])
AC_CHECK_HEADERS([fcntl.h inttypes.h stdint.h stdlib.h string.h unistd.h])
# Search for pthread
have_pthreads=no
@ -154,8 +154,8 @@ AC_CHECK_FUNCS([memset mkdir strerror])
AC_CONFIG_FILES([Makefile
src/Makefile
trexio.pc
tests/Makefile])
tests/Makefile
trexio.pc])
AC_OUTPUT
echo \

View File

@ -114,30 +114,31 @@ typedef int32_t trexio_exit_code;
** Error handling
#+NAME: table-exit-codes
| Macro | Code | Description |
|----------------------------+------+------------------------|
| ~TREXIO_FAILURE~ | -1 | 'Unknown failure' |
| ~TREXIO_SUCCESS~ | 0 | 'Success' |
| ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' |
| ~TREXIO_INVALID_ARG_2~ | 2 | 'Invalid argument 2' |
| ~TREXIO_INVALID_ARG_3~ | 3 | 'Invalid argument 3' |
| ~TREXIO_INVALID_ARG_4~ | 4 | 'Invalid argument 4' |
| ~TREXIO_INVALID_ARG_5~ | 5 | 'Invalid argument 5' |
| ~TREXIO_END~ | 6 | 'End of file' |
| ~TREXIO_READONLY~ | 7 | 'Read-only file' |
| ~TREXIO_ERRNO~ | 8 | strerror(errno) |
| ~TREXIO_INVALID_ID~ | 9 | 'Invalid ID' |
| ~TREXIO_ALLOCATION_FAILED~ | 10 | 'Allocation failed' |
| ~TREXIO_HAS_NOT~ | 11 | 'Element absent' |
| ~TREXIO_INVALID_NUM~ | 12 | 'Invalid exit code' |
| ~TREXIO_OPEN_ERROR~ | 13 | 'Error opening file' |
| ~TREXIO_LOCK_ERROR~ | 14 | 'Error locking file' |
| ~TREXIO_UNLOCK_ERROR~ | 15 | 'Error unlocking file' |
| ~TREXIO_FILE_ERROR~ | 16 | 'Invalid file handle' |
| ~TREXIO_GROUP_READ_ERROR~ | 17 | 'Error reading group' |
| ~TREXIO_GROUP_WRITE_ERROR~ | 18 | 'Error writing group' |
| ~TREXIO_ELEM_READ_ERROR~ | 19 | 'Error reading element |
| ~TREXIO_ELEM_WRITE_ERROR~ | 20 | 'Error writing element |
| Macro | Code | Description |
|-----------------------------+------+--------------------------------|
| ~TREXIO_FAILURE~ | -1 | 'Unknown failure' |
| ~TREXIO_SUCCESS~ | 0 | 'Success' |
| ~TREXIO_INVALID_ARG_1~ | 1 | 'Invalid argument 1' |
| ~TREXIO_INVALID_ARG_2~ | 2 | 'Invalid argument 2' |
| ~TREXIO_INVALID_ARG_3~ | 3 | 'Invalid argument 3' |
| ~TREXIO_INVALID_ARG_4~ | 4 | 'Invalid argument 4' |
| ~TREXIO_INVALID_ARG_5~ | 5 | 'Invalid argument 5' |
| ~TREXIO_END~ | 6 | 'End of file' |
| ~TREXIO_READONLY~ | 7 | 'Read-only file' |
| ~TREXIO_ERRNO~ | 8 | strerror(errno) |
| ~TREXIO_INVALID_ID~ | 9 | 'Invalid ID' |
| ~TREXIO_ALLOCATION_FAILED~ | 10 | 'Allocation failed' |
| ~TREXIO_HAS_NOT~ | 11 | 'Element absent' |
| ~TREXIO_INVALID_NUM~ | 12 | 'Invalid exit code' |
| ~TREXIO_NUM_ALREADY_EXISTS~ | 13 | 'This variable already exists' |
| ~TREXIO_OPEN_ERROR~ | 14 | 'Error opening file' |
| ~TREXIO_LOCK_ERROR~ | 15 | 'Error locking file' |
| ~TREXIO_UNLOCK_ERROR~ | 16 | 'Error unlocking file' |
| ~TREXIO_FILE_ERROR~ | 17 | 'Invalid file handle' |
| ~TREXIO_GROUP_READ_ERROR~ | 18 | 'Error reading group' |
| ~TREXIO_GROUP_WRITE_ERROR~ | 19 | 'Error writing group' |
| ~TREXIO_ELEM_READ_ERROR~ | 20 | 'Error reading element' |
| ~TREXIO_ELEM_WRITE_ERROR~ | 21 | 'Error writing element' |
# We need to force Emacs not to indent the Python code:
# -*- org-src-preserve-indentation: t
@ -183,6 +184,15 @@ return '\n'.join(result)
#define TREXIO_ALLOCATION_FAILED ((trexio_exit_code) 10)
#define TREXIO_HAS_NOT ((trexio_exit_code) 11)
#define TREXIO_INVALID_NUM ((trexio_exit_code) 12)
#define TREXIO_NUM_ALREADY_EXISTS ((trexio_exit_code) 13)
#define TREXIO_OPEN_ERROR ((trexio_exit_code) 14)
#define TREXIO_LOCK_ERROR ((trexio_exit_code) 15)
#define TREXIO_UNLOCK_ERROR ((trexio_exit_code) 16)
#define TREXIO_FILE_ERROR ((trexio_exit_code) 17)
#define TREXIO_GROUP_READ_ERROR ((trexio_exit_code) 18)
#define TREXIO_GROUP_WRITE_ERROR ((trexio_exit_code) 19)
#define TREXIO_ELEM_READ_ERROR ((trexio_exit_code) 20)
#define TREXIO_ELEM_WRITE_ERROR ((trexio_exit_code) 21)
#+end_src
#+begin_src f90 :tangle prefix_fortran.f90 :exports none
@ -200,6 +210,15 @@ return '\n'.join(result)
integer(trexio_exit_code), parameter :: TREXIO_ALLOCATION_FAILED = 10
integer(trexio_exit_code), parameter :: TREXIO_HAS_NOT = 11
integer(trexio_exit_code), parameter :: TREXIO_INVALID_NUM = 12
integer(trexio_exit_code), parameter :: TREXIO_NUM_ALREADY_EXISTS = 13
integer(trexio_exit_code), parameter :: TREXIO_OPEN_ERROR = 14
integer(trexio_exit_code), parameter :: TREXIO_LOCK_ERROR = 15
integer(trexio_exit_code), parameter :: TREXIO_UNLOCK_ERROR = 16
integer(trexio_exit_code), parameter :: TREXIO_FILE_ERROR = 17
integer(trexio_exit_code), parameter :: TREXIO_GROUP_READ_ERROR = 18
integer(trexio_exit_code), parameter :: TREXIO_GROUP_WRITE_ERROR = 19
integer(trexio_exit_code), parameter :: TREXIO_ELEM_READ_ERROR = 20
integer(trexio_exit_code), parameter :: TREXIO_ELEM_WRITE_ERROR = 21
#+end_src
:end:

View File

@ -235,9 +235,8 @@ trexio_hdf5_write_$group_num$ (trexio_t* const file, const uint64_t num)
if (infile_num != num) {
if (infile_num != 0) {
printf("%lu -> %lu %s \n", num, infile_num,
"This variable already exists. Overwriting it is not supported");
return TREXIO_FAILURE;
return TREXIO_NUM_ALREADY_EXISTS;
} else {

View File

@ -38,7 +38,7 @@
#include "trexio_private.h"
#include "trexio_s.h"
#include <errno.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -347,7 +347,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
return NULL;
}
rc = fscanf(f, "%lu\n", &($group$->dims_$group_dset$[i]));
rc = fscanf(f, "%" SCNu64 "\n", &($group$->dims_$group_dset$[i]));
assert(!(rc != 1));
if (rc != 1) {
FREE(buffer);
@ -373,7 +373,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
return NULL;
}
rc = fscanf(f, "%lu", &($group$->$group_num$));
rc = fscanf(f, "%" SCNu64 "", &($group$->$group_num$));
assert(!(rc != 1));
if (rc != 1) {
FREE(buffer);
@ -479,14 +479,14 @@ trexio_text_flush_$group$ (trexio_text_t* const file)
if ($group$->rank_$group_dset$ != 0) size_$group_dset$ = 1;
for (unsigned int i=0; i<$group$->rank_$group_dset$; ++i){
fprintf(f, "dims_$group_dset$ %u %lu\n", i, $group$->dims_$group_dset$[i]);
fprintf(f, "dims_$group_dset$ %u %" PRIu64 "\n", i, $group$->dims_$group_dset$[i]);
size_$group_dset$ *= $group$->dims_$group_dset$[i];
}
// END REPEAT GROUP_DSET
// START REPEAT GROUP_NUM
fprintf(f, "$group_num$ %lu\n", $group$->$group_num$);
fprintf(f, "$group_num$ %" PRIu64 "\n", $group$->$group_num$);
// END REPEAT GROUP_NUM
/* Write arrays */
@ -758,7 +758,7 @@ rdm_t* trexio_text_read_rdm(trexio_text_t* const file) {
assert (rc == 1);
assert (strcmp(buffer, "dim_one_e") == 0);
rc = fscanf(f, "%lu", &(rdm->dim_one_e));
rc = fscanf(f, "%" SCNu64 "", &(rdm->dim_one_e));
assert (rc == 1);
/* Allocate arrays */
@ -831,7 +831,7 @@ trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file) {
fseek(f, 0L, SEEK_SET);
/* Write the dimensioning variables */
fprintf(f, "num %lu\n", rdm->dim_one_e);
fprintf(f, "num %" PRIu64 "\n", rdm->dim_one_e);
/* Write arrays */
fprintf(f, "one_e\n");
@ -993,7 +993,7 @@ trexio_text_buffered_read_rdm_two_e(trexio_t* const file,
fseek(f, (long) offset * line_length, SEEK_SET);
for (uint64_t i=0 ; i<size ; ++i) {
int rc = fscanf(f, "%9ld %9ld %9ld %9ld %24le\n",
int rc = fscanf(f, "%9" SCNd64 " %9" SCNd64 " %9" SCNd64 " %9" SCNd64 " %24le\n",
&index[4*i],
&index[4*i+1],
&index[4*i+2],
@ -1032,7 +1032,7 @@ trexio_text_buffered_write_rdm_two_e(trexio_t* const file,
fseek(f, (long) offset * line_length, SEEK_SET);
for (uint64_t i=0 ; i<size ; ++i) {
int rc = fprintf(f, "%9ld %9ld %9ld %9ld %24le\n",
int rc = fprintf(f, "%9" PRId64 " %9" PRId64 " %9" PRId64 " %9" PRId64 " %24le\n",
index[4*i],
index[4*i+1],
index[4*i+2],

View File

@ -77,7 +77,7 @@ int test_h5write() {
// should not work: try to overwrite the nucleus_num
rc = trexio_write_nucleus_num(file,25);
assert (rc != TREXIO_SUCCESS);
assert (rc == TREXIO_NUM_ALREADY_EXISTS);
// close current session
rc = trexio_close(file);

View File

@ -151,8 +151,8 @@ for fname in files_funcs_groups:
std_dtype_out = '24.16e'
std_dtype_in = 'lf'
elif params['dtype'] == 'int64_t':
std_dtype_out = 'ld'
std_dtype_in = 'ld'
std_dtype_out = '" PRId64 "'
std_dtype_in = '" SCNd64 "'
templine1 = templine2.replace('$group_dset_std_dtype_out$', std_dtype_out)
templine2 = templine1.replace('$group_dset_std_dtype_in$', std_dtype_in)