From 537c9982c6a1223b0c0506a7fe6ffbc1d0489921 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Thu, 13 Jul 2023 14:43:12 -0600 Subject: [PATCH 01/14] Initial attempt of setting default constituent value. --- Externals_CAM.cfg | 2 +- src/data/write_init_files.py | 35 ++++++- src/dynamics/se/dyn_comp.F90 | 6 +- src/physics/utils/physics_data.F90 | 94 +++++++++++++------ .../write_init_files/physics_inputs_4D.F90 | 57 +++++++++-- .../write_init_files/physics_inputs_bvd.F90 | 39 +++++++- .../write_init_files/physics_inputs_ddt.F90 | 57 +++++++++-- .../write_init_files/physics_inputs_ddt2.F90 | 39 +++++++- .../physics_inputs_ddt_array.F90 | 39 +++++++- .../physics_inputs_host_var.F90 | 40 +++++++- .../write_init_files/physics_inputs_mf.F90 | 59 +++++++++--- .../physics_inputs_no_horiz.F90 | 40 +++++++- .../write_init_files/physics_inputs_noreq.F90 | 39 +++++++- .../write_init_files/physics_inputs_param.F90 | 39 +++++++- .../physics_inputs_protect.F90 | 40 +++++++- .../physics_inputs_scalar.F90 | 39 +++++++- .../physics_inputs_simple.F90 | 39 +++++++- 17 files changed, 625 insertions(+), 78 deletions(-) diff --git a/Externals_CAM.cfg b/Externals_CAM.cfg index 32b3fe54..00960059 100644 --- a/Externals_CAM.cfg +++ b/Externals_CAM.cfg @@ -2,7 +2,7 @@ local_path = ccpp_framework protocol = git repo_url = https://github.com/peverwhee/ccpp-framework -tag = CPF_0.2.043 +tag = CPF_0.2.045 required = True [cosp2] diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 41f18b60..667122e6 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -819,10 +819,12 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, ["physics_data", ["read_field", "find_input_name_idx", "no_exist_idx", "init_mark_idx", "prot_no_init_idx", "const_idx"]], - ["cam_ccpp_cap", ["ccpp_physics_suite_variables", "cam_constituents_array"]], + ["cam_ccpp_cap", ["ccpp_physics_suite_variables", "cam_constituents_array", "cam_model_const_properties"]], ["ccpp_kinds", ["kind_phys"]], [phys_check_fname_str, ["phys_var_stdnames", - "input_var_names", "std_name_len"]]] + "input_var_names", "std_name_len"]], + ["ccpp_constituent_prop_mod", ["ccpp_constituent_prop_ptr_t"]], + ["cam_logfile", ["iulog"]]] # Add in host model data use statements use_stmts.extend(host_imports) @@ -860,6 +862,14 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("character(len=2) :: sep2 !String separator used to print err messages", 2) outfile.write("character(len=2) :: sep3 !String separator used to print err messages", 2) outfile.write("real(kind=kind_phys), pointer :: field_data_ptr(:,:,:)", 2) + outfile.write("logical :: var_found !Bool to determine if consituent found in data files", 2) + outfile.blank_line() + outfile.comment("Fields needed for getting default data value for constituents", 2) + outfile.write("type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:)", 2) + outfile.write("real(kind=kind_phys) :: constituent_default_value", 2) + outfile.write("integer :: constituent_errflg", 2) + outfile.write("character(len=SHR_KIND_CX) :: constituent_errmsg", 2) + outfile.write("logical :: constituent_has_default", 2) outfile.blank_line() outfile.comment("Logical to default optional argument to False:", 2) outfile.write("logical :: use_init_variables", 2) @@ -949,8 +959,27 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.blank_line() outfile.comment("If an index was found in the constituent hash table, then read in the data to that index of the constituent array", 6) outfile.blank_line() + outfile.write("var_found = .false.", 6) outfile.write("field_data_ptr => cam_constituents_array()", 6) - outfile.write("call read_field(file, ccpp_required_data(req_idx), [ccpp_required_data(req_idx)], 'lev', timestep, field_data_ptr(:,:,constituent_idx), mark_as_read=.false.)", 6) + outfile.write("call read_field(file, ccpp_required_data(req_idx), [ccpp_required_data(req_idx)], 'lev', timestep, field_data_ptr(:,:,constituent_idx), mark_as_read=.false., error_on_not_found=.false., var_found=var_found)", 6) + outfile.write("if(.not. var_found) then", 6) + outfile.write("const_props => cam_model_const_properties()", 7) + outfile.write("constituent_has_default = .false.", 7) + outfile.write("call const_props(constituent_idx)%has_default(constituent_has_default, constituent_errflg, constituent_errmsg)", 7) + outfile.write("if (constituent_has_default) then", 7) + outfile.write("call const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg, constituent_errmsg)", 8) + outfile.write("field_data_ptr(:,:,constituent_idx) = constituent_default_value", 8) + outfile.write("if (masterproc) then", 8) + outfile.write("write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), ' initialized from file: ', constituent_default_value", 9) + outfile.write("end if", 8) + outfile.write("else", 7) + outfile.write("field_data_ptr(:,:,constituent_idx) = 0._kind_phys", 8) + outfile.write("if (masterproc) then", 8) + outfile.write("write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), ' default value not configured. Setting to 0.'", 9) + outfile.write("end if", 8) + outfile.write("end if", 7) + outfile.write("end if", 6) + outfile.blank_line() # start default case steps: outfile.write("case default", 5) diff --git a/src/dynamics/se/dyn_comp.F90 b/src/dynamics/se/dyn_comp.F90 index 8c0d3049..baf02117 100644 --- a/src/dynamics/se/dyn_comp.F90 +++ b/src/dynamics/se/dyn_comp.F90 @@ -1843,9 +1843,9 @@ subroutine read_inidat(dyn_in) call mark_as_initialized("reciprocal_of_pressure_thickness") call mark_as_initialized("inverse_exner_function_wrt_surface_pressure") call mark_as_initialized("lagrangian_tendency_of_air_pressure") - call mark_as_initialized("total_tendency_of_air_temperature") - call mark_as_initialized("total_tendency_of_x_wind") - call mark_as_initialized("total_tendency_of_y_wind") + call mark_as_initialized("tendency_of_air_temperature_due_to_model_physics") + call mark_as_initialized("tendency_of_x_wind_due_to_model_physics") + call mark_as_initialized("tendency_of_y_wind_due_to_model_physics") end subroutine read_inidat diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index eace4795..87838303 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -135,7 +135,7 @@ function arr2str(name_array) end function arr2str - subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_read) + subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_read, error_on_not_found, var_found) use shr_assert_mod, only: shr_assert_in_domain use shr_sys_mod, only: shr_sys_flush use pio, only: file_desc_t, var_desc_t @@ -156,9 +156,12 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re integer, intent(in) :: timestep real(kind_phys), intent(inout) :: buffer(:) logical, optional, intent(in) :: mark_as_read + logical, optional, intent(in) :: error_on_not_found + logical, optional, intent(out) :: var_found ! Local variables logical :: mark_as_read_local - logical :: var_found + logical :: error_on_not_found_local + logical :: var_found_local character(len=std_name_len) :: found_name type(var_desc_t) :: vardesc character(len=*), parameter :: subname = 'read_field_2d: ' @@ -169,35 +172,52 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re mark_as_read_local = .true. end if - call cam_pio_find_var(file, var_names, found_name, vardesc, var_found) - if (.not. var_found) then - call cam_pio_find_var(file, [std_name], found_name, vardesc, var_found) + if (present(error_on_not_found)) then + error_on_not_found_local = error_on_not_found + else + error_on_not_found_local = .true. end if - if (var_found) then + var_found_local = .false. + call cam_pio_find_var(file, var_names, found_name, vardesc, var_found_local) + if (.not. var_found_local) then + call cam_pio_find_var(file, [std_name], found_name, vardesc, var_found_local) + end if + + if (var_found_local) then if (masterproc) then write(iulog, *) 'Reading input field, ', trim(found_name) call shr_sys_flush(iulog) end if - call cam_read_field(found_name, file, buffer, var_found, & + call cam_read_field(found_name, file, buffer, var_found_local, & timelevel=timestep) + if (mark_as_read_local) then call mark_as_read_from_file(std_name) end if + + if (var_found_local) then + call shr_assert_in_domain(buffer, is_nan=.false., & + varname=trim(found_name), & + msg=subname//'NaN found in '//trim(found_name)) + else + call endrun(subname//'Mismatch variable found in '//arr2str(var_names)) + end if + else if (.not. error_on_not_found_local) then + if (masterproc) then + write(iulog, *) 'Var not found AND not failing when not found reading ', trim(arr2str(var_names)), ' and ', trim(std_name) + call shr_sys_flush(iulog) + end if else call endrun(subname//'No variable found in '//arr2str(var_names)) end if - if (var_found) then - call shr_assert_in_domain(buffer, is_nan=.false., & - varname=trim(found_name), & - msg=subname//'NaN found in '//trim(found_name)) - else - call endrun(subname//'Mismatch variable found in '//arr2str(var_names)) - end if + if (present(var_found)) then + var_found = var_found_local + end if end subroutine read_field_2d subroutine read_field_3d(file, std_name, var_names, vcoord_name, & - timestep, buffer, mark_as_read) + timestep, buffer, mark_as_read, error_on_not_found, var_found) use shr_assert_mod, only: shr_assert_in_domain use shr_sys_mod, only: shr_sys_flush use pio, only: file_desc_t, var_desc_t @@ -220,9 +240,12 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & integer, intent(in) :: timestep real(kind_phys), intent(inout) :: buffer(:,:) logical, optional, intent(in) :: mark_as_read + logical, optional, intent(in) :: error_on_not_found + logical, optional, intent(out) :: var_found ! Local variables logical :: mark_as_read_local - logical :: var_found + logical :: error_on_not_found_local + logical :: var_found_local integer :: num_levs character(len=std_name_len) :: found_name type(var_desc_t) :: vardesc @@ -234,12 +257,20 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & mark_as_read_local = .true. end if - call cam_pio_find_var(file, var_names, found_name, vardesc, var_found) + if (present(error_on_not_found)) then + error_on_not_found_local = error_on_not_found + else + error_on_not_found_local = .true. + end if - if (.not. var_found) then - call cam_pio_find_var(file, [std_name], found_name, vardesc, var_found) + var_found_local = .false. + call cam_pio_find_var(file, var_names, found_name, vardesc, var_found_local) + + if (.not. var_found_local) then + call cam_pio_find_var(file, [std_name], found_name, vardesc, var_found_local) end if - if (var_found) then + + if (var_found_local) then if (trim(vcoord_name) == 'lev') then num_levs = pver else if (trim(vcoord_name) == 'ilev') then @@ -251,21 +282,30 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & write(iulog, *) 'Reading input field, ', trim(found_name) call shr_sys_flush(iulog) end if - call cam_read_field(found_name, file, buffer, var_found, & + call cam_read_field(found_name, file, buffer, var_found_local, & timelevel=timestep, dim3name=trim(vcoord_name), & dim3_bnds=(/1, num_levs/)) + if (mark_as_read_local) then call mark_as_read_from_file(std_name) end if + if (var_found_local) then + call shr_assert_in_domain(buffer, is_nan=.false., & + varname=trim(found_name), & + msg=subname//'NaN found in '//trim(found_name)) + else + call endrun(subname//'Mismatch variable found in '//trim(std_name)) + end if + else if (.not. error_on_not_found_local) then + if (masterproc) then + write(iulog, *) 'Var not found AND not failing when not found reading ', trim(arr2str(var_names)), ' and ', trim(std_name) + call shr_sys_flush(iulog) + end if else call endrun(subname//'No variable found in '//arr2str(var_names)) end if - if (var_found) then - call shr_assert_in_domain(buffer, is_nan=.false., & - varname=trim(found_name), & - msg=subname//'NaN found in '//trim(found_name)) - else - call endrun(subname//'Mismatch variable found in '//found_name) + if (present(var_found)) then + var_found = var_found_local end if end subroutine read_field_3d diff --git a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 index 9f658864..e74d2a90 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 @@ -29,15 +29,18 @@ module physics_inputs_4D CONTAINS subroutine physics_read_data(file, suite_names, timestep, read_initialized_variables) - use pio, only: file_desc_t - use cam_abortutils, only: endrun - use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX - use physics_data, only: read_field, find_input_name_idx, no_exist_idx - use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx - use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array - use ccpp_kinds, only: kind_phys - use phys_vars_init_check_4D, only: phys_var_stdnames, input_var_names, std_name_len - use physics_types_4D, only: slp, theta + use pio, only: file_desc_t + use cam_abortutils, only: endrun + use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX + use physics_data, only: read_field, find_input_name_idx, no_exist_idx + use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx + use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties + use ccpp_kinds, only: kind_phys + use phys_vars_init_check_4D, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog + use physics_types_4D, only: slp, theta ! Dummy arguments type(file_desc_t), intent(inout) :: file @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 index f7b111bd..90c3e9b9 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_bvd, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_bad_vertdim, only: slp, theta ! Dummy arguments @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 index 8e6b39fc..c2520655 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 @@ -29,15 +29,18 @@ module physics_inputs_ddt CONTAINS subroutine physics_read_data(file, suite_names, timestep, read_initialized_variables) - use pio, only: file_desc_t - use cam_abortutils, only: endrun - use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX - use physics_data, only: read_field, find_input_name_idx, no_exist_idx - use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx - use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array - use ccpp_kinds, only: kind_phys - use phys_vars_init_check_ddt, only: phys_var_stdnames, input_var_names, std_name_len - use physics_types_ddt, only: phys_state, slp + use pio, only: file_desc_t + use cam_abortutils, only: endrun + use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX + use physics_data, only: read_field, find_input_name_idx, no_exist_idx + use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx + use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties + use ccpp_kinds, only: kind_phys + use phys_vars_init_check_ddt, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog + use physics_types_ddt, only: phys_state, slp ! Dummy arguments type(file_desc_t), intent(inout) :: file @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 index 0c5fcbb3..5f4ce25a 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_ddt2, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_ddt2, only: phys_state ! Dummy arguments @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 index f563a44a..e2548410 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 @@ -36,8 +36,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables use cam_ccpp_cap, only: cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_ddt_array, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_ddt_array, only: ix_theta, phys_state ! Dummy arguments @@ -65,6 +68,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -131,10 +143,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 index 84969562..84822f38 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 @@ -35,9 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables - use cam_ccpp_cap, only: cam_constituents_array + use cam_ccpp_cap, only: cam_constituents_array, cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_host_var, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_host_var, only: slp ! Dummy arguments @@ -65,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -131,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 index 47458e33..1883f425 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 @@ -29,16 +29,19 @@ module physics_inputs_mf CONTAINS subroutine physics_read_data(file, suite_names, timestep, read_initialized_variables) - use pio, only: file_desc_t - use cam_abortutils, only: endrun - use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX - use physics_data, only: read_field, find_input_name_idx, no_exist_idx - use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx - use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array - use ccpp_kinds, only: kind_phys - use phys_vars_init_check_mf, only: phys_var_stdnames, input_var_names, std_name_len - use ref_theta, only: theta - use physics_types_mf, only: slp + use pio, only: file_desc_t + use cam_abortutils, only: endrun + use shr_kind_mod, only: SHR_KIND_CS, SHR_KIND_CL, SHR_KIND_CX + use physics_data, only: read_field, find_input_name_idx, no_exist_idx + use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx + use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties + use ccpp_kinds, only: kind_phys + use phys_vars_init_check_mf, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog + use ref_theta, only: theta + use physics_types_mf, only: slp ! Dummy arguments type(file_desc_t), intent(inout) :: file @@ -65,6 +68,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -131,10 +143,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 index 49f3453c..af4292cb 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 @@ -35,9 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables - use cam_ccpp_cap, only: cam_constituents_array + use cam_ccpp_cap, only: cam_constituents_array, cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_no_horiz, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_no_horiz, only: slp, theta ! Dummy arguments @@ -65,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -131,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 index f398a22b..a2e47099 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_noreq, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog ! Dummy arguments type(file_desc_t), intent(inout) :: file @@ -63,6 +66,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -129,10 +141,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 index 83f6ef05..1e0082b5 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_param, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_param, only: g, slp, theta ! Dummy arguments @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 index cfc9417e..532ad9da 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 @@ -35,9 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables - use cam_ccpp_cap, only: cam_constituents_array + use cam_ccpp_cap, only: cam_constituents_array, cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_protect, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_protected, only: slp, theta ! Dummy arguments @@ -65,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -131,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 index b210038c..a2be48d6 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_scalar, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_scalar_var, only: slp, theta ! Dummy arguments @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: diff --git a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 index 2482391a..c29356c0 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 @@ -35,8 +35,11 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia use physics_data, only: read_field, find_input_name_idx, no_exist_idx use physics_data, only: init_mark_idx, prot_no_init_idx, const_idx use cam_ccpp_cap, only: ccpp_physics_suite_variables, cam_constituents_array + use cam_ccpp_cap, only: cam_model_const_properties use ccpp_kinds, only: kind_phys use phys_vars_init_check_simple, only: phys_var_stdnames, input_var_names, std_name_len + use ccpp_constituent_prop_mod, only: ccpp_constituent_prop_ptr_t + use cam_logfile, only: iulog use physics_types_simple, only: slp, theta ! Dummy arguments @@ -64,6 +67,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia character(len=2) :: sep2 !String separator used to print err messages character(len=2) :: sep3 !String separator used to print err messages real(kind=kind_phys), pointer :: field_data_ptr(:,:,:) + logical :: var_found !Bool to determine if consituent found in + ! data files + + ! Fields needed for getting default data value for constituents + type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) + real(kind=kind_phys) :: constituent_default_value + integer :: constituent_errflg + character(len=SHR_KIND_CX) :: constituent_errmsg + logical :: constituent_has_default ! Logical to default optional argument to False: logical :: use_init_variables @@ -130,10 +142,35 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia ! If an index was found in the constituent hash table, then read in the data ! to that index of the constituent array + var_found = .false. field_data_ptr => cam_constituents_array() call read_field(file, ccpp_required_data(req_idx), & [ccpp_required_data(req_idx)], 'lev', timestep, & - field_data_ptr(:,:,constituent_idx), mark_as_read=.false.) + field_data_ptr(:,:,constituent_idx), mark_as_read=.false., & + error_on_not_found=.false., var_found=var_found) + if(.not. var_found) then + const_props => cam_model_const_properties() + constituent_has_default = .false. + call const_props(constituent_idx)%has_default(constituent_has_default, & + constituent_errflg, constituent_errmsg) + if (constituent_has_default) then + call & + const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& + constituent_errmsg) + field_data_ptr(:,:,constituent_idx) = constituent_default_value + if (masterproc) then + write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & + ' initialized from file: ', constituent_default_value + end if + else + field_data_ptr(:,:,constituent_idx) = 0._kind_phys + if (masterproc) then + write(iulog,*) 'Constituent ', ccpp_required_data(req_idx), & + ' default value not configured. Setting to 0.' + end if + end if + end if + case default ! Read variable from IC file: From b7c8cede81c4e5c33746b46726cb52cb417e5378 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Mon, 24 Jul 2023 09:36:25 -0600 Subject: [PATCH 02/14] Updating errmsg length to be hard coded. --- src/data/write_init_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 667122e6..994b292c 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -868,7 +868,7 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:)", 2) outfile.write("real(kind=kind_phys) :: constituent_default_value", 2) outfile.write("integer :: constituent_errflg", 2) - outfile.write("character(len=SHR_KIND_CX) :: constituent_errmsg", 2) + outfile.write("character(len=512) :: constituent_errmsg", 2) outfile.write("logical :: constituent_has_default", 2) outfile.blank_line() outfile.comment("Logical to default optional argument to False:", 2) From 0c17824fd728df925fda636a9d936ef819fecc5e Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 25 Jul 2023 10:53:05 -0600 Subject: [PATCH 03/14] Fixing whitespace and ending model runtime on data error. --- src/data/write_init_files.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 994b292c..d2b282d0 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -966,8 +966,17 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("const_props => cam_model_const_properties()", 7) outfile.write("constituent_has_default = .false.", 7) outfile.write("call const_props(constituent_idx)%has_default(constituent_has_default, constituent_errflg, constituent_errmsg)", 7) + outfile.write("if (constituent_errflg .ne. 0) then", 7) + outfile.write("call endrun(constituent_errmsg)", 8) + outfile.write("end if", 7) outfile.write("if (constituent_has_default) then", 7) - outfile.write("call const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg, constituent_errmsg)", 8) + outfile.write("call const_props(constituent_idx)%default_value( &", 8) + outfile.write("constituent_default_value, &", 19) + outfile.write("constituent_errflg, & ", 19) + outfile.write("constituent_errmsg)", 19) + outfile.write("if (constituent_errflg .ne. 0) then", 8) + outfile.write("call endrun(constituent_errmsg)", 9) + outfile.write("end if", 8) outfile.write("field_data_ptr(:,:,constituent_idx) = constituent_default_value", 8) outfile.write("if (masterproc) then", 8) outfile.write("write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), ' initialized from file: ', constituent_default_value", 9) From 0cc6a5355d2df19b988c2d3818ce9bde2aed8f29 Mon Sep 17 00:00:00 2001 From: mwaxmonsky <137746677+mwaxmonsky@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:56:16 -0400 Subject: [PATCH 04/14] Update src/data/write_init_files.py Updating debug message from PR. Co-authored-by: Jesse Nusbaumer --- src/data/write_init_files.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index d2b282d0..1df9c52c 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -979,7 +979,7 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("end if", 8) outfile.write("field_data_ptr(:,:,constituent_idx) = constituent_default_value", 8) outfile.write("if (masterproc) then", 8) - outfile.write("write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), ' initialized from file: ', constituent_default_value", 9) + outfile.write("write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), ' initialized to default value: ', constituent_default_value", 9) outfile.write("end if", 8) outfile.write("else", 7) outfile.write("field_data_ptr(:,:,constituent_idx) = 0._kind_phys", 8) From f1ec6b120609f3abf35f7178ae141bca77b04c71 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 25 Jul 2023 13:28:48 -0600 Subject: [PATCH 05/14] Reverting manual line formatting changes to allow next formatting change to correctly handle ine length. --- src/data/write_init_files.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 1df9c52c..b2d6f634 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -970,10 +970,7 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("call endrun(constituent_errmsg)", 8) outfile.write("end if", 7) outfile.write("if (constituent_has_default) then", 7) - outfile.write("call const_props(constituent_idx)%default_value( &", 8) - outfile.write("constituent_default_value, &", 19) - outfile.write("constituent_errflg, & ", 19) - outfile.write("constituent_errmsg)", 19) + outfile.write("call const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg, constituent_errmsg)", 8) outfile.write("if (constituent_errflg .ne. 0) then", 8) outfile.write("call endrun(constituent_errmsg)", 9) outfile.write("end if", 8) From 3f400ec89242b049213c84d9ca37f5402d79b46b Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 25 Jul 2023 13:46:49 -0600 Subject: [PATCH 06/14] Updating write init files from python file update. --- .../write_init_files/physics_inputs_4D.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_bvd.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_ddt.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_ddt2.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_ddt_array.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_host_var.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_mf.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_no_horiz.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_noreq.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_param.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_protect.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_scalar.F90 | 10 ++++++++-- .../write_init_files/physics_inputs_simple.F90 | 10 ++++++++-- 13 files changed, 104 insertions(+), 26 deletions(-) diff --git a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 index e74d2a90..ace5eabf 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 index 90c3e9b9..04316ed7 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 index c2520655..25e77e2b 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 index 5f4ce25a..ef5db742 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 index e2548410..881184d4 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 @@ -75,7 +75,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -154,14 +154,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 index 84822f38..0c0e0827 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 index 1883f425..f90095d1 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 @@ -75,7 +75,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -154,14 +154,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 index af4292cb..9e40162a 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 index a2e47099..3d5bc4de 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 @@ -73,7 +73,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -152,14 +152,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 index 1e0082b5..d1d15748 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 index 532ad9da..7a376923 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 index a2be48d6..58bff3f1 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys diff --git a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 index c29356c0..d62b832b 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 @@ -74,7 +74,7 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia type(ccpp_constituent_prop_ptr_t), pointer :: const_props(:) real(kind=kind_phys) :: constituent_default_value integer :: constituent_errflg - character(len=SHR_KIND_CX) :: constituent_errmsg + character(len=512) :: constituent_errmsg logical :: constituent_has_default ! Logical to default optional argument to False: @@ -153,14 +153,20 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) + if (constituent_errflg .ne. 0) then + call endrun(constituent_errmsg) + end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then write(iulog,*) 'Consitituent ', ccpp_required_data(req_idx), & - ' initialized from file: ', constituent_default_value + ' initialized to default value: ', constituent_default_value end if else field_data_ptr(:,:,constituent_idx) = 0._kind_phys From 839047a9648e646718831a9790beab734d6fe398 Mon Sep 17 00:00:00 2001 From: mwaxmonsky <137746677+mwaxmonsky@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:01:49 -0400 Subject: [PATCH 07/14] Update src/data/write_init_files.py Updating not equal comparison to match current code style. Adding line number and file name to error message. Co-authored-by: Jesse Nusbaumer --- src/data/write_init_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index b2d6f634..4e90de17 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -966,8 +966,8 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("const_props => cam_model_const_properties()", 7) outfile.write("constituent_has_default = .false.", 7) outfile.write("call const_props(constituent_idx)%has_default(constituent_has_default, constituent_errflg, constituent_errmsg)", 7) - outfile.write("if (constituent_errflg .ne. 0) then", 7) - outfile.write("call endrun(constituent_errmsg)", 8) + outfile.write("if (constituent_errflg /= 0) then", 7) + outfile.write("call endrun(constituent_errmsg, file=__FILE__, line=__LINE__)", 8) outfile.write("end if", 7) outfile.write("if (constituent_has_default) then", 7) outfile.write("call const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg, constituent_errmsg)", 8) From 66e540dd4eb604c6f287948f9686de931a04ded1 Mon Sep 17 00:00:00 2001 From: mwaxmonsky <137746677+mwaxmonsky@users.noreply.github.com> Date: Tue, 1 Aug 2023 10:03:11 -0400 Subject: [PATCH 08/14] Update src/data/write_init_files.py Updating not equal comparison to match current code style. Adding line number and file name to error message. Co-authored-by: Jesse Nusbaumer --- src/data/write_init_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/data/write_init_files.py b/src/data/write_init_files.py index 4e90de17..1918a994 100644 --- a/src/data/write_init_files.py +++ b/src/data/write_init_files.py @@ -971,8 +971,8 @@ def write_phys_read_subroutine(outfile, host_dict, host_vars, host_imports, outfile.write("end if", 7) outfile.write("if (constituent_has_default) then", 7) outfile.write("call const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg, constituent_errmsg)", 8) - outfile.write("if (constituent_errflg .ne. 0) then", 8) - outfile.write("call endrun(constituent_errmsg)", 9) + outfile.write("if (constituent_errflg /= 0) then", 8) + outfile.write("call endrun(constituent_errmsg, file=__FILE__, line=__LINE__)", 9) outfile.write("end if", 8) outfile.write("field_data_ptr(:,:,constituent_idx) = constituent_default_value", 8) outfile.write("if (masterproc) then", 8) From 2b2e2a9d88101bd27349d71b3d84467b79be3474 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 1 Aug 2023 08:34:54 -0600 Subject: [PATCH 09/14] Updating reference sample files to reflect updates to fortran output. --- .../sample_files/write_init_files/physics_inputs_4D.F90 | 8 ++++---- .../sample_files/write_init_files/physics_inputs_bvd.F90 | 8 ++++---- .../sample_files/write_init_files/physics_inputs_ddt.F90 | 8 ++++---- .../sample_files/write_init_files/physics_inputs_ddt2.F90 | 8 ++++---- .../write_init_files/physics_inputs_ddt_array.F90 | 8 ++++---- .../write_init_files/physics_inputs_host_var.F90 | 8 ++++---- .../sample_files/write_init_files/physics_inputs_mf.F90 | 8 ++++---- .../write_init_files/physics_inputs_no_horiz.F90 | 8 ++++---- .../write_init_files/physics_inputs_noreq.F90 | 8 ++++---- .../write_init_files/physics_inputs_param.F90 | 8 ++++---- .../write_init_files/physics_inputs_protect.F90 | 8 ++++---- .../write_init_files/physics_inputs_scalar.F90 | 8 ++++---- .../write_init_files/physics_inputs_simple.F90 | 8 ++++---- 13 files changed, 52 insertions(+), 52 deletions(-) diff --git a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 index ace5eabf..bb1a327f 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_4D.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 index 04316ed7..d2ed56b7 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_bvd.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 index 25e77e2b..33cbbd8d 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 index ef5db742..20245ac4 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt2.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 index 881184d4..6e948e09 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_ddt_array.F90 @@ -154,15 +154,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 index 0c0e0827..8e819e3d 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_host_var.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 index f90095d1..c64bd92a 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_mf.F90 @@ -154,15 +154,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 index 9e40162a..bfd6fde4 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_no_horiz.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 index 3d5bc4de..8b23f945 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_noreq.F90 @@ -152,15 +152,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 index d1d15748..11686cfd 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_param.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_param.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 index 7a376923..d1b12beb 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_protect.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 index 58bff3f1..b6862cf5 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_scalar.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then diff --git a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 index d62b832b..22e69a7d 100644 --- a/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 +++ b/test/unit/sample_files/write_init_files/physics_inputs_simple.F90 @@ -153,15 +153,15 @@ subroutine physics_read_data(file, suite_names, timestep, read_initialized_varia constituent_has_default = .false. call const_props(constituent_idx)%has_default(constituent_has_default, & constituent_errflg, constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if if (constituent_has_default) then call & const_props(constituent_idx)%default_value(constituent_default_value, constituent_errflg,& constituent_errmsg) - if (constituent_errflg .ne. 0) then - call endrun(constituent_errmsg) + if (constituent_errflg /= 0) then + call endrun(constituent_errmsg, file=__FILE__, line=__LINE__) end if field_data_ptr(:,:,constituent_idx) = constituent_default_value if (masterproc) then From cd7cf8a76d191b0aeb6bf3b590048ab05fdfe5aa Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Wed, 16 Aug 2023 09:38:55 -0400 Subject: [PATCH 10/14] Updating error message. --- src/physics/utils/physics_data.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index 87838303..e26f20b2 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -205,7 +205,7 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re end if else if (.not. error_on_not_found_local) then if (masterproc) then - write(iulog, *) 'Var not found AND not failing when not found reading ', trim(arr2str(var_names)), ' and ', trim(std_name) + write(iulog, *) trim(std_name), ' not found, also looked for: ', trim(arr2str(var_names)) call shr_sys_flush(iulog) end if else @@ -298,7 +298,7 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & end if else if (.not. error_on_not_found_local) then if (masterproc) then - write(iulog, *) 'Var not found AND not failing when not found reading ', trim(arr2str(var_names)), ' and ', trim(std_name) + write(iulog, *) trim(std_name), ' not found, also looked for: ', trim(arr2str(var_names)) call shr_sys_flush(iulog) end if else From 97379fd7e74d3bed30150ee5c3feafb35ccfcb35 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Mon, 21 Aug 2023 09:52:51 -0400 Subject: [PATCH 11/14] Adding optional variable comments. --- src/physics/utils/physics_data.F90 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index e26f20b2..dc7c2f1b 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -155,9 +155,9 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re character(len=*), intent(in) :: var_names(:) ! var name on file integer, intent(in) :: timestep real(kind_phys), intent(inout) :: buffer(:) - logical, optional, intent(in) :: mark_as_read - logical, optional, intent(in) :: error_on_not_found - logical, optional, intent(out) :: var_found + logical, optional, intent(in) :: mark_as_read ! Mark field as read if found + logical, optional, intent(in) :: error_on_not_found ! Flag to error and exit if not found + logical, optional, intent(out) :: var_found ! Flag to mark variable was found ! Local variables logical :: mark_as_read_local logical :: error_on_not_found_local @@ -239,9 +239,9 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & character(len=*), intent(in) :: vcoord_name integer, intent(in) :: timestep real(kind_phys), intent(inout) :: buffer(:,:) - logical, optional, intent(in) :: mark_as_read - logical, optional, intent(in) :: error_on_not_found - logical, optional, intent(out) :: var_found + logical, optional, intent(in) :: mark_as_read ! Mark field as read if found + logical, optional, intent(in) :: error_on_not_found ! Flag to error and exit if not found + logical, optional, intent(out) :: var_found ! Flag to mark variable was found ! Local variables logical :: mark_as_read_local logical :: error_on_not_found_local From fd959dffb3b1f52635de47fc72ce46947cf63570 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Mon, 21 Aug 2023 10:46:38 -0400 Subject: [PATCH 12/14] Updating error messages. --- src/physics/utils/physics_data.F90 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index dc7c2f1b..7b947434 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -201,7 +201,9 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Mismatch variable found in '//arr2str(var_names)) + call endrun(subname//'Unable to properly check the found variable "',trim(found_name),'" in the IC file. ' & + 'Please double-check if the variable exists in the file, ' & + 'and that the file is not corrupted or damaged.') end if else if (.not. error_on_not_found_local) then if (masterproc) then @@ -294,7 +296,9 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Mismatch variable found in '//trim(std_name)) + call endrun(subname//'Unable to properly check the found variable "',trim(found_name),'" in the IC file. ' & + 'Please double-check if the variable exists in the file, ' & + 'and that the file is not corrupted or damaged.') end if else if (.not. error_on_not_found_local) then if (masterproc) then From 7b5c375af842ee9d32f5c28fe48e26d0728d97a7 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 22 Aug 2023 00:06:25 -0600 Subject: [PATCH 13/14] Fix compiler errors for error message formatting. --- src/physics/utils/physics_data.F90 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index 7b947434..61f51ca0 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -201,8 +201,8 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Unable to properly check the found variable "',trim(found_name),'" in the IC file. ' & - 'Please double-check if the variable exists in the file, ' & + call endrun(subname//'Unable to properly check the found variable "'//trim(found_name)//'" in the IC file. '// & + 'Please double-check if the variable exists in the file, '// & 'and that the file is not corrupted or damaged.') end if else if (.not. error_on_not_found_local) then @@ -296,8 +296,8 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Unable to properly check the found variable "',trim(found_name),'" in the IC file. ' & - 'Please double-check if the variable exists in the file, ' & + call endrun(subname//'Unable to properly check the found variable "'//trim(found_name)//'" in the IC file. '// & + 'Please double-check if the variable exists in the file, '// & 'and that the file is not corrupted or damaged.') end if else if (.not. error_on_not_found_local) then From 3381e151cf36ef2bcd52cc987cbab9f95e8ec663 Mon Sep 17 00:00:00 2001 From: Michael Waxmonsky Date: Tue, 22 Aug 2023 17:30:47 -0600 Subject: [PATCH 14/14] Fixing string formatting for error message. --- src/physics/utils/physics_data.F90 | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/physics/utils/physics_data.F90 b/src/physics/utils/physics_data.F90 index 61f51ca0..1aa6f54e 100644 --- a/src/physics/utils/physics_data.F90 +++ b/src/physics/utils/physics_data.F90 @@ -1,6 +1,7 @@ module physics_data use ccpp_kinds, only: kind_phys + use shr_kind_mod, only: cl=>shr_kind_cl implicit none private @@ -165,6 +166,7 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re character(len=std_name_len) :: found_name type(var_desc_t) :: vardesc character(len=*), parameter :: subname = 'read_field_2d: ' + character(len=cl) :: strerr if (present(mark_as_read)) then mark_as_read_local = mark_as_read @@ -201,9 +203,9 @@ subroutine read_field_2d(file, std_name, var_names, timestep, buffer, mark_as_re varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Unable to properly check the found variable "'//trim(found_name)//'" in the IC file. '// & - 'Please double-check if the variable exists in the file, '// & - 'and that the file is not corrupted or damaged.') + write(strerr,*) subname//'Unable to properly check the found variable "', trim(found_name), '" in the IC file. & + &Please double-check if the variable exists in the file and that the file is not corrupted or damaged.' + call endrun(strerr) end if else if (.not. error_on_not_found_local) then if (masterproc) then @@ -252,6 +254,7 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & character(len=std_name_len) :: found_name type(var_desc_t) :: vardesc character(len=*), parameter :: subname = 'read_field_3d: ' + character(len=cl) :: strerr if (present(mark_as_read)) then mark_as_read_local = mark_as_read @@ -291,14 +294,15 @@ subroutine read_field_3d(file, std_name, var_names, vcoord_name, & if (mark_as_read_local) then call mark_as_read_from_file(std_name) end if + if (var_found_local) then call shr_assert_in_domain(buffer, is_nan=.false., & varname=trim(found_name), & msg=subname//'NaN found in '//trim(found_name)) else - call endrun(subname//'Unable to properly check the found variable "'//trim(found_name)//'" in the IC file. '// & - 'Please double-check if the variable exists in the file, '// & - 'and that the file is not corrupted or damaged.') + write(strerr,*) subname//'Unable to properly check the found variable "', trim(found_name), '" in the IC file. & + &Please double-check if the variable exists in the file and that the file is not corrupted or damaged.' + call endrun(strerr) end if else if (.not. error_on_not_found_local) then if (masterproc) then