forked from open-atmos/PyPartMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaero_mode.F90
283 lines (200 loc) · 8.34 KB
/
aero_mode.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
!###################################################################################################
! This file is a part of PyPartMC licensed under the GNU General Public License v3 (LICENSE file) #
! Copyright (C) 2022 University of Illinois Urbana-Champaign #
! Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
!###################################################################################################
module PyPartMC_aero_mode
use iso_c_binding
use pmc_aero_mode
implicit none
contains
subroutine f_aero_mode_ctor(ptr_c) bind(C)
type(aero_mode_t), pointer :: ptr_f => null()
type(c_ptr), intent(out) :: ptr_c
allocate(ptr_f)
ptr_c = c_loc(ptr_f)
end subroutine
subroutine f_aero_mode_dtor(ptr_c) bind(C)
type(aero_mode_t), pointer :: ptr_f => null()
type(c_ptr), intent(in) :: ptr_c
call c_f_pointer(ptr_c, ptr_f)
deallocate(ptr_f)
end subroutine
subroutine f_aero_mode_set_num_conc(ptr_c, val) bind(C)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double), intent(in) :: val
call c_f_pointer(ptr_c, aero_mode)
aero_mode%num_conc = val
end subroutine
subroutine f_aero_mode_get_num_conc(ptr_c, val) bind(C)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double), intent(out) :: val
call c_f_pointer(ptr_c, aero_mode)
val = aero_mode_total_num_conc(aero_mode)
end subroutine
subroutine f_aero_mode_num_conc(ptr_c, bin_grid_ptr_c, &
aero_data_ptr_c, arr_data, arr_size) bind(C)
type(c_ptr), intent(in) :: ptr_c, bin_grid_ptr_c, &
aero_data_ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
type(bin_grid_t), pointer :: bin_grid => null()
type(aero_data_t), pointer :: aero_data => null()
integer(c_int), intent(in) :: arr_size
real(c_double), dimension(arr_size), intent(out) :: arr_data
call c_f_pointer(ptr_c, aero_mode)
call c_f_pointer(bin_grid_ptr_c, bin_grid)
call c_f_pointer(aero_data_ptr_c, aero_data)
call aero_mode_num_conc(aero_mode, bin_grid, aero_data, &
arr_data)
end subroutine
subroutine f_aero_mode_get_n_spec(ptr_c, len) bind(C)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: len
call c_f_pointer(ptr_c, aero_mode)
len = size(aero_mode%vol_frac)
end subroutine
subroutine f_aero_mode_get_vol_frac(ptr_c, arr_data, arr_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: arr_size
real(c_double) :: arr_data(arr_size)
call c_f_pointer(ptr_c, aero_mode)
arr_data = aero_mode%vol_frac
end subroutine
subroutine f_aero_mode_set_vol_frac(ptr_c, arr_data, arr_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: arr_size
real(c_double) :: arr_data(arr_size)
call c_f_pointer(ptr_c, aero_mode)
aero_mode%vol_frac = arr_data
end subroutine
subroutine f_aero_mode_get_vol_frac_std(ptr_c, arr_data, arr_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: arr_size
real(c_double) :: arr_data(arr_size)
call c_f_pointer(ptr_c, aero_mode)
arr_data = aero_mode%vol_frac_std
end subroutine
subroutine f_aero_mode_set_vol_frac_std(ptr_c, arr_data, arr_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: arr_size
real(c_double) :: arr_data(arr_size)
call c_f_pointer(ptr_c, aero_mode)
aero_mode%vol_frac_std = arr_data
end subroutine
subroutine f_aero_mode_get_char_radius(ptr_c, char_radius) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double) :: char_radius
call c_f_pointer(ptr_c, aero_mode)
char_radius = aero_mode%char_radius
end subroutine
subroutine f_aero_mode_set_char_radius(ptr_c, char_radius) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double) :: char_radius
call c_f_pointer(ptr_c, aero_mode)
aero_mode%char_radius = char_radius
end subroutine
subroutine f_aero_mode_get_gsd(ptr_c, gsd) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double) :: gsd
call c_f_pointer(ptr_c, aero_mode)
gsd = 10**(aero_mode%log10_std_dev_radius)
end subroutine
subroutine f_aero_mode_set_gsd(ptr_c, gsd) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
real(c_double) :: gsd
call c_f_pointer(ptr_c, aero_mode)
aero_mode%log10_std_dev_radius = log10(gsd)
end subroutine
subroutine f_aero_mode_from_json(ptr_c, aero_data_ptr_c) bind(C)
type(aero_mode_t), pointer :: ptr_f => null()
type(aero_data_t), pointer :: aero_data_ptr_f => null()
type(c_ptr), intent(inout) :: ptr_c, aero_data_ptr_c
type(spec_file_t) :: file
logical :: eof
call c_f_pointer(ptr_c, ptr_f)
call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f)
call spec_file_read_aero_mode(file, aero_data_ptr_f, .false., ptr_f, eof)
end subroutine
subroutine f_aero_mode_set_sampled(ptr_c, diam_data, num_conc_data, &
arr_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int) :: arr_size
real(c_double) :: diam_data(arr_size), num_conc_data(arr_size-1)
call c_f_pointer(ptr_c, aero_mode)
aero_mode%type = AERO_MODE_TYPE_SAMPLED
aero_mode%sample_radius = diam_data / 2
aero_mode%sample_num_conc = num_conc_data
end subroutine
subroutine f_aero_mode_set_type(ptr_c, type) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int), intent(in) :: type
call c_f_pointer(ptr_c, aero_mode)
aero_mode%type = type
end subroutine
subroutine f_aero_mode_get_type(ptr_c, type) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int), intent(out) :: type
call c_f_pointer(ptr_c, aero_mode)
type = aero_mode%type
end subroutine
subroutine f_aero_mode_set_name(ptr_c, name_data, name_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
character(kind=c_char), dimension(*), intent(in) :: name_data
integer(c_int), intent(in) :: name_size
integer :: i
call c_f_pointer(ptr_c, aero_mode)
do i=1, name_size
aero_mode%name(i:i) = name_data(i)
end do
do i=name_size+1, len(aero_mode%name)
aero_mode%name(i:i) = " "
end do
end subroutine
subroutine f_aero_mode_get_name(ptr_c, name_data, name_size) bind(C)
type(c_ptr), intent(inout) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
type(c_ptr), intent(out) :: name_data
integer(c_int), intent(out) :: name_size
call c_f_pointer(ptr_c, aero_mode)
name_data = c_loc(aero_mode%name)
name_size = len_trim(aero_mode%name)
end subroutine
subroutine f_aero_mode_get_sample_num_conc(ptr_c, arr_data, data_size) bind(C)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int), intent(in) :: data_size
real(c_double), dimension(data_size), intent(inout) :: arr_data
call c_f_pointer(ptr_c, aero_mode)
arr_data = aero_mode%sample_num_conc
end subroutine
subroutine f_aero_mode_get_sample_radius(ptr_c, arr_data, data_size) bind(C)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int), intent(in) :: data_size
real(c_double), dimension(data_size), intent(inout) :: arr_data
call c_f_pointer(ptr_c, aero_mode)
arr_data = aero_mode%sample_radius
end subroutine
subroutine f_aero_mode_get_sample_bins(ptr_c, n_bins) bind(c)
type(c_ptr), intent(in) :: ptr_c
type(aero_mode_t), pointer :: aero_mode => null()
integer(c_int), intent(out) :: n_bins
call c_f_pointer(ptr_c, aero_mode)
n_bins = size(aero_mode%sample_num_conc)
end subroutine
end module