예제 #1
0
static void
init_compare(t_topology * /* top */, int /* npar */, gmx_ana_selparam_t *param, void *data)
{
    t_methoddata_compare *d = (t_methoddata_compare *)data;
    int                   n1, n2;

    /* Store the values */
    n1 = init_comparison_value(&d->left, &param[0]);
    n2 = init_comparison_value(&d->right, &param[3]);
    /* Store the comparison type */
    d->cmpt = comparison_type(d->cmpop);
    if (d->cmpt == CMP_INVALID)
    {
        GMX_THROW(gmx::InternalError("Invalid comparison type"));
    }
    /* Convert the values to the same type */
    /* TODO: Currently, there are no dynamic integer-valued selection methods,
     * which means that only the branches with convert_int_real() will ever be
     * taken. It should be considered whether it is necessary to support these
     * other cases at all.
     */
    if ((d->left.flags & CMP_REALVAL) && !(d->right.flags & CMP_REALVAL))
    {
        if (d->left.flags & d->right.flags & CMP_DYNAMICVAL)
        {
            /* Nothing can be done */
        }
        else if (!(d->right.flags & CMP_DYNAMICVAL))
        {
            convert_int_real(n2, &d->right);
        }
        else /* d->left is static */
        {
            convert_real_int(n1, &d->left, d->cmpt, false);
        }
    }
    else if (!(d->left.flags & CMP_REALVAL) && (d->right.flags & CMP_REALVAL))
    {
        if (d->left.flags & d->right.flags & CMP_DYNAMICVAL)
        {
            /* Reverse the sides to place the integer on the right */
            int    flags;
            d->left.r      = d->right.r;
            d->right.r     = NULL;
            d->right.i     = d->left.i;
            d->left.i      = NULL;
            flags          = d->left.flags;
            d->left.flags  = d->right.flags;
            d->right.flags = flags;
            d->cmpt        = reverse_comparison_type(d->cmpt);
        }
        else if (!(d->left.flags & CMP_DYNAMICVAL))
        {
            convert_int_real(n1, &d->left);
        }
        else /* d->right is static */
        {
            convert_real_int(n2, &d->right, d->cmpt, true);
        }
    }
}
예제 #2
0
/*!
 * \param[in] top   Not used.
 * \param[in] npar  Not used (should be 5).
 * \param[in] param Method parameters (should point to \ref smparams_compare).
 * \param[in] data  Should point to a \c t_methoddata_compare.
 * \returns   0 if the input data is valid, -1 on error.
 */
static int
init_compare(t_topology *top, int npar, gmx_ana_selparam_t *param, void *data)
{
    t_methoddata_compare *d = (t_methoddata_compare *)data;
    int                   n1, n2;

    /* Store the values */
    n1 = init_comparison_value(&d->left, &param[0]);
    n2 = init_comparison_value(&d->right, &param[3]);
    if (n1 == 0 || n2 == 0)
    {
        gmx_bug("one of the values for comparison missing");
        return -1;
    }
    /* Store the comparison type */
    d->cmpt = comparison_type(d->cmpop);
    if (d->cmpt == CMP_INVALID)
    {
        gmx_bug("invalid comparison type");
        return -1;
    }
    /* Convert the values to the same type */
    if ((d->left.flags & CMP_REALVAL) && !(d->right.flags & CMP_REALVAL))
    {
        if (d->left.flags & d->right.flags & CMP_DYNAMICVAL)
        {
            /* Nothing can be done */
        }
        else if (!(d->right.flags & CMP_DYNAMICVAL))
        {
            convert_int_real(n2, &d->right);
        }
        else /* d->left is static */
        {
            if (convert_real_int(n1, &d->left, d->cmpt, FALSE))
            {
                return -1;
            }
        }
    }
    else if (!(d->left.flags & CMP_REALVAL) && (d->right.flags & CMP_REALVAL))
    {
        if (d->left.flags & d->right.flags & CMP_DYNAMICVAL)
        {
            /* Reverse the sides to place the integer on the right */
            int    flags;
            d->left.r  = d->right.r;
            d->right.r = NULL;
            d->right.i = d->left.i;
            d->left.i  = NULL;
            flags          = d->left.flags;
            d->left.flags  = d->right.flags;
            d->right.flags = flags;
            d->cmpt = reverse_comparison_type(d->cmpt);
        }
        else if (!(d->left.flags & CMP_DYNAMICVAL))
        {
            convert_int_real(n1, &d->left);
        }
        else /* d->right is static */
        {
            if (convert_real_int(n2, &d->right, d->cmpt, TRUE))
            {
                return -1;
            }
        }
    }
    return 0;
}