/*! * \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); } }
/*! * \param[out] g Index group structure. * \param[in] ngrps Number of index groups. * \param[in] isize Array of index group sizes. * \param[in] index Array of pointers to indices of each group. * \param[in] name Array of names of the groups. * \param[in] bFree If TRUE, the \p isize, \p index and \p name arrays * are freed after they have been copied. */ void gmx_ana_indexgrps_set(gmx_ana_indexgrps_t **g, int ngrps, int *isize, atom_id **index, char **name, bool bFree) { int i; gmx_ana_indexgrps_alloc(g, ngrps); for (i = 0; i < ngrps; ++i) { gmx_ana_index_set(&(*g)->g[i], isize[i], index[i], name[i], isize[i]); } if (bFree) { sfree(isize); sfree(index); sfree(name); } }
/*! * \param[out] g Index group structure. * \param[in] top Topology structure. * \param[in] fnm File name for the index file. * Memory is automatically allocated. * * One or both of \p top or \p fnm can be NULL. * If \p top is NULL, an index file is required and the groups are read * from the file (uses Gromacs routine init_index()). * If \p fnm is NULL, default groups are constructed based on the * topology (uses Gromacs routine analyse()). * If both are null, the index group structure is initialized empty. */ void gmx_ana_indexgrps_init(gmx_ana_indexgrps_t **g, t_topology *top, const char *fnm) { t_blocka *block = NULL; char **names = NULL; int i, j; if (fnm) { block = init_index(fnm, &names); } else if (top) { block = new_blocka(); analyse(&top->atoms, block, &names, FALSE, FALSE); } else { snew(*g, 1); (*g)->nr = 0; (*g)->g = NULL; return; } gmx_ana_indexgrps_alloc(g, block->nr); for (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->index[j] = block->a[block->index[i]+j]; } grp->name = names[i]; grp->nalloc_index = grp->isize; } done_blocka(block); sfree(block); sfree(names); }