From 8a0ae10cca140bb17f2b6cbe1b61bc9baffd4b88 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 13 Mar 2024 17:28:41 +0100 Subject: [PATCH] Implemented helper functions for permutations --- src/templates_front/templator_front.org | 1124 +++++++++++++++++++++-- 1 file changed, 1060 insertions(+), 64 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index c21b253..9f61837 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -6698,7 +6698,7 @@ perms = {} for row in data: k = row[0] v = "["+row[1]+"]" - if k is not None: + if k is not '': id = k perms[id] = {"index": eval(v)} else: @@ -6714,8 +6714,10 @@ for k in perms: perms[k]["anti"] = "_anti" break + # Generate header code -h_code = [ """#+begin_src c :tangle prefix_front.h : exports none + +h_code = [ """#+begin_src c :tangle prefix_front.h #define TREXIO_POS (+1) #define TREXIO_NEG (-1) """ @@ -6725,12 +6727,45 @@ for k,v in perms.items(): m = v["m"] anti = v["anti"] name = "trexio_%d_index_%d_perm%s"%(n,m,anti) - h_code += [ "const int32_t* "+name+"();" ] + h_code += [ "trexio_exit_code is_"+name+"(trexio_t* const file, int32_t* const array, const int64_t size_max);" ] + h_code += [ "trexio_exit_code get_"+name+"(trexio_t* const file, int32_t* const array, const int64_t size_max);", "" ] h_code += [ " #+end_src" ] h_code = "\n".join(h_code) + +# Generate Fortran binding code + +f_code = [ """#+begin_src f90 :tangle helper_fortran.f90 :exports none +""" +] +for k,v in perms.items(): + n = v["n"] + m = v["m"] + anti = v["anti"] + name = "trexio_%d_index_%d_perm%s"%(n,m,anti) + f_code += [ " interface", + " integer(trexio_exit_code) function is_"+name+"(trex_file, array, size_max) bind(C)", + " use, intrinsic :: iso_c_binding", + " implicit none", + " integer(trexio_t) , intent(in), value :: trex_file", + " integer(c_int64_t), intent(in), value :: size_max", + " integer(c_int32_t), intent(in) :: array(size_max)", + " end function is_"+name, + " end interface", ""] + f_code += [ " interface", + " integer(trexio_exit_code) function get_"+name+"(trex_file, array, size_max) bind(C)", + " use, intrinsic :: iso_c_binding", + " implicit none", + " integer(trexio_t) , intent(in), value :: trex_file", + " integer(c_int64_t), intent(in), value :: size_max", + " integer(c_int32_t), intent(out) :: array(size_max)", + " end function get_"+name, + " end interface", ""] +f_code += [ " #+end_src" ] +f_code = "\n".join(f_code) + # Generate C code -c_code = [ "#+begin_src c :tangle prefix_front.c : exports none" +c_code = [ "#+begin_src c :tangle prefix_front.c :exports none" ] for k,v in perms.items(): n = int(v["n"]) @@ -6738,105 +6773,1066 @@ for k,v in perms.items(): anti = v["anti"] name = "trexio_%d_index_%d_perm%s"%(n,m,anti) c_code += [ """ -static int32_t NAME__[DIM] = { -}; -const int32_t* NAME() { return &(NAME__[0]) }; -""" +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < $DIM) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[$DIM] = { """ + .replace("$NAME",name) + .replace("$DIM",str((n+1)*m)) ] + for i in v["index"]: + tmp = [ str(k+1) for k in i ] + if i[-1] == 1: + tmp[-1] = "TREXIO_POS" + else: + tmp[-1] = "TREXIO_NEG" + tmp = " "+", ".join(tmp) + "," + c_code += [ tmp ] + tmp = tmp[:-1] + c_code[-1] = tmp + c_code += [ """ }; + memcpy(array, &f[0], $DIM*sizeof(int32_t)); + } else { + int32_t c[$DIM] = { """ + .replace("$NAME",name) + .replace("$DIM",str((n+1)*m)) ] + for i in v["index"]: + tmp = [ str(k) for k in i ] + if i[-1] == 1: + tmp[-1] = "TREXIO_POS" + else: + tmp[-1] = "TREXIO_NEG" + tmp = " "+", ".join(tmp) + "," + c_code += [ tmp ] + tmp = tmp[:-1] + c_code[-1] = tmp + c_code += [ """ }; + memcpy(array, &c[0], $DIM*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + """ + .replace("$NAME",name) + .replace("$DIM",str((n+1)*m)) ] + + c_code += [ """ +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < $DIM) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[$DIM] = { """ + .replace("$NAME",name) + .replace("$DIM",str((n+1)*m)) ] + for i in v["index"]: + tmp = [ str(k+1) for k in i ] + if i[-1] == 1: + tmp[-1] = "TREXIO_POS" + else: + tmp[-1] = "TREXIO_NEG" + tmp = " "+", ".join(tmp) + "," + c_code += [ tmp ] + tmp = tmp[:-1] + c_code[-1] = tmp + c_code += [ """ }; + if (memcmp(array, &f[0], $DIM*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[$DIM] = { """ + .replace("$NAME",name) + .replace("$DIM",str((n+1)*m)) ] + for i in v["index"]: + tmp = [ str(k) for k in i ] + if i[-1] == 1: + tmp[-1] = "TREXIO_POS" + else: + tmp[-1] = "TREXIO_NEG" + tmp = " "+", ".join(tmp) + "," + c_code += [ tmp ] + tmp = tmp[:-1] + c_code[-1] = tmp + c_code += [ """ }; + if (memcmp(array, &c[0], $DIM*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + """ .replace("NAME",name) - .replace("DIM",str((n+1)*m)) ] + .replace("$DIM",str((n+1)*m)) ] c_code += [ " #+end_src" ] c_code = "\n".join(c_code) -result = [ h_code, c_code ] + + + +result = [ h_code, c_code, f_code ] return "\n\n".join(result) #+end_src #+RESULTS: :results: -#+begin_src c :tangle prefix_front.h : exports none +#+begin_src c :tangle prefix_front.h #define TREXIO_POS (+1) #define TREXIO_NEG (-1) -const int32_t* trexio_2_index_1_perm(); -const int32_t* trexio_2_index_2_perm(); -const int32_t* trexio_2_index_2_perm_anti(); -const int32_t* trexio_3_index_1_perm(); -const int32_t* trexio_3_index_2_perm(); -const int32_t* trexio_3_index_2_perm_anti(); -const int32_t* trexio_3_index_3_perm(); -const int32_t* trexio_4_index_4_perm_anti(); -const int32_t* trexio_4_index_1_perm(); -const int32_t* trexio_4_index_4_perm(); -const int32_t* trexio_4_index_4_perm_anti(); -const int32_t* trexio_4_index_4_perm(); -const int32_t* trexio_4_index_4_perm_anti(); +trexio_exit_code is_trexio_2_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_2_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_2_index_2_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_2_index_2_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_2_index_2_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_2_index_2_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_3_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_3_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_3_index_2_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_3_index_2_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_3_index_2_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_3_index_2_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_3_index_6_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_3_index_6_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_4_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_4_index_1_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_4_index_4_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_4_index_4_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_4_index_4_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_4_index_4_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_4_index_8_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_4_index_8_perm(trexio_t* const file, int32_t* const array, const int64_t size_max); + +trexio_exit_code is_trexio_4_index_8_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); +trexio_exit_code get_trexio_4_index_8_perm_anti(trexio_t* const file, int32_t* const array, const int64_t size_max); + #+end_src -#+begin_src c :tangle prefix_front.c : exports none +#+begin_src c :tangle prefix_front.c :exports none -static int32_t trexio_2_index_1_perm__[3] = { -}; -const int32_t* trexio_2_index_1_perm() { return &(trexio_2_index_1_perm__[0]) }; +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + if (size_max < 3) return TREXIO_UNSAFE_ARRAY_DIM; -static int32_t trexio_2_index_2_perm__[6] = { -}; -const int32_t* trexio_2_index_2_perm() { return &(trexio_2_index_2_perm__[0]) }; + if (file->one_based) { + int32_t f[3] = { + 1, 2, TREXIO_POS + }; + memcpy(array, &f[0], 3*sizeof(int32_t)); + } else { + int32_t c[3] = { + 0, 1, TREXIO_POS + }; + memcpy(array, &c[0], 3*sizeof(int32_t)); + } + return TREXIO_SUCCESS; +} + -static int32_t trexio_2_index_2_perm_anti__[6] = { -}; -const int32_t* trexio_2_index_2_perm_anti() { return &(trexio_2_index_2_perm_anti__[0]) }; +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + if (size_max < 3) return TREXIO_UNSAFE_ARRAY_DIM; -static int32_t trexio_3_index_1_perm__[4] = { -}; -const int32_t* trexio_3_index_1_perm() { return &(trexio_3_index_1_perm__[0]) }; + if (file->one_based) { + int32_t f[3] = { + 1, 2, TREXIO_POS + }; + if (memcmp(array, &f[0], 3*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[3] = { + 0, 1, TREXIO_POS + }; + if (memcmp(array, &c[0], 3*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { -static int32_t trexio_3_index_2_perm__[8] = { -}; -const int32_t* trexio_3_index_2_perm() { return &(trexio_3_index_2_perm__[0]) }; + if (size_max < 6) return TREXIO_UNSAFE_ARRAY_DIM; + if (file->one_based) { + int32_t f[6] = { + 1, 2, TREXIO_POS, + 2, 1, TREXIO_POS + }; + memcpy(array, &f[0], 6*sizeof(int32_t)); + } else { + int32_t c[6] = { + 0, 1, TREXIO_POS, + 1, 0, TREXIO_POS + }; + memcpy(array, &c[0], 6*sizeof(int32_t)); + } -static int32_t trexio_3_index_2_perm_anti__[8] = { -}; -const int32_t* trexio_3_index_2_perm_anti() { return &(trexio_3_index_2_perm_anti__[0]) }; + return TREXIO_SUCCESS; +} + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { -static int32_t trexio_3_index_3_perm__[12] = { -}; -const int32_t* trexio_3_index_3_perm() { return &(trexio_3_index_3_perm__[0]) }; + if (size_max < 6) return TREXIO_UNSAFE_ARRAY_DIM; + if (file->one_based) { + int32_t f[6] = { + 1, 2, TREXIO_POS, + 2, 1, TREXIO_POS + }; + if (memcmp(array, &f[0], 6*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[6] = { + 0, 1, TREXIO_POS, + 1, 0, TREXIO_POS + }; + if (memcmp(array, &c[0], 6*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + -static int32_t trexio_4_index_4_perm_anti__[20] = { -}; -const int32_t* trexio_4_index_4_perm_anti() { return &(trexio_4_index_4_perm_anti__[0]) }; +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + if (size_max < 6) return TREXIO_UNSAFE_ARRAY_DIM; -static int32_t trexio_4_index_1_perm__[5] = { -}; -const int32_t* trexio_4_index_1_perm() { return &(trexio_4_index_1_perm__[0]) }; + if (file->one_based) { + int32_t f[6] = { + 1, 2, TREXIO_POS, + 2, 1, TREXIO_NEG + }; + memcpy(array, &f[0], 6*sizeof(int32_t)); + } else { + int32_t c[6] = { + 0, 1, TREXIO_POS, + 1, 0, TREXIO_NEG + }; + memcpy(array, &c[0], 6*sizeof(int32_t)); + } + return TREXIO_SUCCESS; +} + -static int32_t trexio_4_index_4_perm__[20] = { -}; -const int32_t* trexio_4_index_4_perm() { return &(trexio_4_index_4_perm__[0]) }; +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + if (size_max < 6) return TREXIO_UNSAFE_ARRAY_DIM; -static int32_t trexio_4_index_4_perm_anti__[20] = { -}; -const int32_t* trexio_4_index_4_perm_anti() { return &(trexio_4_index_4_perm_anti__[0]) }; + if (file->one_based) { + int32_t f[6] = { + 1, 2, TREXIO_POS, + 2, 1, TREXIO_NEG + }; + if (memcmp(array, &f[0], 6*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[6] = { + 0, 1, TREXIO_POS, + 1, 0, TREXIO_NEG + }; + if (memcmp(array, &c[0], 6*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { -static int32_t trexio_4_index_4_perm__[20] = { -}; -const int32_t* trexio_4_index_4_perm() { return &(trexio_4_index_4_perm__[0]) }; + if (size_max < 4) return TREXIO_UNSAFE_ARRAY_DIM; + if (file->one_based) { + int32_t f[4] = { + 1, 2, 3, TREXIO_POS + }; + memcpy(array, &f[0], 4*sizeof(int32_t)); + } else { + int32_t c[4] = { + 0, 1, 2, TREXIO_POS + }; + memcpy(array, &c[0], 4*sizeof(int32_t)); + } -static int32_t trexio_4_index_4_perm_anti__[20] = { -}; -const int32_t* trexio_4_index_4_perm_anti() { return &(trexio_4_index_4_perm_anti__[0]) }; + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 4) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[4] = { + 1, 2, 3, TREXIO_POS + }; + if (memcmp(array, &f[0], 4*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[4] = { + 0, 1, 2, TREXIO_POS + }; + if (memcmp(array, &c[0], 4*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 8) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[8] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_POS + }; + memcpy(array, &f[0], 8*sizeof(int32_t)); + } else { + int32_t c[8] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_POS + }; + memcpy(array, &c[0], 8*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 8) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[8] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_POS + }; + if (memcmp(array, &f[0], 8*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[8] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_POS + }; + if (memcmp(array, &c[0], 8*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 8) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[8] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_NEG + }; + memcpy(array, &f[0], 8*sizeof(int32_t)); + } else { + int32_t c[8] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_NEG + }; + memcpy(array, &c[0], 8*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 8) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[8] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_NEG + }; + if (memcmp(array, &f[0], 8*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[8] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_NEG + }; + if (memcmp(array, &c[0], 8*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 24) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[24] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_POS, + 1, 3, 2, TREXIO_POS, + 2, 3, 1, TREXIO_POS, + 3, 1, 2, TREXIO_POS, + 3, 2, 1, TREXIO_POS + }; + memcpy(array, &f[0], 24*sizeof(int32_t)); + } else { + int32_t c[24] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_POS, + 0, 2, 1, TREXIO_POS, + 1, 2, 0, TREXIO_POS, + 2, 0, 1, TREXIO_POS, + 2, 1, 0, TREXIO_POS + }; + memcpy(array, &c[0], 24*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 24) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[24] = { + 1, 2, 3, TREXIO_POS, + 2, 1, 3, TREXIO_POS, + 1, 3, 2, TREXIO_POS, + 2, 3, 1, TREXIO_POS, + 3, 1, 2, TREXIO_POS, + 3, 2, 1, TREXIO_POS + }; + if (memcmp(array, &f[0], 24*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[24] = { + 0, 1, 2, TREXIO_POS, + 1, 0, 2, TREXIO_POS, + 0, 2, 1, TREXIO_POS, + 1, 2, 0, TREXIO_POS, + 2, 0, 1, TREXIO_POS, + 2, 1, 0, TREXIO_POS + }; + if (memcmp(array, &c[0], 24*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 5) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[5] = { + 1, 2, 3, 4, TREXIO_POS + }; + memcpy(array, &f[0], 5*sizeof(int32_t)); + } else { + int32_t c[5] = { + 0, 1, 2, 3, TREXIO_POS + }; + memcpy(array, &c[0], 5*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 5) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[5] = { + 1, 2, 3, 4, TREXIO_POS + }; + if (memcmp(array, &f[0], 5*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[5] = { + 0, 1, 2, 3, TREXIO_POS + }; + if (memcmp(array, &c[0], 5*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 20) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[20] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_POS, + 1, 4, 3, 2, TREXIO_POS, + 3, 4, 1, 2, TREXIO_POS + }; + memcpy(array, &f[0], 20*sizeof(int32_t)); + } else { + int32_t c[20] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_POS, + 0, 3, 2, 1, TREXIO_POS, + 2, 3, 0, 1, TREXIO_POS + }; + memcpy(array, &c[0], 20*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 20) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[20] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_POS, + 1, 4, 3, 2, TREXIO_POS, + 3, 4, 1, 2, TREXIO_POS + }; + if (memcmp(array, &f[0], 20*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[20] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_POS, + 0, 3, 2, 1, TREXIO_POS, + 2, 3, 0, 1, TREXIO_POS + }; + if (memcmp(array, &c[0], 20*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 20) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[20] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_NEG, + 1, 4, 3, 2, TREXIO_NEG, + 3, 4, 1, 2, TREXIO_POS + }; + memcpy(array, &f[0], 20*sizeof(int32_t)); + } else { + int32_t c[20] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_NEG, + 0, 3, 2, 1, TREXIO_NEG, + 2, 3, 0, 1, TREXIO_POS + }; + memcpy(array, &c[0], 20*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 20) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[20] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_NEG, + 1, 4, 3, 2, TREXIO_NEG, + 3, 4, 1, 2, TREXIO_POS + }; + if (memcmp(array, &f[0], 20*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[20] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_NEG, + 0, 3, 2, 1, TREXIO_NEG, + 2, 3, 0, 1, TREXIO_POS + }; + if (memcmp(array, &c[0], 20*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 40) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[40] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_POS, + 1, 4, 3, 2, TREXIO_POS, + 3, 4, 1, 2, TREXIO_POS, + 2, 1, 4, 3, TREXIO_POS, + 2, 3, 4, 1, TREXIO_POS, + 4, 1, 2, 3, TREXIO_POS, + 4, 3, 2, 1, TREXIO_POS + }; + memcpy(array, &f[0], 40*sizeof(int32_t)); + } else { + int32_t c[40] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_POS, + 0, 3, 2, 1, TREXIO_POS, + 2, 3, 0, 1, TREXIO_POS, + 1, 0, 3, 2, TREXIO_POS, + 1, 2, 3, 0, TREXIO_POS, + 3, 0, 1, 2, TREXIO_POS, + 3, 2, 1, 0, TREXIO_POS + }; + memcpy(array, &c[0], 40*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 40) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[40] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_POS, + 1, 4, 3, 2, TREXIO_POS, + 3, 4, 1, 2, TREXIO_POS, + 2, 1, 4, 3, TREXIO_POS, + 2, 3, 4, 1, TREXIO_POS, + 4, 1, 2, 3, TREXIO_POS, + 4, 3, 2, 1, TREXIO_POS + }; + if (memcmp(array, &f[0], 40*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[40] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_POS, + 0, 3, 2, 1, TREXIO_POS, + 2, 3, 0, 1, TREXIO_POS, + 1, 0, 3, 2, TREXIO_POS, + 1, 2, 3, 0, TREXIO_POS, + 3, 0, 1, 2, TREXIO_POS, + 3, 2, 1, 0, TREXIO_POS + }; + if (memcmp(array, &c[0], 40*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + +trexio_exit_code get_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 40) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[40] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_NEG, + 1, 4, 3, 2, TREXIO_NEG, + 3, 4, 1, 2, TREXIO_POS, + 2, 1, 4, 3, TREXIO_POS, + 2, 3, 4, 1, TREXIO_NEG, + 4, 1, 2, 3, TREXIO_NEG, + 4, 3, 2, 1, TREXIO_POS + }; + memcpy(array, &f[0], 40*sizeof(int32_t)); + } else { + int32_t c[40] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_NEG, + 0, 3, 2, 1, TREXIO_NEG, + 2, 3, 0, 1, TREXIO_POS, + 1, 0, 3, 2, TREXIO_POS, + 1, 2, 3, 0, TREXIO_NEG, + 3, 0, 1, 2, TREXIO_NEG, + 3, 2, 1, 0, TREXIO_POS + }; + memcpy(array, &c[0], 40*sizeof(int32_t)); + } + + return TREXIO_SUCCESS; +} + + +trexio_exit_code is_NAME(trexio_t* const file, int32_t* const array, const int64_t size_max) { + + if (size_max < 40) return TREXIO_UNSAFE_ARRAY_DIM; + + if (file->one_based) { + int32_t f[40] = { + 1, 2, 3, 4, TREXIO_POS, + 3, 2, 1, 4, TREXIO_NEG, + 1, 4, 3, 2, TREXIO_NEG, + 3, 4, 1, 2, TREXIO_POS, + 2, 1, 4, 3, TREXIO_POS, + 2, 3, 4, 1, TREXIO_NEG, + 4, 1, 2, 3, TREXIO_NEG, + 4, 3, 2, 1, TREXIO_POS + }; + if (memcmp(array, &f[0], 40*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } else { + int32_t c[40] = { + 0, 1, 2, 3, TREXIO_POS, + 2, 1, 0, 3, TREXIO_NEG, + 0, 3, 2, 1, TREXIO_NEG, + 2, 3, 0, 1, TREXIO_POS, + 1, 0, 3, 2, TREXIO_POS, + 1, 2, 3, 0, TREXIO_NEG, + 3, 0, 1, 2, TREXIO_NEG, + 3, 2, 1, 0, TREXIO_POS + }; + if (memcmp(array, &c[0], 40*sizeof(int32_t)) == 0) { + return TREXIO_SUCCESS; + else + return TREXIO_HAS_NOT; + } + } +} + + #+end_src + +#+begin_src f90 :tangle helper_fortran.f90 :exports none + + interface + integer(trexio_exit_code) function is_trexio_2_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_2_index_1_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_2_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_2_index_1_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_2_index_2_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_2_index_2_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_2_index_2_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_2_index_2_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_2_index_2_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_2_index_2_perm_anti + end interface + + interface + integer(trexio_exit_code) function get_trexio_2_index_2_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_2_index_2_perm_anti + end interface + + interface + integer(trexio_exit_code) function is_trexio_3_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_3_index_1_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_3_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_3_index_1_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_3_index_2_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_3_index_2_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_3_index_2_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_3_index_2_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_3_index_2_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_3_index_2_perm_anti + end interface + + interface + integer(trexio_exit_code) function get_trexio_3_index_2_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_3_index_2_perm_anti + end interface + + interface + integer(trexio_exit_code) function is_trexio_3_index_6_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_3_index_6_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_3_index_6_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_3_index_6_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_4_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_4_index_1_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_4_index_1_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_4_index_1_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_4_index_4_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_4_index_4_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_4_index_4_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_4_index_4_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_4_index_4_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_4_index_4_perm_anti + end interface + + interface + integer(trexio_exit_code) function get_trexio_4_index_4_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_4_index_4_perm_anti + end interface + + interface + integer(trexio_exit_code) function is_trexio_4_index_8_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_4_index_8_perm + end interface + + interface + integer(trexio_exit_code) function get_trexio_4_index_8_perm(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_4_index_8_perm + end interface + + interface + integer(trexio_exit_code) function is_trexio_4_index_8_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(in) :: array(size_max) + end function is_trexio_4_index_8_perm_anti + end interface + + interface + integer(trexio_exit_code) function get_trexio_4_index_8_perm_anti(trex_file, array, size_max) bind(C) + use, intrinsic :: iso_c_binding + implicit none + integer(trexio_t) , intent(in), value :: trex_file + integer(c_int64_t), intent(in), value :: size_max + integer(c_int32_t), intent(out) :: array(size_max) + end function get_trexio_4_index_8_perm_anti + end interface #+end_src :end: