Line data Source code
1 : !! The CARMAGAS module contains configuration information about a gas used by CARMA.
2 : !!
3 : !! @version May-2009
4 : !! @author Chuck Bardeen
5 : module carmagas_mod
6 :
7 : use carma_precision_mod
8 : use carma_enums_mod
9 : use carma_constants_mod
10 : use carma_types_mod
11 :
12 : ! CARMA explicitly declares all variables.
13 : implicit none
14 :
15 : ! All CARMA variables and procedures are private except those explicitly declared to be public.
16 : private
17 :
18 : ! Declare the public methods.
19 : public CARMAGAS_Create
20 : public CARMAGAS_Destroy
21 : public CARMAGAS_Get
22 : public CARMAGAS_Print
23 :
24 : contains
25 :
26 : !! Defines a gas used by CARMA for nucleation and growth of cloud and
27 : !! aerosol particles.
28 : !!
29 : !! @author Chuck Bardeen
30 : !! @version May-2009
31 : !!
32 : !! @see CARMA_AddGas
33 : !! @see CARMAGAS_Destroy
34 3072 : subroutine CARMAGAS_Create(carma, igas, name, wtmol, ivaprtn, icomposition, &
35 1536 : rc, shortname, dgc_threshold, ds_threshold, refidx)
36 : type(carma_type), intent(inout) :: carma !! the carma object
37 : integer, intent(in) :: igas !! the gas index
38 : character(*), intent(in) :: name !! the gas name, maximum of 255 characters
39 : real(kind=f), intent(in) :: wtmol !! the gas molecular weight [g/mol]
40 : integer, intent(in) :: ivaprtn !! vapor pressure routine for this gas
41 : integer, intent(in) :: icomposition !! gas compound specification
42 : integer, intent(out) :: rc !! return code, negative indicates failure
43 : character(*), optional, intent(in) :: shortname !! the gas shortname, maximum of 6 characters
44 : real(kind=f), optional, intent(in) :: dgc_threshold !! convergence criteria for gas concentration
45 : !! [0 : off; > 0 : percentage change]
46 : real(kind=f), optional, intent(in) :: ds_threshold !! convergence criteria for gas saturation
47 : !! [0 : off; > 0 : percentage change; < 0 : amount past 0 crossing]
48 : complex(kind=f), optional, intent(in) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) !! refractive indices
49 :
50 : integer :: ier
51 :
52 : ! Assume success.
53 3072 : rc = RC_OK
54 :
55 : ! Make sure there are enough gases allocated.
56 3072 : if (igas > carma%f_NGAS) then
57 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAGAS_GetCreate:: ERROR - The specifed gas (", &
58 0 : igas, ") is larger than the number of gases (", carma%f_NGAS, ")."
59 0 : rc = RC_ERROR
60 0 : return
61 : end if
62 :
63 3072 : if ((carma%f_NWAVE > 0) .and. (carma%f_NREFIDX > 0)) then
64 : allocate( &
65 0 : carma%f_gas(igas)%f_refidx(carma%f_NWAVE, carma%f_NREFIDX), &
66 12288 : stat=ier)
67 3072 : if(ier /= 0) then
68 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAELEMENT_Add: ERROR allocating, status=", ier
69 0 : rc = RC_ERROR
70 0 : return
71 : end if
72 :
73 98304 : carma%f_gas(igas)%f_refidx(:,:) = CMPLX(0._f, 0._f, kind=f)
74 : end if
75 :
76 :
77 : ! Save off the settings.
78 3072 : carma%f_gas(igas)%f_name = name
79 3072 : carma%f_gas(igas)%f_wtmol = wtmol
80 3072 : carma%f_gas(igas)%f_ivaprtn = ivaprtn
81 3072 : carma%f_gas(igas)%f_icomposition = icomposition
82 :
83 :
84 : ! Defaults for optional parameters
85 3072 : carma%f_gas(igas)%f_shortname = ""
86 3072 : carma%f_gas(igas)%f_dgc_threshold = 0._f
87 3072 : carma%f_gas(igas)%f_ds_threshold = 0._f
88 :
89 : ! Set optional parameters.
90 3072 : if (present(shortname)) carma%f_gas(igas)%f_shortname = shortname
91 3072 : if (present(dgc_threshold)) carma%f_gas(igas)%f_dgc_threshold = dgc_threshold
92 3072 : if (present(ds_threshold)) carma%f_gas(igas)%f_ds_threshold = ds_threshold
93 50688 : if (present(refidx)) carma%f_gas(igas)%f_refidx(:,:) = refidx(:,:)
94 :
95 : return
96 3072 : end subroutine CARMAGAS_Create
97 :
98 :
99 : !! Deallocates the memory associated with a CARMAGAS object.
100 : !!
101 : !! @author Chuck Bardeen
102 : !! @version May-2009
103 : !!
104 : !! @see CARMAGAS_Create
105 3072 : subroutine CARMAGAS_Destroy(carma, igas, rc)
106 : type(carma_type), intent(inout) :: carma !! the carma object
107 : integer, intent(in) :: igas !! the gas index
108 : integer, intent(out) :: rc !! return code, negative indicates failure
109 :
110 : integer :: ier
111 :
112 : ! Assume success.
113 3072 : rc = RC_OK
114 :
115 : ! Make sure there are enough gases allocated.
116 3072 : if (igas > carma%f_NGAS) then
117 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAGAS_Destroy:: ERROR - The specifed gas (", &
118 0 : igas, ") is larger than the number of gases (", carma%f_NGAS, ")."
119 0 : rc = RC_ERROR
120 0 : return
121 : end if
122 :
123 3072 : if (allocated(carma%f_gas(igas)%f_refidx)) then
124 3072 : deallocate(carma%f_gas(igas)%f_refidx, stat=ier)
125 : if(ier /= 0) then
126 : if (carma%f_do_print) then
127 : write(carma%f_LUNOPRT, *) "CARMAGAS_Destroy: ERROR deallocating f_refidx, status=", ier
128 : endif
129 : rc = RC_ERROR
130 : return
131 : endif
132 : endif
133 :
134 :
135 : return
136 : end subroutine CARMAGAS_Destroy
137 :
138 :
139 : !! Gets information about a gas.
140 : !!
141 : !! The group name and other properties are available after a call to
142 : !! CARMAGAS_Create().
143 : !!
144 : !! @author Chuck Bardeen
145 : !! @version May-2009
146 : !!
147 : !! @see CARMAGAS_Create
148 : !! @see CARMA_GetGas
149 0 : subroutine CARMAGAS_Get(carma, igas, rc, name, shortname, wtmol, ivaprtn, icomposition, dgc_threshold, ds_threshold, refidx)
150 : type(carma_type), intent(in) :: carma !! the carma object
151 : integer, intent(in) :: igas !! the gas index
152 : integer, intent(out) :: rc !! return code, negative indicates failure
153 : character(len=*), optional, intent(out) :: name !! the gas name
154 : character(len=*), optional, intent(out) :: shortname !! the gas short name
155 : real(kind=f), optional, intent(out) :: wtmol !! the gas molecular weight [g/mol]
156 : integer, optional, intent(out) :: ivaprtn !! vapor pressure routine for this gas
157 : integer, optional, intent(out) :: icomposition !! gas compound specification
158 : real(kind=f), optional, intent(out) :: dgc_threshold !! convergence criteria for gas concentration [fraction]
159 : real(kind=f), optional, intent(out) :: ds_threshold !! convergence criteria for gas saturation [fraction]
160 : complex(kind=f), optional, intent(out) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) !! Refractive indices
161 :
162 : ! Assume success.
163 3072 : rc = RC_OK
164 :
165 : ! Make sure there are enough gases allocated.
166 3072 : if (igas > carma%f_NGAS) then
167 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAGAS_Get:: ERROR - The specifed gas (", &
168 0 : igas, ") is larger than the number of gases (", carma%f_NGAS, ")."
169 0 : rc = RC_ERROR
170 0 : return
171 : end if
172 :
173 : ! Return any requested properties of the group.
174 3072 : if (present(name)) name = carma%f_gas(igas)%f_name
175 3072 : if (present(shortname)) shortname = carma%f_gas(igas)%f_shortname
176 3072 : if (present(wtmol)) wtmol = carma%f_gas(igas)%f_wtmol
177 3072 : if (present(ivaprtn)) ivaprtn = carma%f_gas(igas)%f_ivaprtn
178 3072 : if (present(icomposition)) icomposition = carma%f_gas(igas)%f_icomposition
179 3072 : if (present(dgc_threshold)) dgc_threshold = carma%f_gas(igas)%f_dgc_threshold
180 3072 : if (present(ds_threshold)) ds_threshold = carma%f_gas(igas)%f_ds_threshold
181 :
182 3072 : if ((carma%f_NWAVE == 0) .or. (carma%f_NREFIDX == 0)) then
183 0 : if (present(refidx)) then
184 0 : if (carma%f_do_print) write(carma%f_LUNOPRT, *) "CARMAGROUP_Get: ERROR no refidx defined."
185 0 : rc = RC_ERROR
186 0 : return
187 : end if
188 : else
189 3072 : if (present(refidx)) refidx(:,:) = carma%f_gas(igas)%f_refidx(:,:)
190 : end if
191 :
192 : return
193 3072 : end subroutine CARMAGAS_Get
194 :
195 :
196 : !! Prints information about a gas.
197 : !!
198 : !! @author Chuck Bardeen
199 : !! @version May-2009
200 : !!
201 : !! @see CARMAGAS_Get
202 0 : subroutine CARMAGAS_Print(carma, igas, rc)
203 : type(carma_type), intent(in) :: carma !! the carma object
204 : integer, intent(in) :: igas !! the gas index
205 : integer, intent(out) :: rc !! return code, negative indicates failure
206 :
207 : ! Local variables
208 : character(len=CARMA_NAME_LEN) :: name !! name
209 : character(len=CARMA_SHORT_NAME_LEN) :: shortname !! shortname
210 : real(kind=f) :: wtmol !! molecular weight (g/mol)
211 : integer :: ivaprtn !! vapor pressure routine for this gas
212 : integer :: icomposition !! gas compound specification
213 : real(kind=f) :: dgc_threshold !! convergence criteria for gas concentration [fraction]
214 : real(kind=f) :: ds_threshold !! convergence criteria for gas saturation [fraction]
215 0 : complex(kind=f) :: refidx(carma%f_NWAVE, carma%f_NREFIDX) ! Refractive indices
216 :
217 : ! Assume success.
218 0 : rc = RC_OK
219 :
220 : ! Test out the Get method.
221 0 : if (carma%f_do_print) then
222 : call CARMAGAS_Get(carma, igas, rc, name=name, shortname=shortname, wtmol=wtmol, &
223 0 : ivaprtn=ivaprtn, icomposition=icomposition, refidx=refidx)
224 0 : if (rc < RC_OK) return
225 :
226 :
227 0 : write(carma%f_LUNOPRT,*) " name : ", trim(name)
228 0 : write(carma%f_LUNOPRT,*) " shortname : ", trim(shortname)
229 0 : write(carma%f_LUNOPRT,*) " wtmol : ", wtmol, " (g/mol)"
230 0 : write(carma%f_LUNOPRT,*) " dgc_threshold : ", dgc_threshold
231 0 : write(carma%f_LUNOPRT,*) " ds_threshold : ", ds_threshold
232 :
233 0 : select case(ivaprtn)
234 : case (I_VAPRTN_H2O_BUCK1981)
235 0 : write(carma%f_LUNOPRT,*) " ivaprtn : Buck [1981]"
236 : case (I_VAPRTN_H2O_MURPHY2005)
237 0 : write(carma%f_LUNOPRT,*) " ivaprtn : Murphy & Koop [2005]"
238 : case default
239 0 : write(carma%f_LUNOPRT,*) " ivaprtn : unknown, ", ivaprtn
240 : end select
241 :
242 0 : select case(icomposition)
243 : case (I_GCOMP_H2O)
244 0 : write(carma%f_LUNOPRT,*) " icomposition : H2O"
245 : case default
246 0 : write(carma%f_LUNOPRT,*) " icomposition : unknown, ", icomposition
247 : end select
248 0 : write(carma%f_LUNOPRT,*) " ref. index : ", refidx
249 : end if
250 :
251 : return
252 : end subroutine CARMAGAS_Print
253 :
254 : end module carmagas_mod
|