Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / fileio / xvgr.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) 2010,2014,2015,2017,2018,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 #ifndef GMX_FILEIO_XVGR_H
38 #define GMX_FILEIO_XVGR_H
39
40 #include <stdio.h>
41
42 #include <string>
43 #include <vector>
44
45 #include "gromacs/utility/basedefinitions.h"
46 #include "gromacs/utility/real.h"
47
48 struct gmx_output_env_t;
49
50 /***************************************************
51  *            XVGR   DEFINITIONS
52  ***************************************************/
53 enum
54 {
55     elNone,
56     elSolid,
57     elDotted,
58     elDashed,
59     elLongDashed,
60     elDotDashed,
61     elNR
62 };
63 /* xvgr line-styles */
64
65 enum
66 {
67     ecWhite,
68     ecFrank,
69     ecBlack = ecFrank,
70     ecRed,
71     ecGreen,
72     ecBlue,
73     ecYellow,
74     ecBrown,
75     ecGray,
76     ecPurple,
77     ecLightBlue,
78     ecViolet,
79     ecHolland,
80     ecLila,
81     ecDarkGray,
82     ecAquamarine,
83     ecOlive,
84     ecNR
85 };
86 /* xvgr line-colors */
87
88 enum
89 {
90     eppNone,
91     eppColor,
92     eppPattern,
93     eppNR
94 };
95 /* xvgr pattern type */
96
97 enum
98 {
99     evView,
100     evWorld,
101     evNR
102 };
103 /* view type */
104
105 /***************************************************
106  *            XVGR   ROUTINES
107  ***************************************************/
108
109 /* Strings such as titles, lables and legends can contain escape sequences
110  * for formatting. Currently supported are:
111  * \s : start subscript
112  * \S : start superscript
113  * \N : end sub/superscript
114  * \symbol : where symbol is the full name of a greek letter
115  *           (see the xvgrstr function in xvgr.c for the full list)
116  *           when starting with a capital, a capital symbol will be printed,
117  *           note that symbol does not need to be followed by a space
118  * \8 : (deprecated) start symbol font
119  * \4 : (deprecated) end symbol font
120  */
121
122 gmx_bool output_env_get_print_xvgr_codes(const struct gmx_output_env_t* oenv);
123 /* Returns if we should print xmgrace or xmgr codes */
124
125 enum
126 {
127     exvggtNONE,
128     exvggtXNY,
129     exvggtXYDY,
130     exvggtXYDYDY,
131     exvggtNR
132 };
133
134 void xvgr_header(FILE*                          fp,
135                  const char*                    title,
136                  const std::string&             xaxis,
137                  const std::string&             yaxis,
138                  int                            exvg_graph_type,
139                  const struct gmx_output_env_t* oenv);
140 /* In most cases you want to use xvgropen_type, which does the same thing
141  * but takes a filename and opens it.
142  */
143
144 FILE* xvgropen_type(const char*                    fn,
145                     const char*                    title,
146                     const std::string&             xaxis,
147                     const std::string&             yaxis,
148                     int                            exvg_graph_type,
149                     const struct gmx_output_env_t* oenv);
150 /* Open a file, and write a title, and axis-labels in Xvgr format
151  * or write nothing when oenv specifies so.
152  * The xvgr graph type enum is defined above.
153  */
154
155 FILE* xvgropen(const char*                    fn,
156                const char*                    title,
157                const std::string&             xaxis,
158                const std::string&             yaxis,
159                const struct gmx_output_env_t* oenv);
160 /* Calls xvgropen_type with graph type xvggtXNY. */
161
162 /* Close xvgr file, and clean up internal file buffers correctly */
163 void xvgrclose(FILE* fp);
164
165 void xvgr_subtitle(FILE* out, const char* subtitle, const struct gmx_output_env_t* oenv);
166 /* Set the subtitle in xvgr */
167
168 void xvgr_view(FILE* out, real xmin, real ymin, real xmax, real ymax, const struct gmx_output_env_t* oenv);
169 /* Set the view in xvgr */
170
171 void xvgr_world(FILE* out, real xmin, real ymin, real xmax, real ymax, const struct gmx_output_env_t* oenv);
172 /* Set the world in xvgr */
173
174 void xvgrLegend(FILE* out, const std::vector<std::string>& setNames, const struct gmx_output_env_t* oenv);
175 /* Make a legend box, and also modifies the view to make room for the legend */
176
177 void xvgr_legend(FILE* out, int nsets, const char* const* setnames, const struct gmx_output_env_t* oenv);
178 /* Make a legend box, and also modifies the view to make room for the legend */
179
180 void xvgr_new_dataset(FILE* out, int nr_first, int nsets, const char** setnames, const struct gmx_output_env_t* oenv);
181 /* End the previous data set(s) and start new one(s).
182     nr_first = the global set number of the first new set (or 0 if no legend)
183     nsets = the number of sets (or 0 if no legends)
184     setnames = the set names (or NULL if no legends)
185  */
186
187 void xvgr_line_props(FILE* out, int NrSet, int LineStyle, int LineColor, const struct gmx_output_env_t* oenv);
188 /* Set xvgr line styles and colors */
189
190 void xvgr_box(FILE*                          out,
191               int                            LocType,
192               real                           xmin,
193               real                           ymin,
194               real                           xmax,
195               real                           ymax,
196               int                            LineStyle,
197               int                            LineWidth,
198               int                            LineColor,
199               int                            BoxFill,
200               int                            BoxColor,
201               int                            BoxPattern,
202               const struct gmx_output_env_t* oenv);
203 /* Make a box */
204
205 int read_xvg_legend(const char* fn, double*** y, int* ny, char** subtitle, char*** legend);
206 /* Read an xvg file for post processing. The number of rows is returned
207  * fn is the filename, y is a pointer to a 2D array (to be allocated by
208  * the routine) ny is the number of columns (including X if appropriate).
209  * If subtitle!=NULL, read the subtitle (when present),
210  * the subtitle string will be NULL when not present.
211  * If legend!=NULL, read the legends for the sets (when present),
212  * 0 is the first y legend, the legend string will be NULL when not present.
213  */
214
215 int read_xvg(const char* fn, double*** y, int* ny);
216 /* As read_xvg_legend, but does not read legends. */
217
218 void write_xvg(const char*                    fn,
219                const char*                    title,
220                int                            nx,
221                int                            ny,
222                real**                         y,
223                const char**                   leg,
224                const struct gmx_output_env_t* oenv);
225 /* Write a two D array (y) of dimensions nx rows times
226  * ny columns to a file. If leg != NULL it will be written too.
227  */
228
229
230 /* This function reads ascii (xvg) files and extracts the data sets to a
231  * two dimensional array which is returned.
232  */
233 real** read_xvg_time(const char* fn,
234                      gmx_bool    bHaveT,
235                      gmx_bool    bTB,
236                      real        tb,
237                      gmx_bool    bTE,
238                      real        te,
239                      int         nsets_in,
240                      int*        nset,
241                      int*        nval,
242                      real*       dt,
243                      real**      t);
244 #endif