Skip to content

Commit 1509097

Browse files
committed
add get entire mixing ratio array
1 parent 4fea974 commit 1509097

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/gas_state.F90

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ subroutine f_gas_state_get_item(ptr_c, idx, val) bind(C)
5757
val = ptr_f%mix_rat(idx+1)
5858
end subroutine
5959

60-
subroutine f_gas_state_from_json(ptr_c) bind(C)
60+
subroutine f_gas_state_from_json(ptr_c, gas_data_ptr_c) bind(C)
6161
type(gas_state_t), pointer :: ptr_f => null()
6262
type(c_ptr), intent(in) :: ptr_c
63+
type(c_ptr), intent(in) :: gas_data_ptr_c
6364

64-
type(gas_data_t), pointer :: gas_data => null()
65+
type(gas_data_t), pointer :: gas_data_ptr_f => null()
6566
integer :: ncid
6667

6768
call c_f_pointer(ptr_c, ptr_f)
68-
call gas_state_input_netcdf(ptr_f, ncid, gas_data)
69+
call c_f_pointer(gas_data_ptr_c, gas_data_ptr_f)
70+
call gas_state_input_netcdf(ptr_f, ncid, gas_data_ptr_f)
6971
end subroutine
7072

7173
subroutine f_gas_state_to_json(ptr_c) bind(C)

src/gas_state.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ extern "C" void f_gas_state_len(const void *ptr, int *len) noexcept;
2020
extern "C" void f_gas_state_to_json(const void *ptr) noexcept;
2121
extern "C" void f_gas_state_from_json(const void *ptr) noexcept;
2222
extern "C" void f_gas_state_set_size(const void *ptr, const void *gasdata_ptr) noexcept;
23+
extern "C" void f_gas_state_mix_rats(const void *ptr, const double *data, const int *len);
2324

2425
struct GasState {
2526
PMCResource ptr;
2627

27-
GasState(const nlohmann::json &json) :
28+
GasState(const GasData &gas_data,
29+
const nlohmann::json &json) :
2830
ptr(f_gas_state_ctor, f_gas_state_dtor)
2931
{
3032
gimmick_ptr() = std::make_unique<InputGimmick>(json);
3133

3234
const int n = json.empty() ? 0 : gimmick_ptr()->find("gas_mixing_ratio")->size();
35+
f_gas_state_set_size(this->ptr.f_arg(), &gas_data.ptr);
3336
//f_gas_state_set_size(this->ptr.f_arg(), &n);
3437
if (n != 0) f_gas_state_from_json(this->ptr.f_arg());
3538

@@ -85,7 +88,10 @@ struct GasState {
8588
f_gas_state_len(&self.ptr, &len);
8689
std::valarray<double> data(len);
8790

88-
91+
for (int idx = 0; idx < len; idx++) {
92+
f_gas_state_get_item(&self.ptr, &idx, &data[idx]);
93+
}
94+
//f_gas_state_mix_rats(&self.ptr, &data, &len);
8995
return data;
9096
}
9197
};

0 commit comments

Comments
 (0)