diff --git a/photochem/cython/PhotochemVars.pyx b/photochem/cython/PhotochemVars.pyx index 4882ad7..0a5e8e0 100644 --- a/photochem/cython/PhotochemVars.pyx +++ b/photochem/cython/PhotochemVars.pyx @@ -52,6 +52,15 @@ cdef class PhotochemVars: cdef ndarray arr = np.empty((dim1, dim2), np.double, order="F") var_pxd.photochemvars_usol_init_get(&self._ptr, &dim1, &dim2, arr.data) return arr + + property relative_humidity: + "double. Relative humidity of H2O in the troposphere." + def __get__(self): + cdef double val + var_pxd.photochemvars_relative_humidity_get(&self._ptr, &val) + return val + def __set__(self, double val): + var_pxd.photochemvars_relative_humidity_set(&self._ptr, &val) property z: "ndarray[double,dim=1], shape (nz). The altitude of the center of each atmopsheric layer (cm)" @@ -99,6 +108,13 @@ cdef class PhotochemVars: cdef ndarray arr = np.empty(dim1, np.double) var_pxd.photochemvars_edd_get(&self._ptr, &dim1, arr.data) return arr + def __set__(self, ndarray[double, ndim=1] edd_new_): + cdef int dim1 + var_pxd.photochemvars_edd_get_size(&self._ptr, &dim1) + cdef ndarray edd_new = np.asfortranarray(edd_new_) + if edd_new.shape[0] != dim1: + raise PhotoException("Input edd is the wrong size.") + var_pxd.photochemvars_edd_set(&self._ptr, &dim1, edd_new.data) property custom_binary_diffusion_fcn: "A function for specifying a custom binary diffusion parameter (b_ij)" diff --git a/photochem/cython/PhotochemVars_pxd.pxd b/photochem/cython/PhotochemVars_pxd.pxd index 7d84721..b35ad24 100644 --- a/photochem/cython/PhotochemVars_pxd.pxd +++ b/photochem/cython/PhotochemVars_pxd.pxd @@ -20,6 +20,9 @@ cdef extern void photochemvars_at_photo_equilibrium_get(void *ptr, bool *at_phot cdef extern void photochemvars_usol_init_get_size(void *ptr, int *dim1, int *dim2) cdef extern void photochemvars_usol_init_get(void *ptr, int *dim1, int *dim2, double *usol_init) +cdef extern void photochemvars_relative_humidity_get(void *ptr, double *val) +cdef extern void photochemvars_relative_humidity_set(void *ptr, double *val) + cdef extern void photochemvars_photon_flux_fcn_set(void *ptr, time_dependent_flux_fcn fcn) cdef extern void photochemvars_temperature_get_size(void *ptr, int *dim1) @@ -27,6 +30,7 @@ cdef extern void photochemvars_temperature_get(void *ptr, int *dim1, double *tem cdef extern void photochemvars_edd_get_size(void *ptr, int *dim1) cdef extern void photochemvars_edd_get(void *ptr, int *dim1, double *arr) +cdef extern void photochemvars_edd_set(void *ptr, int *dim1, double *arr) cdef extern void photochemvars_custom_binary_diffusion_fcn_set(void *ptr, binary_diffusion_fcn fcn) diff --git a/photochem/fortran/PhotochemVars_wrapper.f90 b/photochem/fortran/PhotochemVars_wrapper.f90 index 3c5eca0..9b1bd0b 100644 --- a/photochem/fortran/PhotochemVars_wrapper.f90 +++ b/photochem/fortran/PhotochemVars_wrapper.f90 @@ -71,6 +71,22 @@ subroutine photochemvars_usol_init_get(ptr, dim1, dim2, usol_init) bind(c) usol_init = var%usol_init end subroutine + subroutine photochemvars_relative_humidity_get(ptr, val) bind(c) + type(c_ptr), intent(in) :: ptr + real(c_double), intent(out) :: val + type(PhotochemVars), pointer :: var + call c_f_pointer(ptr, var) + val = var%relative_humidity + end subroutine + + subroutine photochemvars_relative_humidity_set(ptr, val) bind(c) + type(c_ptr), intent(in) :: ptr + real(c_double), intent(in) :: val + type(PhotochemVars), pointer :: var + call c_f_pointer(ptr, var) + var%relative_humidity = val + end subroutine + subroutine photochemvars_photon_flux_fcn_set(ptr, photon_flux_fcn_c) bind(c) use photochem_types, only: time_dependent_flux_fcn type(c_ptr), intent(in) :: ptr @@ -119,6 +135,15 @@ subroutine photochemvars_edd_get(ptr, dim1, arr) bind(c) arr = var%edd end subroutine + subroutine photochemvars_edd_set(ptr, dim1, arr) bind(c) + type(c_ptr), intent(in) :: ptr + integer(c_int), intent(in) :: dim1 + real(c_double), intent(in) :: arr(dim1) + type(PhotochemVars), pointer :: var + call c_f_pointer(ptr, var) + var%edd = arr + end subroutine + subroutine photochemvars_custom_binary_diffusion_fcn_set(ptr, fcn_c) bind(c) use photochem_types, only: binary_diffusion_fcn type(c_ptr), intent(in) :: ptr diff --git a/src/input/photochem_input_read.f90 b/src/input/photochem_input_read.f90 index 352ea58..9e059a2 100644 --- a/src/input/photochem_input_read.f90 +++ b/src/input/photochem_input_read.f90 @@ -745,14 +745,13 @@ subroutine unpack_settings(infile, s, dat, var, err) if (dat%fix_water_in_trop) then - allocate(var%relative_humidity) read(s%relative_humidity,*,iostat = io) var%relative_humidity if (io /= 0) then ! it isn't a float if (trim(s%relative_humidity) == "manabe") then var%use_manabe = .true. - deallocate(var%relative_humidity) + var%relative_humidity = -1.0 else err = '"relative-humidity" can only be a number between 0 and 1, or "manabe". See '//trim(infile) return diff --git a/src/photochem_types.f90 b/src/photochem_types.f90 index 2136481..f21ffe4 100644 --- a/src/photochem_types.f90 +++ b/src/photochem_types.f90 @@ -404,7 +404,7 @@ subroutine time_dependent_rate_fcn(tn, nz, rate) real(dp) :: rainfall_rate !! relative to modern Earth's average rainfall rate of 1.1e17 molecules/cm2/s integer :: trop_ind !! index of troposphere (only for fix_water_in_trop == true or gas_rainout == true) logical :: use_manabe !! use manabe formula - real(dp), allocatable :: relative_humidity !! relative humidity if no manabe + real(dp) :: relative_humidity !! relative humidity if no manabe real(dp) :: H2O_condensation_rate(3) !! H2O condesation rate parameters ! radiative transfer