Analysis Plugins > Reference > Types > AnalysisConstants

AnalysisConstants

Holds a set user defined constants as defined in Options tab of the Sizing form.

Field Type
Constants UserConstant[10]

Referenced by: Hs_UDef

Fortran Example

function GetUserConstantValue(analysisConstants, name, defaultValue) result(userValue)

 

    ! Return the user value for a given constant name by looping through all of the constants for all analyses.

    ! If the constant does not exist - use the default value passed in by the caller.

 

    real(4) :: userValue

    type(AnalysisConstantsType), intent(in) :: analysisConstants(:)

    character(len=LEN_CNAME), intent(in) :: name

    real(4), intent(in) :: defaultValue

    integer :: i, j

 

    userValue = defaultValue

 

    do i = 1, ubound(analysisConstants, 1)

        do j = 1, ubound(analysisConstants(i)%Constants, 1)

            if (len_trim(analysisConstants(i)%Constants(j)%Name) == 0) then

                cycle

            end if

           if (index(analysisConstants(i)%Constants(j)%Name, name) > 0) then

                userValue= analysisConstants(i)%Constants(j)%Value

                exit

            end if

        end do

    end do

 

end function

C++ Example

inline bool TryGetUserConstant(AnalysisConstants analysisConstants[], const char* name, double* valueOut)

{

    // Returns a user constant value. Searches all analyses.

    // Returns false if the constant is not found.

 

    // Copy name to a temp variable so that it is truncated to LEN_CNAME (if necessary).

    char tempName[LEN_CNAME];

    CopyString(tempName, name, LEN_CNAME);

 

    const int ANALYSIS_COUNT = 10; // Hardcoded in V7.0. In V7.1, this number will be dynamic and the AnalysisConstants change.

    for (int i = 0; i < ANALYSIS_COUNT; i++)

    {

        auto analysisConstant = &(analysisConstants[i]);

        for (int c = 0; c < MAX_CONS; c++)

        {

            auto constant = analysisConstant->Constants[c];

            if (strcmp(constant.Name, tempName) == 0)

            {

                // Name found.

                *valueOut = constant.Value;

                return true;

            }

            else if (strlen(constant.Name) == 0)

            {

                // No more names for this analysis. Early exit from the inner (c) loop.

                break;

            }

        }

    }

 

    // Constant not found.

    *valueOut = 0;

    return false;

}