4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
17 * GROMACS: A message-passing parallel molecular dynamics implementation
18 * H.J.C. Berendsen, D. van der Spoel and R. van Drunen
19 * Comp. Phys. Comm. 91, 43-56 (1995)
21 * Also check out our WWW page:
22 * http://md.chem.rug.nl/~gmx
27 * Green Red Orange Magenta Azure Cyan Skyblue
29 static char *SRCID_xvgr_c
= "$Id$";
43 return (getenv("XMGRACE") != NULL
);
46 FILE *xgopen(char *fn
,char *header
,char *title
,char *xaxis
,char *yaxis
)
51 fprintf(xg
,"TitleText: %s: %s\n",header
,title
);
52 fprintf(xg
,"XUnitText: %s\n",xaxis
);
53 fprintf(xg
,"YUnitText: %s\n",yaxis
);
58 FILE *xvgropen(char *fn
,char *title
,char *xaxis
,char *yaxis
)
63 xvgr
=(FILE *)ffopen(fn
,"w");
64 fprintf(xvgr
,"# This file was created by %s\n",Program());
65 fprintf(xvgr
,"# which is part of G R O M A C S:\n");
66 fprintf(xvgr
,"# %s\n",bromacs());
68 fprintf(xvgr
,"# All this happened at: %s",ctime(&t
));
70 fprintf(xvgr
,"@ title \"%s\"\n",title
);
71 fprintf(xvgr
,"@ xaxis label \"%s\"\n",xaxis
);
72 fprintf(xvgr
,"@ yaxis label \"%s\"\n",yaxis
);
73 fprintf(xvgr
,"@TYPE nxy\n");
78 void xgraph_file(char *fn
,char *opts
)
85 sprintf(doit
,"xgraph =100+100 %s %s &",opts
,fn
);
90 void xvgr_file(char *fn
,char *opts
)
95 sprintf(doit
,"%s -geometry +100+100 %s %s &",
96 bXmGrace() ? "xmgrace" : "xmgr",opts
? opts
: "",fn
);
101 void xv_file(char *fn
,char *opts
)
106 sprintf(doit
,"xv %s %s &",opts
? opts
: "",fn
);
111 void xvgr_view(FILE *out
,real xmin
,real ymin
,real xmax
,real ymax
)
113 fprintf(out
,"@ view %g, %g, %g, %g\n",xmin
,ymin
,xmax
,ymax
);
116 void xvgr_world(FILE *out
,real xmin
,real ymin
,real xmax
,real ymax
)
118 fprintf(out
,"@ world xmin %g\n"
121 "@ world ymax %g\n",xmin
,ymin
,xmax
,ymax
);
124 void xvgr_legend(FILE *out
,int nsets
,char *setname
[])
128 xvgr_view(out
,0.15,0.15,0.75,0.85);
129 fprintf(out
,"@ legend on\n");
130 fprintf(out
,"@ legend box on\n");
131 fprintf(out
,"@ legend loctype view\n");
132 fprintf(out
,"@ legend %g, %g\n",0.78,0.8);
133 fprintf(out
,"@ legend length %d\n",2);
134 for(i
=0; (i
<nsets
); i
++)
136 fprintf(out
,"@ s%d legend \"%s\"\n",i
,setname
[i
]);
138 fprintf(out
,"@ legend string %d \"%s\"\n",i
,setname
[i
]);
141 void xvgr_line_props(FILE *out
, int NrSet
, int LineStyle
, int LineColor
)
143 fprintf(out
, "@ with g0\n");
144 fprintf(out
, "@ s%d linestyle %d\n", NrSet
, LineStyle
);
145 fprintf(out
, "@ s%d color %d\n", NrSet
, LineColor
);
148 static char *LocTypeStr
[] = { "view", "world" };
149 static char *BoxFillStr
[] = { "none", "color", "pattern" };
151 void xvgr_box(FILE *out
,
153 real xmin
,real ymin
,real xmax
,real ymax
,
154 int LineStyle
,int LineWidth
,int LineColor
,
155 int BoxFill
,int BoxColor
,int BoxPattern
)
157 fprintf(out
,"@with box\n");
158 fprintf(out
,"@ box on\n");
159 fprintf(out
,"@ box loctype %s\n",LocTypeStr
[LocType
]);
160 fprintf(out
,"@ box %g, %g, %g, %g\n",xmin
,ymin
,xmax
,ymax
);
161 fprintf(out
,"@ box linestyle %d\n",LineStyle
);
162 fprintf(out
,"@ box linewidth %d\n",LineWidth
);
163 fprintf(out
,"@ box color %d\n",LineColor
);
164 fprintf(out
,"@ box fill %s\n",BoxFillStr
[BoxFill
]);
165 fprintf(out
,"@ box fill color %d\n",BoxColor
);
166 fprintf(out
,"@ box fill pattern %d\n",BoxPattern
);
167 fprintf(out
,"@box def\n");
170 void lsq_y_ax(int n
, real x
[], real y
[], real
*a
)
176 for (i
=0; (i
< n
); i
++) {
183 void lsq_y_ax_b(int n
, real x
[], real y
[], real
*a
, real
*b
)
189 for (i
=0; (i
< n
); i
++) {
195 *a
=(n
*yx
-sy
*sx
)/(n
*xx
-sx
*sx
);
199 static char *fgets3(FILE *fp
)
201 static char *ptr
= NULL
;
202 static int len
= STRLEN
;
209 if (fgets(ptr
,len
-1,fp
) == NULL
)
212 while ((strchr(ptr
,'\n') == NULL
) && (!feof(fp
))) {
213 /* This line is longer than len characters, let's increase len! */
217 if (fgets(p
-1,STRLEN
,fp
) == NULL
)
221 if (ptr
[slen
-1] == '\n')
226 static int wordcount(char *ptr
)
232 if (strlen(ptr
) == 0)
234 /* fprintf(stderr,"ptr='%s'\n",ptr); */
236 for(i
=0; (ptr
[i
] != '\0'); i
++) {
237 is
[cur
] = isspace(ptr
[i
]);
238 if ((i
> 0) && (is
[cur
] && !is
[prev
]))
245 int read_xvg(char *fn
,real
***y
,int *ny
)
251 int k
,line
=0,nny
,nx
,maxx
,rval
;
260 while ((ptr
= fgets3(fp
)) != NULL
) {
263 if ((ptr
[0] != '@') && (ptr
[0] != '#')) {
265 (*ny
) = nny
= wordcount(ptr
);
266 /* fprintf(stderr,"There are %d columns in your file\n",nny);*/
273 /* Allocate column space */
276 for(k
=0; (k
<nny
); k
++)
279 /* Initiate format string */
283 /* fprintf(stderr,"ptr='%s'\n",ptr);*/
284 for(k
=0; (k
<nny
); k
++) {
287 rval
= sscanf(ptr
,fmt
,&lf
);
288 /* fprintf(stderr,"rval = %d\n",rval);*/
289 if ((rval
== EOF
) || (rval
== 0))
292 srenew(fmt
,3*(nny
+1)+1);
293 srenew(base
,3*nny
+1);
297 fprintf(stderr
,"Only %d columns on line %d in file %s\n",
312 void dump_xvg(char *fn
,char *title
,int nx
,int ny
,real
**y
)
317 fp
=xvgropen(fn
,title
,"X","Y");
318 for(i
=0; (i
<nx
); i
++) {
319 for(j
=0; (j
<ny
); j
++) {
320 fprintf(fp
," %12.5e",y
[j
][i
]);