Skip to content

Commit 9f781a1

Browse files
committed
Clean-up missing file code/test.
1 parent ee897bb commit 9f781a1

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

src/physics/utils/pio_reader.F90

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,14 @@ subroutine open_netcdf_file(this, file_path, errmsg, errcode)
7070
return
7171
end if
7272

73-
!if(file_path == 'UNSET_PATH') then
74-
! errcode = 1
75-
! errmsg = "Found UNSET_PATH trying to open file"
76-
! return
77-
!end if
78-
7973
!Open provided file with PIO:
80-
call cam_pio_openfile(this%sima_pio_fh%pio_fh, file_path, PIO_NOWRITE, errcode=errcode)
74+
call cam_pio_openfile(this%sima_pio_fh%pio_fh, file_path, PIO_NOWRITE, &
75+
errcode=errcode)
8176

8277
if(errcode /= PIO_NOERR) then
8378
!Extract error message from PIO and return:
84-
call get_pio_errmsg(pio_inq_var_info_err, file_path, errcode, errmsg)
79+
call get_pio_errmsg(1, file_path, errcode, errmsg, &
80+
file_msg=.true.)
8581
return
8682
end if
8783

@@ -2785,7 +2781,7 @@ subroutine get_netcdf_var_char_5d(this, varname, var, errmsg, errcode)
27852781
errmsg = ''
27862782
end subroutine get_netcdf_var_char_5d
27872783

2788-
subroutine get_pio_errmsg(caller_errcode, varname, errcode, errmsg)
2784+
subroutine get_pio_errmsg(caller_errcode, varname, errcode, errmsg, file_msg)
27892785
!Set error message based off PIO error code,
27902786
!and then reset PIO error code to caller-specified
27912787
!error code.
@@ -2799,21 +2795,36 @@ subroutine get_pio_errmsg(caller_errcode, varname, errcode, errmsg)
27992795
use pio, only: PIO_NOERR
28002796

28012797
!Input/output arguments:
2802-
integer, intent(in) :: caller_errcode !New error code caller wants.
2803-
character(len=*), intent(in) :: varname
2804-
integer, intent(inout) :: errcode !Error code
2805-
character(len=*), intent(inout) :: errmsg !Error message
2798+
integer, intent(in) :: caller_errcode !New error code caller wants.
2799+
character(len=*), intent(in) :: varname
2800+
integer, intent(inout) :: errcode !Error code
2801+
character(len=*), intent(inout) :: errmsg !Error message
2802+
logical, optional, intent(in) :: file_msg !If true then error is for file.
28062803

28072804
!Local variables:
28082805
integer :: strerr !Error code returned if pio_strerror fails
28092806
character(len=256) :: pio_error
2807+
logical :: file_msg_flag
28102808

2809+
!Check if error is for a file instead of a variable:
2810+
if (present(file_msg)) then
2811+
file_msg_flag = file_msg
2812+
else
2813+
file_msg_flag = .false.
2814+
end if
2815+
2816+
!Get error message from PIO:
28112817
strerr = pio_strerror(errcode, pio_error)
2812-
write(errmsg, '(a,a,a,a)') 'Error for variable "', varname, '" - message: ', trim(pio_error)
28132818
if(strerr /= PIO_NOERR) then
28142819
write(errmsg, *) "Failed to get error message for PIO code: ", errcode
28152820
errcode = pio_get_msg_err
28162821
else
2822+
if (file_msg_flag) then
2823+
write(errmsg, '(a,a,a,a)') "Error for file '", varname, "' - message: ", trim(pio_error)
2824+
else
2825+
!Variable error message
2826+
write(errmsg, '(a,a,a,a)') "Error for variable '", varname, "' - message: ", trim(pio_error)
2827+
end if
28172828
errcode = caller_errcode
28182829
end if
28192830
end subroutine get_pio_errmsg

src/utils/cam_pio_utils.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ subroutine cam_pio_openfile(file, fname, mode, log_info, errcode)
12841284
! If an error code is present, make sure PIO returns an error
12851285
! instead of aborting:
12861286
if (present(errcode)) then
1287-
call pio_seterrorhandling(file, PIO_BCAST_ERROR, &
1287+
call pio_seterrorhandling(pio_subsystem, PIO_BCAST_ERROR, &
12881288
oldmethod=err_handling)
12891289
end if
12901290

@@ -1309,7 +1309,7 @@ subroutine cam_pio_openfile(file, fname, mode, log_info, errcode)
13091309
! the error handling back to whatever was
13101310
! running before this routine:
13111311
if (present(errcode)) then
1312-
call pio_seterrorhandling(file, err_handling)
1312+
call pio_seterrorhandling(pio_subsystem, err_handling)
13131313
end if
13141314

13151315
end subroutine cam_pio_openfile

test/unit/fortran/src/mock_routines/test_pio_reader.pf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ subroutine test_pio_reader_already_opened_file_err()
8383
! File name for testing:
8484
! NOTE: This specific file is added during the Github Actions workflow.
8585
character(len=*), parameter :: fname = &
86-
'../../../rrtmgp-data/rrtmgp-gas-sw-g112.nc'
86+
"../../../rrtmgp-data/rrtmgp-gas-sw-g112.nc"
8787

8888
! Expected error message:
8989
character(len=*), parameter :: expected_err_msg = &
@@ -134,11 +134,11 @@ subroutine test_pio_reader_no_file_err()
134134
! File name for testing
135135
! NOTE: This file does not actually exist.
136136
character(len=*), parameter :: fname = &
137-
'glinda_the_good.nc'
137+
"glinda_the_good.nc"
138138

139139
! Expected error message:
140140
character(len=*), parameter :: expected_err_msg = &
141-
"Error opening file '"//fname//"': No such file or directory"
141+
"Error for file '"//fname//"' - message: No such file or directory"
142142

143143
! Begin test:
144144

@@ -152,8 +152,8 @@ subroutine test_pio_reader_no_file_err()
152152
write(*,*) "Error message: ", trim(errmsg)
153153

154154
! Check that the correct error was raised:
155-
@assertTrue(errcode /= PIO_NOERR)
156-
!@assertTrue(trim(errmsg) == expected_err_msg)
155+
@assertTrue(errcode /= 0)
156+
@assertTrue(trim(errmsg) == expected_err_msg)
157157

158158
! Perform test cleanup:
159159
deallocate(reader)

test/unit/fortran/utils/cam_pio_utils.F90

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ subroutine cam_pio_openfile(file, fname, mode, log_info, errcode)
5858
! If an error code is present, make sure PIO returns an error
5959
! instead of aborting:
6060
if (present(errcode)) then
61-
call pio_seterrorhandling(pio_system, PIO_BCAST_ERROR) !, oldmethod=err_handling)
61+
call pio_seterrorhandling(pio_system, PIO_BCAST_ERROR, &
62+
oldmethod=err_handling)
6263
end if
6364

6465
ierr = pio_openfile(pio_system, file, pio_iotype_netcdf, fname, mode)
@@ -80,9 +81,9 @@ subroutine cam_pio_openfile(file, fname, mode, log_info, errcode)
8081
! If an error code is requested, then set
8182
! the error handling back to whatever was
8283
! running before this routine:
83-
!if (present(errcode)) then
84-
!call pio_seterrorhandling(file, err_handling)
85-
!end if
84+
if (present(errcode)) then
85+
call pio_seterrorhandling(pio_system, err_handling)
86+
end if
8687

8788
end subroutine cam_pio_openfile
8889
!===========================================================================

0 commit comments

Comments
 (0)