src/fmu/common_fmu2.c
ObjectContainer * Fmu2ReadParams(ParametersInput * input, fmi2_import_t * import, ObjectContainer * ignore) {
    ObjectContainer * params = (ObjectContainer *) object_create(ObjectContainer);
    ObjectContainer * ret = params;                  // used for unified cleanup via goto

    size_t i = 0;
    size_t num = 0;
    McxStatus retVal = RETURN_OK;

    if (!params) {
        return NULL;
    }

    num = input->parameters->Size(input->parameters);
    for (i = 0; i < num; i++) {
        ParameterInput * parameterInput = (ParameterInput *) input->parameters->At(input->parameters, i);

        char * name = NULL;
        Fmu2Value * val = NULL;
        ObjectContainer * vals = NULL;


        name = mcx_string_copy(parameterInput->parameter.arrayParameter->name);
        if (!name) {
            ret = NULL;
            goto fmu2_read_params_for_cleanup;
        }

        // ignore the parameter if it is in the `ignore` container
        if (ignore && ignore->GetNameIndex(ignore, name) >= 0) {
            goto fmu2_read_params_for_cleanup;
        }

        if (parameterInput->type == PARAMETER_ARRAY) {
            // read parameter dimensions (if any) - should only be defined for array parameters
            if (parameterInput->parameter.arrayParameter->numDims >=2 &&
                parameterInput->parameter.arrayParameter->dims[1] &&
                !parameterInput->parameter.arrayParameter->dims[0]) {
                mcx_log(LOG_ERROR, "FMU: Array parameter %s: Missing definition for the first dimension "
                        "while the second dimension is defined.", parameterInput->parameter.arrayParameter->name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }

            // array - split it into scalars
            vals = Fmu2ReadArrayParamValues(name, parameterInput->parameter.arrayParameter, import, params);
            if (vals == NULL) {
                mcx_log(LOG_ERROR, "FMU: Could not read array parameter %s", name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }

            // store the scalar values
            size_t j = 0;
            for (j = 0; j < vals->Size(vals); j++) {
                Object * v = vals->At(vals, j);
                retVal = params->PushBackNamed(params, v, ((Fmu2Value*)v)->name);
                if (RETURN_OK != retVal) {
                    ret = NULL;
                    goto fmu2_read_params_for_cleanup;
                }
            }

            object_destroy(vals);
        } else {
            // read the scalar value
            val = Fmu2ReadParamValue(parameterInput->parameter.scalarParameter, import);
            if (val == NULL) {
                mcx_log(LOG_ERROR, "FMU: Could not read parameter value of parameter %s", name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }

            // store the read value
            retVal = params->PushBackNamed(params, (Object * ) val, name);
            if (RETURN_OK != retVal) {
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }
        }

fmu2_read_params_for_cleanup:
        if (name) { mcx_free(name); }
        if (ret == NULL) {
            if (val)  { object_destroy(val); }
            if (vals) {
                vals->DestroyObjects(vals);
                object_destroy(vals);
            }

            goto cleanup;
        }
    }

    {
        size_t i = 0;
        size_t n = params->Size(params);

        if (n > 0) {
            McxStatus status = RETURN_OK;
            status = params->Sort(params, NaturalComp, NULL);
            if (RETURN_OK != status) {
                mcx_log(LOG_ERROR, "FMU: Unable to sort parameters");
                ret = NULL;
                goto cleanup;
            }

            for (i = 0; i < n - 1; i++) {
                Fmu2Value * a = (Fmu2Value *) params->At(params, i);
                Fmu2Value * b = (Fmu2Value *) params->At(params, i + 1);

                if (! strcmp(a->name, b->name)) {
                    mcx_log(LOG_ERROR, "FMU: Duplicate definition of parameter %s", a->name);
                    ret = NULL;
                    goto cleanup;
                }
            }
        }
    }

cleanup:
    if (ret == NULL) {
        params->DestroyObjects(params);
        object_destroy(params);
    }

    return ret;
}
// Reads parameters from the input file (both scalar and array).
//
// Ignores parameters provided via the `ignore` argument.
Reads parameters from the input file (both scalar and array).
Ignores parameters provided via the `ignore` argument.
Reads parameters from the input file ( both scalar and array ) . Ignores parameters provided via the ` ignore ` argument .
ObjectContainer * Fmu2ReadParams(ParametersInput * input, fmi2_import_t * import, ObjectContainer * ignore) {
    ObjectContainer * params = (ObjectContainer *) object_create(ObjectContainer);
    ObjectContainer * ret = params;                  
    size_t i = 0;
    size_t num = 0;
    McxStatus retVal = RETURN_OK;
    if (!params) {
        return NULL;
    }
    num = input->parameters->Size(input->parameters);
    for (i = 0; i < num; i++) {
        ParameterInput * parameterInput = (ParameterInput *) input->parameters->At(input->parameters, i);
        char * name = NULL;
        Fmu2Value * val = NULL;
        ObjectContainer * vals = NULL;
        name = mcx_string_copy(parameterInput->parameter.arrayParameter->name);
        if (!name) {
            ret = NULL;
            goto fmu2_read_params_for_cleanup;
        }
        if (ignore && ignore->GetNameIndex(ignore, name) >= 0) {
            goto fmu2_read_params_for_cleanup;
        }
        if (parameterInput->type == PARAMETER_ARRAY) {
            if (parameterInput->parameter.arrayParameter->numDims >=2 &&
                parameterInput->parameter.arrayParameter->dims[1] &&
                !parameterInput->parameter.arrayParameter->dims[0]) {
                mcx_log(LOG_ERROR, "FMU: Array parameter %s: Missing definition for the first dimension "
                        "while the second dimension is defined.", parameterInput->parameter.arrayParameter->name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }
            vals = Fmu2ReadArrayParamValues(name, parameterInput->parameter.arrayParameter, import, params);
            if (vals == NULL) {
                mcx_log(LOG_ERROR, "FMU: Could not read array parameter %s", name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }
            size_t j = 0;
            for (j = 0; j < vals->Size(vals); j++) {
                Object * v = vals->At(vals, j);
                retVal = params->PushBackNamed(params, v, ((Fmu2Value*)v)->name);
                if (RETURN_OK != retVal) {
                    ret = NULL;
                    goto fmu2_read_params_for_cleanup;
                }
            }
            object_destroy(vals);
        } else {
            val = Fmu2ReadParamValue(parameterInput->parameter.scalarParameter, import);
            if (val == NULL) {
                mcx_log(LOG_ERROR, "FMU: Could not read parameter value of parameter %s", name);
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }
            retVal = params->PushBackNamed(params, (Object * ) val, name);
            if (RETURN_OK != retVal) {
                ret = NULL;
                goto fmu2_read_params_for_cleanup;
            }
        }
fmu2_read_params_for_cleanup:
        if (name) { mcx_free(name); }
        if (ret == NULL) {
            if (val)  { object_destroy(val); }
            if (vals) {
                vals->DestroyObjects(vals);
                object_destroy(vals);
            }
            goto cleanup;
        }
    }
    {
        size_t i = 0;
        size_t n = params->Size(params);
        if (n > 0) {
            McxStatus status = RETURN_OK;
            status = params->Sort(params, NaturalComp, NULL);
            if (RETURN_OK != status) {
                mcx_log(LOG_ERROR, "FMU: Unable to sort parameters");
                ret = NULL;
                goto cleanup;
            }
            for (i = 0; i < n - 1; i++) {
                Fmu2Value * a = (Fmu2Value *) params->At(params, i);
                Fmu2Value * b = (Fmu2Value *) params->At(params, i + 1);
                if (! strcmp(a->name, b->name)) {
                    mcx_log(LOG_ERROR, "FMU: Duplicate definition of parameter %s", a->name);
                    ret = NULL;
                    goto cleanup;
                }
            }
        }
    }
cleanup:
    if (ret == NULL) {
        params->DestroyObjects(params);
        object_destroy(params);
    }
    return ret;
}
ObjectContainer * Fmu2ReadParams ( ParametersInput * input , fmi2_import_t * import , ObjectContainer * ignore ) { ObjectContainer * params = ( ObjectContainer * ) object_create ( ObjectContainer ) ; ObjectContainer * ret = params ; size_t i = 0 ; size_t num = 0 ; McxStatus retVal = RETURN_OK ; if ( ! params ) { return NULL ; } num = input -> parameters -> Size ( input -> parameters ) ; for ( i = 0 ; i < num ; i ++ ) { ParameterInput * parameterInput = ( ParameterInput * ) input -> parameters -> At ( input -> parameters , i ) ; char * name = NULL ; Fmu2Value * val = NULL ; ObjectContainer * vals = NULL ; name = mcx_string_copy ( parameterInput -> parameter . arrayParameter -> name ) ; if ( ! name ) { ret = NULL ; goto fmu2_read_params_for_cleanup ; } if ( ignore && ignore -> GetNameIndex ( ignore , name ) >= 0 ) { goto fmu2_read_params_for_cleanup ; } if ( parameterInput -> type == PARAMETER_ARRAY ) { if ( parameterInput -> parameter . arrayParameter -> numDims >= 2 && parameterInput -> parameter . arrayParameter -> dims [ 1 ] && ! parameterInput -> parameter . arrayParameter -> dims [ 0 ] ) { mcx_log ( LOG_ERROR , " " " " , parameterInput -> parameter . arrayParameter -> name ) ; ret = NULL ; goto fmu2_read_params_for_cleanup ; } vals = Fmu2ReadArrayParamValues ( name , parameterInput -> parameter . arrayParameter , import , params ) ; if ( vals == NULL ) { mcx_log ( LOG_ERROR , " " , name ) ; ret = NULL ; goto fmu2_read_params_for_cleanup ; } size_t j = 0 ; for ( j = 0 ; j < vals -> Size ( vals ) ; j ++ ) { Object * v = vals -> At ( vals , j ) ; retVal = params -> PushBackNamed ( params , v , ( ( Fmu2Value * ) v ) -> name ) ; if ( RETURN_OK != retVal ) { ret = NULL ; goto fmu2_read_params_for_cleanup ; } } object_destroy ( vals ) ; } else { val = Fmu2ReadParamValue ( parameterInput -> parameter . scalarParameter , import ) ; if ( val == NULL ) { mcx_log ( LOG_ERROR , " " , name ) ; ret = NULL ; goto fmu2_read_params_for_cleanup ; } retVal = params -> PushBackNamed ( params , ( Object * ) val , name ) ; if ( RETURN_OK != retVal ) { ret = NULL ; goto fmu2_read_params_for_cleanup ; } } fmu2_read_params_for_cleanup : if ( name ) { mcx_free ( name ) ; } if ( ret == NULL ) { if ( val ) { object_destroy ( val ) ; } if ( vals ) { vals -> DestroyObjects ( vals ) ; object_destroy ( vals ) ; } goto cleanup ; } } { size_t i = 0 ; size_t n = params -> Size ( params ) ; if ( n > 0 ) { McxStatus status = RETURN_OK ; status = params -> Sort ( params , NaturalComp , NULL ) ; if ( RETURN_OK != status ) { mcx_log ( LOG_ERROR , " " ) ; ret = NULL ; goto cleanup ; } for ( i = 0 ; i < n - 1 ; i ++ ) { Fmu2Value * a = ( Fmu2Value * ) params -> At ( params , i ) ; Fmu2Value * b = ( Fmu2Value * ) params -> At ( params , i + 1 ) ; if ( ! strcmp ( a -> name , b -> name ) ) { mcx_log ( LOG_ERROR , " " , a -> name ) ; ret = NULL ; goto cleanup ; } } } } cleanup : if ( ret == NULL ) { params -> DestroyObjects ( params ) ; object_destroy ( params ) ; } return ret ; }
Reads parameters from the input file (both scalar and array).
Reads parameters from the input file ( both scalar and array ) .
// used for unified cleanup via goto // ignore the parameter if it is in the `ignore` container // read parameter dimensions (if any) - should only be defined for array parameters // array - split it into scalars // store the scalar values // read the scalar value // store the read value