MONC
q_indices.F90
Go to the documentation of this file.
1 
5  implicit none
6 
7 #ifndef TEST_MODE
8  private
9 #endif
10 
11  integer, parameter :: n_maxqs=100
12  integer, parameter :: n_maxqname=100
13 
14 
16  character(n_maxqname) :: name
17  logical :: l_used=.false.
18  end type q_metadata_type
19 
20 
22 
23 
24  ! standard names
26  character(LEN=6 ) :: vapour = 'vapour'
27  character(LEN=17) :: cloud_liquid_mass = 'cloud_liquid_mass'
28  character(LEN=9 ) :: rain_mass = 'rain_mass'
29  character(LEN=8 ) :: ice_mass = 'ice_mass'
30  character(LEN=9 ) :: snow_mass = 'snow_mass'
31  character(LEN=12) :: graupel_mass = 'graupel_mass'
32  character(LEN=19) :: cloud_liquid_number = 'cloud_liquid_number'
33  character(LEN=11) :: rain_number = 'rain_number'
34  character(LEN=10) :: ice_number = 'ice_number'
35  character(LEN=11) :: snow_number = 'snow_number'
36  character(LEN=14) :: graupel_number = 'graupel_number'
37  character(LEN=17) :: rain_third_moment = 'rain_third_moment'
38  character(LEN=17) :: snow_third_moment = 'snow_third_moment'
39  character(LEN=20) :: graupel_third_moment = 'graupel_third_moment'
40  character(LEN=15) :: aitken_sol_mass = 'aitken_sol_mass'
41  character(LEN=17) :: aitken_sol_number = 'aitken_sol_number'
42  character(LEN=14) :: accum_sol_mass = 'accum_sol_mass'
43  character(LEN=16) :: accum_sol_number = 'accum_sol_number'
44  character(LEN=15) :: coarse_sol_mass = 'coarse_sol_mass'
45  character(LEN=17) :: coarse_sol_number = 'coarse_sol_number'
46  character(LEN=17) :: active_sol_liquid = 'active_sol_liquid'
47  character(LEN=15) :: active_sol_rain = 'active_sol_rain'
48  character(LEN=16) :: coarse_dust_mass = 'coarse_dust_mass'
49  character(LEN=18) :: coarse_dust_number = 'coarse_dust_number'
50  character(LEN=16) :: active_insol_ice = 'active_insol_ice'
51  character(LEN=14) :: active_sol_ice = 'active_sol_ice'
52  character(LEN=19) :: active_insol_liquid = 'active_insol_liquid'
53  character(LEN=16) :: accum_insol_mass = 'accum_insol_mass'
54  character(LEN=18) :: accum_insol_number = 'accum_insol_number'
55  character(LEN=17) :: active_sol_number = 'active_sol_number'
56  character(LEN=19) :: active_insol_number = 'active_insol_number'
57  end type standard_q_names_type
58 
60 
63 
64 
65 contains
66 
70  subroutine set_q_index(index, name)
71  integer, intent(in) :: index
72  character(len=*), intent(in) :: name
73 
74  q_register(index)%name=adjustr(trim(name))
75  q_register(index)%l_used=.true.
76  end subroutine set_q_index
77 
80  integer function get_max_number_q_indices()
82  end function get_max_number_q_indices
83 
86  integer function get_number_active_q_indices()
87 
88  integer :: i
89 
91  do i=1, n_maxqs
93  end do
94  end function get_number_active_q_indices
95 
99  function get_indices_descriptor(i)
100  integer :: i
101  type(q_metadata_type) :: get_indices_descriptor
102 
103  get_indices_descriptor=q_register(i)
104  end function get_indices_descriptor
105 
111  integer function get_q_index(name, assigning_component)
112  character(*), intent(in) :: name
113  character(*), optional :: assigning_component
114 
115  integer :: iname, i_unused
116 
117  i_unused=0
118 
119  do iname=n_maxqs, 1, -1
120  if (trim(name) == trim(q_register(iname)%name)) then
121  ! Here we find the variable has already been added
122  get_q_index=iname
123  return
124  end if
125  ! Counting backwards we will eventually find the first open slot
126  if (.not. q_register(iname)%l_used) then
127  i_unused=iname
128  end if
129  end do
130 
131  if (i_unused == 0) then
132  call log_master_log(log_error, 'Somehow we need to extend q_register')
133  end if
134 
135  ! Not already defined, so populate the empty slot
136  get_q_index=i_unused
137  q_register(get_q_index)%name = adjustr(trim(name))
138  q_register(get_q_index)%l_used = .true.
139 
140  if (present(assigning_component)) then
141  call log_master_log(log_info, 'q variable #'//trim(conv_to_string(get_q_index))//' is assigned to '//trim(name)//&
142  '. Assigned from component: '//trim(assigning_component))
143  else
144  call log_master_log(log_info, 'q variable #'//trim(conv_to_string(get_q_index))//' is assigned to '//trim(name))
145  end if
146 
147  end function get_q_index
148 end module q_indices_mod
type(standard_q_names_type), public standard_q_names
Definition: q_indices.F90:59
integer, parameter, public log_error
Only log ERROR messages.
Definition: logging.F90:11
integer function, public get_max_number_q_indices()
Gets the maximum number of Q indicies.
Definition: q_indices.F90:81
Logging utility.
Definition: logging.F90:2
integer, parameter n_maxqs
Maximum number of Q variables to manage.
Definition: q_indices.F90:11
subroutine, public log_master_log(level, message)
Will log just from the master process.
Definition: logging.F90:47
Conversion between common inbuilt FORTRAN data types.
Definition: conversions.F90:5
Converts data types to strings.
Definition: conversions.F90:36
integer, parameter n_maxqname
Length to allocate for a Q variable name.
Definition: q_indices.F90:12
type(q_metadata_type) function, public get_indices_descriptor(i)
Retrieves the indicies descriptor at a specific location.
Definition: q_indices.F90:100
This manages the Q variables and specifically the mapping between names and the index that they are s...
Definition: q_indices.F90:2
integer function, public get_number_active_q_indices()
Gets the number of active Q indicies (i.e. those allocated to specific uses)
Definition: q_indices.F90:87
type(q_metadata_type), dimension(n_maxqs) q_register
Definition: q_indices.F90:21
integer, parameter, public log_info
Log INFO, WARNING and ERROR messages.
Definition: logging.F90:13
subroutine, public set_q_index(index, name)
Sets a Q index to be active at a specific index and sets the name.
Definition: q_indices.F90:71
integer function, public get_q_index(name, assigning_component)
Add in a new entry into the register if the name does not already exist or return the index of the pr...
Definition: q_indices.F90:112