Skip to content

Commit

Permalink
updated fortran-yaml-c and updated clima version
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Oct 27, 2022
1 parent a11a4d7 commit 890e061
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION "3.14")
project(Photochem LANGUAGES Fortran C VERSION "0.3.7")
project(Photochem LANGUAGES Fortran C VERSION "0.3.8")

include(FortranCInterface)
FortranCInterface_VERIFY()
Expand Down
8 changes: 4 additions & 4 deletions src/dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ CPMAddPackage(

CPMAddPackage(
NAME fortran-yaml-c
VERSION 0.1.2
VERSION 0.2.1
GITHUB_REPOSITORY "Nicholaswogan/fortran-yaml-c"
GIT_TAG "v0.1.2"
GIT_TAG "v0.2.1"
EXCLUDE_FROM_ALL ON
)

Expand Down Expand Up @@ -49,10 +49,10 @@ CPMAddPackage(

CPMAddPackage(
NAME clima
VERSION 0.2.0
VERSION 0.2.3
OPTIONS
"BUILD_WITH_OPENMP ${BUILD_WITH_OPENMP}"
GITHUB_REPOSITORY "Nicholaswogan/clima"
GIT_TAG "v0.2.0"
GIT_TAG "v0.2.3"
EXCLUDE_FROM_ALL ON
)
2 changes: 1 addition & 1 deletion src/input/photochem_input.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module photochem_input
use yaml_types, only : type_node, type_dictionary, type_list, type_error, &
use fortran_yaml_c_types, only : type_node, type_dictionary, type_list, type_error, &
type_list_item, type_scalar, type_key_value_pair
use photochem_types, only : PhotochemData, PhotochemVars, PhotoSettings
use photochem_const, only: dp, str_len, s_str_len
Expand Down
53 changes: 19 additions & 34 deletions src/input/photochem_input_read.f90
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,24 @@ module subroutine read_all_files(mechanism_file, s, flux_file, atmosphere_txt, b
end subroutine

subroutine get_photomech(infile, dat, var, err)
use fortran_yaml_c, only : parse, error_length
use fortran_yaml_c, only : YamlFile
character(len=*), intent(in) :: infile
type(PhotochemData), intent(inout) :: dat
type(PhotochemVars), intent(in) :: var
character(:), allocatable, intent(out) :: err

character(error_length) :: error
class (type_node), pointer :: root

type(YamlFile) :: file

! parse yaml file
root => parse(infile,error=error)
if (error /= '') then
err = trim(error)
return
end if
select type (root)
call file%parse(infile, err)
if (allocated(err)) return
select type (root => file%root)
class is (type_dictionary)
call get_rxmechanism(root, infile, dat, var, err)
class default
err = "yaml file must have dictionaries at root level"
end select
call root%finalize()
deallocate(root)
call file%finalize()
if (allocated(err)) return

end subroutine
Expand Down Expand Up @@ -1000,33 +995,28 @@ subroutine get_henry_parse(root, dat, var, henry_names, henry_data, err)

subroutine get_henry(dat, var, s, err)
use photochem_types, only: PhotoSettings
use fortran_yaml_c, only : parse, error_length
use fortran_yaml_c, only : YamlFile
type(PhotochemData), intent(inout) :: dat
type(PhotochemVars), intent(in) :: var
type(PhotoSettings), intent(in) :: s
character(:), allocatable :: err

character(error_length) :: error
class (type_node), pointer :: root
type(YamlFile) :: file
integer :: j, ind, ind1, i

character(len=s_str_len), allocatable :: henry_names(:)
real(dp), allocatable :: henry_data(:,:)

! parse yaml file
root => parse(trim(var%data_dir)//"/henry/henry.yaml",error=error)
if (error /= '') then
err = trim(error)
return
end if
select type (root)
call file%parse(trim(var%data_dir)//"/henry/henry.yaml", err)
if (allocated(err)) return
select type (root => file%root)
class is (type_list)
call get_henry_parse(root, dat, var, henry_names, henry_data, err)
class default
err = "yaml file must have dictionaries at root level"
end select
call root%finalize()
deallocate(root)
call file%finalize()
if (allocated(err)) return

allocate(dat%henry_data(2,dat%nsp))
Expand Down Expand Up @@ -2365,33 +2355,28 @@ subroutine get_photolysis_xs(dat, var, err)


subroutine get_rayleigh(dat, var, err)
use fortran_yaml_c, only : parse, error_length
use fortran_yaml_c, only : YamlFile
type(PhotochemData), intent(inout) :: dat
type(PhotochemVars), intent(in) :: var
character(:), allocatable, intent(out) :: err

real(dp), allocatable :: A(:), B(:), Delta(:)
character(len=str_len) :: rayleigh_file

character(error_length) :: error
class (type_node), pointer :: root
type(YamlFile) :: file
integer :: i, j

rayleigh_file = trim(var%data_dir)//"/rayleigh/rayleigh.yaml"

! parse yaml file
root => parse(rayleigh_file,error=error)
if (error /= '') then
err = trim(error)
return
end if
select type (root)
call file%parse(rayleigh_file, err)
if (allocated(err)) return
select type (root => file%root)
class is (type_dictionary)
call rayleigh_params(root,dat,trim(rayleigh_file),err, &
dat%raynums, A, B, Delta)
end select
call root%finalize()
deallocate(root)
call file%finalize()
if (allocated(err)) return

! compute cross sections
Expand Down
21 changes: 8 additions & 13 deletions src/photochem_types_create.f90
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
submodule (photochem_types) photochem_types_create
use yaml_types, only : type_node, type_dictionary, type_list, type_error, &
type_list_item, type_scalar, type_key_value_pair
use fortran_yaml_c_types, only : type_node, type_dictionary, type_list, type_error, &
type_list_item, type_scalar, type_key_value_pair
implicit none

contains

module function create_PhotoSettings(filename, err) result(s)
use fortran_yaml_c, only : parse, error_length
use fortran_yaml_c, only : YamlFile
use photochem_types, only: PhotoSettings
character(*), intent(in) :: filename
character(:), allocatable, intent(out) :: err

type(PhotoSettings) :: s

character(error_length) :: error
class (type_node), pointer :: root
type(YamlFile) :: file

! parse yaml file
root => parse(filename,error=error)
if (error /= '') then
err = trim(error)
return
end if
select type (root)
call file%parse(filename, err)
if (allocated(err)) return
select type (root => file%root)
class is (type_dictionary)
s = unpack_PhotoSettings(root, filename, err)
class default
err = "yaml file must have dictionaries at root level"
end select
call root%finalize()
deallocate(root)
call file%finalize()
if (allocated(err)) return

end function
Expand Down

0 comments on commit 890e061

Please sign in to comment.