evaluate = cdata->evaluate;
if (cdata->flags & SEL_CDATA_MINMAXALLOC)
{
- cdata->gmin->name = NULL;
- cdata->gmax->name = NULL;
gmx_ana_index_deinit(cdata->gmin);
gmx_ana_index_deinit(cdata->gmax);
sfree(cdata->gmin);
{
std::string name(gmx::formatString("SubExpr %d", i));
sel->setName(name);
- sel->u.cgrp.name = strdup(name.c_str());
}
/*! \brief
if (root->child->type != SEL_SUBEXPR
|| (root->child->v.type != GROUP_VALUE && !(root->flags & SEL_ATOMVAL)))
{
- gmx_ana_index_set(&root->u.cgrp, -1, 0, root->u.cgrp.name, 0);
+ gmx_ana_index_set(&root->u.cgrp, -1, 0, 0);
}
else if (root->child->cdata->flags & SEL_CDATA_FULLEVAL)
{
- gmx_ana_index_set(&root->u.cgrp, sc->gall.isize, sc->gall.index,
- root->u.cgrp.name, 0);
+ gmx_ana_index_set(&root->u.cgrp, sc->gall.isize, sc->gall.index, 0);
}
root = root->next;
}
* */
if (sel->v.type == GROUP_VALUE)
{
- gmx_ana_index_set(&sel->u.cgrp, sel->v.u.g->isize, sel->v.u.g->index, NULL, 0);
+ gmx_ana_index_set(&sel->u.cgrp, sel->v.u.g->isize, sel->v.u.g->index, 0);
}
}
* and hence we can overwrite it safely. */
if (child->u.cgrp.nalloc_index > 0)
{
- char *name = child->u.cgrp.name;
gmx_ana_index_copy(&child->u.cgrp, child->v.u.g, false);
gmx_ana_index_squeeze(&child->u.cgrp);
- child->u.cgrp.name = name;
}
else
{
gmx_ana_index_copy(sel->child->v.u.g, gmin, false);
if (sel->child->u.cgrp.nalloc_index > 0)
{
- /* Keep the name as in evaluate_boolean_static_part(). */
- char *name = sel->child->u.cgrp.name;
gmx_ana_index_reserve(&sel->child->u.cgrp, gmin->isize);
gmx_ana_index_copy(&sel->child->u.cgrp, gmin, false);
- sel->child->u.cgrp.name = name;
}
else
{
{
gmx_ana_index_squeeze(sel->cdata->gmin);
gmx_ana_index_squeeze(sel->cdata->gmax);
- sfree(sel->cdata->gmin->name);
- sfree(sel->cdata->gmax->name);
- sel->cdata->gmin->name = NULL;
- sel->cdata->gmax->name = NULL;
}
/* Replace the result of the evaluation */
}
/* Set the evaluation group */
- char *name = root->u.cgrp.name;
if (root->evaluate)
{
/* Non-atom-valued non-group expressions don't care about the group, so
if ((expr->flags & SEL_VARNUMVAL)
|| ((expr->flags & SEL_SINGLEVAL) && expr->v.type != GROUP_VALUE))
{
- gmx_ana_index_set(&root->u.cgrp, -1, NULL, NULL, 0);
+ gmx_ana_index_set(&root->u.cgrp, -1, NULL, 0);
}
else if (expr->cdata->gmax->isize == gall->isize)
{
/* Save some memory by only referring to the global group. */
- gmx_ana_index_set(&root->u.cgrp, gall->isize, gall->index, NULL, 0);
+ gmx_ana_index_set(&root->u.cgrp, gall->isize, gall->index, 0);
}
else
{
{
gmx_ana_index_clear(&root->u.cgrp);
}
- root->u.cgrp.name = name;
}
&& (sel->cdata->flags & SEL_CDATA_STATICEVAL)
&& !(sel->cdata->flags & SEL_CDATA_FULLEVAL))
{
- char *name;
-
/* We need to free memory allocated for the group, because it is no
* longer needed (and would be lost on next call to the evaluation
- * function). But we need to preserve the name. */
- name = sel->u.cgrp.name;
+ * function). */
gmx_ana_index_deinit(&sel->u.cgrp);
- sel->u.cgrp.name = name;
sel->evaluate = &_gmx_sel_evaluate_subexpr_staticeval;
sel->cdata->evaluate = sel->evaluate;
}
else
{
- gmx_ana_index_set(&sel->u.cgrp, g->isize, g->index, sel->u.cgrp.name, 0);
+ gmx_ana_index_set(&sel->u.cgrp, g->isize, g->index, 0);
}
}
}
SelelemTemporaryValueAssigner assigner(sel->child, *sel);
sel->child->evaluate(data, sel->child, g);
}
- /* We need to keep the name for the cgrp across the copy to avoid
- * problems if g has a name set. */
- char *name = sel->u.cgrp.name;
gmx_ana_index_copy(&sel->u.cgrp, g, false);
- sel->u.cgrp.name = name;
gmiss.isize = 0;
}
else
{
gmissreserver.reserve(&gmiss, g->isize);
gmx_ana_index_difference(&gmiss, g, &sel->u.cgrp);
- gmiss.name = NULL;
}
if (gmiss.isize > 0)
{
child = child->next;
while (child && tmp.isize > 0)
{
- tmp.name = NULL;
{
MempoolSelelemReserver reserver(child, tmp.isize);
child->evaluate(data, child, &tmp);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_selection
*/
+#include "gromacs/selection/indexutil.h"
+
+#include <cstring>
+
+#include <string>
+#include <vector>
+
#include "gromacs/legacyheaders/index.h"
#include "gromacs/legacyheaders/gmx_fatal.h"
#include "gromacs/legacyheaders/smalloc.h"
-#include "gromacs/legacyheaders/string2.h"
#include "gromacs/legacyheaders/typedefs.h"
-#include "gromacs/selection/indexutil.h"
/********************************************************************
* gmx_ana_indexgrps_t functions
*/
struct gmx_ana_indexgrps_t
{
+ //! Initializes an empty set of groups.
+ explicit gmx_ana_indexgrps_t(int nr) : nr(nr), g(NULL)
+ {
+ names.reserve(nr);
+ snew(g, nr);
+ }
+ ~gmx_ana_indexgrps_t()
+ {
+ for (int i = 0; i < nr; ++i)
+ {
+ gmx_ana_index_deinit(&g[i]);
+ }
+ sfree(g);
+ }
+
/** Number of index groups. */
- int nr;
+ int nr;
/** Array of index groups. */
- gmx_ana_index_t *g;
+ gmx_ana_index_t *g;
+ /** Group names. */
+ std::vector<std::string> names;
};
-/*!
- * \param[out] g Index group structure.
- * \param[in] ngrps Number of groups for which memory is allocated.
- */
-void
-gmx_ana_indexgrps_alloc(gmx_ana_indexgrps_t **g, int ngrps)
-{
- snew(*g, 1);
- (*g)->nr = ngrps;
- snew((*g)->g, ngrps);
-}
-
/*!
* \param[out] g Index group structure.
* \param[in] top Topology structure.
{
t_blocka *block = NULL;
char **names = NULL;
- int i, j;
if (fnm)
{
}
else
{
- snew(*g, 1);
- (*g)->nr = 0;
- (*g)->g = NULL;
+ *g = new gmx_ana_indexgrps_t(0);
return;
}
- gmx_ana_indexgrps_alloc(g, block->nr);
- for (i = 0; i < block->nr; ++i)
+ try
{
- gmx_ana_index_t *grp = &(*g)->g[i];
+ *g = new gmx_ana_indexgrps_t(block->nr);
+ for (int i = 0; i < block->nr; ++i)
+ {
+ gmx_ana_index_t *grp = &(*g)->g[i];
- grp->isize = block->index[i+1] - block->index[i];
- snew(grp->index, grp->isize);
- for (j = 0; j < grp->isize; ++j)
+ grp->isize = block->index[i+1] - block->index[i];
+ snew(grp->index, grp->isize);
+ for (int j = 0; j < grp->isize; ++j)
+ {
+ grp->index[j] = block->a[block->index[i]+j];
+ }
+ grp->nalloc_index = grp->isize;
+ (*g)->names.push_back(names[i]);
+ }
+ }
+ catch (...)
+ {
+ done_blocka(block);
+ sfree(block);
+ for (int i = 0; i < block->nr; ++i)
{
- grp->index[j] = block->a[block->index[i]+j];
+ sfree(names[i]);
}
- grp->name = names[i];
- grp->nalloc_index = grp->isize;
+ sfree(names);
+ throw;
}
-
done_blocka(block);
sfree(block);
+ for (int i = 0; i < block->nr; ++i)
+ {
+ sfree(names[i]);
+ }
sfree(names);
}
void
gmx_ana_indexgrps_free(gmx_ana_indexgrps_t *g)
{
- int i;
-
- if (g->nr == 0)
- {
- sfree(g);
- return;
- }
- for (i = 0; i < g->nr; ++i)
- {
- gmx_ana_index_deinit(&g->g[i]);
- }
- sfree(g->g);
- g->nr = 0;
- g->g = NULL;
- sfree(g);
-}
-
-/*!
- * \param[out] dest Destination index groups.
- * \param[in] src Source index groups.
- *
- * A deep copy is made for all fields, including the group names.
- */
-void
-gmx_ana_indexgrps_clone(gmx_ana_indexgrps_t **dest, gmx_ana_indexgrps_t *src)
-{
- int g;
-
- gmx_ana_indexgrps_alloc(dest, src->nr);
- for (g = 0; g < src->nr; ++g)
- {
- gmx_ana_index_copy(&(*dest)->g[g], &src->g[g], true);
- }
+ delete g;
}
/*!
}
/*!
- * \param[out] dest Output structure.
- * \param[in] src Input index groups.
- * \param[in] n Number of the group to extract.
+ * \param[out] dest Output structure.
+ * \param[out] destName Receives the name of the group if found.
+ * \param[in] src Input index groups.
+ * \param[in] n Number of the group to extract.
* \returns true if \p n is a valid group in \p src, false otherwise.
*/
bool
-gmx_ana_indexgrps_extract(gmx_ana_index_t *dest, gmx_ana_indexgrps_t *src, int n)
+gmx_ana_indexgrps_extract(gmx_ana_index_t *dest, std::string *destName,
+ gmx_ana_indexgrps_t *src, int n)
{
+ destName->clear();
if (n < 0 || n >= src->nr)
{
dest->isize = 0;
return false;
}
+ if (destName != NULL)
+ {
+ *destName = src->names[n];
+ }
gmx_ana_index_copy(dest, &src->g[n], true);
return true;
}
/*!
- * \param[out] dest Output structure.
- * \param[in] src Input index groups.
- * \param[in] name Name (or part of the name) of the group to extract.
+ * \param[out] dest Output structure.
+ * \param[out] destName Receives the name of the group if found.
+ * \param[in] src Input index groups.
+ * \param[in] name Name (or part of the name) of the group to extract.
* \returns true if \p name is a valid group in \p src, false otherwise.
*
* Uses the Gromacs routine find_group() to find the actual group;
* the comparison is case-insensitive.
*/
bool
-gmx_ana_indexgrps_find(gmx_ana_index_t *dest, gmx_ana_indexgrps_t *src, char *name)
+gmx_ana_indexgrps_find(gmx_ana_index_t *dest, std::string *destName,
+ gmx_ana_indexgrps_t *src,
+ const char *name)
{
- int i;
- char **names;
+ const char **names;
+ destName->clear();
snew(names, src->nr);
- for (i = 0; i < src->nr; ++i)
+ for (int i = 0; i < src->nr; ++i)
{
- names[i] = src->g[i].name;
+ names[i] = src->names[i].c_str();
}
- i = find_group(name, src->nr, names);
+ int n = find_group(const_cast<char *>(name), src->nr,
+ const_cast<char **>(names));
sfree(names);
- if (i == NOTSET)
+ if (n == NOTSET)
{
dest->isize = 0;
return false;
}
- return gmx_ana_indexgrps_extract(dest, src, i);
+ return gmx_ana_indexgrps_extract(dest, destName, src, n);
}
/*!
void
gmx_ana_indexgrps_print(FILE *fp, gmx_ana_indexgrps_t *g, int maxn)
{
- int i;
-
- for (i = 0; i < g->nr; ++i)
+ for (int i = 0; i < g->nr; ++i)
{
- fprintf(fp, " %2d: ", i);
- gmx_ana_index_dump(fp, &g->g[i], i, maxn);
+ fprintf(fp, " Group %2d \"%s\" ", i + 1, g->names[i].c_str());
+ gmx_ana_index_dump(fp, &g->g[i], maxn);
}
}
{
g->isize = 0;
g->index = NULL;
- g->name = NULL;
g->nalloc_index = 0;
}
* \param[out] g Output structure.
* \param[in] isize Number of atoms in the new group.
* \param[in] index Array of \p isize atoms (can be NULL if \p isize is 0).
- * \param[in] name Name for the new group (can be NULL).
* \param[in] nalloc Number of elements allocated for \p index
* (if 0, \p index is not freed in gmx_ana_index_deinit())
*
* No copy if \p index is made.
*/
void
-gmx_ana_index_set(gmx_ana_index_t *g, int isize, atom_id *index, char *name,
- int nalloc)
+gmx_ana_index_set(gmx_ana_index_t *g, int isize, atom_id *index, int nalloc)
{
g->isize = isize;
g->index = index;
- g->name = name;
g->nalloc_index = nalloc;
}
/*!
* \param[out] g Output structure.
* \param[in] natoms Number of atoms.
- * \param[in] name Name for the new group (can be NULL).
*/
void
-gmx_ana_index_init_simple(gmx_ana_index_t *g, int natoms, char *name)
+gmx_ana_index_init_simple(gmx_ana_index_t *g, int natoms)
{
int i;
{
g->index[i] = i;
}
- g->name = name;
g->nalloc_index = natoms;
}
{
sfree(g->index);
}
- sfree(g->name);
gmx_ana_index_clear(g);
}
snew(dest->index, dest->isize);
dest->nalloc_index = dest->isize;
}
- memcpy(dest->index, src->index, dest->isize*sizeof(*dest->index));
- }
- if (bAlloc && src->name)
- {
- dest->name = strdup(src->name);
- }
- else if (bAlloc || src->name)
- {
- dest->name = src->name;
+ std::memcpy(dest->index, src->index, dest->isize*sizeof(*dest->index));
}
}
/*!
* \param[in] fp Where to print the output.
* \param[in] g Index group to print.
- * \param[in] i Group number to use if the name is NULL.
* \param[in] maxn Maximum number of indices to print (-1 = print all).
*/
void
-gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int i, int maxn)
+gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int maxn)
{
int j, n;
- if (g->name)
- {
- fprintf(fp, "\"%s\"", g->name);
- }
- else
- {
- fprintf(fp, "Group %d", i+1);
- }
- fprintf(fp, " (%d atoms)", g->isize);
+ fprintf(fp, "(%d atoms)", g->isize);
if (maxn != 0)
{
fprintf(fp, ":");
fprintf(fp, "\n");
}
-/*!
- * \param[in] g Input index group.
- * \param[in] natoms Number of atoms to check against.
- *
- * If any atom index in the index group is less than zero or >= \p natoms,
- * gmx_fatal() is called.
- */
-void
-gmx_ana_index_check(gmx_ana_index_t *g, int natoms)
-{
- int j;
-
- for (j = 0; j < g->isize; ++j)
- {
- if (g->index[j] >= natoms)
- {
- gmx_fatal(FARGS, "Atom index (%d) in index group %s (%d atoms) "
- "larger than number of atoms in trajectory (%d atoms)",
- g->index[j], g->name, g->isize, natoms);
- }
- else if (g->index[j] < 0)
- {
- gmx_fatal(FARGS, "Atom index (%d) in index group %s (%d atoms) "
- "is less than zero",
- g->index[j], g->name, g->isize);
- }
- }
-}
-
/*!
* \param[in] g Index group to check.
* \returns true if the index group is sorted and has no duplicates,
srenew(t->a, g->isize);
t->nalloc_a = g->isize;
}
- memcpy(t->a, g->index, g->isize*sizeof(*(t->a)));
+ std::memcpy(t->a, g->index, g->isize*sizeof(*(t->a)));
}
/* Allocate memory for the block index. We don't know in advance
m->mapid[i] = m->orgid[i];
}
m->mapb.nr = m->nr;
- memcpy(m->mapb.index, m->b.index, (m->nr+1)*sizeof(*(m->mapb.index)));
+ std::memcpy(m->mapb.index, m->b.index, (m->nr+1)*sizeof(*(m->mapb.index)));
m->bStatic = true;
m->bMapStatic = true;
}
dest->type = src->type;
dest->b.nr = src->b.nr;
dest->b.nra = src->b.nra;
- memcpy(dest->orgid, src->orgid, dest->b.nr*sizeof(*dest->orgid));
- memcpy(dest->b.index, src->b.index, (dest->b.nr+1)*sizeof(*dest->b.index));
- memcpy(dest->b.a, src->b.a, dest->b.nra*sizeof(*dest->b.a));
+ std::memcpy(dest->orgid, src->orgid, dest->b.nr*sizeof(*dest->orgid));
+ std::memcpy(dest->b.index, src->b.index, (dest->b.nr+1)*sizeof(*dest->b.index));
+ std::memcpy(dest->b.a, src->b.a, dest->b.nra*sizeof(*dest->b.a));
}
dest->nr = src->nr;
dest->mapb.nr = src->mapb.nr;
- memcpy(dest->refid, src->refid, dest->nr*sizeof(*dest->refid));
- memcpy(dest->mapid, src->mapid, dest->nr*sizeof(*dest->mapid));
- memcpy(dest->mapb.index, src->mapb.index, (dest->mapb.nr+1)*sizeof(*dest->mapb.index));
+ std::memcpy(dest->refid, src->refid, dest->nr*sizeof(*dest->refid));
+ std::memcpy(dest->mapid, src->mapid, dest->nr*sizeof(*dest->mapid));
+ std::memcpy(dest->mapb.index, src->mapb.index, (dest->mapb.nr+1)*sizeof(*dest->mapb.index));
dest->bStatic = src->bStatic;
dest->bMapStatic = src->bMapStatic;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
#ifndef GMX_SELECTION_INDEXUTIL_H
#define GMX_SELECTION_INDEXUTIL_H
+#include <string>
+
#include "../legacyheaders/typedefs.h"
/** Stores a set of index groups. */
int isize;
/** List of atoms. */
atom_id *index;
- /** Group name. */
- char *name;
/** Number of items allocated for \p index. */
int nalloc_index;
} gmx_ana_index_t;
/*! \name Functions for handling gmx_ana_indexgrps_t
*/
/*@{*/
-/** Allocate memory for index groups. */
-void
-gmx_ana_indexgrps_alloc(gmx_ana_indexgrps_t **g, int ngrps);
/** Reads index groups from a file or constructs them from topology. */
void
gmx_ana_indexgrps_init(gmx_ana_indexgrps_t **g, t_topology *top,
/** Frees memory allocated for index groups. */
void
gmx_ana_indexgrps_free(gmx_ana_indexgrps_t *g);
-/** Create a deep copy of \c gmx_ana_indexgrps_t. */
-void
-gmx_ana_indexgrps_clone(gmx_ana_indexgrps_t **dest, gmx_ana_indexgrps_t *src);
/** Returns true if the index group structure is emtpy. */
bool
gmx_ana_indexgrps_is_empty(gmx_ana_indexgrps_t *g);
gmx_ana_indexgrps_get_grp(gmx_ana_indexgrps_t *g, int n);
/** Extracts a single index group. */
bool
-gmx_ana_indexgrps_extract(gmx_ana_index_t *dest, gmx_ana_indexgrps_t *src, int n);
+gmx_ana_indexgrps_extract(gmx_ana_index_t *dest, std::string *destName,
+ gmx_ana_indexgrps_t *src, int n);
/** Finds and extracts a single index group by name. */
bool
-gmx_ana_indexgrps_find(gmx_ana_index_t *dest, gmx_ana_indexgrps_t *src, char *name);
+gmx_ana_indexgrps_find(gmx_ana_index_t *dest, std::string *destName,
+ gmx_ana_indexgrps_t *src, const char *name);
/** Writes out a list of index groups. */
void
gmx_ana_index_clear(gmx_ana_index_t *g);
/** Constructs a \c gmx_ana_index_t from given values. */
void
-gmx_ana_index_set(gmx_ana_index_t *g, int isize, atom_id *index, char *name,
- int nalloc);
+gmx_ana_index_set(gmx_ana_index_t *g, int isize, atom_id *index, int nalloc);
/** Creates a simple index group from the first to the \p natoms'th atom. */
void
-gmx_ana_index_init_simple(gmx_ana_index_t *g, int natoms, char *name);
+gmx_ana_index_init_simple(gmx_ana_index_t *g, int natoms);
/** Frees memory allocated for an index group. */
void
gmx_ana_index_deinit(gmx_ana_index_t *g);
/** Writes out the contents of a index group. */
void
-gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int i, int maxn);
+gmx_ana_index_dump(FILE *fp, gmx_ana_index_t *g, int maxn);
-/** Checks whether all indices are between 0 and \p natoms. */
-void
-gmx_ana_index_check(gmx_ana_index_t *g, int natoms);
/** Checks whether an index group is sorted. */
bool
gmx_ana_index_check_sorted(gmx_ana_index_t *g);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
}
SelectionTreeElementPointer sel(new SelectionTreeElement(SEL_CONST));
_gmx_selelem_set_vtype(sel, GROUP_VALUE);
- /* FIXME: The constness should not be cast away */
- if (!gmx_ana_indexgrps_find(&sel->u.cgrp, grps, (char *)name))
+ std::string foundName;
+ if (!gmx_ana_indexgrps_find(&sel->u.cgrp, &foundName, grps, name))
{
_gmx_selparser_error(scanner, "Cannot match 'group %s'", name);
return SelectionTreeElementPointer();
}
- sel->setName(sel->u.cgrp.name);
+ sel->setName(foundName);
return sel;
}
}
SelectionTreeElementPointer sel(new SelectionTreeElement(SEL_CONST));
_gmx_selelem_set_vtype(sel, GROUP_VALUE);
- if (!gmx_ana_indexgrps_extract(&sel->u.cgrp, grps, id))
+ std::string foundName;
+ if (!gmx_ana_indexgrps_extract(&sel->u.cgrp, &foundName, grps, id))
{
_gmx_selparser_error(scanner, "Cannot match 'group %d'", id);
return SelectionTreeElementPointer();
}
- sel->setName(sel->u.cgrp.name);
+ sel->setName(foundName);
return sel;
}
if (name)
{
root->setName(name);
- root->u.cgrp.name = strdup(name);
}
/* Update the flags */
_gmx_selelem_update_flags(root, scanner);
&& child->child->child->type == SEL_CONST
&& child->child->child->v.type == GROUP_VALUE)
{
- const char *grpName = child->child->child->u.cgrp.name;
- root->setName(grpName);
- root->u.cgrp.name = strdup(grpName);
+ root->setName(child->child->child->name());
}
}
/* If there still is no name, use the selection string */
if (root->name().empty())
{
- const char *selStr = _gmx_sel_lexer_pselstr(scanner);
- root->setName(selStr);
- root->u.cgrp.name = strdup(selStr);
+ root->setName(_gmx_sel_lexer_pselstr(scanner));
}
/* Print out some information if the parser is interactive */
/* Create the root element */
root.reset(new SelectionTreeElement(SEL_ROOT));
root->setName(name);
- root->u.cgrp.name = strdup(name);
/* Create the subexpression element */
root->child.reset(new SelectionTreeElement(SEL_SUBEXPR));
root->child->setName(name);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
if ((pc->flags & POS_COMPLWHOLE) && !bBase && pc->b.nra > g->isize)
{
gmx_ana_index_copy(&pc->gmax, g, true);
- sfree(pc->gmax.name);
- pc->gmax.name = NULL;
}
else
{
- gmx_ana_index_set(&pc->gmax, pc->b.nra, pc->b.a, NULL, 0);
+ gmx_ana_index_set(&pc->gmax, pc->b.nra, pc->b.a, 0);
}
}
return false;
}
/* Find the overlap between the calculations. */
- gmx_ana_index_set(&g2, pc2->b.nra, pc2->b.a, NULL, 0);
+ gmx_ana_index_set(&g2, pc2->b.nra, pc2->b.a, 0);
gmx_ana_index_intersection(g, g1, &g2);
/* Do not merge if there is no overlap. */
if (g->isize == 0)
int i, bi, bj, bo;
base->flags |= pc->flags & (POS_VELOCITIES | POS_FORCES);
- gmx_ana_index_set(&gp, pc->b.nra, pc->b.a, NULL, 0);
- gmx_ana_index_set(&gb, base->b.nra, base->b.a, NULL, 0);
+ gmx_ana_index_set(&gp, pc->b.nra, pc->b.a, 0);
+ gmx_ana_index_set(&gb, base->b.nra, base->b.a, 0);
isize = gmx_ana_index_difference_size(&gp, &gb);
if (isize > 0)
{
base->b.a = g.index;
base->b.nalloc_a = g.isize;
/* Refresh the gmax field */
- gmx_ana_index_set(&base->gmax, base->b.nra, base->b.a, NULL, 0);
+ gmx_ana_index_set(&base->gmax, base->b.nra, base->b.a, 0);
}
}
return;
}
- gmx_ana_index_set(&gp, pc->b.nra, pc->b.a, NULL, 0);
+ gmx_ana_index_set(&gp, pc->b.nra, pc->b.a, 0);
gmx_ana_index_clear(&g);
gmx_ana_index_reserve(&g, pc->b.nra);
pbase = pc;
merge_bases(pbase, base);
}
}
- gmx_ana_index_set(&gp, pbase->b.nra, pbase->b.a, NULL, 0);
+ gmx_ana_index_set(&gp, pbase->b.nra, pbase->b.a, 0);
gmx_ana_index_reserve(&g, pc->b.nra);
}
/* Proceed to the next unchecked calculation */
{
gmx_ana_pos_t &p = rawPositions_;
gmx_ana_index_copy(p.g, rootElement().v.u.g, false);
- p.g->name = NULL;
gmx_ana_indexmap_update(&p.m, p.g, hasFlag(gmx::efSelection_DynamicMask));
p.nr = p.m.nr;
refreshMassesAndCharges(top);
fprintf(fp, " ");
printInfo(fp);
- fprintf(fp, " ");
- gmx_ana_index_dump(fp, p.g, -1, nmaxind);
+ fprintf(fp, " Group ");
+ gmx_ana_index_dump(fp, p.g, nmaxind);
fprintf(fp, " Block (size=%d):", p.m.mapb.nr);
if (!p.m.mapb.index)
if (root->type == SEL_GROUPREF)
{
- bool bOk = true;
+ bool bOk = true;
+ std::string foundName;
if (grps_ == NULL)
{
// TODO: Improve error messages
else if (root->u.gref.name != NULL)
{
char *name = root->u.gref.name;
- if (!gmx_ana_indexgrps_find(&root->u.cgrp, grps_, name))
+ bOk = gmx_ana_indexgrps_find(&root->u.cgrp, &foundName, grps_, name);
+ sfree(name);
+ root->u.gref.name = NULL;
+ if (!bOk)
{
// TODO: Improve error messages
errors->append("Unknown group referenced in a selection");
- bOk = false;
- }
- else
- {
- sfree(name);
}
}
else
{
- if (!gmx_ana_indexgrps_extract(&root->u.cgrp, grps_,
+ if (!gmx_ana_indexgrps_extract(&root->u.cgrp, &foundName, grps_,
root->u.gref.id))
{
// TODO: Improve error messages
if (bOk)
{
root->type = SEL_CONST;
- root->setName(root->u.cgrp.name);
+ root->setName(foundName);
}
}
}
gmx_ana_selcollection_t *sc = &impl_->sc_;
// Do this first, as it allocates memory, while the others don't throw.
- gmx_ana_index_init_simple(&sc->gall, natoms, NULL);
+ gmx_ana_index_init_simple(&sc->gall, natoms);
sc->pcc.setTopology(top);
sc->top = top;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
"Trajectory (%d atoms) does not match topology (%d atoms)",
impl_->fr->natoms, top.topology()->atoms.nr)));
}
- // Check index groups if they have been initialized based on the topology.
+ // TODO: Check index groups if they have been initialized based on the topology.
/*
if (top)
{