|
| 1 | +#include <iostream> |
| 2 | +#include <ISO_Fortran_binding.h> |
| 3 | + |
| 4 | +#include "bounds.h" |
| 5 | + |
| 6 | +// ==================== 1D Version ==================== |
| 7 | +bool c_bounder(CFI_cdesc_t* a, |
| 8 | + CFI_index_t fortran_lower, |
| 9 | + CFI_index_t fortran_upper) |
| 10 | +{ |
| 11 | + std::cout << "=== C++: c_bounder (1D) called ===\n"; |
| 12 | + |
| 13 | + if (a == nullptr) { |
| 14 | + std::cerr << "ERROR: nullptr descriptor\n"; |
| 15 | + return false; |
| 16 | + } |
| 17 | + |
| 18 | + if (a->rank != 1) { |
| 19 | + std::cerr << "ERROR: Expected rank 1, got " << a->rank << "\n"; |
| 20 | + return false; |
| 21 | + } |
| 22 | + |
| 23 | + const CFI_dim_t& dim = a->dim[0]; |
| 24 | + const CFI_index_t c_lower = dim.lower_bound; |
| 25 | + const CFI_index_t extent = dim.extent; |
| 26 | + const CFI_index_t c_upper = c_lower + extent - 1; |
| 27 | + |
| 28 | + std::cout << "C Descriptor: lower=" << c_lower << ", upper=" << c_upper << ", extent=" << extent << "\n"; |
| 29 | + std::cout << "Fortran Array: lower=" << fortran_lower << ", upper=" << fortran_upper << "\n"; |
| 30 | + |
| 31 | + if (c_lower != 0) { |
| 32 | + std::cerr << "WARNING: C lower bound is not 0 (got " << c_lower << ")\n"; |
| 33 | + } |
| 34 | + |
| 35 | + if (extent != (fortran_upper - fortran_lower + 1)) { |
| 36 | + std::cerr << "ERROR: Extent mismatch! Expected " << (fortran_upper - fortran_lower + 1) << ", got " << extent << "\n"; |
| 37 | + return false; |
| 38 | + } |
| 39 | + |
| 40 | + std::cout << "✓ Extent check PASSED\n"; |
| 41 | + |
| 42 | + return true; |
| 43 | +} |
| 44 | + |
| 45 | +// ==================== 2D Version ==================== |
| 46 | +bool c_bounder_2d(CFI_cdesc_t* a, |
| 47 | + CFI_index_t fl1, CFI_index_t fu1, |
| 48 | + CFI_index_t fl2, CFI_index_t fu2) |
| 49 | +{ |
| 50 | + std::cout << "=== C++: c_bounder_2d called ===\n"; |
| 51 | + |
| 52 | + if (a == nullptr || a->rank != 2) { |
| 53 | + std::cerr << "ERROR: Expected rank 2\n"; |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + // Check dimensions |
| 58 | + const CFI_index_t extent1 = a->dim[0].extent; |
| 59 | + const CFI_index_t extent2 = a->dim[1].extent; |
| 60 | + |
| 61 | + if (extent1 != (fu1 - fl1 + 1)) { |
| 62 | + std::cerr << "ERROR: Dim1 extent mismatch\n"; |
| 63 | + return false; |
| 64 | + } |
| 65 | + |
| 66 | + if (extent2 != (fu2 - fl2 + 1)) { |
| 67 | + std::cerr << "ERROR: Dim2 extent mismatch\n"; |
| 68 | + return false; |
| 69 | + } |
| 70 | + |
| 71 | + std::cout << "✓ 2D Extent check PASSED: [" << fl1 << ":" << fu1 << ", " << fl2 << ":" << fu2 << "]\n"; |
| 72 | + |
| 73 | + return true; |
| 74 | +} |
0 commit comments