From ce480af7752bc2eba8099a34efc66bb4b0f7a6d9 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 19 Mar 2021 18:26:29 +0100 Subject: [PATCH] Added Fortran interface for qmckl_string_of_error --- src/qmckl_error.org | 81 +++++++++++---------------------------------- 1 file changed, 19 insertions(+), 62 deletions(-) diff --git a/src/qmckl_error.org b/src/qmckl_error.org index 08284d5..87451e3 100644 --- a/src/qmckl_error.org +++ b/src/qmckl_error.org @@ -32,7 +32,7 @@ MunitResult test_<>() { perform any input/output operations. This decision has to be taken by the developer of the code calling the library. - All the functions return with an <<>>, defined as + All the functions return with an exit code, defined as #+NAME: type-exit-code #+begin_src c :comments org :tangle (eval h) typedef int32_t qmckl_exit_code; @@ -140,10 +140,11 @@ return '\n'.join(result) string is assumed to be large enough to contain the error message (typically 128 characters). - #+begin_src c :comments org :tangle (eval h) :exports none -#define QMCKL_ERROR_MAX_STRING_LENGTH 128 + #+NAME: MAX_STRING_LENGTH + : 128 -void qmckl_string_of_error(qmckl_exit_code error, char string[QMCKL_ERROR_MAX_STRING_LENGTH]); + #+begin_src c :comments org :tangle (eval h) :exports none :noweb yes +void qmckl_string_of_error(qmckl_exit_code error, char string[<>]); #+end_src The text strings are extracted from the previous table. @@ -165,72 +166,28 @@ return '\n'.join(result) #+end_src - #+RESULTS: cases - #+begin_example - case QMCKL_SUCCESS: - message = "Success"; - break; - case QMCKL_INVALID_ARG_1: - message = "Invalid argument 1"; - break; - case QMCKL_INVALID_ARG_2: - message = "Invalid argument 2"; - break; - case QMCKL_INVALID_ARG_3: - message = "Invalid argument 3"; - break; - case QMCKL_INVALID_ARG_4: - message = "Invalid argument 4"; - break; - case QMCKL_INVALID_ARG_5: - message = "Invalid argument 5"; - break; - case QMCKL_INVALID_ARG_6: - message = "Invalid argument 6"; - break; - case QMCKL_INVALID_ARG_7: - message = "Invalid argument 7"; - break; - case QMCKL_INVALID_ARG_8: - message = "Invalid argument 8"; - break; - case QMCKL_INVALID_ARG_9: - message = "Invalid argument 9"; - break; - case QMCKL_INVALID_ARG_10: - message = "Invalid argument 10"; - break; - case QMCKL_FAILURE: - message = "Failure"; - break; - case QMCKL_ERRNO: - message = strerror(errno); - break; - case QMCKL_INVALID_CONTEXT: - message = "Invalid context"; - break; - case QMCKL_ALLOCATION_FAILED: - message = "Allocation failed"; - break; - case QMCKL_DEALLOCATION_FAILED: - message = "De-allocation failed"; - break; - case QMCKL_INVALID_EXIT_CODE: - message = "Invalid exit code"; - break; - #+end_example - - + # Source #+begin_src c :comments org :tangle (eval c) :noweb yes -void qmckl_string_of_error(qmckl_exit_code error, char string[QMCKL_ERROR_MAX_STRING_LENGTH]) { +void qmckl_string_of_error(qmckl_exit_code error, char string[<>]) { char* message; switch (error) { <> } - strncpy(string,message,QMCKL_ERROR_MAX_STRING_LENGTH); + strncpy(string,message,<>); } #+end_src + # Fortran interface + #+begin_src f90 :tangle (eval fh) :noexport :noweb yes + interface + type (c_ptr) function qmckl_string_of_error (error, string) bind(C) + use, intrinsic :: iso_c_binding + integer (c_int32_t), intent(in), value :: error + character*(<>), intent(out) :: string + end function qmckl_string_of_error + end interface + #+end_src + * End of files :noexport: ** Test