From 14226862f33dbc1e3829b762df35e9ee3f556906 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 4 Jul 2017 14:44:21 -0500 Subject: [PATCH] Have openmc_tally_results accept ID instead of array index --- docs/source/capi/index.rst | 6 +++--- src/api.F90 | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/source/capi/index.rst b/docs/source/capi/index.rst index ae072448d..c932bcde9 100644 --- a/docs/source/capi/index.rst +++ b/docs/source/capi/index.rst @@ -124,12 +124,12 @@ C API :return: Return status (negative if an error occurs) :rtype: int -.. c:function:: void openmc_tally_results(int i, double** ptr, int shape_[3]) +.. c:function:: void openmc_tally_results(int id, double** ptr, int shape_[3]) Get a pointer to tally results array. - :param i: Index in the tallies array - :type i: int + :param id: ID of the tally + :type id: int :param ptr: Pointer to the results array :type ptr: double** :param shape_: Shape of the results array diff --git a/src/api.F90 b/src/api.F90 index c0ee84594..72879f41f 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -376,14 +376,17 @@ contains ! directly. !=============================================================================== - subroutine openmc_tally_results(i, ptr, shape_) bind(C) - integer(C_INT), intent(in), value :: i + subroutine openmc_tally_results(id, ptr, shape_) bind(C) + integer(C_INT), intent(in), value :: id type(C_PTR), intent(out) :: ptr integer(C_INT), intent(out) :: shape_(3) + integer :: i + ptr = C_NULL_PTR if (allocated(tallies)) then - if (i >= 1 .and. i <= size(tallies)) then + if (tally_dict % has_key(id)) then + i = tally_dict % get_key(id) if (allocated(tallies(i) % results)) then ptr = C_LOC(tallies(i) % results(1,1,1)) shape_(:) = shape(tallies(i) % results)