Upped the version to 3.2.0
[gromacs.git] / src / ngmx / xstat.c
bloba34ccf42268fa7b7ba485360ed81c112bf023c09
1 /*
2 * $Id$
3 *
4 * This source code is part of
5 *
6 * G R O M A C S
7 *
8 * GROningen MAchine for Chemical Simulations
9 *
10 * VERSION 3.2.0
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
33 * And Hey:
34 * Gyas ROwers Mature At Cryogenic Speed
36 #include "sysstuff.h"
37 #include "smalloc.h"
38 #include "x11.h"
39 #include "string2.h"
40 #include "macros.h"
41 #include "fgrid.h"
42 #include "futil.h"
43 #include "xdlg.h"
44 #include "xdlghi.h"
46 typedef struct {
47 int nopt,nAppl;
48 char **name;
49 char **description;
50 char **dlgfile;
51 t_dlg *dlg;
52 t_dlg *appl;
53 } t_data;
55 static void ApplCallback(t_x11 *x11,int dlg_mess,int item_id,
56 char *set,void *dta)
58 t_data *data;
59 t_dlg *dlg;
60 t_dlgitem *item;
61 int i;
62 char doit[1024];
64 data=(t_data *)dta;
65 dlg=data->appl;
67 fprintf(stderr,"item_id: %d (%s)\n",item_id,set);
68 if (strcasecmp(set,"OK") == 0) {
69 /* Doit */
70 sprintf(doit,
71 "xterm -geometry +100+100 -n %s"
72 " -title \"GROMACS: %s\" -e nice %s ",
73 data->name[data->nAppl],
74 data->name[data->nAppl],
75 data->name[data->nAppl]);
76 for(i=0; (i<dlg->nitem); i++) {
77 item=dlg->dlgitem[i];
78 switch (item->type) {
79 case edlgRB:
80 strcat(doit,item->set);
81 strcat(doit," ");
82 break;
83 case edlgCB:
84 if (item->u.checkbox.bChecked)
85 strcat(doit,item->set);
86 strcat(doit," ");
87 break;
88 case edlgET:
89 if (strlen(item->u.edittext.buf) > 0) {
90 strcat(doit,item->set);
91 strcat(doit," ");
92 strcat(doit,item->u.edittext.buf);
93 strcat(doit," ");
95 break;
96 default:
97 fprintf(stderr,"Type: %d\n",item->type);
100 strcat(doit," &");
101 fprintf(stderr,"Going to exec: '%s'\n",doit);
102 system(doit);
103 HideDlg(data->appl);
105 else if (strcasecmp(set,"Cancel") == 0) {
106 data->nAppl = -1;
107 HideDlg(data->appl);
111 static void Callback(t_x11 *x11,int dlg_mess,int item_id,
112 char *set,void *dta)
114 t_data *data=(t_data *)dta;
116 if (item_id == data->nopt) {
117 fprintf(stderr,"Doei...\n");
118 exit(0);
120 else {
121 fprintf(stderr,"%d: %s\n",item_id,data->description[item_id]);
122 if (data->nAppl != -1)
123 HideDlg(data->appl);
124 data->nAppl=item_id;
125 data->appl=ReadDlg(x11,0,data->name[item_id],
126 BLACK,LIGHTGREY,data->dlgfile[item_id],
127 50,50,FALSE,FALSE,ApplCallback,data);
128 ShowDlg(data->appl);
132 static void read_opts(t_data *data)
134 FILE *in;
135 char fn[STRLEN],buf[STRLEN];
136 int i,n;
138 sprintf(fn,"xstat.dat");
139 in=libopen(fn);
140 fscanf(in,"%d",&n);
141 data->nopt=n;
142 snew(data->name,data->nopt);
143 snew(data->description,data->nopt);
144 snew(data->dlgfile,data->nopt);
146 for(i=0; (i<data->nopt); i++) {
147 ReadQuoteString(fn,in,buf);
148 data->name[i] = strdup(buf);
149 ReadQuoteString(fn,in,buf);
150 data->description[i] = strdup(buf);
151 ReadQuoteString(fn,in,buf);
152 data->dlgfile[i] = strdup(buf);
154 fclose(in);
157 static void add_opts(t_x11 *x11,t_data *data)
159 t_dlgitem *but;
160 int i,y0,w;
162 y0=OFFS_Y;
163 for(i=0; (i<data->nopt); i++) {
164 but=CreateButton(x11,data->description[i],FALSE,
165 (t_id)i,(t_id)0,
166 OFFS_X,y0,0,0,1);
167 AddDlgItem(data->dlg,but);
168 y0+=but->win.height+OFFS_Y;
170 but=CreateButton(x11,"Quit",TRUE,(t_id)data->nopt,(t_id)0,
171 OFFS_X,y0,0,0,1);
172 AddDlgItem(data->dlg,but);
173 y0+=but->win.height+OFFS_Y;
175 w=0;
176 for(i=0; (i<=data->nopt); i++)
177 w=max(w,QueryDlgItemW(data->dlg,i));
178 w+=2*OFFS_X;
179 for(i=0; (i<=data->nopt); i++)
180 SetDlgItemSize(data->dlg,i,w,0);
181 SetDlgSize(data->dlg,w+2*OFFS_X,y0,TRUE);
184 void main(int argc,char *argv[])
186 t_x11 *x11;
187 t_data data;
189 /* Initiate X and data */
190 if ((x11=GetX11(&argc,argv))==NULL) {
191 fprintf(stderr,"Can't open DISPLAY\n");
192 exit(1);
194 read_opts(&data);
195 data.dlg=CreateDlg(x11,0,argv[0],0,0,0,0,0,BLACK,LIGHTGREY,Callback,&data);
196 add_opts(x11,&data);
197 data.nAppl=-1;
199 ShowDlg(data.dlg);
200 x11->MainLoop(x11);
201 HideDlg(data.dlg);