345 integer(kind=i_kind),
intent(in) :: spec_state_id
347 type(
property_t),
pointer :: sections, section, phases
348 integer(kind=i_kind) :: i_section, i_phase, j_phase, k_phase, &
350 integer(kind=i_kind) :: curr_spec_state_id
351 integer(kind=i_kind) :: num_phase, num_bin
352 integer(kind=i_kind) :: n_int_param, n_float_param
353 character(len=:),
allocatable :: key_name, phase_name, sect_type, str_val
354 real(kind=dp) :: min_dp, max_dp, d_log_dp
357 n_int_param = num_int_prop_
358 n_float_param = num_real_prop_
361 key_name =
"modes/bins"
363 this%property_set%get_property_t(key_name, sections), &
364 "Missing sections/bins for modal/binned mass aerosol "// &
365 "representation '"//this%rep_name//
"'")
366 call assert_msg(894962494, sections%size().gt.0,
"No sections or bins "// &
367 "specified for modal/binned mass aerosol representation '"// &
371 allocate(this%section_name(sections%size()))
376 call sections%iter_reset()
377 do i_section = 1, sections%size()
380 call assert(867378489, sections%get_key(key_name))
381 call assert_msg(234513113, len(key_name).gt.0,
"Missing mode/bin "// &
382 "name in modal/binned mass aerosol representation '"// &
384 this%section_name(i_section)%string = key_name
387 call assert_msg(517138327, sections%get_property_t(val=section), &
388 "Invalid structure for mode/bin '"// &
389 this%section_name(i_section)%string// &
390 "' in modal/binned mass aerosol representation '"// &
395 call assert_msg(742404898, section%get_string(key_name, sect_type), &
396 "Missing mode/bin type in mode/bin '"// &
397 this%section_name(i_section)%string// &
398 "' in modal/binned mass aerosol representation '"// &
401 sect_type.eq.
"MODAL".or.sect_type.eq.
"BINNED", &
402 "Invalid mode/bin type '"//sect_type//
"' in mode/bin '"// &
403 this%section_name(i_section)%string// &
404 "' in modal/binned mass aerosol representation '"// &
409 if (sect_type.eq.
"BINNED")
then
412 call assert_msg(824494286, section%get_int(key_name, num_bin), &
413 "Missing number of bins in bin '"// &
414 this%section_name(i_section)%string// &
415 "' in modal/binned mass aerosol representation '"// &
421 n_int_param = n_int_param + 5
425 n_float_param = n_float_param + 3*num_bin
429 call assert_msg(815518058, section%get_property_t(key_name, phases), &
430 "Missing phases for mode '"// &
431 this%section_name(i_section)%string// &
432 "' in modal/binned mass aerosol representation '"// &
436 call assert_msg(772593427, phases%size().gt.0, &
437 "No phases specified for mode '"// &
438 this%section_name(i_section)%string// &
439 "' in modal/binned mass aerosol representation '"// &
441 num_phase = num_phase + phases%size() * num_bin
444 call phases%iter_reset()
445 do i_phase = 1, phases%size()
448 call assert_msg(393427582, phases%get_string(val=phase_name), &
449 "Non-string phase name for mode '"// &
450 this%section_name(i_section)%string// &
451 "' in modal/binned mass aerosol representation '"// &
455 do j_phase = 1,
size(aero_phase_set)
456 if (phase_name.eq.aero_phase_set(j_phase)%val%name())
then
460 n_int_param = n_int_param + 3 * num_bin
463 n_float_param = n_float_param + 2 * num_bin
466 else if (j_phase.eq.
size(aero_phase_set))
then
467 call die_msg(652391420,
"Non-existant aerosol phase '"// &
468 phase_name//
"' specified for mode '"// &
469 this%section_name(i_section)%string// &
470 "' in modal/binned mass aerosol representation '"// &
475 call phases%iter_next()
478 call sections%iter_next()
482 allocate(this%aero_phase(num_phase))
483 allocate(this%aero_phase_is_at_surface(num_phase))
484 allocate(this%phase_state_id(
size(this%aero_phase)))
487 allocate(this%condensed_data_int(n_int_param))
488 allocate(this%condensed_data_real(n_float_param))
489 this%condensed_data_int(:) = int(0, kind=i_kind)
490 this%condensed_data_real(:) = real(0.0, kind=dp)
491 int_data_size_ = n_int_param
492 real_data_size_ = n_float_param
495 num_section_ = sections%size()
498 this%num_env_params = 2 * num_section_
504 n_int_param = num_int_prop_+2*num_section_+1
505 n_float_param = num_real_prop_+1
506 call sections%iter_reset()
507 do i_section = 1, num_section_
510 mode_int_prop_loc_(i_section) = n_int_param
511 mode_real_prop_loc_(i_section) = n_float_param
514 call assert(394743663, sections%get_property_t(val=section))
518 call assert(667058653, section%get_string(key_name, sect_type))
519 if (sect_type.eq.
"MODAL")
then
520 section_type_(i_section) = modal
521 else if (sect_type.eq.
"BINNED")
then
522 section_type_(i_section) = binned
524 call die_msg(256924433,
"Internal error")
528 num_bins_(i_section) = 1
529 if (section_type_(i_section).eq.binned)
then
531 call assert(315215287, section%get_int(key_name, num_bins_(i_section)))
535 if (section_type_(i_section).eq.modal)
then
539 effective_radius_(i_section,1) = -9999.9
540 number_conc_(i_section,1) = -9999.9
543 else if (section_type_(i_section).eq.binned)
then
546 key_name =
"minimum diameter [m]"
547 call assert_msg(548762180, section%get_real(key_name, min_dp), &
548 "Missing minimum diameter for bin '"// &
549 this%section_name(i_section)%string// &
550 "' in modal/binned mass aerosol representation '"// &
554 key_name =
"maximum diameter [m]"
555 call assert_msg(288632226, section%get_real(key_name, max_dp), &
556 "Missing maximum diameter for bin '"// &
557 this%section_name(i_section)%string// &
558 "' in modal/binned mass aerosol representation '"// &
563 call assert_msg(404761639, section%get_string(key_name, str_val), &
564 "Missing bin scale for bin '"// &
565 this%section_name(i_section)%string// &
566 "' in modal/binned mass aerosol representation '"// &
570 if (str_val.eq.
"LINEAR")
then
571 do i_bin = 1, num_bins_(i_section)
572 bin_dp_(i_section,i_bin) = min_dp + &
573 (i_bin-1) * (max_dp-min_dp)/(num_bins_(i_section)-1)
575 else if (str_val.eq.
"LOG")
then
576 d_log_dp = (log10(max_dp)-log10(min_dp))/(num_bins_(i_section)-1)
577 do i_bin = 1, num_bins_(i_section)
578 bin_dp_(i_section,i_bin) = 10.0d0**( log10(min_dp) + &
579 (i_bin-1) * d_log_dp )
582 call die_msg(236797392,
"Invalid scale specified for bin '"// &
583 this%section_name(i_section)%string// &
584 "' in modal/binned mass aerosol representation '"// &
587 do i_bin = 1, num_bins_(i_section)
589 effective_radius_(i_section,i_bin) = bin_dp_(i_section,i_bin) / 2.0
590 number_conc_(i_section,i_bin) = -9999.9
596 call assert(712411046, section%get_property_t(key_name, phases))
599 num_phase_(i_section) = phases%size()
602 n_int_param = n_int_param + 3
605 n_float_param = n_float_param + 3 * num_bins_(i_section)
608 call phases%iter_reset()
609 do j_phase = 1, phases%size()
612 call assert(775801035, phases%get_string(val=phase_name))
615 do k_phase = 1,
size(aero_phase_set)
616 if (phase_name.eq.aero_phase_set(k_phase)%val%name())
then
619 do i_bin = 1, num_bins_(i_section)
622 this%aero_phase(i_phase) = aero_phase_set(k_phase)
625 this%aero_phase_is_at_surface(i_phase) = .true.
628 this%phase_state_id(i_phase) = curr_spec_state_id
629 phase_state_id_(i_section, j_phase, i_bin) = curr_spec_state_id
632 curr_spec_state_id = curr_spec_state_id + &
633 aero_phase_set(k_phase)%val%size()
636 phase_model_data_id_(i_section, j_phase, i_bin) = k_phase
638 i_phase = i_phase + 1
643 n_int_param = n_int_param + 3*num_bins_(i_section)
646 n_float_param = n_float_param + 2*num_bins_(i_section)
649 else if (k_phase.eq.
size(aero_phase_set))
then
650 call die_msg(652391420,
"Internal error.")
654 call phases%iter_next()
657 call sections%iter_next()
664 call assert(951534966, i_phase-1.eq.num_phase)
665 call assert(951534966, n_int_param.eq.int_data_size_+1)
666 call assert(325387136, n_float_param.eq.real_data_size_+1)
748 character(len=*),
optional,
intent(in) :: phase_name
750 integer(kind=i_kind),
optional,
intent(in) :: tracer_type
752 character(len=*),
optional,
intent(in) ::
spec_name
754 logical,
optional,
intent(in) :: phase_is_at_surface
756 integer(kind=i_kind) :: num_spec, i_spec, j_spec, i_phase, j_phase, &
758 integer(kind=i_kind) :: curr_tracer_type
759 character(len=:),
allocatable :: curr_section_name, curr_phase_name, &
761 type(
string_t),
allocatable :: spec_names(:)
765 do i_phase = 1,
size(this%aero_phase)
768 if (
present(phase_name))
then
769 curr_phase_name = this%aero_phase(i_phase)%val%name()
770 if (phase_name.ne.curr_phase_name) cycle
774 if (
present(phase_is_at_surface))
then
775 if (phase_is_at_surface .neqv. &
776 this%aero_phase_is_at_surface(i_phase)) cycle
780 if (
present(
spec_name).or.
present(tracer_type))
then
781 spec_names = this%aero_phase(i_phase)%val%get_species_names()
782 do j_spec = 1,
size(spec_names)
784 this%aero_phase(i_phase)%val%get_species_type( &
785 spec_names(j_spec)%string)
787 if (
spec_name.ne.spec_names(j_spec)%string) cycle
789 if (
present(tracer_type))
then
790 if (tracer_type.ne.curr_tracer_type) cycle
792 num_spec = num_spec + 1
795 num_spec = num_spec + this%aero_phase(i_phase)%val%size()
806 do i_section = 1, num_section_
809 curr_section_name = this%section_name(i_section)%string
812 do j_phase = 1, num_phase_(i_section)
815 curr_phase_name = this%aero_phase(i_phase)%val%name()
818 if (
present(phase_name))
then
819 if (phase_name.ne.curr_phase_name)
then
820 i_phase = i_phase + num_bins_(i_section)
826 if (
present(phase_is_at_surface))
then
827 if (phase_is_at_surface .neqv. &
828 this%aero_phase_is_at_surface(i_phase))
then
829 i_phase = i_phase + num_bins_(i_section)
835 spec_names = this%aero_phase(i_phase)%val%get_species_names()
838 do i_bin = 1, num_bins_(i_section)
841 if (num_bins_(i_section).gt.1)
then
842 curr_bin_str = trim(
to_string(i_bin))//
"."
848 num_spec = this%aero_phase(i_phase)%val%size()
849 do j_spec = 1, num_spec
853 if (
spec_name.ne.spec_names(j_spec)%string) cycle
857 if (
present(tracer_type))
then
859 this%aero_phase(i_phase)%val%get_species_type( &
860 spec_names(j_spec)%string)
861 if (tracer_type.ne.curr_tracer_type) cycle
865 unique_names(i_spec)%string = curr_section_name//
"."// &
866 curr_bin_str//curr_phase_name//
'.'// &
867 spec_names(j_spec)%string
873 i_phase = i_phase + 1
877 deallocate(spec_names)