changed reading hint
[gromacs/adressmacs.git] / src / ngmx / xstat.c
blobe00b348787096f3a7eecae047d3a8ada40478c7e
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 2.0
12 * Copyright (c) 1991-1999
13 * BIOSON Research Institute, Dept. of Biophysical Chemistry
14 * University of Groningen, The Netherlands
16 * Please refer to:
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
23 * or e-mail to:
24 * gromacs@chem.rug.nl
26 * And Hey:
27 * Great Red Oystrich Makes All Chemists Sane
29 static char *SRCID_xstat_c = "$Id$";
31 #include "sysstuff.h"
32 #include "smalloc.h"
33 #include "x11.h"
34 #include "string2.h"
35 #include "macros.h"
36 #include "fgrid.h"
37 #include "futil.h"
38 #include "xdlg.h"
39 #include "xdlghi.h"
41 typedef struct {
42 int nopt,nAppl;
43 char **name;
44 char **description;
45 char **dlgfile;
46 t_dlg *dlg;
47 t_dlg *appl;
48 } t_data;
50 static void ApplCallback(t_x11 *x11,int dlg_mess,int item_id,
51 char *set,void *dta)
53 t_data *data;
54 t_dlg *dlg;
55 t_dlgitem *item;
56 int i;
57 char doit[1024];
59 data=(t_data *)dta;
60 dlg=data->appl;
62 fprintf(stderr,"item_id: %d (%s)\n",item_id,set);
63 if (strcasecmp(set,"OK") == 0) {
64 /* Doit */
65 sprintf(doit,
66 "xterm -geometry +100+100 -n %s"
67 " -title \"GROMACS: %s\" -e nice %s ",
68 data->name[data->nAppl],
69 data->name[data->nAppl],
70 data->name[data->nAppl]);
71 for(i=0; (i<dlg->nitem); i++) {
72 item=dlg->dlgitem[i];
73 switch (item->type) {
74 case edlgRB:
75 strcat(doit,item->set);
76 strcat(doit," ");
77 break;
78 case edlgCB:
79 if (item->u.checkbox.bChecked)
80 strcat(doit,item->set);
81 strcat(doit," ");
82 break;
83 case edlgET:
84 if (strlen(item->u.edittext.buf) > 0) {
85 strcat(doit,item->set);
86 strcat(doit," ");
87 strcat(doit,item->u.edittext.buf);
88 strcat(doit," ");
90 break;
91 default:
92 fprintf(stderr,"Type: %d\n",item->type);
95 strcat(doit," &");
96 fprintf(stderr,"Going to exec: '%s'\n",doit);
97 system(doit);
98 HideDlg(data->appl);
100 else if (strcasecmp(set,"Cancel") == 0) {
101 data->nAppl = -1;
102 HideDlg(data->appl);
106 static void Callback(t_x11 *x11,int dlg_mess,int item_id,
107 char *set,void *dta)
109 t_data *data=(t_data *)dta;
111 if (item_id == data->nopt) {
112 fprintf(stderr,"Doei...\n");
113 exit(0);
115 else {
116 fprintf(stderr,"%d: %s\n",item_id,data->description[item_id]);
117 if (data->nAppl != -1)
118 HideDlg(data->appl);
119 data->nAppl=item_id;
120 data->appl=ReadDlg(x11,0,data->name[item_id],
121 BLACK,LIGHTGREY,data->dlgfile[item_id],
122 50,50,FALSE,FALSE,ApplCallback,data);
123 ShowDlg(data->appl);
127 static void read_opts(t_data *data)
129 FILE *in;
130 char *lib,fn[STRLEN],buf[STRLEN];
131 int i,n;
133 if ((lib=getenv("GMXLIB"))==NULL) {
134 fprintf(stderr,"No variable GMXLIB !\n");
135 exit(1);
137 sprintf(fn,"%s/xstat.dat",lib);
138 in=ffopen(fn,"r");
139 fscanf(in,"%d",&n);
140 data->nopt=n;
141 snew(data->name,data->nopt);
142 snew(data->description,data->nopt);
143 snew(data->dlgfile,data->nopt);
145 for(i=0; (i<data->nopt); i++) {
146 ReadQuoteString(fn,in,buf);
147 data->name[i] = strdup(buf);
148 ReadQuoteString(fn,in,buf);
149 data->description[i] = strdup(buf);
150 ReadQuoteString(fn,in,buf);
151 data->dlgfile[i] = strdup(buf);
153 fclose(in);
156 static void add_opts(t_x11 *x11,t_data *data)
158 t_dlgitem *but;
159 int i,y0,w;
161 y0=OFFS_Y;
162 for(i=0; (i<data->nopt); i++) {
163 but=CreateButton(x11,data->description[i],FALSE,
164 (t_id)i,(t_id)0,
165 OFFS_X,y0,0,0,1);
166 AddDlgItem(data->dlg,but);
167 y0+=but->win.height+OFFS_Y;
169 but=CreateButton(x11,"Quit",TRUE,(t_id)data->nopt,(t_id)0,
170 OFFS_X,y0,0,0,1);
171 AddDlgItem(data->dlg,but);
172 y0+=but->win.height+OFFS_Y;
174 w=0;
175 for(i=0; (i<=data->nopt); i++)
176 w=max(w,QueryDlgItemW(data->dlg,i));
177 w+=2*OFFS_X;
178 for(i=0; (i<=data->nopt); i++)
179 SetDlgItemSize(data->dlg,i,w,0);
180 SetDlgSize(data->dlg,w+2*OFFS_X,y0,TRUE);
183 void main(int argc,char *argv[])
185 t_x11 *x11;
186 t_data data;
188 /* Initiate X and data */
189 if ((x11=GetX11(&argc,argv))==NULL) {
190 fprintf(stderr,"Can't open DISPLAY\n");
191 exit(1);
193 read_opts(&data);
194 data.dlg=CreateDlg(x11,0,argv[0],0,0,0,0,0,BLACK,LIGHTGREY,Callback,&data);
195 add_opts(x11,&data);
196 data.nAppl=-1;
198 ShowDlg(data.dlg);
199 x11->MainLoop(x11);
200 HideDlg(data.dlg);