FV3 Bundle
ncdr_check.f90
Go to the documentation of this file.
1 module ncdr_check
2  use ncd_kinds, only: i_long
3  use ncdr_climsg, only: ncdr_error
5  use netcdf, only: nf90_noerr, nf90_strerror, nf90_inquire, &
6  nf90_ebadid
7 
8  implicit none
9 
10  contains
11  subroutine ncdr_check_ncdr_id(file_ncdr_id)
12  integer(i_long), intent(in) :: file_ncdr_id
13 
14  if (file_ncdr_id > ncdr_file_count) &
15  call ncdr_error("The specified NCDR ID does not exist and/or is already closed!")
16 
17  if (.NOT. ncdr_files(file_ncdr_id)%file_open) &
18  call ncdr_error("The specified NCDR ID does not exist or is already closed! (Still in DB, but closed!)")
19  end subroutine ncdr_check_ncdr_id
20 
22  if (current_ncdr_id == -1) &
23  call ncdr_error("Current NCDR ID indicates that no files are open.")
25  end subroutine ncdr_check_current_ncdr_id
26 
27  subroutine ncdr_check_ncid(file_ncid)
28  integer(i_long), intent(in) :: file_ncid
29  integer(i_long) :: nc_err
30 
31  nc_err = nf90_inquire(file_ncid)
32 
33  if (nc_err == nf90_ebadid) &
34  call ncdr_error("The specified NCID does not exist and/or is already closed!")
35 
36  ! General error - something we can't handle!
37  if (nc_err /= nf90_noerr) &
38  call ncdr_nc_check(nc_err)
39  end subroutine ncdr_check_ncid
40 
41  subroutine ncdr_check_current_ncid
44  end subroutine ncdr_check_current_ncid
45 
46  function nc_diag_read_get_index_from_ncid(file_ncid) result(file_ind)
47  integer(i_long), intent(in) :: file_ncid
48  integer(i_long) :: i, file_ind
49 
50  if (ncdr_file_count == 0) then
51  file_ind = -1
52  return
53  end if
54 
55  do i = 1, ncdr_file_count
56  if ((file_ncid == ncdr_files(i)%ncid) .AND. (ncdr_files(i)%file_open)) then
57  file_ind = i
58  return
59  end if
60  end do
61 
62  file_ind = -1
64 
65  function nc_diag_read_get_index_from_filename(file_name) result(file_ind)
66  character(len=*), intent(in) :: file_name
67  integer(i_long) :: i, file_ind
68 
69  if (ncdr_file_count == 0) then
70  file_ind = -1
71  return
72  end if
73 
74  do i = 1, ncdr_file_count
75  if ((file_name == ncdr_files(i)%filename) .AND. (ncdr_files(i)%file_open)) then
76  file_ind = i
77  return
78  end if
79  end do
80 
81  file_ind = -1
83 
84  subroutine ncdr_nc_check(status)
85  integer(i_long), intent ( in) :: status
86 
87  if(status /= nf90_noerr) then
88  call ncdr_error(trim(nf90_strerror(status)))
89  end if
90  end subroutine ncdr_nc_check
91 end module ncdr_check
integer, parameter, public i_long
Definition: ncd_kinds.F90:47
subroutine ncdr_nc_check(status)
Definition: ncdr_check.f90:85
integer(i_long) current_ncdr_id
Definition: ncdr_state.f90:7
type(ncdr_file), dimension(:), allocatable ncdr_files
Definition: ncdr_state.f90:14
subroutine ncdr_check_current_ncdr_id
Definition: ncdr_check.f90:22
subroutine ncdr_check_ncid(file_ncid)
Definition: ncdr_check.f90:28
subroutine ncdr_check_ncdr_id(file_ncdr_id)
Definition: ncdr_check.f90:12
integer(i_long) function nc_diag_read_get_index_from_filename(file_name)
Definition: ncdr_check.f90:66
integer(i_long) ncdr_file_count
Definition: ncdr_state.f90:15
subroutine ncdr_check_current_ncid
Definition: ncdr_check.f90:42
subroutine ncdr_error(err)
Definition: ncdr_climsg.F90:13
integer(i_long) function nc_diag_read_get_index_from_ncid(file_ncid)
Definition: ncdr_check.f90:47