| 
 | 1 | +!###################################################################################################  | 
 | 2 | +! This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file)  #  | 
 | 3 | +! Copyright (C) 2025 University of Illinois Urbana-Champaign                                       #  | 
 | 4 | +! Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors                              #  | 
 | 5 | +!###################################################################################################  | 
 | 6 | + | 
 | 7 | +module PyPartMC_aero_binned  | 
 | 8 | +  use iso_c_binding  | 
 | 9 | +  use pmc_aero_binned  | 
 | 10 | +  implicit none  | 
 | 11 | + | 
 | 12 | +  contains  | 
 | 13 | + | 
 | 14 | +  subroutine f_aero_binned_ctor(ptr_c) bind(C)  | 
 | 15 | +    type(aero_binned_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_aero_binned_dtor(ptr_c) bind(C)  | 
 | 23 | +    type(aero_binned_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_aero_binned_num_conc(ptr_c, num_conc, n_bins) bind(C)  | 
 | 31 | +    type(aero_binned_t), pointer :: ptr_f => null()  | 
 | 32 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 33 | +    integer(c_int), intent(in) :: n_bins  | 
 | 34 | +    real(c_double), intent(inout) :: num_conc(n_bins)  | 
 | 35 | + | 
 | 36 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 37 | + | 
 | 38 | +    num_conc = ptr_f%num_conc  | 
 | 39 | + | 
 | 40 | +  end subroutine  | 
 | 41 | + | 
 | 42 | +  subroutine f_aero_binned_species_vol_conc(ptr_c, vol_conc, n_bins, i_spec) bind(C)  | 
 | 43 | +    type(aero_binned_t), pointer :: ptr_f => null()  | 
 | 44 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 45 | +    integer(c_int), intent(in) :: n_bins, i_spec  | 
 | 46 | +    real(c_double), intent(inout) :: vol_conc(n_bins)  | 
 | 47 | + | 
 | 48 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 49 | + | 
 | 50 | +    vol_conc = ptr_f%vol_conc(:,i_spec+1)  | 
 | 51 | + | 
 | 52 | +  end subroutine  | 
 | 53 | + | 
 | 54 | +  subroutine f_aero_binned_len(ptr_c, len) bind(C)  | 
 | 55 | +    type(aero_binned_t), pointer :: ptr_f => null()  | 
 | 56 | +    type(c_ptr), intent(in) :: ptr_c  | 
 | 57 | +    integer(c_int), intent(out) :: len  | 
 | 58 | + | 
 | 59 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 60 | + | 
 | 61 | +    len = size(ptr_f%num_conc)  | 
 | 62 | + | 
 | 63 | +  end subroutine  | 
 | 64 | + | 
 | 65 | +  subroutine f_aero_binned_add_aero_dist(ptr_c, bin_grid_ptr_c, aero_data_ptr_c, &  | 
 | 66 | +       aero_dist_ptr_c) bind(C)  | 
 | 67 | +    type(c_ptr), intent(in) :: ptr_c, bin_grid_ptr_c, aero_data_ptr_c, &  | 
 | 68 | +        aero_dist_ptr_c  | 
 | 69 | +    type(aero_binned_t), pointer :: ptr_f => null()  | 
 | 70 | +    type(aero_data_t), pointer :: aero_data_ptr_f => null()  | 
 | 71 | +    type(aero_dist_t), pointer :: aero_dist_ptr_f => null()  | 
 | 72 | +    type(bin_grid_t), pointer :: bin_grid_ptr_f => null()  | 
 | 73 | + | 
 | 74 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 75 | +    call c_f_pointer(bin_grid_ptr_c, bin_grid_ptr_f)  | 
 | 76 | +    call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)  | 
 | 77 | +    call c_f_pointer(aero_dist_ptr_c, aero_dist_ptr_f)  | 
 | 78 | + | 
 | 79 | +    call aero_binned_add_aero_dist(ptr_f, bin_grid_ptr_f, &  | 
 | 80 | +         aero_data_ptr_f, aero_dist_ptr_f)  | 
 | 81 | + | 
 | 82 | +  end subroutine  | 
 | 83 | + | 
 | 84 | +  subroutine f_aero_binned_set_sizes(ptr_c, aero_data_ptr_c, bin_grid_ptr_c) bind(C)  | 
 | 85 | +    type(c_ptr), intent(in) :: ptr_c, bin_grid_ptr_c, aero_data_ptr_c  | 
 | 86 | +    type(aero_binned_t), pointer :: ptr_f => null()  | 
 | 87 | +    type(aero_data_t), pointer :: aero_data_ptr_f => null()  | 
 | 88 | +    type(bin_grid_t), pointer :: bin_grid_ptr_f => null()  | 
 | 89 | + | 
 | 90 | +    call c_f_pointer(ptr_c, ptr_f)  | 
 | 91 | +    call c_f_pointer(bin_grid_ptr_c, bin_grid_ptr_f)  | 
 | 92 | +    call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)  | 
 | 93 | + | 
 | 94 | +    call aero_binned_set_sizes(ptr_f, bin_grid_size(bin_grid_ptr_f), &  | 
 | 95 | +         aero_data_n_spec(aero_data_ptr_f))  | 
 | 96 | + | 
 | 97 | +  end subroutine  | 
 | 98 | + | 
 | 99 | +end module  | 
0 commit comments