Skip to content

Commit

Permalink
added ability to do true for k-distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholaswogan committed Oct 26, 2023
1 parent b4daf6b commit 3751150
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/clima_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module clima_types
character(:), allocatable :: k_method
integer :: nbins

logical, allocatable :: k_distributions_bool
character(s_str_len), allocatable :: k_distributions(:)
logical, allocatable :: cia_bool
character(s_str_len), allocatable :: cia(:)
Expand Down
35 changes: 24 additions & 11 deletions src/clima_types_create.f90
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,8 @@ subroutine unpack_settingsopacity(op_dict, filename, op, err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif

! k-distributions
tmp => opacities%get_list("k-distributions",required=.false., error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif
if (associated(tmp)) then
node => opacities%get("k-distributions")
if (associated(node)) then

! k-distribution settings
! ability to rebin k-coefficients in the files, before any calculations
Expand All @@ -850,10 +849,10 @@ subroutine unpack_settingsopacity(op_dict, filename, op, err)
endif
endif

! get k-method, and check that it is valid
op%k_method = op_dict%get_string("k-method", error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif
op%k_method = trim(op%k_method)

if (op%k_method == "RandomOverlapResortRebin") then
op%nbins = op_dict%get_integer("number-of-bins", error=io_err)
if (allocated(io_err)) then; err = trim(filename)//trim(io_err%message); return; endif
Expand All @@ -865,14 +864,28 @@ subroutine unpack_settingsopacity(op_dict, filename, op, err)
err = 'k-method "'//op%k_method//'" in "'//filename//'" is not an option.'
return
endif

call unpack_string_list(filename, tmp, op%k_distributions, err)
if (allocated(err)) return
ind = check_for_duplicates(op%k_distributions)
if (ind /= 0) then
err = '"'//trim(op%k_distributions(ind))//'" is a duplicate in '//trim(tmp%path)

! Which k-distributions to consider
select type (node)
class is (type_list)
call unpack_string_list(filename, node, op%k_distributions, err)
if (allocated(err)) return
ind = check_for_duplicates(op%k_distributions)
if (ind /= 0) then
err = '"'//trim(op%k_distributions(ind))//'" is a duplicate in '//trim(node%path)
return
endif
class is (type_scalar)
allocate(op%k_distributions_bool)
op%k_distributions_bool = node%to_logical(default=.true.,success=success)
if (.not. success) then
err = 'Failed to convert "'//trim(node%path)//'" to logical'
return
endif
class default
err = '"'//trim(node%path)//'" must be a list or a scalar.'
return
endif
end select
endif

! CIA
Expand Down
55 changes: 49 additions & 6 deletions src/radtran/clima_radtran_types_create.f90
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,58 @@ module function create_OpticalProperties(datadir, optype, species_names, &
!!!!!!!!!!!!!!!!!!!!!!!
!!! k-distributions !!!
!!!!!!!!!!!!!!!!!!!!!!!
if (allocated(sop%k_distributions)) then
tmp_bool = .false.
if (allocated(sop%k_distributions_bool)) tmp_bool = sop%k_distributions_bool

if (allocated(sop%k_distributions) .or. tmp_bool) then

if (tmp_bool) then

! Look to see if the files / data exist
j = 0
do i = 1,size(species_names)
filename = datadir//"/kdistributions/"//trim(species_names(i))//".h5"
inquire(file=filename, exist=file_exists)
if (file_exists) j = j + 1
enddo

if (j == 0) then
err = 'No k-distribution data was found, but at least one k-distribution '// &
'is needed.'
return
endif

! Make a list of avaliable data files
op%nk = j
if (allocated(tmp_str_list)) deallocate(tmp_str_list)
allocate(tmp_str_list(op%nk))
j = 1
do i = 1,size(species_names)
filename = datadir//"/kdistributions/"//trim(species_names(i))//".h5"
inquire(file=filename, exist=file_exists)
if (file_exists) then
tmp_str_list(j) = species_names(i)
j = j + 1
endif
enddo

else
op%nk = size(sop%k_distributions)
if (allocated(tmp_str_list)) deallocate(tmp_str_list)
allocate(tmp_str_list(op%nk))
tmp_str_list = sop%k_distributions
endif

! k distributions settings
op%kset = create_Ksettings(sop)

op%nk = size(sop%k_distributions)
allocate(op%k(op%nk))

do i = 1,op%nk
filename = datadir//"/kdistributions/"//trim(sop%k_distributions(i))//".h5"
ind1 = findloc(species_names, trim(sop%k_distributions(i)), 1)
filename = datadir//"/kdistributions/"//trim(tmp_str_list(i))//".h5"
ind1 = findloc(species_names, trim(tmp_str_list(i)), 1)
if (ind1 == 0) then
err = 'Species "'//trim(sop%k_distributions(i))//'" in optical property '// &
err = 'Species "'//trim(tmp_str_list(i))//'" in optical property '// &
'"k-distributions" is not in the list of species.'
return
endif
Expand Down Expand Up @@ -265,9 +304,12 @@ module function create_OpticalProperties(datadir, optype, species_names, &
endif

else
op%nk = 0
endif

if (op%nk == 0) then
err = "You must specify at least one k-distribution in the settings file."
return
! op%nk = 0
endif

!!!!!!!!!!!
Expand Down Expand Up @@ -378,6 +420,7 @@ module function create_OpticalProperties(datadir, optype, species_names, &
endif
pair => pair%next
enddo
if (allocated(tmp_str_list)) deallocate(tmp_str_list)
allocate(tmp_str_list(i))
i = 1
pair => root_dict%first
Expand Down

0 comments on commit 3751150

Please sign in to comment.