FV3 Bundle
ncdc_dims.F90
Go to the documentation of this file.
1 module ncdc_dims
2  use ncd_kinds, only: i_long
7 
8  implicit none
9 
10  integer(i_long), parameter :: dim_start_size = 256
11 
12  contains
13  function nc_diag_cat_lookup_dim(dim_name) result(ind)
14  character(len=*), intent(in) :: dim_name
15  integer(i_long) :: i, ind
16 
17  ind = -1
18 
19  if (allocated(dim_names)) then
20  do i = 1, dim_arr_total
21  if (dim_names(i) == dim_name) then
22  ind = i
23  exit
24  end if
25  end do
26  end if
27  end function nc_diag_cat_lookup_dim
28 
29  subroutine nc_diag_cat_metadata_add_dim(dim_name, dim_size, dim_ul_size)
30  character(len=*), intent(in) :: dim_name
31  integer(i_long) , intent(in) :: dim_size
32  integer(i_long),optional, intent(in) :: dim_ul_size
33 
34  integer(i_long) :: dim_index
35  character(len=1000) :: err_string
36 
37  dim_index = nc_diag_cat_lookup_dim(dim_name)
38 
39  ! If we can't find it, it's new! Make sure we have enough
40  ! space for it...
41  if (dim_index == -1) then
42 #ifdef DEBUG
43  print *, "NEW DIM!"
44 #endif
46 
47  if (dim_arr_total >= dim_arr_size) then
48  if (allocated(dim_names)) then
55  else
56  allocate(dim_names(dim_start_size))
57  allocate(dim_sizes(dim_start_size))
58  allocate(dim_counters(dim_start_size))
62  end if
63  end if
64 
65  dim_index = dim_arr_total
66 
67  ! Add name
68  dim_names(dim_index) = dim_name
69  dim_sizes(dim_index) = 0
70  dim_unlim_sizes(dim_index) = 0
71 
72  ! Set counter to 0
73  dim_counters(dim_index) = 0
74  dim_output_ids(dim_index) = -1
75  end if
76 
77  if (dim_size /= -1) then
78  ! Add/update size
79  if ((index(dim_name, "_maxstrlen") /= 0) .OR. (index(dim_name, "_str_dim") /= 0)) then
80  ! Use the maximum as the new size... and skip the check.
81  if (dim_size > dim_sizes(dim_index)) dim_sizes(dim_index) = dim_size
82  else
83  if ((dim_sizes(dim_index) /= 0) .AND. (dim_size /= dim_sizes(dim_index))) then
84  write (err_string, "(A, I0, A, I0, A)") &
85  "Fixed dimension length changed between files!" // &
86  char(10) // " " // &
87  "(Fixed dimension '" // dim_name // "' changed from length ", &
88  dim_sizes(dim_index), &
89  char(10) // " " // &
90  "to ", &
91  dim_size, &
92  "!)"
93  call ncdc_error(trim(err_string))
94  end if
95  dim_sizes(dim_index) = dim_size
96  end if
97  else
98  if ((dim_sizes(dim_index) /= -1) .AND. (dim_sizes(dim_index) /= 0)) then
99  write (err_string, "(A, I0, A)") &
100  "Changed from a fixed dimension length to unlimited" // &
101  char(10) // " " // &
102  "dimension length. (Fixed dimension '" // &
103  trim(dim_name) // &
104  "' had a fixed" // &
105  char(10) // " " // &
106  "length of ", &
107  dim_sizes(dim_index), &
108  "!)"
109  call ncdc_error(trim(err_string))
110  end if
111  dim_sizes(dim_index) = -1
112 
113  if (present(dim_ul_size)) then
114  dim_unlim_sizes(dim_index) = dim_unlim_sizes(dim_index) + dim_ul_size
115  else
116  call ncdc_warning("Call made for unlimited dimension without specifying unlimited size!")
117  end if
118  end if
119  end subroutine nc_diag_cat_metadata_add_dim
120 end module ncdc_dims
integer(i_long), dimension(:), allocatable dim_output_ids
Definition: ncdc_state.F90:19
subroutine nc_diag_cat_metadata_add_dim(dim_name, dim_size, dim_ul_size)
Definition: ncdc_dims.F90:30
integer(i_long) dim_arr_size
Definition: ncdc_state.F90:25
integer, parameter, public i_long
Definition: ncd_kinds.F90:47
character(len=100), dimension(:), allocatable dim_names
Definition: ncdc_state.F90:17
integer(i_long) function nc_diag_cat_lookup_dim(dim_name)
Definition: ncdc_dims.F90:14
integer(i_long), dimension(:), allocatable dim_counters
Definition: ncdc_state.F90:20
subroutine ncdc_error(err)
Definition: ncdc_climsg.F90:29
subroutine ncdc_warning(warn)
Definition: ncdc_climsg.F90:58
integer(i_long), dimension(:), allocatable dim_unlim_sizes
Definition: ncdc_state.F90:21
integer(i_long), parameter dim_start_size
Definition: ncdc_dims.F90:10
integer(i_long) dim_arr_total
Definition: ncdc_state.F90:24
integer(i_long), dimension(:), allocatable dim_sizes
Definition: ncdc_state.F90:18