@@ -70,18 +70,14 @@ subroutine open_netcdf_file(this, file_path, errmsg, errcode)
70
70
return
71
71
end if
72
72
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
-
79
73
! 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)
81
76
82
77
if (errcode /= PIO_NOERR) then
83
78
! 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. )
85
81
return
86
82
end if
87
83
@@ -2785,7 +2781,7 @@ subroutine get_netcdf_var_char_5d(this, varname, var, errmsg, errcode)
2785
2781
errmsg = ' '
2786
2782
end subroutine get_netcdf_var_char_5d
2787
2783
2788
- subroutine get_pio_errmsg (caller_errcode , varname , errcode , errmsg )
2784
+ subroutine get_pio_errmsg (caller_errcode , varname , errcode , errmsg , file_msg )
2789
2785
! Set error message based off PIO error code,
2790
2786
! and then reset PIO error code to caller-specified
2791
2787
! error code.
@@ -2799,21 +2795,36 @@ subroutine get_pio_errmsg(caller_errcode, varname, errcode, errmsg)
2799
2795
use pio, only: PIO_NOERR
2800
2796
2801
2797
! 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.
2806
2803
2807
2804
! Local variables:
2808
2805
integer :: strerr ! Error code returned if pio_strerror fails
2809
2806
character (len= 256 ) :: pio_error
2807
+ logical :: file_msg_flag
2810
2808
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:
2811
2817
strerr = pio_strerror(errcode, pio_error)
2812
- write (errmsg, ' (a,a,a,a)' ) ' Error for variable "' , varname, ' " - message: ' , trim (pio_error)
2813
2818
if (strerr /= PIO_NOERR) then
2814
2819
write (errmsg, * ) " Failed to get error message for PIO code: " , errcode
2815
2820
errcode = pio_get_msg_err
2816
2821
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
2817
2828
errcode = caller_errcode
2818
2829
end if
2819
2830
end subroutine get_pio_errmsg
0 commit comments