Modernize t_psdata
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 12 Aug 2019 09:00:55 +0000 (11:00 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Mon, 19 Aug 2019 14:30:39 +0000 (16:30 +0200)
This is useful in itself, but mainly prepares to modernize other users
of t_rgb, which need it to have a constructor.

Also made a comment more neutral

Refs #2899

Change-Id: I1717c8c049f81c313c2b435f7d56b36a3f914551

src/gromacs/fileio/writeps.cpp
src/gromacs/fileio/writeps.h
src/gromacs/gmxana/gmx_wheel.cpp
src/gromacs/gmxana/gmx_xpm2ps.cpp
src/programs/view/molps.cpp
src/programs/view/molps.h
src/programs/view/view.cpp

index 9a7f29c05690aad98def49d4d83f82838b20d44e..72bf72ba4ebac035cd5efe1e9c72cc1d8c222cfe 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 
 #include "writeps.h"
 
-#include <cstdio>
-
 #include "gromacs/fileio/gmxfio.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
-#include "gromacs/utility/smalloc.h"
+
+using namespace gmx;
 
 const char *fontnm[efontNR] = {
     "Times-Roman", "Times-Italic",     "Times-Bold",    "Times-BoldItalic",
@@ -51,69 +50,44 @@ const char *fontnm[efontNR] = {
     "Courier",    "Courier-Oblique",  "Courier-Bold",  "Courier-BoldOblique"
 };
 
-
-/* Internal psdata structure (abstract datatype)
- * to maintain the current state of the ps engine.
- */
-struct t_int_psdata  {
-    FILE   *fp;
-    int     maxrgb;
-    int     nrgb;
-    t_rgb  *rgb;
-    real    gen_ybox;
-    int     ostack;
-};
-
-
 t_psdata ps_open(const char *fn, real x1, real y1, real x2, real y2)
 {
     t_psdata ps;
 
-    snew(ps, 1);
-
-    ps->fp = gmx_fio_fopen(fn, "w");
-    fprintf(ps->fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
-    fprintf(ps->fp, "%%%%Creator: GROMACS\n");
-    fprintf(ps->fp, "%%%%Title: %s\n", fn);
-    fprintf(ps->fp, "%%%%BoundingBox: %g %g %g %g\n", x1, y1, x2, y2);
-    fprintf(ps->fp, "%%%%EndComments\n");
-    fprintf(ps->fp, "/m {moveto} bind def\n");
-    fprintf(ps->fp, "/l {lineto} bind def\n");
-    fprintf(ps->fp, "/rm {rmoveto} bind def\n");
-    fprintf(ps->fp, "/r  {rlineto} bind def\n");
-    fprintf(ps->fp, "/f {fill} bind def\n");
-    fprintf(ps->fp, "/s {stroke} bind def\n");
-
-    ps->nrgb     = 0;
-    ps->maxrgb   = 0;
-    ps->rgb      = nullptr;
-    ps->gen_ybox = 0;
-    ps->ostack   = 0;
+    ps.fp = gmx_fio_fopen(fn, "w");
+    fprintf(ps.fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");
+    fprintf(ps.fp, "%%%%Creator: GROMACS\n");
+    fprintf(ps.fp, "%%%%Title: %s\n", fn);
+    fprintf(ps.fp, "%%%%BoundingBox: %g %g %g %g\n", x1, y1, x2, y2);
+    fprintf(ps.fp, "%%%%EndComments\n");
+    fprintf(ps.fp, "/m {moveto} bind def\n");
+    fprintf(ps.fp, "/l {lineto} bind def\n");
+    fprintf(ps.fp, "/rm {rmoveto} bind def\n");
+    fprintf(ps.fp, "/r  {rlineto} bind def\n");
+    fprintf(ps.fp, "/f {fill} bind def\n");
+    fprintf(ps.fp, "/s {stroke} bind def\n");
 
     return ps;
 }
 
-void ps_linewidth(t_psdata ps, int lw)
+void ps_linewidth(t_psdata *ps, int lw)
 {
     fprintf(ps->fp, "%d setlinewidth\n", lw);
 }
 
-static void ps_defcolor(t_psdata ps, real r, real g, real b, char *cname)
+static void ps_defcolor(t_psdata *ps, real r, real g, real b, char *cname)
 {
     fprintf(ps->fp, "/%s {%g %g %g setrgbcolor} bind def\n", cname, r, g, b);
 }
 
-static void ps_selcolor(t_psdata ps, char *cname)
+static void ps_selcolor(t_psdata *ps, char *cname)
 {
     fprintf(ps->fp, "%s\n", cname);
 }
 
-static int search_col(t_psdata ps, real r, real g, real b)
+static gmx::index search_col(t_psdata *ps, real r, real g, real b)
 {
-    int  i;
-    char buf[12];
-
-    for (i = 0; (i < ps->nrgb); i++)
+    for (gmx::index i = 0; ssize(ps->rgb); ++i)
     {
         if ((ps->rgb[i].r == r) && (ps->rgb[i].g == g) && (ps->rgb[i].b == b))
         {
@@ -121,41 +95,32 @@ static int search_col(t_psdata ps, real r, real g, real b)
         }
     }
 
-    if (ps->nrgb >= ps->maxrgb)
-    {
-        ps->maxrgb += 100;
-        srenew(ps->rgb, ps->maxrgb);
-    }
-
-    sprintf(buf, "C%d", ps->nrgb);
+    char buf[12];
+    int  indexToBackElement = static_cast<int>(ssize(ps->rgb));
+    sprintf(buf, "C%d", indexToBackElement);
     ps_defcolor(ps, r, g, b, buf);
-    fprintf(ps->fp, "/B%d {%s b} bind def\n", ps->nrgb, buf);
-    ps->rgb[i].r = r;
-    ps->rgb[i].g = g;
-    ps->rgb[i].b = b;
-    ps->nrgb++;
+    fprintf(ps->fp, "/B%zu {%s b} bind def\n", ps->rgb.size(), buf);
+    ps->rgb.emplace_back(t_rgb {r, g, b});
 
-    return (ps->nrgb-1);
+    return indexToBackElement;
 }
 
-void ps_color(t_psdata ps, real r, real g, real b)
+void ps_color(t_psdata *ps, real r, real g, real b)
 {
     char buf[12];
-    int  i;
-
-    i = search_col(ps, r, g, b);
+    int  indexToElement = static_cast<int>(search_col(ps, r, g, b));
 
-    sprintf(buf, "C%d", i);
+    sprintf(buf, "C%d", indexToElement);
     ps_selcolor(ps, buf);
 }
 
-void ps_rgb(t_psdata ps, t_rgb *rgb)
+void ps_rgb(t_psdata *ps, const t_rgb *rgb)
 {
     ps_color(ps, rgb->r, rgb->g, rgb->b);
 }
 
 
-void ps_init_rgb_nbox(t_psdata ps, real xbox, real ybox)
+void ps_init_rgb_nbox(t_psdata *ps, real xbox, real ybox)
 {
     ps->gen_ybox = ybox;
     fprintf(ps->fp, "/by {def currentpoint "
@@ -164,7 +129,7 @@ void ps_init_rgb_nbox(t_psdata ps, real xbox, real ybox)
     /* macro bn is used in ps_rgb_nbox to draw rectangular boxes */
 }
 
-void ps_rgb_nbox(t_psdata ps, t_rgb *rgb, real n)
+void ps_rgb_nbox(t_psdata *ps, t_rgb *rgb, real n)
 {
     int i;
 
@@ -184,7 +149,7 @@ void ps_rgb_nbox(t_psdata ps, t_rgb *rgb, real n)
 
 }
 
-void ps_init_rgb_box(t_psdata ps, real xbox, real ybox)
+void ps_init_rgb_box(t_psdata *ps, real xbox, real ybox)
 {
     fprintf(ps->fp, "/b {currentpoint "
             "%g %g r %g %g r %g %g r %g %g r f %g add moveto} bind def\n",
@@ -192,40 +157,40 @@ void ps_init_rgb_box(t_psdata ps, real xbox, real ybox)
     /* macro b is used in search_col to define macro B */
 }
 
-void ps_rgb_box(t_psdata ps, t_rgb *rgb)
+void ps_rgb_box(t_psdata *ps, t_rgb *rgb)
 {
-    fprintf(ps->fp, "B%d\n", search_col(ps, rgb->r, rgb->g, rgb->b));
+    fprintf(ps->fp, "B%zd\n", search_col(ps, rgb->r, rgb->g, rgb->b));
     /* macro B is defined in search_col from macro b */
 }
 
-void ps_lineto(t_psdata ps, real x, real y)
+void ps_lineto(t_psdata *ps, real x, real y)
 {
     fprintf(ps->fp, "%g %g l\n", x, y);
 }
 
-void ps_linerel(t_psdata ps, real dx, real dy)
+void ps_linerel(t_psdata *ps, real dx, real dy)
 {
     fprintf(ps->fp, "%g %g r\n", dx, dy);
 }
 
-void ps_moveto(t_psdata ps, real x, real y)
+void ps_moveto(t_psdata *ps, real x, real y)
 {
     fprintf(ps->fp, "%g %g m\n", x, y);
 }
 
-void ps_moverel(t_psdata ps, real dx, real dy)
+void ps_moverel(t_psdata *ps, real dx, real dy)
 {
     fprintf(ps->fp, "%g %g rm\n", dx, dy);
 }
 
-void ps_line(t_psdata ps, real x1, real y1, real x2, real y2)
+void ps_line(t_psdata *ps, real x1, real y1, real x2, real y2)
 {
     ps_moveto(ps, x1, y1);
     ps_lineto(ps, x2, y2);
     fprintf(ps->fp, "s\n");
 }
 
-static void do_box(t_psdata ps, real x1, real y1, real x2, real y2)
+static void do_box(t_psdata *ps, real x1, real y1, real x2, real y2)
 {
     ps_moveto(ps, x1, y1);
     ps_linerel(ps, 0, static_cast<real>(y2-y1));
@@ -234,48 +199,48 @@ static void do_box(t_psdata ps, real x1, real y1, real x2, real y2)
     ps_linerel(ps, static_cast<real>(x1-x2), 0);
 }
 
-void ps_box(t_psdata ps, real x1, real y1, real x2, real y2)
+void ps_box(t_psdata *ps, real x1, real y1, real x2, real y2)
 {
     do_box(ps, x1, y1, x2, y2);
     fprintf(ps->fp, "s\n");
 }
 
-void ps_fillbox(t_psdata ps, real x1, real y1, real x2, real y2)
+void ps_fillbox(t_psdata *ps, real x1, real y1, real x2, real y2)
 {
     do_box(ps, x1, y1, x2, y2);
     fprintf(ps->fp, "f\n");
 }
 
-void ps_arc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
+void ps_arc(t_psdata *ps, real x1, real y1, real rad, real a0, real a1)
 {
     fprintf(ps->fp, "%g %g %g %g %g arc s\n", x1, y1, rad, a0, a1);
 }
 
-void ps_fillarc(t_psdata ps, real x1, real y1, real rad, real a0, real a1)
+void ps_fillarc(t_psdata *ps, real x1, real y1, real rad, real a0, real a1)
 {
     fprintf(ps->fp, "%g %g %g %g %g arc f\n", x1, y1, rad, a0, a1);
 }
 
-void ps_arcslice(t_psdata ps, real xc, real yc,
+void ps_arcslice(t_psdata *ps, real xc, real yc,
                  real rad1, real rad2, real a0, real a1)
 {
     fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath s\n",
             xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
 }
 
-void ps_fillarcslice(t_psdata ps, real xc, real yc,
+void ps_fillarcslice(t_psdata *ps, real xc, real yc,
                      real rad1, real rad2, real a0, real a1)
 {
     fprintf(ps->fp, "newpath %g %g %g %g %g arc %g %g %g %g %g arcn closepath f\n",
             xc, yc, rad1, a0, a1, xc, yc, rad2, a1, a0);
 }
 
-void ps_circle(t_psdata ps, real x1, real y1, real rad)
+void ps_circle(t_psdata *ps, real x1, real y1, real rad)
 {
     ps_arc(ps, x1, y1, rad, 0, 360);
 }
 
-void ps_font(t_psdata ps, int font, real size)
+void ps_font(t_psdata *ps, int font, real size)
 {
 
     if ((font < 0) || (font > efontNR))
@@ -287,19 +252,19 @@ void ps_font(t_psdata ps, int font, real size)
     fprintf(ps->fp, "%g scalefont setfont\n", size);
 }
 
-void ps_strfont(t_psdata ps, char *font, real size)
+void ps_strfont(t_psdata *ps, char *font, real size)
 {
     fprintf(ps->fp, "/%s findfont\n", font);
     fprintf(ps->fp, "%g scalefont setfont\n", size);
 }
 
-void ps_text(t_psdata ps, real x1, real y1, const char *str)
+void ps_text(t_psdata *ps, real x1, real y1, const std::string &str)
 {
     ps_moveto(ps, x1, y1);
-    fprintf(ps->fp, "(%s) show\n", str);
+    fprintf(ps->fp, "(%s) show\n", str.c_str());
 }
 
-void ps_flip(t_psdata ps, gmx_bool bPlus)
+void ps_flip(t_psdata *ps, gmx_bool bPlus)
 {
     if (bPlus)
     {
@@ -311,12 +276,12 @@ void ps_flip(t_psdata ps, gmx_bool bPlus)
     }
 }
 
-void ps_rotate(t_psdata ps, real angle)
+void ps_rotate(t_psdata *ps, real angle)
 {
     fprintf(ps->fp, "%f rotate\n", angle);
 }
 
-void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
+void ps_ctext(t_psdata *ps, real x1, real y1, const std::string &str, int expos)
 {
     if (expos == eXLeft)
     {
@@ -324,7 +289,7 @@ void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
         return;
     }
     ps_moveto(ps, x1, y1);
-    fprintf(ps->fp, "(%s) stringwidth\n", str);
+    fprintf(ps->fp, "(%s) stringwidth\n", str.c_str());
     switch (expos)
     {
         case eXLeft:
@@ -339,21 +304,21 @@ void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos)
         default:
             gmx_fatal(FARGS, "invalid position index (expos=%d)", expos);
     }
-    fprintf(ps->fp, "rmoveto (%s) show\n", str);
+    fprintf(ps->fp, "rmoveto (%s) show\n", str.c_str());
 }
 
-void ps_translate(t_psdata ps, real x, real y)
+void ps_translate(t_psdata *ps, real x, real y)
 {
     fprintf(ps->fp, "%g %g translate\n", x, y);
 }
 
-void ps_setorigin(t_psdata ps)
+void ps_setorigin(t_psdata *ps)
 {
     fprintf(ps->fp, "currentpoint dup 3 -1 roll dup 4 1 roll exch translate\n");
     ps->ostack++;
 }
 
-void ps_unsetorigin(t_psdata ps)
+void ps_unsetorigin(t_psdata *ps)
 {
     if (ps->ostack <= 0)
     {
@@ -363,16 +328,14 @@ void ps_unsetorigin(t_psdata ps)
     ps->ostack--;
 }
 
-void ps_close(t_psdata ps)
+void ps_close(t_psdata *ps)
 {
     fprintf(ps->fp, "%%showpage\n");
     fprintf(ps->fp, "%%%%EOF\n");
     gmx_fio_fclose(ps->fp);
-    sfree(ps->rgb);
-    sfree(ps);
 }
 
-void ps_comment(t_psdata ps, const char *s)
+void ps_comment(t_psdata *ps, const char *s)
 {
     fprintf(ps->fp, "%%%% %s\n", s);
 }
index 3e995b3c0dc1c4cba5ee19d4c9e0a12528d65ee5..1d3dc02a973df3f917425f798e763805ae33c375 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2010,2014,2015,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef GMX_FILEIO_WRITEPS_H
 #define GMX_FILEIO_WRITEPS_H
 
-#include <stdio.h>
+#include <cstdio>
+
+#include <string>
+#include <vector>
 
 #include "gromacs/fileio/rgb.h"
 #include "gromacs/utility/basedefinitions.h"
@@ -62,62 +65,67 @@ enum {
 };
 
 
-typedef struct t_int_psdata *t_psdata;
-/* Only use t_psdata - it is a pointer to an abstract datatype
- * that maintains the state of the postscript currently written.
- */
+struct t_psdata
+{
+    FILE              *fp     = nullptr;
+    int                maxrgb = 0;
+    std::vector<t_rgb> rgb;
+    real               gen_ybox = 0;
+    int                ostack   = 0;
+};
+
 
 extern const char *fontnm[efontNR];
 
 t_psdata ps_open(const char *fn, real x1, real y1, real x2, real y2);
 
-void ps_linewidth(t_psdata ps, int lw);
-void ps_color(t_psdata ps, real r, real g, real b);
-void ps_rgb(t_psdata ps, t_rgb *rgb);
+void ps_linewidth(t_psdata *ps, int lw);
+void ps_color(t_psdata *ps, real r, real g, real b);
+void ps_rgb(t_psdata *ps, const t_rgb *rgb);
 
-void ps_rgb_box(t_psdata ps, t_rgb *rgb);
-void ps_rgb_nbox(t_psdata ps, t_rgb *rgb, real n);
-void ps_init_rgb_box(t_psdata ps, real xbox, real ybox);
-void ps_init_rgb_nbox(t_psdata ps, real xbox, real ybox);
+void ps_rgb_box(t_psdata *ps, t_rgb *rgb);
+void ps_rgb_nbox(t_psdata *ps, t_rgb *rgb, real n);
+void ps_init_rgb_box(t_psdata *ps, real xbox, real ybox);
+void ps_init_rgb_nbox(t_psdata *ps, real xbox, real ybox);
 
-void ps_lineto(t_psdata ps, real x, real y);
-void ps_linerel(t_psdata ps, real dx, real dy);
+void ps_lineto(t_psdata *ps, real x, real y);
+void ps_linerel(t_psdata *ps, real dx, real dy);
 
-void ps_moveto(t_psdata ps, real x, real y);
-void ps_moverel(t_psdata ps, real dx, real dy);
+void ps_moveto(t_psdata *ps, real x, real y);
+void ps_moverel(t_psdata *ps, real dx, real dy);
 
-void ps_line(t_psdata ps, real x1, real y1, real x2, real y2);
+void ps_line(t_psdata *ps, real x1, real y1, real x2, real y2);
 
-void ps_box(t_psdata ps, real x1, real y1, real x2, real y2);
-void ps_fillbox(t_psdata ps, real x1, real y1, real x2, real y2);
+void ps_box(t_psdata *ps, real x1, real y1, real x2, real y2);
+void ps_fillbox(t_psdata *ps, real x1, real y1, real x2, real y2);
 
-void ps_arc(t_psdata ps, real x1, real y1, real rad, real a0, real a1);
-void ps_fillarc(t_psdata ps, real x1, real y1, real rad, real a0, real a1);
-void ps_arcslice(t_psdata ps, real xc, real yc,
+void ps_arc(t_psdata *ps, real x1, real y1, real rad, real a0, real a1);
+void ps_fillarc(t_psdata *ps, real x1, real y1, real rad, real a0, real a1);
+void ps_arcslice(t_psdata *ps, real xc, real yc,
                  real rad1, real rad2, real a0, real a1);
-void ps_fillarcslice(t_psdata ps, real xc, real yc,
+void ps_fillarcslice(t_psdata *ps, real xc, real yc,
                      real rad1, real rad2, real a0, real a1);
 
-void ps_circle(t_psdata ps, real x1, real y1, real rad);
+void ps_circle(t_psdata *ps, real x1, real y1, real rad);
 
-void ps_font(t_psdata ps, int font, real size);
-void ps_strfont(t_psdata ps, char *font, real size);
+void ps_font(t_psdata *ps, int font, real size);
+void ps_strfont(t_psdata *ps, char *font, real size);
 
-void ps_text(t_psdata ps, real x1, real y1, const char *str);
-void ps_ctext(t_psdata ps, real x1, real y1, const char *str, int expos);
+void ps_text(t_psdata *ps, real x1, real y1, const std::string &str);
+void ps_ctext(t_psdata *ps, real x1, real y1, const std::string &str, int expos);
 
-void ps_close(t_psdata ps);
+void ps_close(t_psdata *ps);
 
-void ps_flip(t_psdata ps, gmx_bool bPlus);
+void ps_flip(t_psdata *ps, gmx_bool bPlus);
 /* Rotate over 90 (bPlus) or -90 (!bPlus) degrees */
 
-void ps_rotate(t_psdata ps, real angle);
+void ps_rotate(t_psdata *ps, real angle);
 
-void ps_translate(t_psdata ps, real x, real y);
+void ps_translate(t_psdata *ps, real x, real y);
 
-void ps_setorigin(t_psdata ps);
-void ps_unsetorigin(t_psdata ps);
+void ps_setorigin(t_psdata *ps);
+void ps_unsetorigin(t_psdata *ps);
 
-void ps_comment(t_psdata ps, const char *s);
+void ps_comment(t_psdata *ps, const char *s);
 
 #endif
index 2db1d8ddeda492d64d1574854be1c3339edb5bc3..35716a650eff123f06859db6f3b13cb56182f435 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -81,7 +81,6 @@ static void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, ch
     const real fontasp   = 0.6;
     const real fontwidth = fontsize*fontasp;
 
-    t_psdata   out;
     int        i, sl, slen;
     real       ring, inner, outer;
     real       xc, yc, box;
@@ -117,30 +116,30 @@ static void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, ch
 
     bPh = bPhobics(nres, resnm);
 
-    out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
+    t_psdata out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
     xc  = box;
     yc  = box;
 
-    ps_font(out, efontHELV, 1.5*fontsize);
-    ps_translate(out, xc, yc);
+    ps_font(&out, efontHELV, 1.5*fontsize);
+    ps_translate(&out, xc, yc);
     if (title)
     {
-        ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
+        ps_ctext(&out, 0, -fontsize*1.5/2.0, title, eXCenter);
     }
-    ps_font(out, efontHELV, fontsize);
-    ps_rotate(out, rot0);
+    ps_font(&out, efontHELV, fontsize);
+    ps_rotate(&out, rot0);
     for (i = 0; (i < nres); )
     {
         if (bPh[i])
         {
-            ps_color(out, gray, gray, gray);
-            ps_fillarcslice(out, 0, 0, inner, outer, -10, 10);
-            ps_color(out, 0, 0, 0);
+            ps_color(&out, gray, gray, gray);
+            ps_fillarcslice(&out, 0, 0, inner, outer, -10, 10);
+            ps_color(&out, 0, 0, 0);
         }
-        ps_arcslice(out, 0, 0, inner, outer, -10, 10);
+        ps_arcslice(&out, 0, 0, inner, outer, -10, 10);
 
-        ps_ctext(out, inner+fontwidth, -fontsize/2.0, rnms[i], eXLeft);
-        ps_rotate(out, -100);
+        ps_ctext(&out, inner+fontwidth, -fontsize/2.0, rnms[i], eXLeft);
+        ps_rotate(&out, -100);
         i++;
 
         if ((i % 18) == 0)
@@ -149,7 +148,7 @@ static void wheel(const char *fn, int nres, char *resnm[], int r0, real rot0, ch
             outer += ring;
         }
     }
-    ps_close(out);
+    ps_close(&out);
 }
 
 static void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *title)
@@ -160,7 +159,6 @@ static void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *tit
     const int  angle     = 9;
     const real fontwidth = fontsize*fontasp;
 
-    t_psdata   out;
     int        i, slen;
     real       ring, inner, outer;
     real       xc, yc, box;
@@ -176,32 +174,32 @@ static void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *tit
     outer = inner+ring;
     box   = (1+gmx::exactDiv(nres, 2*angle))*outer;
 
-    out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
+    t_psdata out = ps_open(fn, 0, 0, 2.0*box, 2.0*box);
     xc  = box;
     yc  = box;
 
-    ps_font(out, efontHELV, 1.5*fontsize);
-    ps_translate(out, xc, yc);
-    ps_color(out, 0, 0, 0);
+    ps_font(&out, efontHELV, 1.5*fontsize);
+    ps_translate(&out, xc, yc);
+    ps_color(&out, 0, 0, 0);
     if (title)
     {
-        ps_ctext(out, 0, -fontsize*1.5/2.0, title, eXCenter);
+        ps_ctext(&out, 0, -fontsize*1.5/2.0, title, eXCenter);
     }
-    ps_font(out, efontHELV, fontsize);
+    ps_font(&out, efontHELV, fontsize);
 
-    ps_rotate(out, rot0);
+    ps_rotate(&out, rot0);
     for (i = 0; (i < nres); )
     {
         if ((i % 5) == 4)
         {
-            ps_color(out, gray, gray, 1.0);
-            ps_fillarcslice(out, 0, 0, inner, outer, -angle, angle);
-            ps_color(out, 0, 0, 0);
+            ps_color(&out, gray, gray, 1.0);
+            ps_fillarcslice(&out, 0, 0, inner, outer, -angle, angle);
+            ps_color(&out, 0, 0, 0);
         }
-        ps_arcslice(out, 0, 0, inner, outer, -angle, angle);
+        ps_arcslice(&out, 0, 0, inner, outer, -angle, angle);
 
-        ps_ctext(out, inner+fontwidth, -fontsize/2.0, resnm[i], eXLeft);
-        ps_rotate(out, -2*angle);
+        ps_ctext(&out, inner+fontwidth, -fontsize/2.0, resnm[i], eXLeft);
+        ps_rotate(&out, -2*angle);
         i++;
 
         if ((i % (2*angle)) == 0)
@@ -210,7 +208,7 @@ static void wheel2(const char *fn, int nres, char *resnm[], real rot0, char *tit
             outer += ring;
         }
     }
-    ps_close(out);
+    ps_close(&out);
 }
 
 int gmx_wheel(int argc, char *argv[])
index 8a881e1640d1266f848cfd9d34a76c02d6452b1d..1890cfb0455f0f17cea3f4b86c2d877be697244b 100644 (file)
@@ -233,7 +233,7 @@ static gmx_bool diff_maps(int nmap1, t_mapping *map1, int nmap2, t_mapping *map2
     return bDiff;
 }
 
-static void leg_discrete(t_psdata ps, real x0, real y0, char *label,
+static void leg_discrete(t_psdata *ps, real x0, real y0, char *label,
                          real fontsize, char *font, int nmap, t_mapping map[])
 {
     int   i;
@@ -263,7 +263,7 @@ static void leg_discrete(t_psdata ps, real x0, real y0, char *label,
     }
 }
 
-static void leg_continuous(t_psdata ps, real x0, real x, real y0, char *label,
+static void leg_continuous(t_psdata *ps, real x0, real x, real y0, char *label,
                            real fontsize, char *font,
                            int nmap, t_mapping map[],
                            int mapoffset)
@@ -307,7 +307,7 @@ static void leg_continuous(t_psdata ps, real x0, real x, real y0, char *label,
              - boxxh/2, yhh, map[nmap-1].desc, eXCenter);
 }
 
-static void leg_bicontinuous(t_psdata ps, real x0, real x, real y0, char *label1,
+static void leg_bicontinuous(t_psdata *ps, real x0, real x, real y0, char *label1,
                              char *label2, real fontsize, char *font,
                              int nmap1, t_mapping map1[], int nmap2, t_mapping map2[])
 {
@@ -360,7 +360,7 @@ static gmx_bool box_do_all_x_min_ticks(t_psrec *psr)
     return (psr->boxspacing > (1.5*psr->X.minorticklen));
 }
 
-static void draw_boxes(t_psdata ps, real x0, real y0, real w,
+static void draw_boxes(t_psdata *ps, real x0, real y0, real w,
                        int nmat, t_matrix mat[], t_psrec *psr)
 {
     char     buf[128];
@@ -517,7 +517,7 @@ static void draw_boxes(t_psdata ps, real x0, real y0, real w,
     }
 }
 
-static void draw_zerolines(t_psdata out, real x0, real y0, real w,
+static void draw_zerolines(t_psdata *out, real x0, real y0, real w,
                            int nmat, t_matrix mat[], t_psrec *psr)
 {
     real   xx, yy, dy, xx00, yy00;
@@ -791,7 +791,6 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
                    int mapoffset)
 {
     char         *legend;
-    t_psdata      out;
     t_psrec       psrec, *psr;
     int           W, H;
     int           i, x, y, col, leg = 0;
@@ -910,16 +909,16 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
         x += 5*DDD;
         y += 4*DDD;
     }
-    out = ps_open(outf, 0, 0, x, y);
-    ps_linewidth(out, static_cast<int>(psr->linewidth));
-    ps_init_rgb_box(out, psr->xboxsize, psr->yboxsize);
-    ps_init_rgb_nbox(out, psr->xboxsize, psr->yboxsize);
-    ps_translate(out, psr->xoffs, psr->yoffs);
+    t_psdata out = ps_open(outf, 0, 0, x, y);
+    ps_linewidth(&out, static_cast<int>(psr->linewidth));
+    ps_init_rgb_box(&out, psr->xboxsize, psr->yboxsize);
+    ps_init_rgb_nbox(&out, psr->xboxsize, psr->yboxsize);
+    ps_translate(&out, psr->xoffs, psr->yoffs);
 
     if (bFrame)
     {
-        ps_comment(out, "Here starts the BOX drawing");
-        draw_boxes(out, x0, y0, w, nmat, mat, psr);
+        ps_comment(&out, "Here starts the BOX drawing");
+        draw_boxes(&out, x0, y0, w, nmat, mat, psr);
     }
 
     for (i = 0; (i < nmat); i++)
@@ -927,8 +926,8 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
         if (bTitle || (bTitleOnce && i == nmat-1) )
         {
             /* Print title, if any */
-            ps_rgb(out, BLACK);
-            ps_strfont(out, psr->titfont, psr->titfontsize);
+            ps_rgb(&out, BLACK);
+            ps_strfont(&out, psr->titfont, psr->titfontsize);
             std::string buf;
             if (!mat2 || (std::strcmp(mat[i].title, mat2[i].title) == 0))
             {
@@ -938,17 +937,17 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
             {
                 buf = gmx::formatString("%s / %s", mat[i].title, mat2[i].title);
             }
-            ps_ctext(out, x0+w/2, y0+box_height(&(mat[i]), psr)+psr->titfontsize,
-                     buf.c_str(), eXCenter);
+            ps_ctext(&out, x0+w/2, y0+box_height(&(mat[i]), psr)+psr->titfontsize,
+                     buf, eXCenter);
         }
-        ps_comment(out, gmx::formatString("Here starts the filling of box #%d", i).c_str());
+        ps_comment(&out, gmx::formatString("Here starts the filling of box #%d", i).c_str());
         for (x = 0; (x < mat[i].nx); x++)
         {
             int nexty;
             int nextcol;
 
             xx = x0+x*psr->xboxsize;
-            ps_moveto(out, xx, y0);
+            ps_moveto(&out, xx, y0);
             y     = 0;
             bMap1 = ((mat2 == nullptr) || (x < y || (x == y && bFirstDiag)));
             if ((bDiag) || (x != y))
@@ -978,17 +977,17 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
                     {
                         if (bMap1)
                         {
-                            ps_rgb_nbox(out, &(mat[i].map[col].rgb), nexty-y);
+                            ps_rgb_nbox(&out, &(mat[i].map[col].rgb), nexty-y);
                         }
                         else
                         {
                             assert(mat2);
-                            ps_rgb_nbox(out, &(mat2[i].map[col].rgb), nexty-y);
+                            ps_rgb_nbox(&out, &(mat2[i].map[col].rgb), nexty-y);
                         }
                     }
                     else
                     {
-                        ps_moverel(out, 0, psr->yboxsize);
+                        ps_moverel(&out, 0, psr->yboxsize);
                     }
                     y     = nexty;
                     bMap1 = bNextMap1;
@@ -1003,14 +1002,14 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
     {
         /* reset y0 for first box */
         y0 = dh;
-        ps_comment(out, "Here starts the zero lines drawing");
-        draw_zerolines(out, x0, y0, w, nmat, mat, psr);
+        ps_comment(&out, "Here starts the zero lines drawing");
+        draw_zerolines(&out, x0, y0, w, nmat, mat, psr);
     }
 
     if (elegend != elNone)
     {
-        ps_comment(out, "Now it's legend time!");
-        ps_linewidth(out, static_cast<int>(psr->linewidth));
+        ps_comment(&out, "Now it's legend time!");
+        ps_linewidth(&out, static_cast<int>(psr->linewidth));
         if (mat2 == nullptr || elegend != elSecond)
         {
             bDiscrete = mat[0].bDiscrete;
@@ -1027,28 +1026,28 @@ static void ps_mat(const char *outf, int nmat, t_matrix mat[], t_matrix mat2[],
         }
         if (bDiscrete)
         {
-            leg_discrete(out, psr->legfontsize, DDD, legend,
+            leg_discrete(&out, psr->legfontsize, DDD, legend,
                          psr->legfontsize, psr->legfont, leg_nmap, leg_map);
         }
         else
         {
             if (elegend != elBoth)
             {
-                leg_continuous(out, x0+w/2, w/2, DDD, legend,
+                leg_continuous(&out, x0+w/2, w/2, DDD, legend,
                                psr->legfontsize, psr->legfont, leg_nmap, leg_map,
                                mapoffset);
             }
             else
             {
                 assert(mat2);
-                leg_bicontinuous(out, x0+w/2, w, DDD, mat[0].legend, mat2[0].legend,
+                leg_bicontinuous(&out, x0+w/2, w, DDD, mat[0].legend, mat2[0].legend,
                                  psr->legfontsize, psr->legfont, nmap1, map1, nmap2, map2);
             }
         }
-        ps_comment(out, "Were there, dude");
+        ps_comment(&out, "Done processing");
     }
 
-    ps_close(out);
+    ps_close(&out);
 }
 
 static void make_axis_labels(int nmat, t_matrix *mat)
index e285dd43d4c3988851c7334ac4640e677e81cb76..67860f68b04199a5342544b7d3173be5a8772b8b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2013, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -52,7 +52,7 @@
 
 #define MSIZE 4
 
-static void ps_draw_atom(t_psdata ps, int ai, iv2 vec2[], char **atomnm[])
+static void ps_draw_atom(t_psdata *ps, int ai, iv2 vec2[], char **atomnm[])
 {
     int xi, yi;
 
@@ -98,7 +98,7 @@ static bool local_pbc_dx(rvec x1, rvec x2)
     return true;
 }
 
-static void ps_draw_bond(t_psdata ps,
+static void ps_draw_bond(t_psdata *ps,
                          int ai, int aj, iv2 vec2[],
                          rvec x[], char **atomnm[])
 {
@@ -133,7 +133,7 @@ static void ps_draw_bond(t_psdata ps,
     }
 }
 
-static void ps_draw_objects(t_psdata ps, int nobj, t_object objs[], iv2 vec2[],
+static void ps_draw_objects(t_psdata *ps, int nobj, t_object objs[], iv2 vec2[],
                             rvec x[], char **atomnm[], bool bShowHydro)
 {
     int          i;
@@ -171,7 +171,7 @@ static void v4_to_iv2(vec4 x4, iv2 v2, int x0, int y0, real sx, real sy)
     v2[YY] = y0-sy*x4[YY]*inv_z;
 }
 
-static void draw_box(t_psdata ps, t_3dview *view, matrix box,
+static void draw_box(t_psdata *ps, t_3dview *view, matrix box,
                      int x0, int y0, real sx, real sy)
 {
     int  ivec[8][4] =  {
@@ -206,7 +206,7 @@ static void draw_box(t_psdata ps, t_3dview *view, matrix box,
     }
 }
 
-void ps_draw_mol(t_psdata ps, t_manager *man)
+void ps_draw_mol(t_psdata *ps, t_manager *man)
 {
     t_windata  *win;
     t_3dview   *view;
index aefd318c49df3243d7eeca7a074f23b0a774c80f..8b3135055f46bb97fd70ffaacefa2205df381a07 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
 #ifndef _molps_h
 #define _molps_h
 
-#include "gromacs/fileio/writeps.h"
-
 #include "manager.h"
 
-extern void ps_draw_mol(t_psdata ps, t_manager *man);
+struct t_psdata;
+
+extern void ps_draw_mol(t_psdata *ps, t_manager *man);
 /* Draw molecules to a postscript file */
 
 #endif  /* _molps_h */
index ce3c306b3a22b1c756507e71ee9353d77c21eeac..c41e8ff80e9e04d62553f9e16325cbf45f2073f3 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -70,8 +70,8 @@ static void dump_it(t_manager *man)
     t_psdata ps;
 
     ps = ps_open("view.ps", 0, 0, man->molw->wd.width, man->molw->wd.height);
-    ps_draw_mol(ps, man);
-    ps_close(ps);
+    ps_draw_mol(&ps, man);
+    ps_close(&ps);
 }
 
 static void done_gmx(t_x11 *x11, t_gmx *gmx)