2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2017,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_FILEIO_MATIO_H
39 #define GMX_FILEIO_MATIO_H
46 #include "gromacs/fileio/rgb.h"
47 #include "gromacs/math/multidimarray.h"
48 #include "gromacs/utility/basedefinitions.h"
49 #include "gromacs/utility/real.h"
51 /*! \brief Models an XPM element
56 //! Should all be non-zero (and printable and not '"')
58 /*! \brief Should all be zero (single char color names: smaller xpm's)
59 * or should all be non-zero (double char color names: more colors). */
63 //! Type of a matrix element
64 typedef short t_matelmt;
66 /*! \brief Maps an XPM element to an RGB color and a string description.
74 const char* desc = nullptr;
79 #define MAT_SPATIAL_X (1 << 0)
80 #define MAT_SPATIAL_Y (1 << 1)
81 /* Defines if x and y are spatial dimensions,
82 * when not, there are n axis ticks at the middle of the elements,
83 * when set, there are n+1 axis ticks at the edges of the elements.
86 //! Convenience typedef
88 using DynamicMatrix2D =
89 gmx::MultiDimArray<std::vector<T>, gmx::extents<gmx::dynamic_extent, gmx::dynamic_extent>>;
91 /*! \brief A matrix of integers, plus supporting values, such as used in XPM output
95 * \todo nx and ny should probably be replaced by operations on the
96 * extent of matrix, but currently there is only limited ability to
97 * iterate over contents of matrix. */
100 //! Defines if x and y are spatial dimensions. See comments on MAT_*.
101 unsigned int flags = 0;
102 //! Size of the matrix in x
104 //! Size of the matrix in y
108 //! Label for the continuous legend
110 //! Label for the x-axis
112 //! Label for the y-axis
114 //! Whether the quantity described is discrete or continuous.
115 bool bDiscrete = false;
117 std::vector<real> axis_x;
119 std::vector<real> axis_y;
120 //! Element x,y is matrix(x, y)
121 DynamicMatrix2D<t_matelmt> matrix;
122 //! Color levels for the output(?)
123 std::vector<t_mapping> map;
126 //! Seach in the \c map for code \c c and return its entry, or -1 if not found.
127 t_matelmt searchcmap(gmx::ArrayRef<const t_mapping> map, t_xpmelmt c);
129 //! Read the mapping table from fn, return number of entries
130 std::vector<t_mapping> readcmap(const char* fn);
132 void printcmap(FILE* out, int n, t_mapping map[]);
133 /* print mapping table to out */
135 void writecmap(const char* fn, int n, t_mapping map[]);
136 /* print mapping table to fn */
138 //! Reads and returns a number of matrices from .xpm file \c fnm.
139 std::vector<t_matrix> read_xpm_matrix(const char* fnm);
141 real** matrix2real(t_matrix* in, real** out);
142 /* Converts an matrix in a t_matrix struct to a matrix of reals
143 * When mat==NULL memory will be allocated
144 * Returns NULL when something went wrong
147 void write_xpm_m(FILE* out, t_matrix m);
148 /* Writes a t_matrix struct to .xpm file */
150 void write_xpm3(FILE* out,
152 const std::string& title,
153 const std::string& legend,
154 const std::string& label_x,
155 const std::string& label_y,
169 * Writes a colormap varying as rlo -> rmid -> rhi.
171 void write_xpm_split(FILE* out,
173 const std::string& title,
174 const std::string& legend,
175 const std::string& label_x,
176 const std::string& label_y,
190 gmx_bool bDiscreteColor,
194 * Writes a colormap with separate above and below diagonal colormaps.
195 * If bDiscrete then a colormap with 16 fixed colors is used, first of
199 void write_xpm(FILE* out,
201 const std::string& title,
202 const std::string& legend,
203 const std::string& label_x,
204 const std::string& label_y,
216 * flags flags, defined types/matrix.h
219 * Defines if x and y are spatial dimensions,
220 * when not, there are n axis ticks at the middle of the elements,
221 * when set, there are n+1 axis ticks at the edges of the elements.
223 * legend label for the continuous legend
224 * label_x label for the x-axis
225 * label_y label for the y-axis
226 * n_x, n_y size of the matrix
227 * axis_x[] the x-ticklabels (n_x or n_x+1)
228 * axis_y[] the y-ticklables (n_y or n_y+1)
229 * *mat[] element x,y is mat[x][y]
230 * lo output lower than lo is set to lo
231 * hi output higher than hi is set to hi
232 * rlo rgb value for level lo
233 * rhi rgb value for level hi
234 * nlevels number of color levels for the output
237 real** mk_matrix(int nx, int ny, gmx_bool b1D);
239 void done_matrix(int nx, real*** m);
241 #endif /* GMX_FILEIO_MATIO_H */