1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-07-03 01:46:12 +02:00

Added Fortran interface for qmckl_string_of_error

This commit is contained in:
Anthony Scemama 2021-03-19 18:26:29 +01:00
parent 5c81cf1dee
commit ce480af775

View File

@ -32,7 +32,7 @@ MunitResult test_<<filename()>>() {
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 <<<exit code>>>, 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[<<MAX_STRING_LENGTH()>>]);
#+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[<<MAX_STRING_LENGTH()>>]) {
char* message;
switch (error) {
<<cases()>>
}
strncpy(string,message,QMCKL_ERROR_MAX_STRING_LENGTH);
strncpy(string,message,<<MAX_STRING_LENGTH()>>);
}
#+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*(<<MAX_STRING_LENTH>>), intent(out) :: string
end function qmckl_string_of_error
end interface
#+end_src
* End of files :noexport:
** Test