Beispiel #1
0
/**
 * Called by the GUI when a key event is received, triggers an action in the
 * controller.
 *
 */
void Controller::receive_gui_event(const char *event,const char *value) {
  if(m_sleeping) return;

  //TODO: Fix this total mess, refactor into switch, break conditions out into methods.
  if(strcmp(event,"Sleep"          ) == 0) event_sleep(event,value);           else
  if(strcmp(event,"KEYPRESS"       ) == 0) m_powerup=true;                     else
  if(strcmp(event,"TOTALTIMER"     ) == 0) event_totaltimer(event,value);      else
  if(strcmp(event,"Save:PulseWidth") == 0) event_save_pulsewidth(event,value); else
  if(strcmp(event,"Save:Calib"     ) == 0) event_save_calibration();           else
  if(strcmp(event,"Save:Becq"      ) == 0) event_save_becq(event,value);       else
  if(strcmp(event,"Save:UTCOff"    ) == 0) event_save_utcoff(event,value);     else
  if(strcmp(event,"Save:Time"      ) == 0) save_time();                        else
  if(strcmp(event,"Save:Date"      ) == 0) save_date();                        else
  if(strcmp(event,"Save:WarnCPM"   ) == 0) save_warncpm();                     else
  if(strcmp(event,"Japanese"       ) == 0) event_japanese(event,value);        else
  if(strcmp(event,"Never Dim"      ) == 0) event_neverdim(event,value);        else
  if(strcmp(event,"English"        ) == 0) event_english(event,value);         else
  if(strcmp(event,"CPM/CPS Auto"   ) == 0) event_cpm_cps_auto(event,value);    else
  if(strcmp(event,"Geiger Beep"    ) == 0) event_geiger_beep(event,value);     else
  if(strcmp(event,"\x80Sv"         ) == 0) event_usv(event,value);             else
  if(strcmp(event,"\x80R"          ) == 0) event_rem(event,value);             else
  if(strcmp(event,"Clear Log"      ) == 0) event_clear_log(event,value);       else
  if(strcmp(event,"Save:Brightness") == 0) event_save_brightness(event,value); else
  if(strcmp(event,"Save:LogInter"  ) == 0) save_loginterval();                 else
  if(strcmp(event,"CALIBRATE"      ) == 0) initialise_calibration();           else
  if(strcmp(event,"UTCSCREEN"      ) == 0) event_utcscreen(event,value);       else
  if(strcmp(event,"TIMESCREEN"     ) == 0) event_timescreen(event,value);      else
  if(strcmp(event,"BECQSCREEN"     ) == 0) event_becqscreen(event,value);      else
  if(strcmp(event,"LOGINTERVAL"    ) == 0) event_loginterval(event,value);     else
  if(strcmp(event,"WARNSCREEN"     ) == 0) event_warnscreen(event,value);      else
  if(strcmp(event,"DATESCREEN"     ) == 0) event_datescreen(event,value);      else
  if(strcmp(event,"BrightnessSCN"  ) == 0) event_brightnessscn(event,value);   else
  if(strcmp(event,"LeftBrightness" ) == 0) event_leftbrightness(event,value);  else
  if(strcmp(event,"QR Transfer"    ) == 0) qr_logxfer();                       else
  if(strcmp(event,"Audio Xfer"     ) == 0) event_audioxfer(event,value);       else
  if(strcmp(event,"QR Tweet"       ) == 0) event_qrtweet(event,value);         else
  if(strcmp(event,"varnumchange"   ) == 0) {
    if(strcmp ("BRIGHTNESS",value) == 0) event_varnum_brightness(event,value); else
    if(strcmpl("CAL"       ,value,3)   ) update_calibration();                 else
    if(strcmpl("DATE"      ,value,4)   ) event_varnum_date(event,value);       else
    if(strcmpl("TIME"      ,value,4)   ) event_varnum_time(event,value);
  }
}
Beispiel #2
0
main(int argc, char *argv[]) {
	char *pgm;
	char *server;
	int   i, j;
	int   id, nc;
	int   nstep   = 10;
	int   nmodule = 5;
	int   running[MAX_MODULES], runstate[MAX_MODULES], nrunning;

	pgm = argv[0];
	++argv; --argc;

	if (!argc) {
		fprintf(stderr, "usage: %s server [nstep] [nmodule]\n", pgm);
		exit(1);
	}
	server = argv[0];
	++argv; --argc;

	if (argc) {
		nstep = atoi(argv[0]);
		++argv; --argc;
	}

	if (argc) {
		nmodule = atoi(argv[0]);
		++argv; --argc;
	}

	if (argc) {
		fprintf(stderr, "usage: %s server [nstep] [nmodule]\n", pgm);
		exit(1);
	}

	event_verbose(0);
	efi_init();

	id = event_join(server, &nc);
	if (!id) {
		fprintf(stderr, "%s: couldn't join server %s\n", pgm, server);
		exit(1);
	}
	fprintf(stderr, "%s: Joined %s as client id %d (%d clients)\n",
		pgm, server, id, nc);

	/* Don't receive any events */
	event_select_type(0, 0, ET_MAX);
	event_receive_enable(0);

	/* Send loaded messages */
	for (i = 0; i < nmodule; ++i) {
		send_state(i, 2);
		event_sleep(irand(100, 1000));
	}

	/* Send an idle messages */
	for (i = 0; i < nmodule; ++i) {
		send_state(i, 3);
		event_sleep(irand(100, 1000));
	}

	/* Cycle run-send-idle for each step */
	for (i = 0; i < nstep; ++i) {
		/* Set all modules to IDLE */
		for (j = 0; j < nmodule; ++j) {
			running[j]  = j;
			runstate[j] = 3;
		}
		nrunning = nmodule;

		/* Randomly cycle a module */
		while (nrunning) {
			j = irand(0, nrunning-1);

			if (runstate[j] == 5) runstate[j] = 3;
			else ++runstate[j];

			send_state(running[j], runstate[j]);

			/* Remove modules that have gone idle */
			if (runstate[j] == 3) {
				running[j]  = running[nrunning-1];
				runstate[j] = runstate[nrunning-1];
				nrunning--;
			}

			event_sleep(irand(100, 2000));
		}
		send_frame(i+1, nstep);
		printf("Finished frame %d\n", i);
	}

	/* Send an unload messages */
	for (i = 0; i < nmodule; ++i) {
		send_state(i, 1);
		event_sleep(irand(100, 1000));
	}

}
Beispiel #3
0
// (i) This thread is responsible for waking up of timed out sleeping
//     threads on timers.
// (ii)Certain threads that are sleeping on certain events must be
//     waken up (nic thread, fdc thread, ...)
void timerthread(void)
{
    struct timerobject *t1, *t2;
    unsigned long oflags;
    unsigned long tmsec;
    struct kthread *thr, *thr1;
    int i, j, inc, cid;

    // Remember this thread address in a global variable.
    timed_event_thread = (struct kthread *)current_thread;
    while (1)
    {
        // Increase priorities of long awiting threads ( > 3 seconds)
        if (priocompute == 1)
        {
            CLI;
            spinlock(ready_qlock);
            priocompute = 0;
            tmsec = (secs & 0x000FFFFF) * 1000 + millesecs;
            for (i=0; i<31; i++)
            {
                // Total queue i is taken out
                thr = (struct kthread *)ready_qhead[i];
                ready_qhead[i] = NULL;
                ready_qtail[i] = NULL;
                while (thr != NULL)
                {
                    thr1 = (struct kthread *)thr->kt_qnext;
                    if (tmsec - thr->kt_schedinf.sc_thrreadystart > 3000) inc = 4;
                    else inc = 2;

                    // Priority must be increased
                    // Insert in the suitable queue.
                    thr->kt_schedinf.sc_cpupri += inc; // Irrespective of the class/type
                    cid = thr->kt_schedinf.sc_cid - 1;
                    if (thr->kt_schedinf.sc_cpupri > maxpri[cid])
                        thr->kt_schedinf.sc_cpupri = maxpri[cid];
                    j = (thr->kt_schedinf.sc_cpupri > thr->kt_schedinf.sc_inhpri) ? ((159 - thr->kt_schedinf.sc_cpupri) / 5) : ((159 - thr->kt_schedinf.sc_inhpri) / 5);
                    thr->kt_qnext = NULL;
                    thr->kt_qprev = (struct kthread *)ready_qtail[j];
                    if (ready_qtail[j] != NULL)
                    {
                        ready_qtail[j]->kt_qnext = thr;
                        ready_qtail[j] = thr;
                    }
                    else ready_qhead[j] = ready_qtail[j] = thr;
                    thr = thr1;
                }
            }
            spinunlock(ready_qlock);
            STI;
        }
        // Check if nic thread is waiting for transmit interrupt
        // for long time
        if (tx_wait_pkt != NULL)
        {
            _lock(&nic.busy);
            if ((tx_wait_pkt != NULL) && (secs - nicwait_start) > 5)
            {
                event_wakeup((struct event_t *)&tx_wait_pkt->threadwait);
            }
            unlock(&nic.busy);
        }


        // Check if fdc thread is waiting for disk interrupt
        //for long time

        // Process timer objects
        if (timeoutflag == 1)
        {
            _lock(&timerq_lock);
            timeoutflag = 0;
            if (timers != NULL)
            {
                t1 = (struct timerobject *)timers;
                while (t1 != NULL && t1->timer_count <= 0)
                {
                    t2 = (struct timerobject *)t1->timer_next;
                    if (t2 != NULL)
                    {
                        t2->timer_count += (t1->timer_count);
                        t2->timer_prev = NULL;
                    }
                    // Add this timed object to the corresponding process.
                    t1->timer_prev = t1->timer_next = NULL;
                    t1->timer_count = -1; // Not in use

                    if (t1->timer_handler == (int (*)(void *))wakeup)
                    {   // Wakeup operation
                        if (t1->timer_ownerthread->kt_schedinf.sc_state == THREAD_STATE_SLEEP)
                            wakeup(t1->timer_ownerthread);
                    }
                    else if (t1->timer_handler != NULL) // Otherwise discard
                    {
                        t1->timer_handler(t1->timer_handlerparam);
                    }
                    t1 = t2;
                }
                timers = t1;
            }
            unlock(&timerq_lock);
        }

        // One round is completed. Sleep on event object
        event_sleep(&timerthr_sleep, NULL);
    }
}
Beispiel #4
0
main(int argc, char *argv[]) {
	char     *file;                         /* data file name       */
	int       ok, help, chann, nchan;       /* cmd line options     */
	int       type;                         /* cmd line options     */
	int       showmap;                      /* more cmd line opts   */
	int       probe;                        /* daffie probe         */
	int       i, j, k;                      /* loop counters        */
	int       nitem;                        /* total data, items per channel */
	int       xs, ys, prevxs, prevys;       /* screen size          */
	int       ix, iy;                       /* screen coords        */
	int       x0;                           /* panned data origin   */
	int       pan;                          /* pan value            */
	int       key;                          /* mouse key on press   */
	int       imgxs, imgys, *img;           /* image data           */
	double    range, dscale;                /* data range/scale     */
	float     xscale, yscale, off;          /* data offset & scaling*/
	float     v;                            /* a datum              */
	int       select[MAXCHANN], nselect;    /* select channels      */
	char      title[300] = {'\0'};          /* title bar            */
	char     *cmapfile = NULL;              /* color map file name  */
	COLORMAP  cmap[MAX_CMAP];               /* color map from above */
	int       ncmap;                        /* # entriesin above    */
	int       cindx[256];                   /* allocated (X) color cells */
	int       crgb[256];                    /* corresponding rgb val */
	int       chindx[256];                  /* color index by channel*/
	int       plotx0, ploty0;               /* base of plot area     */

	Pgm = argv[0];  if (streq(Pgm, "app_main")) Pgm = "wplot";
	++argv; --argc;

	chann = 0;
	nchan = 0;
	help  = 0;
	ok    = 1;
	type  = 0;
	showmap = 0;
	Sample  = 1;
	probe   = 0;
	while (argc && *argv[0] == '-') {
		char *opt;

		opt = argv[0]+1;
		++argv; --argc;

		if (substr(opt, "help")) ++help;
		else if (substr(opt, "scatter"))     type |= T_SCATTER;
		else if (substr(opt, "line"))        type |= T_LINE;
		else if (substr(opt, "colormapped")) type |= T_COLORMAP;
		else if (substr(opt, "stacked"))     type |= T_STACKED;
		else if (substr(opt, "showmap"))     showmap = 1;
		else if (substr(opt, "probe"))       probe   = 1;
		else if (substr(opt, "ascii"))       Binary  = 0;
		else if (substr(opt, "binary"))      Binary  = 1;
		else if (substr(opt, "bin64"))       Binary  = BinDouble = 1;
		else if (substr(opt, "autopan"))     Autopan = 1;
		else if (substr(opt, "channel")) {
			char *s;
			int           x;

			if (!argc || !isdigit(*argv[0])) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}

			s = argv[0];
			++argv; --argc;

			nchan = chann = 0;
			while (*s && isdigit(*s))
			   nchan = 10*nchan + *s++ - '0';
			if (*s) ++s;
			while (*s && isdigit(*s))
			  chann = 10*chann + *s++ - '0';

			if (!nchan) {
				fprintf(stderr,
					"%s: invalid argument to -%s\n",
					Pgm, opt);
				ok = 0;
			}
		}

		else if (substr(opt, "dimensions")) {
			int   i = 0;
			int   x;
			char *s;

			if (!argc || !isdigit(*argv[0])) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}
			s = argv[0];

			i = 0;
			--s;
			do {
				x = 0; ++s;
				while (isdigit(*s)) x = 10*x + *s++ -'0';
				Dim[i++] = x;
			} while (*s == '.' || *s == 'x');

			++argv; --argc;
		}

		else if (substr(opt, "pan")) {
			if (!argc || !isdigit(*argv[0])) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}

			Pan = 0.01 * atoi(argv[0]);
			++argv; --argc;
		}

		else if (substr(opt, "sample")) {
			if (!argc || !isdigit(*argv[0])) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}

			Sample = atoi(argv[0]);
			++argv; --argc;
		}

		else if (substr(opt, "title")) {
			if (!argc || !isdigit(*argv[0])) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}

			strcpy(title, argv[0]);
			++argv; --argc;
		}
		else if (substr(opt, "range")) {
			if (argc < 2) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
				continue;
			}
			ok &= sscanf(argv[0], " %f", &RangeMin);
			ok &= sscanf(argv[1], " %f", &RangeMax);
			if (!ok) {
				fprintf(stderr,
					"%s: invalid arguments to -%s\n",
					Pgm, opt);
			}
			Autorange = Rerange = 0;
			argv += 2;
			argc -= 2;
		}
		else if (substr(opt, "map")) {
			if (!argc) {
				fprintf(stderr,
					"%s: missing argument to -%s\n",
					Pgm, opt);
				ok = 0;
			}
			else {
				cmapfile = argv[0];
				++argv; --argc;
			}
		}
		else if (substr(opt, "double")) Double = 1;
		else if (streq(opt, "db"))      Double = 1;
		else {
			 fprintf(stderr, "%s: ignoring argument -%s\n", Pgm, opt);
			 ok = 0;
		}
	}

	if (!ok || help || !argc) {
		usage(Pgm, help);
		exit(!help);
	}

	/* See if -dim was given if not -chan */
	if (!nchan && Dim[1]) nchan = Dim[1];
	if (nchan) Nchan = nchan;
	else       Nchan = 1;

	file = argv[0];
	++argv; --argc;

	/* Allocate storage for the data */
	Data = (float *)malloc(MAXDATA * sizeof(float));
	if (!Data) {
		fprintf(stderr, "%s: not enough memory for %d datum\n", Pgm, MAXDATA);
		exit(1);
	}

	/*
	 * Read in data file
	 */
	if (substr("daffie://", file) || substr("//", file)) probe = 1;

	if (!probe) readfile(file);
	else        setprobe(file);

	if (Autorange) {
		RangeMin = DataMin;
		RangeMax = DataMax;
	}
	range = RangeMax - RangeMin;
	dscale = 1.0/range;

	printf("%s: read %d items (min = %f, max = %f)\n",
		Pgm, Ndata, DataMin, DataMax);

	if (Nchan > 1) printf("%s: display channel %d of %d\n", Pgm, chann, Nchan);

	PlotType = type;

	if (!title[0]) sprintf(title, "%s %s", Pgm, file);
	xw_title(title);

	/* Initialize display */
	xw_size(1000, 512);
	xw_init();
	for (i = 0; i < 8; ++i) xw_setcol(i, (i&1)?255:0, (i&2)?255:0, (i&4)?255:0);

	/* Initializing RGB byte ordering table */
	make_rgb_ordering();

	xw_color(7);

#ifdef XWINDOWS
	/* Create back buffer */
	if (Double) {
		int xs, ys;

		xw_qsize(&xs, &ys);
		BackBuf  = xw_unused();
		FrontBuf = xw_select(BackBuf);
		xw_pixmap(1);
		xw_size(xs, ys);
		xw_init();
		for (i = 0; i < 8; ++i)
		    xw_setcol(i, (i&1)?255:0, (i&2)?255:0, (i&4)?255:0);

		xw_select(FrontBuf);
	}
#endif

	/* Create color map */
	ncmap = make_colormap(cmapfile, cmap, MAX_CMAP);

	for (i = 0; i < 128; ++i) {
		int k, ci, rgb;

		j  = ncmap-1 - ((float)i)/127.0 * (ncmap-1);
		ci = xw_alloccol(cmap[j].r, cmap[j].g, cmap[j].b);
	     /****
		printf("Allocated color cell %d for index %d (%d %d %d)\n",
			k, i<<1, cmap[j].r, cmap[j].g, cmap[j].b);
	     ****/
#ifdef XWINDOWS
		if (Double) {
			xw_select(BackBuf);
			xw_setcol(ci, cmap[j].r, cmap[j].g, cmap[j].b);
			xw_select(FrontBuf);
		}
#endif
		k = i<<1;

		cindx[k]   = ci;
		cindx[k+1] = ci;

	     /*****
		rgb = (cmap[j].r<<16) | (cmap[j].g<<8) | cmap[j].b;
	      *****/
		rgb = make_rgb(cmap[j].r, cmap[j].g, cmap[j].b);

		crgb[k]   = rgb;
		crgb[k+1] = rgb;
	}

	if (Nchan) for (i = 0; i < Nchan; ++i) {
		j = ((float) i)/(Nchan-1) * 255.0;
	     /****
		printf("Setting channel %d to cmap entry %d, color cell %d\n", i, j, cindx[j]);
	     ****/
		chindx[i] = cindx[j];
	}

	if (Nchan && !chann) for (i = 0; i < Nchan; ++i) select[i] = 1;
	else for (i = 0; i < Nchan; ++i) select[i] = (i == chann-1);

	if (showmap) {
		int xs, ys, box0, box1;
		float bs;

		xw_qsize(&xs, &ys);
		bs = (float)xs / (float)Nchan;

		for (i = 0; i < Nchan; ++i) {
			printf("Channel %d - color index %d\n", i, chindx[i]);
			xw_color(chindx[i]);
			box0 = i*bs;
			box1 = (i+1)*bs - 1;
			xw_move(box0,  0);
			xw_flbox(box1, ys-1);
		}
		printf("Click in window to continue...\n");
		xw_xyin(&ix, &iy);
	}

	/* Initialize user interface */
	startui();

	x0 = 0;

	img = NULL;
	prevxs = prevys = 0;
	while (!Done) {
		char  text[100];
		int   border = 4;
		int   th, tw, ta, td;   /* text metrics */

		updateui();

		/* Verify/allocate an in-core image buffer for the display */
		xw_qsize(&xs, &ys);
		if (!img || imgxs != xs || imgys != ys) {
			if (img) free(img);
			img = (int *)malloc(xs*ys*sizeof(int));
			if (!img) {
				fprintf(stderr,
					"Not enough memory for %dx%d image buffer\n",
					xs, ys);
				exit(4);
			}
			imgxs = xs;
			imgys = ys;
			memset(img, 0, xs*ys*sizeof(int));
		}

		/* Redraw if window size changed */
		if (xs != prevxs || ys != prevys) {
			prevxs = xs;
			prevys = ys;
			Redraw = 1;
		}

		/*
		 * Set effective number of items to plot given number of
		 * channels and sampling size
		 */
		nitem  = Ndata/(Nchan*Sample);

		/* Do any desired panning */
		pan  = Pan * xs;  /* pan amount */

		if (PanLeft)       x0 = max(x0-pan, 0);
		else if (PanRight) x0 = min(x0+pan, max(0,nitem-xs));
		if (!KeepTrucking) PanLeft = PanRight = 0;
		else {
			unsigned long long now, elapsed;

			now = event_clock();
			elapsed = now-Lastdraw;
			if (elapsed < MINREDRAW)
			   event_sleep(NORMREDRAW-elapsed);
		}

		if (!Redraw && !KeepTrucking) {
			event_sleep(20);
			continue;
		}
		Redraw = 0;

#ifdef XWINDOWS
		/* Use double buffer on X Windows displays */
		if (Double) xw_select(BackBuf);
#endif

		/* Compute data range if necessary */
		if (Autorange && Rerange) {
			if (DataMin < RangeMin) {
				float delta = RangeMin - DataMin;

				while (RangeInc < delta) {
					if (9.0*RangeInc >= delta)
					  while (RangeInc < delta) RangeInc += RangeInc;
					else RangeInc *= 10.0;
				}
				RangeMin -= RangeInc;
				printf("Set Range min to %f\n", RangeMin);
			}
			if (DataMax > RangeMax) {
				float delta = DataMax - RangeMax;

				while (RangeInc < delta) {
					if (9.0*RangeInc >= delta)
					  while (RangeInc < delta) RangeInc += RangeInc;
					else RangeInc *= 10.0;
				}

				RangeMax += RangeInc;
				printf("Set Range max to %f\n", RangeMax);
			}
			Rerange = 0;
		}
		range  = RangeMax-RangeMin;
		if (range > EPSILON) dscale = 1.0/range;
		else                 dscale = 1.0;
		off    = -RangeMin;

		yscale = ys*dscale;

		/*
		 * Redraw the display
		 */
		xw_erase();
		xw_color(7);
		xw_move(0, 0);

		plotx0 = 0;
		ploty0 = 1;

		nselect = 0;
		for (k = 0; k < Nchan; ++k) if (select[k]) ++nselect;
		if (!nselect) {
			printf("nothing selected!!!");
			break;
		}

		if (PlotType & T_STACKED) yscale /= Nchan;

		if (PlotType & T_COLORMAP) {
			if (!img) for (i = 0; i < min(xs, nitem); ++i) {
				float yband;
				int    iy;

				 yband = (float)(ys - ploty0) / (float)Nchan;

				ix = plotx0 + i;
				xw_move(ix, ploty0);

				for (k = 0; k < Nchan; ++k) {
					int ci;

				     /******
					v  = Data[Nchan*(x0 + i*Sample) + k];
				      *****/
					v = datum(Data, x0+i, k, Sample);

					ci = (v+off)*dscale * 255.0 + 0.5;
					xw_color(cindx[ci]);

					iy = (k+1) * yband;

					xw_draw(ix, iy);
				}
			}
			else {
			  for (i = 0; i < min(xs, nitem/Sample); ++i) {
				float yband;
				int   iy0, iy1;
				int  *pix;

				yband = (float)(ys - ploty0) / (float)Nchan;

				ix  = plotx0 + i;
				iy0 = ploty0;

				pix = img + imgxs * (imgys-1) + ix;

				for (k = 0; k < Nchan; ++k) {
					int ci, rgbcol;

				     /*******
					v  = Data[Nchan*(x0 + i*Sample) + k];
				      *******/
					v = datum(Data, x0+i, k, Sample);

					ci = (v+off)*dscale * 255.0 + 0.5;
					rgbcol = crgb[ci];
					iy1 = (k+1) * yband;

					while (iy0++ <= iy1) {
						*pix = rgbcol;
						pix -= xs;
					}
					--iy0;
				}
			  }
			  /* Fill remainder of image with black */
			  for (ix = i; ix < imgxs; ++ix)
			    for (iy = ploty0; iy < imgys; ++iy)
				img[imgxs*iy + ix] = 0;

			  /* Send above created image to the display */
			  xw_showimage(img, i, imgys, 0, imgys-1, 0);
			}
		}
		else for (k = 0; k < Nchan; ++k) {
			if (!select[k]) continue;

			if (nselect > 1) {
			     /***
				printf("plotting chan %d color %d\n", k, chindx[k]);
			      ***/
				xw_color(chindx[k]);
			}
			else xw_color(7);

			if (PlotType & T_STACKED) ploty0 = k*(float)ys/(float)Nchan;

			for (i = 0; i < min(xs, nitem/Sample); i += Sample) {
				v  = Data[Nchan*(x0 + i*Sample) + k];
				ix = plotx0 + i;
				iy = ploty0 + yscale*(v+off);

				if (PlotType & T_SCATTER || !i) xw_move(ix, iy);

				xw_draw(ix, iy);
			}
		}

		if (!(PlotType & (T_STACKED|T_COLORMAP))) {
			iy = yscale*off;
			xw_color(1);
			xw_move(plotx0,  1+iy);
			xw_draw(xs,      1+iy);
		}
		xw_color(7);
		sprintf(text, "%d", Domain_X0/Nchan + x0);
		xw_qtext(text, &tw, &th, &ta, &td);

		xw_move(border, border);
		xw_text(text);
		xw_move(border, ys - border - th);
		xw_text(text);

		sprintf(text, "%d", min(nitem, x0+xs*Sample-1));
		xw_qtext(text, &tw, &th, &ta, &td);

		xw_move(xs-tw-border, border);
		xw_text(text);
		xw_move(xs-tw-border, ys - border - th);
		xw_text(text);

		xw_flush();

#ifdef XWINDOWS
		if (Double) {
			int xs, ys;

			xw_qsize(&xs, &ys);
			xw_select(FrontBuf);
			xw_copyfrom(BackBuf, 0, 0, xs, ys, 0, 0);
			xw_flush();
		}
#endif
		Lastdraw = event_clock();


	}
#ifdef XWINDOWS
	xw_erase();
	xw_flush();
	sleep(1);
	xw_fini();
#endif
}