diff --git a/src/soca/LinearVariableChange/Balance/CMakeLists.txt b/src/soca/LinearVariableChange/Balance/CMakeLists.txt index c1f1756e..bc8a3f86 100644 --- a/src/soca/LinearVariableChange/Balance/CMakeLists.txt +++ b/src/soca/LinearVariableChange/Balance/CMakeLists.txt @@ -6,4 +6,5 @@ soca_target_sources( soca_balance.interface.F90 soca_ksshts_mod.F90 soca_kst_mod.F90 + soca_write_jacobian_mod.F90 ) \ No newline at end of file diff --git a/src/soca/LinearVariableChange/Balance/soca_balance_mod.F90 b/src/soca/LinearVariableChange/Balance/soca_balance_mod.F90 index 45c25ab7..ad5ba416 100644 --- a/src/soca/LinearVariableChange/Balance/soca_balance_mod.F90 +++ b/src/soca/LinearVariableChange/Balance/soca_balance_mod.F90 @@ -17,6 +17,7 @@ module soca_balance_mod use soca_ksshts_mod, only: soca_ksshts, soca_steric_jacobian use soca_kst_mod, only: soca_kst, soca_soft_jacobian use soca_state_mod, only: soca_state +use soca_write_jacobian_mod, only: write_jacobian_to_netcdf implicit none private @@ -96,6 +97,7 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) ! declarations related to the dynamic height Jacobians character(len=:), allocatable :: filename + character(len=:), allocatable :: str ! declarations related to the sea-ice Jacobian character(len=:), allocatable :: kct_name @@ -165,6 +167,12 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) end do end do deallocate(jac) + + ! optionally write out Kst Jacobian + if ( f_conf%has("kst.jacobian_output")) then + call f_conf%get_or_die("kst.jacobian_output.filename", str) + call write_jacobian_to_netcdf(self%kst%jacobian, geom, str, "kst_jacobian") + end if end if ! Get configuration for Ksshts @@ -193,6 +201,13 @@ subroutine soca_balance_setup(self, f_conf, traj, geom) end do deallocate(jac) + ! optionally write out Ksshts Jacobian + if ( f_conf%has("ksshts.jacobian_output")) then + call f_conf%get_or_die("ksshts.jacobian_output.filename", str) + call write_jacobian_to_netcdf(self%ksshts%kssht, geom, str, "kssht_jacobian") + call write_jacobian_to_netcdf(self%ksshts%ksshs, geom, str, "ksshs_jacobian") + end if + ! Compute Kct if (traj%has("sea_ice_area_fraction")) then ! Setup dc/dT diff --git a/src/soca/LinearVariableChange/Balance/soca_write_jacobian_mod.F90 b/src/soca/LinearVariableChange/Balance/soca_write_jacobian_mod.F90 new file mode 100644 index 00000000..4bdef0a5 --- /dev/null +++ b/src/soca/LinearVariableChange/Balance/soca_write_jacobian_mod.F90 @@ -0,0 +1,35 @@ +! (C) Copyright 2017-2025 UCAR +! +! This software is licensed under the terms of the Apache Licence Version 2.0 +! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + +module soca_write_jacobian_mod + +use kinds, only: kind_real +use soca_geom_mod, only: soca_geom +use fms_mod, only: write_data, set_domain +use fms_io_mod, only: fms_io_init, fms_io_exit + +implicit none +private +public :: write_jacobian_to_netcdf + +contains + +subroutine write_jacobian_to_netcdf(jacobian, geom, filename, varname) + real(kind=kind_real), intent(in) :: jacobian(:,:,:) + type(soca_geom), intent(in) :: geom + character(len=*), intent(in) :: filename + character(len=*), intent(in) :: varname + + + call fms_io_init() + call set_domain(geom%Domain%mpp_domain) + + ! Write the jacobian data from all PEs + call write_data(filename, varname, jacobian, geom%Domain%mpp_domain) + + call fms_io_exit() +end subroutine write_jacobian_to_netcdf + +end module soca_write_jacobian_mod