| 
 | 1 | +!###################################################################################################  | 
 | 2 | +! This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file)  #  | 
 | 3 | +! Copyright (C) 2022 University of Illinois Urbana-Champaign                                       #  | 
 | 4 | +! Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors                              #  | 
 | 5 | +!###################################################################################################  | 
 | 6 | + | 
 | 7 | +module PyPartMC_bin_grid  | 
 | 8 | +  use iso_c_binding  | 
 | 9 | +  use pmc_bin_grid  | 
 | 10 | +  implicit none  | 
 | 11 | + | 
 | 12 | +  contains  | 
 | 13 | + | 
 | 14 | +  subroutine f_bin_grid_ctor(ptr_c) bind(C)  | 
 | 15 | +    type(bin_grid_t), pointer :: ptr_f => null()  | 
 | 16 | +    type(c_ptr), intent(out) :: ptr_c  | 
 | 17 | + | 
 | 18 | +    allocate(ptr_f)  | 
 | 19 | +    ptr_c = c_loc(ptr_f)  | 
 | 20 | +  end subroutine  | 
 | 21 | + | 
 | 22 | +  subroutine f_bin_grid_dtor(ptr_c) bind(C)  | 
 | 23 | +    type(bin_grid_t), pointer :: ptr_f => null()  | 
 | 24 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 25 | + | 
 | 26 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 27 | +    deallocate(ptr_f)  | 
 | 28 | +  end subroutine  | 
 | 29 | + | 
 | 30 | +  subroutine f_bin_grid_init(ptr_c, n_bin, bin_grid_type, min, max) bind(C)  | 
 | 31 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 32 | +    type(bin_grid_t), pointer :: bin_grid => null()  | 
 | 33 | +    integer(c_int), intent(in) :: n_bin  | 
 | 34 | +    integer(c_int), intent(in) :: bin_grid_type  | 
 | 35 | +    real(c_double), intent(in) :: min  | 
 | 36 | +    real(c_double), intent(in) :: max  | 
 | 37 | +    | 
 | 38 | +    call c_f_pointer(ptr_c, bin_grid)   | 
 | 39 | +    call bin_grid_make(bin_grid, bin_grid_type, n_bin, min, max)  | 
 | 40 | +   | 
 | 41 | +  end subroutine  | 
 | 42 | + | 
 | 43 | +  subroutine f_bin_grid_size(ptr_c, val) bind(C)  | 
 | 44 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 45 | +    type(bin_grid_t), pointer :: bin_grid => null()  | 
 | 46 | +    integer(c_int), intent(out) :: val  | 
 | 47 | + | 
 | 48 | +    call c_f_pointer(ptr_c, bin_grid)  | 
 | 49 | +    val = bin_grid_size(bin_grid)  | 
 | 50 | + | 
 | 51 | +  end subroutine  | 
 | 52 | + | 
 | 53 | +  subroutine f_bin_grid_edges(ptr_c, arr_data, arr_size) bind(C)  | 
 | 54 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 55 | +    type(bin_grid_t), pointer :: bin_grid => null()  | 
 | 56 | +    integer(c_int), intent(in) :: arr_size  | 
 | 57 | +    real(c_double), dimension(arr_size), intent(out) :: arr_data  | 
 | 58 | + | 
 | 59 | +    call c_f_pointer(ptr_c, bin_grid)  | 
 | 60 | +    arr_data = bin_grid%edges  | 
 | 61 | +  end subroutine  | 
 | 62 | + | 
 | 63 | +  subroutine f_bin_grid_centers(ptr_c, arr_data, arr_size) bind(C)  | 
 | 64 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 65 | +    type(bin_grid_t), pointer :: bin_grid => null()  | 
 | 66 | +    integer(c_int), intent(in) :: arr_size  | 
 | 67 | +    real(c_double), dimension(arr_size), intent(out) :: arr_data  | 
 | 68 | + | 
 | 69 | +    call c_f_pointer(ptr_c, bin_grid)  | 
 | 70 | +    arr_data = bin_grid%centers  | 
 | 71 | +  end subroutine  | 
 | 72 | + | 
 | 73 | +end module  | 
0 commit comments