From 366673c8fb1e47edc425b58e89d7c1bd84aa8af5 Mon Sep 17 00:00:00 2001 From: Haipeng Lin Date: Fri, 13 Mar 2026 12:22:59 -0400 Subject: [PATCH 1/4] Check and enforce FLOAT64 snapshots for null dycore --- src/dynamics/none/dyn_grid.F90 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/dynamics/none/dyn_grid.F90 b/src/dynamics/none/dyn_grid.F90 index 8d2b0431c..6fe7760c4 100644 --- a/src/dynamics/none/dyn_grid.F90 +++ b/src/dynamics/none/dyn_grid.F90 @@ -62,6 +62,7 @@ subroutine model_grid_init() use pio, only: PIO_BCAST_ERROR, pio_seterrorhandling use pio, only: pio_get_var, pio_freedecomp use pio, only: pio_read_darray + use pio, only: pio_inq_vartype, PIO_NOERR use spmd_utils, only: npes, iam use cam_pio_utils, only: cam_pio_handle_error, cam_pio_find_var use cam_pio_utils, only: cam_pio_var_info, pio_subsystem @@ -107,6 +108,7 @@ subroutine model_grid_init() character(len=8) :: lat_dim_name character(len=8) :: lon_dim_name character(len=128) :: errormsg + integer :: xtype character(len=*), parameter :: subname = 'model_grid_init' @@ -225,6 +227,22 @@ subroutine model_grid_init() 'eastward_wind' /), & fieldname, vardesc, var_found) if (var_found) then + ! Check that snapshot file has 64-bit floats (ndens=1). + ! Running with 32-bit (FLOAT32) snapshots will definitely cause + ! answer differences between CAM-SIMA and the CAM snapshot + ! leading to wasted debugging time, so disallow this configuration: + iret = pio_inq_vartype(fh_ini, vardesc, xtype) + if (iret /= PIO_NOERR) then + call endrun(subname//': Unable to inquire variable type for '// & + trim(fieldname)) + end if + if (xtype /= PIO_DOUBLE) then + call endrun(subname//': Snapshot file has non-FLOAT64 data '// & + '(variable '//trim(fieldname)//'). '// & + 'This will cause answer differences!'// & + 'Please rerun CAM with ndens = 1 to write 64-bit float '// & + 'snapshots for use with CAM-SIMA.') + end if ! Find the variable dimension info dimnames = '' dimids = -1 From 032aa7d9792c532746fc8b63aa464ad34f69fbbc Mon Sep 17 00:00:00 2001 From: Haipeng Lin Date: Fri, 13 Mar 2026 12:52:24 -0400 Subject: [PATCH 2/4] Fix space --- src/dynamics/none/dyn_grid.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dynamics/none/dyn_grid.F90 b/src/dynamics/none/dyn_grid.F90 index 6fe7760c4..e47591d1a 100644 --- a/src/dynamics/none/dyn_grid.F90 +++ b/src/dynamics/none/dyn_grid.F90 @@ -239,7 +239,7 @@ subroutine model_grid_init() if (xtype /= PIO_DOUBLE) then call endrun(subname//': Snapshot file has non-FLOAT64 data '// & '(variable '//trim(fieldname)//'). '// & - 'This will cause answer differences!'// & + 'This will cause answer differences! '// & 'Please rerun CAM with ndens = 1 to write 64-bit float '// & 'snapshots for use with CAM-SIMA.') end if From 54dfebfe8d82d83523e1a718254ae652aaab671e Mon Sep 17 00:00:00 2001 From: Haipeng Lin Date: Sun, 15 Mar 2026 18:03:31 -0400 Subject: [PATCH 3/4] Address review comment: check float64 snapshot only when ncdata_check is not unset_path_str --- src/dynamics/none/dyn_grid.F90 | 32 +++++++++++++++++++------------- src/physics/utils/phys_comp.F90 | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/dynamics/none/dyn_grid.F90 b/src/dynamics/none/dyn_grid.F90 index e47591d1a..64cc20b8b 100644 --- a/src/dynamics/none/dyn_grid.F90 +++ b/src/dynamics/none/dyn_grid.F90 @@ -69,7 +69,8 @@ subroutine model_grid_init() use cam_pio_utils, only: cam_pio_newdecomp use cam_abortutils, only: endrun use cam_logfile, only: cam_log_multiwrite - use cam_initfiles, only: initial_file_get_id + use cam_initfiles, only: initial_file_get_id, unset_path_str + use phys_comp, only: ncdata_check use vert_coord, only: vert_coord_init, pver use hycoef, only: hycoef_init, hypi, hypm, nprlev, & hyam, hybm, hyai, hybi, ps0 @@ -230,18 +231,23 @@ subroutine model_grid_init() ! Check that snapshot file has 64-bit floats (ndens=1). ! Running with 32-bit (FLOAT32) snapshots will definitely cause ! answer differences between CAM-SIMA and the CAM snapshot - ! leading to wasted debugging time, so disallow this configuration: - iret = pio_inq_vartype(fh_ini, vardesc, xtype) - if (iret /= PIO_NOERR) then - call endrun(subname//': Unable to inquire variable type for '// & - trim(fieldname)) - end if - if (xtype /= PIO_DOUBLE) then - call endrun(subname//': Snapshot file has non-FLOAT64 data '// & - '(variable '//trim(fieldname)//'). '// & - 'This will cause answer differences! '// & - 'Please rerun CAM with ndens = 1 to write 64-bit float '// & - 'snapshots for use with CAM-SIMA.') + ! leading to wasted debugging time, so disallow this configuration. + ! Only check when running a snapshot test (ncdata_check is set), + ! since the null dycore may also be used for other purposes + ! (e.g. single-column model) where lower-precision data is fine. + if (trim(ncdata_check) /= trim(unset_path_str)) then + iret = pio_inq_vartype(fh_ini, vardesc, xtype) + if (iret /= PIO_NOERR) then + call endrun(subname//': Unable to inquire variable type for '// & + trim(fieldname)) + end if + if (xtype /= PIO_DOUBLE) then + call endrun(subname//': Snapshot file has non-FLOAT64 data '// & + '(variable '//trim(fieldname)//'). '// & + 'This will cause answer differences! '// & + 'Please rerun CAM with ndens = 1 to write 64-bit float '// & + 'snapshots for use with CAM-SIMA.') + end if end if ! Find the variable dimension info dimnames = '' diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index 471ee9e03..fc1a12563 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -26,7 +26,7 @@ module phys_comp character(len=SHR_KIND_CS), allocatable :: suite_names(:) character(len=SHR_KIND_CS) :: suite_parts_expect(2) = (/"physics_before_coupler", "physics_after_coupler "/) character(len=SHR_KIND_CS), allocatable :: suite_parts(:) - character(len=SHR_KIND_CL) :: ncdata_check = unset_str + character(len=SHR_KIND_CL), public, protected :: ncdata_check = unset_str logical :: ncdata_check_err = .false. character(len=SHR_KIND_CL) :: cam_physics_mesh = unset_str character(len=SHR_KIND_CS) :: cam_take_snapshot_before = unset_str From 69a2f93b2ae778dbdfe8eab013a1f9d5e7ece918 Mon Sep 17 00:00:00 2001 From: Haipeng Lin Date: Mon, 16 Mar 2026 13:27:11 -0400 Subject: [PATCH 4/4] Move ncdata_check to public section --- src/physics/utils/phys_comp.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/physics/utils/phys_comp.F90 b/src/physics/utils/phys_comp.F90 index fc1a12563..4db7c9c71 100644 --- a/src/physics/utils/phys_comp.F90 +++ b/src/physics/utils/phys_comp.F90 @@ -22,11 +22,14 @@ module phys_comp ! suite_name: Suite we are running character(len=SHR_KIND_CS), public, protected :: phys_suite_name = unset_str + ! ncdata_check: Path to file for physics_check_data to verify against + ! at the end of every timestep (if not unset) + character(len=SHR_KIND_CL), public, protected :: ncdata_check = unset_str + ! Private module data character(len=SHR_KIND_CS), allocatable :: suite_names(:) character(len=SHR_KIND_CS) :: suite_parts_expect(2) = (/"physics_before_coupler", "physics_after_coupler "/) character(len=SHR_KIND_CS), allocatable :: suite_parts(:) - character(len=SHR_KIND_CL), public, protected :: ncdata_check = unset_str logical :: ncdata_check_err = .false. character(len=SHR_KIND_CL) :: cam_physics_mesh = unset_str character(len=SHR_KIND_CS) :: cam_take_snapshot_before = unset_str