changed reading hint
[gromacs/adressmacs.git] / src / ngmx / nload.c
blob2bf6a23c0faf1f5695ab0564c7e0e064aa7b3eff
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_nload_c = "$Id$";
31 #include <math.h>
32 #include <typedefs.h>
33 #include <macros.h>
34 #include <smalloc.h>
35 #include <string.h>
36 #include "nload.h"
37 #include "buttons.h"
39 void DrawLoad(t_x11 *x11,t_windata *Win,int nloads,int *loadinfo)
41 static char *Strings[] = { "Unbalance","Single Processor","Your Ad Here ?"};
42 int i,y0,bwidth,boff,bar,bmax,bmin,ym,yh;
43 int *lb;
44 real bav,bscale;
45 char maxstr[6];
47 return;
49 XClearWindow(x11->disp, Win->self);
50 y0=XTextHeight(x11->font)+AIR;
51 yh=(Win->height-y0)/2;
52 ym=y0+yh;
53 XSetForeground(x11->disp,x11->gc,WHITE);
54 XDrawLine(x11->disp,Win->self,x11->gc,0,y0,Win->width,y0);
56 if (nloads >= 2) {
57 TextInRect(x11,Win->self,Strings[0],AIR,0,Win->width-2*AIR,y0,
58 eXLeft,eYCenter);
59 if (loadinfo[0] == 0) {
60 nloads--;
61 lb=&loadinfo[1];
63 else {
64 lb=loadinfo;
65 if (loadinfo[nloads-1] == 0)
66 nloads--;
68 bwidth = (Win->width) / nloads;
69 boff = (Win->width % nloads)/2;
70 bav = 0.0;
72 bmax=bmin=lb[0];
74 for (i=1; (i<nloads); i++) {
75 bmax = max (bmax,lb[i]);
76 bmin = min (bmin,lb[i]);
77 bav += lb[i];
79 bav/=nloads;
80 bscale = (yh-2)/max(fabs(bmax-bav),fabs(bav-bmin));
81 sprintf(maxstr,"(%d%%)",(int)(100.0*(bmax-bav)/bav));
82 TextInRect(x11,Win->self,maxstr,AIR,0,Win->width-2*AIR,y0,
83 eXRight,eYCenter);
85 XDrawLine(x11->disp,Win->self,x11->gc,0,ym,Win->width,ym);
86 if (bmax-bmin) {
87 for(i=0; i<nloads; i++) {
88 bar=(lb[i]-bav)*bscale;
89 if (bar != 0) {
90 if (bar > 0)
91 XFillRectangle(x11->disp,Win->self,x11->gc,
92 (i*bwidth)+boff+1,ym-bar+1,bwidth-2,bar);
93 else
94 XFillRectangle(x11->disp,Win->self,x11->gc,
95 (i*bwidth)+boff+1,ym,bwidth-2,-bar);
101 else {
102 TextInRect(x11,Win->self,Strings[1],AIR,0,Win->width,y0,eXLeft,eYCenter);
103 TextInRect(x11,Win->self,Strings[2],AIR,y0,Win->width,
104 Win->height-y0,eXLeft,eYCenter);
106 XSetForeground(x11->disp,x11->gc,x11->fg);
109 static bool LWCallBack(t_x11 *x11,XEvent *event, Window w, void *data)
111 t_loadwin *lw;
113 lw=(t_loadwin *)data;
114 switch(event->type) {
115 case Expose:
116 DrawLoad(x11,&lw->wd,lw->nprocs,lw->load);
117 break;
118 default:
119 break;
121 return FALSE;
124 t_loadwin *init_lw(t_x11 *x11,Window Parent,
125 int x,int y,int width,int height,
126 unsigned long fg,unsigned long bg)
128 t_loadwin *lw;
130 snew(lw,1);
131 snew(lw->load,MAXPROC);
132 lw->nprocs=1;
133 InitWin(&lw->wd,x,y,width,height,1,"Load Window");
134 lw->wd.self=XCreateSimpleWindow(x11->disp,Parent,x,y,1,1,1,fg,bg);
135 x11->RegisterCallback(x11,lw->wd.self,Parent,LWCallBack,lw);
136 x11->SetInputMask(x11,lw->wd.self,ExposureMask);
138 return lw;
141 void map_lw(t_x11 *x11,t_loadwin *lw)
143 XMapWindow(x11->disp,lw->wd.self);
146 void set_load(t_x11 *x11,t_loadwin *lw,int nprocs,int load[])
148 int i;
149 bool bChange=FALSE;
151 lw->nprocs=nprocs;
152 for(i=0; (i<nprocs); i++)
153 if (lw->load[i] != load[i]) {
154 bChange=TRUE;
155 lw->load[i]=load[i];
157 if (bChange)
158 ExposeWin(x11->disp,lw->wd.self);
161 void done_lw(t_x11 *x11,t_loadwin *lw)
163 x11->UnRegisterCallback(x11,lw->wd.self);
164 sfree(lw);