Skip to content

Commit

Permalink
evo out2atmophere python
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Mar 9, 2023
1 parent f0892aa commit 13cd90c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions photochem/cython/EvoAtmosphere.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ cdef class EvoAtmosphere:
wrk = PhotochemWrk(alloc = False)
wrk._ptr = self._wrk_ptr
return wrk

def out2atmosphere_txt(self,filename = None, bool overwrite = False, bool clip = True):
cdef bytes filename_b = pystring2cstring(filename)
cdef char *filename_c = filename_b
cdef char err[ERR_LEN+1]
ea_pxd.evoatmosphere_out2atmosphere_txt_wrapper(&self._ptr, filename_c, &overwrite, &clip, err)
if len(err.strip()) > 0:
raise PhotoException(err.decode("utf-8").strip())

def regrid_prep_atmosphere(self, ndarray[double, ndim=2] usol_, double top_atmos):
cdef char err[ERR_LEN+1]
Expand Down
2 changes: 2 additions & 0 deletions photochem/cython/EvoAtmosphere_pxd.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ cdef extern void evoatmosphere_init_wrapper(void *ptr, char *data_dir, char *mec
char *atmosphere_txt, void *dat_ptr, void *var_ptr,
void *wrk_ptr, char *err);

cdef extern void evoatmosphere_out2atmosphere_txt_wrapper(void *ptr, char *filename, bool *overwrite, bool *clip, char *err)

cdef extern void evoatmosphere_regrid_prep_atmosphere_wrapper(void *ptr, int *nq, int *nz, double *usol, double *top_atmos, char *err)

cdef extern void evoatmosphere_evolve_wrapper(void *ptr, char *filename,
Expand Down
26 changes: 26 additions & 0 deletions photochem/fortran/EvoAtmosphere_wrapper.f90
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,32 @@ subroutine evoatmosphere_init_wrapper(ptr, data_dir, mechanism_file, &
wrk_ptr = c_loc(pc%wrk)
end subroutine

subroutine evoatmosphere_out2atmosphere_txt_wrapper(ptr, filename, overwrite, clip, err) bind(c)
type(c_ptr), intent(in) :: ptr
character(kind=c_char), intent(in) :: filename(*)
logical(c_bool), intent(in) :: overwrite, clip
character(kind=c_char), intent(out) :: err(err_len+1)

character(len=:), allocatable :: filename_f
logical :: overwrite_f, clip_f
character(:), allocatable :: err_f
type(EvoAtmosphere), pointer :: pc

call c_f_pointer(ptr, pc)

allocate(character(len=len_cstring(filename))::filename_f)
call copy_string_ctof(filename, filename_f)
overwrite_f = overwrite
clip_f = clip

call pc%out2atmosphere_txt(filename_f, overwrite_f, clip_f, err_f)
err(1) = c_null_char
if (allocated(err_f)) then
call copy_string_ftoc(err_f, err)
endif

end subroutine

subroutine evoatmosphere_regrid_prep_atmosphere_wrapper(ptr, nq, nz, usol, top_atmos, err) bind(c)
type(c_ptr), intent(in) :: ptr
integer(c_int), intent(in) :: nq, nz
Expand Down

0 comments on commit 13cd90c

Please sign in to comment.