Line data Source code
1 : !! The CARMAELEMENT module contains configuration information about a particle
2 : !! element used by CARMA.
3 : !!
4 : !! @version March-2010
5 : !! @author Chuck Bardeen
6 : module CARMAELEMENT_mod
7 :
8 : use carma_precision_mod
9 : use carma_enums_mod
10 : use carma_constants_mod
11 : use carma_types_mod
12 :
13 : ! CARMA explicitly declares all variables.
14 : implicit none
15 :
16 : ! All CARMA variables and procedures are private except those explicitly declared to be public.
17 : private
18 :
19 : ! Declare the public methods.
20 : public CARMAELEMENT_Create
21 : public CARMAELEMENT_Destroy
22 : public CARMAELEMENT_Get
23 : public CARMAELEMENT_Print
24 :
25 : contains
26 :
27 : !! Defines a gas used by CARMA for nucleation and growth of cloud and
28 : !! aerosol particles.
29 : !!
30 : !! NOTE: The element density can be specifeid per bin using rhobin; however,
31 : !! if only the bulk density is provided (rho) then the same value will be used
32 : !! for all bins. The bulk density allows for backward compatability and ease of
33 : !! configuration. If rhobin is provided, then rho is ignored.
34 : !!
35 : !! @author Chuck Bardeen
36 : !! @version March-2010
37 : !!
38 : !! @see CARMA_AddGas
39 : !! @see CARMAELEMENT_Destroy
40 10752 : subroutine CARMAELEMENT_Create(carma, ielement, igroup, name, rho, itype, icomposition, rc, &
41 6144 : shortname, isolute, rhobin, arat, kappa, refidx, isShell)
42 : type(carma_type), intent(inout) :: carma !! the carma object
43 : integer, intent(in) :: ielement !! the element index
44 : integer, intent(in) :: igroup !! Group to which the element belongs
45 : character(*), intent(in) :: name !! the element name, maximum of 255 characters
46 : real(kind=f), intent(in) :: rho !! bulk mass density of particle element [g/cm^3]
47 : integer, intent(in) :: itype !! Particle type specification
48 : integer, intent(in) :: icomposition !! Particle compound specification
49 : integer, intent(out) :: rc !! return code, negative indicates failure
50 : character(*), optional, intent(in) :: shortname !! the element shortname, maximum of 6 characters
51 : integer, optional, intent(in) :: isolute !! Index of solute for the particle element
52 : real(kind=f), optional, intent(in) :: rhobin(carma%f_NBIN)!! mass density per bin of particle element [g/cm^3]
53 : real(kind=f), optional, intent(in) :: arat(carma%f_NBIN) !! projected area ratio
54 : real(kind=f), optional, intent(in) :: kappa !! hygroscopicity parameter for the particle element [units?]
55 : complex(kind=f), optional, intent(in) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) !! refractive indices
56 : logical, optional, intent(in) :: isShell !! Is this element part of the shell or the core?
57 :
58 : ! Local variables
59 : integer :: ier
60 :
61 : ! Assume success.
62 10752 : rc = RC_OK
63 :
64 : ! Make sure there are enough elements allocated.
65 10752 : if (ielement > carma%f_NELEM) then
66 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Create:: ERROR - The specifed element (", &
67 0 : ielement, ") is larger than the number of elements (", carma%f_NELEM, ")."
68 0 : rc = RC_ERROR
69 0 : return
70 : end if
71 :
72 : ! Make sure there are enough groups allocated.
73 10752 : if (igroup > carma%f_NGROUP) then
74 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Create:: ERROR - The specifed group (", &
75 0 : igroup, ") is larger than the number of groups (", carma%f_NGROUP, ")."
76 0 : rc = RC_ERROR
77 0 : return
78 : end if
79 :
80 : allocate( &
81 0 : carma%f_element(ielement)%f_rho(carma%f_NBIN), &
82 32256 : stat=ier)
83 10752 : if(ier /= 0) then
84 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Add: ERROR allocating, status=", ier
85 0 : rc = RC_ERROR
86 0 : return
87 : end if
88 :
89 10752 : if ((carma%f_NWAVE > 0) .and. (carma%f_NREFIDX > 0)) then
90 : allocate( &
91 0 : carma%f_element(ielement)%f_refidx(carma%f_NWAVE, carma%f_NREFIDX), &
92 43008 : stat=ier)
93 10752 : if(ier /= 0) then
94 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Add: ERROR allocating, status=", ier
95 0 : rc = RC_ERROR
96 0 : return
97 : end if
98 :
99 344064 : carma%f_element(ielement)%f_refidx(:,:) = CMPLX(0._f, 0._f, kind=f)
100 : end if
101 :
102 :
103 : ! Save off the settings.
104 10752 : carma%f_element(ielement)%f_igroup = igroup
105 10752 : carma%f_element(ielement)%f_name = name
106 225792 : carma%f_element(ielement)%f_rho(:) = rho
107 10752 : carma%f_element(ielement)%f_itype = itype
108 10752 : carma%f_element(ielement)%f_icomposition = icomposition
109 :
110 :
111 : ! Defaults for optional parameters
112 10752 : carma%f_element(ielement)%f_shortname = ""
113 10752 : carma%f_element(ielement)%f_isolute = 0
114 10752 : carma%f_element(ielement)%f_kappa = 0.0_f
115 10752 : carma%f_element(ielement)%f_isShell = .true.
116 :
117 : ! Set optional parameters.
118 10752 : if (present(shortname)) carma%f_element(ielement)%f_shortname = shortname
119 10752 : if (present(kappa)) carma%f_element(ielement)%f_kappa = kappa
120 201216 : if (present(refidx)) carma%f_element(ielement)%f_refidx(:,:) = refidx(:,:)
121 10752 : if (present(isShell)) carma%f_element(ielement)%f_isShell = isShell
122 :
123 10752 : if (present(isolute)) then
124 :
125 : ! Make sure there are enough solutes allocated.
126 0 : if (isolute > carma%f_NSOLUTE) then
127 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Create:: ERROR - The specifed solute (", &
128 0 : isolute, ") is larger than the number of solutes (", carma%f_NSOLUTE, ")."
129 0 : rc = RC_ERROR
130 0 : return
131 : end if
132 :
133 0 : carma%f_element(ielement)%f_isolute = isolute
134 : end if
135 10752 : if (present(rhobin)) carma%f_element(ielement)%f_rho(:) = rhobin(:)
136 :
137 : ! If the area ratio is specfied (usually along with rhobin), then set this
138 : ! for the group.
139 10752 : if (present(arat)) carma%f_group(igroup)%f_arat(:) = arat(:)
140 :
141 : ! Keep track of the fact that another element has been added to the group.
142 10752 : carma%f_group(igroup)%f_nelem = carma%f_group(igroup)%f_nelem + 1
143 :
144 10752 : return
145 16896 : end subroutine CARMAELEMENT_Create
146 :
147 :
148 : !! Deallocates the memory associated with a CARMAELEMENT object.
149 : !!
150 : !! @author Chuck Bardeen
151 : !! @version March-2010
152 : !!
153 : !! @see CARMAELEMENT_Create
154 10752 : subroutine CARMAELEMENT_Destroy(carma, ielement, rc)
155 : type(carma_type), intent(inout) :: carma !! the carma object
156 : integer, intent(in) :: ielement !! the element index
157 : integer, intent(out) :: rc !! return code, negative indicates failure
158 :
159 : ! Local variables
160 : integer :: ier
161 :
162 : ! Assume success.
163 10752 : rc = RC_OK
164 :
165 : ! Make sure there are enough elements allocated.
166 10752 : if (ielement > carma%f_NELEM) then
167 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Destroy:: ERROR - The specifed element (", &
168 0 : ielement, ") is larger than the number of elements (", carma%f_NELEM, ")."
169 0 : rc = RC_ERROR
170 0 : return
171 : end if
172 :
173 10752 : if (allocated(carma%f_element(ielement)%f_rho)) then
174 10752 : deallocate(carma%f_element(ielement)%f_rho,stat=ier)
175 : if(ier /= 0) then
176 : if (carma%f_do_print) then
177 : write(carma%f_LUNOPRT, *) "CARMAELEMENT_Destroy: ERROR deallocating f_rho, status=", ier
178 : endif
179 : rc = RC_ERROR
180 : return
181 : endif
182 : endif
183 10752 : if (allocated(carma%f_element(ielement)%f_refidx)) then
184 10752 : deallocate(carma%f_element(ielement)%f_refidx, stat=ier)
185 : if(ier /= 0) then
186 : if (carma%f_do_print) then
187 : write(carma%f_LUNOPRT, *) "CARMAELEMENT_Destroy: ERROR deallocating f_refidx, status=", ier
188 : endif
189 : rc = RC_ERROR
190 : return
191 : endif
192 : endif
193 :
194 : return
195 : end subroutine CARMAELEMENT_Destroy
196 :
197 :
198 : !! Gets information about a particle element.
199 : !!
200 : !! The group name and other properties are available after a call to
201 : !! CARMAELEMENT_Create().
202 : !!
203 : !! @author Chuck Bardeen
204 : !! @version March-2010
205 : !!
206 : !! @see CARMAELEMENT_Create
207 : !! @see CARMA_GetElement
208 826578432 : subroutine CARMAELEMENT_Get(carma, ielement, rc, igroup, name, shortname, rho, itype, icomposition, isolute, kappa, refidx, isShell)
209 : type(carma_type), intent(in) :: carma !! the carma object
210 : integer, intent(in) :: ielement !! the element index
211 : integer, intent(out) :: rc !! return code, negative indicates failure
212 : integer, optional, intent(out) :: igroup !! Group to which the element belongs
213 : character(len=*), optional, intent(out) :: name !! the element name
214 : character(len=*), optional, intent(out) :: shortname !! the element short name
215 : real(kind=f), optional, intent(out) :: rho(carma%f_NBIN) !! Mass density of particle element [g/cm^3]
216 : integer, optional, intent(out) :: itype !! Particle type specification
217 : integer, optional, intent(out) :: icomposition !! Particle compound specification
218 : integer, optional, intent(out) :: isolute !! Index of solute for the particle element
219 : real(kind=f), optional, intent(out) :: kappa !! hygroscopicity parameter for the particle element [units?]
220 : complex(kind=f), optional, intent(out) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) !! Refractive indices
221 : logical, optional, intent(out) :: isShell !! Is this element part of the shell or the core?
222 :
223 : ! Assume success.
224 94703395602 : rc = RC_OK
225 :
226 : ! Make sure there are enough elements allocated.
227 94703395602 : if (ielement > carma%f_NELEM) then
228 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Get:: ERROR - The specifed element (", &
229 0 : ielement, ") is larger than the number of elements (", carma%f_NELEM, ")."
230 0 : rc = RC_ERROR
231 0 : return
232 : end if
233 :
234 : ! Return any requested properties of the group.
235 94703395602 : if (present(igroup)) igroup = carma%f_element(ielement)%f_igroup
236 94703395602 : if (present(name)) name = carma%f_element(ielement)%f_name
237 94703395602 : if (present(shortname)) shortname = carma%f_element(ielement)%f_shortname
238 >11123*10^7 : if (present(rho)) rho(:) = carma%f_element(ielement)%f_rho(:)
239 94703395602 : if (present(itype)) itype = carma%f_element(ielement)%f_itype
240 94703395602 : if (present(icomposition)) icomposition = carma%f_element(ielement)%f_icomposition
241 94703395602 : if (present(isolute)) isolute = carma%f_element(ielement)%f_isolute
242 94703395602 : if (present(kappa)) kappa = carma%f_element(ielement)%f_kappa
243 94703395602 : if (present(isShell)) isShell = carma%f_element(ielement)%f_isShell
244 :
245 94703395602 : if ((carma%f_NWAVE == 0) .or. (carma%f_NREFIDX == 0)) then
246 0 : if (present(refidx)) then
247 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAGROUP_Get: ERROR no refidx defined."
248 0 : rc = RC_ERROR
249 0 : return
250 : end if
251 : else
252 94703395602 : if (present(refidx)) refidx(:,:) = carma%f_element(ielement)%f_refidx(:,:)
253 : end if
254 :
255 : return
256 95529974034 : end subroutine CARMAELEMENT_Get
257 :
258 :
259 : !! Prints information about an element.
260 : !!
261 : !! @author Chuck Bardeen
262 : !! @version March-2010
263 : !!
264 : !! @see CARMAELEMENT_Get
265 0 : subroutine CARMAELEMENT_Print(carma, ielement, rc)
266 : type(carma_type), intent(in) :: carma !! the carma object
267 : integer, intent(in) :: ielement !! the element index
268 : integer, intent(out) :: rc !! return code, negative indicates failure
269 :
270 : ! Local variables
271 : character(len=CARMA_NAME_LEN) :: name ! name
272 : character(len=CARMA_SHORT_NAME_LEN) :: shortname ! shortname
273 0 : real(kind=f) :: rho(carma%f_NBIN)! density (g/cm3)
274 : integer :: igroup ! Group to which the element belongs
275 : integer :: itype ! Particle type specification
276 : integer :: icomposition ! Particle compound specification
277 : integer :: isolute ! Index of solute for the particle element
278 : real(kind=f) :: kappa ! hygroscopicity factor
279 0 : complex(kind=f) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) ! Refractive indices
280 : logical :: isShell ! Is this element part of the shell or the core?
281 :
282 : ! Assume success.
283 0 : rc = RC_OK
284 :
285 : ! Test out the Get method.
286 0 : if (carma%f_do_print) then
287 : call CARMAELEMENT_Get(carma, ielement, rc, name=name, shortname=shortname, igroup=igroup, &
288 : itype=itype, icomposition=icomposition, rho=rho, isolute=isolute, &
289 0 : kappa=kappa, refidx=refidx, isShell=isShell)
290 0 : if (rc < 0) return
291 :
292 :
293 0 : write(carma%f_LUNOPRT,*) " name : ", trim(name)
294 0 : write(carma%f_LUNOPRT,*) " igroup : ", igroup
295 0 : write(carma%f_LUNOPRT,*) " shortname : ", trim(shortname)
296 0 : write(carma%f_LUNOPRT,*) " rho : ", rho, " (g/cm3)"
297 :
298 0 : select case(itype)
299 : case (I_INVOLATILE)
300 0 : write(carma%f_LUNOPRT,*) " itype : involatile"
301 : case (I_VOLATILE)
302 0 : write(carma%f_LUNOPRT,*) " itype : volatile"
303 : case (I_COREMASS)
304 0 : write(carma%f_LUNOPRT,*) " itype : core mass"
305 : case (I_VOLCORE)
306 0 : write(carma%f_LUNOPRT,*) " itype : volatile core"
307 : case (I_CORE2MOM)
308 0 : write(carma%f_LUNOPRT,*) " itype : core mass - second moment"
309 : case default
310 0 : write(carma%f_LUNOPRT,*) " itype : unknown, ", itype
311 : end select
312 :
313 0 : write(carma%f_LUNOPRT,*) " icomposition : ", icomposition
314 0 : write(carma%f_LUNOPRT,*) " isolute : ", isolute
315 0 : write(carma%f_LUNOPRT,*) " kappa : ", kappa
316 0 : write(carma%f_LUNOPRT,*) " isShell : ", isShell
317 0 : write(carma%f_LUNOPRT,*) " ref. index : ", refidx
318 : end if
319 :
320 : return
321 : end subroutine CARMAELEMENT_Print
322 :
323 : end module CARMAELEMENT_mod
|