|
| 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_aero_mode |
| 8 | + use iso_c_binding |
| 9 | + use pmc_aero_mode |
| 10 | + implicit none |
| 11 | + |
| 12 | + contains |
| 13 | + |
| 14 | + subroutine f_aero_mode_ctor(ptr_c) bind(C) |
| 15 | + type(aero_mode_t), pointer :: ptr_f => null() |
| 16 | + type(c_ptr), intent(out) :: ptr_c |
| 17 | + |
| 18 | + allocate(ptr_f) |
| 19 | + |
| 20 | + ptr_c = c_loc(ptr_f) |
| 21 | + end subroutine |
| 22 | + |
| 23 | + subroutine f_aero_mode_dtor(ptr_c) bind(C) |
| 24 | + type(aero_mode_t), pointer :: ptr_f => null() |
| 25 | + type(c_ptr), intent(in) :: ptr_c |
| 26 | + |
| 27 | + call c_f_pointer(ptr_c, ptr_f) |
| 28 | + |
| 29 | + deallocate(ptr_f) |
| 30 | + end subroutine |
| 31 | + |
| 32 | + subroutine f_aero_mode_init(ptr_c, aero_data_ptr_c) bind(C) |
| 33 | + type(c_ptr), intent(inout) :: ptr_c |
| 34 | + type(c_ptr), intent(in) :: aero_data_ptr_c |
| 35 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 36 | + type(aero_data_t), pointer :: aero_data => null() |
| 37 | + |
| 38 | + call c_f_pointer(ptr_c, aero_mode) |
| 39 | + call c_f_pointer(aero_data_ptr_c, aero_data) |
| 40 | + end subroutine |
| 41 | + |
| 42 | + subroutine f_aero_mode_set_num_conc(ptr_c, val) bind(C) |
| 43 | + type(c_ptr), intent(in) :: ptr_c |
| 44 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 45 | + real(c_double), intent(in) :: val |
| 46 | + |
| 47 | + call c_f_pointer(ptr_c, aero_mode) |
| 48 | + aero_mode%num_conc = val |
| 49 | + |
| 50 | + end subroutine |
| 51 | + |
| 52 | + subroutine f_aero_mode_get_num_conc(ptr_c, val) bind(C) |
| 53 | + type(c_ptr), intent(in) :: ptr_c |
| 54 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 55 | + real(c_double), intent(out) :: val |
| 56 | + |
| 57 | + call c_f_pointer(ptr_c, aero_mode) |
| 58 | + val = aero_mode_total_num_conc(aero_mode) |
| 59 | + |
| 60 | + end subroutine |
| 61 | + |
| 62 | + subroutine f_aero_mode_num_conc(ptr_c, bin_grid_ptr_c, & |
| 63 | + aero_data_ptr_c, arr_data, arr_size) bind(C) |
| 64 | + |
| 65 | + type(c_ptr), intent(in) :: ptr_c, bin_grid_ptr_c, & |
| 66 | + aero_data_ptr_c |
| 67 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 68 | + type(bin_grid_t), pointer :: bin_grid => null() |
| 69 | + type(aero_data_t), pointer :: aero_data => null() |
| 70 | + integer(c_int), intent(in) :: arr_size |
| 71 | + real(c_double), dimension(arr_size), intent(out) :: arr_data |
| 72 | + |
| 73 | + call c_f_pointer(ptr_c, aero_mode) |
| 74 | + call c_f_pointer(bin_grid_ptr_c, bin_grid) |
| 75 | + call c_f_pointer(aero_data_ptr_c, aero_data) |
| 76 | + |
| 77 | + call aero_mode_num_conc(aero_mode, bin_grid, aero_data, & |
| 78 | + arr_data) |
| 79 | + |
| 80 | + end subroutine |
| 81 | + |
| 82 | + subroutine f_aero_mode_get_n_spec(ptr_c, len) bind(C) |
| 83 | + type(c_ptr), intent(in) :: ptr_c |
| 84 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 85 | + integer(c_int) :: len |
| 86 | + |
| 87 | + call c_f_pointer(ptr_c, aero_mode) |
| 88 | + |
| 89 | + len = size(aero_mode%vol_frac) |
| 90 | + |
| 91 | + end subroutine |
| 92 | + |
| 93 | + subroutine f_aero_mode_get_vol_frac(ptr_c, arr_data, arr_size) bind(C) |
| 94 | + type(c_ptr), intent(inout) :: ptr_c |
| 95 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 96 | + integer(c_int) :: arr_size |
| 97 | + real(c_double) :: arr_data(arr_size) |
| 98 | + |
| 99 | + call c_f_pointer(ptr_c, aero_mode) |
| 100 | + |
| 101 | + arr_data = aero_mode%vol_frac |
| 102 | + |
| 103 | + end subroutine |
| 104 | + |
| 105 | + subroutine f_aero_mode_set_vol_frac(ptr_c, arr_data, arr_size) bind(C) |
| 106 | + type(c_ptr), intent(inout) :: ptr_c |
| 107 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 108 | + integer(c_int) :: arr_size |
| 109 | + real(c_double) :: arr_data(arr_size) |
| 110 | + |
| 111 | + call c_f_pointer(ptr_c, aero_mode) |
| 112 | + aero_mode%vol_frac = arr_data |
| 113 | + |
| 114 | + end subroutine |
| 115 | + |
| 116 | + subroutine f_aero_mode_get_vol_frac_std(ptr_c, arr_data, arr_size) bind(C) |
| 117 | + type(c_ptr), intent(inout) :: ptr_c |
| 118 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 119 | + integer(c_int) :: arr_size |
| 120 | + real(c_double) :: arr_data(arr_size) |
| 121 | + |
| 122 | + call c_f_pointer(ptr_c, aero_mode) |
| 123 | + |
| 124 | + arr_data = aero_mode%vol_frac_std |
| 125 | + |
| 126 | + end subroutine |
| 127 | + |
| 128 | + subroutine f_aero_mode_set_vol_frac_std(ptr_c, arr_data, arr_size) bind(C) |
| 129 | + type(c_ptr), intent(inout) :: ptr_c |
| 130 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 131 | + integer(c_int) :: arr_size |
| 132 | + real(c_double) :: arr_data(arr_size) |
| 133 | + |
| 134 | + call c_f_pointer(ptr_c, aero_mode) |
| 135 | + aero_mode%vol_frac_std = arr_data |
| 136 | + |
| 137 | + end subroutine |
| 138 | + |
| 139 | + |
| 140 | + subroutine f_aero_mode_get_char_radius(ptr_c, char_radius) bind(C) |
| 141 | + type(c_ptr), intent(inout) :: ptr_c |
| 142 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 143 | + real(c_double) :: char_radius |
| 144 | + |
| 145 | + call c_f_pointer(ptr_c, aero_mode) |
| 146 | + |
| 147 | + char_radius = aero_mode%char_radius |
| 148 | + |
| 149 | + end subroutine |
| 150 | + |
| 151 | + subroutine f_aero_mode_set_char_radius(ptr_c, char_radius) bind(C) |
| 152 | + type(c_ptr), intent(inout) :: ptr_c |
| 153 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 154 | + real(c_double) :: char_radius |
| 155 | + |
| 156 | + call c_f_pointer(ptr_c, aero_mode) |
| 157 | + aero_mode%char_radius = char_radius |
| 158 | + |
| 159 | + end subroutine |
| 160 | + |
| 161 | + subroutine f_aero_mode_get_gsd(ptr_c, gsd) bind(C) |
| 162 | + type(c_ptr), intent(inout) :: ptr_c |
| 163 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 164 | + real(c_double) :: gsd |
| 165 | + |
| 166 | + call c_f_pointer(ptr_c, aero_mode) |
| 167 | + |
| 168 | + gsd = 10**(aero_mode%log10_std_dev_radius) |
| 169 | + |
| 170 | + end subroutine |
| 171 | + |
| 172 | + subroutine f_aero_mode_set_gsd(ptr_c, gsd) bind(C) |
| 173 | + type(c_ptr), intent(inout) :: ptr_c |
| 174 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 175 | + real(c_double) :: gsd |
| 176 | + |
| 177 | + call c_f_pointer(ptr_c, aero_mode) |
| 178 | + aero_mode%log10_std_dev_radius = log10(gsd) |
| 179 | + |
| 180 | + end subroutine |
| 181 | + |
| 182 | + subroutine f_aero_mode_from_json(ptr_c, aero_data_ptr_c) bind(C) |
| 183 | + type(aero_mode_t), pointer :: ptr_f => null() |
| 184 | + type(aero_data_t), pointer :: aero_data_ptr_f => null() |
| 185 | + type(c_ptr), intent(inout) :: ptr_c, aero_data_ptr_c |
| 186 | + type(spec_file_t) :: file |
| 187 | + logical :: eof |
| 188 | + |
| 189 | + call c_f_pointer(ptr_c, ptr_f) |
| 190 | + call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f) |
| 191 | + |
| 192 | + call spec_file_read_aero_mode(file, aero_data_ptr_f, ptr_f, eof) |
| 193 | + |
| 194 | + end subroutine |
| 195 | + |
| 196 | + subroutine f_aero_mode_set_sampled(ptr_c, diam_data, num_conc_data, & |
| 197 | + arr_size) bind(C) |
| 198 | + type(c_ptr), intent(inout) :: ptr_c |
| 199 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 200 | + integer(c_int) :: arr_size |
| 201 | + real(c_double) :: diam_data(arr_size), num_conc_data(arr_size-1) |
| 202 | + |
| 203 | + call c_f_pointer(ptr_c, aero_mode) |
| 204 | + |
| 205 | + aero_mode%type = AERO_MODE_TYPE_SAMPLED |
| 206 | + aero_mode%sample_radius = diam_data / 2 |
| 207 | + aero_mode%sample_num_conc = num_conc_data |
| 208 | + |
| 209 | + end subroutine |
| 210 | + |
| 211 | + subroutine f_aero_mode_set_type(ptr_c, type) bind(C) |
| 212 | + type(c_ptr), intent(inout) :: ptr_c |
| 213 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 214 | + integer(c_int), intent(in) :: type |
| 215 | + |
| 216 | + call c_f_pointer(ptr_c, aero_mode) |
| 217 | + aero_mode%type = type |
| 218 | + |
| 219 | + end subroutine |
| 220 | + |
| 221 | + subroutine f_aero_mode_get_type(ptr_c, type) bind(C) |
| 222 | + type(c_ptr), intent(inout) :: ptr_c |
| 223 | + type(aero_mode_t), pointer :: aero_mode => null() |
| 224 | + integer(c_int), intent(out) :: type |
| 225 | + |
| 226 | + call c_f_pointer(ptr_c, aero_mode) |
| 227 | + type = aero_mode%type |
| 228 | + |
| 229 | + end subroutine |
| 230 | + |
| 231 | +end module |
0 commit comments