|
| 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_output |
| 8 | + |
| 9 | +use iso_c_binding |
| 10 | +use pmc_output |
| 11 | +use pmc_util |
| 12 | + |
| 13 | +implicit none |
| 14 | + |
| 15 | +contains |
| 16 | + |
| 17 | + subroutine f_output_state(prefix_data, prefix_size, aero_data_ptr_c, & |
| 18 | + aero_state_ptr_c, gas_data_ptr_c, gas_state_ptr_c, env_state_ptr_c, & |
| 19 | + index, time, del_t, i_repeat, record_removals, record_optical) bind(C) |
| 20 | + |
| 21 | + character(kind=c_char), dimension(*), intent(in) :: prefix_data |
| 22 | + integer(c_int), intent(in) :: prefix_size |
| 23 | + type(aero_state_t), pointer :: aero_state_ptr_f => null() |
| 24 | + type(aero_data_t), pointer :: aero_data_ptr_f => null() |
| 25 | + type(env_state_t), pointer :: env_state_ptr_f => null() |
| 26 | + type(gas_state_t), pointer :: gas_state_ptr_f => null() |
| 27 | + type(gas_data_t), pointer :: gas_data_ptr_f => null() |
| 28 | + |
| 29 | + type(c_ptr) :: aero_data_ptr_c, aero_state_ptr_c, gas_data_ptr_c, & |
| 30 | + gas_state_ptr_c, env_state_ptr_c |
| 31 | + integer(c_int), intent(in) :: index, i_repeat |
| 32 | + real(c_double), intent(in) :: time, del_t |
| 33 | + logical(c_bool), intent(in) :: record_removals, record_optical |
| 34 | + |
| 35 | + character(len=PMC_UUID_LEN) :: uuid |
| 36 | + integer :: output_type |
| 37 | + character(len=prefix_size) :: prefix |
| 38 | + integer :: i |
| 39 | + |
| 40 | + do i=1, prefix_size |
| 41 | + prefix(i:i) = prefix_data(i) |
| 42 | + end do |
| 43 | + |
| 44 | + output_type = OUTPUT_TYPE_SINGLE |
| 45 | + call uuid4_str(uuid) |
| 46 | + |
| 47 | + call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f) |
| 48 | + call c_f_pointer(aero_state_ptr_c, aero_state_ptr_f) |
| 49 | + call c_f_pointer(gas_data_ptr_c, gas_data_ptr_f) |
| 50 | + call c_f_pointer(gas_state_ptr_c, gas_state_ptr_f) |
| 51 | + call c_f_pointer(env_state_ptr_c, env_state_ptr_f) |
| 52 | + |
| 53 | + call output_state(prefix, output_type, aero_data_ptr_f, aero_state_ptr_f, & |
| 54 | + gas_data_ptr_f, gas_state_ptr_f, env_state_ptr_f, index, time, del_t, & |
| 55 | + i_repeat, logical(record_removals), logical(record_optical), uuid) |
| 56 | + |
| 57 | + end subroutine |
| 58 | + |
| 59 | + subroutine f_input_state(filename_data, filename_size, index, time, del_t, & |
| 60 | + i_repeat, aero_data_ptr_c, aero_state_ptr_c, gas_data_ptr_c, & |
| 61 | + gas_state_ptr_c, env_state_ptr_c) bind(C) |
| 62 | + |
| 63 | + type(aero_state_t), pointer :: aero_state_ptr_f => null() |
| 64 | + type(aero_data_t), pointer :: aero_data_ptr_f => null() |
| 65 | + type(env_state_t), pointer :: env_state_ptr_f => null() |
| 66 | + type(gas_state_t), pointer :: gas_state_ptr_f => null() |
| 67 | + type(gas_data_t), pointer :: gas_data_ptr_f => null() |
| 68 | + character(kind=c_char), dimension(*), intent(in) :: filename_data |
| 69 | + integer(c_int), intent(in) :: filename_size |
| 70 | + type(c_ptr) :: aero_data_ptr_c, aero_state_ptr_c, gas_data_ptr_c, & |
| 71 | + gas_state_ptr_c, env_state_ptr_c |
| 72 | + integer(c_int), intent(out) :: index, i_repeat |
| 73 | + real(c_double), intent(out) :: time, del_t |
| 74 | + character(len=PMC_UUID_LEN) :: uuid |
| 75 | + |
| 76 | + character(len=filename_size) :: filename |
| 77 | + integer :: i |
| 78 | + |
| 79 | + do i=1, filename_size |
| 80 | + filename(i:i) = filename_data(i) |
| 81 | + end do |
| 82 | + |
| 83 | + call c_f_pointer(aero_data_ptr_c, aero_data_ptr_f) |
| 84 | + call c_f_pointer(aero_state_ptr_c, aero_state_ptr_f) |
| 85 | + call c_f_pointer(gas_data_ptr_c, gas_data_ptr_f) |
| 86 | + call c_f_pointer(gas_state_ptr_c, gas_state_ptr_f) |
| 87 | + call c_f_pointer(env_state_ptr_c, env_state_ptr_f) |
| 88 | + |
| 89 | + call input_state(filename, index, time, del_t, i_repeat, uuid, & |
| 90 | + aero_data_ptr_f, aero_state_ptr_f, gas_data_ptr_f, gas_state_ptr_f, & |
| 91 | + env_state_ptr_f) |
| 92 | + |
| 93 | + end subroutine |
| 94 | + |
| 95 | +end module |
0 commit comments