forked from ufs-community/UFS_UTILS
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate the namelist read routine and netcdf error
routines into their own library. Write a unit test for the namelist read routine. Fixes ufs-community#944.
- Loading branch information
George Gayno
committed
Sep 26, 2024
1 parent
a3237fb
commit e17b8d8
Showing
8 changed files
with
111 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
!> Read program namelist. | ||
!! | ||
!! @param[out] ocean_mask_dir Directory containing MOM6 ocean mask file. | ||
!! @param[out] lake_mask_dir Directory containing the lake mask file. | ||
!! @param[out] out_dir Directory where output file will be written. | ||
!! @param[out] atmres Atmosphere grid resolution. | ||
!! @param[out] ocnres Ocean grid resolution. | ||
!! @param[out] binary_lake or fractional lake | ||
!! @author Rahul Mahajan | ||
!! @author Sanath Kumar | ||
subroutine read_nml(ocean_mask_dir, lake_mask_dir, atmres,ocnres,out_dir,binary_lake) | ||
|
||
integer :: unit=7, io_status | ||
|
||
character(len=120), intent(out) :: ocean_mask_dir | ||
character(len=120), intent(out) :: lake_mask_dir | ||
character(len=120), intent(out) :: out_dir | ||
character(len=10), intent(out) :: atmres,ocnres | ||
integer, intent(out):: binary_lake | ||
|
||
namelist/mask_nml/ocean_mask_dir, lake_mask_dir, atmres, ocnres,out_dir,binary_lake | ||
open(unit=unit, file='input.nml', iostat=io_status ) | ||
read(unit,mask_nml, iostat=io_status ) | ||
close(unit) | ||
if (io_status > 0) then | ||
print *,'Error reading input.nml' | ||
call handle_err(-1) | ||
end if | ||
end subroutine read_nml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
!> Handle netCDF errors. | ||
!! | ||
!! @param[in] ret NetCDF return code. | ||
!! @author Shan Sun | ||
subroutine handle_err (ret) | ||
use netcdf | ||
integer, intent(in) :: ret | ||
|
||
if (ret /= NF90_NOERR) then | ||
write(6,*) nf90_strerror (ret) | ||
stop 999 | ||
end if | ||
end subroutine handle_err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# This is the cmake build file for the tests directory of the | ||
# UFS_UTILS project. | ||
# | ||
# George Gayno | ||
|
||
if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$") | ||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -r8 -assume byterecl") | ||
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$") | ||
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -ffree-line-length-0 -fdefault-real-8") | ||
endif() | ||
|
||
# Copy necessary test files from the source data directory to the | ||
# build data directory. | ||
|
||
execute_process( COMMAND ${CMAKE_COMMAND} -E copy | ||
${CMAKE_CURRENT_SOURCE_DIR}/data/input.nml ${CMAKE_CURRENT_BINARY_DIR}/input.nml) | ||
|
||
add_executable(ftst_read_nml ftst_read_nml.F90) | ||
target_link_libraries(ftst_read_nml om_lib) | ||
|
||
add_test(NAME ocean_merge-ftst_read_nml COMMAND ftst_read_nml) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
&mask_nml | ||
ocean_mask_dir="/ocean/mask/dir" | ||
ocnres="mx025" | ||
lake_mask_dir="/lake/mask/dir" | ||
atmres="C96" | ||
out_dir="/out/dir" | ||
binary_lake=1 | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
! Unit test for the read_nml routine. | ||
|
||
program read_namelist | ||
|
||
implicit none | ||
|
||
character(len=120) :: ocean_mask_dir | ||
character(len=120) :: lake_mask_dir | ||
character(len=120) :: out_dir | ||
character(len=10) :: atmres,ocnres | ||
|
||
integer :: binary_lake | ||
|
||
print*,"Call routine read_nml." | ||
|
||
call read_nml(ocean_mask_dir, lake_mask_dir, atmres,ocnres,out_dir,binary_lake) | ||
|
||
if (trim(ocean_mask_dir) /= "/ocean/mask/dir") stop 2 | ||
if (trim(lake_mask_dir) /= "/lake/mask/dir") stop 4 | ||
if (trim(atmres) /= "C96") stop 6 | ||
if (trim(ocnres) /= "mx025") stop 8 | ||
if (trim(out_dir) /= "/out/dir") stop 8 | ||
if (binary_lake /= 1) stop 10 | ||
|
||
print*, "OK" | ||
|
||
print*, "SUCCESS!" | ||
|
||
end program read_namelist |