From 48109ca6f3c82eefa946d3a6dabad25193a03f01 Mon Sep 17 00:00:00 2001 From: "larissa.reames@noaa.gov" Date: Fri, 8 Mar 2024 17:43:57 +0000 Subject: [PATCH 1/2] chgres_cube: Added a check at orogoraphy data read for incompatible, old static data. Program successfully errors when used with incompatible data. --- sorc/chgres_cube.fd/static_data.F90 | 86 ++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 20 deletions(-) diff --git a/sorc/chgres_cube.fd/static_data.F90 b/sorc/chgres_cube.fd/static_data.F90 index e95756c6c..bb4445722 100644 --- a/sorc/chgres_cube.fd/static_data.F90 +++ b/sorc/chgres_cube.fd/static_data.F90 @@ -15,8 +15,8 @@ module static_data use esmf use utilities, only : error_handler, netcdf_err - - implicit none + +implicit none private @@ -49,6 +49,7 @@ module static_data subroutine get_static_fields(localpet) use model_grid, only : num_tiles_target_grid, & + land_frac_target_grid, & i_target, j_target implicit none @@ -60,11 +61,13 @@ subroutine get_static_fields(localpet) real(esmf_kind_r8), allocatable :: data_one_tile(:,:) real(esmf_kind_r8), allocatable :: max_data_one_tile(:,:) real(esmf_kind_r8), allocatable :: min_data_one_tile(:,:) - + real(esmf_kind_r8), allocatable :: land_frac_target_tile(:,:) if (localpet==0) then allocate(data_one_tile(i_target,j_target)) + allocate(land_frac_target_tile(i_target,j_target)) else allocate(data_one_tile(0,0)) + allocate(land_frac_target_tile(0,0)) endif call create_static_fields @@ -74,8 +77,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('slope_type', i_target, j_target, tile, data_one_tile) + call read_static_file('slope_type', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID SLOPE TYPE." call ESMF_FieldScatter(slope_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -88,8 +94,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('maximum_snow_albedo', i_target, j_target, tile, data_one_tile) + call read_static_file('maximum_snow_albedo', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID MAXIMUM SNOW ALBEDO." call ESMF_FieldScatter(mxsno_albedo_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -102,8 +111,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('soil_type', i_target, j_target, tile, data_one_tile) + call read_static_file('soil_type', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID SOIL TYPE." call ESMF_FieldScatter(soil_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -116,8 +128,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('vegetation_type', i_target, j_target, tile, data_one_tile) + call read_static_file('vegetation_type', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID VEGETATION TYPE." call ESMF_FieldScatter(veg_type_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -138,9 +153,12 @@ subroutine get_static_fields(localpet) endif do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then call read_static_file('vegetation_greenness', i_target, j_target, tile, data_one_tile, & - max_data_one_tile, min_data_one_tile) + land_frac_target_tile, max_data_one_tile, min_data_one_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID VEGETATION GREENNESS." call ESMF_FieldScatter(veg_greenness_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -163,8 +181,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('substrate_temperature', i_target, j_target, tile, data_one_tile) + call read_static_file('substrate_temperature', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID SUBSTRATE TEMPERATURE." call ESMF_FieldScatter(substrate_temp_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -177,8 +198,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('visible_black_sky_albedo', i_target, j_target, tile, data_one_tile) + call read_static_file('visible_black_sky_albedo', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID ALVSF." call ESMF_FieldScatter(alvsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -187,8 +211,11 @@ subroutine get_static_fields(localpet) enddo do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('visible_white_sky_albedo', i_target, j_target, tile, data_one_tile) + call read_static_file('visible_white_sky_albedo', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID ALVWF." call ESMF_FieldScatter(alvwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -197,8 +224,11 @@ subroutine get_static_fields(localpet) enddo do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('near_IR_black_sky_albedo', i_target, j_target, tile, data_one_tile) + call read_static_file('near_IR_black_sky_albedo', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID ALNSF." call ESMF_FieldScatter(alnsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -207,8 +237,11 @@ subroutine get_static_fields(localpet) enddo do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('near_IR_white_sky_albedo', i_target, j_target, tile, data_one_tile) + call read_static_file('near_IR_white_sky_albedo', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID ALNWF." call ESMF_FieldScatter(alnwf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -221,8 +254,11 @@ subroutine get_static_fields(localpet) !------------------------------------------------------------------------------ do tile = 1, num_tiles_target_grid + call ESMF_FieldGather(land_frac_target_grid, land_frac_target_tile, rootPet=0,tile=tile, rc=error) + if(ESMF_logFoundError(rcToCheck=error,msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__))& + call error_handler("IN FieldGather", error) if (localpet == 0) then - call read_static_file('facsf', i_target, j_target, tile, data_one_tile) + call read_static_file('facsf', i_target, j_target, tile, data_one_tile, land_frac_target_tile) endif print*,"- CALL FieldScatter FOR TARGET GRID FACSF." call ESMF_FieldScatter(facsf_target_grid, data_one_tile, rootpet=0, tile=tile, rc=error) @@ -259,11 +295,11 @@ end subroutine get_static_fields !! yearly value on the tile !! @author George Gayno NCEP/EMC subroutine read_static_file(field, i_target, j_target, tile, & - data_one_tile, max_data_one_tile, & + data_one_tile, land_frac, max_data_one_tile, & min_data_one_tile) use netcdf - use model_grid, only : tiles_target_grid + use model_grid, only : tiles_target_grid, land_frac_target_grid use program_setup, only : fix_dir_target_grid, cres_target_grid, & cycle_mon, cycle_day, cycle_hour @@ -271,10 +307,11 @@ subroutine read_static_file(field, i_target, j_target, tile, & character(len=*), intent(in) :: field character(len=100) :: filename - character(len=500) :: the_file + character(len=500) :: the_file, err_msg integer, intent(in) :: i_target, j_target, tile + real(esmf_kind_r8), intent(in) :: land_frac(i_target,j_target) real(esmf_kind_r8), intent(out) :: data_one_tile(i_target,j_target) real(esmf_kind_r8), intent(out), optional :: max_data_one_tile(i_target,j_target) real(esmf_kind_r8), intent(out), optional :: min_data_one_tile(i_target,j_target) @@ -289,6 +326,8 @@ subroutine read_static_file(field, i_target, j_target, tile, & real(esmf_kind_r8) :: num_days, num_days_rec1, rinc(5) real(esmf_kind_r8) :: weight_rec1, weight_rec2 + real(esmf_kind_r8), allocatable :: land_frac_target_tile(:,:) + if (trim(field) == 'facsf') filename = "/" // trim(cres_target_grid) // ".facsf." // trim(tiles_target_grid(tile)) // ".nc" if (trim(field) == 'maximum_snow_albedo') filename = "/" // trim(cres_target_grid) // ".maximum_snow_albedo." // trim(tiles_target_grid(tile)) // ".nc" if (trim(field) == 'slope_type') filename = "/" // trim(cres_target_grid) // ".slope_type." // trim(tiles_target_grid(tile)) // ".nc" @@ -370,9 +409,16 @@ subroutine read_static_file(field, i_target, j_target, tile, & deallocate(days_since) else ! file contains only one time record - - data_one_tile = dummy(:,:,1) - + + do j = 1, j_target + do i = 1, i_target + if(land_frac(i,j) > 0.0 .and. dummy(i,j,1) == -999) then + err_msg = "Detected missing data point in " // trim(filename) // ". Static data may be outdated. Please use static data created with the latest UFS_UTILS release that supports fractional land coverage" + call error_handler(err_msg,-1) + endif + data_one_tile(i,j) = dummy(i,j,1) + enddo + enddo endif if (trim(field) == 'vegetation_greenness') then From 5c99fb691a7915d094db715dbde9b92eba98b85f Mon Sep 17 00:00:00 2001 From: "larissa.reames@noaa.gov" Date: Fri, 15 Mar 2024 21:45:53 +0000 Subject: [PATCH 2/2] Removed extraneous arrays. Added appropriate doxygen documentation. --- sorc/chgres_cube.fd/static_data.F90 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sorc/chgres_cube.fd/static_data.F90 b/sorc/chgres_cube.fd/static_data.F90 index bb4445722..0de2b2af9 100644 --- a/sorc/chgres_cube.fd/static_data.F90 +++ b/sorc/chgres_cube.fd/static_data.F90 @@ -288,6 +288,7 @@ end subroutine get_static_fields !! @param[in] i_target the "i" dimension of the target model tile !! @param[in] j_target the "j" dimension of the target model tile !! @param[in] tile the tile number of be processed +!! @param[in] land_frac landcover fraction on the target model tile !! @param[out] data_one_tile the processed surface data on the tile !! @param[out] max_data_one_tile for fields with multiple time periods, the max !! yearly value on the tile @@ -299,7 +300,7 @@ subroutine read_static_file(field, i_target, j_target, tile, & min_data_one_tile) use netcdf - use model_grid, only : tiles_target_grid, land_frac_target_grid + use model_grid, only : tiles_target_grid use program_setup, only : fix_dir_target_grid, cres_target_grid, & cycle_mon, cycle_day, cycle_hour @@ -326,8 +327,6 @@ subroutine read_static_file(field, i_target, j_target, tile, & real(esmf_kind_r8) :: num_days, num_days_rec1, rinc(5) real(esmf_kind_r8) :: weight_rec1, weight_rec2 - real(esmf_kind_r8), allocatable :: land_frac_target_tile(:,:) - if (trim(field) == 'facsf') filename = "/" // trim(cres_target_grid) // ".facsf." // trim(tiles_target_grid(tile)) // ".nc" if (trim(field) == 'maximum_snow_albedo') filename = "/" // trim(cres_target_grid) // ".maximum_snow_albedo." // trim(tiles_target_grid(tile)) // ".nc" if (trim(field) == 'slope_type') filename = "/" // trim(cres_target_grid) // ".slope_type." // trim(tiles_target_grid(tile)) // ".nc"