88 subroutine rrtmgp_sw_gas_optics_init(rrtmgp_root_dir, rrtmgp_sw_file_gas, &
89 active_gases_array, mpicomm, mpirank, mpiroot, errmsg, errflg)
92 character(len=128),
intent(in) :: &
93 rrtmgp_root_dir, & !< RTE-RRTMGP root directory
95 character(len=*),
dimension(:),
intent(in) :: &
97 type(mpi_comm),
intent(in) :: &
99 integer,
intent(in) :: &
100 mpirank, & !< Current MPI rank
104 character(len=*),
intent(out) :: &
106 integer,
intent(out) :: &
110 integer :: status, ncid, dimid, varID, mpierr, iChar
111 integer,
dimension(:),
allocatable :: temp1, temp2, temp3, temp4
112 character(len=264) :: sw_gas_props_file
113 type(ty_gas_concs) :: gas_concs
120 sw_gas_props_file = trim(rrtmgp_root_dir)//trim(rrtmgp_sw_file_gas)
129 if (mpirank .eq. mpiroot)
then
131 write (*,*)
'Reading RRTMGP shortwave k-distribution metadata ... '
134 status = nf90_open(trim(sw_gas_props_file), nf90_nowrite, ncid)
137 status = nf90_inq_dimid(ncid,
'temperature', dimid)
138 status = nf90_inquire_dimension(ncid, dimid, len=ntempssw)
139 status = nf90_inq_dimid(ncid,
'pressure', dimid)
140 status = nf90_inquire_dimension(ncid, dimid, len=npresssw)
141 status = nf90_inq_dimid(ncid,
'absorber', dimid)
142 status = nf90_inquire_dimension(ncid, dimid, len=nabsorberssw)
143 status = nf90_inq_dimid(ncid,
'minor_absorber',dimid)
144 status = nf90_inquire_dimension(ncid, dimid, len=nminorabsorberssw)
145 status = nf90_inq_dimid(ncid,
'absorber_ext', dimid)
146 status = nf90_inquire_dimension(ncid, dimid, len=nextrabsorberssw)
147 status = nf90_inq_dimid(ncid,
'mixing_fraction', dimid)
148 status = nf90_inquire_dimension(ncid, dimid, len=nmixingfracssw)
149 status = nf90_inq_dimid(ncid,
'atmos_layer', dimid)
150 status = nf90_inquire_dimension(ncid, dimid, len=nlayerssw)
151 status = nf90_inq_dimid(ncid,
'bnd', dimid)
152 status = nf90_inquire_dimension(ncid, dimid, len=nbndssw)
153 status = nf90_inq_dimid(ncid,
'gpt', dimid)
154 status = nf90_inquire_dimension(ncid, dimid, len=ngptssw)
155 status = nf90_inq_dimid(ncid,
'pair', dimid)
156 status = nf90_inquire_dimension(ncid, dimid, len=npairssw)
157 status = nf90_inq_dimid(ncid,
'contributors_lower',dimid)
158 status = nf90_inquire_dimension(ncid, dimid, len=ncontributors_lowersw)
159 status = nf90_inq_dimid(ncid,
'contributors_upper', dimid)
160 status = nf90_inquire_dimension(ncid, dimid, len=ncontributors_uppersw)
161 status = nf90_inq_dimid(ncid,
'minor_absorber_intervals_lower', dimid)
162 status = nf90_inquire_dimension(ncid, dimid, len=nminor_absorber_intervals_lowersw)
163 status = nf90_inq_dimid(ncid,
'minor_absorber_intervals_upper', dimid)
164 status = nf90_inquire_dimension(ncid, dimid, len=nminor_absorber_intervals_uppersw)
170 call mpi_barrier(mpicomm, mpierr)
178 call mpi_bcast(nbndssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
179 call mpi_bcast(ngptssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
180 call mpi_bcast(nmixingfracssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
181 call mpi_bcast(ntempssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
182 call mpi_bcast(npresssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
183 call mpi_bcast(nabsorberssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
184 call mpi_bcast(nextrabsorberssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
185 call mpi_bcast(nminorabsorberssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
186 call mpi_bcast(nlayerssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
187 call mpi_bcast(npairssw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
188 call mpi_bcast(ncontributors_uppersw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
189 call mpi_bcast(ncontributors_lowersw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
190 call mpi_bcast(nminor_absorber_intervals_uppersw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
191 call mpi_bcast(nminor_absorber_intervals_lowersw, 1, mpi_integer, mpiroot, mpicomm, mpierr)
200 if (.not.
allocated(gas_namessw)) &
201 allocate(gas_namessw(nabsorberssw))
202 if (.not.
allocated(scaling_gas_lowersw)) &
203 allocate(scaling_gas_lowersw(nminor_absorber_intervals_lowersw))
204 if (.not.
allocated(scaling_gas_uppersw)) &
205 allocate(scaling_gas_uppersw(nminor_absorber_intervals_uppersw))
206 if (.not.
allocated(gas_minorsw)) &
207 allocate(gas_minorsw(nminorabsorberssw))
208 if (.not.
allocated(identifier_minorsw)) &
209 allocate(identifier_minorsw(nminorabsorberssw))
210 if (.not.
allocated(minor_gases_lowersw)) &
211 allocate(minor_gases_lowersw(nminor_absorber_intervals_lowersw))
212 if (.not.
allocated(minor_gases_uppersw)) &
213 allocate(minor_gases_uppersw(nminor_absorber_intervals_uppersw))
214 if (.not.
allocated(minor_limits_gpt_lowersw)) &
215 allocate(minor_limits_gpt_lowersw(npairssw,nminor_absorber_intervals_lowersw))
216 if (.not.
allocated(minor_limits_gpt_uppersw)) &
217 allocate(minor_limits_gpt_uppersw(npairssw,nminor_absorber_intervals_uppersw))
218 if (.not.
allocated(band2gptsw)) &
219 allocate(band2gptsw(2,nbndssw))
220 if (.not.
allocated(key_speciessw)) &
221 allocate(key_speciessw(2,nlayerssw,nbndssw))
222 if (.not.
allocated(band_limssw)) &
223 allocate(band_limssw(2,nbndssw))
224 if (.not.
allocated(press_refsw)) &
225 allocate(press_refsw(npresssw))
226 if (.not.
allocated(temp_refsw)) &
227 allocate(temp_refsw(ntempssw))
228 if (.not.
allocated(vmr_refsw)) &
229 allocate(vmr_refsw(nlayerssw, nextrabsorberssw, ntempssw))
230 if (.not.
allocated(kminor_lowersw)) &
231 allocate(kminor_lowersw(ncontributors_lowersw, nmixingfracssw, ntempssw))
232 if (.not.
allocated(kmajorsw)) &
233 allocate(kmajorsw(ngptssw, nmixingfracssw, npresssw+1, ntempssw))
234 if (.not.
allocated(kminor_start_lowersw)) &
235 allocate(kminor_start_lowersw(nminor_absorber_intervals_lowersw))
236 if (.not.
allocated(kminor_uppersw)) &
237 allocate(kminor_uppersw(ncontributors_uppersw, nmixingfracssw, ntempssw))
238 if (.not.
allocated(kminor_start_uppersw)) &
239 allocate(kminor_start_uppersw(nminor_absorber_intervals_uppersw))
240 if (.not.
allocated(minor_scales_with_density_lowersw)) &
241 allocate(minor_scales_with_density_lowersw(nminor_absorber_intervals_lowersw))
242 if (.not.
allocated(minor_scales_with_density_uppersw)) &
243 allocate(minor_scales_with_density_uppersw(nminor_absorber_intervals_uppersw))
244 if (.not.
allocated(scale_by_complement_lowersw)) &
245 allocate(scale_by_complement_lowersw(nminor_absorber_intervals_lowersw))
246 if (.not.
allocated(scale_by_complement_uppersw)) &
247 allocate(scale_by_complement_uppersw(nminor_absorber_intervals_uppersw))
248 if (.not.
allocated(rayl_uppersw)) &
249 allocate(rayl_uppersw(ngptssw, nmixingfracssw, ntempssw))
250 if (.not.
allocated(rayl_lowersw)) &
251 allocate(rayl_lowersw(ngptssw, nmixingfracssw, ntempssw))
252 if (.not.
allocated(solar_quietsw)) &
253 allocate(solar_quietsw(ngptssw))
254 if (.not.
allocated(solar_facularsw)) &
255 allocate(solar_facularsw(ngptssw))
256 if (.not.
allocated(solar_sunspotsw)) &
257 allocate(solar_sunspotsw(ngptssw))
258 if (.not.
allocated(temp1)) &
259 allocate(temp1(nminor_absorber_intervals_lowersw))
260 if (.not.
allocated(temp2)) &
261 allocate(temp2(nminor_absorber_intervals_uppersw))
262 if (.not.
allocated(temp3)) &
263 allocate(temp3(nminor_absorber_intervals_lowersw))
264 if (.not.
allocated(temp4)) &
265 allocate(temp4(nminor_absorber_intervals_uppersw))
274 if (mpirank .eq. mpiroot)
then
276 write (*,*)
'Reading RRTMGP shortwave k-distribution data ... '
277 status = nf90_inq_varid(ncid,
'gas_names', varid)
278 status = nf90_get_var( ncid, varid, gas_namessw)
279 status = nf90_inq_varid(ncid,
'scaling_gas_lower', varid)
280 status = nf90_get_var( ncid, varid, scaling_gas_lowersw)
281 status = nf90_inq_varid(ncid,
'scaling_gas_upper', varid)
282 status = nf90_get_var( ncid, varid, scaling_gas_uppersw)
283 status = nf90_inq_varid(ncid,
'gas_minor', varid)
284 status = nf90_get_var( ncid, varid, gas_minorsw)
285 status = nf90_inq_varid(ncid,
'identifier_minor', varid)
286 status = nf90_get_var( ncid, varid, identifier_minorsw)
287 status = nf90_inq_varid(ncid,
'minor_gases_lower', varid)
288 status = nf90_get_var( ncid, varid, minor_gases_lowersw)
289 status = nf90_inq_varid(ncid,
'minor_gases_upper', varid)
290 status = nf90_get_var( ncid, varid, minor_gases_uppersw)
291 status = nf90_inq_varid(ncid,
'minor_limits_gpt_lower', varid)
292 status = nf90_get_var( ncid, varid, minor_limits_gpt_lowersw)
293 status = nf90_inq_varid(ncid,
'minor_limits_gpt_upper', varid)
294 status = nf90_get_var( ncid, varid, minor_limits_gpt_uppersw)
295 status = nf90_inq_varid(ncid,
'bnd_limits_gpt', varid)
296 status = nf90_get_var( ncid, varid, band2gptsw)
297 status = nf90_inq_varid(ncid,
'key_species', varid)
298 status = nf90_get_var( ncid, varid, key_speciessw)
299 status = nf90_inq_varid(ncid,
'bnd_limits_wavenumber', varid)
300 status = nf90_get_var( ncid, varid, band_limssw)
301 status = nf90_inq_varid(ncid,
'press_ref', varid)
302 status = nf90_get_var( ncid, varid, press_refsw)
303 status = nf90_inq_varid(ncid,
'temp_ref', varid)
304 status = nf90_get_var( ncid, varid, temp_refsw)
305 status = nf90_inq_varid(ncid,
'absorption_coefficient_ref_P', varid)
306 status = nf90_get_var( ncid, varid, temp_ref_psw)
307 status = nf90_inq_varid(ncid,
'absorption_coefficient_ref_T', varid)
308 status = nf90_get_var( ncid, varid, temp_ref_tsw)
309 status = nf90_inq_varid(ncid,
'tsi_default', varid)
310 if (status .eq. 0)
then
311 status = nf90_get_var( ncid, varid, tsi_defaultsw)
313 tsi_defaultsw = tsi_default
315 status = nf90_inq_varid(ncid,
'mg_default', varid)
316 if (status .eq. 0)
then
317 status = nf90_get_var( ncid, varid, mg_defaultsw)
319 mg_defaultsw = mg_default
321 status = nf90_inq_varid(ncid,
'sb_default', varid)
322 if (status .eq. 0)
then
323 status = nf90_get_var( ncid, varid, sb_defaultsw)
325 sb_defaultsw = sb_default
327 status = nf90_inq_varid(ncid,
'press_ref_trop', varid)
328 status = nf90_get_var( ncid, varid, press_ref_tropsw)
329 status = nf90_inq_varid(ncid,
'kminor_lower', varid)
330 status = nf90_get_var( ncid, varid, kminor_lowersw)
331 status = nf90_inq_varid(ncid,
'kminor_upper', varid)
332 status = nf90_get_var( ncid, varid, kminor_uppersw)
333 status = nf90_inq_varid(ncid,
'vmr_ref', varid)
334 status = nf90_get_var( ncid, varid, vmr_refsw)
335 status = nf90_inq_varid(ncid,
'kmajor', varid)
336 status = nf90_get_var( ncid, varid, kmajorsw)
337 status = nf90_inq_varid(ncid,
'kminor_start_lower', varid)
338 status = nf90_get_var( ncid, varid, kminor_start_lowersw)
339 status = nf90_inq_varid(ncid,
'kminor_start_upper', varid)
340 status = nf90_get_var( ncid, varid, kminor_start_uppersw)
341 status = nf90_inq_varid(ncid,
'solar_source_quiet', varid)
342 status = nf90_get_var( ncid, varid, solar_quietsw)
343 status = nf90_inq_varid(ncid,
'solar_source_facular', varid)
344 status = nf90_get_var( ncid, varid, solar_facularsw)
345 status = nf90_inq_varid(ncid,
'solar_source_sunspot', varid)
346 status = nf90_get_var( ncid, varid, solar_sunspotsw)
347 status = nf90_inq_varid(ncid,
'rayl_lower', varid)
348 status = nf90_get_var( ncid, varid, rayl_lowersw)
349 status = nf90_inq_varid(ncid,
'rayl_upper', varid)
350 status = nf90_get_var( ncid, varid, rayl_uppersw)
353 status = nf90_inq_varid(ncid,
'minor_scales_with_density_lower', varid)
354 status = nf90_get_var( ncid, varid,temp1)
355 minor_scales_with_density_lowersw(:) = .false.
356 where(temp1 .eq. 1) minor_scales_with_density_lowersw(:) = .true.
357 status = nf90_inq_varid(ncid,
'minor_scales_with_density_upper', varid)
358 status = nf90_get_var( ncid, varid,temp2)
359 minor_scales_with_density_uppersw(:) = .false.
360 where(temp2 .eq. 1) minor_scales_with_density_uppersw(:) = .true.
361 status = nf90_inq_varid(ncid,
'scale_by_complement_lower', varid)
362 status = nf90_get_var( ncid, varid,temp3)
363 scale_by_complement_lowersw(:) = .false.
364 where(temp3 .eq. 1) scale_by_complement_lowersw(:) = .true.
365 status = nf90_inq_varid(ncid,
'scale_by_complement_upper', varid)
366 status = nf90_get_var( ncid, varid,temp4)
367 scale_by_complement_uppersw(:) = .false.
368 where(temp4 .eq. 1) scale_by_complement_uppersw(:) = .true.
371 status = nf90_close(ncid)
376 call mpi_barrier(mpicomm, mpierr)
386 call mpi_bcast(press_ref_tropsw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
387 call mpi_bcast(temp_ref_psw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
388 call mpi_bcast(temp_ref_tsw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
389 call mpi_bcast(tsi_defaultsw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
390 call mpi_bcast(mg_defaultsw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
391 call mpi_bcast(sb_defaultsw, 1, mpi_double_precision, mpiroot, mpicomm, mpierr)
394 call mpi_bcast(kminor_start_lowersw, &
395 size(kminor_start_lowersw), mpi_integer, mpiroot, mpicomm, mpierr)
396 call mpi_bcast(kminor_start_uppersw, &
397 size(kminor_start_uppersw), mpi_integer, mpiroot, mpicomm, mpierr)
398 call mpi_bcast(band2gptsw, &
399 size(band2gptsw), mpi_integer, mpiroot, mpicomm, mpierr)
400 call mpi_bcast(minor_limits_gpt_lowersw, &
401 size(minor_limits_gpt_lowersw), mpi_integer, mpiroot, mpicomm, mpierr)
402 call mpi_bcast(minor_limits_gpt_uppersw, &
403 size(minor_limits_gpt_uppersw), mpi_integer, mpiroot, mpicomm, mpierr)
404 call mpi_bcast(key_speciessw, &
405 size(key_speciessw), mpi_integer, mpiroot, mpicomm, mpierr)
408 call mpi_bcast(press_refsw, &
409 size(press_refsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
410 call mpi_bcast(temp_refsw, &
411 size(temp_refsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
412 call mpi_bcast(solar_quietsw, &
413 size(solar_quietsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
414 call mpi_bcast(solar_facularsw, &
415 size(solar_facularsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
416 call mpi_bcast(solar_sunspotsw, &
417 size(solar_sunspotsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
418 call mpi_bcast(band_limssw, &
419 size(band_limssw), mpi_double_precision, mpiroot, mpicomm, mpierr)
420 call mpi_bcast(vmr_refsw, &
421 size(vmr_refsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
422 call mpi_bcast(kminor_lowersw, &
423 size(kminor_lowersw), mpi_double_precision, mpiroot, mpicomm, mpierr)
424 call mpi_bcast(kminor_uppersw, &
425 size(kminor_uppersw), mpi_double_precision, mpiroot, mpicomm, mpierr)
426 call mpi_bcast(rayl_lowersw, &
427 size(rayl_lowersw), mpi_double_precision, mpiroot, mpicomm, mpierr)
428 call mpi_bcast(rayl_uppersw, &
429 size(rayl_uppersw), mpi_double_precision, mpiroot, mpicomm, mpierr)
430 call mpi_bcast(kmajorsw, &
431 size(kmajorsw), mpi_double_precision, mpiroot, mpicomm, mpierr)
434 do ichar=1,nabsorberssw
435 call mpi_bcast(gas_namessw(ichar), &
436 len(gas_namessw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
438 do ichar=1,nminorabsorberssw
439 call mpi_bcast(gas_minorsw(ichar), &
440 len(gas_minorsw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
441 call mpi_bcast(identifier_minorsw(ichar), &
442 len(identifier_minorsw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
444 do ichar=1,nminor_absorber_intervals_lowersw
445 call mpi_bcast(minor_gases_lowersw(ichar), &
446 len(minor_gases_lowersw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
447 call mpi_bcast(scaling_gas_lowersw(ichar), &
448 len(scaling_gas_lowersw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
451 do ichar=1,nminor_absorber_intervals_uppersw
452 call mpi_bcast(minor_gases_uppersw(ichar), &
453 len(minor_gases_uppersw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
454 call mpi_bcast(scaling_gas_uppersw(ichar), &
455 len(scaling_gas_uppersw(ichar)), mpi_character, mpiroot, mpicomm, mpierr)
459 call mpi_bcast(minor_scales_with_density_lowersw, &
460 size(minor_scales_with_density_lowersw), mpi_logical, mpiroot, mpicomm, mpierr)
461 call mpi_bcast(minor_scales_with_density_uppersw, &
462 size(minor_scales_with_density_uppersw), mpi_logical, mpiroot, mpicomm, mpierr)
463 call mpi_bcast(scale_by_complement_lowersw, &
464 size(scale_by_complement_lowersw), mpi_logical, mpiroot, mpicomm, mpierr)
465 call mpi_bcast(scale_by_complement_uppersw, &
466 size(scale_by_complement_uppersw), mpi_logical, mpiroot, mpicomm, mpierr)
468 call mpi_barrier(mpicomm, mpierr)
476 call check_error_msg(
'rrtmgp_sw_gas_optics_init_gas_concs',gas_concs%init(active_gases_array))
477 call check_error_msg(
'rrtmgp_sw_gas_optics_init_load',sw_gas_props%load(gas_concs, &
478 gas_namessw, key_speciessw, band2gptsw, band_limssw, press_refsw, press_ref_tropsw,&
479 temp_refsw, temp_ref_psw, temp_ref_tsw, vmr_refsw, kmajorsw, kminor_lowersw, &
480 kminor_uppersw, gas_minorsw, identifier_minorsw, minor_gases_lowersw, &
481 minor_gases_uppersw, minor_limits_gpt_lowersw, minor_limits_gpt_uppersw, &
482 minor_scales_with_density_lowersw, minor_scales_with_density_uppersw, &
483 scaling_gas_lowersw, scaling_gas_uppersw, scale_by_complement_lowersw, &
484 scale_by_complement_uppersw, kminor_start_lowersw, kminor_start_uppersw, &
485 solar_quietsw, solar_facularsw, solar_sunspotsw, tsi_defaultsw, mg_defaultsw, &
486 sb_defaultsw, rayl_lowersw, rayl_uppersw))