Remove unused thole polarization rfac parameter
[alexxy/gromacs.git] / src / gromacs / fileio / matio.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
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.
10  *
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.
15  *
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.
20  *
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.
25  *
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.
33  *
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.
36  */
37
38 #ifndef GMX_FILEIO_MATIO_H
39 #define GMX_FILEIO_MATIO_H
40
41 #include <stdio.h>
42
43 #include <string>
44 #include <vector>
45
46 #include "gromacs/fileio/rgb.h"
47 #include "gromacs/math/multidimarray.h"
48 #include "gromacs/utility/basedefinitions.h"
49 #include "gromacs/utility/real.h"
50
51 /*! \brief Models an XPM element
52  *
53  * \libinternal */
54 struct t_xpmelmt
55 {
56     //! Should all be non-zero (and printable and not '"')
57     char c1 = 0;
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). */
60     char c2 = 0;
61 };
62
63 //! Type of a matrix element
64 typedef short t_matelmt;
65
66 /*! \brief Maps an XPM element to an RGB color and a string description.
67  *
68  * \libinternal */
69 struct t_mapping
70 {
71     //! XPM element code
72     t_xpmelmt code;
73     //! Description
74     const char* desc = nullptr;
75     //! RGB color
76     t_rgb rgb;
77 };
78
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.
84  */
85
86 //! Convenience typedef
87 template<typename T>
88 using DynamicMatrix2D =
89         gmx::MultiDimArray<std::vector<T>, gmx::extents<gmx::dynamic_extent, gmx::dynamic_extent>>;
90
91 /*! \brief A matrix of integers, plus supporting values, such as used in XPM output
92  *
93  * \libinternal
94  *
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. */
98 struct t_matrix
99 {
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
103     int nx = 0;
104     //! Size of the matrix in y
105     int ny = 0;
106     //! Matrix title
107     std::string title;
108     //! Label for the continuous legend
109     std::string legend;
110     //! Label for the x-axis
111     std::string label_x;
112     //! Label for the y-axis
113     std::string label_y;
114     //! Whether the quantity described is discrete or continuous.
115     bool bDiscrete = false;
116     //! The x-ticklabels
117     std::vector<real> axis_x;
118     //! The y-ticklabels
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;
124 };
125
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);
128
129 //! Read the mapping table from fn, return number of entries
130 std::vector<t_mapping> readcmap(const char* fn);
131
132 void printcmap(FILE* out, int n, t_mapping map[]);
133 /* print mapping table to out */
134
135 void writecmap(const char* fn, int n, t_mapping map[]);
136 /* print mapping table to fn */
137
138 //! Reads and returns a number of matrices from .xpm file \c fnm.
139 std::vector<t_matrix> read_xpm_matrix(const char* fnm);
140
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
145  */
146
147 void write_xpm_m(FILE* out, t_matrix m);
148 /* Writes a t_matrix struct to .xpm file */
149
150 void write_xpm3(FILE*              out,
151                 unsigned int       flags,
152                 const std::string& title,
153                 const std::string& legend,
154                 const std::string& label_x,
155                 const std::string& label_y,
156                 int                n_x,
157                 int                n_y,
158                 real               axis_x[],
159                 real               axis_y[],
160                 real*              mat[],
161                 real               lo,
162                 real               mid,
163                 real               hi,
164                 t_rgb              rlo,
165                 t_rgb              rmid,
166                 t_rgb              rhi,
167                 int*               nlevels);
168 /* See write_xpm.
169  * Writes a colormap varying as rlo -> rmid -> rhi.
170  */
171 void write_xpm_split(FILE*              out,
172                      unsigned int       flags,
173                      const std::string& title,
174                      const std::string& legend,
175                      const std::string& label_x,
176                      const std::string& label_y,
177                      int                n_x,
178                      int                n_y,
179                      real               axis_x[],
180                      real               axis_y[],
181                      real*              mat[],
182                      real               lo_top,
183                      real               hi_top,
184                      int*               nlevel_top,
185                      t_rgb              rlo_top,
186                      t_rgb              rhi_top,
187                      real               lo_bot,
188                      real               hi_bot,
189                      int*               nlevel_bot,
190                      gmx_bool           bDiscreteColor,
191                      t_rgb              rlo_bot,
192                      t_rgb              rhi_bot);
193 /* See write_xpm.
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
196  * which is white.
197  */
198
199 void write_xpm(FILE*              out,
200                unsigned int       flags,
201                const std::string& title,
202                const std::string& legend,
203                const std::string& label_x,
204                const std::string& label_y,
205                int                n_x,
206                int                n_y,
207                real               t_x[],
208                real               t_y[],
209                real*              mat[],
210                real               lo,
211                real               hi,
212                t_rgb              rlo,
213                t_rgb              rhi,
214                int*               nlevels);
215 /* out        xpm file
216  * flags      flags, defined types/matrix.h
217  *            MAT_SPATIAL_X
218  *            MAT_SPATIAL_Y
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.
222  * title      matrix title
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
235  */
236
237 real** mk_matrix(int nx, int ny, gmx_bool b1D);
238
239 void done_matrix(int nx, real*** m);
240
241 #endif /* GMX_FILEIO_MATIO_H */