scalar_property.f90 Source File


This file depends on

sourcefile~~scalar_property.f90~~EfferentGraph sourcefile~scalar_property.f90 scalar_property.f90 sourcefile~base.f90 base.f90 sourcefile~scalar_property.f90->sourcefile~base.f90 sourcefile~constants.f90 constants.f90 sourcefile~scalar_property.f90->sourcefile~constants.f90 sourcefile~base.f90->sourcefile~constants.f90

Files dependent on this one

sourcefile~~scalar_property.f90~~AfferentGraph sourcefile~scalar_property.f90 scalar_property.f90 sourcefile~critical_constants.f90 critical_constants.f90 sourcefile~critical_constants.f90->sourcefile~scalar_property.f90 sourcefile~properties.f90 properties.f90 sourcefile~properties.f90->sourcefile~scalar_property.f90 sourcefile~properties.f90->sourcefile~critical_constants.f90 sourcefile~forsus.f90 forsus.F90 sourcefile~forsus.f90->sourcefile~properties.f90 sourcefile~substance.f90 substance.f90 sourcefile~forsus.f90->sourcefile~substance.f90 sourcefile~substance.f90->sourcefile~properties.f90

Source Code

module forsus_properties_scalar
    use forsus_constants, only: pr, forsus_default_dir, forsus_dir
    use forsus_properties_base, only: Property, open_json
    use json_module, only: json_file
    implicit none

    type, extends(Property) :: ScalarProperty
        !! Scalar property.
        !!
        !! A property with a single scalar value, like a critical constant.
        real(pr) :: value !! Property value
    contains
        procedure :: from_json => scalar_from_json
    end type ScalarProperty

contains

    impure elemental subroutine scalar_from_json(self, name, json_str, path)
        !! Setup a scalar property from a provided json key and json file path.
        use iso_fortran_env, only: error_unit
        class(ScalarProperty), intent(in out) :: self
        character(len=*), intent(in) :: name
            !! Property name. Should be the key in the `json` file.
        character(len=*), intent(in) :: json_str
            !! `json` file relative path to executable.
        character(len=*), optional, intent(in) :: path
            !! `json` file relative path to executable.

        type(json_file) :: json

        self%name = name

        json = open_json(json_str, path)
        call json%initialize()

        if (present(path)) then
            call json%load_file(path//"/"//json_str)
        else
            if (allocated(forsus_dir)) then
                call json%load_file(forsus_dir//"/"//json_str)
            else
                call json%load_file(forsus_default_dir//"/"//json_str)
            end if
        end if

        call json%get(self%name//".value(1)", self%value)
        call json%get(self%name//".units", self%units)
    end subroutine scalar_from_json
end module forsus_properties_scalar