77 subroutine rrtmgp_lw_gas_optics_init(rrtmgp_root_dir, rrtmgp_lw_file_gas, &
78 active_gases_array, mpicomm, mpirank, mpiroot, errmsg, errflg)
81 character(len=128),
intent(in) :: &
82 rrtmgp_root_dir, & !< RTE-RRTMGP root directory
84 character(len=*),
dimension(:),
intent(in) :: &
86 type(mpi_comm),
intent(in) :: &
88 integer,
intent(in) :: &
89 mpirank, & !< Current MPI rank
93 character(len=*),
intent(out) :: &
95 integer,
intent(out) :: &
99 integer :: ncid, dimID, varID, status, ii, mpierr, iChar
100 integer,
dimension(:),
allocatable :: temp1, temp2, temp3, temp4
101 character(len=264) :: lw_gas_props_file
102 type(ty_gas_concs) :: gas_concs
109 lw_gas_props_file = trim(rrtmgp_root_dir)//trim(rrtmgp_lw_file_gas)
118 if (mpirank .eq. mpiroot)
then
120 write (*,*)
'Reading RRTMGP longwave k-distribution metadata ... '
123 status = nf90_open(trim(lw_gas_props_file), nf90_nowrite, ncid)
126 status = nf90_inq_dimid(ncid,
'temperature', dimid)
127 status = nf90_inquire_dimension(ncid, dimid, len = ntempslw)
128 status = nf90_inq_dimid(ncid,
'pressure', dimid)
129 status = nf90_inquire_dimension(ncid, dimid, len = npresslw)
130 status = nf90_inq_dimid(ncid,
'absorber', dimid)
131 status = nf90_inquire_dimension(ncid, dimid, len = nabsorberslw)
132 status = nf90_inq_dimid(ncid,
'minor_absorber', dimid)
133 status = nf90_inquire_dimension(ncid, dimid, len = nminorabsorberslw)
134 status = nf90_inq_dimid(ncid,
'absorber_ext', dimid)
135 status = nf90_inquire_dimension(ncid, dimid, len = nextrabsorberslw)
136 status = nf90_inq_dimid(ncid,
'mixing_fraction', dimid)
137 status = nf90_inquire_dimension(ncid, dimid, len = nmixingfracslw)
138 status = nf90_inq_dimid(ncid,
'atmos_layer', dimid)
139 status = nf90_inquire_dimension(ncid, dimid, len = nlayerslw)
140 status = nf90_inq_dimid(ncid,
'bnd', dimid)
141 status = nf90_inquire_dimension(ncid, dimid, len = nbndslw)
142 status = nf90_inq_dimid(ncid,
'gpt', dimid)
143 status = nf90_inquire_dimension(ncid, dimid, len = ngptslw)
144 status = nf90_inq_dimid(ncid,
'pair', dimid)
145 status = nf90_inquire_dimension(ncid, dimid, len = npairslw)
146 status = nf90_inq_dimid(ncid,
'contributors_lower', dimid)
147 status = nf90_inquire_dimension(ncid, dimid, len = ncontributors_lowerlw)
148 status = nf90_inq_dimid(ncid,
'contributors_upper', dimid)
149 status = nf90_inquire_dimension(ncid, dimid, len = ncontributors_upperlw)
150 status = nf90_inq_dimid(ncid,
'fit_coeffs', dimid)
151 status = nf90_inquire_dimension(ncid, dimid, len = nfit_coeffslw)
152 status = nf90_inq_dimid(ncid,
'minor_absorber_intervals_lower', dimid)
153 status = nf90_inquire_dimension(ncid, dimid, len = nminor_absorber_intervals_lowerlw)
154 status = nf90_inq_dimid(ncid,
'minor_absorber_intervals_upper', dimid)
155 status = nf90_inquire_dimension(ncid, dimid, len = nminor_absorber_intervals_upperlw)
156 status = nf90_inq_dimid(ncid,
'temperature_Planck', dimid)
157 status = nf90_inquire_dimension(ncid, dimid, len = ninternalsourcetempslw)
162 call mpi_barrier(mpicomm, mpierr)
170 call mpi_bcast(ntempslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
171 call mpi_bcast(npresslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
172 call mpi_bcast(ngptslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
173 call mpi_bcast(nabsorberslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
174 call mpi_bcast(nextrabsorberslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
175 call mpi_bcast(nminorabsorberslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
176 call mpi_bcast(nmixingfracslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
177 call mpi_bcast(nlayerslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
178 call mpi_bcast(nbndslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
179 call mpi_bcast(npairslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
180 call mpi_bcast(ninternalsourcetempslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
181 call mpi_bcast(nminor_absorber_intervals_lowerlw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
182 call mpi_bcast(nminor_absorber_intervals_upperlw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
183 call mpi_bcast(ncontributors_lowerlw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
184 call mpi_bcast(ncontributors_upperlw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
185 call mpi_bcast(nfit_coeffslw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
189 if (.not.
allocated(gas_nameslw)) &
190 allocate(gas_nameslw(nabsorberslw))
191 if (.not.
allocated(scaling_gas_lowerlw)) &
192 allocate(scaling_gas_lowerlw(nminor_absorber_intervals_lowerlw))
193 if (.not.
allocated(scaling_gas_upperlw)) &
194 allocate(scaling_gas_upperlw(nminor_absorber_intervals_upperlw))
195 if (.not.
allocated(gas_minorlw)) &
196 allocate(gas_minorlw(nminorabsorberslw))
197 if (.not.
allocated(identifier_minorlw)) &
198 allocate(identifier_minorlw(nminorabsorberslw))
199 if (.not.
allocated(minor_gases_lowerlw)) &
200 allocate(minor_gases_lowerlw(nminor_absorber_intervals_lowerlw))
201 if (.not.
allocated(minor_gases_upperlw)) &
202 allocate(minor_gases_upperlw(nminor_absorber_intervals_upperlw))
203 if (.not.
allocated(minor_limits_gpt_lowerlw)) &
204 allocate(minor_limits_gpt_lowerlw(npairslw, nminor_absorber_intervals_lowerlw))
205 if (.not.
allocated(minor_limits_gpt_upperlw)) &
206 allocate(minor_limits_gpt_upperlw(npairslw, nminor_absorber_intervals_upperlw))
207 if (.not.
allocated(band2gptlw)) &
208 allocate(band2gptlw(2, nbndslw))
209 if (.not.
allocated(key_specieslw)) &
210 allocate(key_specieslw(2, nlayerslw, nbndslw))
211 if (.not.
allocated(band_limslw)) &
212 allocate(band_limslw(2, nbndslw))
213 if (.not.
allocated(press_reflw)) &
214 allocate(press_reflw(npresslw))
215 if (.not.
allocated(temp_reflw)) &
216 allocate(temp_reflw(ntempslw))
217 if (.not.
allocated(vmr_reflw)) &
218 allocate(vmr_reflw(nlayerslw, nextrabsorberslw, ntempslw))
219 if (.not.
allocated(kminor_lowerlw)) &
220 allocate(kminor_lowerlw(ncontributors_lowerlw, nmixingfracslw, ntempslw))
221 if (.not.
allocated(kmajorlw)) &
222 allocate(kmajorlw(ngptslw, nmixingfracslw, npresslw+1, ntempslw))
223 if (.not.
allocated(kminor_start_lowerlw)) &
224 allocate(kminor_start_lowerlw(nminor_absorber_intervals_lowerlw))
225 if (.not.
allocated(kminor_upperlw)) &
226 allocate(kminor_upperlw(ncontributors_upperlw, nmixingfracslw, ntempslw))
227 if (.not.
allocated(kminor_start_upperlw)) &
228 allocate(kminor_start_upperlw(nminor_absorber_intervals_upperlw))
229 if (.not.
allocated(optimal_angle_fitlw)) &
230 allocate(optimal_angle_fitlw(nfit_coeffslw, nbndslw))
231 if (.not.
allocated(minor_scales_with_density_lowerlw)) &
232 allocate(minor_scales_with_density_lowerlw(nminor_absorber_intervals_lowerlw))
233 if (.not.
allocated(minor_scales_with_density_upperlw)) &
234 allocate(minor_scales_with_density_upperlw(nminor_absorber_intervals_upperlw))
235 if (.not.
allocated(scale_by_complement_lowerlw)) &
236 allocate(scale_by_complement_lowerlw(nminor_absorber_intervals_lowerlw))
237 if (.not.
allocated(scale_by_complement_upperlw)) &
238 allocate(scale_by_complement_upperlw(nminor_absorber_intervals_upperlw))
239 if (.not.
allocated(temp1)) &
240 allocate(temp1(nminor_absorber_intervals_lowerlw))
241 if (.not.
allocated(temp2)) &
242 allocate(temp2(nminor_absorber_intervals_upperlw))
243 if (.not.
allocated(temp3)) &
244 allocate(temp3(nminor_absorber_intervals_lowerlw))
245 if (.not.
allocated(temp4)) &
246 allocate(temp4(nminor_absorber_intervals_upperlw))
247 if (.not.
allocated(totplnklw)) &
248 allocate(totplnklw(ninternalsourcetempslw, nbndslw))
249 if (.not.
allocated(planck_fraclw)) &
250 allocate(planck_fraclw(ngptslw, nmixingfracslw, npresslw+1, ntempslw))
259 if (mpirank .eq. mpiroot)
then
261 write (*,*)
'Reading RRTMGP longwave k-distribution data ... '
262 status = nf90_inq_varid(ncid,
'gas_names', varid)
263 status = nf90_get_var( ncid, varid, gas_nameslw)
264 status = nf90_inq_varid(ncid,
'scaling_gas_lower', varid)
265 status = nf90_get_var( ncid, varid, scaling_gas_lowerlw)
266 status = nf90_inq_varid(ncid,
'scaling_gas_upper', varid)
267 status = nf90_get_var( ncid, varid, scaling_gas_upperlw)
268 status = nf90_inq_varid(ncid,
'gas_minor', varid)
269 status = nf90_get_var( ncid, varid, gas_minorlw)
270 status = nf90_inq_varid(ncid,
'identifier_minor', varid)
271 status = nf90_get_var( ncid, varid, identifier_minorlw)
272 status = nf90_inq_varid(ncid,
'minor_gases_lower', varid)
273 status = nf90_get_var( ncid, varid, minor_gases_lowerlw)
274 status = nf90_inq_varid(ncid,
'minor_gases_upper', varid)
275 status = nf90_get_var( ncid, varid, minor_gases_upperlw)
276 status = nf90_inq_varid(ncid,
'minor_limits_gpt_lower', varid)
277 status = nf90_get_var( ncid, varid, minor_limits_gpt_lowerlw)
278 status = nf90_inq_varid(ncid,
'minor_limits_gpt_upper', varid)
279 status = nf90_get_var( ncid, varid, minor_limits_gpt_upperlw)
280 status = nf90_inq_varid(ncid,
'bnd_limits_gpt', varid)
281 status = nf90_get_var( ncid, varid, band2gptlw)
282 status = nf90_inq_varid(ncid,
'key_species', varid)
283 status = nf90_get_var( ncid, varid, key_specieslw)
284 status = nf90_inq_varid(ncid,
'bnd_limits_wavenumber', varid)
285 status = nf90_get_var( ncid, varid, band_limslw)
286 status = nf90_inq_varid(ncid,
'press_ref', varid)
287 status = nf90_get_var( ncid, varid, press_reflw)
288 status = nf90_inq_varid(ncid,
'temp_ref', varid)
289 status = nf90_get_var( ncid, varid, temp_reflw)
290 status = nf90_inq_varid(ncid,
'absorption_coefficient_ref_P', varid)
291 status = nf90_get_var( ncid, varid, temp_ref_plw)
292 status = nf90_inq_varid(ncid,
'absorption_coefficient_ref_T', varid)
293 status = nf90_get_var( ncid, varid, temp_ref_tlw)
294 status = nf90_inq_varid(ncid,
'press_ref_trop', varid)
295 status = nf90_get_var( ncid, varid, press_ref_troplw)
296 status = nf90_inq_varid(ncid,
'kminor_lower', varid)
297 status = nf90_get_var( ncid, varid, kminor_lowerlw)
298 status = nf90_inq_varid(ncid,
'kminor_upper', varid)
299 status = nf90_get_var( ncid, varid, kminor_upperlw)
300 status = nf90_inq_varid(ncid,
'vmr_ref', varid)
301 status = nf90_get_var( ncid, varid, vmr_reflw)
302 status = nf90_inq_varid(ncid,
'optimal_angle_fit',varid)
303 status = nf90_get_var( ncid, varid, optimal_angle_fitlw)
304 status = nf90_inq_varid(ncid,
'kmajor', varid)
305 status = nf90_get_var( ncid, varid, kmajorlw)
306 status = nf90_inq_varid(ncid,
'kminor_start_lower', varid)
307 status = nf90_get_var( ncid, varid, kminor_start_lowerlw)
308 status = nf90_inq_varid(ncid,
'kminor_start_upper', varid)
309 status = nf90_get_var( ncid, varid, kminor_start_upperlw)
310 status = nf90_inq_varid(ncid,
'totplnk', varid)
311 status = nf90_get_var( ncid, varid, totplnklw)
312 status = nf90_inq_varid(ncid,
'plank_fraction', varid)
313 status = nf90_get_var( ncid, varid, planck_fraclw)
316 status = nf90_inq_varid(ncid,
'minor_scales_with_density_lower', varid)
317 status = nf90_get_var( ncid, varid,temp1)
318 status = nf90_inq_varid(ncid,
'minor_scales_with_density_upper', varid)
319 status = nf90_get_var( ncid, varid,temp2)
320 status = nf90_inq_varid(ncid,
'scale_by_complement_lower', varid)
321 status = nf90_get_var( ncid, varid,temp3)
322 status = nf90_inq_varid(ncid,
'scale_by_complement_upper', varid)
323 status = nf90_get_var( ncid, varid,temp4)
324 status = nf90_close(ncid)
326 do ii=1,nminor_absorber_intervals_lowerlw
327 if (temp1(ii) .eq. 0) minor_scales_with_density_lowerlw(ii) = .false.
328 if (temp1(ii) .eq. 1) minor_scales_with_density_lowerlw(ii) = .true.
329 if (temp3(ii) .eq. 0) scale_by_complement_lowerlw(ii) = .false.
330 if (temp3(ii) .eq. 1) scale_by_complement_lowerlw(ii) = .true.
332 do ii=1,nminor_absorber_intervals_upperlw
333 if (temp2(ii) .eq. 0) minor_scales_with_density_upperlw(ii) = .false.
334 if (temp2(ii) .eq. 1) minor_scales_with_density_upperlw(ii) = .true.
335 if (temp4(ii) .eq. 0) scale_by_complement_upperlw(ii) = .false.
336 if (temp4(ii) .eq. 1) scale_by_complement_upperlw(ii) = .true.
342 call mpi_barrier(mpicomm, mpierr)
352 call mpi_bcast(press_ref_troplw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
353 call mpi_bcast(temp_ref_plw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
354 call mpi_bcast(temp_ref_tlw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
357 call mpi_bcast(kminor_start_lowerlw, &
358 size(kminor_start_lowerlw), mpi_integer, mpiroot, mpicomm, mpierr)
359 call mpi_bcast(kminor_start_upperlw, &
360 size(kminor_start_upperlw), mpi_integer, mpiroot, mpicomm, mpierr)
361 call mpi_bcast(band2gptlw, &
362 size(band2gptlw), mpi_integer, mpiroot, mpicomm, mpierr)
363 call mpi_bcast(minor_limits_gpt_lowerlw, &
364 size(minor_limits_gpt_lowerlw), mpi_integer, mpiroot, mpicomm, mpierr)
365 call mpi_bcast(minor_limits_gpt_upperlw, &
366 size(minor_limits_gpt_upperlw), mpi_integer, mpiroot, mpicomm, mpierr)
367 call mpi_bcast(key_specieslw, &
368 size(key_specieslw), mpi_integer, mpiroot, mpicomm, mpierr)
371 call mpi_bcast(press_reflw, &
372 size(press_reflw), mpi_double_precision, mpiroot, mpicomm, mpierr)
373 call mpi_bcast(temp_reflw, &
374 size(temp_reflw), mpi_double_precision, mpiroot, mpicomm, mpierr)
375 call mpi_bcast(band_limslw, &
376 size(band_limslw), mpi_double_precision, mpiroot, mpicomm, mpierr)
377 call mpi_bcast(totplnklw, &
378 size(totplnklw), mpi_double_precision, mpiroot, mpicomm, mpierr)
379 call mpi_bcast(optimal_angle_fitlw, &
380 size(optimal_angle_fitlw), mpi_double_precision, mpiroot, mpicomm, mpierr)
381 call mpi_bcast(vmr_reflw, &
382 size(vmr_reflw), mpi_double_precision, mpiroot, mpicomm, mpierr)
383 call mpi_bcast(kminor_lowerlw, &
384 size(kminor_lowerlw), mpi_double_precision, mpiroot, mpicomm, mpierr)
385 call mpi_bcast(kminor_upperlw, &
386 size(kminor_upperlw), mpi_double_precision, mpiroot, mpicomm, mpierr)
387 call mpi_bcast(kmajorlw, &
388 size(kmajorlw), mpi_double_precision, mpiroot, mpicomm, mpierr)
389 call mpi_bcast(planck_fraclw, &
390 size(planck_fraclw), mpi_double_precision, mpiroot, mpicomm, mpierr)
394 do ichar=1,nabsorberslw
395 call mpi_bcast(gas_nameslw(ichar), &
396 len(gas_nameslw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
398 do ichar=1,nminorabsorberslw
399 call mpi_bcast(gas_minorlw(ichar), &
400 len(gas_minorlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
401 call mpi_bcast(identifier_minorlw(ichar), &
402 len(identifier_minorlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
404 do ichar=1,nminor_absorber_intervals_lowerlw
405 call mpi_bcast(minor_gases_lowerlw(ichar), &
406 len(minor_gases_lowerlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
407 call mpi_bcast(scaling_gas_lowerlw(ichar), &
408 len(scaling_gas_lowerlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
410 do ichar=1,nminor_absorber_intervals_upperlw
411 call mpi_bcast(minor_gases_upperlw(ichar), &
412 len(minor_gases_upperlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
413 call mpi_bcast(scaling_gas_upperlw(ichar), &
414 len(scaling_gas_upperlw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
418 call mpi_bcast(minor_scales_with_density_lowerlw, &
419 size(minor_scales_with_density_lowerlw), mpi_logical, mpiroot, mpicomm, mpierr)
420 call mpi_bcast(minor_scales_with_density_upperlw, &
421 size(minor_scales_with_density_upperlw), mpi_logical, mpiroot, mpicomm, mpierr)
422 call mpi_bcast(scale_by_complement_lowerlw, &
423 size(scale_by_complement_lowerlw), mpi_logical, mpiroot, mpicomm, mpierr)
424 call mpi_bcast(scale_by_complement_upperlw, &
425 size(scale_by_complement_upperlw), mpi_logical, mpiroot, mpicomm, mpierr)
427 call mpi_barrier(mpicomm, mpierr)
435 call check_error_msg(
'rrtmgp_lw_gas_optics_init_gas_concs',gas_concs%init(active_gases_array))
436 call check_error_msg(
'rrtmgp_lw_gas_optics_init_load',lw_gas_props%load(gas_concs, &
437 gas_nameslw, key_specieslw, band2gptlw, band_limslw, press_reflw, press_ref_troplw,&
438 temp_reflw, temp_ref_plw, temp_ref_tlw, vmr_reflw, kmajorlw, kminor_lowerlw, &
439 kminor_upperlw, gas_minorlw, identifier_minorlw, minor_gases_lowerlw, &
440 minor_gases_upperlw, minor_limits_gpt_lowerlw, minor_limits_gpt_upperlw, &
441 minor_scales_with_density_lowerlw, minor_scales_with_density_upperlw, &
442 scaling_gas_lowerlw, scaling_gas_upperlw, scale_by_complement_lowerlw, &
443 scale_by_complement_upperlw, kminor_start_lowerlw, kminor_start_upperlw, totplnklw,&
444 planck_fraclw, rayl_lowerlw, rayl_upperlw, optimal_angle_fitlw))