3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
32 * \brief Implementation of functions in position.h.
44 #include <indexutil.h>
48 * \param[out] pos Output structure.
50 * Any contents of \p pos are discarded without freeing.
53 gmx_ana_pos_clear(gmx_ana_pos_t
*pos
)
57 gmx_ana_indexmap_clear(&pos
->m
);
62 * \param[in,out] pos Position data structure.
63 * \param[in] n Maximum number of positions.
64 * \param[in] isize Maximum number of atoms.
66 * Ensures that enough memory is allocated in \p pos to calculate \p n
67 * positions from \p isize atoms.
70 gmx_ana_pos_reserve(gmx_ana_pos_t
*pos
, int n
, int isize
)
79 gmx_ana_indexmap_reserve(&pos
->m
, n
, isize
);
84 * \param[out] pos Position data structure to initialize.
85 * \param[in] x Position vector to use.
88 gmx_ana_pos_init_const(gmx_ana_pos_t
*pos
, rvec x
)
90 gmx_ana_pos_clear(pos
);
93 copy_rvec(x
, pos
->x
[0]);
94 gmx_ana_indexmap_init(&pos
->m
, NULL
, NULL
, INDEX_UNKNOWN
);
99 * \param[in,out] pos Position data structure.
101 * Frees any memory allocated within \p pos.
102 * The pointer \p pos itself is not freed.
104 * \see gmx_ana_pos_free()
107 gmx_ana_pos_deinit(gmx_ana_pos_t
*pos
)
110 sfree(pos
->x
); pos
->x
= NULL
;
111 gmx_ana_indexmap_deinit(&pos
->m
);
115 * \param[in,out] pos Position data structure.
117 * Frees any memory allocated for \p pos.
118 * The pointer \p pos is also freed, and is invalid after the call.
120 * \see gmx_ana_pos_deinit()
123 gmx_ana_pos_free(gmx_ana_pos_t
*pos
)
125 gmx_ana_pos_deinit(pos
);
130 * \param[in,out] dest Destination positions.
131 * \param[in] src Source positions.
132 * \param[in] bFirst If TRUE, memory is allocated for \p dest and a full
133 * copy is made; otherwise, only variable parts are copied, and no memory
136 * \p dest should have been initialized somehow (calloc() is enough).
139 gmx_ana_pos_copy(gmx_ana_pos_t
*dest
, gmx_ana_pos_t
*src
, bool bFirst
)
143 gmx_ana_pos_reserve(dest
, src
->nr
, 0);
146 memcpy(dest
->x
, src
->x
, dest
->nr
*sizeof(*dest
->x
));
147 gmx_ana_indexmap_copy(&dest
->m
, &src
->m
, bFirst
);