#!/bin/sh
: "This is a shell archive, meaning:                              "
: "1. Remove everything above the #! /bin/sh line.                "
: "2. Save the resulting test in a file.                          "
: "3. Execute the file with /bin/sh (not csh) to create the files:"
: "	README"
: "	VERSIONLOG"
: "	a.c"
: "	animate.c"
: "	chattrib.c"
: "	cbtable.c"
: "	control.c"
: "	contour.c"
: "	contourlevel.c"
: "	ctlcontour.c"
: "	data.c"
: "	dtmstuff.c"
: "	getfile.c"
: "	glob.c"
: "	gr_xwi.c"
: "	graph.c"
: "	i.c"
: "	image.c"
: "	intensity.c"
: "	main.c"
: "	mem.c"
: "	notebook.c"
: "	palentry.c"
: "	palette.c"
: "	profile.c"
: "	polar.c"
: "	read.c"
: "	shade.c"
: "	sliceSDS.c"
: "	write.c"
: "	xstuff.c"
: "	xstuff2.c"
: "	xinit.c"
: "	y.tab.c"
: "	parse.c"
: "	parseSupport.c"
: "	fcmp1.c"
: "	remote.c"
: "	list.c"
: "	date.c"
: "	gram.y"
: "	exp.l"
: "	lex.yy.c"
: "	parse2.c"
: "	DScope.h"
: "	animate.h"
: "	buttons.h"
: "	data.h"
: "	dataObject.h"
: "	fview.h"
: "	getfile.h"
: "	gr_com.h"
: "	gr_def.h"
: "	gr_ext.h"
: "	gr_inc.h"
: "	gr_var.h"
: "	gr_xwi.h"
: "	i.h"
: "	libmgrP.h"
: "	list.h"
: "	listP.h"
: "	mac.h"
: "	mem.h"
: "	notebook.h"
: "	palentry.h"
: "	paletteP.h"
: "	parse.h"
: "	parseSupport.h"
: "	patterns.h"
: "	process.h"
: "	resources.h"
: "	sem_stack.h"
: "	sem_stack_t.h"
: "	types.h"
: "	value.h"
: "	ximage.h"
: "	xstuff.h"
: "	xstuff2.h"
: "	ximage.icon"
: "	ximage.1"
: "	Makefile"
: "
: "Example: type the following:   "
: " 	/bin/sh nameofthisfile    "
: "
: "This archive created:  Fri Nov 1 16:42:29 CST 1991 "
echo file: README
sed 's/^X//' >README << 'END-of-README'
XThis directory contains source code for NCSA X Image Version 1.2.
XAt the time of this writing (7/2/91), this source code has been 
Xsuccessfully compiled on the following platforms.
X
X	Sun 3 (SunOS 4.0.3)
X	Sun 4 (SunOS 4.1)
X	DECstation 3100 (Ultrix 4.0)
X	IBM RS6000 (AIX 3.1 3003)
X	Silicon Graphics PI (OS 3.3.1)
X	Motorola 3200 (System V/68 R3V6)
X	Cray 2 (UNICOS 6.0)
X	Cray YMP (UNICOS 6.0)
X
XIn most cases they have successfully been compiled using either the
XX.V11R4 or X.V11R3 X window libraries from MIT.
X
XShould you decide to compile X Image, you will need HDF 
X(Hierarchical Data Format) version 3.1 or later.  Source code is 
Xavailable from NCSA's anonymous ftp server (141.142.20.50).   
X
XVersion 1.2 of XImage will read data sent over a network via the 
XDTM protocol/library also available on the NCSA anonymous ftp server.
X
XThe public domain 2D HP widget set is also required to compile XImage.
XYou may get this from the NCSA's anonymous ftp server. 
X
XIf you successfully port NCSA X Image to a machine not currently supported,
Xwe would be interested in getting a copy of your patches and binaries.
XSend info to softdev@ncsa.uiuc.edu.
X
XThis NCSA software product is public domain software.  Permission
Xis granted to do whatever you like with it.  We would appreciate it
Xif you would tell us how you use our software, what you think of the 
Xsoftware, additional features you would like to see, etc.  Please
Xsend your comments to softdev@ncsa.uiuc.edu
X
XPlease send bug reports/fixes to:
XDave Thompson
Xdavet@ncsa.uiuc.edu
Xand bugs@ncsa.uiuc.edu
X
X--------
XThe latest version of all NCSA software is kept on the anonymous ftp 
Xserver ftp.ncsa.uiuc.edu (141.142.20.50).  If you don't have access to
Xthe anonymous ftp server, you can obtain a copies through the 
XNCSA Technical Resources Catalog.  NCSA software and manuals 
Xare available for purchase.  To obtain a copy of the catalog, contact:
X
XNCSA Documentation Orders
X152 Computing Applications Building
X605 East Springfield Avenue
XChampaign, IL 61820
X(217) 244-0072
X
X--------
X
XSample data files and PRE-MADE EXECUTABLES may be picked up from 
Xftp.ncsa.uiuc.edu (141.142.20.50)
X
XThe pre-made executables may save you the trouble of compiling 
Xximage, hdf, and the 2D HP widget set for your system.
X
X--------
XCompile instructions:
X
X	You will need to tell the Makefile where your X libraries and 
X	headers are.  See the Makefile for instructions.
X	Edit the Makefile to fit your system.  Type 'make'.  
X
X
X-------------
X
XNOTICE:  Version 1.0.4 (and later) obtains an install Colormap resource which
Xtells it how to handle colormap installation.
X
XTWM previous to R4 patch 8 distributed with X11R4 requires that 
Xclients follow ONLY ICCCM rules for setting colormaps.  Previously
XXimage tried to satisfy all window managers by following ICCCM conventions and
Xthe standard method previous to ICCCM which was to XInstallColormap.
XThe default now is for ximage to follow ICCCM conventions by setting
Xa colormap attribute.
X
XIf you are using a non ICCCM window manager (such as some R3 or all
Xprevious to R2 or the standard wm on the IRIS IRIX3.3 or earlier) 
Xyou will need to do the following:
X
XEdit your .Xdefaults file in your home directory so that it contains
Xa line like the following:
X
Xximage*installCMap:     True
X
XIf you are using an ICCCM compliant window manager, you may want
Xto have a line that looks like this:
X
Xximage*installCMap:     False
X
XNote: installCMap is set to False by default, so the above line is
Xnot necessary.
X
X
END-of-README
echo file: VERSIONLOG
sed 's/^X//' >VERSIONLOG << 'END-of-VERSIONLOG'
XPlease send bug reports and fixes to davet@ncsa.uiuc.edu.
X
X
XVersion 1.0.0	(9/17/89)
X		First Release
X
XVersion 1.0.1	(9/24/89)
X		Fixed XtTextReplace() call in PrintMesg() in module control.c
X
X		Fixed IsItHDF() in read.c.  DFR8GetDims() dumped core b/c 
X			hasPal was char instead of int.
X
X		palette.c: no longer assumes 8 planes means 256 colors.
X			It does a XDisplayCells() lookup now.
X
X		Changed (void *) to (char *) for portability.
X
XVersion 1.0.2	(10/19/89)
X		xstuff.c: 
X			Added Callback for EnterWindow event to all 
X			dialog widgets.  Callback sets input focus to the 
X			window when cursor enters.  
X			Makes text input compatible with OpenLook 
X			and Motif wm.  
X
X			MakeRasterImage(): image param not defined.
X			fixed.
X
X		animate.c: Prevent user from hitting 'Done' button
X			while animation is still running.
X
X			Put in XSync after XClearArea to get events
X			from server dispatched while animation going on.
X
X			Added support for machines with > 8 bit planes.
X
X			Defined a usleep macro for SYSV machines.
X
X		palette.c:
X			Added support for machines with > 8 bit planes.
X
X			didn't uninstall palette before XtDestroy.
X			with some wm, palette was screwed up.
X
X		xinit.c:
X			(Added) Print out Display information upon startup.
X
X		image.c:
X			Added support for machines with > 8 bit planes.
X
X		getfile.c:
X			Clear current filename when opening getfile.
X
X			Allocate space to hold filenames instead hoping
X			that the values returned from readdir() would
X			stick around long enough.
X
X		i.c:
X			NewIMAGE() didn't set i->prev to previous IMAGE.
X
XVersion 1.0.3 (11/29/89)
X		Several changes made to source to make it comply with
X		X11R4 contrib tape guidelines.
X
X		getfile.c:
X			Change directory when user presses return.
X			Change directory when user selects on directory.
X
XVersion 1.0.4 (4/13/90)
X
X		Several Changes in various modules to make compile under
X			X.V11R4.
X		
X		getfile.c:
X			Various changes to make file entering smoother.
X
X		
X		Numerous bug fixes.
X
XVersion 1.1 (10/4/90)
X
X		Numerous bug fixes Including core dumps on animations.
X		HSV color model fixed in palette.
X	
X		New features include: profile graph, area selection
X		for histogram and DTM support
X
XVersion (1.2)
X		contains many bug fixes, feature enhancements, etc.
X		new features include:
X			DTM network input
X			mathmatical notebook parser
X			expansion of image (pixel replication & interpolation)
X			color contours
X
XVersion (1.2.1) (11/1/91)
X		fixes animation X event pause problem.
X			changed XtPending() to XPending().
X		Ultrix executable was linked with a bad HDF library.
END-of-VERSIONLOG
echo file: a.c
sed 's/^X//' >a.c << 'END-of-a.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include "ximage.h"
X#include "animate.h"
X
X#define NIL     (struct ANIMATION *) 0
X
Xextern void CBDoneAnimateCtrlBox();
X
Xstruct ANIMATION *headANIMATION = NIL;
Xstruct ANIMATION *tailANIMATION = NIL;
X
X
Xstruct ANIMATION *NewAnimation()
X{
Xstruct ANIMATION *a;
X	
X
X	if (!(a = (struct ANIMATION *) XIMalloc(sizeof(struct ANIMATION)))) 
X		return(NULL);
X
X	a->name = (char *) 0;
X	a->xdim = 0;
X	a->ydim = 0;
X	a->files = (char **) NULL;
X	a->numFrames = 0;
X	a->frameNum = 0;
X	a->skip = 0;
X	a->status = A_STOP;
X	a->inMemory = FALSE;
X	a->ctrl_showing = FALSE;
X	a->pixmaps = (Pixmap *) NULL;
X	a->raster = (unsigned char *) NULL;
X	a->expRaster = (unsigned char *) NULL;
X	a->isExpanded = FALSE;
X
X	a->next = NIL;
X	a->prev = NIL;
X
X	if (headANIMATION == NIL)
X	        tailANIMATION = headANIMATION = a;
X	else {
X	        tailANIMATION->next = a;
X		a->prev = tailANIMATION;
X	        tailANIMATION = a;
X	        }
X
X	return(a);
X
X} /* NewAnimation() */
X
Xvoid DestroyAnimation(a)
Xstruct ANIMATION *a;
X{
X        if (a->prev)
X                a->prev->next = a->next;
X        else
X                headANIMATION = a->next;
X        if(a->next)
X                a->next->prev = a->prev;
X        else
X                tailANIMATION = a->prev;
X
X	if (a->isExpanded)
X		XIFree(a->expRaster);
X
X	XIFree(a->files);
X	XIFree(a->name);
X	return;
X}
X
Xvoid ReleaseAllAnimations()
X{
X	while (headANIMATION)
X		CBDoneAnimateCtrlBox(0,headANIMATION,0);
X}
END-of-a.c
echo file: animate.c
sed 's/^X//' >animate.c << 'END-of-animate.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X/*#include <X11/StringDefs.h>*/
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#ifndef XtSpecificationRelease
X/* previous to R4 */
X#include <X11/Dialog.h>
X#include <Xw/Xw.h>
X#include <Xw/Valuator.h>
X#else
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xw/Xw.h>
X#include <X11/Xw/Valuator.h>
X#endif
X
X#include "ximage.h"
X#include "animate.h"
X#include "xstuff.h"
X#include "getfile.h"
X
X#define	PAL_WIDTH	30
X#define PBOXHEIGHT	40
X#define PBOXWIDTH	360
X#define	ACBOXWIDTH	360
X#define ACBOXHEIGHT	100
X
X#ifdef SYSV 
X/*#include <sys/time.h>*/
Xstruct timeval   st_delay;
X#define usleep(x)   { \
X        st_delay.tv_usec = (x % 1000000); \
X        st_delay.tv_sec = (x / 1000000); \
X        select(32, NULL, NULL, NULL, &st_delay); }
X#endif
X
X#ifdef ULTRIX
X/*#include <sys/time.h>*/
Xstruct timeval   st_delay;
X#define usleep(x)   { \
X        st_delay.tv_usec = (x % 1000000); \
X        st_delay.tv_sec = (x / 1000000); \
X        select(32, NULL, NULL, NULL, &st_delay); }
X#endif
X
X#ifdef IRIS4
X/*#include <sys/time.h>*/
Xstruct timeval   st_delay;
X#define usleep(x)   { \
X        st_delay.tv_usec = (x % 1000000); \
X        st_delay.tv_sec = (x / 1000000); \
X        select(32, NULL, NULL, NULL, &st_delay); }
X#endif
X
Xextern	Widget	toplevelform;		/* the top composite widget */
Xextern  XColor  origccells[];		/* currently defined in palette.c*/
Xextern  XColor  rccells[];		/* currently defined in palette.c*/
X
Xextern	void	SetColormap();	
Xextern	struct	ANIMATION *NewAnimation();
Xextern	void	DestroyAnimation();
Xextern	void	GetAFile();
Xextern	void	gr_DialogSetValue();
Xextern	void	CBInstallImageCMap();
Xextern	void	CBUnInstallImageCMap();
Xextern	void	StoreColors();
X
Xstatic	XImage	*palXImage;	/* display palette with this */
Xstatic	struct	GetFile	animateFile;
Xstatic	Widget	toggled,togglem;
Xstatic	Visual	*myVis;
Xstatic	Display *myDpy;
Xstatic	char	badAllocError = False;
X
Xvoid	AnimateCtrlBox();
X
X
X
X
Xint InitAnimation(dpy)
XDisplay *dpy;
X{
X	myDpy = dpy;
X	myVis = GetVisual(myDpy);
X
X	if (!(palXImage = MakePalette(myDpy,PAL_WIDTH,TRUE))) {
X		return(0); /* malloc probably failed */
X		}
X
X	return(1);
X} /* InitAnimation() */
X
X
X
Xchar *ComboFile(directory,file)    /*what?*/
Xchar *directory;
Xchar *file;
X{
Xstatic char combo[512];
X
X	sprintf(combo,"%s/%s",directory,file);
X	return(combo); /* good till called again */
X}
X
X
Xstatic void DidntGetANewAnimation(a)
Xstruct ANIMATION *a;
X{
X	PrintMesg("Get new animation sequence cancelled\n");
X	DestroyAnimation(a);
X}
X
XCBinMemory(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	ANIMATION *a;
X
X	a = (struct ANIMATION *) client_data;
X	a->inMemory = ! a->inMemory;
X	if (a->inMemory) {
X		PrintMesg("Animate from server memory\n");
X		SetToggle(toggled,False);
X		SetToggle(togglem,True);
X		}
X	else {
X		PrintMesg("Animate from disk\n");
X		SetToggle(togglem,False);
X		SetToggle(toggled,True);
X		}
X	
X}
X
XCBinMemoryDone(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	XtDestroyWidget(a->topQbox);
X	
X	AnimateCtrlBox(a);
X}
X
XAnimateError(dpy,myErr)
XDisplay *dpy;
XXErrorEvent *myErr;
X{
Xchar buff[1024];
X	badAllocError= True;
X#ifdef DEBUG
X	fprintf(stderr,"XErrorHandler:\n");
X	XGetErrorText(myDpy,myErr->error_code,buff,1024);
X	fprintf(stderr,"\n******X server out of memory:%s\n",buff);
X	fprintf(stderr,"resource id: %d\n",myErr->resourceid);
X#endif
X}
XAnimateIOError(dpy,myErr)
XDisplay *dpy;
XXErrorEvent *myErr;
X{
Xchar buff[1024];
X	badAllocError= True;
X#ifdef DEBUG
X	fprintf(stderr,"XIOErrorHandler:\n");
X	XGetErrorText(myDpy,myErr->error_code,buff,1024);
X	fprintf(stderr,"\n******X server out of memory:%s\n",buff);
X	fprintf(stderr,"resource id: %d\n",myErr->resourceid);
X#endif
X}
X
Xstatic void GotANewAnimation(a)
Xstruct ANIMATION *a;
X{ /* initialize animation record */
Xchar buff[256];
X
X	XSetErrorHandler(AnimateError);
X	/*XSetIOErrorHandler(AnimateIOError);*/
X	XSync(myDpy,False);
X	a->name = animateFile.base;
X
X	a->directory = animateFile.directory;
X	a->files= animateFile.file;
X	a->numFiles = animateFile.numFiles;
X	a->xdim = animateFile.xdim;
X	a->ydim = animateFile.ydim;
X
X	a->isHDF = animateFile.isHDF;
X	a->isFloat = animateFile.isFloat;
X	a->frameNum = 1;
X	a->skip = 0;
X	a->status = A_STOP;
X
X/**/	a->numFrames = a->numFiles;
X	if (a->numFiles == 1)  {
X		if (a->isHDF) {
X			if (a->isFloat) 
X			    a->numFrames = HowManySDSInHDF(
X					ComboFile(a->directory,a->files[0]));
X			else {
X			    a->numFrames = HowManyImagesInHDF(
X					ComboFile(a->directory,a->files[0]));
X			    if(!(a->frameIndex = (int *) XICalloc(a->numFrames,
X						sizeof(int)))) {
X					PrintMesg("out of memory\n");
X					return;
X					}
X			    if (!MakeHDFImageIndex(ComboFile(a->directory,
X							a->files[0]),
X						a->frameIndex,
X						a->numFrames)) {
X					PrintMesg("Can't read HDF file\n");
X					return;
X					}
X
X			    }
X			}
X		}
X	
X	if (a->numFrames < 2) {
X		PrintMesg("Animation requires more than one frame\n");
X		PrintMesg("Cancelling Animation\n");
X		return;
X		}
X		
X	sprintf(buff,"Animation sequence has %d images\n",a->numFrames);
X	PrintMesg(buff);
X
X	/* read in Palette */
X/*	a->hasPalette = FALSE;*/
X
X	a->hasPalette = TRUE;
X/**/	a->palette = origccells;
X	if (a->isHDF) {
X	    if (ReadHDFHasPalette(ComboFile(a->directory,a->files[0])) > 0){
X		    if (!(a->palette=(XColor *)XICalloc(256,sizeof(XColor)))){
X			PrintMesg("Not enough memory for palette\n");
X			return;
X			}
X		    ReadHDFPalette(ComboFile(a->directory,a->files[0]),
X				a->palette);
X		    a->hasPalette = TRUE;
X		    }
X		}
X	a->inMemory = False;
X	{
X	Widget comp;
X	int screen;
X
X        screen = XDefaultScreen(myDpy);
X	a->topQbox = MakeATopLevelOverride("X Image [Animation].inMemory?",
X				toplevelform,
X				(DisplayWidth(myDpy,screen)-200)/2,
X				(DisplayHeight(myDpy,screen)-100)/2,
X				200,100);
X	comp = Make_Board("inMemory?",a->topQbox,0,0,200,200);
X	togglem =  Make_Toggle("animate from X server memory",comp,5,20,
X			CBinMemory,a,CBinMemory,a,False,a->inMemory);
X	toggled =  Make_Toggle("animate from disk",comp,5,50,
X			CBinMemory,a,CBinMemory,a,False,!a->inMemory);
X	(void) MakeButton("     Ok     ",comp,5,70,CBinMemoryDone,a,0,0);
X	}
X	
X} /* GotANewAnimation() */
X
X
Xvoid CBNewAnimate(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	ANIMATION *a;
X
X	if (!(a = NewAnimation())){
X		PrintMesg("Out of memory\n");
X		return;
X		}
X	animateFile.yesfile = GotANewAnimation;
X	animateFile.nofile = DidntGetANewAnimation;
X	animateFile.type = FTYPE_IMAGE;
X	animateFile.param = (char *) a;
X	PrintMesg("Please select animation file(s)\n");
X	GetAFile(&animateFile);
X} /* CBNewAnimate() */
X
Xvoid CBDoneAnimateCtrlBox(w,client_data,call_data)
XWidget	w;
Xcaddr_t	client_data;
Xcaddr_t call_data;
X{
Xint x;
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	if (a->status != A_STOP) {
X		a->status = A_STOP;
X		/* instead of returning here, should clean up and close */
X		/* currently reuquires a double click on Done if animation */
X		/* is running. */
X		return;	
X		}
X
X	if (a->inMemory) {
X		PrintMesg("Freeing server memory\n");
X		for (x = 0; x < a->numFrames; x++)
X			XFreePixmap(myDpy,a->pixmaps[x]);
X		}
X	XIFree(a->pixmaps);
X	XIFree(a->raster);
X
X	if (a->ctrl_showing) {
X/*#ifdef  NON_ICCCM_WINDOW_MANAGER*/
X	        CBUnInstallImageCMap(a->topLevel,a->cmap,call_data);
X/*#endif*/
X		XtDestroyWidget(a->topLevel);
X		}
X
X	DestroyAnimation(a);
X
X	return;
X} /*CBDoneAnimateCtrlBox() */
X
X
Xstatic void CBUpdateCMap(w,client_data,call_data)
X/* Update colormap in client_data to be same as palette module's rccells */
X/* ....Sync image palette with palette windows palette */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XColormap cmap;
X        cmap = (Colormap) client_data;
X        StoreColors(rccells,FALSE,cmap);
X}
X
X
Xstatic void CBLockPalette(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X        a->lockcmap = ! a->lockcmap;
X        if (a->lockcmap) {
X                StoreColors(rccells,FALSE,a->cmap);
X                XtAddEventHandler(a->topLevel,EnterWindowMask,0,
X                        CBUpdateCMap,a->cmap);
X		}
X        else {
X                if (a->hasPalette) 
X                        StoreColors(a->palette,FALSE,a->cmap);
X                else
X                        StoreColors(origccells,FALSE,a->cmap);
X
X                XtRemoveEventHandler(a->topLevel,EnterWindowMask,
X			0,CBUpdateCMap,a->cmap);
X		}
X} /* CBLockPalette() */
X
X
Xstatic int GetNextImage(a,frameNum)
X/* prepare and put next image into a->raster or a->expRaster*/
X/* takes care of source: HDF or SEQ, multiple or single file */
X/* return 0 on error */
X
Xstruct ANIMATION *a;
Xint frameNum; /* start at 1 (1..infinity) */
X{
Xregister int x;
Xregister int y;
Xregister int z;
Xint     planes;
Xint     nbp;    /* number of bytes per pixel */
Xunsigned char *p;
Xchar buff[1024];
X
X	if (! a->isHDF) {
X		/* multiple SEQ files */
X
X		if (! ReadSEQAnimation(ComboFile(a->directory,
X				a->files[frameNum-1]),
X			a->raster,a->xdim,a->ydim)) {
X			sprintf(buff,"SEQ Read Failed on %s\n",
X				ComboFile(a->directory,
X				a->files[frameNum-1]));
X			PrintMesg(buff);
X			return(0);
X			}
X		}
X	else {
X		/* it's an HDF file */
X
X		if (a->numFiles == 1) {
X			/* animate from one HDF file */
X
X			if (a->isFloat) {
X				/*read in float
X				convert it
X				*/
X				PrintMesg("Can't animate float yet\n");
X				return(0); /*for now */
X				}
X			else { 
X				if (!ReadHDFAnimationImage(
X					ComboFile(a->directory,a->files[0]),
X				   a->raster,a->frameIndex[frameNum-1])) {
X					sprintf(buff,"Read Failed for %s\n",
X					   ComboFile(a->directory,a->files[0]));
X					PrintMesg(buff);
X					return(0);
X					}
X				}
X			}
X		else { /* animate from multiple HDF files */
X			if (a->isFloat) {
X				/*
X				read in float
X				convert it
X				*/
X				PrintMesg("Can't animate SDS yet\n");
X				return(0); /*for now */
X				}
X			else {
X#ifdef DEBUG
X				printf("reading in %s\n", 
X				  ComboFile(a->directory,a->files[frameNum-1]));
X#endif
X				if (!ReadHDFAnimationImage(
X				  ComboFile(a->directory,a->files[frameNum-1]),
X					a->raster,1)) {
X					sprintf(buff,"Read Failed for %s\n",
X				  		ComboFile(a->directory,
X						a->files[frameNum-1]));
X					PrintMesg(buff);
X					return(0);
X					}
X				}
X			}
X		} /* else: it's an HDF */
X
X
X	if (a->expRaster) {
X	        planes = DisplayPlanes(myDpy,DefaultScreen(myDpy));
X	
X		nbp = (planes > 7) ? (planes / 8 + ((planes%8)?1:0)) :1;
X
X	        if (nbp >= 3)
X			nbp = 4;
X
X		p = a->expRaster;
X		for(y = 0; y < a->ydim; y++)
X			for(x = 0; x < a->xdim; x++) {
X				for (z = 1; z < nbp; z++){
X					(*p) = (unsigned char) 0;
X					p++;
X					}
X				(*p) = a->raster[y*a->xdim+x];
X				p++;
X				}
X		}
X
X
X	return(1);/* ok */
X
X} /* GetNextImage() */
X
X
Xstatic int DisplayImage(a,frameNum)
Xstruct ANIMATION *a;
Xint frameNum;
X{
XArg	arglist[1];
Xchar	buff[256];
X
X	if (! a->inMemory) {
X		if (!GetNextImage(a,frameNum)) {
X			if (a->numFiles == 1) 
X			    sprintf(buff,"Couldn't get %dth image out of %s\n",
X				frameNum,ComboFile(a->directory,a->files[0]));
X			else 
X			    sprintf(buff,"Couldn't get image from file %s\n",
X				ComboFile(a->directory,a->files[frameNum-1]));
X			PrintMesg(buff);
X			return(0);
X			}
X
X		XPutImage(myDpy,XtWindow(a->awin),
X				a->awinGC,a->image,
X				0,0,0,0,a->xdim,a->ydim);
X		}
X	else {
X
X/*		XSetFunction(myDpy,a->awin,GXcopy);*/
X		XSetWindowBackgroundPixmap(myDpy,
X					XtWindow(a->awin),
X					a->pixmaps[frameNum-1]);
X		XClearArea(myDpy,XtWindow(a->awin),
X				0,0,a->xdim,a->ydim,False);
X		XSync(myDpy,False);
X/*		XPutImage(myDpy,XtWindow(a->awin),
X				a->awinGC,a->image,
X				0,0,0,0,a->xdim,a->ydim);
X*/
X		}
X	
X	/* Set dialog */
X	sprintf(a->dFrameString,"%d",a->frameNum);
X	gr_DialogSetValue(a->dFrame,a->dFrameString);
X
X	/* Set valuator */
X	XtSetArg(arglist[0],XtNsliderOrigin,frameNum);
X	XtSetValues(a->slidebar,arglist,1);
X
X	return(TRUE);
X}
X
Xstatic void PrepMemAnimation(a)
Xstruct ANIMATION *a;
X{
Xint x;	
Xint	screen;
Xint	frameSize;
Xunsigned char *memPtr;
X
X	screen = XDefaultScreen(myDpy);
X	memPtr = a->dataCube;
X	frameSize = a->xdim * a->ydim;
X	for (x = 0; x < a->numFrames; x++) {
X#ifdef DEBUG
X		printf("a->numFrames = %d: creating pixmap %d;raster=0x%x\n",
X						a->numFrames,x,a->raster);
X#endif
X		a->pixmaps[x] = XCreatePixmap(myDpy,
X					XtWindow(a->awin),
X					a->xdim,a->ydim,
X					DisplayPlanes(myDpy,screen));
X#ifdef DEBUG 
X		printf("XCreatePixmap returns %d\n",a->pixmaps[x]);
X#endif
X
X		memcpy(a->raster,memPtr,frameSize);
X		memPtr += frameSize;
X		XPutImage(myDpy,a->pixmaps[x],a->awinGC,a->image,
X					0,0,0,0,a->xdim,a->ydim);
X
X		XSetWindowBackgroundPixmap(myDpy,
X					XtWindow(a->awin),
X					a->pixmaps[x]);
X		XClearArea(myDpy,XtWindow(a->awin),
X				0,0,a->xdim,a->ydim,False);
X#ifdef DEBUG
X		printf("a->pixmaps[%d]=%d\n",x,a->pixmaps[x]);
X#endif
X		XSync(myDpy,False);
X		}
X	XIFree(a->dataCube);
X
X} /* PrepMemAnimation() */
X
Xstatic int ReadThemAll(a)
X/* return 1 on success, 0 on failure */
Xstruct ANIMATION *a;
X{
Xregister int x,j;
Xchar buff[80];
Xfloat	fourth;
Xint	screen;
X
X	screen = XDefaultScreen(myDpy);
X
X	sprintf(buff,"Reading in %d frames into server memory\n",a->numFrames);
X	PrintMesg(buff);
X
X	badAllocError = False;
X	XSynchronize(myDpy,1);
X	fourth = ((float) a->numFrames) / 4.0;
X	for (j = 0; j < 4; j++) {
X	    for (x = ROUND(((float)j)*fourth) 
X		     ;x < ROUND((((float)j)+1.0)*fourth); x++ ) {
X
X		if (! GetNextImage(a,x+1)) {
X			XSynchronize(myDpy,0);
X			return(0);
X			}
X
X		if (!badAllocError)
X			a->pixmaps[x] = XCreatePixmap(myDpy,
X					XtWindow(a->awin),
X					a->xdim,a->ydim,
X					DisplayPlanes(myDpy,screen));
X#ifdef DEBUG 
X		printf("XCreatePixmap returns %d\n",a->pixmaps[x]);
X#endif
X		if (badAllocError) {
X			PrintMesg("Out of X server memory. \n");
X			a->numFrames = x-1;
X			sprintf(buff,"Truncating animation to %d frames\n",
X					a->numFrames);
X			PrintMesg(buff);
X			SetValuatorMax(a->slidebar,a->numFrames+1);
X			PrintMesg("Done loading animation images\n");
X			XSynchronize(myDpy,0);
X			return(1);
X			}
X		else {
X			XPutImage(myDpy,a->pixmaps[x],a->awinGC,a->image,
X					0,0,0,0,a->xdim,a->ydim);
X
X			XSetWindowBackgroundPixmap(myDpy,
X					XtWindow(a->awin),
X					a->pixmaps[x]);
X			XClearArea(myDpy,XtWindow(a->awin),
X				0,0,a->xdim,a->ydim,False);
X			XSync(myDpy,False);
X			}
X
X		}
X	    switch (j) {
X		case 0: PrintMesg("Done loading 25% of animation images\n");
X			break;
X		case 1: PrintMesg("Done loading 50% of animation images\n");
X			break;
X		case 2: PrintMesg("Done loading 75% of animation images\n");
X			break;
X		case 3: PrintMesg("Done loading animation images\n");
X			break;
X		};
X	}
X	XSynchronize(myDpy,0);
X	return(1);
X} /* CBReadThemAll() */
X
X
Xstatic void CBSingleForward(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	a->frameNum = a->frameNum + 1 + a->skip;
X
X	if ((a->frameNum > a->numFrames) || (a->frameNum < 1)) {
X		if (a->repeat || (a->status == A_STOP))
X			a->frameNum = 1;
X		else {
X			a->frameNum = a->frameNum - 1 - a->skip;
X			a->status = A_STOP;
X			return;
X			}
X		}
X
X	DisplayImage(a,a->frameNum);
X
X	return;
X
X} /* CBSingleForward */
X
X
X
Xstatic void CBSingleReverse(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	a->frameNum = a->frameNum - 1 - a->skip;
X
X	if ((a->frameNum > a->numFrames) || (a->frameNum < 1))
X		if (a->repeat || (a->status == A_STOP))
X			a->frameNum = a->numFrames;
X		else {
X			a->frameNum = a->frameNum + 1 + a->skip;
X			a->status = A_STOP;
X			return;
X			}
X
X	DisplayImage(a,a->frameNum);
X
X
X	return;
X} /* CBSingleReverse() */
X
X
X
Xstatic void CBStop(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	((struct ANIMATION *)client_data)->status = A_STOP;
X}
X
Xstatic void CBContinuousForward(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XXEvent event_return;
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	a->status = A_CFOR;
X	while(a->status == A_CFOR) {
X
X		CBSingleForward(w,client_data,call_data);
X
X		while(XPending(myDpy)) {
X			XtNextEvent(&event_return);
X			XtDispatchEvent(&event_return);
X			}
X		if (a->delay)
X			usleep((a->delay)*100000); /* a->delay in 1/10 sec*/
X		}
X} /* CBContinuousForward() */
X
X
Xstatic void CBContinuousReverse(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XXEvent event_return;
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	a->status = A_CREV;
X	while(a->status == A_CREV) {
X
X		CBSingleReverse(w,client_data,call_data);
X
X		while(XPending(myDpy)) {
X			XtNextEvent(&event_return);
X			XtDispatchEvent(&event_return);
X			}
X		if (a->delay)
X			usleep((a->delay)*100000); /* a->delay in 1/10 sec*/
X		}
X} /* CBContinuousReverse() */
X
X
Xstatic void CBSetFrame(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
Xint	newFrame;
Xchar	buff[80];
X
X	a = (struct ANIMATION *) client_data;
X
X	newFrame = atoi(XtDialogGetValueString(a->dFrame));
X	if ((newFrame > a->numFrames) || ( newFrame < 1)) {
X		sprintf(buff,"Frame number out of Range (1 - %d)\n",
X					a->numFrames);
X		PrintMesg(buff);
X		}
X	else {
X		a->frameNum = newFrame;
X		DisplayImage(a,a->frameNum);
X		}
X
X	sprintf(a->dFrameString,"%d",a->frameNum);
X	gr_DialogSetValue(a->dFrame,a->dFrameString);
X
X
X} /* CBSetFrame */
X
Xstatic void CBValuatorRelease(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	newFrame;
Xchar	buff[80];
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X	newFrame = (int) call_data;
X
X	if ((newFrame > a->numFrames) || ( newFrame < 1)) {
X		/* this should never happen */
X		sprintf(buff,"Frame number out of Range (1 - %d)\n",
X					a->numFrames);
X		PrintMesg(buff);
X		}
X	else {
X		a->frameNum = newFrame;
X		DisplayImage(a,a->frameNum);
X		}
X
X	sprintf(a->dFrameString,"%d",a->frameNum);
X	gr_DialogSetValue(a->dFrame,a->dFrameString);
X
X}
X
Xstatic void CBSetSkip(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
Xint	newSkip;
Xchar	buff[80];
X
X	a = (struct ANIMATION *) client_data;
X
X	newSkip = atoi(XtDialogGetValueString(a->dSkip));
X	if ((newSkip > a->numFrames) || ( newSkip < 0)) {
X		sprintf(buff,"Number out of Range (0 - %d)\n",a->numFrames);
X		PrintMesg(buff);
X		}
X	else {
X		a->skip = newSkip;
X		}
X	sprintf(a->dSkipString,"%d",a->skip);
X	gr_DialogSetValue(a->dSkip,a->dSkipString);
X} /* CBSetSkip */
X
Xstatic void CBSetDelay(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar	buff[80];
Xstruct ANIMATION *a;
Xint	newDelay;
X
X	a = (struct ANIMATION *) client_data;
X
X	newDelay= atoi(XtDialogGetValueString(a->dDelay));
X	if ((newDelay > 1000) || ( newDelay < 0)) 
X		PrintMesg("Delay: That number just won't do...\n"); 
X	else 
X
X		a->delay = newDelay;
X
X	sprintf(a->dDelayString,"%d",a->delay);
X	gr_DialogSetValue(a->dDelay,a->dDelayString);
X
X	if (a->delay == 10)/* I know this is silly.....adds to the esthetics */
X		PrintMesg("Setting delay to 1 second\n");
X	else {
X		sprintf(buff,"Setting delay to %.1f seconds\n",
X			((float)a->delay)/10.0);
X		PrintMesg(buff);
X		}
X}
X
X
Xstatic void CBExpose(w,client_data,call_data)
X/* Animation window exposed, redraw image */
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
X
X#ifdef DEBUG
X	printf("Animate Window: Just received Expose Event\n");
X#endif 
X	a = (struct ANIMATION *) client_data;
X
X	if (a->frameNum == 0){
X		DisplayImage(a,1);
X		a->frameNum = 1;
X		}
X	else
X		DisplayImage(a,a->frameNum);
X
X} /* CBExpose() */
X
Xstatic void CBExpose2(client_data,id)
Xcaddr_t client_data;
XXtIntervalId *id;
X{
X	CBExpose(((struct ANIMATION *)client_data)->awin,client_data,0);
X}
X
X
Xstatic void CBRepeat(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct ANIMATION *a;
X	a = (struct ANIMATION *) client_data;
X
X	a->repeat = ! a->repeat;
X}
X
X
Xvoid AnimateCtrlBox(a)
Xstruct ANIMATION	*a;
X{
Xint	xpos,ypos;
Xint	width,height;
XWidget	box1,box4;
XWidget	acbox;	/*animation control box */
XWidget	pbox;	/*palette box */
XWidget	box5,box6;
XXGCValues       gcvalues;
Xchar	buff[256];
X
X	PlaceWindow(&xpos,&ypos);
X	width = a->xdim + 10;
X	width = (width < ACBOXWIDTH+10)? ACBOXWIDTH +10 : width;
X	width = (width < PBOXWIDTH+10)? PBOXWIDTH+10: width;
X	height = a->ydim + 40 + ACBOXHEIGHT+ PBOXHEIGHT;
X
X	if (!(a->pixmaps = (Pixmap *) 
X			XICalloc(a->numFrames,sizeof(Pixmap)))) {
X		PrintMesg("Can't Allocate any memory\n");
X		return;
X		}
X
X	if(!(a->raster = (unsigned char *)
X			XIMalloc( sizeof(char) * a->xdim * a->ydim ))){
X		PrintMesg("Can't allocate memory for animation\n");
X		/**** should clean up stuff here (like trash a)*/
X		return;	
X		}
X
X	{
X	int planes;
X	int	nbp; /* number of bits per pixel */
X
X
X        planes = DisplayPlanes(myDpy,DefaultScreen(myDpy));
X	
X	if (planes > 8){
X       	    nbp = (planes > 7) ? (planes / 8 + ((planes%8)?1:0)) :1;
X
X	   if(!(a->expRaster=(unsigned char *) XIMalloc(a->xdim*a->ydim*nbp))){
X		PrintMesg("Couldn't allocate enough memory\n");
X		return;
X		}
X	    a->image = XCreateImage(myDpy,myVis,planes,ZPixmap,0,
X					a->expRaster,a->xdim,a->ydim,
X					8*nbp,a->xdim*nbp);
X	    a->isExpanded = TRUE;
X	    }
X	else {
X	    a->image = XCreateImage(myDpy, myVis, 8, ZPixmap, 0, 
X				a->raster, a->xdim, a->ydim, 8, a->xdim);
X	    a->isExpanded = FALSE;
X	    }
X	}
X
X	a->topLevel = MakeATopLevel("X Image [Animate]",toplevelform,
X				xpos,ypos,width,height);
X	a->lockcmap = FALSE;
X	if (myVis->class == PseudoColor) {
X		a->cmap = XCreateColormap(myDpy,XtWindow(a->topLevel),
X			myVis,AllocAll);
X			}
X	else {
X		a->cmap = XCreateColormap(myDpy,XtWindow(a->topLevel),
X			myVis,AllocNone);
X			}
X        SetColormap(a->topLevel,a->cmap);
X
X	Set_Pointer(a->topLevel,XC_gumby);
X
X	a->composite = Make_Board(a->name,a->topLevel,0,0,
X				width,height);
X	
X	box1 = Make_ButtonBox(a->composite,5,5,width-50,25);
X        (void) Make_Label(a->name,box1,2,2,width-55);
X
X	(void) MakeButton("Done",a->composite,width-40,5,
X				CBDoneAnimateCtrlBox,a,0,0);
X
X	a->awin = Make_Board("Animate widget",a->composite,
X				(width - a->xdim)/2,35,
X				a->xdim,a->ydim);
X
X
X	a->awinGC = XtGetGC(a->awin,NULL,&gcvalues);
X
X	pbox = Make_ButtonBox(a->composite,(width-PBOXWIDTH)/2,
X				height - ACBOXHEIGHT- PBOXHEIGHT,
X                                PBOXWIDTH,PAL_WIDTH +5);
X
X
X        a->pal_win = MakeRasterImage("palette",pbox,
X                                2,2,
X                                palXImage,NULL,NULL);
X
X	(void) Make_Toggle("Lock Palette",pbox,265,10,
X			CBLockPalette,a,CBLockPalette,a,True,False);
X
X
X	a->frameNum = 1;
X
X	acbox = Make_ButtonBox(a->composite,
X				(width-ACBOXWIDTH)/2,
X				height-ACBOXHEIGHT,
X                                ACBOXWIDTH,ACBOXHEIGHT-10);
X
X	a->repeat = FALSE;
X	Make_Toggle("Repeat",acbox,5,70,CBRepeat,a,CBRepeat,a,False,False);
X#ifdef UNDER_DEVELOPMENT
X	Make_Toggle("Reverse",acbox,70,70,NULL,NULL,NULL,NULL,False,False);
X#endif
X
X	box4 = Make_ButtonBox(acbox,2,2,155,60);
X
X	a->bcrev = MakeButton("<<",box4,5,5,CBContinuousReverse,a,0,0);
X	a->bsrev = MakeButton("< ",box4,30,5,CBSingleReverse,a,0,0);
X	a->bstop = MakeButton("<STOP>",box4,55,5,CBStop,a,0,0);
X	a->bsfor = MakeButton(" >",box4,105,5,CBSingleForward,a,0,0);
X	a->bcfor = MakeButton(">>",box4,130,5,CBContinuousForward,a,0,0);
X
X	if (a->inMemory)
X		a->slidebar =MakeValuator("valuator",box4,5,30,145,25,FALSE,1,
X				a->numFrames+1,a->frameNum,1,
X				CBValuatorRelease,a,
X				CBValuatorRelease,a,
X				CBValuatorRelease,a);
X	else
X		a->slidebar =MakeValuator("valuator",box4,5,30,145,25,FALSE,1,
X				a->numFrames+1,a->frameNum,1,
X				NULL,NULL,
X				CBValuatorRelease,a,
X				CBValuatorRelease,a);
X
X        Set_Pointer(a->slidebar,XC_sb_h_double_arrow);
X
X	sprintf(a->dFrameString,"1");
X	box5 = Make_ButtonBox(acbox,160,2,62,ACBOXHEIGHT-15);
X	a->dFrame = Make_Dialog("name",box5,"Frame:",
X			a->dFrameString,DSTRINGSIZE,2,2,56,56);
X	MakeButton("  Set   ",box5,2,65,CBSetFrame,a,0,0);
X	a->frameNum = 1;
X	a->delay = 0;
X
X	sprintf(a->dSkipString,"%d",a->skip);
X	box6 = Make_ButtonBox(acbox,227,2,62,ACBOXHEIGHT-15);
X	a->dSkip = Make_Dialog("name",box6,"Skip:",a->dSkipString,
X				DSTRINGSIZE,2,2,56,56);
X	MakeButton("  Set   ",box6,2,65,CBSetSkip,a,0,0);
X
X	sprintf(a->dDelayString,"%d",a->delay);
X	box6 = Make_ButtonBox(acbox,293,2,62,ACBOXHEIGHT-15);
X	a->dDelay= Make_Dialog("name",box6,"Delay:",a->dDelayString,
X				DSTRINGSIZE,2,2,56,56);
X	MakeButton("  Set   ",box6,2,65,CBSetDelay,a,0,0);
X
X
X        XtAddEventHandler(a->awin,ExposureMask,0,CBExpose,a);
X	/* Make sure it displays in case no initial Expose event happens */
X	XtAddTimeOut(500,CBExpose2,a);
X
X	XSync(myDpy,False);	 /* a->awin must be created before cont. */
X	XFlush(myDpy);
X	XSync(myDpy,False);	 
X
X
X        Set_Pointer(a->awin,XC_left_ptr);
X
X	if (a->hasPalette) {
X		StoreColors(a->palette,FALSE,a->cmap);
X                }
X        else
X                StoreColors(origccells,FALSE,a->cmap);
X
X
X    sprintf(buff,"Dimensions of animation sequence: %dx%d\n",a->xdim,a->ydim);
X	PrintMesg(buff);
X
X	a->ctrl_showing = TRUE;
X
X	if (a->inMemory) {
X		if (a->numFiles == 0) 
X		    PrepMemAnimation(a);
X		else
X		    if (! ReadThemAll(a)) {
X			CBDoneAnimateCtrlBox(a->awin,(caddr_t)a,(caddr_t)NULL);
X			return;
X			}
X		}
X
X} /* AnimateCtrlBox() */
X
END-of-animate.c
echo file: chattrib.c
sed 's/^X//' >chattrib.c << 'END-of-chattrib.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled
X * to make a contribution for the use of this software, please send
X * comments as to what you like or don't like about the software,
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "i.h"
X
X#define	STRING_SIZE	80
X
X#define NAME_YLOC	50
X#define MIN_YLOC	100
X#define MAX_YLOC	130
X#define MINMAX_YLOC	160
X#define EXPAND_YLOC	200
X#define EXPAND_FORMAT	"%d"
X
Xextern	Display *myDpy;
Xextern	Widget	toplevelform;
Xextern  void	SetMinMax();
Xextern	void	CBDoCart();
Xextern	void	CBCloseCartImageBox();
X
X
Xvoid CBCloseAttrib(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct  IMAGE   *i;
X
X	i = (struct IMAGE *) client_data;
X	
X	XIFree(i->chaws.pdata);
X	XIFree(i->chaws.pdata2);
X	XIFree(i->chaws.pdata3);
X
X	XtDestroyWidget(i->chaws.toplevel);
X	i->chaws.amIShowing = FALSE;
X
X}
X
X
Xvoid CBApplyAttrib(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XArg	arglist[10];
Xchar buff[256];
Xchar buff2[256];
Xstruct  IMAGE   *i;
Xchar	*tmp;
Xfloat	f;
Xint	x;
Xchar	showing;
X
X        i = (struct IMAGE *) client_data;
X	if (strcmp(i->chaws.pdata,i->name)) {
X		tmp = i->name;
X		/* Change name */
X		if (!(i->name = XIMalloc(strlen(i->chaws.pdata)+1))){
X			i->name = tmp;
X			PrintMesg("Out of Memory\n");
X			XtDestroyWidget(i->chaws.toplevel);
X			return;
X			}
X		
X		strcpy(i->name,i->chaws.pdata);
X
X		if (i->cws.amIShowing) 
X			SetLabelString(i->cws.title,i->name);
X		if (i->iws.amIShowing)
X			SetLabelString(i->iws.title,i->name);
X		if (i->pws.amIShowing)
X			SetLabelString(i->pws.title,i->name);
X		if (i->dws.amIShowing)
X			SetLabelString(i->dws.title,i->name);
X		if (i->gws.amIShowing)
X			SetLabelString(i->gws.title,i->name);
X		if (i->gcws.amIShowing)
X			SetLabelString(i->gcws.title,i->name);
X		if (i->gpws.amIShowing)
X			SetLabelString(i->gpws.title,i->name);
X		if (i->gsws.amIShowing)
X			SetLabelString(i->gsws.title,i->name);
X		if (i->ghws.amIShowing)
X			SetLabelString(i->ghws.title,i->name);
X		if (i->chaws.amIShowing)
X			SetLabelString(i->chaws.title,i->name);
X		
X		sprintf(buff,"changing \"%s\" --> \"%s\"\n",tmp,i->name);
X		PrintMesg(buff);
X
X		XIFree(tmp);
X		}
X
X#ifdef DEBUG
X	printf("Before apply\n");
X	printf("maxvalue = %f, minvalue = %f\n",i->maxvalue,i->minvalue);
X	printf("pdata2= %s, pdata3= %s\n",i->chaws.pdata2,i->chaws.pdata3);
X#endif
X
X
X
X	/* Check Max value change */
X	if (i->isFloat) 
X		sprintf(buff,i->format,i->maxvalue);
X	else 
X		sprintf(buff,i->format, (int) i->maxvalue);
X	if (strcmp(buff,i->chaws.pdata2)) {
X		if (!sscanf(i->chaws.pdata2,"%f",&f)) {
X			sprintf(buff,"Bad Max Value: %s\n",i->chaws.pdata2);
X			PrintMesg(buff);
X			ClearString(i->chaws.pdata2,strlen(i->chaws.pdata2),0);
X			if (i->isFloat) 
X				sprintf(i->chaws.pdata2,i->format,i->maxvalue);
X			else 
X				sprintf(i->chaws.pdata2,i->format,
X					(int) i->maxvalue);
X			RedisplayTextEdit(i->chaws.box2,
X					i->chaws.pdata2,STRING_SIZE);
X			return;
X			}
X		else {
X			i->maxvalue = f;
X			sprintf(buff,"%s's Max Value = %s\n",
X						i->name,i->format);
X			ClearString(i->chaws.pdata2,strlen(i->chaws.pdata2),0);
X			if (i->isFloat) {
X				sprintf(buff2,buff,i->maxvalue);
X				sprintf(i->chaws.pdata2,i->format,i->maxvalue);
X				}
X			else {
X				sprintf(buff2,buff,(int) i->maxvalue);
X				sprintf(i->chaws.pdata2,i->format,
X						(int) i->maxvalue);
X				}
X			PrintMesg(buff2);
X			RedisplayTextEdit(i->chaws.box2,
X					i->chaws.pdata2,STRING_SIZE);
X			}
X		}
X
X	/* Check Min value change */
X	if (i->isFloat) 
X		sprintf(buff,i->format,i->minvalue);
X	else 
X		sprintf(buff,i->format, (int) i->minvalue);
X	if (strcmp(buff,i->chaws.pdata3)) {
X		if (!sscanf(i->chaws.pdata3,"%f",&f)) {
X			sprintf(buff,"Bad Min Value: %s\n",i->chaws.pdata3);
X			PrintMesg(buff);
X			ClearString(i->chaws.pdata3,strlen(i->chaws.pdata3),0);
X			if (i->isFloat) 
X				sprintf(i->chaws.pdata3,i->format,i->minvalue);
X			else
X				sprintf(i->chaws.pdata3,i->format,
X						(int) i->minvalue);
X			RedisplayTextEdit(i->chaws.box3,
X					i->chaws.pdata3,STRING_SIZE);
X			RedisplayTextEdit(i->chaws.box2,
X					i->chaws.pdata2,STRING_SIZE);
X			return;
X			}
X		else {
X			i->minvalue = f;
X			sprintf(buff,"%s's Min Value = %s\n",
X						i->name,i->format);
X			ClearString(i->chaws.pdata3,strlen(i->chaws.pdata3),0);
X			if (i->isFloat){
X				sprintf(buff2,buff,i->minvalue);
X				sprintf(i->chaws.pdata3,i->format,i->minvalue);
X				}
X			else {
X				sprintf(buff2,buff,(int) i->minvalue);
X				sprintf(i->chaws.pdata3,i->format,
X						(int) i->minvalue);
X				}
X			PrintMesg(buff2);
X			RedisplayTextEdit(i->chaws.box3,
X					i->chaws.pdata3,STRING_SIZE);
X			}
X		}
X
X	sprintf(buff,EXPAND_FORMAT,(int) i->expansionFactor);
X	if (strcmp(buff,i->chaws.pdata4)) {
X		if (!sscanf(i->chaws.pdata4,"%d",&x)) {
X			sprintf(buff,"Bad Expansion Value %s\n",
X				i->chaws.pdata4);
X			PrintMesg(buff);
X			ClearString(i->chaws.pdata4,strlen(i->chaws.pdata4),0);
X			sprintf(i->chaws.pdata4,EXPAND_FORMAT,
X					(int) i->expansionFactor);
X			RedisplayTextEdit(i->chaws.box4,
X					i->chaws.pdata4,STRING_SIZE);
X			}
X		else {
X			if (((x * i->xdim) > DisplayWidth(myDpy,
X						XDefaultScreen(myDpy))) ||
X			   (((x * i->ydim) > DisplayHeight(myDpy,
X						XDefaultScreen(myDpy))))) {
X				
X
X				PrintMesg("Expansion Factor = ... What? I don't think so... \n");
X				PrintMesg("Image would be bigger than display\n");
X				ClearString(i->chaws.pdata4,
X					strlen(i->chaws.pdata4),0);
X				sprintf(i->chaws.pdata4,EXPAND_FORMAT,
X						(int) i->expansionFactor);
X				RedisplayTextEdit(i->chaws.box4,
X						i->chaws.pdata4,STRING_SIZE);
X				}
X			else {
X				if (i->iws.amIShowing) {
X					showing = TRUE;
X					CBCloseCartImageBox(i->iws.box3,
X						(caddr_t) i,
X						(caddr_t) 0);
X					}
X				else
X					showing = FALSE;
X				i->expansionFactor = (float) x;
X				if (i->expansionFactor < 1.0)
X					i->expansionFactor = 1.0;
X				if (i->expansionFactor > 1.0)
X					i->expand = TRUE;
X				else
X					i->expand = FALSE;
X	
X				ClearString(i->chaws.pdata4,
X					strlen(i->chaws.pdata4),0);
X				sprintf(i->chaws.pdata4,EXPAND_FORMAT,
X						(int) i->expansionFactor);
X				RedisplayTextEdit(i->chaws.box4,
X						i->chaws.pdata4,STRING_SIZE);
X				sprintf(buff,"Expansion Factor = %d\n",
X						(int) i->expansionFactor);
X				PrintMesg(buff);
X				if (showing)
X					CBDoCart(NULL,i,NULL);
X				}
X	
X			}
X		} /* if expansionFactor Changed */
X		
X#ifdef DEBUG
X	printf("After apply\n");
X	printf("maxvalue = %f, minvalue = %f\n",i->maxvalue,i->minvalue);
X	printf("maxvalue = %d, minvalue = %d\n",i->maxvalue,i->minvalue);
X	printf("pdata2= %s, pdata3= %s\n",i->chaws.pdata2,i->chaws.pdata3);
X#endif
X
X
X}
X
Xvoid CBCalcMaxMin(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X	ClearString(i->chaws.pdata2,strlen(i->chaws.pdata2),0);
X	ClearString(i->chaws.pdata3,strlen(i->chaws.pdata3),0);
X
X	if (i->isFloat) {
X		SetMinMax(i->fdataset,i->xdim,i->ydim,
X					&i->minvalue,&i->maxvalue);
X		sprintf(i->chaws.pdata2,i->format,i->maxvalue);
X		sprintf(i->chaws.pdata3,i->format,i->minvalue);
X		}
X	else {
X		i->maxvalue = 255.0;
X		i->minvalue = 0.0;
X		sprintf(i->chaws.pdata2,i->format,(int) i->maxvalue);
X		sprintf(i->chaws.pdata3,i->format,(int) i->minvalue);
X		}
X
X	RedisplayTextEdit(i->chaws.box2,
X			i->chaws.pdata2,STRING_SIZE);
X	RedisplayTextEdit(i->chaws.box3,
X			i->chaws.pdata3,STRING_SIZE);
X
X#ifdef DEBUG
X	printf("After CalcMaxMin\n");
X	printf("maxvalue = %f, minvalue = %f\n",i->maxvalue,i->minvalue);
X	printf("pdata2= %s, pdata3= %s\n",i->chaws.pdata2,i->chaws.pdata3);
X#endif
X
X	
X} /* CBCalcMaxMin() */
X
Xvoid CBInterpolate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X	i->interpExpansion = ! i->interpExpansion;
X
X	SetToggle(i->chaws.box5,! i->interpExpansion); /* pixel replicate */
X	SetToggle(i->chaws.box6,  i->interpExpansion); /* interpolate */
X}
X
X
Xvoid CBChangeAttrib(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	xpos,ypos;
Xstruct  IMAGE   *i;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->chaws.amIShowing) {
X		PrintMesg("Change Attribute window already open\n");
X		XRaiseWindow(myDpy,XtWindow(i->chaws.toplevel));
X		return;
X		}
X
X        PlaceWindow(&xpos,&ypos);
X	i->chaws.toplevel = MakeATopLevel("X Image [Image.Change Attributes]",
X				toplevelform,xpos,ypos,400,300);
X        i->chaws.composite = Make_Board(i->name,i->chaws.toplevel,0,0,400,122);
X
X        i->chaws.box1 = Make_ButtonBox(i->chaws.composite,5,5,350,25);
X        i->chaws.label = Make_Label(i->label,i->chaws.box1,2,2,30);
X        i->chaws.title = Make_Label(i->name,i->chaws.box1,33,2,315);
X	(void) MakeButton("Done",i->chaws.composite,360,5,CBCloseAttrib,i,0,0);
X
X	if (!(i->chaws.pdata = XIMalloc(STRING_SIZE))){
X		PrintMesg("Out of Memory\n");
X		XtDestroyWidget(i->chaws.toplevel);
X		return;
X		}
X
X	if (!(i->chaws.pdata2 = XIMalloc(STRING_SIZE))){
X		PrintMesg("Out of Memory\n");
X		XtDestroyWidget(i->chaws.toplevel);
X		return;
X		}
X	if (!(i->chaws.pdata3 = XIMalloc(STRING_SIZE))){
X		PrintMesg("Out of Memory\n");
X		XtDestroyWidget(i->chaws.toplevel);
X		return;
X		}
X
X	if (!(i->chaws.pdata4 = XIMalloc(STRING_SIZE))){
X		PrintMesg("Out of Memory\n");
X		XtDestroyWidget(i->chaws.toplevel);
X		return;
X		}
X
X
X	strcpy(i->chaws.pdata,i->name);
X	(void) Make_Text_Inp("textInp",i->chaws.composite,i->chaws.pdata,
X				STRING_SIZE,200,NAME_YLOC,190,20,
X				CBApplyAttrib,i);
X	(void) Make_Label("Variable Name:",i->chaws.composite,5,NAME_YLOC,190);
X
X	if (i->isFloat) {
X		sprintf(i->chaws.pdata2,i->format,i->maxvalue);
X		sprintf(i->chaws.pdata3,i->format,i->minvalue);
X		}
X	else {
X		sprintf(i->chaws.pdata2,i->format,(int) i->maxvalue);
X		sprintf(i->chaws.pdata3,i->format,(int) i->minvalue);
X		}
X
X	i->chaws.box2 = Make_Text_Inp("textInp",i->chaws.composite,
X				i->chaws.pdata2,
X				STRING_SIZE,200,MAX_YLOC,190,20,
X				CBApplyAttrib,i);
X	(void) Make_Label("Maximum Value of Interest:",
X			i->chaws.composite,5,MAX_YLOC,190);
X	i->chaws.box3 = Make_Text_Inp("textInp",i->chaws.composite,
X				i->chaws.pdata3,
X				STRING_SIZE,200,MIN_YLOC,190,20,
X				CBApplyAttrib,i);
X	(void) Make_Label("Minimum Value of Interest:",
X			i->chaws.composite,5,MIN_YLOC,190);
X	MakeButton("Calculate Max & Min",i->chaws.composite,200,MINMAX_YLOC,
X					CBCalcMaxMin,i,190,20);
X
X	sprintf(i->chaws.pdata4,EXPAND_FORMAT,(int) i->expansionFactor);
X	(void) Make_Label("Exapansion Factor:",
X			i->chaws.composite,5,EXPAND_YLOC,190);
X
X	i->chaws.box4 = Make_Text_Inp("textInp",i->chaws.composite,
X				i->chaws.pdata4,
X				STRING_SIZE,200,EXPAND_YLOC,190,20,
X				CBApplyAttrib,i);
X	i->chaws.box5 = Make_Toggle("replicate",i->chaws.composite,
X				200,EXPAND_YLOC+30,
X				CBInterpolate,i, CBInterpolate,i,
X				False, ! i->interpExpansion);
X	i->chaws.box6 = Make_Toggle("interpolate",i->chaws.composite,
X				300,EXPAND_YLOC+30,
X				CBInterpolate,i,CBInterpolate,i,
X				False,i->interpExpansion);
X
X
X
X	(void) MakeButton("Apply",i->chaws.composite,5,270,
X				CBApplyAttrib,i,390,25);
X
X	i->chaws.amIShowing = TRUE;
X}
END-of-chattrib.c
echo file: cbtable.c
sed 's/^X//' >cbtable.c << 'END-of-cbtable.c'
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X
X#define MALLOC	XIMalloc
X#define FREE	XIFree
X
Xstruct CBP{
X	Widget w;
X	XtCallbackProc cbp;
X	caddr_t	cbdata;
X	struct CBP *prev;
X	struct CBP *next;
X	};
X
X#define NIL (struct CBP *) 0
X
Xstatic struct CBP *headCBP = NIL;
Xstatic struct CBP *tailCBP = NIL;
X
Xvoid	RemoveFromCBTable();
X
X
Xstatic void CBCBPDestroyWidget(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	RemoveFromCBTable(w);
X}
X
Xvoid InsertInCBTable(w,cbp,cbdata)
XWidget w;
XXtCallbackProc cbp;
Xcaddr_t	cbdata;
X{
Xstruct CBP *c;
X	
X	if (!(c = (struct CBP *) MALLOC(sizeof(struct CBP)))) {
X		printf("Out of Memory\n");
X		return;
X		}
X	c->w = w;
X	c->cbp = cbp;
X	c->cbdata = cbdata;
X
X	c->next = NIL;
X	c->prev = NIL;
X
X	if (headCBP == NIL)
X		tailCBP = headCBP = c;
X	else {
X		tailCBP->next = c;
X		c->prev = tailCBP;
X		tailCBP = c;
X		}
X
X	XtAddCallback(w,"destroyCallback",CBCBPDestroyWidget,0);
X
X
X} /* InsertInCBTable() */
X
X
X	
Xstatic struct CBP *SearchByWidgetCBP(w)
XWidget w;
X{
Xstruct CBP *c;
X
X        c = headCBP;
X
X        while (c != NIL) {
X		if (w == c->w)
X                        return(c);
X                else
X                        c = c->next;
X                }
X        return(NIL);
X
X} /* SearchByWidgetCBP() */
X
X
Xvoid RemoveFromCBTable(w)
XWidget w;
X{
Xstruct CBP *c;
X
X	if (!(c = SearchByWidgetCBP(w))) {
X		return; /* widget not found */
X		}
X
X       if (c->prev)
X                c->prev->next = c->next;
X        else
X                headCBP = c->next;
X        if(c->next)
X                c->next->prev = c->prev;
X        else
X                tailCBP = c->prev;
X
X	FREE(c);
X
X}
X
Xvoid CallCallBack(w)
XWidget w;
X{
Xstruct CBP *c;
X
X	if (!(c = SearchByWidgetCBP(w))) 
X		return; /* widget not found */
X
X	(c->cbp)(c->w,c->cbdata,0);
X}
END-of-cbtable.c
echo file: control.c
sed 's/^X//' >control.c << 'END-of-control.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X/*#include <X11/AsciiText.h>*/
X#include <X11/cursorfont.h>
X
X#ifdef XtSpecificationRelease
X#include <X11/Xaw/Text.h>
X#else
X#include <X11/Text.h>
X#endif
X
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "buttons.h"
X
X#define MAIN_CTRL_DIM_X
X#define MAIN_CTRL_DIM_Y
X#define MSGBUFFSIZE	4096
X
Xextern void Quit();
Xextern void ImageBox();
Xextern void CBNewImage();
Xextern void PaletteBox();
Xextern void CBDrawSDSBox();
Xextern void CBNewAnimate();
X
Xextern char *GetVersionDate();
Xextern char *GetVersion();
Xextern Display *myDpy;
X
Xstatic	Widget	msg_window;
Xstatic	char msgbuff[MSGBUFFSIZE];
Xstatic	char msgWidgetCreated = FALSE;
Xstatic	char msgWindowCreated = FALSE;
X
X
X
XInit_Ctrl_Window(parent)
XWidget parent;
X{
XWidget	buttonbox;
Xint	x;
XWidget  ctrl_window;
X
X
X	ctrl_window = Make_Window(GetVersion(),parent,0,0,402,200); 
X
X	
X	for(x=0; x< MSGBUFFSIZE; x++)
X		msgbuff[x]=' ';
X	for(x=0; x < MSGBUFFSIZE; x+=10)
X		msgbuff[x]='\n';
X
X	msgbuff[MSGBUFFSIZE-1]='\0';
X
X/*	msg_window = Make_Text(ctrl_window,1,22,400,80,
X				msgbuff);
X*/
X
X	msg_window = (Widget) MakeText("LogWindow",ctrl_window,VERTONLY,
X                                        SELECTABLE,STRINGSOURCE,
X                                        msgbuff,MSGBUFFSIZE,
X                                        1, 22, 400, 80);
X
X
X	msgWidgetCreated = TRUE;
X	PrintMesg("This software is a product of the National Center for \n");
X      PrintMesg("Supercomputing Applications at the University of Illinois\n");
X	PrintMesg("Please send bug reports to davet@ncsa.uiuc.edu\n");
X	PrintMesg(GetVersionDate());
X
X        Set_Pointer(msg_window,XC_gumby);
X	buttonbox = Make_ButtonBox(ctrl_window,1,105,402,42);
X	b[CTRL_IMAGE]	= MakeButton("Dataset",buttonbox,1,1,
X				CBNewImage,NULL,0,0);
X	b[CTRL_PALETTE]	= MakeButton("Palette",buttonbox,58,1,
X				PaletteBox,NULL,0,0);
X	b[CTRL_ANIMATE] = MakeButton("Animate",buttonbox,114,1,
X				CBNewAnimate,NULL,0,0);
X
X/*
X	(void) MakeButton("Test",buttonbox,250,1,CBDrawSDSBox,NULL,0,0);
X*/
X
X	b[CTRL_QUIT]	= MakeButton("Quit",buttonbox,365,1,Quit,NULL,0,0);
X}
X
XPrintMesg(s)
Xchar *s;
X{
Xstatic long ptr = 0;	/* # of chars currently used in Message buffer */
X
X#ifndef XtSpecificationRelease
X/* previous to R4 */
XXtTextBlock text;
X#else
XXawTextBlock text;
X#endif
X
Xint slength = strlen(s);
X
X	if (!msgWidgetCreated){
X		printf("%s",s);
X		return;
X		}
X
X	/* Will this message fit in the message buff */
X	if((slength + ptr) > MSGBUFFSIZE) {
X		/* reset message buffer */
X		int x;
X		ptr = 0;
X		for(x=0; x< MSGBUFFSIZE; x++)
X			msgbuff[x]=' ';
X		for(x=0; x < MSGBUFFSIZE; x+=10)
X			msgbuff[x]='\n';
X		msgbuff[MSGBUFFSIZE-1]='\0';
X		}
X
X	strncpy((msgbuff+ptr),s,slength); /* copy mesg except for null */
X
X	text.ptr = s;
X	text.firstPos = 0;
X	text.length = slength;
X	text.format = FMT8BIT;
X	(void) XtTextReplace(msg_window,ptr,strlen(s)+ptr,&text);
X
X	XtTextDisplay(msg_window);
X	XtTextSetInsertionPoint(msg_window,ptr+slength);
X	ptr = ptr + slength;
X
X}
X
X
END-of-control.c
echo file: contour.c
sed 's/^X//' >contour.c << 'END-of-contour.c'
X
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Dave Thompson, National Center for Supercomputing Applications
X * davet@ncsa.uiuc.edu
X */
X
X/* Author: Dave Whittington */
X/*  All new contour plot -- for faster execution speeds and extra  */
X/*  compactness.  Now available in convenient "FamileePaks".	   */
X
X#include	<X11/Xlib.h>
X#include	<X11/Intrinsic.h>
X#include "ximage.h"
X
X
X#define	data(x,y)	(unsigned char) ri[y*xmax + x]
X
Xvoid Updt_Contour(w,ri,cl,xmax,ymax,px,py,xdim,ydim,fore,back)
XWidget	w;			/* widget to draw contour in */
Xunsigned char	*ri;		/* data set */
Xunsigned char	cl[];		/* contour levels; cl[0] contains # of levels*/
Xint	xmax,ymax;		/* dimensions of data set */
Xint	px,py;			/* starting point to do contour */
Xint	xdim,ydim; 		/* dimensions of rectangle to do contour on*/
Xunsigned long	fore,back;	/* colors to plot in */
X{
Xint	x,y,count;
Xunsigned char	d0,d1,d2;
XDisplay	*disp;
XDrawable d;
XGC	the_gc;
XXGCValues values;
XBoolean	plotMe;
X
X/*	set up XWindows specific stuff...	*/
X
X	disp = XtDisplay(w);
X	d = XtWindow(w);
X	values.foreground = fore;
X	values.background = back;
X	the_gc = XtGetGC(w,(GCForeground | GCBackground),&values);
X
X	XSetForeground(disp,the_gc,fore);
X	XSetBackground(disp,the_gc,back);
X/*	Now, check the bounds and start plotting	*/
X
X	if (xdim > xmax) xdim = xmax;
X	if (ydim > ymax) ydim = ymax;
X	for (y = py; y < ydim; y++)
X	{
X		x = px;
X		d1 = data(x,y);
X		d2 = data(x,(y+1));
X		while (x < xdim)
X		{
X			d0 = d1;
X			d1 = data(x+1,y);
X			d2 = data(x,(y+1));
X			plotMe = (d0 >= cl[1]) && (d0 <= cl[cl[0]]);
X			plotMe = plotMe || (d1 >= cl[1]) && (d1 <= cl[cl[0]]);
X			plotMe = plotMe || (d2 >= cl[1]) && (d2 >= cl[cl[0]]);
X			count = 1;
X			while ((count <= cl[0]) && plotMe)
X			{
X				if (((d0 >= cl[count]) && (d1 < cl[count])) ||
X				   ((d0 < cl[count]) && (d1 >= cl[count])) ||
X				   ((d0 >= cl[count]) && (d2 < cl[count])) ||
X				   ((d1 < cl[count]) && (d2 >= cl[count])))
X				{
X					XDrawPoint(disp,d,the_gc,x,y);
X					count = cl[0];
X				}
X				count++;
X				plotMe = (d0 <= cl[cl[0]]);
X				plotMe = (d1 <= cl[cl[0]]) || plotMe;
X				plotMe = (d2 <= cl[cl[0]]) || plotMe;
X			}
X			x++;
X		}
X	}
X}
END-of-contour.c
echo file: contourlevel.c
sed 's/^X//' >contourlevel.c << 'END-of-contourlevel.c'
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	ContourLine		draw a contour line
X	
X			indata =	pointer to input data
X			godata = 	pointer to output data
X			value =		the value of the contour level (0-255)
X			color =		the color of the contour level (0-255)
X			x =			number of x-points in the array
X			y =			number of y-points in the array
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	ContourLine(indata,godata,value,color,x,y)
Xunsigned char			*indata,*godata;
Xregister unsigned char	value,color;
Xregister long			x;
Xlong					y;
X{
X	register unsigned char	*p,*u;
X	unsigned char			*q;
X	int						rows_done = 0;
X
X	p = indata;
X	q = p + (long)(x * y - 1);
X	u = indata + (long)(x - 1);
X
X	while (!rows_done)
X	{
X		while (p < u)
X		{
X			if	  (*p < value)
X			{
X				while (*p < value && p < u) p++;
X				if (*p >= value)
X					*(godata + (long)(p - indata)) = color;
X			}
X			else if (*p == value)
X			{
X				while (*p == value && p < u) p++;
X				if (*p < value || *p > value)
X					*(godata + (long)(p - indata)) = color;
X			}
X			else
X			{
X				while (*p > value && p < u) p++;
X				if (*p <= value)
X					*(godata + (long)(p - indata)) = color;
X			}
X		}
X		if (u == q)	rows_done = 1;
X		else
X		{
X			u += x;
X			p++;
X		}
X	}
X
X	p = indata;
X	q = p + (long)(x * y - 1);
X	u = q - (long)(x - 1);
X
X	while (u <= q)
X	{
X		while (p < u)
X		{
X			if	  (*p < value)
X			{
X				while (*p < value && p < u) p += x;
X				if (*p >= value)
X					*(godata + (long)(p - indata)) = color;
X			}
X			else if (*p == value)
X			{
X				while (*p == value && p < u) p += x;
X				if (*p < value || *p > value)
X					*(godata + (long)(p - indata)) = color;
X			}
X			else
X			{
X				while (*p > value && p < u) p += x;
X				if (*p <= value)
X					*(godata + (long)(p - indata)) = color;
X			}
X		}
X		if (u == q)	return;
X		u++;
X		p = indata + (long)(x - 1) - (long)(q - u);
X	}
X}
X
X
END-of-contourlevel.c
echo file: ctlcontour.c
sed 's/^X//' >ctlcontour.c << 'END-of-ctlcontour.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X/*#include <X11/StringDefs.h>*/
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#ifdef XtSpecificationRelease
X/* R4 */
X#include <X11/Xaw/Dialog.h>
X#else
X#include <X11/Dialog.h>
X#endif
X
X#include "ximage.h"
X#include "i.h"
X#include "xstuff.h"
X
X#define	CTRLBOX_XDIM	350		/* dimensions of contour input box*/
X#define	CTRLBOX_YDIM	110
X
X#define EVENLY_SPACED	0
X#define	USER_DEF	1
X
X#define MAX_CONTOUR_LEVELS	256	/* maximum number of contour levels */
X#define	DEFAULT_NUM_LEVELS	5	/* Default number of contour levels*/
X
Xextern	Display	*myDpy;
Xextern  Widget  toplevelform;
Xextern	void	CBContour();	/* <----should be moved into this module*/
Xextern	XFontStruct	*ximageFont;
X
Xstatic	char	AmIOpen = FALSE;	/* is the ctrlContourBox created?*/
Xstatic	Widget	ctrlContourBox;
Xstatic	Widget	ctrlCBboard;
Xstatic	Widget	InputBox;
Xstatic	char	contourMode = EVENLY_SPACED;
Xstatic	float	contourMin,contourMax,contourIsFloat;
Xstatic	unsigned char	*contourLevels;
Xstatic	struct	IMAGE	*imageToContour;		/* Image working on */
X
Xstatic  Widget  mes_Dialog_NL;
Xstatic	char	mes_numLevels[10];
Xstatic	Widget	mes_Dialog_Min;
Xstatic	char	mes_minLevel[10];
Xstatic	Widget	mes_Dialog_Max;
Xstatic	char	mes_maxLevel[10];
X
Xstatic	Widget	mud_Dialog_L;
Xstatic	char	mud_Levels[1024];
Xstatic	Widget	esToggle;
Xstatic	Widget	udToggle;
X       
X
Xstatic void MakeEvenlySpaced(w)
XWidget w;
X{
Xchar	buff[80];
X
X
X	mes_Dialog_NL = Make_Dialog("NumLevels",w,"Number of Levels",
X			mes_numLevels,sizeof(mes_numLevels)-1,
X			2,2, CTRLBOX_XDIM/3,CTRLBOX_YDIM/2-5);
X
X	if (contourIsFloat)
X		sprintf(buff,"Min Value (%6.3f)",contourMin);
X	else
X		sprintf(buff,"Min Value (%d)",(int) contourMin);
X		
X	mes_Dialog_Min = Make_Dialog("Min",w,buff, 
X			mes_minLevel,sizeof(mes_minLevel)-1,
X			CTRLBOX_XDIM/3+2,2, CTRLBOX_XDIM/3-2,CTRLBOX_YDIM/2-5);
X
X	if (contourIsFloat)
X		sprintf(buff,"Max Value (%6.3f)",contourMax);
X	else
X		sprintf(buff,"Max Value (%d)",(int) contourMax);
X	mes_Dialog_Max = Make_Dialog("Max",w,buff, 
X			mes_maxLevel,sizeof(mes_maxLevel)-1,
X			CTRLBOX_XDIM*2/3+2,2, CTRLBOX_XDIM/3-5,CTRLBOX_YDIM/2-5);
X} /* MakeEvenlySpaced() */
X
Xstatic void RemoveEvenlySpaced()
X{
X	XtDestroyWidget(mes_Dialog_NL);
X	XtDestroyWidget(mes_Dialog_Min);
X	XtDestroyWidget(mes_Dialog_Max);
X}
X
X
Xstatic void MakeUserDef(w)
XWidget w;
X{
X/**/	fprintf(stderr,"MakeUserDef(): I've been called\n ");
X
X
X	mud_Dialog_L = Make_Dialog("NumLevels",w,
X			"Please specify levels (separate with space)",
X		mud_Levels,sizeof(mud_Levels),
X		2,2, CTRLBOX_XDIM-7,CTRLBOX_YDIM/2-5);
X
X
X/**/	fprintf(stderr,"MakeUserDef(): exiting \n");
X	fflush(stderr);
X}
X
Xstatic void RemoveUserDef()
X{
X	XtDestroyWidget(mud_Dialog_L);
X}
X
Xstatic void CBCancel(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	PrintMesg("Cancelled Contour\n");
X	XtDestroyWidget((Widget) client_data);
X	AmIOpen = FALSE;
X
X	return;
X
X} /* CBCancel */
X
X
X
Xint TranslateFtoRI(f,min,max)
Xfloat	f;
Xfloat	min,max;
X/* Translate from floating point scale to int 0-255 scale */
X{
X	if ((max - min))
X		return((int)(((f - min)/(max - min)) * 255.0));
X	else
X		return(0);
X}
X
Xstatic void AdvanceToBlank(s)
Xchar **s;
X{
X	/* skip over any white space (if any) */
X	while( (**s) && ( (**s == ' ') || (**s == '\n')))
X		(*s)++;
X	/* skip over test till next white space */
X	while( (**s) && ( (**s != ' ') && (**s != '\n')))
X		(*s)++;
X	
X}
X
Xstatic void CBOk(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar	buff[80];
X	/* check everything*/
X
X	if (contourMode == EVENLY_SPACED) {
X		float max,min;
X		int num,x;
X		int start,end,inc,count;
X
X		/*** This should be atof instead of atoi ***/
X		/**** but atof doesn't seem to be working */
X		max = (float)atoi(XtDialogGetValueString(mes_Dialog_Max));
X/*		printf("Dialog max says %s\n",
X			XtDialogGetValueString(mes_Dialog_Max));
X		printf("max is %f\n",max);
X*/
X		min = (float)atoi(XtDialogGetValueString(mes_Dialog_Min));
X		num = atoi(XtDialogGetValueString(mes_Dialog_NL));
X		max = (max > contourMax)? contourMax: 
X				(max < contourMin)? contourMax: max;
X		min = (min < contourMin)? contourMin:
X				(min > contourMax)? contourMin: min;
X
X		/* check bounds */ 
X		if ((max == 0.0) && (min == 0.0)) { 
X			max = contourMax; 
X			min = contourMin;
X			}
X		num = ((num <= 0) || (num >MAX_CONTOUR_LEVELS))?
X				DEFAULT_NUM_LEVELS:num;
X
X		if (contourIsFloat) {
X			start = TranslateFtoRI(min,contourMin,contourMax);
X			end = TranslateFtoRI(max,contourMin,contourMax);
X			sprintf(buff,
X			  "Plotting %d contours levels from %6.3f to %6.3f\n",
X			   num,min,max);
X			PrintMesg(buff);
X			}
X		else {
X			start = (int) min;
X			end = (int) max;
X			sprintf(buff,
X				"Plotting %d contours levels from %d to %d\n",
X				num,start,end);
X			PrintMesg(buff);
X			}
X		if (!(end|start)) {
X			contourLevels[0] = 0;
X			contourLevels[1] = 0;
X			}
X		else {
X			
X			inc = (end-start) / num;
X			for(x=start, count=1; x < end ; x+=inc, count++)
X				contourLevels[count] = x;
X			contourLevels[0] = --count;
X			}
X		}
X	else { /* User Defined */
X		char	*contourString;
X		float	floatLevel;
X		int	intLevel;
X		int	count;
X
X#ifndef XtSpecificationRelease
X/* previous to R4 */
X		contourString = XtDialogGetValueString(mud_Dialog_L);
X#else
X		contourString = XawDialogGetValueString(mud_Dialog_L);
X#endif
X
X		if (contourIsFloat) {
X			count = 1;
X			while(sscanf(contourString,"%f",&floatLevel) == 1) {
X				contourLevels[count++] = (unsigned char) 
X						TranslateFtoRI(floatLevel,
X						contourMin,contourMax);
X				AdvanceToBlank(&contourString);
X				}
X			contourLevels[0] = --count;
X			}
X		else {
X			count = 1;
X			while(sscanf(contourString,"%d",&intLevel) == 1) {
X				contourLevels[count++] = (unsigned char)
X						intLevel;
X				AdvanceToBlank(&contourString);
X				}
X			contourLevels[0] = --count;
X			}/*else*/
X		}/*else*/
X
X	XtDestroyWidget((Widget) client_data);
X	AmIOpen = FALSE;
X	PrintMesg("Plotting Contour\n");
X
X/*	{ int x;
X	for (x=1; x <= contourLevels[0]; x++ )
X		printf("doing level %d \n",(int) contourLevels[x]);
X	}
X*/
X	CBContour(w,imageToContour,NULL);
X
X	return;
X} /* CBOk */
X
Xstatic void CBEvenlySpaced(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X
X	if (contourMode == EVENLY_SPACED) { /* if already set */
X		SetToggle(w,True);
X		return;
X		}
X	else {
X		SetToggle(udToggle,False);
X		RemoveUserDef();
X		MakeEvenlySpaced(InputBox);
X		contourMode = EVENLY_SPACED;
X		}
X	return;
X	
X}
Xstatic void CBUserDefined(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	if (contourMode == USER_DEF) { /* if already set */
X		SetToggle(w,True);
X		return;
X		}
X	else {
X		SetToggle(esToggle,False);
X		RemoveEvenlySpaced();
X		MakeUserDef(InputBox);
X		contourMode = USER_DEF;
X		}
X	return;
X	
X} /* CBUserDefined() */
X
Xvoid CBColorContour(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X	i->gcws.data1 = ! i->gcws.data1;
X
X	if (i->gcws.data1){
X		SetToggle(i->gcws.box6,True);
X		SetToggle(i->gcws.box7,False);
X		}
X	else {
X		SetToggle(i->gcws.box6,False);
X		SetToggle(i->gcws.box7,True);
X		}
X
X} /* CBColorContour()*/
X
X
X
X
Xvoid CBCtrlContourBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct  IMAGE *i;		/* data set info stored here */
Xint	xpos,ypos;		/* where to put the box */
XWidget	b2,b3,b4;
X
X        i = (struct IMAGE *) client_data;
X
X	if (AmIOpen) {
X		PrintMesg("Contour Control Box already open\n");
X		XRaiseWindow(myDpy,XtWindow(ctrlContourBox));
X		return;
X		}
X
X	if (i->gcws.amIShowing) {
X		PrintMesg("Contour already displayed\n");
X		XRaiseWindow(myDpy,XtWindow(i->gcws.toplevel));
X		return;
X		}
X
X
X
X	contourMin = i->minvalue;
X	contourMax = i->maxvalue;
X	contourIsFloat = i->isFloat;
X	imageToContour = i;
X	if(!(i->contourLevels = contourLevels = (unsigned char *) 
X		XICalloc(MAX_CONTOUR_LEVELS,sizeof(unsigned char)))){
X		PrintMesg("Can't allocate memory for contour levels\n");
X		return;
X		}
X
X	PrintMesg("Please specify contour levels to plot\n");
X
X	PlaceWindow(&xpos,&ypos);
X	ctrlContourBox = MakeATopLevel("X Image [Image.Graph.Contour]",
X                                toplevelform,xpos,ypos,CTRLBOX_XDIM,
X				CTRLBOX_YDIM+50);
X
X	ctrlCBboard = Make_Board(i->name,ctrlContourBox,0,0,
X                                CTRLBOX_XDIM,CTRLBOX_YDIM+50);
X
X	InputBox = Make_Board(i->name,ctrlCBboard,0,0,
X				CTRLBOX_XDIM,CTRLBOX_YDIM/2);
X
X
X	b2 = Make_Board(i->name,ctrlCBboard,3,CTRLBOX_YDIM/2+2,CTRLBOX_XDIM/2-3,CTRLBOX_YDIM/2-5);
X	esToggle = Make_Toggle("Evenly spaced",b2,5,5,CBEvenlySpaced,NULL,
X				CBEvenlySpaced,NULL,False,False);
X	udToggle = Make_Toggle("User defined levels",b2,5,30,CBUserDefined,NULL,
X				CBUserDefined,NULL,False,False);
X
X	b4 = Make_Board(i->name,ctrlCBboard,3,
X		CTRLBOX_YDIM/2+52,CTRLBOX_XDIM/2-3,50);
X
X	i->gcws.data1 = TRUE; /* Color Contour */
X	i->gcws.box6 = Make_Toggle("Color Contour",b4,5,5,CBColorContour,i,
X				CBColorContour,i,False,i->gcws.data1);
X
X	i->gcws.box7 = Make_Toggle("Black & White Contour",b4,5,30,
X				CBColorContour,i,
X				CBColorContour,i,False,! i->gcws.data1);
X
X	b3 = Make_Board(i->name,ctrlCBboard,CTRLBOX_XDIM/2,CTRLBOX_YDIM/2+2,
X				CTRLBOX_XDIM/2-2,50+CTRLBOX_YDIM/2-5);
X	(void) MakeButton("    Ok    ",b3,10,5,/*25+(CTRLBOX_YDIM/4)-12,*/
X				CBOk,ctrlContourBox,0,0);
X	(void) MakeButton("  Cancel  ",b3,(CTRLBOX_XDIM/2)-85,
X				5 /*25+(CTRLBOX_YDIM/4)-12*/,CBCancel,
X				ctrlContourBox,0,0);
X
X	if (contourMode == EVENLY_SPACED) {
X		MakeEvenlySpaced(InputBox);
X		SetToggle(esToggle,True);
X		}
X	if (contourMode == USER_DEF) {
X		MakeUserDef(InputBox);
X		SetToggle(udToggle,True);
X		}
X
X	AmIOpen = TRUE;
X	return;
X} /* CBCtrlContourBox */
X
X
X/*
Xvoid CBMakeEvenlySpaced(ew,client_data,call_data)
XWidget ew;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XGC	gc;
XXGCValues	gcval;
Xchar	buff[80];
XWidget	w;
X
X	w = (Widget) client_data;
X	gcval.foreground = black;
X	gcval.background = white;
X	gc = XtGetGC(i->ghws.box3,GCForeground | GCBackground , &gcval);
X	if (ximageFont)
X		XSetFont(XtDisplay(w),gc,ximageFont->fid);
X
X	XDrawString(XtDisplay(w),XtWindow(w),gc,5,(CTRLBOX_YDIM/4)-5,
X			"Number of Levels",16);
X	sprintf(buff,"Min Value (%f)",contourMin);
X	XDrawString(XtDisplay(w),XtWindow(w),gc,CTRLBOX_XDIM/2,5,
X			buff,strlen(buff));
X	sprintf(buff,"Max Value (%f)",contourMax);
X	XDrawString(XtDisplay(w),XtWindow(w),gc,CTRLBOX_XDIM/2,40,
X			buff,strlen(buff));
X}
X*/
X/****	XtAddEventHandler(ctrlContourBox,Exposure,0,
X		CBMakeEvenlySpaced,w); *****/
X	
END-of-ctlcontour.c
echo file: data.c
sed 's/^X//' >data.c << 'END-of-data.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X
X#ifdef XtSpecificationRelease
X/*R4 */
X#include <X11/Xaw/List.h>
X#else
X#include <X11/List.h>
X#endif
X
X#include <math.h>
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "xstuff2.h"
X#include "i.h"
X
X#define	FRACTSIZE	3
X#define	WIDTH		5
X
X
X#define	XLOC		300
X#define	YLOC		300
X#define	XDIM		350
X#define	YDIM		350
X
Xextern  Widget  toplevelform;
Xextern	void	gr_ListHighlight();
Xextern	void	gr_VPortMoveChild();
Xextern	void	gr_VPortHoriMove();
Xextern	void	gr_VPortVertMove();
Xextern	void	CartHighlightSelectedImage();
Xextern	void	PolarHighlightSelectedImage();
Xextern  void    SetColormap();
X
Xstatic	Display	*myDpy;
X
Xstatic void MakeDataString();
Xvoid CBDoneData();
Xvoid CBSelectData();
X
X
Xint InitData(dpy)
XDisplay *dpy;
X{
X
X	myDpy = dpy;
X	return(1);	/* return NULL if fatal */
X}
X
X
Xstatic int MakeScalarString(datastring,length,width,ptr)
Xchar	*datastring[]; 
Xint	length;		/* how many entries? */
Xint	width;
Xchar	**ptr;	/* return value: storage area for strings */
X{
Xint	z;
Xchar	format[20];
Xchar	**tmpPtr;
X
X	if(!(*ptr = (char *) XIMalloc(length*(width+1)))) { 
X		printf("Can't allocate enough memory for data display\n");
X		return(0);
X		}
X	tmpPtr = ptr;
X	if (width > 6)
X		sprintf(format,"%%%dd   ",width-3);
X	else
X		sprintf(format,"%%%dd",width);
X	for (z = 0 ; z < length; z++) {
X		sprintf(*tmpPtr,format,z);
X		datastring[z] = *tmpPtr;
X		(*tmpPtr) += (strlen(*tmpPtr)+1);
X		}
X
X	datastring[length] = NULL;
X	return(1);
X
X} /* MakeScalarString() */
X
X
Xstatic void CBDataVScroll(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i = (struct IMAGE *) client_data;
X
X	gr_VPortVertMove(i->dws.box4,(int) call_data);
X}
X
X
Xstatic void CBDataHScroll(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i = (struct IMAGE *) client_data;
X
X	gr_VPortHoriMove(i->dws.box3,(int) call_data);
X}
X
X
X
X
Xstatic void DisplayData(i)
Xstruct IMAGE *i;
X{
Xint length;
X
X	if (i->dws.amIShowing) {
X		PrintMesg("DataWindow already displayed\n");
X		XRaiseWindow(myDpy,XtWindow(i->dws.toplevel));
X		return;
X		}
X
X	/* allocate space for data display strings */
X	if (i->isFloat)
X	    i->dws.pdata = (char *)XICalloc(i->xdim*i->ydim+1,
X				i->fwidth+3);/*3=[+-].\0 */
X	else
X	    i->dws.pdata = (char *)XICalloc(i->xdim*i->ydim+1,i->fwidth+2);
X
X	if (!i->dws.pdata) {
X		PrintMesg("Can't allocate enough memory to display data\n");
X		return;
X		}
X		
X
X	/* allocate space for index of strings (for list widget) */
X	i->dws.pdata2 = (char *) XICalloc(i->xdim*i->ydim + 1,sizeof(char *));
X	if (!i->dws.pdata2) {
X		PrintMesg("Can't allocate enough memory to display data\n");
X		XIFree(i->dws.pdata);
X		return;
X		}
X
X	if (i->isFloat)
X		MakeDataString(i->dws.pdata2,i->dws.pdata,i->xdim,
X				i->ydim,i->fdataset, TRUE,i->format);
X	else
X		MakeDataString(i->dws.pdata2,i->dws.pdata,i->xdim,
X				i->ydim,i->ri,FALSE,i->format);
X	/* Done creating string list of data for data window */
X
X	/* Make Widgets */
X	i->dws.toplevel = MakeATopLevel("X Image [Image.DataSet]",toplevelform,
X				XLOC,YLOC,XDIM,YDIM);
X
X	i->dws.composite = Make_Board(i->name,i->dws.toplevel,
X				5,5,XDIM,YDIM);
X
X	/* The huge display spreadsheet list */
X	i->dws.box5 = NewMakeList("DataSet",i->dws.composite,&(i->dws.box2),
X				VERTHORIZ,i->xdim,5,
X				CBDataVScroll,CBDataHScroll,CBSelectData,i,
X				i->dws.pdata2,40,60,XDIM-50,YDIM-65);
X
X
X	/* Create X and Y string lists for data window ticks */
X	i->dws.pdata3 = (char *) XICalloc(i->xdim + 2,sizeof(char *));
X	if (!i->dws.pdata3) {
X		PrintMesg("Can't allocate enough memory to display data\n");
X		XIFree(i->dws.pdata);
X		XIFree(i->dws.pdata2);
X		return;
X		}
X
X	/* Y */
X	i->dws.pdata4 = (char *) XICalloc(i->ydim + 2,sizeof(char *));
X	if (!i->dws.pdata4) {
X		PrintMesg("Can't allocate enough memory to display data\n");
X		XIFree(i->dws.pdata);
X		XIFree(i->dws.pdata2);
X		XIFree(i->dws.pdata3);
X		return;
X		}
X	{
X	/* find length of longest string */
X		char buff1[100];
X		char buff2[100];
X		int  l1,l2;
X	
X		sprintf(buff1,i->format,i->maxvalue);
X		sprintf(buff2,i->format,i->minvalue);
X		l1 = strlen(buff1);
X		l2 = strlen(buff2);
X		length = (l1 > l2)?l1:l2;
X	}
X	/* X */
X	if (i->isFloat) {
X		if(! MakeScalarString((char **) i->dws.pdata3,i->xdim+1,
X				length, &(i->dws.pdata5)))
X			return;
X		}
X	else {
X		if(! MakeScalarString((char **) i->dws.pdata3,
X				i->xdim+1,i->fwidth,
X				&(i->dws.pdata5)))
X			return;
X		}
X
X	/* Y */
X	if(! MakeScalarString((char **) i->dws.pdata4,i->ydim+1,
X			(int)log10((double)i->ydim)+1,
X			&(i->dws.pdata6))) 
X		return;	
X	/* X */
X	i->dws.box6 = NewMakeListStatic("staticList",i->dws.composite,
X			&(i->dws.box3), i->xdim,NULL,NULL,
X			(char *) i->dws.pdata3,40,35,XDIM-75,20);
X	/* Y */
X	i->dws.box7 = NewMakeListStatic("OogaBooga",i->dws.composite,
X			&(i->dws.box4), 1,NULL,NULL,
X			(char *) i->dws.pdata4,5,60,30,YDIM-90);
X
X
X	i->dws.box1 = Make_ButtonBox(i->dws.composite,5,5,XDIM-60,25);
X	i->dws.label = Make_Label(i->label,i->dws.box1,2,2,30);
X	i->dws.title = Make_Label(i->name,i->dws.box1,33,2,XDIM-100);
X	(void) MakeButton("Done",i->dws.composite,XDIM-50,6,CBDoneData,i,0,0);
X
X	SetColormap(i->dws.toplevel,i->iws.cmap);
X
X	i->dws.amIShowing= TRUE;
X	
X	return;
X} /* DisplayData() */
X
X
Xstatic void MakeDataString(datastring,mbuff,xdim,ydim,dataset,isFloat,format)
Xchar	*datastring[];	
Xchar	*mbuff;	
Xint	xdim,ydim;
Xfloat	*dataset;
Xchar	*format;
Xchar	isFloat;
X{
Xregister int	x,y;
Xchar	*ptr;
Xfloat	*fdataset;	/* float data set */
Xunsigned char	*cdataset;	/* raster image data set */
X
X
X	if (isFloat) {
X		fdataset = (float *) dataset;
X		ptr = mbuff;
X		for(y = 0 ; y < ydim ; y++) {
X			for(x = 0 ; x < xdim; x++ ) {
X				sprintf(ptr,format,fdataset[y*xdim+x]);
X				datastring[y*xdim+x] = ptr;
X				ptr += (strlen(ptr)+1);
X				}
X			}
X		}
X	else {
X		cdataset = (unsigned char *) dataset;
X		ptr = mbuff;
X		for(y = 0 ; y < ydim ; y++) {
X			for(x = 0 ; x < xdim; x++ ) {
X				sprintf(ptr,format,cdataset[y*xdim+x]);
X				datastring[y*xdim+x] = ptr;
X				ptr += (strlen(ptr)+1);
X				}
X			}
X		}
X
X
X	datastring[xdim*ydim]=NULL;
X
X	return;
X
X} /* MakeDataString() */
X
X
Xvoid CBDisplayData(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X
X	DisplayData((struct IMAGE *) client_data);
X}
X
X
X
Xvoid CBDoneData(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X	i = (struct IMAGE *) client_data;
X
X	XIFree(i->dws.pdata);
X	XIFree(i->dws.pdata2);
X	XIFree(i->dws.pdata3);
X	XIFree(i->dws.pdata4);
X	XIFree(i->dws.pdata5);
X	XIFree(i->dws.pdata6);
X	XtDestroyWidget(i->dws.toplevel);
X	i->dws.amIShowing = FALSE;
X}
X
X
Xvoid SelectPointFromImage(i,x,y)
X/* A point has been selected image, this proc highlights point in data */
Xstruct IMAGE *i;
Xint x,y;	/* with respect to data set */
X{
X	if (! i->dws.amIShowing)
X		return;
X	if ((x < 0) || (x > i->xdim) || (y < 0) || (y > i->ydim))
X		return;
X
X	gr_ListHighlight(i->dws.box5,y*i->xdim+x);
X	gr_ListHighlight(i->dws.box6,x);
X	gr_ListHighlight(i->dws.box7,y);
X
X	/* turn off old pixel highlight box */
X
X	/* scroll the data window and update scales */
X	gr_VPortMoveChild(i->dws.box2,&x,&y,i->xdim,i->ydim);
X	gr_VPortVertMove(i->dws.box4,y);
X	gr_VPortHoriMove(i->dws.box3,x);
X
X} /* SelectPointFromImage() */
X
Xstatic void CBSelectData(w,client_data,call_data)
X/* A point has been selected in Data window */
X/* set X&Y ticks, and image */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X#ifndef XtSpecificationRelease
X/* previous to R4 */
XXtListReturnStruct *lr;
X#else
XXawListReturnStruct *lr;
X#endif
X
Xint x,y;
X
X	i = (struct IMAGE *) client_data;
X#ifndef XtSpecificationRelease
X/* previous to R4 */
X	lr = (XtListReturnStruct *) call_data;
X	y = lr->index / i->xdim;
X	x = lr->index % i->xdim;
X#else
X	lr = (XawListReturnStruct *) call_data;
X	y = lr->list_index / i->xdim;
X	x = lr->list_index % i->xdim;
X#endif
X
X	gr_ListHighlight(i->dws.box6,x);
X	gr_ListHighlight(i->dws.box7,y);
X	if (i->iws.amIShowing)
X		CartHighlightSelectedImage(i,x,y);
X	if (i->pws.amIShowing) {
X		double theta;
X
X		theta=(((double)x)/((double)i->xdim))
X			*((double)(2.0*PI)) + PI/2.0;
X
X		PolarHighlightSelectedImage(i,
X			ROUND(((double)y)*sin(theta)) + i->ydim,
X			ROUND(((double)y)*cos(theta)) + i->ydim);
X		}
X} /* CBSelectData() */
X
Xvoid UpdateData(i)
Xstruct IMAGE *i;
X{
X        if (!i->dws.amIShowing)
X                return;
X
X	/* generate new list */
X	if (i->isFloat)
X		MakeDataString(i->dws.pdata2,i->dws.pdata,i->xdim,
X				i->ydim,i->fdataset, TRUE,i->format);
X	else
X		MakeDataString(i->dws.pdata2,i->dws.pdata,i->xdim,
X				i->ydim,i->ri,FALSE,i->format);
X	/* display list */
X	XtListChange(i->dws.box5,i->dws.pdata2,i->xdim*i->ydim,0,False);
X
X	/* set index to origin because list will display at origin */
X/*	   ^not true 
X	gr_VPortVertMove(i->dws.box4,0);
X	gr_VPortHoriMove(i->dws.box3,0);
X*/
X}
END-of-data.c
echo file: dtmstuff.c
sed 's/^X//' >dtmstuff.c << 'END-of-dtmstuff.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled
X * to make a contribution for the use of this software, please send
X * comments as to what you like or don't like about the software,
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Dave Thompson, National Center for Supercomputing Applications
X * davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include "ximage.h"
X#include "i.h"
X#include "animate.h"
X#include "xstuff.h"
X
X#ifdef USE_DTM
X#include <dtm/dtm.h> 
X#include <dtm/sds.h>
X#include <dtm/ris.h>
X
X#ifndef DTM_STRING_SIZE
X#define DTM_STRING_SIZE 256
X#endif
X#endif
X
X#define TIME_INTERVAL	3000	/* Time between DTM polls in millisec */
X#define	IN_PORT_NUMBER	7777
X#define	WIDTH		160	/* dims of DTM Input Control box */
X#define	HEIGHT		50
Xstatic	int	inPort;
Xstatic	char	receivedData = FALSE;	/* set on first transmission */
Xstatic	char	pauseDTM = FALSE;		/* Stop Go button */
Xstatic	Widget	pauseGoButton;
Xstatic	Widget	controlBox;
X
Xstatic	void	(*retFunc)() = NULL;	/* return Func for special DTM message*/
Xstatic	char	*retFuncValue;		/* parameter to pass back */
X
X
X
Xextern void ConvertToXColors();
Xextern void CreateImageCtrlBox();
Xextern void SetMinMax();
Xextern int  CreateRasterFromFloat();
Xextern struct IMAGE *NewIMAGE();
Xextern struct IMAGE *SearchByNameIMAGE();
Xextern struct IMAGE *ci;
Xextern Widget toplevelform;
Xextern Display *myDpy;
Xextern char *dtmPortId;
Xextern struct ANIMATION *NewAnimation();
Xextern int CalculateNBP();
Xextern void ExpandCharByPixelReplication();
Xextern void ExpandCharByInterpolation();
X
X#ifdef USE_DTM
X
Xvoid CheckDTM();
X
XCBPauseGoDTM(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	pauseDTM = ! pauseDTM;
X
X	if (pauseDTM)
X		SetButtonString(pauseGoButton,"Go");
X	else {
X		SetButtonString(pauseGoButton,"Pause");
X		CheckDTM(0,0);
X		}
X}
X
X
Xvoid CreateDTMControl()
X{
Xint	xpos,ypos;
XWidget	box;
X
X
X	PlaceWindow(&xpos,&ypos);
X
X	controlBox = MakeATopLevel("DTMControl",toplevelform,xpos,ypos,
X				WIDTH,HEIGHT);
X
X	box = Make_Window("DTM Input Control",controlBox,0,0,WIDTH,HEIGHT);
X	
X	pauseGoButton = MakeButton("Go",box,60,25,CBPauseGoDTM,NULL,50,0);
X
X}
X
X
Xstatic void AnimateDTM(header,dims,hasPalette,ccells)
Xchar	*header; 	/* DTM header */
Xint	*dims;
Xchar	hasPalette;
XXColor	*ccells;
X{
Xstruct ANIMATION *a;
XDTMCMD  cmd;
Xchar    *dtmGroup;
Xchar    s[DTM_STRING_SIZE];
XDTMTYPE type;
Xint	size;
Xfloat	*data;
Xchar	buff[256];
Xfloat	min,max;
X
X
X
X	if (!(dtmGroup = (char *) XIMalloc(DTM_STRING_SIZE))) {
X		PrintMesg("Can't malloc for DTM SDS name\n");
X		DTMendRead(inPort);
X		return;
X		}
X	SDSgetGroup(header,&cmd,dtmGroup,s);
X
X	if (DTMgetType(header,&type) == -1) {
X		PrintMesg("Error getting DTM type\n");
X		DTMendRead(inPort);
X		return;
X		}
X
X	size = dims[0]*dims[1]*dims[2];
X
X	switch(type) {
X		case DTM_FLOAT:
X			if (!(data = (float *) XIMalloc(
X				size*sizeof(float)))){
X				PrintMesg("Can't Malloc for DTM dataset\n");
X				DTMendRead(inPort);
X				return;
X				}
X			if (DTMERROR == DTMrecvDataset(inPort,data,size,type)){
X				PrintMesg("Error receiving DTM SDS data \n");
X				DTMendRead(inPort);
X				return;
X				}
X
X			/* convert to char */
X			if(-1==SDSgetMinMax(header,&min, &max)){
X				SetMinMax(data,dims[0],dims[1]*dims[2],
X					&min,&max);
X				}
X
X			/* Change floats to chars in same data space */
X			CreateRasterFromFloat(data,(unsigned char **)&data,
X				dims[0],dims[1]*dims[2],min,max,FALSE);
X			PrintMesg("Received DTM 3d float data set.");
X			break;
X		case DTM_CHAR:
X			if (!(data = (float *) XIMalloc(
X				size*sizeof(char)))){
X				PrintMesg("Can't Malloc for DTM dataset\n");                                    DTMendRead(inPort);
X				return;
X				}
X			if (DTMERROR == DTMrecvDataset(inPort,data,size,type)){
X				PrintMesg("Error receiving DTM SDS data \n");
X				DTMendRead(inPort);
X				return;
X				}
X			PrintMesg("Received DTM 3d char data set.");
X			break;
X		default:
X			PrintMesg("Can't handle this DTM type\n");
X			DTMendRead(inPort);
X			return;
X		}; /*switch*/
X
X
X
X	DTMendRead(inPort);
X	sprintf(buff,"Just read in DTM animation sequence of %d frames\n",
X			dims[2]);
X	PrintMesg(buff);
X	sprintf(buff,"animation frame dimensions: %d,%d\n",dims[0],dims[1]);
X	PrintMesg(buff);
X
X	if (!(a = NewAnimation())) {
X		PrintMesg("Out of Memory\n");
X		XIFree(data);
X		return;
X		}
X
X	a->name = dtmGroup;
X	a->directory = (char *) 0;
X	a->files = (char **) 0;
X	a->numFiles = 0;
X	a->xdim = dims[0];
X	a->ydim = dims[1];
X	a->isHDF = FALSE;
X	a->isFloat = FALSE;
X	a->frameNum = 1;
X	a->skip = 0;
X	a->status = A_STOP;
X	a->numFrames = dims[2];
X
X	if (a->numFrames < 2) { /* this shouldn't happen */
X		PrintMesg("Animation requires more than one frame\n");
X		PrintMesg("Cancelling Animation\n");
X		XIFree(data);
X		return;
X		}
X	a->hasPalette = hasPalette;
X	a->palette = ccells;
X	a->inMemory = True;
X	a->dataCube = (unsigned char *) data;
X
X	sprintf(buff,"Loading %dx%d animation of %d frames\n",
X				a->xdim,a->ydim,a->numFrames);
X	PrintMesg(buff);
X
X	AnimateCtrlBox(a);
X
X} /* AnimateDTM() */
X
Xstatic void ReadDTMTextMessage(header) 
Xchar *header;
X{
X	header +=4; /* skip over "DTM " */
X	PrintMesg("Just received DTM message:\n");
X	PrintMesg(header);
X}
X
Xstatic void ReadDTMSpecTextMessage(header) 
Xchar *header;
X{
X	header +=4; /* skip over "DTM " */
X	if (retFunc) {
X#ifdef DEBUG
X		printf("Just received special DTM message: \"%s\"\n",header);
X		PrintMesg("Just received special DTM message:");
X		PrintMesg(header);
X		PrintMesg("\n");
X#endif
X		retFunc(header,retFuncValue);
X		retFunc = NULL;
X		}
X	else {
X		PrintMesg("Just received special DTM message:");
X		PrintMesg(header);
X		PrintMesg("\n");
X		PrintMesg("Discarding special DTM message\n");
X		}
X}
X
X
X
X
Xstatic void GetDTMdata()
X{
Xstatic unsigned char palette[768];
Xstatic	char	hasPalette=FALSE;
Xchar	header[DTM_MAX_HEADER];
Xint	xdim,ydim;
Xunsigned char	*image;
Xstatic  XColor	*ccells;
Xchar	buff[256];
Xstruct	IMAGE *i;
Xchar	*dtmGroup;
XXEvent	event_return;
XDTMCMD	cmd;
Xchar	s[DTM_STRING_SIZE];
Xfloat	*data;
Xint	length;
X
X#ifdef DEBUG
X	printf("GetDTMdata():  I've been called\n");
X#endif
X
X
X   while ((!pauseDTM)&&DTMavailRead(inPort)) {
X/*   while (DTMavailRead(inPort)) {*/
X		if (DTMerrno) {
X			sprintf(buff,"DTM status: %s\n",
X                                        DTMerrmsg(1));
X			PrintMesg(buff);
X			return;
X			}
X
X		/* if there is more dtm stuff, service X events first*/
X		XSync(myDpy,False);
X		XFlush(myDpy);
X		XSync(myDpy,False);
X		while(XtPending()) {
X			XtNextEvent(&event_return);
X			XtDispatchEvent(&event_return);
X			XSync(myDpy,False);
X			}
X
X/*
X	if (pauseDTM)
X		return;
X*/
X
X	if ((length =DTMbeginRead(inPort,header,DTM_MAX_HEADER)) == DTMERROR){
X		PrintMesg("Error reading DTM header\n");
X		return;
X		}
X#ifdef DEBUG
X	printf("DTM header: %s\n",header);
X	printf("Length of header = %d\n",length);
X#endif 
X
X	if (length == 0) {
X#ifdef DEBUG
X		printf("zero length DTM header: discarding with DTMendRead\n");
X#endif 
X		DTMendRead(inPort);
X#ifdef DEBUG
X		printf("done discarding\n");
X#endif 
X		return;
X		}
X
X	if (DTMcompareClass(header,"MSG")) {
X		/* Then it's a text message */
X		DTMendRead(inPort);
X		ReadDTMTextMessage(header);
X		return;
X		}
X
X	if (DTMcompareClass(header,"DTM")) {
X		/* Then it's a text message */
X		DTMendRead(inPort);
X		ReadDTMSpecTextMessage(header);
X		return;
X		}
X
X	if (DTMcompareClass(header,RIS8class)) {
X		/* Read in a RIS8 image */
X		if (!(dtmGroup = (char *) XIMalloc(DTM_STRING_SIZE))) {
X			PrintMesg("Can't allocate memory for DTM RIS8 name\n");
X			DTMendRead(inPort);
X			return;
X			}
X		RISgetGroup(header,&cmd,dtmGroup,s);
X
X	    if (i=SearchByNameIMAGE(dtmGroup)) {
X		/* This RIS8 name has been read in before */
X		RISgetDimensions(header,&xdim,&ydim);
X		if ((xdim != i->xdim) || (ydim != i->ydim)) {
X		    PrintMesg("DTM image is of different size. Discarding\n");
X		    DTMendRead(inPort);
X		    return;
X		    }
X
X		if (i->isFloat){
X		PrintMesg("This DTM image was previously a float type\n");
X			PrintMesg("data set, not a char. Discarding\n");
X			DTMendRead(inPort);
X			return;
X			}
X
X		if (DTMrecvDataset(inPort,i->ri,i->xdim*i->ydim,DTM_CHAR)
X				== DTMERROR){
X			PrintMesg("Error reading DTM dataset\n");
X			DTMendRead(inPort);
X			return;
X			}
X		DTMendRead(inPort);
X
X		sprintf(buff,"Just read in DTM image of %d,%d dimension: %s\n",
X				i->xdim,i->ydim,dtmGroup);
X		PrintMesg(buff);
X
X		if (i->expand) {
X			int nbp;
X			nbp = CalculateNBP(myDpy);
X			if (i->interpExpansion) {
X				ExpandCharByInterpolation(i->ri,
X					i->xdim,i->ydim,i->dExpRIExpand,
X					i->expansionFactor,nbp);
X				}
X			else {
X				ExpandCharByPixelReplication(i->ri,
X					i->xdim,i->ydim,i->dExpRIExpand,
X					i->expansionFactor,nbp);
X				}
X			}
X		UpdateImageData(i);
X		return;
X		}
X	    else {
X		/* This is a new RIS8 */
X
X		RISgetDimensions(header,&xdim,&ydim);
X
X		if (!(image = (unsigned char *) 
X				XIMalloc(xdim*ydim*sizeof(char)))) {
X			PrintMesg("Can't allocate memory for DTM RIS8 image\n");
X			DTMendRead(inPort);
X			return;
X			}
X
X		if (DTMrecvDataset(inPort,image,xdim*ydim,DTM_CHAR)== DTMERROR){
X			PrintMesg("Error reading DTM dataset\n");
X			DTMendRead(inPort);
X			return;
X			}
X
X
X		DTMendRead(inPort);
X
X		if (!(i = NewIMAGE())) {
X			PrintMesg("Can't allocate memory for new data set\n");
X			return;
X			}
X
X		i->name = dtmGroup;
X		i->xdim = xdim;
X		i->ydim = ydim;
X		i->isHDF = FALSE;
X		i->isFloat = FALSE;
X		i->palette = ccells;
X		i->hasPalette = hasPalette;
X		i->fdataset = NULL;
X		i->format = "%3d";
X		i->fwidth = 3;
X		i->maxvalue = 255;
X		i->minvalue = 0;
X		i->ri = image;
X
X		sprintf(buff,"Just read in DTM image of %d,%d dimension: %s\n",
X				i->xdim,i->ydim,dtmGroup);
X		PrintMesg(buff);
X/**/		ci = i; /* in for debugging purposes */
X		CreateImageCtrlBox(i);
X		} /* if old RIS8 else new RIS8*/
X	    } /* if RIS8 then */
X	else {
X		/* Not a DTM RIS8 */
X		if (DTMcompareClass(header,PALclass)) {
X			hasPalette= TRUE;
X			if (!(ccells = (XColor *) 
X				 XIMalloc(sizeof(XColor) * 256))) {
X                              PrintMesg("Can't alloc memory for DTM palette\n");
X                              hasPalette = FALSE;
X			      }
X			    else {
X			      DTMrecvDataset(inPort,palette,768,DTM_CHAR);
X			      ConvertToXColors(palette,ccells);
X			      }
X			 DTMendRead(inPort);
X			 PrintMesg("Just read in DTM palette\n");
X			 }
X		else {
X			/* Not a DTM PAL or RIS8*/
X		    if (DTMcompareClass(header,SDSclass)) {
X			int x,size,rank,dims[10];
X			DTMTYPE type;
X
X			if (-1 == SDSgetDimensions(header,&rank,dims,sizeof(dims))) {
X			    PrintMesg("Failed at getting dimensions of DTM\n");
X			    DTMendRead(inPort);
X			    return;
X			    }
X			
X
X			/*if (rank != 2) {*/
X			if ((rank >3) || (rank < 2)) {
X			    sprintf(buff,"DTM data set has %d dimensions\n",
X					rank);
X			    PrintMesg(buff);
X			    PrintMesg("Can only handle 2D & 3D DTM data sets\n");
X			    DTMendRead(inPort);
X			    return;
X			    }
X			if (rank == 3) {
X				AnimateDTM(header,dims,hasPalette,ccells);
X				return;
X				}
X
X			if (!(dtmGroup = (char *) XIMalloc(DTM_STRING_SIZE))) {
X				PrintMesg("Can't malloc for DTM SDS name\n");
X				DTMendRead(inPort);
X				return;
X				}
X			SDSgetGroup(header,&cmd,dtmGroup,s);
X
X		      if (i=SearchByNameIMAGE(dtmGroup)) {
X			if ((i->xdim != dims[0]) || (i->ydim != dims[1])) {
X			   PrintMesg("DTM image different size. Discarding\n");
X			   DTMendRead(inPort);
X			   return;
X	                   }
X                        if (SDSgetType(header,&type) == -1) {
X			   PrintMesg("Error getting DTM type\n");
X			   DTMendRead(inPort);
X			   return;
X	                   }
X                        switch (type) {
X                            case DTM_FLOAT:
X				if (!i->isFloat){
X					PrintMesg("This DTM image was previously a char type data set\n");
X					PrintMesg("not a float. Discarding\n");
X				    	DTMendRead(inPort);
X				    	return;
X					}
X				if (DTMrecvDataset(inPort,i->fdataset,
X					i->xdim*i->ydim,DTM_FLOAT) 
X					== DTMERROR) {
X				    PrintMesg("Error reading DTM dataset\n");
X				    DTMendRead(inPort);
X				    return;
X				    }
X
X				if(-1==SDSgetMinMax(header,&(i->minvalue),
X                                        &(i->maxvalue))){
X                                     SetMinMax(i->fdataset,i->xdim,i->ydim,
X                                            &(i->minvalue),&(i->maxvalue));
X                                	}
X				CreateRasterFromFloat(i->fdataset,&(i->ri),
X                                   i->xdim,i->ydim,i->minvalue,i->maxvalue,0);
X				sprintf(buff,"Just read in DTM %d,%d float SDS: %s\n",i->xdim,i->ydim,dtmGroup);
X				PrintMesg(buff);
X                                break;
X                            case DTM_CHAR:
X				if (i->isFloat){
X					PrintMesg("This DTM image was previously a float type data set\n");
X					PrintMesg("not a char. Discarding\n");
X				    	DTMendRead(inPort);
X				    	return;
X					}
X				if (DTMrecvDataset(inPort,i->ri,
X					i->xdim*i->ydim,DTM_CHAR) 
X					== DTMERROR) {
X				    PrintMesg("Error reading DTM dataset\n");
X				    DTMendRead(inPort);
X				    return;
X				    }
X				sprintf(buff,"Just read in DTM %d,%d char SDS: %s\n",i->xdim,i->ydim,dtmGroup);
X				PrintMesg(buff);
X                                break;
X                            default:
X                                 PrintMesg("Can't handle this DTM type\n");
X                                 DTMendRead(inPort);
X                                 return;
X                            };
X
X
X			DTMendRead(inPort);
X			if (i->expand) {
X				int nbp;
X				nbp = CalculateNBP(myDpy);
X				if (i->interpExpansion) {
X					ExpandCharByInterpolation(i->ri,
X						i->xdim,i->ydim,i->dExpRIExpand,
X						i->expansionFactor,nbp);
X					}
X				else {
X					ExpandCharByPixelReplication(i->ri,
X						i->xdim,i->ydim,i->dExpRIExpand,
X						i->expansionFactor,nbp);
X					}
X				}
X			UpdateImageData(i);
X			return;
X			}
X		      else {
X			/* new sds */
X
X			for(x=1,size=dims[0]; x < rank; x++)
X				size *= dims[x];
X
X                        if (SDSgetType(header,&type) == -1 ) {
X			   PrintMesg("Error getting DTM type\n");
X			   DTMendRead(inPort);
X			   return;
X	                   }
X			switch (type) {
X			    case DTM_FLOAT:
X#ifdef DEBUG 
X				printf("received SDS DTM_FLOAT\n");
X#endif
X				if (!(data = (float *) XIMalloc(
X						size*sizeof(float)))){
X				    PrintMesg("Can't Malloc for DTM dataset\n");
X				    DTMendRead(inPort);
X				    return;
X				    }
X				break;
X			    case DTM_CHAR:
X#ifdef DEBUG 
X				printf("received SDS DTM_CHAR\n");
X#endif
X				if (!(data = (float *) XIMalloc(
X						size*sizeof(char)))){
X				    PrintMesg("Can't Malloc for DTM dataset\n");
X				    DTMendRead(inPort);
X				    return;
X				    }
X				break;
X			    default: 
X				 PrintMesg("Can't handle this DTM type\n");
X				 DTMendRead(inPort);
X				 return;
X			    };
X
X			if (DTMERROR == DTMrecvDataset(inPort,data,size,type)){
X			    PrintMesg("Error receiving DTM SDS data \n");
X			    DTMendRead(inPort);
X			    return;
X			    }
X#ifdef DEBUG
X	printf("received dataset at address %d\n",data);
X#endif
X
X			DTMendRead(inPort);
X			switch (type) {
X			    case DTM_FLOAT:
X				sprintf(buff,"Just read in DTM %d,%d float SDS: %s\n",dims[0],dims[1],dtmGroup);
X				PrintMesg(buff);
X				break;
X			    case DTM_CHAR:
X				sprintf(buff,"Just read in DTM %d,%d char SDS: %s\n",dims[0],dims[1],dtmGroup);
X				PrintMesg(buff);
X				break;
X			    };
X			/* assume rank is 2  (2 dimensional)*/
X			/* assume not read in before */
X			/* New Image */
X			if (!(i = NewIMAGE())) {
X			    PrintMesg("Can't allocate mem for new data set\n");
X			    XIFree(data);
X			    return;
X			    }
X			 i->name = dtmGroup;
X			 i->xdim = dims[0];
X			 i->ydim = dims[1];
X			 i->isHDF = FALSE;
X			 i->palette = ccells;
X			 i->hasPalette = hasPalette;
X			 if (type == DTM_FLOAT) {
X			    i->isFloat = TRUE;
X			    i->fdataset = data;
X			    if(-1==SDSgetMinMax(header,&(i->minvalue),
X					&(i->maxvalue))){
X				SetMinMax(i->fdataset,i->xdim,i->ydim,
X						&(i->minvalue),&(i->maxvalue));
X				}
X			    if (!CreateRasterFromFloat(i->fdataset,&(i->ri),
X				   i->xdim,i->ydim,i->minvalue,i->maxvalue,1)){
X					/* Can't create raster */
X					XIFree(data);
X					DestroyIMAGE(i);
X					return;
X					}
X			    i->format = "% 6.3f";
X			    i->fwidth = 7;
X			    }
X			else { /* It's DTM_CHAR */
X			    i->isFloat = FALSE;
X			    i->fdataset = NULL;
X			    i->ri = (unsigned char *) data;
X			    i->maxvalue = 255.0;
X			    i->minvalue = 0.0;
X			    i->format = "%3d";
X			    i->fwidth = 3;
X			    }
X
X/**/			ci = i; /* in for debugging purposes */
X
X			CreateImageCtrlBox(i);
X			}
X		      } /* else not read in before */
X		    else{
X			  /* Not a DTM RIS8,PAL,SDS */
X			  PrintMesg("Unknown data type from DTM connection\n");
X			  DTMendRead(inPort);
X			  }
X		    }
X		}
X
X	if (!receivedData) {
X	    CreateDTMControl();
X	    receivedData = TRUE;
X	    pauseDTM = TRUE;
X	    }
X	else
X	   XRaiseWindow(myDpy,XtWindow(controlBox));
X
X
X	} /* while */
X
X
X} /* GetDTMdata() */
X
X
X
Xstatic int CheckInPort(port)
X/* return true if something to read else false */
Xint port;
X{
Xchar buff[256];
X
X	if (port != -1 ) {
X		if (DTMavailRead(port)) {
X			if (!DTMerrno)
X			      return(1);
X			else {
X			      sprintf(buff,"DTM status: %s\n", DTMerrmsg(1));
X			      PrintMesg(buff);
X			      }
X			}
X		}
X	return(0);
X}
X
X
Xstatic void CheckDTM(client_data,id)
Xcaddr_t client_data;
XXtIntervalId *id;
X{
Xchar buff[256];
X#ifdef DEBUG
X/*	printf("CheckDTM(): I've been called\n");*/
X#endif
X
X		while((!pauseDTM) && CheckInPort(inPort))
X			GetDTMdata();
X
X		/* Continue checking every TIME_INTERVAL msecs */
X		XtAddTimeOut(TIME_INTERVAL,CheckDTM,NULL);
X
X
X} /* CheckDTM */
X
X
X
X
X
Xint MakeAnyInPort()
X{
Xint inPort;
Xchar buff[256];
X
X	if (-1 == (inPort = DTMmakeInPort(":0"))) {
X
X		sprintf(buff,"Error setting up DTM in port: %s\n",
X				DTMerrmsg(1));
X
X		PrintMesg(buff);
X		}
X	else {
X		DTMgetPortAddr(inPort,dtmPortId,80);
X		sprintf(buff,"Using DTM port %s for input\n",dtmPortId);
X		PrintMesg(buff);
X		}
X
X
X	return (inPort);
X}
X#endif
X
XInitDTM()
X{
X#ifdef USE_DTM
Xchar buff[256];
X
X	if (dtmPortId == (char*) 0) {
X		sprintf(buff,":%d",IN_PORT_NUMBER);
X		if (-1 == (inPort = DTMmakeInPort(buff))) {
X			sprintf(buff,"Couldn't use DTM port :%d for input\n",
X				IN_PORT_NUMBER);
X			PrintMesg(buff);
X			inPort = MakeAnyInPort();
X			}
X		else {
X			sprintf(buff,"Using port %d as DTM input\n",
X				IN_PORT_NUMBER);
X			PrintMesg(buff);
X			}
X		DTMgetPortAddr(inPort,dtmPortId,80);
X		}
X	else { /* user specified */
X		if (-1 == (inPort = DTMmakeInPort(dtmPortId))) {
X			sprintf(buff,"Couldn't use DTM port %s for input\n",
X				dtmPortId);
X			PrintMesg(buff);
X			inPort = MakeAnyInPort();
X			}
X		else {
X			/*
X			DTMgetPortAddr(inPort, buff, sizeof buff);
X			fprintf(stderr, "%s", buff);
X			fflush(stderr);
X			*/
X			sprintf(buff,"Using DTM port %s for input\n",dtmPortId);
X			PrintMesg(buff);
X			}
X		}
X
X	XtAddTimeOut(TIME_INTERVAL,CheckDTM,NULL); /* Check every 5 sec */
X
X	receivedData = FALSE;
X	pauseDTM = FALSE; 
X#endif
X
X	return(1);
X}
X
X
X
X
Xint MakeWriteConnection(port)
X/* return portnumber or -1 on failure */
Xchar *port;
X{
X#ifdef USE_DTM
Xint portnum;
Xchar buff[256];
X
X#ifdef DEBUG
X	printf("MakeWriteConnection():Creating write connection to %s\n",port);
X#endif 
X
X	if (DTMERROR == (portnum = DTMmakeOutPort(port))) {
X		sprintf(buff,"Error setting up DTM out port %s:\n%s\n",
X				port,DTMerrmsg(1));
X		PrintMesg(buff);
X		return(-1);
X		}
X
X#ifdef DEBUG
X	printf("Successfully Created write connection portnum=%d\n",portnum);
X#endif 
X	return(portnum);
X#endif
X}
X
Xint MakeReadConnection(port)
X/* return portnumber or -1 on failure */
Xchar *port;
X{
X#ifdef USE_DTM
Xint portnum;
Xchar buff[256];
X
X	if (DTMERROR == (portnum = DTMmakeInPort(port))) {
X		sprintf(buff,"Error setting up DTM in port: %s\n",
X				DTMerrmsg(1));
X		PrintMesg(buff);
X		return(-1);
X		}
X
X	return(portnum);
X#endif
X}
X
X
XSendPalette(outPort,pal)
Xint outPort;
Xchar *pal;
X{
X#ifdef USE_DTM
Xchar palheader[RISsize];
X
X	PALsetClass(palheader);
X	DTMbeginWrite(outPort, palheader, strlen(palheader)+1);
X	DTMsendDataset(outPort,pal,768,DTM_CHAR);
X	DTMendWrite(outPort);
X
X#endif
X}
X
XSendData(outPort,data,xdim,ydim,isFloat,title)
Xint	outPort;
Xchar	*data;
Xint	xdim,ydim;
Xchar	isFloat;
Xchar 	*title;
X{
Xchar buff[256];
Xchar buff2[80];
X#ifdef USE_DTM
Xchar header[SDSsize];
Xint dims[3];
Xint rank;
X
X	while(CheckInPort(inPort))
X		GetDTMdata();
X#ifdef DEBUG
X	printf("SendData(): sending data on port %d\n",outPort);
X#endif
X
X	SDSsetClass(header);
X	rank = 2;
X	dims[0]=xdim;
X	dims[1]=ydim;
X	SDSsetDimensions(header,rank,dims);
X	if (title)
X		SDSsetTitle(header,title);
X
X	if (DTMERROR == DTMbeginWrite(outPort, header, strlen(header)+1)) {
X		DTMgetPortAddr(outPort,buff2,80);
X		sprintf(buff,"Error sending data to DTM port %s:\n%s\n",
X				buff2,DTMerrmsg(1));
X		PrintMesg(buff);
X/*****/		DTMerrno = DTMNOERR;
X/* take me out later */
X		return(-1);
X		}
X
X	if (isFloat) 
X		DTMsendDataset(outPort,data,xdim*ydim*sizeof(float),DTM_FLOAT);
X	else
X		DTMsendDataset(outPort,data,xdim*ydim*sizeof(char),DTM_CHAR);
X		
X	DTMendWrite(outPort);
X
X#endif
X}
X
XRegisterSpecialDTMMesgReturn(func,var)
X/* register a function to be called when a special message gets sent */
X/* call back is of the form func(mesg,var) */
Xvoid (*func)();
Xchar *var;
X{
X#ifdef DEBUG
X	printf("RegisterSpecialDTMMesgReturn(func = %d,var = %d)\n",func,var);
X#endif
X	retFunc = func;
X	retFuncValue = var;
X}
X
END-of-dtmstuff.c
echo file: getfile.c
sed 's/^X//' >getfile.c << 'END-of-getfile.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xos.h>
X#include <sys/stat.h>
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/IntrinsicP.h>
X#ifdef XtSpecificationRelease
X/*R4 */
X#include <X11/Xaw/ViewportP.h>
X#include <X11/Xaw/List.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xaw/Scroll.h>
X#else
X#include <X11/ViewportP.h>
X#include <X11/List.h>
X#include <X11/Dialog.h>
X#include <X11/Scroll.h>
X#endif 
X
X#if defined(SYSV) || defined(AIX)
X#include <dirent.h>
X#else
X#include <sys/dir.h>
X#include <sys/param.h>
X#endif
X
X#ifndef MAXPATHLEN
X#define MAXPATHLEN	255
X#endif
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "getfile.h"
X
X
X#define	XDIM	300
X#define YDIM	308
X#define	MAXFILES	512			/* Max number of files/dir */
X
Xextern	Widget	toplevelform;
Xextern	char	*getenv();
Xextern	void	gr_DialogSetValue();
Xextern	void	Terminate();
X
Xstatic	char	usecwd = TRUE;			/* Use current working dir*/
Xstatic	char	*defdir;
Xstatic	char	*cfilename = "";
Xstatic	char	directory[MAXPATHLEN];
Xstatic	DIR	*dirFD;
Xstatic	char	dirFDopen = FALSE;
Xstatic	Widget	topFileWidget;
Xstatic	Widget	dir_dialog_widget;
Xstatic	Widget	cfile_dialog;
Xstatic	Widget	file_list_widget;
Xstatic	Widget	file_list_vport_widget;
Xstatic	char	*listOfFiles[MAXFILES];
Xstatic	int	numFiles = 0;		/* number of files in listOfFiles */
Xstatic	Widget	inputBox;
Xstatic	char	aFileHasBeenChosen = FALSE;
Xstatic	char	fileChosen[80];
Xstatic	struct	GetFile	*thisFile;
Xstatic	Widget	xDimDialog;
Xstatic	Widget	yDimDialog;
Xstatic	char	amIAlreadyOpen = FALSE;
Xstatic	Display	*myDpy;
X
X/* These are registered in xinit.c */
Xstatic  char ChangeDirTrans[] = "<Key>Return:    ETDirReturn()";
Xstatic  char OpenFileTrans[] = "<Key>Return:    ETRetOpen()";
Xstatic  char JumpToYDimDialog[] = "<Key>Return:    ETJumpToYDimDialog()";
Xstatic  char JumpToOk[] = "<Key>Return:    ETJumpToOk()";
X
Xvoid CBChoseFile();
Xvoid CBOpen();
Xvoid CBChangeDirectory();
Xvoid CBCancel();
Xvoid CBUpDir();
X
Xint InitGetAFile(dpy)
XDisplay *dpy;
X{
Xint x;
X
X	myDpy = dpy;
X	if (!(defdir = (char *) XIMalloc(MAXPATHLEN))) {
X		PrintMesg("Can't XIMalloc any memory\n");
X		return(NULL);
X		}
X
X	for(x = 0; x < MAXPATHLEN; x++)
X		directory[x]=' ';
X
X#if defined(SYSV) || defined(AIX)
X	if (!getcwd(defdir,MAXPATHLEN))
X#else
X	if (!getwd(defdir)) 
X#endif
X		{
X		PrintMesg("Can't get working directory\n");
X		return(NULL);
X		}
X
X	dirFDopen = FALSE;
X
X	return(1);
X}
X
X
X
Xchar DoesFileExist(f)
Xchar *f;
X{
XFILE *fp;
X	if (fp = fopen(f,"r")) {
X		fclose(fp);
X		return(TRUE);
X		}
X	else
X		return(FALSE);
X}
X
X
Xvoid GetAFile(fileinfo)
Xstruct	GetFile	*fileinfo;
X{
XWidget	board;
XWidget	fileCtrlWidget;
XWidget	bbox;
XWidget	bbox2;
XWidget	box3;
Xint	screen;
X
X	if (amIAlreadyOpen)
X		return;
X
X	thisFile = fileinfo;
X
X	screen = XDefaultScreen(myDpy);
X	topFileWidget = MakeATopLevelOverride("GetAFile",
X				toplevelform, 
X				(DisplayWidth(myDpy,screen)-XDIM)/2,
X				(DisplayHeight(myDpy,screen)-YDIM)/2,
X				XDIM,YDIM);
X
X	fileCtrlWidget = Make_Window("NCSA X Image",topFileWidget,
X				5,5,XDIM,YDIM);
X
X	if (usecwd) {
X		strcpy(directory,defdir);
X		}
X
X	
X	if (!(CreateListofFiles(directory,listOfFiles,&numFiles)))
X		return;
X
X
X	board= Make_Board("blabla",fileCtrlWidget,2,22,XDIM-7,55);
X	
X	dir_dialog_widget = Make_Dialog("DirOfFiles",board,
X			"Directory:                    ",
X				directory,80,2,2,XDIM-60,50);
X
X	DialogAddTrans(dir_dialog_widget,ChangeDirTrans);
X	
X	(void) MakeButton("Up", board,XDIM-54,2,CBUpDir,NULL,
X				44,50);
X
X	box3 = Make_Board("blabla",fileCtrlWidget,2,80,XDIM-7,55);
X	cfile_dialog = Make_Dialog("DirOfFiles",box3,
X			"Current Filename:                    ",
X				cfilename,80,2,2,XDIM-60,50);
X
X	DialogAddTrans(cfile_dialog,OpenFileTrans);
X
X	gr_DialogSetValue(cfile_dialog,"");
X
X	aFileHasBeenChosen = FALSE;
X
X	file_list_widget = MakeList("ListOfFiles",fileCtrlWidget,
X			VERTONLY,&file_list_vport_widget,1,CBChoseFile,
X			listOfFiles,2,138,150,YDIM-142,NULL,NULL);
X
X
X	bbox = Make_ButtonBox(fileCtrlWidget,155,138,XDIM-160,YDIM-142);
X	bbox2 = Make_ButtonBox(bbox,2,2,XDIM-165,30);
X	(void) MakeButton(" Open ",bbox2,10,5,CBOpen,NULL,0,0);
X	(void) MakeButton(" Cancel ",bbox2,70,5,CBCancel,NULL,0,0);
X	inputBox = Make_ButtonBox(bbox,2,35,XDIM-165,YDIM-181);
X
X	fileChosen[0]='\0';
X	amIAlreadyOpen = TRUE;
X	
X	return;
X
X} /* GetAFile() */
X
X
Xstatic void CloseFileWidget()
X{
Xchar **p;
X
X	p = listOfFiles;
X	while (*p) {
X		XIFree(*p);
X		p++;
X		}
X
X	if(dirFDopen) {
X		closedir(dirFD);
X		dirFDopen = FALSE;
X		}
X	XtDestroyWidget(topFileWidget);
X
X/*	XFlush(XtDisplay(topFileWidget));*/
X	XSync(XtDisplay(topFileWidget),False);
X
X	amIAlreadyOpen = FALSE;
X	return;
X}
X
X
Xvoid CBCancel(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X
X	CloseFileWidget();
X	thisFile->nofile(thisFile->param);
X
X} /*CBCancel() */
X
X
XBubbleSort(list,num)
Xchar *list[];
X{
Xchar *tmp;
Xint x,y;
X	for(x=0; x< num; x++)
X		for(y=0; y < num-x-1; y++)
X			if (strcmp(list[y],list[y+1]) > 0) {
X				tmp = list[y+1];
X				list[y+1] = list[y];
X				list[y] = tmp;
X				}
X
X}
X
X
Xint CreateListofFiles(theDir,listOfFiles,nf)
Xchar	*theDir;
Xchar	*listOfFiles[];
Xint	*nf; /* initially contains num files in listOfFiles,  */
X	     /* and returns new value */
X{
Xchar errmesg[100];
Xint	count;
XDIR	*newdirFD;
Xchar **p;
Xregister int x;
Xstruct stat fileStat;
Xchar path[MAXPATHLEN];
X
X#if defined(SYSV) || defined(AIX)
Xstruct dirent *dirInfo;
X#else
Xstruct	direct	*dirInfo;
X#endif
X
X	if (!(newdirFD = opendir(theDir))) {
X		sprintf(errmesg,"Can't open directory %s\n",theDir);
X		PrintMesg(errmesg);
X		return(NULL);
X		}
X
X	if (dirFDopen) {
X		closedir(dirFD);
X		/* free old Malloc list */
X		for (x=0,p=listOfFiles; x < *nf; x++,p++) 
X			XIFree(p);
X	
X		}
X
X	dirFD= newdirFD;
X	dirFDopen = TRUE;
X
X	count = 0;
X	while((dirInfo = readdir(dirFD))  && (count < (MAXFILES-2))) {
X		if (strcmp(dirInfo->d_name,".")&
X			(strcmp(dirInfo->d_name,".."))) {
X			listOfFiles[count] = (char *) XIMalloc(strlen(
X							dirInfo->d_name)+2);
X			sprintf(path,"%s/%s",theDir,dirInfo->d_name);
X			stat(path,&fileStat);
X			if (fileStat.st_mode & S_IFDIR) 
X				sprintf(listOfFiles[count],"%s/",
X							dirInfo->d_name);
X			else
X				strcpy(listOfFiles[count], dirInfo->d_name);
X			count++;
X			}
X		}
X	/**nf = count;*/
X
X	BubbleSort(listOfFiles,count);
X
X	listOfFiles[count++] = "                          ";
X	for (x = count; x < 9 ; x++)
X		listOfFiles[count++] = " ";
X
X	*nf = count;
X	listOfFiles[count] = NULL;
X
X/*
X	while(count < MAXFILES-2) {
X		listOfFiles[count] = " ";
X		count++;
X		}
X
X	listOfFiles[count] = NULL;
X*/
X
X	return(1);
X}
X
X
X
X
Xstatic void CBChangeDirectory(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data; /* if TRUE, directory already contains new dir */
Xcaddr_t call_data;
X{
Xchar	tmp[MAXPATHLEN];
X
X	if (!client_data) {
X		strcpy(tmp,XtDialogGetValueString(dir_dialog_widget));
X		Terminate(tmp);
X		}
X	else
X		strcpy(tmp,directory);
X
X	usecwd = FALSE;
X	if (!CreateListofFiles(tmp,listOfFiles,&numFiles)){
X		gr_DialogSetValue(dir_dialog_widget,directory);
X		return; /* couldn't open directory */
X		}
X	strcpy(directory,tmp);
X
X	gr_DialogSetValue(cfile_dialog,"");
X	
X	SetVPortVertScrollBar(file_list_vport_widget,0);
X	XSync(myDpy,False);
X
X	XtListChange(file_list_widget,listOfFiles,numFiles,0,True);
X
X	SetVPortVertScrollBar(file_list_vport_widget,0);
X
X	XtMoveWidget(file_list_widget,0,0);
X
X/*
X	XtScrollBarSetThumb(
X		((ViewportWidget) file_list_vport_widget)->viewport.vert_bar,
X		0,0);
X*/
X	
X} /* CBChangeDirectory() */
X
X
X
X
X
Xstatic void CBUpDir(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar    tmp[MAXPATHLEN];
Xchar	*p;
Xchar	done;
X
X	strcpy(tmp,XtDialogGetValueString(dir_dialog_widget));
X
X	p = &(tmp[strlen(tmp)-1]);
X	done = FALSE;
X	while((p > tmp)&&(!done)) {
X		if (*p == '/') {
X			done = TRUE;
X			*p = '\0';
X			}
X		else
X			p--;
X		}
X
X	if (p <= tmp) 
X		strcpy(tmp,"/");
X	
X	strcpy(directory,tmp);
X
X	gr_DialogSetValue(dir_dialog_widget,directory);
X
X	CBChangeDirectory(w,TRUE,0);
X
X} /* CBUpDir() */
X
X
X
X
Xvoid ETDirReturn(w, event, params, num_params)
XWidget w;
XXEvent *event;
XString *params;
Xint num_params;
X{
X	CBChangeDirectory(w,NULL,NULL);
X	
X}
X
X
X	
X
Xvoid CBChoseFile(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar path[MAXPATHLEN];
Xstruct stat fileStat;
X
X#ifndef XtSpecificationRelease
X/* previous to R4 */
X	strcpy (fileChosen,((XtListReturnStruct *)call_data)->string);
X#else
X	strcpy (fileChosen,((XawListReturnStruct *)call_data)->string);
X#endif
X
X	if (!strcmp(directory,"/"))
X		sprintf(path,"/%s",fileChosen);
X	else
X		sprintf(path,"%s/%s",directory,fileChosen);
X	stat(path,&fileStat);
X	if (fileStat.st_mode & S_IFDIR) {
X		path[strlen(path)-1]='\0';
X		strcpy(directory,path);
X		gr_DialogSetValue(dir_dialog_widget,directory);
X		CBChangeDirectory(w,(caddr_t) TRUE,(caddr_t) NULL);
X		return;
X		}
X		
X	
X	aFileHasBeenChosen = TRUE;
X	gr_DialogSetValue(cfile_dialog,fileChosen);
X
X/*	sprintf(buff,"Just chose file %s/%s\n",directory,fileChosen);
X	PrintMesg(buff);
X*/
X}
X
Xstatic void CBOk(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	/* return values */
X	thisFile->xdim = atoi(XtDialogGetValueString(xDimDialog));
X	thisFile->ydim = atoi(XtDialogGetValueString(yDimDialog));
X
X	CloseFileWidget();
X
X
X	thisFile->yesfile(thisFile->param);
X}
X
X
Xvoid CBOpen(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar buff[256];
Xchar firstFile[512];
X
X#ifndef XtSpecificationRelease
X/* previous to R4 */
X	cfilename = XtDialogGetValueString(cfile_dialog);
X#else
X	cfilename = XawDialogGetValueString(cfile_dialog);
X#endif
X	if (!cfilename[0]) {
X		PrintMesg("Please select a file\n");
X		return;
X		}
X
X	thisFile->base = (char *) XIMalloc(strlen(cfilename)+1);
X	sprintf(thisFile->base,cfilename);
X
X	thisFile->directory = (char *) XIMalloc(strlen(directory)+1);
X	sprintf(thisFile->directory,directory);
X
X	if (!Glob(directory,cfilename,&(thisFile->numFiles),
X				&(thisFile->file))){
X		sprintf(buff,"Can't open directory %s\n",directory);
X		PrintMesg(buff);
X		return;
X		}
X	
X	sprintf(firstFile,"%s/%s",thisFile->directory,*(thisFile->file));
X
X	if (! DoesFileExist(firstFile)){
X		sprintf(buff,"Can't open file %s\n",firstFile);
X		PrintMesg(buff);
X		return;
X		}
X
X	if (thisFile->numFiles > 1)
X		sprintf(buff,"Selected files %s/%s\n",thisFile->directory,
X						thisFile->base);
X	else
X		sprintf(buff,"Selected file %s\n",firstFile);
X	PrintMesg(buff);
X
X	if (thisFile->type == FTYPE_IMAGE) {
X	    /* if fileChosen is HDF */
X	    if (IsItHDF(firstFile,&(thisFile->xdim),&(thisFile->ydim),
X			&(thisFile->isFloat))){
X		thisFile->isHDF = TRUE;
X		CloseFileWidget();
X		thisFile->yesfile(thisFile->param);
X
X		}
X	    else {
X		thisFile->isHDF = FALSE;
X		PrintMesg("Please Type in the dimensions of the image\n");
X		xDimDialog = Make_Dialog("GetXDimension",inputBox,
X					"Width of Image:","",4,
X					2,2,XDIM-170,50);
X		DialogAddTrans(xDimDialog,JumpToYDimDialog);
X
X		yDimDialog = Make_Dialog("GetYDimension",inputBox,
X					"Height of Image:","",4,
X					2,55,XDIM-170,50);
X		DialogAddTrans(yDimDialog,JumpToOk);
X		MakeButton("         OK         ",inputBox,2,108,CBOk,
X				NULL,0,0);
X		{
X		XWindowAttributes winAttrib;
X		Window root, child;
X		int     root_x,root_y;
X		int     win_x,win_y; 
X		unsigned int    keys_buttons;
X		int     win;
X		
X			win = XtWindow(topFileWidget);
X		
X			if (!XGetWindowAttributes(myDpy,win,&winAttrib)){
X				PrintMesg("returning at GetWindow Attrib\n");
X						return;
X				}
X       			if (XQueryPointer(myDpy,win,&root,&child,
X                		&root_x,&root_y,&win_x,&win_y,&keys_buttons)){
X				XWarpPointer(myDpy,win,win,win_x,win_y,
X				winAttrib.width,winAttrib.height,260,210);
X                		}
X		}
X
X
X
X
X		}
X	    }
X	else { /*Else it's a FTYPE_PAL */
X		CloseFileWidget();
X		thisFile->isHDF = FALSE;
X		if (DFishdf(firstFile) == 0)
X			thisFile->isHDF = TRUE;
X		thisFile->yesfile(thisFile->param);
X		}
X}
X
Xvoid ETRetOpen(w, event, params, num_params)
XWidget w;
XXEvent *event;
XString *params;
Xint num_params;
X{
X	CBOpen(w,NULL,NULL);
X}
X
X
Xvoid ETJumpToYDimDialog(w, event, params, num_params)
X/* Warp pointer from GetXDimension Dialog to GetYDimenion Dialog */
XWidget w;
XXEvent *event;
XString *params;
Xint num_params;
X{
XXWindowAttributes winAttrib;
XWindow root, child;
Xint     root_x,root_y;  /* X & Y coordinates with respect to root */
Xint     win_x,win_y;    /* X & Y coordinates with respect to window */
Xunsigned int    keys_buttons;
Xint     win;
X
X	win = XtWindow(topFileWidget);
X
X	if (!XGetWindowAttributes(myDpy,win,&winAttrib)){
X		PrintMesg("returning at GetWindow Attrib\n");
X		return;
X		}
X
X       if (XQueryPointer(myDpy,win,&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X
X		XWarpPointer(myDpy,win,win,win_x,win_y,
X			winAttrib.width,winAttrib.height,260,265);
X                }
X}
X
X
X
X
X
Xvoid ETJumpToOk(w, event, params, num_params)
XWidget w;
XXEvent *event;
XString *params;
Xint num_params;
X{
X	CBOk(w,NULL,NULL);
X}
X
END-of-getfile.c
echo file: glob.c
sed 's/^X//' >glob.c << 'END-of-glob.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xos.h>
X#include <X11/Intrinsic.h>
X#include "ximage.h"
X
X#if defined(SYSV) || defined(AIX)
X#include <dirent.h>
X#else
X#include <sys/dir.h>
X#include <sys/param.h>
X#endif
X
X
X#define MAXENTRY	1000
X#define	MALLOC		XIMalloc
X
X
Xstatic void BubbleSort(list,num)
Xchar *list[];
Xint num;
X{
Xchar *tmp;
Xint x,y;
X
X	for(x=1; x< num-1; x++)
X		for(y=num-1; y >= x; y--) 
X			if (strcmp(list[y-1],list[y]) > 0) {
X				tmp = list[y-1];
X				list[y-1] = list[y];
X				list[y] = tmp;
X				}
X	return;
X} /* BubbleSort() */
X
X
X
Xint Glob(dir,key,nargc,rargv)
X/* expand a wild card.  Can only handle an '*' at the end of filename*/
X/* didn't have time to write a decent globbing routine  :-) */
X/* RETURNS 0 if can't open directory */
X
Xchar	*dir;	  /*string containing directory name */
Xchar	*key;	/*search key('*' at end of filename is only wildcard excepted*/
Xint	*nargc;   /* RETURNED: number of matches found */
Xchar	***rargv; /* RETURNED: expanded file name strings */
X{
Xchar	**tmpargv;
Xchar	**nargv;
Xint	numFiles;
Xint	astPos;
Xint	x;
Xchar	*buff;	/* will contain space for list of files */
X
X#if defined(SYSV) || defined(AIX)
Xstruct dirent *fileEntry;
X#else
Xstruct direct *fileEntry;
X#endif
X
XDIR *newdirFD;
X
X
X
X
X	if (!(astPos=FindGlobChar(key))) {
X		/* no wild cards, so return key */
X		*nargc=1;
X		*rargv = (char **) MALLOC( sizeof(char *) );
X		buff = (char *) MALLOC(strlen(key)+1);
X		strcpy(buff,key);
X		**rargv = buff;
X		return(1);
X		}
X
X       if (!(newdirFD = opendir(dir))) {
X                printf("ximage.Glob():Can't open directory %s\n",dir);
X                return(NULL);
X                }
X
X	/* Find out how many entries */
X        numFiles = 0;
X        while ((fileEntry = readdir(newdirFD))&& (numFiles < MAXENTRY)) {
X                        if (fileEntry->d_name[0] != '.') {
X				numFiles++;
X			}
X		}
X	*nargc = numFiles;
X	tmpargv = nargv = (char **) MALLOC(*nargc * sizeof(char *));
X
X	/* Read in the file names and save the ones that match */
X	rewinddir(newdirFD);
X        numFiles = 0;
X        while ((fileEntry = readdir(newdirFD))&& (numFiles < MAXENTRY)) {
X		/* no files that start with a '.' */
X		if (fileEntry->d_name[0] != '.') {
X			if (!strncmp(fileEntry->d_name,key,astPos)) {
X				*tmpargv = MALLOC(strlen(fileEntry->d_name)+1);
X				strcpy(*tmpargv,fileEntry->d_name);
X				tmpargv++;
X				numFiles++;
X				}
X                	}
X		}
X        closedir(newdirFD);
X
X	*nargc = numFiles;  
X	BubbleSort(nargv,*nargc);
X
X	*rargv = nargv;
X	return(1);
X
X} /* Glob() */
X
X
Xstatic int FindGlobChar(key)
X/* What character position is the '*' in the string? */
X/* return 0 if no '*' */
Xchar *key;
X{
Xregister int	count = 0;
X
X	for (count = 0;(*key)&&(*key != '*');key++,count++);
X
X
X	if (! *key)
X		return(0); /* no '*' found */
X
X	return(count);
X
X} /* FindGlobChar() */
X
END-of-glob.c
echo file: gr_xwi.c
sed 's/^X//' >gr_xwi.c << 'END-of-gr_xwi.c'
X/*
X * National Center for SuperComputing Applications, University of Illinois
X *
X * This NCSA software product is public domain software.  Permission
X * is hereby granted to do whatever you like with it. Should you wish
X * to make a contribution towards the production of this software, please
X * send us your comments about your experience with the software,  why
X * you liked or disliked it, how you use it, and most importantly, how it
X * helps your work. We will receive your comments at softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Eng-Whatt Toh, National Center for Supercomputing Applications
X *         ewtoh@ncsa.uiuc.edu
X */
X
X/*
X *	File:		gr_xwi.c
X *	Contents:	Manipulation functions for X widgets
X *	The functions defined are specific to X-windows Athena and HP widget
X *	sets.  Some of them actually goes into the internals of the widgets
X *	to gain capabilities that the widgets would not otherwise have.
X */
X
X#include "gr_com.h"
X#include "gr_xwi.h"
X#include <X11/IntrinsicP.h>
X
X#ifdef XtSpecificationRelease
X#include <X11/Xaw/BoxP.h>
X#include <X11/Xaw/DialogP.h>
X#include <X11/Xaw/ViewportP.h>
X#include <X11/Xw/XwP.h>
X#include <X11/Xw/ArrowP.h>
X#include <X11/Xw/ScrollBarP.h>
X#include <X11/Xw/BBoardP.h>
X#include <X11/Xw/SWindowP.h>
X#include <X11/Xw/ValuatorP.h>
X#else
X#include <X11/BoxP.h>
X#include <X11/DialogP.h>
X#include <X11/ViewportP.h>
X#include <Xw/XwP.h>
X#include <Xw/ArrowP.h>
X#include <Xw/ScrollBarP.h>
X#include <Xw/BBoardP.h>
X#include <Xw/SWindowP.h>
X#include <Xw/ValuatorP.h>
X#endif
X
X/*
X *	Attempt to get a PseudoColor 8-plane visual if possible
X */
XVisual
X*gr_GetVisual(dpy,scr)
XDisplay	*dpy;
Xint		scr;
X{
X	XVisualInfo	vinfo;
X
X	if (XMatchVisualInfo(dpy,scr,(int)8,PseudoColor,&vinfo))
X		return(vinfo.visual);
X	else
X		return(DefaultVisual(dpy,scr));
X}
X
X/*
X * Turn a widget On or Off
X */
Xvoid
Xgr_WidgetSensitive(wid,sen)
XWidget wid;
XBoolean sen;
X{
X	XtSetArg(argList[0],XtNsensitive,sen);
X	XtSetValues(wid,argList,1);
X}
X
X
X/*
X * Turn a Button On or Off, mostly for HP toggles
X */
Xvoid
Xgr_ButtonSet(wid,isOn)
XWidget wid;
XBoolean isOn;
X{
X	XtSetArg(argList[0],XtNset,isOn);
X	XtSetValues(wid,argList,1);
X}
X
X
X/*
X * Change a cursor font for a shell window
X */
Xvoid
Xgr_WidgetCursor(wid,cursorfont)
XWidget wid;
Xint cursorfont;
X{
X	Cursor cursor;
X	Window win = XtWindow(wid);
X	Display *dpy = XtDisplay(wid);
X
X	if (win)
X	{
X		cursor = XCreateFontCursor(dpy,cursorfont);
X		XDefineCursor(dpy,win,cursor);
X		XFlush(dpy);
X	}
X
X	return;
X}
X
X
X/*
X * Change a cursor font for a special widget
X */
Xvoid
Xgr_WidgetCursor1(wid,cursorfont)
XWidget wid;
Xint cursorfont;
X{
X	Cursor cursor;
X	Display *dpy = XtDisplay(wid);
X
X	cursor = XCreateFontCursor(dpy,cursorfont);
X	XtSetArg(argList[0],XtNcursor,cursor);
X	XtSetValues(wid,argList,1);
X
X	return;
X}
X
X
X/*
X * Change the contents of an Athena list widget
X */
Xvoid
Xgr_ListChange(wid,list,nitems,longest,resize)
XWidget wid;
XString *list;
Xint nitems,longest;
XBoolean resize;
X{
X#ifdef XtSpecificationRelease
X	XawListHighlight(wid,0);
X	XawListChange(wid,list,nitems,longest,resize);
X	XawListHighlight(wid,0);
X#else
X	XtListHighlight(wid,0);
X	XtListChange(wid,list,nitems,longest,resize);
X	XtListHighlight(wid,0);
X#endif
X}
X
X
X/*
X * Highlight an entry in an Athena list widget
X */
Xvoid
Xgr_ListHighlight(wid,item)
XWidget wid;
Xint item;
X{
X#ifdef XtSpecificationRelease
X	XawListHighlight(wid,item);
X#else
X	XtListHighlight(wid,item);
X#endif
X}
X
X
X/*
X * Get the string and index of the selected list item in Athena list
X */
Xchar
X*gr_ListgetStruct(wid,ind)
XWidget wid;
Xint	   *ind;
X{
X#ifdef XtSpecificationRelease
X	XawListReturnStruct	*strngStruct;
X
X	strngStruct = XawListShowCurrent(wid);
X	*ind = strngStruct->list_index;
X	return(strngStruct->string);
X#else
X	XtListReturnStruct	*strngStruct;
X
X	strngStruct = XtListShowCurrent(wid);
X	*ind = strngStruct->index;
X	return(strngStruct->string);
X#endif
X}
X
X
X/*
X * Set insertion pointer in Athena text widget
X */
Xvoid
Xgr_TextSetInsertionPoint(wid,atPos)
XWidget wid;
Xlong   atPos;
X{
X#ifdef XtSpecificationRelease
X	XawTextSetInsertionPoint(wid,atPos);
X#else
X	XtTextSetInsertionPoint(wid,atPos);
X#endif
X}
X
X
X/*
X * Replace text in an Athena text widget
X */
Xvoid
Xgr_TextReplace(wid,startPos,endPos,strng)
XWidget wid;
Xchar *strng;
Xlong startPos,endPos;
X{
X#ifdef XtSpecificationRelease
X	XawTextBlock	text;
X#else
X	XtTextBlock	text;
X#endif
X
X	text.firstPos = 0;
X	text.length = strlen(strng);
X	text.ptr = strng;
X	text.format = FMT8BIT;
X
X#ifdef XtSpecificationRelease
X	XawTextReplace(wid,startPos,endPos,&text);
X#else
X	XtTextReplace(wid,startPos,endPos,&text);
X#endif
X}
X
X
X/*
X * Get internal Athena text widget from Athena dialog widget
X */
XWidget
Xgr_DialogGetTextWind(w)
XWidget w;
X{
X	return (((DialogWidget)w)->dialog.valueW);
X}
X
X
X/*
X * Get string from Athena dialog widget
X */
Xchar
X*gr_DialogGetValue(wid)
XWidget wid;
X{
X#ifdef XtSpecificationRelease
X	return(XawDialogGetValueString(wid));
X#else
X	return(XtDialogGetValueString(wid));
X#endif
X}
X
X
X/*
X * Set string in Athena dialog widget
X */
Xvoid
Xgr_DialogSetValue(wid,strng)
XWidget wid;
Xchar *strng;
X{
X	Widget textWid;
X	String oldStrng;
X
X	textWid = ((DialogWidget)wid)->dialog.valueW;
X#ifdef XtSpecificationRelease
X	oldStrng = gr_DialogGetValue(wid);
X#else
X	oldStrng = ((DialogWidget)wid)->dialog.value;
X#endif
X	gr_TextReplace(textWid,0,strlen(oldStrng),strng);
X	gr_TextSetInsertionPoint(textWid,strlen(strng));
X}
X
X
X/*
X * Set label string in Athena Label/Command widget
X */
Xvoid
Xgr_LabelSetValue(wid,strng)
XWidget wid;
Xchar *strng;
X{
X	XtSetArg(argList[0],XtNlabel,strng);
X	XtSetValues(wid,argList,1);
X}
X
X
X/*
X * Set image for HP static raster image
X */
Xvoid
Xgr_StaticRasterSetImage(wid,image)
XWidget wid;
XXImage *image;
X{
X	XtSetArg(argList[0],XtNsRimage,image);
X	XtSetValues(wid,argList,1);
X}
X
X
X/*
X * Set slider origin in HP valuator widget
X */
Xvoid
Xgr_SliderSetValue(wid,pos)
XWidget wid;
Xint	   pos;
X{
X	XtSetArg(argList[0],XtNsliderOrigin,pos);
X	XtSetValues(wid,argList,1);
X}
X
X
X/*
X * Get slider origin in HP valuator widget
X */
Xint
Xgr_SliderGetValue(wid)
XWidget wid;
X{
X	int pos;
X
X	XtSetArg(argList[0],XtNsliderOrigin,&pos);
X	XtGetValues(wid,argList,1);
X	return(pos);
X}
X
X
X/*
X * Move child widget in HP scrolled window widget
X * This function is called to translate the position of the child in
X * a scrolledWindowWidget so that the point (xpos,ypos) of the child
X * is centered in the scrolled window of size: xsize by ysize.
X * The actual resulting coordinates of the translation is returned in
X * (xpos,ypos).  They may then be used to update other children based 
X * on the same horizontal and vertical slider values as needed.
X*/
Xvoid
Xgr_VPortMoveChild(w,xpos,ypos,xsize,ysize)
XWidget w;
Xint	   *xpos,*ypos,xsize,ysize;
X{
X	XwSWindowWidget		 sw = (XwSWindowWidget)w;
X	XwScrollBarWidget	 vscroll,hscroll;
X	Widget	 child;
X	int		 vnewPos,hnewPos,vorg,horg;
X	int		 vmin,vmax,vext,vsize;
X	int		 hmin,hmax,hext,hsize;
X
X	vscroll = sw->swindow.vScrollBar;
X	hscroll = sw->swindow.hScrollBar;
X	child  = sw->swindow.bbChild;
X
X	/* Calculate the new vertical (y) position of the child */
X	if (vscroll != NULL)
X	{
X		vmin = sw->swindow.vmin;
X		vmax = sw->swindow.vmax;
X		vext = sw->swindow.vExtent;
X		vorg = sw->swindow.vOrigin;
X		vsize = vmax - vmin;
X		vnewPos = ((float)*ypos/(float)ysize)*(float)vsize;
X		if ((vnewPos < vorg+10) ||
X			(vnewPos > (vorg+vext-10)))
X		{
X			vnewPos = vnewPos - (float)((float)vext/(float)2.0);
X			if (vnewPos < vmin)
X				vnewPos = vmin;
X			else
X			if (vnewPos > (vmax-vext-1))
X				vnewPos = vmax-vext-1;
X			sw->swindow.vOrigin = vnewPos;
X			gr_SliderSetValue((Widget)vscroll,vnewPos);
X		}
X		else
X			vnewPos = vorg;
X	}
X
X	/* Calculate the new horizontal (x) position of the child */
X	if (hscroll != NULL)
X	{
X		hmin = sw->swindow.hmin;
X		hmax = sw->swindow.hmax;
X		hext = sw->swindow.hExtent;
X		horg = sw->swindow.hOrigin;
X		hsize = hmax - hmin;
X		hnewPos = ((float)*xpos/(float)xsize)*(float)hsize;
X		if ((hnewPos < horg+10) ||
X			(hnewPos > (horg+hext-10)))
X		{
X			hnewPos = hnewPos - (float)((float)hext/(float)2.0);
X			if (hnewPos<hmin)
X				hnewPos = hmin;
X			else
X			if (hnewPos>(hmax-hext-1))
X				hnewPos = hmax-hext-1;
X			sw->swindow.hOrigin = hnewPos;
X			gr_SliderSetValue((Widget)hscroll,hnewPos);
X		}
X		else
X			hnewPos = horg;
X	}
X
X	/* Translate child in the scrolledWindow viewport */
X	if ((vscroll != NULL) && (hscroll != NULL) && (child != NULL))
X	{
X		*xpos = hnewPos;
X		*ypos = vnewPos;
X		XtMoveWidget(child,(Position)-hnewPos,(Position)-vnewPos);
X	}
X}
X
X
X/*
X * This function moves the first child of a box widget horizontally
X * in the box to effect a horizontal scroll on the contents of the
X * box.
X */
Xvoid
Xgr_VPortHoriMove(w,newpos)
XWidget w;
Xint	   newpos;
X{
X	BoxWidget	bbw = (BoxWidget)w;
X	register Widget	child = bbw->composite.children[0];
X	int		 pos;
X
X	pos = newpos + 1;
X	if (pos < 1)
X		pos = 1;
X	else
X	if (pos > child->core.width)
X		pos = child->core.width;
X	child->core.x = pos;
X
X	XtMoveWidget(child, (Position)-pos, (Position)child->core.y);
X}
X
X
X/*
X * This function moves the first child of a box widget vertically
X * in the box to effect a vertical scroll on the contents of the
X * box.
X */
Xvoid
Xgr_VPortVertMove(w,newpos)
XWidget w;
Xint	   newpos;
X{
X	BoxWidget	bbw = (BoxWidget)w;
X	register Widget	child = bbw->composite.children[0];
X	int		 pos;
X
X	pos	= newpos + 1;
X	if (pos < 1)
X		pos = 1;
X	else
X	if (pos > child->core.height)
X		pos = child->core.height;
X	child->core.y = pos;
X
X	XtMoveWidget(child, (Position)child->core.x, (Position)-pos);
X}
X
X
X/*
X *	Override existing key translations for text Widget in Dialog Widget.
X */
Xvoid
Xgr_DialogAddTrans(wid,trans)
XWidget wid;
Xchar   *trans;
X{
X	XtTranslations	trans_table;
X	Widget			textWid=gr_DialogGetTextWind(wid);
X
X	trans_table = XtParseTranslationTable(trans);
X
X	XtOverrideTranslations(textWid,trans_table);
X}
END-of-gr_xwi.c
echo file: graph.c
sed 's/^X//' >graph.c << 'END-of-graph.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h> 
X#include <X11/Intrinsic.h> 
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#include "ximage.h"
X#include "i.h"
X#include "xstuff.h"
X
X#define	HISTO_HEIGHT	200
X#define	HISTO_WIDTH	256
X#define MAXNUMCONTLEVELS 50
X#define	NUM_REDRAW_REGIONS	4		/* sqrt(# redraw regions) */
X
Xextern	Widget	toplevelform;
Xextern  unsigned long   black,white;
Xextern	void	CBCtrlContourBox();
Xextern	void	Updt_Contour();
Xextern	void	Updt_Shaded();
Xextern	void	Updt_Intensity();
Xextern	void	SetColormap();
Xextern	void	DoProfile();
Xextern	void	CBDoneProfile();
Xextern	void 	ContourLine();
Xextern	Display	*myDpy;
X
Xvoid CBDoneHistogram();
Xvoid CBHistogram();
X
XCBDoneGraphBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	XtDestroyWidget((Widget) client_data);
X}
X
X
XCBDoneContourBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X	i->gcws.amIShowing = FALSE;
X	XtDestroyWidget(i->gcws.toplevel);
X} 
X
Xvoid  CBNewContourExpose(w,client_data,call_data)
X/* Draw the contour in parts of the window that is exposed */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X	i = (struct IMAGE *) client_data;
X        if (i->gcws.amIShowing) {
X                XPutImage(myDpy,XtWindow(i->gcws.box3),i->gcws.box3gc,
X                        i->gcws.pdata5,0,0,0,0,i->xdim,i->ydim);
X                }
X
X}
X
Xvoid CBContourExpose(w,client_data,call_data)
X/* Draw the contour in parts of the window that is exposed */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
XRegion	region;
Xint	x,y;
Xint	xrdim,yrdim;	/* dimension of those rectanagles */
Xint	overlap;
Xint 	pdim,prdim;
X
X	i = (struct IMAGE *) client_data;
X	region  = (Region) call_data;
X	
X	if (i->gcws.data1) { /* plot contour */
X	    xrdim=i->xdim/NUM_REDRAW_REGIONS;
X	    yrdim=i->ydim/NUM_REDRAW_REGIONS;
X
X	    for (y=0; y < i->ydim ; y+=yrdim) 
X		for (x=0; x < i->xdim; x+=xrdim) {
X			overlap = XRectInRegion(region,x,y,xrdim,yrdim);
X			if ((overlap==RectangleIn)||(overlap==RectanglePart)){
X				Updt_Contour(i->gcws.box3,i->ri,
X					i->contourLevels,i->xdim,i->ydim,
X					x,y,x+xrdim,y+yrdim,
X					black,white);
X				}
X			}
X		}
X	else { /* plot polar */
X	    pdim = i->ydim << 1;
X	    prdim = pdim / NUM_REDRAW_REGIONS;
X	    for (y=0; y < pdim ; y+=prdim) 
X		for (x=0; x < pdim; x+=prdim) {
X			overlap = XRectInRegion(region,x,y,prdim,prdim);
X			if ((overlap==RectangleIn)||(overlap==RectanglePart))
X				Updt_Contour(i->gcws.box3,i->polarimage,
X					i->contourLevels,pdim,pdim,
X					x,y,x+prdim,y+prdim,
X					black,white);
X			} /*for x*/
X	    } /*else*/
X
X} /* CBContourExpose() */
X
X
Xvoid DoNewContour(i,data,contourImage,contourLevels,xdim,ydim)
Xstruct IMAGE *i;
Xunsigned char *data;
Xunsigned char *contourImage;
Xunsigned char contourLevels[];
Xint	xdim,ydim;
X{
Xregister int x;
Xregister unsigned char *p;
Xunsigned char 	whitePixel;
Xint	length;
X
X	
X	whitePixel = (unsigned char) white;
X	length=xdim*ydim;
X	for (x=0, p=contourImage; x < length; x++,p++)
X		*p= whitePixel;
X
X	if (i->gcws.data1)	/* Color Contour */
X		for (x=1;x< (contourLevels[0]+1); x++) 
X			ContourLine(data,contourImage,contourLevels[x],
X				contourLevels[x],xdim,ydim);
X	else
X		for (x=1;x< (contourLevels[0]+1); x++) 
X			ContourLine(data,contourImage,contourLevels[x],
X				black,xdim,ydim);
X				
X
X
X}
X
X
X
X
X
X
X
X
X
Xvoid CBContour(w,client_data,call_data)
X/* Make Box for contour to be drawn in */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint xpos,ypos;
Xstruct IMAGE *i;
Xint xdim,ydim;
XXGCValues gcvals;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->gcws.amIShowing) {
X		PrintMesg("Contour graph already displayed.\n");
X		XRaiseWindow(myDpy,XtWindow(i->gcws.toplevel));
X		return;
X		}
X
X	if (i->plotSepWindow) {
X
X		if (!(i->plotCartesian)) {
X			if (!i->polarimage) {
X				PrintMesg("Please calculate polar first\n");
X				return;
X				}
X			xdim = ydim = i->ydim * 2;
X			}
X		else {
X			xdim = i->xdim;
X			ydim = i->ydim;
X			}
X		PlaceWindow(&xpos,&ypos);
X		i = (struct IMAGE *) client_data;
X		i->gcws.toplevel = MakeATopLevel(
X				"X Image [Image.Graph.Contour]",
X				toplevelform,xpos,ypos,xdim+10,ydim+45);
X		i->gcws.composite = Make_Board(i->name,i->gcws.toplevel,0,0,
X				xdim+50,ydim+50);
X		i->gcws.box1 =Make_ButtonBox(i->gcws.composite,5,5,xdim-50,25);
X		i->gcws.label = Make_Label(i->label,i->gcws.box1,2,2,30);
X		i->gcws.title = Make_Label(i->name,i->gcws.box1,33,2,xdim-85);
X
X		i->gcws.box3 = MakeWorkSpace("contour",i->gcws.composite,5,35,
X				xdim,ydim,
X				CBNewContourExpose,i,
X				NULL,NULL);
X
X		(void) MakeButton("Done",i->gcws.composite,xdim-40,6,
X				CBDoneContourBox,i,0,0);
X/*****/
X		/* i->gcws.pdata6 contains contour image */
X		if (!(i->gcws.pdata6 = XIMalloc(i->xdim*i->ydim))) {
X			PrintMesg("Malloc for contour failed\n");
X			return;
X			}
X		/* i->gcws.pdata5 contains XImage * of pdata6 */
X		i->gcws.pdata5 = (char *) XCreateImage(myDpy,
X					GetVisual(myDpy),
X					8,ZPixmap,0,i->gcws.pdata6,
X					i->xdim,i->ydim,8,i->xdim);
X		gcvals.foreground = black;
X		gcvals.background = white;
X		i->gcws.box3gc = XtGetGC(i->gcws.box3,
X				GCForeground| GCBackground, &gcvals);
X/******** Note this is only for 8 bit pseudoe at the moment */
X		DoNewContour(i,i->ri,i->gcws.pdata6,i->contourLevels,
X				i->xdim,i->ydim);
X/*****/
X		SetColormap(i->gcws.toplevel,i->iws.cmap);
X
X
X		i->gcws.data1 = i->plotCartesian;  
X
X		}
X	i->gcws.amIShowing = TRUE;
X
X} /* CBContour() */
X
Xvoid CBShadeExpose(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
XRegion	region;
Xint	x,y;
Xint	xrdim,yrdim;	/* dimension of those rectanagles */
Xint	overlap;
Xint 	pdim,prdim;
X
X	i = (struct IMAGE *) client_data;
X	region  = (Region) call_data;
X	
X	if (i->gsws.data1) { /* plot shade */
X	    xrdim=i->xdim/NUM_REDRAW_REGIONS;
X	    yrdim=i->ydim/NUM_REDRAW_REGIONS;
X
X	    for (y=0; y < i->ydim ; y+=yrdim) 
X		for (x=0; x < i->xdim; x+=xrdim) {
X			overlap = XRectInRegion(region,x,y,xrdim,yrdim);
X			if ((overlap==RectangleIn)||(overlap==RectanglePart)){
X				Updt_Shaded(i->gsws.box3,i->ri,
X					i->xdim,i->ydim,
X					x,y,x+xrdim,y+yrdim);
X				}
X			}
X		}
X	else { /* plot polar */
X	    pdim = i->ydim << 1;
X	    prdim = pdim / NUM_REDRAW_REGIONS;
X	    for (y=0; y < pdim ; y+=prdim) 
X		for (x=0; x < pdim; x+=prdim) {
X			overlap = XRectInRegion(region,x,y,prdim,prdim);
X			if ((overlap==RectangleIn)||(overlap==RectanglePart))
X				Updt_Shaded(i->gsws.box3,i->polarimage,
X					pdim,pdim,
X					x,y,x+prdim,y+prdim);
X			} /*for x*/
X	    } /*else*/
X
X} /* CBShadeExpose() */
X
X
XCBDoneShadeBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X	i->gsws.amIShowing = FALSE;
X	XtDestroyWidget(i->gsws.toplevel);
X} 
X
Xvoid CBShade(w,client_data,call_data)
X/* Make Box for contour to be drawn in */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint xpos,ypos;
Xstruct IMAGE *i;
Xint xdim,ydim;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->gsws.amIShowing) {
X		PrintMesg("Shade graph already displayed.\n");
X		XRaiseWindow(myDpy,XtWindow(i->gsws.toplevel));
X		return;
X		}
X
X	if (i->plotSepWindow) {
X
X		if (!(i->plotCartesian)) {
X			if (!i->polarimage) {
X				PrintMesg("Please calculate polar first\n");
X				return;
X				}
X			xdim = ydim = i->ydim * 2;
X			}
X		else {
X			xdim = i->xdim;
X			ydim = i->ydim;
X			}
X		PlaceWindow(&xpos,&ypos);
X		i = (struct IMAGE *) client_data;
X		i->gsws.toplevel = MakeATopLevel(
X				"X Image [Image.Graph.Shade]",
X				toplevelform,xpos,ypos,xdim+10,ydim+45);
X		i->gsws.composite = Make_Board(i->name,i->gsws.toplevel,0,0,
X				xdim+50,ydim+50);
X		i->gsws.box1 =Make_ButtonBox(i->gsws.composite,5,5,xdim-50,25);
X		i->gsws.label = Make_Label(i->label,i->gsws.box1,2,2,30);
X		i->gsws.title = Make_Label(i->name,i->gsws.box1,33,2,xdim-85);
X
X		i->gsws.box3 = MakeWorkSpace("shade",i->gsws.composite,5,35,
X				xdim,ydim,
X				CBShadeExpose,i,
X				NULL,NULL);
X
X		(void) MakeButton("Done",i->gsws.composite,xdim-40,6,
X				CBDoneShadeBox,i,0,0);
X
X		i->gsws.data1 = i->plotCartesian;  
X
X		i->gsws.amIShowing = TRUE;
X		}
X
X	 /* plot shade in same window */
X/*
X	else {
X		if (i->plotCartestian) {
X			Updt_Shaded(i->iws.box3,i->ri,
X				i->xdim,i->ydim,
X				0,0,i->xdim,i->ydim);
X		else
X			Updt_Shaded(i->pws.box3,i->polarimage,
X				i->ydim*2,i->ydim*2,
X				0,0,i->ydim*2,i->ydim*2);
X		}
X*/
X} /* CBShade */
X
X
Xvoid CBIntensity(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint xpos,ypos;
Xstruct IMAGE *i;
Xint xdim,ydim;
X
X	i = (struct IMAGE *) client_data;
X
X
X	if (i->plotSepWindow) {
X
X		if (!(i->plotCartesian))
X			xdim = ydim = i->ydim * 2;
X		else {
X			xdim = i->xdim;
X			ydim = i->ydim;
X			}
X		PlaceWindow(&xpos,&ypos);
X		i = (struct IMAGE *) client_data;
X		i->gsws.toplevel = MakeATopLevel(
X				"X Image [Image.Graph.Intensity]",
X				toplevelform,xpos,ypos,xdim+50,ydim+50);
X		i->gsws.composite = Make_Board(i->name,i->gsws.toplevel,0,0,
X				xdim+50,ydim+50);
X		i->gsws.box1 = Make_ButtonBox(i->gsws.composite,5,5,250,25);
X		i->gsws.label =  Make_Label(i->label,i->gsws.box1,2,2,30);
X		i->gsws.title = Make_Label(i->name,i->gsws.box1,33,2,215);
X
X		i->gsws.box3 = Make_ButtonBox(i->gsws.composite,5,35,
X				xdim,ydim);
X
X		(void) MakeButton("Done",i->gsws.composite,260,6,CBDoneGraphBox,
X				i->gsws.toplevel,0,0);
X
X		/* Should Actually wait for window to appear */
X		XSync(XtDisplay(i->gsws.box3),False);
X
X		if (i->plotCartesian)
X			Updt_Intensity(i->gsws.box3,i->ri,i->xdim,i->ydim,
X						black,FALSE);
X		else {
X			if (i->polarimage)
X				Updt_Intensity(i->gsws.box3,i->polarimage,
X						i->ydim*2,i->ydim*2,
X						black,FALSE);
X			else {
X				PrintMesg("Please calculate polar first\n");
X				return;
X				}
X			}
X		}
X	else {
X		if (i->plotCartesian) {
X			if (i->iws.amIShowing)
X			 	Updt_Intensity(i->iws.box3,i->ri,i->xdim,
X						i->ydim,0,TRUE);
X			else {
X				PrintMesg("Cartesian Image not Showing\n");
X				return;
X				}
X			}
X		else {
X			if (i->pws.amIShowing) {
X				Updt_Intensity(i->pws.box3,i->polarimage,
X						i->ydim*2,i->ydim*2,
X						0,TRUE);
X				}
X			else {
X				PrintMesg("Polar Image not Showing\n");
X				return;
X				}
X			} /*else*/
X		} /*else*/
X}
X
X
X
XCBPlotWhichDataSet(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X
X	i = (struct IMAGE *)client_data;
X
X	i->plotCartesian = ! i->plotCartesian;
X
X	SetToggle(w,True);
X	if (i->plotCartesian)
X		SetToggleString(w,"Plot Cartesian");
X	else
X		SetToggleString(w,"Plot Polar");
X		
X}
X
Xvoid CBPlotInWhichWindow(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X
X	i = (struct IMAGE *)client_data;
X	i->plotSepWindow = ! i->plotSepWindow;
X	SetToggle(w,True);
X	if (i->plotSepWindow)
X		SetToggleString(w,"Plot in Separate Window");
X	else
X		SetToggleString(w,"Overlay Graph in Image Window");
X}
X
X
Xvoid CBDoneGraphControlBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X	i = (struct IMAGE *) client_data;
X
X	if (i->gcws.amIShowing)
X		CBDoneContourBox(w,(caddr_t) i,(caddr_t) 0);
X	if (i->gsws.amIShowing)
X		CBDoneShadeBox(w,(caddr_t) i,(caddr_t) 0);
X	if (i->ghws.amIShowing)
X		CBDoneHistogram(w,(caddr_t) i,(caddr_t) 0);
X	if (i->gpws.amIShowing)
X		CBDoneProfile(w,(caddr_t) i,(caddr_t) 0);
X
X
X	XtDestroyWidget(i->gws.toplevel);
X	i->gws.amIShowing = FALSE;
X}
X
X
Xvoid CBGraphControlBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
Xint	xpos,ypos;
X
X	i = (struct IMAGE *) client_data;
X	
X	if (i->gws.amIShowing){
X		PrintMesg("Graph control window already showing\n");
X		XRaiseWindow(myDpy,XtWindow(i->gws.toplevel));
X		return;
X		}
X
X	PlaceWindow(&xpos,&ypos);
X	i->gws.toplevel = MakeATopLevel("X Image [Image.Graph]",
X				toplevelform,xpos,ypos,300,125);
X	Set_Pointer(i->gws.toplevel,XC_gumby);
X	i->gws.composite= Make_Board("Graph",i->gws.toplevel,0,0,300,125);
X
X	i->gws.box1 = Make_ButtonBox(i->gws.composite,5,5,250,25);
X	i->gws.label = Make_Label(i->label,i->gws.box1,2,2,30);
X	i->gws.title = Make_Label(i->name,i->gws.box1,33,2,215);
X
X	i->gws.box2 = Make_ButtonBox(i->gws.composite,5,35,290,50);
X	(void) MakeAltToggle("Plot Cartesian",i->gws.box2,5,5,
X			CBPlotWhichDataSet,i,CBPlotWhichDataSet,i,
X			False,False);
X/*	(void) MakeAltToggle("Plot in Separate Window",i->gws.box2,5,30,
X			CBPlotInWhichWindow,i,CBPlotInWhichWindow,i,
X			False,False);
X*/
X	
X	i->gws.box3 = Make_ButtonBox(i->gws.composite,5,90,290,25);
X	(void) MakeButton("Contour",i->gws.box3,5,2,CBCtrlContourBox,i,0,0);
X/*	(void) MakeButton("Intensity",i->gws.box3,000,2,CBIntensity,i,0,0);*/
X	(void) MakeButton("Shade",i->gws.box3,62,2,CBShade,i,0,0);
X/*	(void) MakeButton("3D",i->gws.box3,195,2,NULL,NULL,0,0);*/
X	(void) MakeButton("Profile",i->gws.box3,175,2,DoProfile,i,0,0);
X#ifdef DEBUG
X/**/ printf("CBGraphControlBox():i->name=%s\n",i->name);
X/**/ printf("CBGraphControlBox():i->xdim=%d,i->ydim=%d\n",i->xdim,i->ydim);
X#endif
X	(void) MakeButton("Histogram",i->gws.box3,107,2,CBHistogram,i,0,0);
X
X	(void) MakeButton("Done",i->gws.composite,260,6,
X				CBDoneGraphControlBox,i,0,0);
X
X	i->gws.amIShowing = TRUE;
X	return;
X
X} /* CBGraphControlBox() */
X
Xvoid CalculateHistogram(i)
Xstruct IMAGE *i;
X{
Xint	*h;
Xregister int	x,y;
Xint	x1,x2,y1,y2;
Xint	theend;
Xint	highest,highest2;
X
X	h = (int *) i->ghws.pdata;
X	for (x = 0; x < 256; x++)
X		h[x] = 0;
X
X	/* MakeHistogram */
X	if (i->plotCartesian) {
X		if ((i->iws.select == AREA) && 
X			(i->iws.selBegX|i->iws.selBegY|
X			i->iws.selEndX|i->iws.selEndY)) {
X			if (i->iws.selBegX < i->iws.selEndX) {
X				x1 = i->iws.selBegX;
X				x2 = i->iws.selEndX;
X				}
X			else {
X				x2 = i->iws.selBegX;
X				x1 = i->iws.selEndX;
X				}
X			if (i->iws.selBegY < i->iws.selEndY) {
X				y1 = i->iws.selBegY;
X				y2 = i->iws.selEndY;
X				}
X			else {
X				y2 = i->iws.selBegY;
X				y1 = i->iws.selEndY;
X				}
X			}
X		else {
X			x1 = y1 = 0;
X			x2 = i->xdim;
X			y2 = i->ydim;
X			}
X		for (y = y1; y < y2; y++) 
X			for (x = x1; x < x2; x++) {
X				(h[i->ri[y*i->xdim+x]])++;
X				}
X		i->ghws.data3 = (x2-x1) * (y2-y1); /* number of points */
X		}
X	else {
X		theend = (i->ydim << 1) * (i->ydim << 1);
X		for(x=0; x < theend; x++)
X			h[i->polarimage[x]] = h[i->polarimage[x]]+1;
X			/*(h[i->polarimage[x]])++;*/
X		i->ghws.data3 = i->xdim * i->ydim;
X		}
X
X	highest = h[0];
X	for (x=0; x < 256; x++)
X		if (h[x] > highest)
X			highest = h[x];
X
X	if  (highest == h[0])
X		highest2 = h[1];
X	else
X		highest2 = h[0];
X	for (x=1; x < 256; x++) {
X		if (h[x] > highest2)
X			if (highest != h[x])
X				highest2 = h[x];
X		}
X		
X		
X	i->ghws.data1 =highest;
X	i->ghws.data2 =highest2;
X
X} /* CalculateHistogram() */
X
X
X
Xvoid CBDoneHistogram(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X	i = (struct IMAGE *) client_data;
X
X	XtDestroyWidget(i->ghws.toplevel);
X	i->ghws.amIShowing = FALSE;
X}
X
Xvoid CBHistoRedraw(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
Xstatic	XGCValues	gcval;
Xint	height;
Xstruct IMAGE *i;
Xint	x;
Xint	*h;
X
X	i = (struct IMAGE *) client_data;
X	h = (int *)i->ghws.pdata;
X	dpy = XtDisplay(i->ghws.box3);
X        XSync(dpy,False);
X        win = XtWindow(i->ghws.box3);
X        gcval.foreground = black;
X        gcval.background = white;
X        gc = XtGetGC(i->ghws.box3,GCForeground | GCBackground, &gcval);
X
X	XClearArea(myDpy,win,0,0,0,0,False);
X	
X        for(x=0; x < 256; x++) {
X                XSetForeground(dpy,gc,x);
X                if (h[x] != i->ghws.data1) {
X                        height = (int)((((float) h[x])
X					/((float)i->ghws.data2))
X                                        *((float) HISTO_HEIGHT));
X/*	printf("data1=%d,data2=%d,h[x]=%d,height = %d\n",i->ghws.data1,
X			i->ghws.data2,h[x],height);
X*/
X
X                        XDrawLine(dpy,win,gc,x+5,HISTO_HEIGHT,x+5,
X                                        HISTO_HEIGHT-height);
X                        }
X		else 
X			XDrawLine(dpy,win,gc,x+5,HISTO_HEIGHT,x+5,0);
X                }
X}
X
X
Xvoid CBHistoUpdate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;
Xint     win_x,win_y;
Xunsigned int    keys_buttons;
Xstruct IMAGE *i;
Xchar	buff[80];
Xfloat	fnum;
Xint 	*h;
X
X	i = (struct IMAGE *) client_data;
X        if (XQueryPointer(XtDisplay(w),XtWindow(w),&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X                }
X
X	win_x = win_x - 5;
X	if ((win_x > 255) || ( win_x < 0))
X		return;
X	
X	if (i->isFloat) {
X		fnum = ((((float)win_x)/255.0)* (i->maxvalue - i->minvalue))
X			+ i->minvalue;
X		sprintf(buff,"%8.3f",fnum);
X		}
X	else
X		 sprintf(buff,"%d",win_x);
X
X
X	/* Data Value */
X	SetToggleString(i->ghws.box2,buff);
X
X	h = (int *)i->ghws.pdata;
X	sprintf(buff,"%8.5f",
X		((float)h[win_x])/((float)(i->ghws.data3))*100.0);
X	SetToggleString(i->ghws.box4,buff);
X
X}
X
X
X
Xvoid CBHistogram(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	*h;	/* an array containing frequency */
Xint 	x;
Xint	xpos,ypos;
Xint	theend;
Xint	highest;
Xint	highest2;
Xstruct IMAGE *i;
XWidget	box;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->ghws.amIShowing) {
X		PrintMesg("Histogram already displayed\n");
X		XRaiseWindow(myDpy,XtWindow(i->ghws.toplevel));
X		return;
X		}
X
X	PlaceWindow(&xpos,&ypos);
X
X	i->ghws.toplevel = MakeATopLevel("X Image [Image.Graph.Histogram]",
X			toplevelform,xpos,ypos,
X			HISTO_WIDTH+42,HISTO_HEIGHT+120);
X	SetColormap(i->ghws.toplevel,i->iws.cmap);
X	Set_Pointer(i->ghws.toplevel,XC_gumby);
X	i->ghws.composite = Make_Board(i->name,i->ghws.toplevel,0,0,
X			HISTO_WIDTH+42,HISTO_HEIGHT+120);
X	i->ghws.box1 = Make_ButtonBox(i->ghws.composite,5,5,250,25);
X	i->ghws.label = Make_Label(i->label,i->ghws.box1,2,2,30);
X	i->ghws.title = Make_Label(i->name,i->ghws.box1,33,2,215);
X
X/*	i->ghws.box3 = Make_ButtonBox(i->ghws.composite,5,35,
X			HISTO_WIDTH+10,HISTO_HEIGHT+10);
X*/
X	i->ghws.box3 = MakeWorkSpace("histo",i->ghws.composite,5,35,
X			HISTO_WIDTH+10,HISTO_HEIGHT+10,
X			CBHistoRedraw,i,NULL,NULL);
X	Set_Pointer(i->ghws.box3,XC_left_ptr);
X	box = Make_ButtonBox(i->ghws.composite,5,HISTO_HEIGHT+50,
X			HISTO_WIDTH+10,60);
X	(void) Make_Label("             Data Value:",box,5,5,HISTO_WIDTH/3*2);
X	(void) Make_Label("   Frequency Percentage:",box,5,30,HISTO_WIDTH/3*2);
X	i->ghws.box2=Make_Label("0",box,HISTO_WIDTH/3*2+10,5,HISTO_WIDTH/3-15);
X	i->ghws.box4=Make_Label("0",box,HISTO_WIDTH/3*2+10,30,HISTO_WIDTH/3-15);
X	
X	XtAddEventHandler(i->ghws.box3,PointerMotionMask,0,
X				CBHistoUpdate,i);
X
X	(void) MakeButton("Done",i->ghws.composite,
X			260,6,CBDoneHistogram,i,0,0);
X
X	if (!(h = (int *) XICalloc(256,sizeof(int)))){
X		PrintMesg("Can't allocate memory for Histogram\n");
X		return;
X		}
X	i->ghws.pdata = (char *) h;
X
X	CalculateHistogram(i);
X
X	i->ghws.amIShowing = TRUE;
X} /* CBHistogram() */
X
Xvoid UpdateHistogram(i)
Xstruct IMAGE *i;
X{
X        if (i->ghws.amIShowing) {
X                CalculateHistogram(i);
X                CBHistoRedraw(i->ghws.box3,i,0);
X                }
X}
X
Xvoid ReplotGraphs(i)
Xstruct IMAGE *i;
X{
X#ifdef DEBUG
X	printf("ReplotGraphs(): I've been called \n");
X
X#endif
X	/* Repolot Contours */
X
X	if (i->gcws.amIShowing) {
X		DoNewContour(i,i->ri,i->gcws.pdata6,i->contourLevels,
X       				i->xdim,i->ydim);
X		CBNewContourExpose(i->gcws.box3,i,0);
X		}
X
X	UpdateHistogram(i);
X
X	if (i->gpws.amIShowing) {
X		CBProfileExpose(i->gpws.box3,i,0);
X		}
X
X}
END-of-graph.c
echo file: i.c
sed 's/^X//' >i.c << 'END-of-i.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X
X#include "ximage.h"
X#include "i.h"
X
X#define	NIL	(struct IMAGE *) 0
X
X#ifndef NULL
X#define	NULL	0
X#endif
X
X#ifndef FALSE
X#define FALSE	0
X#endif
X
Xextern	void	CBCloseImageCtrlBox();
Xextern	struct IMAGE *regionSelected;
X
Xstatic	struct	IMAGE *headIMAGE = NIL;
Xstatic	struct	IMAGE *tailIMAGE = NIL;
X
Xstatic	char	deflabel = 'a';
X
Xstruct IMAGE *SearchByNameIMAGE(searchName)
X/* returns the first IMAGE structure that has the same name field */
X/* returns NIL if no match */
Xchar *searchName;
X{
Xstruct IMAGE *i;
X
X	i = headIMAGE;
X
X	while (i != NIL) {
X		if (!strcmp(searchName,i->name))
X			return(i);
X		else
X			i = i->next;
X		}
X	return(NIL);
X
X} /* SearchByNameIMAGE() */
X
Xstruct IMAGE *NewIMAGE()
X/* return NULL on failure */
X{
Xstruct	IMAGE *i;
X	if (i = (struct IMAGE *) XIMalloc(sizeof(struct IMAGE))) {
X
X#ifdef DEBUG
X/*
X		printf("PrintStatus: before NewIMAGE()\n");
X		fflush(stdout);
X		PrintStatus();
X*/
X#endif
X
X		i->name = (char *) NULL;
X		i->fname = (char *) NULL;
X		i->isHDF = FALSE;
X		i->xdim = 0;
X		i->ydim = 0;
X		i->label[0] = deflabel;
X		i->label[1] = '\0';
X		if ((++deflabel) > 'z') 
X			deflabel = 'a';
X
X		i->isFloat = FALSE;
X		i->fdataset = (float *) NULL;
X		i->maxvalue = 0;
X		i->minvalue = 0;
X		i->format = (char *) NULL;
X		i->fwidth = 0;
X
X		i->ri = NULL;
X		i->dExpRI= NULL;
X		i->isDExpRI = FALSE;
X		i->polarimage = NULL;
X		i->dExpPI= NULL;
X		i->isDExpPI = FALSE;
X
X		i->riExpand = NULL;
X		i->dExpRIExpand= NULL;
X		i->isDExpRIExpand = FALSE;
X
X		i->cimageExpand = i->cimage = i->pimage = (XImage *) NULL;
X
X		i->plotCartesian = TRUE;
X		i->plotSepWindow = TRUE;
X		i->cws.amIShowing = FALSE;
X		i->iws.amIShowing = FALSE;
X		i->pws.amIShowing = FALSE;
X		i->dws.amIShowing = FALSE;
X		i->gws.amIShowing = FALSE;
X		i->gcws.amIShowing = FALSE;
X		i->gpws.amIShowing = FALSE;
X		i->gsws.amIShowing = FALSE;
X		i->ghws.amIShowing = FALSE;
X		i->chaws.amIShowing = FALSE;
X		i->hasPalette = FALSE;
X		i->palette = (XColor *) NULL;
X		i->iws.select = POINT;
X		i->pws.select = POINT;
X
X		i->image_loaded = FALSE;
X		i->image_showing = FALSE;
X
X		i->notebook.hasNotebook = FALSE;
X		i->notebook.notebookUsed = FALSE;
X		i->notebook.notebookShowing = FALSE;
X
X		i->expand = FALSE;
X		i->expansionFactor = 1;
X		i->interpExpansion = FALSE;
X
X		i->next = NIL;
X		i->prev = NIL;
X
X		if (headIMAGE == NIL) 
X			tailIMAGE = headIMAGE = i;
X		else {
X			tailIMAGE->next = i;
X			i->prev = tailIMAGE;
X			tailIMAGE = i;
X			}
X		}
X	else { /* XIMalloc failed */
X		return(NULL);
X		}
X#ifdef DEBUG
X/*	printf("PrintStatus: after NewIMAGE()\n");
X	fflush(stdout);
X	PrintStatus();
X*/
X#endif
X
X	return(i);
X
X} /* NewIMAGE() */
X
XDestroyIMAGE(im)
Xstruct IMAGE *im;
X{
X#ifdef DEBUG
X/*	printf("PrintStatus: before DestroyIMAGE()\n");
X	fflush(stdout);
X	PrintStatus();
X*/
X#endif 
X
X	if (regionSelected == im)
X		regionSelected = NULL;
X	
X	if (im->prev) 
X		im->prev->next = im->next;
X	else 
X		headIMAGE = im->next;
X	if(im->next)
X		im->next->prev = im->prev;
X	else
X		tailIMAGE = im->prev;
X
X
X	if (im->cimage)
X		XDestroyImage(im->cimage);
X	if (im->pimage)
X		XDestroyImage(im->pimage);
X	if (im->ri)
X		XIFree(im->ri);
X	if (im->polarimage)
X		XIFree(im->polarimage);
X	if (im->name)
X		XIFree(im->name);
X
X	if (im->isDExpRI)
X		XIFree(im->dExpRI);
X	if (im->isDExpPI)
X		XIFree(im->dExpPI);
X
X	XIFree(im);
X
X#ifdef DEBUG
X/*	printf("PrintStatus: after DestroyIMAGE()\n");
X	fflush(stdout);
X	PrintStatus();
X*/
X#endif
X
X} /* DestroyIMAGE() */
X
X
Xvoid ReleaseAllImages()
X{
X	while(headIMAGE)
X		CBCloseImageCtrlBox(0,(caddr_t) headIMAGE,(caddr_t) 0);
X}
X
X#ifdef DEBUG
XPrintStatus()
X/* Print IMAGE list for debugging */
X{
Xstruct IMAGE *i;
X
X	printf("Printing image link\n");
X	fflush(stdout);
X
X	if (headIMAGE)
X		printf("headIMAGE = %s\n",headIMAGE->name);
X	else
X		printf("headIMAGE = NIL\n");
X	fflush(stdout);
X
X	if (tailIMAGE)
X		printf("tailIMAGE = %s\n",tailIMAGE->name);
X	else
X		printf("tailIMAGE = NIL\n");
X	fflush(stdout);
X
X	i = headIMAGE;
X	while(i != NIL){
X		if (i->prev) 
X			printf("%s<-",i->prev->name);
X		else
X			printf("NIL<- ");
X
X		printf("%s",i->name);
X
X		if (i->next)
X			printf("-> %s \n",i->next->name);
X		else
X			printf("-> NIL\n");
X
X		fflush(stdout);
X		i = i->next;
X		}
X
X	printf("*****done\n");
X}
X#endif
X
END-of-i.c
echo file: image.c
sed 's/^X//' >image.c << 'END-of-image.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <math.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#include "ximage.h"
X#include "buttons.h"
X#include "xstuff.h"
X#include "i.h"
X#include "getfile.h"
X
X#define PAL_WIDTH	50
X
X#define FillSelectionRectangle  0       /* True or False */
X#define CROSSHATCH_width 8
X#define CROSSHATCH_height 8
Xstatic char CROSSHATCH_bits[] = {
X   0xff, 0x83, 0x45, 0x29, 0x11, 0x29, 0x45, 0x83};
X
X
Xextern	Widget	toplevelform;
Xextern	unsigned long	black,white;
Xextern	XColor	rccells[];
Xextern	XColor	origccells[];
Xextern	XFontStruct *ximageFont;
Xextern	struct	IMAGE *NewIMAGE();
Xextern 	void	CBDisplayData();
Xextern	void	CBGraphControlBox();
Xextern	void	GetAFile();
Xextern	void	CBDoneData();
Xextern	void	CBDoneGraphControlBox();
Xextern	void	SelectPointFromImage();
Xextern	void	StoreColors();
Xextern	void	CBProfileExpose();
Xextern	void	CBDoneProfile();
Xextern	void	ReplotGraphs();
Xextern	void	UpdateDate();
Xextern	void	UpdateHistogram();
Xextern	void	CBNotebook();
Xextern	void	CBDoneNotebook();
Xextern	void	CBChangeAttrib();
X
Xstruct IMAGE	*regionSelected = NULL;
X
Xstatic	Display	*myDpy;	
Xstatic	Visual	*myVis;		
XXImage	*palXImage;
Xstatic  struct  GetFile imageFile;
Xstatic	struct	GetFile	palFile;
X/**/	struct IMAGE *ci;	/* left in for debugging (current image)*/
X
X
Xvoid DisplayImage();
Xvoid CBDoCart();
Xvoid CBDoPolar();
Xint  ReadInImage();
Xvoid CreateImageCtrlBox();
Xvoid CBUnInstallImageCMap();
Xvoid CBCloseCartImageBox();
Xvoid CBClosePolarImageBox();
X
X
X/**/ void CBTestShaded();
X
Xint InitImage(dpy)
XDisplay	*dpy;
X{
X
X	myDpy  = dpy;
X	myVis  = GetVisual(myDpy);
X
X	if (!(palXImage = MakePalette(myDpy,PAL_WIDTH,FALSE)))
X		return(0);
X
X	return(1); 
X
X} /* InitImage() */
X
Xvoid ExpandCharByPixelReplication(data,xdim,ydim,newRaster,expansionFactor,nbp)
X/* Will expand image to larger image.  Will do fractional expansion */
Xunsigned char *data; 	/* image data */
Xint	xdim,ydim;	/* dimensions of data */
Xunsigned char *newRaster; /* mem space big enough for expanded image */
Xfloat expansionFactor;  /* fractional expansion factor */
Xint nbp;		/* number of bytes per pixel */
X{
Xint	expansion;
Xregister int	x,y,z;
Xregister int	xExpand,yExpand;
Xregister float	fxExpand,fyExpand;
Xfloat	xleftOver,yleftOver,expFraction;
Xint	xoffset,yoffset;
X
X	expansion = (int) expansionFactor;
X
X	if (nbp <= 1) {
X	    if (expansionFactor == ((float) ((int)expansionFactor))) {
X		for (y = 0 ; y < ydim; y++)
X		    for(yExpand = 0; yExpand < expansion; yExpand ++)
X			for (x = 0; x < xdim; x++)
X			    for (xExpand = 0; xExpand < expansion; xExpand++){
X				*newRaster = data[xdim*y+x];
X				newRaster++;
X				}
X		}
X	    else {
X		expFraction = expansionFactor - (float) expansion;
X		yleftOver =0.0;
X		yoffset = 0;
X		for (y = 0 ; y < ydim; y++){
X		    yleftOver = yleftOver + expFraction;
X		    yoffset = (int) yleftOver;
X		    yleftOver = yleftOver - (float) yoffset;
X		    for(yExpand = 0.0; y < expansion +yoffset; yExpand ++) {
X			xleftOver = 0.0;
X			for (x = 0; x < xdim; x++){
X			    xleftOver = xleftOver + expFraction;
X			    xoffset = (int) xleftOver;
X			    xleftOver = xleftOver - (float) xoffset;
X
X			    for(xExpand=0;xExpand<expansion+xoffset;xExpand++){
X				*newRaster = data[xdim*y+x];
X				newRaster++;
X				}
X			    }
X			}
X		    }
X	    	} /*for y*/
X	    } /*else*/
X	else { /* nbp is > 1 */
X	    if (expansionFactor == ((float) ((int)expansionFactor))) {
X		for (y = 0 ; y < ydim; y++)
X		    for(yExpand = 0; yExpand < expansion; yExpand ++)
X			for (x = 0; x < xdim; x++)
X			    for (xExpand = 0; xExpand < expansion; xExpand++)
X				for (z=0; z < nbp; z++) {
X					*newRaster = data[xdim*y+x];
X					newRaster++;
X					}
X		}
X	    else {
X		expFraction = expansionFactor - (float) expansion;
X		yleftOver =0.0;
X		yoffset = 0;
X		for (y = 0 ; y < ydim; y++){
X		    yleftOver = yleftOver + expFraction;
X		    yoffset = (int) yleftOver;
X		    yleftOver = yleftOver - (float) yoffset;
X		    for(yExpand = 0.0; y < expansion +yoffset; yExpand ++) {
X			xleftOver = 0.0;
X			for (x = 0; x < xdim; x++){
X			    xleftOver = xleftOver + expFraction;
X			    xoffset = (int) xleftOver;
X			    xleftOver = xleftOver - (float) xoffset;
X
X			    for(xExpand=0;xExpand<expansion+xoffset;xExpand++)
X				for (z=0; z < nbp; z++) {
X					*newRaster = data[xdim*y+x];
X					newRaster++;
X					}
X			    }
X			}
X		    }/*for yExpand*/
X		}/*for y*/
X	    }/*else*/
X
X} /* ExpandeCharByPixelExpansion() */
X	    
X
Xvoid ExpandCharByInterpolation(data,xdim,ydim,newRaster,expansionFactor,nbp)
Xunsigned char *data; 	/* image data */
Xint	xdim,ydim;	/* dimensions of data */
Xunsigned char *newRaster; /* mem space big enough for expanded image */
Xfloat expansionFactor;  /* fractional expansion factor */
Xint nbp;		/* number of bytes per pixel */
X{
Xint	expand;
Xfloat	expand1;
Xregister int y,yy,x,xx;
Xregister unsigned char *rp,*dp;
Xint	xexpand,yexpand;	/* expanded dimensions */
Xfloat	ftmp;
X
X	expand = (int) expansionFactor;
X	expand1 = ((float) expand);
X
X	/* clear memory for debugging */
X	for(y=0; y<ydim*expand; y++)
X		for(x=0; x<xdim*expand;x++) 
X			newRaster[y*xdim*expand+x] = 0;
X
X	/* do Y expansion */
X	xexpand = xdim*expand;
X	{
X	float dataStep;
X	for (x = 0; x < xdim; x++) 
X		for (y=0; y < ydim-1 ; y++) {
X			dataStep=((float)(((float)data[(y+1)*xdim+x])
X					-((float)data[y*xdim+x])))/
X					((float) expansionFactor);
X			ftmp = ((float)data[y*xdim+x]);
X			for( yy = 0; yy < expand ; yy++) {
X				newRaster[(y*expand+yy)*xexpand+x*expand] = 
X				(unsigned char) ftmp;
X				ftmp += dataStep;
X				}
X			}
X		}
X	/* expand in X direction */
X	{
X	float dataStep;
X	register unsigned char *nrp; /* newRaster Pointer */
X	register unsigned char *dp;  /* data pointer */
X	nrp = newRaster;
X	dp = newRaster;
X	yexpand = ydim*expand;
X	for (y=0; y < yexpand; y++)
X		for(x=0; x < xdim-1;x++) {
X			dataStep = (((float) *(dp+expand)) - ((float)*dp))
X					/ ((float) expansionFactor);
X			ftmp = ((float)*dp);
X			dp += expand;
X			for(xx = 0; xx < expand; xx++) {
X				*nrp++ = (unsigned char) ftmp;
X				ftmp += dataStep;
X				}
X			}
X		}
X	
X	return;
X}
X
Xint CalculateNBP(myDpy)
X/* return number of bytes per pixel this display uses */
XDisplay *myDpy;
X{
Xint	planes;
Xint	nbp;
X
X	planes = DisplayPlanes(myDpy,DefaultScreen(myDpy));
X	
X	nbp = (planes > 7) ? (planes / 8 + ((planes%8)?1:0)) :1;
X
X	if (nbp >= 3)
X		nbp = 4;
X
X	return(nbp);
X} /* CalculateNBP() */
X
X
XXImage *ConformImageToNPlanes(raster,xdim,ydim,newRaster,
X				expansionFactor,interpExpansion)
X/* return 0 on memory failure */
X/* newRaster is set to NULL if no expansion was necessary */
Xunsigned char *raster;	/* 8 bit raster image */
Xint xdim,ydim;		/* dimensions of raster */
Xunsigned char **newRaster; /* RETURNED: expanded raster image */
Xfloat	expansionFactor;	/* expand image by n*/
Xchar	interpExpansion;	/* should it be an interpolated expansion */
X{
Xregister int x;
Xregister int y;
Xregister int z;
Xint	nbp;	/* number of bytes per pixel */
XXImage	*returnMe;
Xunsigned char *p;
Xint	newXDim,newYDim;
Xint	planes;
X
X	nbp = CalculateNBP(myDpy);
X	planes = DisplayPlanes(myDpy,DefaultScreen(myDpy));
X
X	if (expansionFactor <= 1.0) {
X	    if (nbp > 1) {
X
X		if ( ! (*newRaster=(unsigned char *)XIMalloc(xdim*ydim*nbp))){
X			printf("Couldn't allocate enough memory\n");
X			return(0);
X			}
X		p = *newRaster;
X	    	for(y = 0; y < ydim; y++) 
X		    for(x = 0; x < xdim; x++) {
X			for (z = 1; z < nbp; z++){
X				(*p) = 0;
X				p++;
X				}
X			(*p) = raster[y*xdim+x];
X			p++;
X			}
X
X        	returnMe = XCreateImage(myDpy,myVis,planes,ZPixmap,0,*newRaster,
X                                xdim,ydim,8*nbp,xdim*nbp);
X		}
X	    else {
X        	returnMe = XCreateImage(myDpy,myVis,8,ZPixmap,0,raster,
X                                xdim,ydim,8,xdim);
X
X		*newRaster = (unsigned char *) NULL;
X		}
X	    }
X	else { /* expand image */
X		newXDim = ROUND(expansionFactor * (float)xdim);
X		newYDim = ROUND(expansionFactor * (float)ydim);
X
X		if ( ! (*newRaster=(unsigned char *)XIMalloc(
X				newXDim*newYDim*nbp))){
X			printf("Couldn't allocate enough memory\n");
X			return(0);
X			}
X        	returnMe = XCreateImage(myDpy,myVis,planes,ZPixmap,0,*newRaster,
X                                newXDim,newYDim,8*nbp,newXDim*nbp);
X		if (interpExpansion) {
X			ExpandCharByInterpolation(raster,xdim,ydim,
X				*newRaster,expansionFactor,nbp);
X			}
X		else {
X			ExpandCharByPixelReplication(raster,xdim,ydim,
X				*newRaster,expansionFactor,nbp);
X			}
X		}
X
X
X	return(returnMe);
X
X} /* ConformImageToNPlanes() */
X
X
Xstatic void DidntGetAFile(i)
Xstruct IMAGE *i;
X{
X	PrintMesg("Get new image cancelled\n");
X	DestroyIMAGE(i);
X}
X
Xstatic void GotANewFile(i)
Xstruct IMAGE *i;
X{
X	i->fname = (char *) XIMalloc(strlen(imageFile.directory) + 
X				strlen(*(imageFile.file)) + 2);
X	sprintf(i->fname,"%s/%s",imageFile.directory,*(imageFile.file));
X	i->name = (char *) XIMalloc(strlen(*(imageFile.file)) + 1);
X	strcpy(i->name,*(imageFile.file));
X
X	i->xdim = imageFile.xdim;
X	i->ydim = imageFile.ydim;
X	i->isHDF = imageFile.isHDF;
X	i->isFloat = imageFile.isFloat;
X
X	if ((i->xdim == 0 ) || (i->ydim == 0)) {
X		char  errbuff[80];
X		sprintf(errbuff,"Error: xdim=%d, ydim=%d\n",i->xdim,i->ydim);
X		PrintMesg(errbuff);
X		DestroyIMAGE(i);
X		return;
X		}
X
X	if (! ReadInImage(i)){ 
X		/* error reading in image */
X		DestroyIMAGE(i);	
X		return;
X		}
X
X	CreateImageCtrlBox(i);
X
X	return;
X
X} /* GotANewFile() */
X
X
Xvoid CBNewImage(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE	*i;
X
X	if (!(i = NewIMAGE())) {
X		PrintMesg("Can't allocate memory for new data set\n");
X		return;
X		}
X		
X/**/	ci = i;	/* left in for debugging */
X
X	imageFile.yesfile = GotANewFile;
X	imageFile.nofile = DidntGetAFile;
X	imageFile.type = FTYPE_IMAGE;
X	imageFile.param = (char *) i;
X
X	PrintMesg("Please select a file for [Image]\n");
X	GetAFile(&imageFile);
X
X} /* CBNewImage */
X
X
Xstatic int ReadInImage(i)
Xstruct IMAGE *i;
X/* Read in an image either seq or HDF */
X/* i->name,i->isHDF,i->xdim,i->ydim must be defined */
X/* if HDF, xdim & ydim don't have to be defined */
X/* return NULL if error, length of image if ok */
X{
Xint	stat;	/* return stat from reading image */
X
X	if (i->isHDF) {
X		if (i->isFloat) 
X			stat = ReadHDFSDS(i,i->xdim,i->ydim,1);
X		else
X			stat = ReadHDFImage(i);
X		}
X	else
X		stat = ReadSEQImage(i);
X
X
X	return(stat);
X
X} /* ReadInImage() */
X
X
Xvoid CBCloseImageCtrlBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->pws.amIShowing)
X		CBClosePolarImageBox(w,(caddr_t) i,(caddr_t) 0);
X	if (i->iws.amIShowing)
X		CBCloseCartImageBox(w,(caddr_t) i,(caddr_t) 0);
X	if (i->dws.amIShowing)
X		CBDoneData(w,(caddr_t) i,(caddr_t) 0);
X	if (i->gws.amIShowing)
X		CBDoneGraphControlBox(w,(caddr_t) i,(caddr_t) 0);
X	if (i->cws.amIShowing)
X		XtDestroyWidget(i->cws.toplevel);
X	if (i->gpws.amIShowing)
X		CBDoneProfile(w,(caddr_t)i,(caddr_t) 0);
X	if (i->notebook.notebookShowing)
X		CBDoneNotebook(w,(caddr_t)(&(i->notebook)),(caddr_t) 0);
X	if (i->chaws.amIShowing)
X		CBCloseAttrib(w,(caddr_t) i,(caddr_t) 0);
X
X	/* held on for image and histogram */
X	XFreeColormap(myDpy,i->iws.cmap);
X
X	DestroyIMAGE(i);
X
X	return;
X
X} /* CBCloseImageCtrlBox() */
X
X
Xvoid CreateImageCtrlBox(i)
Xstruct	IMAGE *i;
X{
Xint	xpos,ypos;
X
X	PlaceWindow(&xpos,&ypos);
X
X	i->cws.toplevel = MakeATopLevel("X Image [Image]",
X				toplevelform,xpos,ypos,300,122);
X	Set_Pointer(i->cws.toplevel,XC_gumby);
X
X	i->cws.composite = Make_Board(i->name,i->cws.toplevel,0,0,300,122);
X
X	i->cws.box1 = Make_ButtonBox(i->cws.composite,5,5,250,25);
X	i->cws.label = Make_Label(i->label,i->cws.box1,2,2,30);
X	i->cws.title = Make_Label(i->name,i->cws.box1,33,2,215);
X
X	i->cws.box2 = Make_ButtonBox(i->cws.composite,5,35,140,80);
X        b[IMAGE_CART] = MakeButton("Display Cartesian",i->cws.box2,
X                                5,6,CBDoCart,i,0,0);
X        b[IMAGE_POLAR] = MakeButton("Display Polar",i->cws.box2,
X				5,30,CBDoPolar,i,0,0);
X	b[IMAGE_DATA] = MakeButton("Display Data Set",i->cws.box2,5,54,
X				CBDisplayData,i,0,0);
X
X	i->cws.box3 = Make_ButtonBox(i->cws.composite,155,35,140,80);
X
X	(void) MakeButton("Notebook",i->cws.box3,5,6,
X				CBNotebook,i,0,0);
X
X	b[IMAGE_GRAPH] = MakeButton("Graph",i->cws.box3,69,6,
X				CBGraphControlBox,i,0,0);
X
X	(void) MakeButton("Change Attributes",i->cws.box3,5,54,
X				CBChangeAttrib,i,0,0);
X
X        b[IMAGE_DONE] = MakeButton("Done",i->cws.composite,
X                                260,5,CBCloseImageCtrlBox,i,0,0);
X
X	/* Create colormap used by Cartesian and Histogram */
X	
X        if (myVis->class== PseudoColor) {
X                i->iws.cmap = XCreateColormap(myDpy,
X                        XtWindow(i->cws.toplevel),
X                        myVis,AllocAll);
X                }
X        else {
X                if (myVis->class == StaticColor) {
X                        i->iws.cmap = XCreateColormap(myDpy,
X                                XtWindow(i->cws.toplevel),
X                                myVis,AllocNone);
X                        }
X		else {
X/**/	printf("\nNot sure how to create a colormap for this display\n");
X/**/		printf("I think I'll die ungracefully\n");
X/**/		fflush(stdout);
X		}
X	}
X	if (i->hasPalette) {
X		StoreColors(i->palette,FALSE,i->iws.cmap);
X		}
X	else
X		StoreColors(origccells,FALSE,i->iws.cmap);
X
X	i->cws.amIShowing = TRUE;
X
X} /* CreateImageCtrlBox() */
X
X
X
Xvoid CBDoCart(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct	IMAGE	*i;
X
X	i = (struct IMAGE *)client_data;
X
X	
X	if (i->iws.amIShowing) {
X		PrintMesg("Cartesian image already showing\n");
X		XRaiseWindow(myDpy,XtWindow(i->iws.toplevel));
X		return;
X		}
X
X	if (DisplayPlanes(myDpy,XDefaultScreen(myDpy)) < 8 ) {
X	  PrintMesg("Display must have more than 8 planes to display image\n");
X	  return;
X	  }
X
X	i->cimage = ConformImageToNPlanes(i->ri,i->xdim,i->ydim,
X					&(i->dExpRI),1.0,0);
X	if (!i->cimage)
X		return; /* malloc problems */
X	if (i->dExpRI)
X		i->isDExpRI = TRUE; /* image was depth expanded */
X
X	if (i->expand) {
X		i->cimageExpand = ConformImageToNPlanes(
X			i->ri,
X			i->xdim,
X			i->ydim,
X			&(i->dExpRIExpand),i->expansionFactor,
X			i->interpExpansion);
X		if (!i->cimageExpand)
X			return; /* malloc problems */
X		if (i->dExpRIExpand)
X			i->isDExpRIExpand = TRUE; /* image was depth expanded */
X		}
X
X
X	DisplayImage(i,&(i->iws),DISPLAY_CART);
X
X	i->iws.data1 = FALSE; /* point not selected (highlighted) */
X	i->iws.data2 = i->iws.data3 = 0;
X
X	i->iws.amIShowing = TRUE;
X
X	return;
X
X}/* CBDoCart() */
X
X
X
Xstatic void CBDoPolar(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct	IMAGE	*i;
Xint	ydim_x_2;
X
X	i = (struct IMAGE *)client_data;
X
X	if (i->pws.amIShowing) {
X		PrintMesg("Polar image already showing\n");
X                XRaiseWindow(myDpy,XtWindow(i->pws.toplevel));
X		return;		/* <--- actually should bring to front */
X		}
X
X	if (DisplayPlanes(myDpy,XDefaultScreen(myDpy)) < 8 ) {
X	  PrintMesg("Display must have more than 8 planes to display image\n");
X	  return;
X	  }
X
X	ydim_x_2 = i->ydim << 1;
X	if (!i->pimage) {
X		if(! DrawPolar2(i))
X			return; /* error creating polar (probably XIMalloc) */
X	
X/*		i->pimage = XCreateImage(myDpy,myVis,8,ZPixmap,0,i->polarimage,
X					ydim_x_2,ydim_x_2,8,ydim_x_2);
X*/
X		i->pimage = ConformImageToNPlanes(i->polarimage,
X					ydim_x_2,ydim_x_2,&(i->dExpPI),1.0,0);
X		if (!i->pimage)
X			return; /* malloc problems */
X		if (i->dExpPI)
X			i->isDExpPI = TRUE; /* image was depth expanded */
X		}
X
X
X	DisplayImage(i,&(i->pws),DISPLAY_POLAR); 
X
X	i->pws.data1 = FALSE; /* point not selected (hilighted) */
X
X	i->pws.amIShowing = TRUE;
X	return;
X
X}/* CBDoPolar() */
X
X
X
Xvoid CBCloseCartImageBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X/*#ifdef  NON_ICCCM_WINDOW_MANAGER*/
X	CBUnInstallImageCMap(i->iws.toplevel,(caddr_t) i->iws.cmap,call_data);
X/*#endif*/
X
X/*	XFreeColormap(myDpy,i->iws.cmap);*/
X
X	if (i->expand) {
X		XDestroyImage(i->cimageExpand);
X		XIFree(i->dExpRIExpand);
X		}
X	XtDestroyWidget(i->iws.toplevel);
X
X	i->iws.amIShowing = FALSE;
X
X} /* CBCloseCartImageBox() */
X
X
X
Xstatic void CBClosePolarImageBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X/*#ifdef  NON_ICCCM_WINDOW_MANAGER*/
X	CBUnInstallImageCMap(i->pws.toplevel,(caddr_t) i->pws.cmap,call_data);
X/*#endif*/
X
X	XFreeColormap(myDpy,i->pws.cmap);
X	XtDestroyWidget(i->pws.toplevel);
X
X	i->pws.amIShowing = FALSE;
X
X} /* CBClosePolarImageBox() */
X
X
X
X/* these three palette setting routines should be in their own module */
Xvoid CBInstallImageCMap(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	if (appResources.installCMap)
X        	XInstallColormap(myDpy,(Colormap) client_data);
X}
X
Xvoid CBUnInstallImageCMap(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{        
X	if (appResources.installCMap)
X		XUninstallColormap(myDpy,(Colormap) client_data);
X}
X
Xvoid SetColormap(w,cmap)
XWidget w;
XColormap cmap;
X{
X
X	/* for non ICCCM window managers */
X        XtAddEventHandler(w,EnterWindowMask,FALSE,
X                        CBInstallImageCMap,cmap);
X        XtAddEventHandler(w,LeaveWindowMask,FALSE,
X                        CBUnInstallImageCMap,cmap);
X
X	/* for ICCCM window managers */
X	if (!defStaticVisual) {
X                XSetWindowColormap(myDpy,XtWindow(w),cmap);
X                XSync(myDpy,False);
X        	}
X}
X
X
Xstatic void CBUpdateCMap(w,client_data,call_data)
X/* Update colormap in client_data to be same as palette module's rccells */
X/* ....Sync image palette with palette windows palette */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 
X{
XColormap cmap;
X	cmap = (Colormap) client_data;
X	StoreColors(rccells,FALSE,cmap);
X}
X
Xstatic void CBLockPaletteCart(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct	IMAGE *i;
X	i = (struct IMAGE *) client_data;
X
X	i->iws.lockcmap = ! i->iws.lockcmap;
X
X	if (i->iws.lockcmap) {
X		StoreColors(rccells,FALSE,i->iws.cmap);
X		XtAddEventHandler(i->iws.toplevel,EnterWindowMask,0,
X			CBUpdateCMap,i->iws.cmap);
X		}
X	else {
X		if (i->hasPalette) 
X			StoreColors(i->palette,FALSE,i->iws.cmap);
X		else
X			StoreColors(origccells,FALSE,i->iws.cmap);
X
X		XtRemoveEventHandler(i->iws.toplevel,
X			EnterWindowMask,0,CBUpdateCMap,i->iws.cmap);
X		}
X			
X} /* CBLockPaletteCart() */
X
Xstatic void CBLockPalettePolar(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data; 		/* should contain the IMAGE */
X{
Xstruct	IMAGE *i;
X	i = (struct IMAGE *) client_data;
X
X	i->pws.lockcmap = ! i->pws.lockcmap;
X
X	if (i->pws.lockcmap) {
X		StoreColors(rccells,FALSE,i->pws.cmap);
X		XtAddEventHandler(i->pws.toplevel,EnterWindowMask,0,
X			CBUpdateCMap,i->pws.cmap);
X		}
X	else {
X		if (i->hasPalette) 
X			StoreColors(i->palette,FALSE,i->pws.cmap);
X		else
X			StoreColors(origccells,FALSE,i->pws.cmap);
X
X		XtRemoveEventHandler(i->pws.toplevel,
X			EnterWindowMask,0,CBUpdateCMap,i->pws.cmap);
X		}
X
X} /* CBLockPalettePolar() */
X
X
XMakeInc(w,maxvalue,minvalue,isFloat,yOffset)
XWidget	w;
Xfloat   maxvalue,minvalue;
Xchar isFloat;
Xint	yOffset;
X{
Xstatic	char	buff[10];
Xstatic	GC	gc;
Xstatic	XGCValues	gcval;
Xfloat	d,dinc;	/* real data scale, data scale increment */
Xint	y,yinc;
X
X/*?*/	XSync(myDpy,False);
X
X	yinc = 25;
X
X	dinc = (isFloat) ? ((maxvalue - minvalue) / 10.0): 25.0 ;
X	
X/*	gcval.font =    GCFont*/
X	gcval.foreground = black;
X	gcval.background = white;
X	gc = XtGetGC(w,GCForeground | GCBackground ,&gcval);
X
X	XSetForeground(myDpy,gc,black);
X	XSetBackground(myDpy,gc,white);
X	if (ximageFont) {
X		XSetFont(myDpy,gc,ximageFont->fid);
X		}
X	XClearWindow(myDpy,XtWindow(w));
X	for (y = yinc, d= (float) minvalue+dinc; y < 231; y+=yinc,d+=dinc) {
X		if (isFloat)
X			sprintf(buff,"%-5.3f",d);
X		else 
X			sprintf(buff,"%-3d",(int) d);
X		XDrawString(myDpy,XtWindow(w),gc,
X			10, 255-((int)y+yOffset),buff,strlen(buff));
X		}
X		
X/*	sprintf(buff,"%-4.f",maxvalue);
X	XDrawString(myDpy,XtWindow(w),gc,
X			10,(int)0+yOffset,buff,4);
X*/
X}
X
X
Xvoid CBRedrawTest2(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X	MakeInc(w,i->maxvalue,i->minvalue,i->isFloat,0);
X
X}
X
XUnDrawSelectedArea(image,drawable,gc,x,y,xdim,ydim)
Xunsigned char	*image;		/* the raster image */
XDrawable 	drawable;	/* window to draw on */
XGC		gc;		/* gc of window to be undrawn on */
Xint		x,y;		/* point to undraw selection */
Xint		xdim,ydim;	/* dimensions of image */
X{
Xint	sx,sy;	/* start x&y */
Xint	ex,ey;	/* end x&y*/
Xint	i,j;	/* index */
X
X	sx = (x == 0)? x: x-1;
X	sy = (y == 0)? y: y-1;
X	ex = (x == xdim)? x:x+1;
X	ey = (y == ydim)? y:y+1;
X
X	for (j = sy; j <= ey; j++)
X		for (i = sx; i <= ex; i++) {
X			XSetForeground(myDpy,gc,image[j*xdim+i]);
X/*			printf("i,j = %d,%d color=%d\n",i,j,image[j*xdim+i]);*/
X			XSync(myDpy,False);
X			XDrawPoint(myDpy,drawable,gc,i,j);
X			XSync(myDpy,False);
X			}
X		
X
X} /* UnDrawSelectedArea() */
X
X
Xvoid CartHighlightSelectedImage(i,x,y)
X/* Highlight point */
Xstruct	IMAGE *i;
Xint	x,y;
X{
XGC	gc;
X
X	if (! i->iws.amIShowing)
X		return;
X
X	XSetFunction(myDpy,i->iws.box3gc,GXxor);
X	XSetForeground(myDpy,i->iws.box3gc,255);
X	XSetLineAttributes(myDpy,i->iws.box3gc,1,LineSolid,CapButt,
X					JoinRound);
X	if (i->iws.data1) {
X		/* erase old */
X		XDrawRectangle(myDpy,XtWindow(i->iws.box3),
X		    i->iws.box3gc,
X		    ROUND(((float)i->iws.data2)*i->expansionFactor),
X		    ROUND(((float)i->iws.data3)*i->expansionFactor),
X		    (int) i->expansionFactor, (int)i->expansionFactor);
X		}
X	i->iws.selBegX = i->iws.selEndX = x;
X	i->iws.selBegY = i->iws.selEndY = y;
X	i->iws.data1 = TRUE;
X	i->iws.data2 = x;
X	i->iws.data3 = y;
X	XDrawRectangle(myDpy,XtWindow(i->iws.box3),
X		i->iws.box3gc,
X		ROUND(((float)i->iws.data2)*i->expansionFactor),
X		ROUND(((float)i->iws.data3)*i->expansionFactor),
X		(int)i->expansionFactor, (int)i->expansionFactor);
X		
X	return;
X
X} /* CartHighlightSelectedImage() */
X
Xvoid PolarHighlightSelectedImage(i,x,y)
Xstruct	IMAGE *i;
Xint	x,y;
X{
XGC	gc;
XXGCValues gcval;
X
X	if (! i->pws.amIShowing)
X		return;
X
X	gcval.foreground = white;
X	gcval.line_width = 1;
X	gc = XtGetGC(i->pws.box3,GCForeground|GCLineWidth,
X			&gcval);
X	if (i->pws.data1) { 
X			UnDrawSelectedArea(i->polarimage,XtWindow(i->pws.box3),
X					gc, i->pws.data2,i->pws.data3,
X					i->ydim*2,i->ydim*2);
X
X		if (( x== i->pws.data2) && (y == i->pws.data3)) {
X			i->pws.data1 = FALSE;	/* is image selected=FALSE*/
X			return;
X			}
X		}
X
X
X	if (i->polarimage[i->ydim*2*y+x] == white)/*yeah?, so what..I'm lazy.*/
X		XSetForeground(myDpy,gc,black); 
X	else
X		XSetForeground(myDpy,gc,white);
X	XDrawRectangle(myDpy,XtWindow(i->pws.box3),
X			gc,x-1,y-1,2,2);
X	i->pws.data1 = TRUE;
X	i->pws.data2 = x;
X	i->pws.data3 = y;
X
X	return;
X
X} /* PolarHighlightSelectedImage() */
X
XDrawSelectionRectangle(dpy,drawable,gc,x1,y1,x2,y2)
XDisplay *dpy;
XDrawable drawable;
XGC gc;
Xint x1,y1,x2,y2;
X{
Xint	width,height;
X
X	if ((x1==x2) && (y1=y2))
X		return;
X
X	width = ABS(x1-x2);
X	height = ABS(y1-y2);
X
X	if (x2 > x1) {
X		if (y2 > y1) {
X		    if (FillSelectionRectangle)
X			XFillRectangle(dpy,drawable,gc,x1,y1,width,height);
X		    else
X			XDrawRectangle(dpy,drawable,gc,x1,y1,width,height);
X		    }
X		else{
X		    if (FillSelectionRectangle)
X			XFillRectangle(dpy,drawable,gc,x1,y2,width,height);
X		    else
X			XDrawRectangle(dpy,drawable,gc,x1,y2,width,height);
X		    }
X		}
X	else {
X		if (y2 > y1) {
X		    if (FillSelectionRectangle)
X			XFillRectangle(dpy,drawable,gc,x2,y1,width,height);
X		    else
X			XDrawRectangle(dpy,drawable,gc,x2,y1,width,height);
X		    }
X		else {
X		    if (FillSelectionRectangle)
X			XFillRectangle(dpy,drawable,gc,x2,y2,width,height);
X		    else
X			XDrawRectangle(dpy,drawable,gc,x2,y2,width,height);
X		    }
X		}
X} /* DrawSelectionRectangle() */
X
Xstatic void CBCartImageDragSelection(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;
Xint     win_x,win_y;
Xint	dataX,dataY;
Xunsigned int    keys_buttons;
Xstruct IMAGE *i;
Xint	width,height;
Xint	bx,by,ex,ey;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->iws.select == POINT)
X		return;
X
X        if (XQueryPointer(myDpy,XtWindow(w),&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X		if ((win_x != i->iws.selEndX) || (win_y != i->iws.selEndY)) {
X
X		    /* pointer has moved and is in boundaries */
X		    if (i->expand) {
X			width = i->cimageExpand->width;
X			height = i->cimageExpand->height;
X		        win_x =(win_x >= width)? width-1:((win_x >0)?win_x:0);
X		        win_y =(win_y >= height)?height-1:((win_y >0)?win_y:0);
X			dataX = ROUND(((float) win_x) / i->expansionFactor);
X			dataY = ROUND(((float) win_y) / i->expansionFactor);
X			bx = ROUND(((float)i->iws.selBegX)*i->expansionFactor);
X			by = ROUND(((float)i->iws.selBegY)*i->expansionFactor);
X			}
X		    else {
X			width = i->xdim;
X			height = i->ydim;
X		        win_x =(win_x >= width)? width-1:((win_x >0)?win_x:0);
X		        win_y =(win_y >= height)?height-1:((win_y >0)?win_y:0);
X			dataX = win_x;
X			dataY = win_y;
X			bx = i->iws.selBegX;
X			by = i->iws.selBegY;
X			}
X
X		    if (i->iws.select == LINE) {
X			/* Erase Line */
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X			XDrawLine(myDpy,XtWindow(i->iws.box3),i->iws.box3gc,
X			    bx,by,
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X
X
X			i->iws.selEndX = dataX;
X			i->iws.selEndY = dataY;
X			/*Draw new line */
X			XDrawLine(myDpy,XtWindow(i->iws.box3),i->iws.box3gc,
X			    bx,by,
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			}
X		   else { /* i->iws.select == AREA;  Draw rectangle */
X			/* Erase Rectangle*/
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X			DrawSelectionRectangle(myDpy,XtWindow(i->iws.box3),
X			    i->iws.box3gc,bx,by,
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			i->iws.selEndX = dataX;
X			i->iws.selEndY = dataY;
X			/*Draw new rectangle*/
X			DrawSelectionRectangle(myDpy,XtWindow(i->iws.box3),
X			    i->iws.box3gc,bx,by,
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			}
X                }
X
X	}
X}
X
X
Xstatic void CBCartImageSelected(w,client_data,call_data)
X/* This routine called on button press event */
X/* button motion events call the CBCartImageDragSelection()*/
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
XXButtonPressedEvent *buttonEvent;
Xchar buff[256];
Xchar buff2[256];
Xint x,y;
X
X	i = (struct IMAGE *) client_data;
X	/*
X	buttonEvent = (XButtonPressedEvent *) call_data;
X	*/
X	buttonEvent = &(((XEvent *)call_data)->xbutton);
X
X	x = buttonEvent->x;
X	y = buttonEvent->y;
X
X	if (i->expand) {
X		x = ROUND(((float) x) / i->expansionFactor);
X		y = ROUND(((float) y) / i->expansionFactor);
X		}
X
X	if ((x < 0) || (x > i->xdim-1) || (y < 0) || (y > i->ydim-1))
X		return;
X
X	switch (i->iws.select) {
X	   case POINT: {
X		if (i->dws.amIShowing) /* Data Spreadsheet Window Visable? */
X			SelectPointFromImage(i,x,y);
X		else {
X			if (i->isFloat) {
X		            sprintf(buff,
X				"Just selected location %d,%d; value=%s\n",
X				x,y,i->format);
X			    sprintf(buff2,buff,i->fdataset[y*i->xdim+x]);
X			    }
X			else {
X			    sprintf(buff,
X				"Just selected location %d,%d; value=%s\n",
X				x,y,i->format);
X			    sprintf(buff2,buff,i->ri[y*i->xdim+x]);
X			    }
X			PrintMesg(buff2);
X			}
X		}
X
X		CartHighlightSelectedImage(i,x,y);
X		break;
X	   case LINE: {
X		XSetFunction(myDpy,i->iws.box3gc,GXxor);
X		XSetForeground(myDpy,i->iws.box3gc,255);
X		XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X		/* Erase old */
X		XDrawLine(myDpy,XtWindow(i->iws.box3),i->iws.box3gc,
X			ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X		i->iws.selBegX = i->iws.selEndX = x;
X		i->iws.selBegY = i->iws.selEndY = y;
X		}
X		break;
X	   case AREA: {
X		XSetFunction(myDpy,i->iws.box3gc,GXxor);
X		XSetForeground(myDpy,i->iws.box3gc,255);
X		XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X		/* Erase old */
X		DrawSelectionRectangle(myDpy,XtWindow(i->iws.box3),
X			i->iws.box3gc,
X			ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X
X		i->iws.selBegX = i->iws.selEndX = x;
X		i->iws.selBegY = i->iws.selEndY = y;
X		if (regionSelected && (regionSelected != i)) {
X			/* Erase Rectangle of another image*/
X                        DrawSelectionRectangle(myDpy,
X				XtWindow(regionSelected->iws.box3),
X                                regionSelected->iws.box3gc,
X				ROUND(((float)regionSelected->iws.selBegX)
X					*regionSelected->expansionFactor),
X				ROUND(((float)regionSelected->iws.selBegY)
X					*regionSelected->expansionFactor),
X				ROUND(((float)regionSelected->iws.selEndX)
X					*regionSelected->expansionFactor),
X				ROUND(((float)regionSelected->iws.selEndY)
X					*regionSelected->expansionFactor));
X				regionSelected->iws.selBegX = 0;
X				regionSelected->iws.selEndX = 0;
X				regionSelected->iws.selBegY = 0;
X				regionSelected->iws.selEndY = 0;
X			}
X		regionSelected = i;
X		}
X		break;
X	   }
X
X
X} /* CBCartImageSelected */
X
X
X
X
Xstatic void CBPolarImageSelected(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
XXButtonPressedEvent *buttonEvent;
Xchar buff[256];
Xchar buff2[256];
Xint x,y;
Xint	yd;	/* ydim  doubled */
Xint	dx,dy;	/*data set x&y*/
Xdouble	r,theta; /* polar coordinates */
X
X
X	i = (struct IMAGE *) client_data;
X	buttonEvent = (XButtonPressedEvent *) call_data;
X	x = buttonEvent->x;
X	y = buttonEvent->y;
X
X	yd = i->ydim *2;
X	if ((x < 0) || (x > yd) || (y < 0) || (y > yd))
X		return;	 /* if out of bounds, then ignore it */
X
X
X	r = sqrt((double) (SQUARE((i->ydim-x)) + SQUARE((i->ydim-y))));
X	theta = atan(((double)(y - i->ydim))/((double)(x - i->ydim)));
X
X	dy = ROUND(r);
X	dx = ROUND(((double)i->xdim) * ((double) theta/(2.0*PI)));
X
X	/* the following quadrant ajustments should be made on theta*/
X	/* before the dx calculations so theta value will be correct */
X	/* when printed out ... but I'm lazy...I'll put off til tomorrow*/
X	if ( x < i->ydim) /* Q2 & Q3 */
X		dx = -dx + i->xdim/2;
X	else {
X		if (y <= i->ydim)  /* Q1 */
X			dx = -dx;
X		else /* Q4 */
X			dx = -dx + i->xdim;
X		}
X
X
X/*	printf("dx = %d, dy = %d\n",dx,dy);*/
X
X	if ((dx > i->xdim) || (dx < 0)) {
X		printf("Error in translation of polar mapping dx =%d\n",dx);
X		return;
X		}
X	if ((dy > i->ydim) || (dy < 0)){
X		PrintMesg("Out of Polar data set range\n");
X		return;
X		}
X
X	if (i->dws.amIShowing)
X		SelectPointFromImage(i,dx,dy);
X	else {
X		float rad;
X/*		degrees = (int) ((((float) dx) / ((float) i->xdim)) * 360.0);*/
X		rad = ((((float) dx) / ((float) i->xdim)) * 2.0*PI);
X
X		if (i->isFloat) {
X			sprintf(buff,
X		    "Selected location r=%d, theta=%.4f; value=%s\n",
X					dy,rad,i->format);
X			sprintf(buff2,buff,i->fdataset[dy*i->xdim+dx]);
X			}
X		else {
X			sprintf(buff,
X		    "Selected location r=%d, theta=%.4f; value=%s\n",
X					dy,rad,i->format);
X			sprintf(buff2,buff,i->ri[dy*i->xdim+dx]);
X			}
X		PrintMesg(buff2);
X		}
X	PolarHighlightSelectedImage(i,x,y);
X}
X
X
Xstatic void CBInitSetColors(w,client_data,call_data)
X/* set palette for the window when exposed */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IWS *ws;
X
X	ws = (struct IWS *) client_data;
X	SetColormap(ws->toplevel,ws->cmap);
X        XtRemoveEventHandler(w,ExposureMask,FALSE,
X                        CBInitSetColors,ws);
X}
X
Xstatic void CBCartSelectionRedraw(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
Xstruct IWS *ws;
X
X	i = (struct IMAGE *) client_data;
X	ws = &(i->iws);
X
X	switch (ws->select) {
X		case POINT:
X			if (i->iws.data1) {
X                     	   XSetFunction(myDpy,ws->box3gc,GXxor);
X                       	   XSetForeground(myDpy,ws->box3gc,255);
X			   XSetLineAttributes(myDpy,i->iws.box3gc,1,
X					LineSolid,CapButt, JoinRound);
X			   XDrawRectangle(myDpy,XtWindow(i->iws.box3),
X			      i->iws.box3gc,
X			      ROUND(((float)i->iws.data2)*i->expansionFactor),
X			      ROUND(((float)i->iws.data3)*i->expansionFactor),
X			      (int)i->expansionFactor, (int)i->expansionFactor);
X			   }
X			break;
X		case LINE:
X                        XSetFunction(myDpy,ws->box3gc,GXxor);
X                        XSetForeground(myDpy,ws->box3gc,255);
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X                        XDrawLine(myDpy,XtWindow(ws->box3),ws->box3gc,
X			    ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			break;
X		case AREA:
X			XSetFunction(myDpy,ws->box3gc,GXxor);
X			XSetForeground(myDpy,ws->box3gc,255);
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X			DrawSelectionRectangle(myDpy,XtWindow(ws->box3),
X			    ws->box3gc,
X			    ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			break;
X		}
X}
Xstatic void CBCartReleaseSelection(w,client_data,call_data)
X/* called on Button Release */
X/* replots the profile graph */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
Xstatic XEvent event;
X
X	i = (struct IMAGE *) client_data;
X
X	if (i->gpws.amIShowing) {
X		CBProfileExpose(w,i,call_data);
X		}
X	if ((i->iws.select == AREA) && (i->ghws.amIShowing)) 
X		UpdateHistogram(i);
X}
X
X
Xstatic void RedisplayCartRasterImage(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X	XSetFunction(myDpy,i->iws.box3gc,GXcopy);
X	if (i->iws.amIShowing) {
X		if (i->expand && i->cimageExpand) 
X			XPutImage(myDpy,XtWindow(i->iws.box3),i->iws.box3gc,
X				i->cimageExpand,0,0,0,0,
X				i->cimageExpand->width,
X				i->cimageExpand->height);
X		else 
X			XPutImage(myDpy,XtWindow(i->iws.box3),i->iws.box3gc,
X				i->cimage,0,0,0,0,i->xdim,i->ydim);
X		}
X
X}
Xstatic void CBSelectChange (w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
Xstruct IWS *ws;
X
X	i = (struct IMAGE *) client_data;
X	ws = &(i->iws);
X	SetToggle(w,True);
X	switch (ws->select) {
X		case POINT:
X			if (i->iws.data1) {
X			  XDrawRectangle(myDpy,XtWindow(i->iws.box3),
X			    i->iws.box3gc,
X			    ROUND(((float)i->iws.data2)*i->expansionFactor),
X			    ROUND(((float)i->iws.data3)*i->expansionFactor),
X			    (int) i->expansionFactor, (int)i->expansionFactor);
X			    }
X			i->iws.data1 = FALSE;
X			ws->select = LINE;
X			SetToggleString(w,"Select Line");
X			ws->selBegX = ws->selBegY = 0;
X			ws->selEndX = ws->selEndY = 0;
X			break;
X		case LINE:
X			/* Erase old LINE */
X			XSetFunction(myDpy,ws->box3gc,GXxor);
X			XSetForeground(myDpy,ws->box3gc,255);
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X                        XDrawLine(myDpy,XtWindow(ws->box3),ws->box3gc,
X			    ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			ws->select = AREA;
X			SetToggleString(w,"Select Area");
X			ws->selBegX = ws->selBegY = 0;
X			ws->selEndX = ws->selEndY = 0;
X			break;
X		case AREA:
X			/* Erase old Rectangle*/
X			XSetFunction(myDpy,ws->box3gc,GXxor);
X			XSetForeground(myDpy,ws->box3gc,255);
X			XSetLineAttributes(myDpy,i->iws.box3gc,3,LineSolid,CapButt,
X					JoinRound);
X			DrawSelectionRectangle(myDpy,XtWindow(ws->box3),
X				ws->box3gc,
X			    ROUND(((float)i->iws.selBegX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selBegY)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndX)*i->expansionFactor),
X			    ROUND(((float)i->iws.selEndY)*i->expansionFactor));
X			ws->select = POINT;
X			SetToggleString(w,"Select Point");
X			ws->selBegX = ws->selBegY = 0;
X			ws->selEndX = ws->selEndY = 0;
X			ws->data1 = ws->data2 = ws->data3 = 0;
X			regionSelected = NULL;
X			break;
X		}
X}
X
Xstatic void ImageDidntGetPalFile()
X{
X	PrintMesg("Change Palette cancelled\n");
X}
X
Xstatic void ImageGotPalFile(i)
Xstruct IMAGE *i;
X{
Xchar fileName[512];
X
X	if (!i->hasPalette){
X		if ( ! (i->palette=(XColor *) XICalloc(256,sizeof(XColor)))) {
X                        PrintMesg("Couldn't XIMalloc memory for palette\n");
X                        return;   /* couldn't get memory */
X                        }
X		}
X
X	sprintf(fileName,"%s/%s",palFile.directory,*(palFile.file));
X	if (! palFile.isHDF) {
X		if(! ReadSEQPalette(fileName,i->palette))
X			return; /* Error reading Colormap */
X		}
X	else {
X		if(! ReadHDFPalette(fileName,i->palette))
X			return; /* Error reading Colormap */
X		}
X	i->hasPalette = TRUE;
X	StoreColors(i->palette,FALSE,i->iws.cmap);
X
X} /* ImageGotPalFile() */
X
Xstatic void CBChangePalette(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X
X	i = (struct IMAGE *) client_data;
X
X        palFile.type = FTYPE_PAL;
X        palFile.yesfile = ImageGotPalFile;
X        palFile.nofile = ImageDidntGetPalFile;
X        palFile.param = (char *) i;
X        GetAFile(&palFile);
X}
X
Xvoid DisplayImage(i,ws,type)
X/* Create color display window for cartesian or polar */
Xstruct	IMAGE	*i;
Xstruct	IWS	*ws;
Xint	type;
X{
Xint	xpos,ypos;
Xint	s;
Xint	width,height;
XXGCValues gcvalues;
XPixmap	stipple;
Xint	w,h;	/* height & width */
X
X	PlaceWindow(&xpos,&ypos);
X	if (i->expand) {
X		w = i->cimageExpand->width;
X		h = i->cimageExpand->height;
X		}
X	else {
X		w = i->xdim;
X		h = i->ydim;
X		}
X	if (type == DISPLAY_POLAR) {
X		s = i->ydim << 1 ;
X		width = ((s+PAL_WIDTH+65) > 200) ? (s+PAL_WIDTH+65) : 200;
X		height = ((s+40)  > 350) ? s+40 : 350;
X		}
X	else {
X		width = ((w+PAL_WIDTH+65) > 200)? (w+PAL_WIDTH+65): 200;
X		height = ((h+40) > 380)?(h+40): 380;
X		}
X
X	ws->toplevel = MakeATopLevel(i->name,toplevelform,xpos,ypos,
X					width,height);
X	ws->lockcmap = FALSE;
X
X	if (type == DISPLAY_POLAR) {
X		if (myVis->class== PseudoColor) {
X		       	ws->cmap = XCreateColormap(myDpy,
X				XtWindow(ws->toplevel),
X				myVis,AllocAll);
X			}
X		else {
X			if (myVis->class == StaticColor) {
X		       		ws->cmap = XCreateColormap(myDpy,
X					XtWindow(ws->toplevel),
X					myVis,AllocNone);
X				}
X			else {
X/**/	printf("\nNot sure how to create a colormap for this display\n");
X/**/		printf("I think I'll die ungracefully\n");
X/**/		fflush(stdout);
X				}
X			}
X		if (i->hasPalette) {
X			StoreColors(i->palette,FALSE,ws->cmap);
X			}
X		else
X			StoreColors(origccells,FALSE,ws->cmap);
X
X		}
X
X	SetColormap(ws->toplevel,ws->cmap);
X		
X
X
X	Set_Pointer(ws->toplevel,XC_gumby);
X	ws->composite = Make_Board(i->name,ws->toplevel,0,0,
X					width,height);
X
X        ws->box1 = Make_ButtonBox(ws->composite,5,5,width-50,25);
X        ws->label = Make_Label(i->label,ws->box1,2,2,30);
X        ws->title = Make_Label(i->name,ws->box1,35,2,width-85);
X
X	ws->box2 = Make_ButtonBox(ws->composite,5,35,
X				PAL_WIDTH+50,height-40);
X	ws->pal_win = MakeRasterImage("palette",ws->box2,
X				2,(height-40)/2 -140,
X				palXImage,NULL,NULL);
X
X
X	if (type == DISPLAY_CART) {
X        	b[IMAGE_CDONE] = MakeButton("Done",ws->composite,
X                                width-40,5,CBCloseCartImageBox,i,0,0);
X/*
X		ws->box3 = MakeRasterImage(i->name,ws->composite,
X					PAL_WIDTH+60,35,
X					i->cimage,CBCartImageSelected,i);
X*/
X		ws->box3 = MakeWorkSpace(i->name,ws->composite,
X				PAL_WIDTH+60,35,w,h,
X				RedisplayCartRasterImage,i,0,0);
X#ifdef DEBUG
X		printf("image.c:ws->box3 has been created \n");
X		fflush(stdout);
X#endif
X
X		/* Make sure it displays incase no Expose event happens */
X/*		XtAddTimeOut(500,RedisplayCartRasterImage,i);*/
X
X		XtAddEventHandler(ws->box3,ButtonPressMask,0,
X				CBCartImageSelected,i);
X		
X		gcvalues.function = GXcopy;
X		gcvalues.foreground = 255;
X		ws->box3gc = XtGetGC(ws->box3,
X				GCFunction|GCForeground,&gcvalues);
X		if (FillSelectionRectangle) {
X			stipple = XCreateBitmapFromData(myDpy,
X				XtWindow(ws->box3),
X				CROSSHATCH_bits,
X				CROSSHATCH_width,CROSSHATCH_height);
X			XSetStipple(myDpy,ws->box3gc,stipple);
X			XSetFillStyle(myDpy,ws->box3gc,FillStippled);
X			}
X		XSetLineAttributes(myDpy,i->iws.box3gc,1,LineSolid,CapButt,
X					JoinRound);
X
X		XtAddEventHandler(ws->box3,ButtonMotionMask,False,
X				CBCartImageDragSelection,i);
X		XtAddEventHandler(ws->box3,ButtonReleaseMask,False,
X				CBCartReleaseSelection,i);
X		XtAddEventHandler(ws->box3,ExposureMask,False,
X				CBCartSelectionRedraw,i);
X
X		ws->box4 = MakeWorkSpace("Values",ws->box2,PAL_WIDTH+5,
X				(height-40)/2-140,40,256,
X				CBRedrawTest2,i,NULL,NULL);
X		MakeInc(ws->box4,i->maxvalue,i->minvalue,
X				i->isFloat,0);
X		
X		(void) Make_Toggle("Lock Palette",ws->box2,
X				2,(height-40)/2 +125,
X				CBLockPaletteCart,i,CBLockPaletteCart,i,
X				True,False);
X        	(void) MakeButton("Change Palette",ws->box2,
X                                2,(height-40)/2 +145,CBChangePalette,i,0,0);
X
X		(void) Make_Toggle("Select Point",ws->box2,
X			2,2,CBSelectChange,i,
X			CBSelectChange,i,
X			False,True);
X		}
X	else {
X		/* It's a polar */
X        	b[IMAGE_PDONE] = MakeButton("Done",ws->composite,
X                                width-40,5,CBClosePolarImageBox,i,0,0);
X		ws->box3 = MakeRasterImage(i->name,ws->composite,
X					PAL_WIDTH+60,35,
X					i->pimage,CBPolarImageSelected,i);
X		gcvalues.function = GXcopy;
X		gcvalues.foreground = 255;
X		ws->box3gc = XtGetGC(ws->box3,
X			GCFunction|GCForeground,&gcvalues);
X		ws->box4 = MakeWorkSpace("Values",ws->box2,PAL_WIDTH+5,
X				(height-40)/2-128,40,256,
X				CBRedrawTest2,i,NULL,NULL);
X		MakeInc(ws->box4,i->maxvalue,i->minvalue,
X				i->isFloat,0);
X		Make_Toggle("Lock Palette",ws->box2,
X				2,(height-40)/2 +140,
X				CBLockPalettePolar,i,
X				CBLockPalettePolar,i,True,False);
X/*
X		Make_Toggle("Select Point",ws->box2,
X			2,2,CBSelectChange,&(i->pws),
X			CBSelectChange,&(i->pws),
X			False,True);
X*/
X		}
X
X
X	Set_Pointer(ws->box3,XC_left_ptr);
X
X
X/*	SetColormap(ws->toplevel,ws->cmap);*/
X
X        XtAddEventHandler(ws->toplevel,ExposureMask,FALSE,
X                        CBInitSetColors,ws);
X} /* DisplayImage() */
X
X
XUpdateImageData(i)
Xstruct IMAGE *i;
X/* The data set has been replaced, so update all the windows displaying it */
X{
X	if (i->iws.amIShowing) {
X		RedisplayCartRasterImage(i->iws.box3,i,0); /* redraw image*/
X		CBRedrawTest2(i->iws.box4,i,0); /* redraw ticks */
X		}
X	if (i->gws.amIShowing)
X		ReplotGraphs(i);
X	if (i->dws.amIShowing)
X		UpdateData(i);
X
X}
END-of-image.c
echo file: intensity.c
sed 's/^X//' >intensity.c << 'END-of-intensity.c'
X/*  plots a fluctuation grid over a data set, with */
X/*  tendencies toward higher data points.  Concept: David Thompson	*/
X/*  Written:  David Whittington.					*/
X
X#include	<X11/Xlib.h>
X#include	<X11/Intrinsic.h>
X#include "ximage.h"
X
X#define	INIT_FIELD_STR	2
X#define	INIT_INERTIA	5
X#define	INIT_X_DENSITY	20
X#define	INIT_Y_DENSITY	20
X
Xstatic	int	x,y;
Xstatic	int	lastX,lastY;
Xstatic	int	xdim,ydim;
Xstatic	char	*ri;
Xstatic	Display	*disp;
Xstatic	Drawable d;
Xstatic	GC	the_gc;
X
Xstatic unsigned char data(x,y)
Xint	x,y;
X{
X	return(ri[y*xdim + x]);
X}
X
Xvoid ForceX(strength,inertia)
Xint	strength,inertia;
X{
Xint	delta,average,direction;
X
X	delta = 0;
X	average = ((int) data(x+1,y) - (int) data(x-1,y))/2;
X	direction = (average < 0) ? -1 : 1;
X	average = average * direction;
X	while ((average - (delta*direction + 1)/strength +
X		direction*(lastX - delta - x)/inertia) > 0)
X	{
X		delta += direction;
X		average -= delta * direction / strength;
X		if ((x+delta) < 1)
X		{
X			delta -= direction;
X			average = 0;
X		}
X		else
X		if ((x+delta) > (xdim - 1))
X		{
X			delta -= direction;
X			average = 0;
X		}
X		else
X		average += (((int) data(x+delta+1,y)-
X			     (int) data(x+delta-1,y))/2)*direction;
X	}
X	XDrawLine(disp,d,the_gc,lastX,lastY,x+delta,y);
X	lastX = x+delta;
X	lastY = y;
X}
X
Xvoid ForceY(strength,inertia)
Xint	strength,inertia;
X{
Xint	delta,average,direction;
X
X	delta = 0;
X	average = ((int) data(x,y+1) - (int) data(x,y-1))/2;
X	direction = (average < 0) ? -1 : 1;
X	average = average * direction;
X	while ((average - (delta*direction + 1)/strength +
X		direction*(lastY - delta - y)/inertia) > 0)
X	{
X		delta += direction;
X		average -= delta * direction / strength;
X		if ((y+delta) < 1)
X		{
X			delta -= direction;
X			average = 0;
X		}
X		else
X		if ((y+delta) > (ydim - 1))
X		{
X			delta -= direction;
X			average = 0;
X		}
X		else
X		average += (((int) data(x,y+delta+1)-
X			     (int) data(x,y+delta-1))/2)*direction;
X	}
X	XDrawLine(disp,d,the_gc,lastX,lastY,x,y+delta);
X	lastX = x;
X	lastY = y+delta;
X}
X
Xvoid Updt_Intensity(w,image,xmax,ymax,fore,xorflag)
XWidget	w;
Xchar	*image;
Xint	xmax,ymax;
Xint	fore,xorflag;
X{
XXGCValues values;
Xint	xDensity,yDensity;
Xint	xStart,yStart;
X
X	disp = XtDisplay(w);
X	d = XtWindow(w);
X	if (xorflag == 0)
X	{
X		values.foreground = fore;
X		the_gc = XtGetGC(w,(GCForeground),&values);
X	}
X	else
X	{
X		values.function = GXxor;
X		values.foreground = 255;
X		the_gc = XtGetGC(w,(GCFunction | GCForeground),&values);
X	}
X
X	xdim = xmax;
X	ydim = ymax;
X	ri = image;
X	xDensity = INIT_X_DENSITY;
X	yDensity = INIT_Y_DENSITY;
X	xStart = (xdim - (xdim / xDensity)*xDensity)/2;
X	yStart = (ydim - (ydim / yDensity)*yDensity)/2;
X	xStart = (xStart < 1) ? xDensity / 2 : xStart;
X	yStart = (yStart < 1) ? yDensity / 2 : yStart;
X
X	for (x = xStart; x < xdim; x += xDensity)
X	{
X		lastX = x;
X		lastY = 0;
X		for (y = 1; y < ydim; y++)
X			ForceX(INIT_FIELD_STR,INIT_INERTIA);
X	}
X	for (y = yStart; y < ydim; y += yDensity)
X	{
X		lastX = 0;
X		lastY = y;
X		for (x = 1; x < xdim; x++)
X			ForceY(INIT_FIELD_STR,INIT_INERTIA);
X	}
X}
X
END-of-intensity.c
echo file: main.c
sed 's/^X//' >main.c << 'END-of-main.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <signal.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X#include <X11/Shell.h>
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "ximage.icon"
X
Xextern  Display *myDpy;
Xextern	Widget toplevel;
Xextern	void ReleaseAllImages();
Xextern	void ClosePaletteBox();
Xextern	void ReleaseAllAnimations();
Xextern	void DevNull();
X
XWidget	b[50];			/* Buttons */
X
Xstatic	char whoWroteMe[]="\nNCSA XImage written by Dave Thompson\nContour&Shade routines written by Dave Whittington\n";
X
Xvoid Quit();
X
Xvoid BreakOut(sig,code,scp,addr)
Xint 	sig, code;
Xstruct	sigcontext *scp;
Xchar	*addr;
X{
X	printf("\n...exiting ximage\n");
X
X#ifdef DEBUG
X	printf("exiting on a ");
X	switch(sig){
X		case SIGHUP: printf("SIGHUP");
X			break;
X		case SIGINT: printf("SIGINT");
X			break;
X		default: printf("SIG %d",sig);
X		};
X	printf("\n");
X#endif
X
X	fflush(stdout);
X	Quit(toplevel,NULL,NULL);
X}
X
Xvoid FatalProblem(sig,code,scp,addr)
Xint 	sig, code;
Xstruct	sigcontext *scp;
Xchar	*addr;
X{
X	fprintf(stderr,"\n\nYou have found a bug in\n");
X	fprintf(stderr,"%s",GetVersionDate());
X	fprintf(stderr,"Please report this to:  bugs@ncsa.uiuc.edu\n");
X	fprintf(stderr,"...exiting ximage now\n\n");
X	fflush(stderr); /* not necessary but can't hurt */
X
X	if (myDpy)
X		XUngrabPointer(myDpy,CurrentTime);
X	XSync(myDpy,True);
X
X#ifndef DEBUG
X	exit(-1);
X#endif
X	switch(sig) {
X		case SIGBUS:	printf("SIGBUS");
X			break;
X		case SIGSEGV:printf("SIGSEGV");
X			break;
X		case SIGILL: printf("SIGILL");
X			break;
X		default: printf("SIG %d",sig);
X		};
X		
X	/* else dump core */
X	signal(SIGBUS,0);
X	signal(SIGSEGV,0);
X	signal(SIGILL,0);
X	abort();
X}
X
Xmain(argc,argv)
Xint	argc;
Xchar	*argv[];
X{
XArg	argList[2];
XPixmap	iconPixmap;
X
X
X	Initialize(argc,argv);
X
X	XtRealizeWidget(toplevel);
X
X	Set_Pointer(toplevel,XC_gumby);
X
X        iconPixmap = XCreateBitmapFromData(XtDisplay(toplevel),
X                XtWindow(toplevel), XIMAGE_ICON, XIMAGE_WIDTH, XIMAGE_HEIGHT);
X        XtSetArg(argList[0],XtNiconPixmap, iconPixmap);
X        XtSetValues(toplevel, argList, 1);
X
X	signal(SIGINT,BreakOut);
X	signal(SIGHUP,BreakOut);
X
X#ifndef DEBUG
X	/* turn off sig trap */
X	signal(SIGBUS,FatalProblem);
X	signal(SIGSEGV,FatalProblem);
X	signal(SIGILL,FatalProblem);
X
X	/* nothing user can do... only developer */
X	/* so don't print it */
X	XtSetWarningMsgHandler(DevNull);
X	XtSetWarningHandler(DevNull);
X#endif
X
X	XtMainLoop();
X}
X
Xvoid Quit(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	ReleaseAllImages();
X	ClosePaletteBox();
X	ReleaseAllAnimations();
X	exit(0);
X}
END-of-main.c
echo file: mem.c
sed 's/^X//' >mem.c << 'END-of-mem.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Intrinsic.h>
X
Xchar *XIMalloc(size) 
Xint size;
X{
Xchar *buff;
X/*
X	printf("About to Malloc %d bytes \n",size);
X	fflush(stdout);
X*/
X
X
X	buff = (char *) XtMalloc(size+512);
X
X#ifdef DEBUG
X/*
X        if (!buff)
X                fprintf(stderr,"Malloc failed for %d bytes\n",size);
X	else
X        	fprintf(stderr,
X                "XIMalloc(): request to malloc %d bytes address %x\n",
X				size,buff);
X*/
X		
X#endif
X
X
X/*
X	printf("Returning from malloc\n");
X	fflush(stdout);
X*/
X	return(buff);
X/*	return((char *) malloc(size));*/
X}
X
Xchar *XICalloc(nelem,elsize)
Xint nelem,elsize;
X{
X/*	return(calloc(nelem+10,elsize));*/
X	return((char *) calloc(nelem,elsize));
X
X} /* XICalloc() */
X
X
Xvoid XIFree(ptr)
Xchar *ptr;
X{
X/*	free(ptr);*/
X#ifndef IRIS4
X	free(ptr);
X#endif
X
X}
END-of-mem.c
echo file: notebook.c
sed 's/^X//' >notebook.c << 'END-of-notebook.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X
X#include <X11/Xlib.h>
X#include <X11/Xatom.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/cursorfont.h>
X
X#ifdef XtSpecificationRelease
X/*R4 */
X#include <X11/Xaw/Form.h>
X#else
X#include <X11/Form.h>
X#endif
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "notebook.h"
X#include "i.h"
X
X#define	NB_DEF_XDIM	400
X#define	NB_DEF_YDIM	300
X#define	NB_TEXT_SPACE	4096
X
Xextern	int	ParseExpr();
Xextern	Widget   toplevelform;
X
Xstatic	Display	*myDpy;
X
Xvoid Notebook();
X
X
XInitNotebook(dpy)
XDisplay *dpy;
X{
X	myDpy = dpy;
X
X	InitRemote();
X
X
X	return(1);
X}
X
X
XNBSetPointerNormal(n)
Xstruct NOTEBOOK *n;
X{
X	Set_Pointer(n->topLevel,XC_gumby);
X	Set_Pointer(n->topComp,XC_gumby);
X	Set_Pointer(n->topForm,XC_gumby);
X	Set_Pointer(n->box1,XC_gumby);
X	Set_Pointer(n->calcButton,XC_hand2);
X/*
X	Set_Pointer(n->saveButton,XC_hand2);
X*/
X	Set_Pointer(n->doneButton,XC_hand2);
X	/*Set_Pointer(n->editWidget,XC_left_ptr);*/
X	Set_Pointer(n->editWidget,XC_xterm);
X	XSync(myDpy,False);
X}
X
X
XNBSetPointerWait(n)
Xstruct NOTEBOOK *n;
X{
X	Set_Pointer(n->topLevel,XC_watch);
X	Set_Pointer(n->topComp,XC_watch);
X	Set_Pointer(n->topForm,XC_watch);
X	Set_Pointer(n->box1,XC_watch);
X	Set_Pointer(n->calcButton,XC_watch);
X/*
X	Set_Pointer(n->saveButton,XC_watch);
X*/
X	Set_Pointer(n->doneButton,XC_watch);
X	Set_Pointer(n->editWidget,XC_watch);
X	XSync(myDpy,False);
X}
X
X
X
Xvoid CBNotebook(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct IMAGE *i;
X	
X	i = (struct IMAGE *) client_data;
X
X	if (i->notebook.notebookShowing) {
X		PrintMesg("Notebook already showing\n");
X		XRaiseWindow(myDpy,XtWindow(i->notebook.topLevel));
X		return;
X		}
X
X	Notebook(&(i->notebook),i->name);
X}
X
X
Xvoid CBDoneNotebook(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct NOTEBOOK *n;
X	n = (struct NOTEBOOK *) client_data;
X
X	if (n->notebookUsed) {
X		/* ask if should save before goes away */
X		}
X
X	XtDestroyWidget(n->topLevel);
X
X	n->notebookShowing = FALSE;
X}
X
X
X
X
Xstatic void CBCalculate2(w,client_data,selection,type,value,length,format)
X/* Got the selection string, now do the calculation */
XWidget  w;
Xcaddr_t client_data;
XAtom	*selection;
XAtom	*type;
Xchar	*value;
Xunsigned long *length;
Xint	*format;
X{
Xstruct NOTEBOOK *n;
Xchar	buff[1024];
X
X	n = (struct NOTEBOOK *) client_data;
X
X	if (*type != XA_STRING) {
X		if (*type == 0)
X		      PrintMesg("Please select formula to calculate first\n");
X		else
X		      PrintMesg("Couldn't get XA_STRING selection type\n");
X		return;
X		}
X	else {
X		if (*length > 512){
X			PrintMesg("Selection to large (max 512 chars)\n");
X			return;
X			}
X		}
X
X	sprintf(buff,"Performing calculation: %s\n",value);
X	PrintMesg(buff);
X	/* Perform calculation */
X
X	NBSetPointerWait(n);
X	ParseExpr(value);
X	NBSetPointerNormal(n);
X
X} /* CBCalculate2() */
X
X
X
Xvoid CBCalculate(w,client_data,call_data)
X/* This callback gets the selection string to calculate then 
X * calls CBCalculate2*/
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct NOTEBOOK *n;
Xchar	buff[1024];
X
X	n = (struct NOTEBOOK *) client_data;
X	XtGetSelectionValue(w,XA_PRIMARY,XA_STRING,CBCalculate2,n,
X				CurrentTime);
X}
X
X
X
X
Xvoid CBSave(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	PrintMesg("Can't save notes yet \n");
X}
X
X
X
Xvoid ClearString(string,length,width)
X/* set to spaces and terminate */
Xchar *string;
Xint length;
Xint width; /* if put \n at width interval */
X{
Xregister char *s;
Xregister int x;
X
X	s = string;
X	length--;
X	for(x =0; x < length;x++)
X		*s++ = ' ';
X	*s = '\0';
X
X	if (width) {
X		s = string;
X		for(x=width; x < length; x+=width) {
X			*s = '\n';
X			s += width;
X			}
X		}
X	
X}
X
X
X
Xvoid Notebook(n,name)
Xstruct NOTEBOOK *n;
Xchar	*name;
X{
Xchar	buff[256];
Xint     xpos,ypos;
XWidget	vport;
Xstatic	Arg setPlace[]={{XtNbottom,(XtArgVal) XtChainBottom},
X			{XtNvertDistance,(XtArgVal) 30}};
X
X	
X	if (!n->hasNotebook) {
X		if (!(n->text = XIMalloc(NB_TEXT_SPACE))) {
X			PrintMesg("Can't Alloc Memory for Notebook text\n");
X			return;
X			}
X
X		ClearString(n->text,NB_TEXT_SPACE,60);
X		n->text[0] = '\0';
X		}
X
X        PlaceWindow(&xpos,&ypos);
X	sprintf(buff,"X Image [Notebook].%s",name);
X	n->topLevel = MakeATopLevel(buff,toplevelform,
X			xpos,ypos,NB_DEF_XDIM,NB_DEF_YDIM);
X
X	n->topComp= MakeForm("Notebook",n->topLevel,0,0,
X				NB_DEF_XDIM,NB_DEF_YDIM,0,0);
X
X	n->box1 = Make_Board("Notebook ctrls",n->topComp,0,0,NB_DEF_XDIM-10,27);
X
X	n->calcButton = MakeButton("Calculate",n->box1,5,2,CBCalculate,n,0,0);
X	/*n->saveButton = MakeButton("Save",n->box1,72,2,CBSave,n,0,0);*/
X	n->doneButton = MakeButton("Done",n->box1,NB_DEF_XDIM-50,2,
X				CBDoneNotebook,n,0,0);
X
X	n->topForm = MakeForm("Form",n->topComp,0,40,NB_DEF_XDIM-10,
X                        NB_DEF_YDIM-37,setPlace,2);
X
X/*
X	vport = MakeVPort("VPort",n->topForm,VERTHORIZ,0,0,NB_DEF_XDIM-10,
X			NB_DEF_YDIM-70);
X*/
X/**/	vport=n->topForm;
X
X
X	n->editWidget = MakeText("Notebook edit",vport,
X			VERTHORIZ,SELECTABLE,STRINGSOURCE,
X			n->text,4096,5,65,NB_DEF_XDIM-20,
X			NB_DEF_YDIM-45);
X
X	NBSetPointerNormal(n);
X
X	n->notebookUsed = TRUE;
X	n->notebookShowing = TRUE;
X
X} /* Notebook() */
X
X
X
XWriteNotebookText(s)
Xchar *s;
X{
X/*	AppendText(n->editWidget,s);*/
X	PrintMesg(s);
X}
END-of-notebook.c
echo file: palentry.c
sed 's/^X//' >palentry.c << 'END-of-palentry.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/cursorfont.h>
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "palentry.h"
X
Xextern Widget   toplevelform;
X/*test*/ extern Colormap fcmap;
Xextern	void	CBInstallCMap();
Xextern	void	CBUnInstallCMap();
Xextern	void	gr_DialogSetValue();
Xextern	void	StoreColors();
X
X#define PEBOX_XDIM	310
X#define PEBOX_YDIM	230
X#define	MAX_COLORS	256
X
X#define	VCDIM		50	/* View color entry box dimension (sqrt) */
X#define	VCDIMX		100
X#define	VCDIMY		50	
X#define	PAL_WIDTH	30
X
Xstatic	unsigned	char	*palImage;
Xstatic	XImage	*palXImage;
X
X
X
Xint InitPalEntry(dpy)
XDisplay *dpy;
X{
XVisual *vis;
Xregister int x;
Xregister int y;
X
X        if ( ! (palImage = (unsigned char *) XIMalloc(PAL_WIDTH*256))) {
X	    printf("Couldn't allocate enough memory for pal entry editor\n");
X            return(0);
X            }
X
X        for(x = 0; x < 256; x++)
X                for(y = 0; y < PAL_WIDTH; y++)
X                        palImage[y*256+ x] = x;
X	vis = GetVisual(dpy);
X        palXImage = XCreateImage(dpy,vis,8,ZPixmap,0,palImage,
X                                256,PAL_WIDTH,8,256);
X        return(1);
X}
X
X
XEditPalEntry(ccells,numColors)
XXColor  ccells[];
Xint     numColors;
X{
Xstatic	struct	PALEDIT p;
X
X	if (numColors > MAX_COLORS) {
X		printf("Can't do more than 256 color pals...remember?\n");
X		return;
X		}
X	MakePalEntryEditor(&p,ccells,numColors);
X}
X
Xvoid CBEditPalEntry(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	EditPalEntry((XColor *)client_data,256);
X}
X
Xstatic void CBDone(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct PALEDIT *p;
X	p = (struct PALEDIT *) client_data;
X
X	XtDestroyWidget((struct PALEDIT *) p->topLevel);
X}
X
Xstatic void CBValuator1(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar    buff[80];
Xstruct PALEDIT *p;
XArg	arglist[2];
Xint	newVal;
X
X        p = (struct PALEDIT *) client_data;
X        newVal = (int) call_data;
X
X
X	p->ccells[p->entry].red = newVal << 8;
X	StoreColors(p->ccells,False,fcmap);
X
X	sprintf(buff,"%d",newVal);
X        XtSetArg(arglist[0],XtNlabel,buff);
X        XtSetValues(p->val1,arglist,1);
X
X}
X
Xstatic void CBValuator2(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar    buff[80];
Xstruct PALEDIT *p;
XArg	arglist[2];
Xint	newVal;
X
X        p = (struct PALEDIT *) client_data;
X        newVal = (int) call_data;
X
X
X	p->ccells[p->entry].green = newVal << 8;
X	StoreColors(p->ccells,False,fcmap);
X
X	sprintf(buff,"%d",newVal);
X        XtSetArg(arglist[0],XtNlabel,buff);
X        XtSetValues(p->val2,arglist,1);
X
X}
X
Xstatic void CBValuator3(w,client_data,call_data)
XWidget  w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar    buff[80];
Xstruct PALEDIT *p;
XArg	arglist[2];
Xint	newVal;
X
X        p = (struct PALEDIT *) client_data;
X        newVal = (int) call_data;
X
X
X	p->ccells[p->entry].blue = newVal << 8;
X	StoreColors(p->ccells,False,fcmap);
X
X	sprintf(buff,"%d",newVal);
X        XtSetArg(arglist[0],XtNlabel,buff);
X        XtSetValues(p->val3,arglist,1);
X
X}
X
X
XCBColorVCE(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct PALEDIT *p;
XDisplay *dpy;
X	
X	dpy = XtDisplay(w);
X	p = (struct PALEDIT *) client_data;
X
X	XSetWindowBackground(dpy,XtWindow(p->vce),p->entry);
X	XClearArea(dpy,XtWindow(p->vce),0,0,VCDIMX,VCDIMY,False);
X}
X
XPalEntryChooser(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;
Xint     win_x,win_y;
Xunsigned int    keys_buttons;
Xstruct	PALEDIT *p;
Xint	v; 
X
X	p = (struct PALEDIT *) client_data;
X        if (XQueryPointer(XtDisplay(w),XtWindow(w),&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X                }
X        if ((win_x > 255) || ( win_x < 0))
X                return;
X	p->entry = win_x;
X
X	sprintf(p->dEntryString,"%3d",p->entry);
X
X	CBColorVCE(w,(caddr_t) p,(caddr_t) 0);
X	gr_DialogSetValue(p->dEntry,p->dEntryString);
X
X	v = p->ccells[p->entry].red >> 8;
X	CBValuator1(w,(caddr_t) p,(caddr_t) v);
X	v = p->ccells[p->entry].green >> 8;
X	CBValuator2(w,(caddr_t) p,(caddr_t) v);
X	v = p->ccells[p->entry].blue >> 8;
X	CBValuator3(w,(caddr_t) p,(caddr_t) v);
X}
X
X
XMakePalEntryEditor(p,ccells,numColors)
Xstruct	PALEDIT *p;
XXColor	ccells[];
Xint	numColors;
X{
Xint     xpos,ypos;
Xint	initE;
XDisplay *dpy;
Xchar	buff[20];
Xint	v1,v2,v3;
XWidget	ebox;
X
X	
X	dpy = XtDisplay(toplevelform);
X	initE = numColors -1;
X	p->ccells = ccells;
X
X	PlaceWindow(&xpos,&ypos);
X        p->topLevel = MakeATopLevel("X Image [Palette.PalEntryEditor]",
X			toplevelform,
X                        xpos,ypos,PEBOX_XDIM,PEBOX_YDIM);
X
X        Set_Pointer(p->topLevel,XC_gumby);
X
X/*#ifdef  NON_ICCCM_WINDOW_MANAGER*/
X        if (appResources.installCMap)
X        	XInstallColormap(dpy,fcmap);
X        /* Make compatible with Release 2 window managers */
X        XtAddEventHandler(p->topLevel,EnterWindowMask,FALSE,
X                        CBInstallCMap,NULL);
X        XtAddEventHandler(p->topLevel,LeaveWindowMask,FALSE,
X                        CBUnInstallCMap,NULL);
X/*#else*/
X
X        XSync(dpy,False);
X	if (!defStaticVisual) {
X                XSetWindowColormap(dpy,XtWindow(p->topLevel),fcmap);
X                XSync(dpy,False);
X		}
X/*#endif*/
X
X	p->composite = Make_Board("palEntryEditor",
X			p->topLevel,0,0,PEBOX_XDIM,PEBOX_YDIM);
X
X	p->composite = Make_Window("X Image [Palette Entry Editor]",
X			p->composite,0,0,PEBOX_XDIM,PEBOX_YDIM);
X
X
X	p->box1 = Make_Board("colors",p->composite,
X			2,22,PEBOX_XDIM-10,95);
X
X/*	{
X	unsigned char *v;
X	int	x;
X	for ( x= 0, v = viewColor; x < VCDIMX*VCDIMY ; x++, v++)
X		*v = initE;
X	}
X*/
X
X	/* vce == View Color Entry  */
X	p->vce = MakeWorkSpace("vce",p->box1,260-VCDIMX,PAL_WIDTH+10,
X			VCDIMX,VCDIMY,CBColorVCE,p,NULL,NULL);
X
X	p->palImage=MakeRasterImage("Palette",p->box1,5,5,palXImage,NULL,NULL);
X        XtAddEventHandler(p->palImage,ButtonMotionMask,0,
X                                PalEntryChooser,p);
X
X        (void) MakeButton("Done",p->box1,265,5,CBDone,p,0,0);
X	
X	p->entry = initE;
X	sprintf(p->dEntryString,"%d",p->entry);
X        ebox = Make_ButtonBox(p->box1,5,PAL_WIDTH+10,PEBOX_XDIM-VCDIMX-60,
X				95 - PAL_WIDTH -20);
X        p->dEntry = Make_Dialog("name",ebox,"Pal Entry:",p->dEntryString,
X                                DSTRINGSIZE,2,2,256-70-VCDIMX,56);
X        MakeButton("  Set   ",ebox,95,4,NULL,p,0,0);
X/*
X	ebox = Make_Board("ebox",p->box1,5,PAL_WIDTH+10,150,27);
X	(void) MakeButton("Palette Entry",ebox,2,4,NULL,NULL,0,0);
X	p->dEntry = MakeTextInput(ebox,95,2,50,20,p->dEntryString);
X	(void) Make_Toggle("rgb",ebox,5,PAL_WIDTH+47,
X			NULL,NULL,NULL,NULL,False);
X*/
X	
X
X	v1 = p->ccells[initE].red >> 8;
X	v2 = p->ccells[initE].green >> 8;
X	v3 = p->ccells[initE].blue >> 8;
X	p->box2 = Make_Board("colors",p->composite,
X			2,122,PEBOX_XDIM-10,PEBOX_YDIM-132);
X
X	p->label1 = Make_Label("red",p->box2,5,10,40);
X	p->slide1 = MakeValuator("slide1",p->box2,50,10,210,20,
X				False,0,MAX_COLORS+9,v1,10,
X				CBValuator1,p,
X				CBValuator1,p,
X				CBValuator1,p);
X	Set_Pointer(p->slide1,XC_sb_h_double_arrow);
X	sprintf(buff,"%d",v1);
X	p->val1	= Make_Label(buff,p->box2,265,10,30);
X
X	p->label2 = Make_Label("green",p->box2,5,40,40);
X	p->slide2 = MakeValuator("slide2",p->box2,50,40,210,20,
X				False,0,MAX_COLORS+9,v2,10,
X				CBValuator2,p,
X				CBValuator2,p,
X				CBValuator2,p);
X	Set_Pointer(p->slide2,XC_sb_h_double_arrow);
X
X	sprintf(buff,"%d",v2);
X	p->val2	= Make_Label(buff,p->box2,265,40,30);
X
X	p->label3 = Make_Label("blue",p->box2,5,70,40);
X	p->slide3 = MakeValuator("slide3",p->box2,50,70,210,20,
X				False,0,MAX_COLORS+9,v3,10,
X				CBValuator3,p,
X				CBValuator3,p,
X				CBValuator3,p);
X	Set_Pointer(p->slide3,XC_sb_h_double_arrow);
X	sprintf(buff,"%d",v3);
X	p->val3	= Make_Label(buff,p->box2,265,70,30);
X	
X
X/*        
X        if (appResources.installCMap)
X		XInstallColormap(dpy,fcmap);
X        XtAddEventHandler(p->topLevel,EnterWindowMask,FALSE,
X                        CBInstallCMap,NULL);
X        XtAddEventHandler(p->topLevel,LeaveWindowMask,FALSE,
X                        CBUnInstallCMap,NULL);
X*/
X
X        XSync(dpy,False);
X	if (!defStaticVisual) {
X                XSetWindowColormap(dpy,XtWindow(p->topLevel),fcmap);
X                XSync(dpy,False);
X		}
X
X}
END-of-palentry.c
echo file: palette.c
sed 's/^X//' >palette.c << 'END-of-palette.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#ifdef XtSpecificationRelease
X#include <X11/Xaw/Viewport.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xw/Xw.h>
X#include <X11/Xw/Toggle.h>
X#else
X/* previous to R4 */
X#include <X11/Viewport.h>
X#include <X11/Form.h>
X#include <X11/Label.h>
X#include <Xw/Xw.h>
X#include <Xw/Toggle.h>
X#endif
X
X#include <stdio.h>
X#include <math.h>
X
X#include "ximage.h"
X#include "buttons.h"
X#include "xstuff.h"
X#include "paletteP.h"
X#include "getfile.h"
X
X#define PALCOMPHEIGHT	100
X#define PAL_WIDTH	28
X
X#ifndef TRUE
X#define TRUE 1
X#endif
X#ifndef FALSE
X#define FALSE 0
X#endif
X
X/* copy a color cell */
X#define cpccell(a,b)	{\
X			a.red = b.red; \
X			a.green = b.green; \
X			a.blue = b.blue;\
X			a.flags = b.flags; \
X			a.pad = b.pad;\
X			}
X
X#define MAX3(a,b,c) ((a>b)&&(a>c)) ? a : ((b > c)? b : c)
X#define MIN3(a,b,c) ((a<b)&&(a<c)) ? a : ((b < c)? b : c)
X#define SIGN(a) ((a)?(a/abs(a)):1) /* return 1 if zero */
X
X
Xextern	Widget	toplevelform;			/* The top dude (composite)*/
Xextern	void	CBEditPalEntry();
Xextern	void	GetAFile();
X
Xunsigned long white;
Xunsigned long black;
X
X/* DTM stuff */
Xchar 	*palPortId;				/* DTM portID to send pal */
Xchar 	sendPalette=FALSE;
Xstatic	int sendPalPort;
X
Xstatic	Display	*myDpy;				/* Display for this program*/
Xstatic	Visual	*myVis;
Xstatic	Widget	top_pal_ctrl_widget;		/* pal ctrl window ap shell*/
Xstatic	Widget	pal_ctrl_widget;		/* composite widget ctrl win*/
Xstatic	XWindowAttributes pcw_attrib;		/* window attributes */
Xstatic	char	pal_loaded	= FALSE;	/* Is the palette loaded */
X/*static*/	Colormap fcmap;
Xstatic	char palette_ctrl_window_showing = FALSE;	/* self explanitory */
Xstatic	XColor	uccells[256];			/* Undo to these colors*/
Xstatic	XColor	bccells[256];			/* Back up copy */
X	XColor	rccells[256];			/* current colors */
X	XColor	origccells[256];		/* original copy */
Xstatic	int	numColors;		/* max num colors on this screen*/
X
Xstatic	char	pal_sfile[80];			/* palette save file name */
Xstatic	char	use_entire_palette=FALSE;
Xstatic	XImage	*palImage;			/* the palette display XImage*/
Xstatic	Widget	pal_image;			/* The palette display window*/
Xstatic	crlastx = 0;
Xstatic	Widget pal_comp;
Xstatic	GC 	pal_comp_gc;
Xstatic	int	comp_pen=0;		/* color to draw new component */
Xstatic	unsigned long comp_pen_dcolor;	/* color to draw comp pen */
Xstatic	int	comp_last_x=0;
Xstatic	int	comp_last_y=0;
Xstatic	XPoint	rpoints[256];		/*drawn red points(CBDrawComponent)*/
Xstatic	XPoint	gpoints[256];		/*drawn green points*/
Xstatic	XPoint	bpoints[256];		/*drawn blue points*/
Xstatic	XPoint	cpoints[256];		/*drawn cyan  */
Xstatic	XPoint	mpoints[256];		/*drawn magenta  */
Xstatic	XPoint	ypoints[256];		/*drawn yellow */
Xstatic	XPoint	hpoints[256];		/*drawn hue */
Xstatic	XPoint	spoints[256];		/*drawn saturation*/
Xstatic	XPoint	vpoints[256];		/*drawn value */
Xstatic	unsigned int	rgbcmyhsv=0;	/* What's plotted (r=(1<<9),v=(1<<1))*/
Xstatic	struct	GetFile	palfile;
Xstatic	palRedraw = FALSE;
X
X
Xvoid	CBInitRotate();
Xvoid	CBEndRotate();
Xvoid	CBReset();
Xvoid	CBEvalExpr();
Xvoid	CBNewLoadPal();
Xvoid	CBSetPen();
Xvoid	CBUnSetPen();
Xvoid	CBPrepChangeComp();
Xvoid	CBChangeComponent();
Xvoid	CBEndChangeComp();
Xvoid	RedrawComponent();
Xvoid	CBLoadPal();
Xvoid	CBTranspose();
Xvoid	TransposeCMap();
Xvoid	CBFiddle();
Xvoid	CRotate();
Xchar	*Get_Save_Pal();
Xint	ChooseColor();
Xvoid	CBRedrawComponents();
Xvoid	CBCompKey();
Xvoid	CBPalSave();
Xvoid	CBUndo();
Xvoid	SaveForUndo();
Xvoid	CBSmooth();
Xvoid	CBInstallCMap();
Xvoid	CBUnInstallCMap();
Xvoid	CBDrawComponent();
Xvoid	CBUnDrawComponent();
Xvoid	ConvertCMapToPalette();
X
Xstatic void PaletteChangeComplete()
X{
X	if (sendPalette) {
X		char pal[768];
X		ConvertCMapToPalette(rccells,pal);
X		SendPalette(sendPalPort,pal);
X		}
X}
X
X
Xvoid StoreColors(ccells,redraw,cmap)
X/* Store colors in colormap */
XXColor	ccells[];	/* colors to be stored */
Xint	redraw;		/* Should I redraw components */
XColormap cmap;		/* colormap to store colors in */
X/* store colors in colormap, except for black & white if 
X * the global variable use_entire_palette is set to false*/
X{
XVisual *vis;
X
X	vis = myVis;
X	if (vis->class == StaticColor) {
X		PrintMesg("Can't set colors for this StaticColor display\n");
X		return;
X		}
X	if (vis->class != PseudoColor) {
X	    PrintMesg("Can't set colors for this non-PseudoColor display\n");
X	    return;
X	    }
X	if (!use_entire_palette) {
X		XColor	inblackcell;
X		XColor	inwhitecell;
X
X		inblackcell = ccells[black];
X		inwhitecell = ccells[white];
X
X		/* restore black and white */
X		ccells[black].red   = (unsigned short) 0;
X		ccells[black].blue  = (unsigned short) 0;
X		ccells[black].green = (unsigned short) 0;
X		ccells[black].flags = DoRed|DoGreen|DoBlue;
X
X		ccells[white].red   = (unsigned short) 65535;
X		ccells[white].blue  = (unsigned short) 65535;
X		ccells[white].green = (unsigned short) 65535;
X		ccells[white].flags = DoRed|DoGreen|DoBlue;
X
X		XStoreColors(myDpy,cmap,ccells,numColors);
X
X		/* take it back out */
X		ccells[black]=inblackcell;
X		ccells[white]=inwhitecell;
X		}
X	else
X		XStoreColors(myDpy,cmap,ccells,numColors);
X
X	if (redraw)
X		RedrawComponent();
X
X	return;
X} /* StoreColors() */
X
X
X
Xstatic void CBUseEntirePalette(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	use_entire_palette = ! use_entire_palette;
X	StoreColors(rccells,TRUE,fcmap);
X	PaletteChangeComplete();
X
X	if (use_entire_palette) {
X                SetToggleString(w,"Use entire palette");
X                SetToggle(w,True);
X		}
X	else {
X                SetToggleString(w,"Don't use entire palette");
X                SetToggle(w,True);
X		}
X}
X
X
Xvoid ClosePaletteBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X/*	XtUnmanageChild(top_pal_ctrl_widget);*/
X	if (palette_ctrl_window_showing) {
X		CBUnInstallCMap(top_pal_ctrl_widget,NULL,NULL);
X		XtDestroyWidget(top_pal_ctrl_widget);
X		}
X
X
X	palette_ctrl_window_showing = FALSE;
X}
X
Xint InitPalette(dpy)
XDisplay *dpy;
X{
Xint x;
Xint screen;
X
X	myDpy = dpy;
X	myVis = GetVisual(dpy);
X	screen = DefaultScreen(dpy);
X
X	white = WhitePixel(dpy,screen);
X	black = BlackPixel(dpy,screen);
X
X	numColors = XDisplayCells(dpy,screen);
X	if (numColors > 256) {
X		numColors = 256;   /* only use max 256 color entries */
X		}
X
X	/* Create startup default palette (use X servers) */ 
X	for(x=0;x < 256; x++)
X		origccells[x].pixel = x;
X	XQueryColors(dpy,DefaultColormap(dpy,screen),
X			origccells,numColors);
X	for(x=0;x < 256; x++) {
X		rccells[x].pixel = x;
X		cpccell(rccells[x],origccells[x]);
X		cpccell(uccells[x],origccells[x]);
X		}
X
X	if (!(palImage = MakePalette(myDpy,PAL_WIDTH,TRUE)))
X		return(0);
X
X	if (sendPalette) {
X		if (-1 == (sendPalPort = MakeWriteConnection(palPortId))) {
X			sendPalette = FALSE;
X			}
X		}
X
X	return(1); /* initialize ok */
X}
X
X
Xvoid CBInitPal(w,client_data,call_data)
X/* This procedure called on exposure of palette control window*/
X/* Sets the colormap for the window */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay *dpy;
X
X	w = top_pal_ctrl_widget;
X/*	printf("CBInitPal() I've been called\n");*/
X	fflush(stdout);
X	dpy = XtDisplay(w);
X	XSync(dpy,False);
X
X	if (!defStaticVisual)
X		XSetWindowColormap(dpy,XtWindow(w),fcmap);
X
X	XtRemoveEventHandler(w,ExposureMask,0,CBInitPal,NULL);
X
X	/* I don't think this command should be here, but it seems *
X	 * to make it work.....oh well... 			   *
X	 * Shake up the ICCCM window manager maybe? 		   */
X/*
X	if (appResources.installCMap)
X		XInstallColormap(dpy,fcmap);
X*/
X
X	if (!defStaticVisual) {
X		XSetWindowColormap(dpy,XtWindow(w),fcmap);
X		XSync(dpy,False);
X		}
X
X}
X
X
Xvoid PaletteBox(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWidget	buttonbox1;
XWidget	buttonbox2;
XWidget	buttonbox3;
XDisplay *dpy;
XVisual	*vis;
Xint x;
Xint	xpos,ypos;
X
X	if (palette_ctrl_window_showing) {
X		PrintMesg("Palette window already open\n");
X		XRaiseWindow(myDpy,XtWindow(top_pal_ctrl_widget));
X		return;
X		}
X
X	dpy = XtDisplay(toplevelform);
X	vis = GetVisual(myDpy);
X	if (vis->class != PseudoColor) {
X		PrintMesg("Can't use X Image Palette on this display.\n");
X		PrintMesg("Not a Pseudo Color device\n");
X		return;
X		}
X/*
X	if ( DisplayPlanes(dpy,XDefaultScreen(dpy)) != 8 ) {
X		PrintMesg("Can't use X Image Palette on this display.\n");
X		PrintMesg("Not an 8 bit display\n");
X		return;
X		}
X*/
X		
X
X	PrintMesg("Opening Palette Box\n");
X
X	rgbcmyhsv = 0;
X	comp_pen = 0;
X	comp_last_x = comp_last_y = 0;
X	crlastx = 0;
X
X	PlaceWindow(&xpos,&ypos);
X	top_pal_ctrl_widget = MakeATopLevel("NCSA X Image [Palette]",
X				toplevelform,xpos,ypos,360,285+PALCOMPHEIGHT);
X	pal_ctrl_widget = Make_Window("NCSA X Image [Palette]",
X				top_pal_ctrl_widget,5,5,360,285+PALCOMPHEIGHT);
X/**/	XSync(dpy,False);
X/*
X	for(x=0;x < 256; x++)
X		origccells[x].pixel = x;
X	XQueryColors(dpy,DefaultColormap(dpy,DefaultScreen(dpy)),
X			origccells,numColors);
X	for(x=0;x < 256; x++) {
X		uccells[x].pixel = rccells[x].pixel = x;
X		cpccell(rccells[x],origccells[x]);
X		cpccell(uccells[x],origccells[x]);
X		}
X*/
X
X	fcmap = XCreateColormap(dpy, XtWindow(top_pal_ctrl_widget),
X			GetVisual(dpy),AllocAll);
X	StoreColors(rccells,TRUE,fcmap);
X
X
X	/* Make compatible with Release 2 window managers */
X	XtAddEventHandler(top_pal_ctrl_widget,EnterWindowMask,FALSE,
X			CBInstallCMap,NULL);
X	XtAddEventHandler(top_pal_ctrl_widget,LeaveWindowMask,FALSE,
X			CBUnInstallCMap,NULL);
X
X	if (!defStaticVisual) {
X		XSetWindowColormap(dpy,XtWindow(top_pal_ctrl_widget),fcmap);
X		XSync(dpy,False);
X		}
X
X        XtAddEventHandler(pal_ctrl_widget,ExposureMask,0,CBInitPal,NULL);
X
X	buttonbox1 = Make_ButtonBox(pal_ctrl_widget,1,200+PALCOMPHEIGHT,
X					355,80);
X	b[PAL_LOAD] = MakeButton("Load",buttonbox1,5,1,CBNewLoadPal,NULL,0,0);
X	b[PAL_RESET] = MakeButton("Reset",buttonbox1,40,1,CBReset,NULL,0,0);
X	(void) MakeButton("Undo",buttonbox1,83,1,CBUndo,NULL,0,0);
X	b[PAL_SMOOTH] = MakeButton("Smooth",buttonbox1,300,1,
X				CBSmooth,&comp_pen,0,0);
X/*
X	(void) MakeButton("Edit Pal Entry",buttonbox1,142,1,CBEditPalEntry,
X					rccells,0,0);
X*/
X#ifdef UNDER_DEVELOPMENT
X	b[PAL_EVAL] = MakeButton("Eval Expr",buttonbox1,240,1,
X				CBEvalExpr,NULL,0,0);
X#endif
X
X
X
X	b[PAL_SAVE] = MakeButton("Save",buttonbox1,5,30,CBPalSave,NULL,0,0);
X	pal_sfile[0]='\0';
X	(void)Make_Text_Inp("pal_save_file",buttonbox1,
X			pal_sfile,80,45,32,300,20,
X			CBPalSave,NULL);
X
X	(void)MakeAltToggle("Don't use entire palette",buttonbox1,45,60,
X			CBUseEntirePalette,NULL,CBUseEntirePalette,NULL);
X/*	(void)MakeAltToggle("Lock in palette",buttonbox1,210,60,
X			NULL,NULL,NULL,NULL);
X*/
X
X	buttonbox2 = Make_ButtonBox(pal_ctrl_widget,1,60+PALCOMPHEIGHT,
X					80,135);
X	(void)	Make_Label("Wholistic",buttonbox2,1,1,78);
X	b[PAL_FIDDLE] = MakeButton("Fiddle",buttonbox2,5,25,CBFiddle,NULL,0,0);
X	b[PAL_INVERT] = MakeButton("Flip",buttonbox2,5,55,CBTranspose,NULL,0,0);
X/*b[PAL_T_ROTATE] =MakeButton("Track Rotate",buttonbox2,70,25,
X			CBRotate,NULL,0,0);*/
X/*	b[PAL_ROTATE] = MakeButton("Rotate",buttonbox2,5,85,NULL,NULL,0,0);*/
X	Set_Pointer(buttonbox2,XC_hand2);
X
X	buttonbox3 = Make_ButtonBox(pal_ctrl_widget,85,60+PALCOMPHEIGHT,
X					270,135);
X	(void)Make_Label("Component Palette Manipulation",buttonbox3,1,1,268);
X	b[PAL_PRED] = Make_Toggle("",buttonbox3,5,25,
X				CBDrawComponent,CRED,
X				CBUnDrawComponent,CRED,True,False);
X	b[PAL_RED] = Make_Toggle("Red",buttonbox3,25,25,
X				CBSetPen,CRED,CBUnSetPen,CRED,False,False);
X	b[PAL_PGREEN] = Make_Toggle("",buttonbox3,5,55,
X				CBDrawComponent,CGREEN,
X				CBUnDrawComponent,CGREEN,True,False);
X	b[PAL_GREEN] = Make_Toggle("Green",buttonbox3,25,55,
X				CBSetPen,CGREEN,CBUnSetPen,CGREEN,False,False);
X	b[PAL_PBLUE] = Make_Toggle("",buttonbox3,5,85,
X				CBDrawComponent,CBLUE,
X				CBUnDrawComponent,CBLUE,True,False);
X	b[PAL_BLUE] = Make_Toggle("Blue",buttonbox3,25,85,
X				CBSetPen,CBLUE,CBUnSetPen,CBLUE,False,False);
X	b[PAL_PCYAN] = Make_Toggle("",buttonbox3,80,25,
X				CBDrawComponent,CCYAN,
X				CBUnDrawComponent,CCYAN,True,False);
X	b[PAL_CYAN] = Make_Toggle("Cyan",buttonbox3,100,25,
X				CBSetPen,CCYAN,CBUnSetPen,CCYAN,False,False);
X	b[PAL_PMAGENTA] = Make_Toggle("",buttonbox3,80,55,
X				CBDrawComponent,CMAGENTA,
X				CBUnDrawComponent,CMAGENTA,True,False);
X	b[PAL_MAGENTA] = Make_Toggle("Magenta",buttonbox3,100,55,
X				CBSetPen,CMAGENTA,CBUnSetPen,CMAGENTA,
X				False,False);
X	b[PAL_PYELLOW] = Make_Toggle("",buttonbox3,80,85,
X				CBDrawComponent,CYELLOW,
X				CBUnDrawComponent,CYELLOW,True,False);
X	b[PAL_YELLOW] = Make_Toggle("Yellow",buttonbox3,100,85,
X				CBSetPen,CYELLOW,CBUnSetPen,CYELLOW,
X				False,False);
X	b[PAL_PHUE] = Make_Toggle("",buttonbox3,170,25,
X				CBDrawComponent,CHUE,
X				CBUnDrawComponent,CHUE,True,False);
X	b[PAL_HUE] = Make_Toggle("Hue",buttonbox3,190,25,
X				CBSetPen,CHUE,CBUnSetPen,CHUE,False,False);
X	b[PAL_PSATURATION] = Make_Toggle("",buttonbox3,170,55,
X				CBDrawComponent,CSATURATION,
X				CBUnDrawComponent,CSATURATION,True,False);
X	b[PAL_SATURATION] = Make_Toggle("Saturation",buttonbox3,190,55,
X				CBSetPen,CSATURATION,CBUnSetPen,CSATURATION,
X				False,False);
X	b[PAL_PVALUE] = Make_Toggle("",buttonbox3,170,85,
X				CBDrawComponent,CVALUE,
X				CBUnDrawComponent,CVALUE,True,False);
X	b[PAL_VALUE] = Make_Toggle("Value",buttonbox3,190,85,
X				CBSetPen,CVALUE,CBUnSetPen,CVALUE,
X				False,False);
X	Set_Pointer(buttonbox3,XC_hand2);
X
X	b[PAL_DONE]=MakeButton("Done",pal_ctrl_widget,320,25,
X				ClosePaletteBox,NULL,0,0);
X
X/*        pal_image = Make_Pal_Window(pal_ctrl_widget,47,23,255,28);*/
X	pal_image = MakeRasterImage("PaletteDisplay",pal_ctrl_widget,
X				47,23,palImage,NULL,NULL);
X
X	pal_comp = Make_Board("Palette_Components",pal_ctrl_widget,47,55,255,
X				PALCOMPHEIGHT+2);
X	pal_comp = MakeWorkSpace("Palette Components",pal_ctrl_widget,
X				47,55,255,PALCOMPHEIGHT+2,
X				CBRedrawComponents,NULL,
X				CBCompKey,NULL);
X	/*(void) MakeImageWindow("Palette_comp_canvas",&pal_comp_image,white,
X				pal_comp,0,0,255,PALCOMPHEIGHT);
X	*/
X	{
X	static XGCValues gcvalues;
X	gcvalues.foreground = black;
X	gcvalues.background = white;
X	pal_comp_gc = XtGetGC(pal_comp,(GCForeground|GCBackground),&gcvalues);
X	}
X
X	
X	/* Component palette display window drawing */
X	XtAddEventHandler(pal_comp,ButtonPressMask,0,
X			CBPrepChangeComp,NULL );
X        XtAddEventHandler(pal_comp,Button1MotionMask,0,
X			CBChangeComponent,NULL );
X	XtAddEventHandler(pal_comp,ButtonReleaseMask|LeaveWindowMask,0,
X			CBEndChangeComp,NULL );
X	Set_Pointer(pal_comp,XC_pencil);
X
X
X        XtAddEventHandler(pal_image,ButtonPressMask,0,CBInitRotate,NULL );
X        XtAddEventHandler(pal_image,Button1MotionMask,0,CRotate,NULL );
X        XtAddEventHandler(pal_image,ButtonReleaseMask,0,CBEndRotate,NULL );
X        Set_Pointer(pal_image,XC_sb_h_double_arrow);
X
X	XSync(dpy,False);
X	StoreColors(rccells,TRUE,fcmap);
X	XSync(dpy,False);
X/*
X        if (appResources.installCMap)
X		XInstallColormap(dpy,fcmap);
X*/
X
X	palette_ctrl_window_showing = TRUE;
X
X	PaletteChangeComplete();
X
X	return;
X
X
X} /* PaletteBox() */
X
X
X
Xstatic void CBRedrawComponents(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	RedrawComponent();
X}
X
Xstatic void CBCompKey(w,client_data,call_data)
X/* this routine is suppose to set which component to draw with 
X * but the HP workspace widget doesn't seem to be returning anything
X * meaningful when a key pressed.... either that or I don't know how
X * to use it. 
X */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X/*	printf("Just pressed %d key(call_data)\n",(int) call_data);
X	printf("Just pressed %c key(call_data)\n",(char *) call_data);
X	printf("Just pressed %d key(client_data)\n",(int) client_data);
X*/
X	/* will use CBSetPen() */
X	/* then set the toggle */
X}
X
Xstatic void CBTranspose(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	TransposeCMap();
X	PaletteChangeComplete();
X	return;
X}
X
Xvoid CBInstallCMap(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X        if (appResources.installCMap)
X		XInstallColormap(XtDisplay(w),fcmap);
X}
X
Xvoid CBUnInstallCMap(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X        if (appResources.installCMap)
X		XUninstallColormap(XtDisplay(w),fcmap);
X}
X
Xstatic void CBEndRotate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	PaletteChangeComplete();
X}
X
Xstatic void CBInitRotate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint	root_x,root_y;
Xint	win_x,win_y;
Xunsigned int	keys_buttons;
X
X	SaveForUndo(rccells);
X	if (XQueryPointer(XtDisplay(w),XtWindow(w),&root,&child,
X		&root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X		crlastx = win_x;
X		}
X}
X
Xstatic void GotPalFile()
X{
X	CBLoadPal(top_pal_ctrl_widget,NULL,NULL);
X	PaletteChangeComplete();
X}
X
Xstatic void DidntGetPalFile()
X{
X	PrintMesg("Palette load canceled\n");
X}
X
Xstatic void CBNewLoadPal(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	palfile.type = FTYPE_PAL;
X	palfile.yesfile = GotPalFile;
X	palfile.nofile = DidntGetPalFile;
X	GetAFile(&palfile);
X}
X
X
X
Xstatic void CBLoadPal(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint x;
Xchar fileName[512];
X
X	SaveForUndo(rccells);
X
X        sprintf(fileName,"%s/%s",palfile.directory,*(palfile.file));
X	if (! palfile.isHDF) {
X		if(! ReadSEQPalette(fileName,origccells))
X			return;	/* Error reading Colormap */
X		}
X	else {
X		if(! ReadHDFPalette(fileName,origccells))
X			return;	/* Error reading Colormap */
X		}
X
X	for(x=0; x < 256 ; x++) {
X                rccells[x].pixel = x;
X                cpccell(rccells[x],origccells[x]);
X                }
X
X        StoreColors(rccells,TRUE,fcmap);
X
X
X	pal_loaded = TRUE;
X	return;
X
X} /* CBLoadPal() */
X
Xvoid ConvertHSVtoRGB(h,s,v,pr,pg,pb)
Xdouble h; /* 0.0 to 360.0 */
Xdouble s; /* 0.0 to 1.0 */
Xdouble v; /* 0.0 to 1.0 */
Xunsigned short *pr,*pg,*pb; /* 0 to 65535 */
X{
Xdouble r,g,b;
Xint i;
Xdouble f;
Xdouble p1,p2,p3;
X
X	r = ((double) *pr) / (double) 65535.0;
X	g = ((double) *pg) / (double) 65535.0;
X	b = ((double) *pb) / (double) 65535.0;
X
X	if (h == 360.0)
X		h = 0.0;
X
X	h = h / 60.0;
X
X	i = (int) h;
X	f = h - ((double) i);
X
X	p1 = v * (1.0 - s);
X	p2 = v * (1.0 - (s * f));
X	p3 = v * (1.0 - (s * (1.0 - f)));
X
X	switch (i) {
X		case 0:
X			r = v; g = p3; b = p1;
X			break;
X		case 1:
X			r = p2; g = v; b = p1;
X			break;
X		case 2:
X			r = p1; g = v; b = p3;
X			break;
X		case 3:
X			r = p1; g = p2; b = v;
X			break;
X		case 4:
X			r = p3; g = p1; b = v;
X			break;
X		case 5:
X			r = v; g = p1; b = p2;
X			break;
X		}
X
X	*pr = (unsigned short) (r * 65535.0);
X	*pg = (unsigned short) (g * 65535.0);
X	*pb = (unsigned short) (b * 65535.0);
X
X} /* ConvertHSVtoRGB */
X
Xint ConvertRGBtoHSV(pr,pg,pb,h,s,v)
X/* will return 0 if hue is undefined else return 1*/
Xunsigned short pr,pg,pb; /* 0 to 65535 */
Xdouble	*h; /* between 0.0 and 360.0 */
Xdouble	*s; /* between 0.0 and 1.0 */
Xdouble	*v; /* between 0.0 and 1.0 */
X{
Xdouble	r,g,b;
Xdouble	range;
Xdouble	min;
Xdouble  rl,gl,bl;
X
X	r = ((double)pr) / (double)65535.0;
X	g = ((double)pg) / (double)65535.0;
X	b = ((double)pb) / (double)65535.0;
X
X	*v  = MAX3(r,g,b);
X	min = MIN3(r,g,b);
X
X	range = *v - min;
X
X	if (*v)
X		*s = range / *v;
X	else
X		*s = 0;
X
X        if (*s) {
X		rl = (*v - r) / range;
X		gl = (*v - g) / range;
X		bl = (*v - b) / range;
X
X	        if ( *v == r ) {
X			if ( min == g)
X				*h = 5.0 + bl;
X			else
X				*h = 1.0 - gl;
X	                }
X		else {
X			if ( *v == g) {
X				if ( min == b)
X					*h = 1.0 + rl;
X				else
X					*h = 3.0 - bl;
X				}
X			else {
X				if (min == r)
X					*h = 3.0 + gl;
X				else
X					*h = 5.0 - rl;
X				}
X			}
X		*h = *h * 60.0;
X		} /* if (*s)
X	else
X		return(0); /* h is undefined */
X
X	return(1);
X	
X} /* ConvertRGBtoHSV() */
X
X
X
Xstatic void DrawComponent(component)
X/* Draw the color components in the component window */
Xint	component;	/* which component to draw */
X{
Xint x;
Xint y;
XXGCValues	gcval;
X
X        gcval.foreground = ChooseColor(rccells,component);
X        XChangeGC(XtDisplay(pal_comp), pal_comp_gc, GCForeground, &gcval);
X	switch (component){
X		case CRED :
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].red >> 8)* 
X						(float) (100.0 / 255.0));
X				rpoints[x].x = x;
X				rpoints[x].y = 100 - y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,rpoints,256,CoordModeOrigin);
X			break;
X		case CGREEN:
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].green >> 8)* 
X						(float) (100.0 / 255.0));
X				gpoints[x].x = x;
X				gpoints[x].y = 100 - y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,gpoints,256,CoordModeOrigin);
X			break;
X		case CBLUE:
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].blue >> 8)* 
X						(float) (100.0 / 255.0));
X				bpoints[x].x = x;
X				bpoints[x].y = 100 -y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,bpoints,256,CoordModeOrigin);
X			break;
X		case CCYAN:
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].red >> 8)* 
X						(float) (100.0 / 255.0));
X				cpoints[x].x = x;
X				cpoints[x].y = y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,cpoints,256,CoordModeOrigin);
X			break;
X		case CMAGENTA:
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].green >> 8)* 
X						(float) (100.0 / 255.0));
X				mpoints[x].x = x;
X				mpoints[x].y = y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,mpoints,256,CoordModeOrigin);
X			break;
X		case CYELLOW:
X			for (x = 0 ; x < 256 ; x++ ) {
X				y = (int) ((float) (rccells[x].blue >> 8)* 
X						(float) (100.0 / 255.0));
X				ypoints[x].x = x;
X				ypoints[x].y = y;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,ypoints,256,CoordModeOrigin);
X			break;
X		case CHUE: {
X			double h,s,v;
X			for (x= 0; x < 256; x++ ) {
X				if (!ConvertRGBtoHSV(rccells[x].red,
X					rccells[x].green,rccells[x].blue,
X					&h,&s,&v)) {
X					h = 0; /* undefined */
X					}
X		
X				y = (int) ((double)(h * (100.0 / 360.0)));
X				hpoints[x].x = x;
X				hpoints[x].y = 100 - y;
X				} 
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,hpoints,256,CoordModeOrigin);
X			}
X			break; /*CHUE*/
X		case CSATURATION: {
X			int r,g,b;
X			int s;
X			int max,min;
X
X			for (x = 0 ; x < 256 ; x++ ) {
X				r = (int) (((float) (rccells[x].red >> 8))* 
X						(float) (100.0 / 255.0));
X				g = (int) (((float) (rccells[x].green >> 8))* 
X						(float) (100.0 / 255.0));
X				b = (int) (((float) (rccells[x].blue >> 8))* 
X						(float) (100.0 / 255.0));
X
X				max = MAX3(r,g,b);
X				min = MIN3(r,g,b);
X
X				if (max != 0)
X		    		    s=(int)(100.0 *(((float) (max - min)) / 
X						((float) max)));
X				else
X				     s = 0;
X		
X				spoints[x].x = x;
X				spoints[x].y = 100 - s;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,spoints,256,CoordModeOrigin);
X			}
X			break;
X		case CVALUE: {
X			int r,g,b;
X			int value;
X			for (x = 0 ; x < 256 ; x++ ) {
X				r = (int) ((float) (rccells[x].red >> 8)* 
X						(float) (100.0 / 255.0));
X				g = (int) ((float) (rccells[x].green >> 8)* 
X						(float) (100.0 / 255.0));
X				b = (int) ((float) (rccells[x].blue >> 8)* 
X						(float) (100.0 / 255.0));
X
X				value = (int) MAX3(r,g,b);
X
X				vpoints[x].x = x;
X				vpoints[x].y = 100 - value;
X				}
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,vpoints,256,CoordModeOrigin);
X			}
X			break;
X		} /* switch */
X
X			
X	
X	rgbcmyhsv = rgbcmyhsv | component;
X	return;
X	
X} /* DrawComponent() */
X
Xstatic void CBDrawComponent(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	DrawComponent((int) client_data);
X}
X
X
Xstatic void UnDrawComponent(component)
Xint component;
X{
XXGCValues	gcval;
Xstatic	Arg arglist[]={{XtNset,(XtArgVal) True}};
X
X        gcval.foreground = white;
X        XChangeGC(XtDisplay(pal_comp), pal_comp_gc, GCForeground, &gcval);
X	switch (component) {
X		case CRED:
X			if ((comp_pen == CRED) && (! palRedraw)){
X				XtSetValues(b[PAL_PRED],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,rpoints,256,CoordModeOrigin);
X			break;
X		case CGREEN:
X			if ((comp_pen == CGREEN) && (! palRedraw)){
X				XtSetValues(b[PAL_PGREEN],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,gpoints,256,CoordModeOrigin);
X			break;
X		case CBLUE:
X			if ((comp_pen == CBLUE) && (! palRedraw)){
X				XtSetValues(b[PAL_PBLUE],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,bpoints,256,CoordModeOrigin);
X			break;
X		case CCYAN:
X			if ((comp_pen == CCYAN) && (! palRedraw)){
X				XtSetValues(b[PAL_PCYAN],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,cpoints,256,CoordModeOrigin);
X			break;
X		case CMAGENTA:
X			if ((comp_pen == CMAGENTA) && (! palRedraw)){
X				XtSetValues(b[PAL_PMAGENTA],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,mpoints,256,CoordModeOrigin);
X			break;
X		case CYELLOW:
X			if ((comp_pen == CYELLOW) && (! palRedraw)){
X				XtSetValues(b[PAL_PYELLOW],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,ypoints,256,CoordModeOrigin);
X			break;
X		case CHUE:
X			if ((comp_pen == CHUE) && (! palRedraw)){
X				XtSetValues(b[PAL_PHUE],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,hpoints,256,CoordModeOrigin);
X			break;
X		case CSATURATION:
X			if ((comp_pen == CSATURATION) && (! palRedraw)){
X				XtSetValues(b[PAL_PSATURATION],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,spoints,256,CoordModeOrigin);
X			break;
X		case CVALUE:
X			if ((comp_pen == CVALUE) && (! palRedraw)){
X				XtSetValues(b[PAL_PVALUE],arglist,1);
X				return;
X				}
X
X			XDrawPoints(XtDisplay(pal_comp),XtWindow(pal_comp),
X				pal_comp_gc,vpoints,256,CoordModeOrigin);
X			break;
X	} /* switch */
X
X	rgbcmyhsv = rgbcmyhsv ^ (rgbcmyhsv & component) ;
X	if (! palRedraw)
X		RedrawComponent();
X
X} /* UnDrawComponent() */
X
Xstatic void CBUnDrawComponent(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	UnDrawComponent((int) client_data);
X}
X
X
X
Xstatic void CBReset(w,client_data,call_data)
X/* Set colormap back to last loaded colors */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint x;
X	SaveForUndo(rccells);
X	for(x=0; x < 256 ; x++) {
X		rccells[x].pixel = x;
X		cpccell(rccells[x],origccells[x]);
X		}
X	RedrawComponent();
X	StoreColors(rccells,TRUE,fcmap);
X	PaletteChangeComplete();
X} /* CBReset() */
X
X/*
Xstatic void CBEvalExpr(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	* Not working yet, but we'll blame it on the user for
X	   not knowing how to use this feature *
X
X	PrintMesg("Bad expression in cut/paste buffer\n");
X}
X*/
X
X
Xstatic void TransposeCMap()
X/* Flip the colormap:  (0<-> 255, 1<->254, etc.)*/
X{
Xint	x;
XXColor	tmp;
X
X	SaveForUndo(rccells);
X	for (x=0; x < 128 ;x++) {
X		cpccell(tmp,rccells[255-x]);
X		cpccell(rccells[255-x],rccells[x]);
X		cpccell(rccells[x],tmp);
X		}
X	StoreColors(rccells,TRUE,fcmap);
X	PaletteChangeComplete();
X
X	return;
X
X} /* TransposeCMap() */
X
X
Xstatic void FiddlePalette(w,xdim,ydim,xpos,ypos)
XWidget w;
Xint	xdim,ydim;
Xint	xpos,ypos;
X{
Xdouble a,b;
Xdouble unit_Theta = (double) 3.14159 / (double) (ydim*2);
Xdouble up,down;
Xregister int prej,i,j,k;
Xint	NUMCOLORS = 256;
X
X	xpos = (((xpos < 0)?0:xpos)>xdim)?xdim:xpos;
X	ypos = (((ypos < 0)?0:ypos)>ydim)?ydim:ypos;
X
X	a = (double) tan((double) (unit_Theta * (double) (ydim - ypos)));
X
X	up = 1 + (short) (127.0 * a);
X	down = 256 - (short) (128.0 * a);
X	if (up > down)
X		b = (((double)xpos / (double)xdim) * (double)(up - down))
X			 + (double) down;
X	else
X		b = (((double)xpos / (double)xdim) * (double)(down - up))
X			 + (double) up;
X	
X	prej = 1;
X
X	for ( i = 1 ; i <= NUMCOLORS - 2 ; i++) {
X	    j = (short) (a * (double) (i - (NUMCOLORS/2)) + b);
X	    if ((j > 0) && (j <= NUMCOLORS-2)) {
X		for ( k = prej; k <= j - 1 ; k++)
X		   /*if((rccells[k].pixel!=white)&&(rccells[k].pixel!=black))*/
X				cpccell(rccells[k],bccells[i]);
X		/*if ((rccells[j].pixel!=white)&&(rccells[j].pixel!=black))*/
X			cpccell(rccells[j],bccells[i]);
X		}
X	    else
X		if (j >= NUMCOLORS-1) {
X			for ( k = prej; k <= NUMCOLORS-2; k++)
X				/*if ((rccells[k].pixel!=white)
X				    &&(rccells[k].pixel!=black))*/
X					cpccell(rccells[k],bccells[i]);
X			break;
X			}
X		else
X			continue;
X
X	    prej = j + 1;
X 	    }
X
X	for(;j < NUMCOLORS;j++) 
X		/*ccells[j].pixel = bccells[255].pixel;*/
X		cpccell(rccells[j],bccells[255]);
X
X        StoreColors(rccells,TRUE,fcmap);
X}
X
Xstatic void Cfiddle(w,client_data,call_data)
X/* Do linear expansion and compression on palette */
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint	root_x,root_y;
Xint	win_x,win_y;
Xunsigned int	keys_buttons;
X
X	if (XQueryPointer(XtDisplay(w),XtWindow(w),&root,&child,
X	    &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X		FiddlePalette(w,pcw_attrib.width,pcw_attrib.height,
X			win_x,win_y);
X		}
X
X} /* Cfiddle() */
X
X
Xstatic void CBPrepFiddle(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	x;
X	SaveForUndo(rccells);
X	for (x=0; x< 256 ; x++) {
X		cpccell(bccells[x],rccells[x]);
X		bccells[x].pixel = rccells[x].pixel;
X		}
X}
X
Xstatic void CBEndFiddle(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;	/* X & Y coordinates with respect to root */
Xint     win_x,win_y;	/* X & Y coordinates with respect to window */
Xunsigned int    keys_buttons;
Xint	win;
X
X	win = XtWindow(w);
X
X        if (XQueryPointer(XtDisplay(w),win,&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X		XWarpPointer(XtDisplay(w),win,win,win_x,win_y,
X		pcw_attrib.width,pcw_attrib.height,30,200);
X		}
X	XUngrabPointer(XtDisplay(w),CurrentTime);
X        XtRemoveEventHandler(pal_ctrl_widget,Button1MotionMask,0,Cfiddle,NULL);
X	XtRemoveEventHandler(pal_ctrl_widget,ButtonReleaseMask,0,
X			CBEndFiddle,NULL);
X	PaletteChangeComplete();
X} /* CBEndFiddle() */
X
X
Xstatic void CBFiddle(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	if(XGrabPointer(XtDisplay(w),XtWindow(pal_ctrl_widget),False,
X		PointerMotionMask|ButtonReleaseMask,
X		GrabModeAsync,GrabModeSync,
X		XtWindow(pal_ctrl_widget),
X		XCreateFontCursor(XtDisplay(w),XC_fleur),
X		CurrentTime)) {
X			PrintMesg("Can't grab pointer for fiddle\n");
X			return;
X			}
X
X        XtAddEventHandler(pal_ctrl_widget,Button1MotionMask,0,Cfiddle,NULL );
X	XtAddEventHandler(pal_ctrl_widget,ButtonReleaseMask,0,
X			CBEndFiddle,NULL);
X
X	CBPrepFiddle(pal_ctrl_widget,NULL,NULL);
X
X
X	XGetWindowAttributes(XtDisplay(w),XtWindow(pal_ctrl_widget),
X			&pcw_attrib);
X} /* CBFiddle() */
X
Xstatic RotatePalette(w,xdim,ydim,xpos,ypos)
XWidget w;
Xint xdim,ydim;
Xint xpos,ypos;
X{
Xint offset;
Xint x;
Xint new;
X
X	if ((crlastx)&& (crlastx != xpos)) {
X		for(x = 0;x < 256; x++)
X			cpccell(bccells[x],rccells[x]);
X
X		offset = xpos - crlastx;
X
X		for(x=0; x < 256; x++) {
X			new = x + offset;
X			new = (new > 255) ? (new - 256) : 
X					(new < 0) ? (new + 256): new;
X			cpccell(rccells[new],bccells[x]);
X			}
X
X		StoreColors(rccells,TRUE,fcmap);
X		}
X	crlastx = xpos;
X	return;
X
X} /* RotatePalette() */
X
X
Xstatic void CRotate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;	/* X & Y coordinates with respect to root */
Xint     win_x,win_y;	/* X & Y coordinates with respect to window */
Xunsigned int    keys_buttons;
X
X        if (XQueryPointer(XtDisplay(w),XtWindow(w),&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X
X		if ((win_x <= 255) && (win_x > 0))
X	                RotatePalette(w,255,28,win_x,win_y);
X                }
X}
X
X
X
X
Xvoid Terminate(s)
Xchar *s;
X{
X        while (*s > ' ')
X                s++;
X        *s='\0';
X	return;
X}
Xstatic char *Get_Save_Pal()
X{
X        Terminate(pal_sfile);
X        return(pal_sfile);
X}
X
X
Xstatic void RedrawComponent()
X{
X	palRedraw = TRUE;
X	if (rgbcmyhsv & CRED ){
X		UnDrawComponent(CRED);
X		DrawComponent(CRED);
X		}
X	if (rgbcmyhsv & CGREEN) {
X		UnDrawComponent(CGREEN);
X		DrawComponent(CGREEN);
X		}
X	if (rgbcmyhsv & CBLUE) {
X		UnDrawComponent(CBLUE);
X		DrawComponent(CBLUE);
X		}
X	if (rgbcmyhsv & CCYAN) {
X		UnDrawComponent(CCYAN);
X		DrawComponent(CCYAN);
X		}
X	if (rgbcmyhsv & CMAGENTA) {
X		UnDrawComponent(CMAGENTA);
X		DrawComponent(CMAGENTA);
X		}
X	if (rgbcmyhsv & CYELLOW) {
X		UnDrawComponent(CYELLOW);
X		DrawComponent(CYELLOW);
X		}
X	if (rgbcmyhsv & CHUE) {
X		UnDrawComponent(CHUE);
X		DrawComponent(CHUE);
X		}
X	if (rgbcmyhsv & CSATURATION) {
X		UnDrawComponent(CSATURATION);
X		DrawComponent(CSATURATION);
X		}
X	if (rgbcmyhsv & CVALUE) {
X		UnDrawComponent(CVALUE);
X		DrawComponent(CVALUE);
X		}
X	palRedraw = FALSE;
X	return;
X} /* RedrawComponent() */
X
Xstatic void CBSetPen(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XArg	arglist[10];
XCardinal i=0;
X
X	XtSetArg(arglist[i],XtNset,False);	i++;
X	/*****reset old toggle*/
X	switch(comp_pen) {
X		case CRED:
X			XtSetValues(b[PAL_RED],arglist,i);
X			break;
X		case CGREEN:
X			XtSetValues(b[PAL_GREEN],arglist,i);
X			break;
X		case CBLUE:
X			XtSetValues(b[PAL_BLUE],arglist,i);
X			break;
X		case CCYAN:
X			XtSetValues(b[PAL_CYAN],arglist,i);
X			break;
X		case CMAGENTA:
X			XtSetValues(b[PAL_MAGENTA],arglist,i);
X			break;
X		case CYELLOW:
X			XtSetValues(b[PAL_YELLOW],arglist,i);
X			break;
X		case CHUE:
X			XtSetValues(b[PAL_HUE],arglist,i);
X			break;
X		case CSATURATION:
X			XtSetValues(b[PAL_SATURATION],arglist,i);
X			break;
X		case CVALUE:
X			XtSetValues(b[PAL_VALUE],arglist,i);
X			break;
X		default:
X			break;
X		} /* switch */
X	
X	comp_pen = (unsigned short) client_data;
X
X	if (!(comp_pen & rgbcmyhsv)) { /* if not already drawn then draw it*/
X		i=0;
X	 	XtSetArg(arglist[i],XtNset,True);	i++;
X		switch (comp_pen) {
X			case CRED:
X				DrawComponent(CRED);
X				XtSetValues(b[PAL_PRED],arglist,i);
X				break;
X			case CGREEN:
X				DrawComponent(CGREEN);
X				XtSetValues(b[PAL_PGREEN],arglist,i);
X				break;
X			case CBLUE:
X				DrawComponent(CBLUE);
X				XtSetValues(b[PAL_PBLUE],arglist,i);
X				break;
X			case CCYAN:
X				DrawComponent(CCYAN);
X				XtSetValues(b[PAL_PCYAN],arglist,i);
X				break;
X			case CMAGENTA:
X				DrawComponent(CMAGENTA);
X				XtSetValues(b[PAL_PMAGENTA],arglist,i);
X				break;
X			case CYELLOW:
X				DrawComponent(CYELLOW);
X				XtSetValues(b[PAL_PYELLOW],arglist,i);
X				break;
X			case CHUE:
X				DrawComponent(CHUE);
X				XtSetValues(b[PAL_PHUE],arglist,i);
X				break;
X			case CSATURATION:
X				DrawComponent(CSATURATION);
X				XtSetValues(b[PAL_PSATURATION],arglist,i);
X				break;
X			case CVALUE:
X				DrawComponent(CVALUE);
X				XtSetValues(b[PAL_PVALUE],arglist,i);
X				break;
X			default:
X				break;
X			} /* switch */
X		} /* if */
X} /* CBSetPen() */
X
X
X
Xstatic void CBUnSetPen(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	comp_pen = 0;
X}
X
X
X
Xstatic void SetPenColor(dpy,wingc,color)
X/*
X * Set pen color for drawing.
X * Using an 8-bit palette, 0 <= color <= 255
X */
XDisplay		*dpy;
XGC		wingc;
Xunsigned short color;
X{
XXGCValues	gcval;
X        gcval.foreground = color;
X        XChangeGC(dpy,wingc, GCForeground, &gcval);
X}
X
X		
XPlotComp(w,x,y,comp)
XWidget w;
Xint x,y;
Xint comp;
X{
XDisplay	*dpy; 
XWindow	win;
X
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	switch(comp) {
X		case CRED:	
X			rccells[x].red = (int) ((((float) y)/
X					((float) PALCOMPHEIGHT)) * 65535.0);
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,rpoints[x].y);
X			rpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,rpoints[x].y);
X			break;
X		case CGREEN:	
X			rccells[x].green= (int) ((((float)y)/
X					((float) PALCOMPHEIGHT)) * 65535.0);
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,gpoints[x].y);
X			gpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,gpoints[x].y);
X			break;
X		case CBLUE:	
X			rccells[x].blue= (int) ((((float) y)/
X					((float) PALCOMPHEIGHT)) * 65535.0);
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,bpoints[x].y);
X			bpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,bpoints[x].y);
X			break;
X		case CCYAN:	
X			rccells[x].red = (int) (65535.0 - ((((float) y)/
X						((float) PALCOMPHEIGHT))
X						 * 65535.0));
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,cpoints[x].y);
X			cpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,cpoints[x].y);
X			break;
X		case CMAGENTA:	
X			rccells[x].green= (int) (65535.0 - ((((float) y)/
X						((float) PALCOMPHEIGHT))
X						 * 65535.0));
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,mpoints[x].y);
X			mpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,mpoints[x].y);
X			break;
X		case CYELLOW:	
X			rccells[x].blue = (int) (65535.0 - ((((float) y)/
X						((float) PALCOMPHEIGHT))
X						 * 65535.0));
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,ypoints[x].y);
X			ypoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,ypoints[x].y);
X			break;
X		case CHUE:{
X
X			double h,s,v;
X			if (!ConvertRGBtoHSV(rccells[x].red,rccells[x].green,
X					rccells[x].blue,&h,&s,&v)) {
X				h = 0;
X				}
X			h = ((double)360.0)
X				*((double) y) / ((double) PALCOMPHEIGHT);
X			ConvertHSVtoRGB(h,s,v,&(rccells[x].red),
X				&(rccells[x].green),&(rccells[x].blue));
X
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,hpoints[x].y);
X			hpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,hpoints[x].y);
X			
X			}
X			break;
X		case CSATURATION:
X			{
X			double h,s,v;
X
X			if (!ConvertRGBtoHSV(rccells[x].red,rccells[x].green,
X					rccells[x].blue,&h,&s,&v)) {
X				h = 0;
X				}
X
X			s = ((double)y) / ((double) PALCOMPHEIGHT);
X
X			ConvertHSVtoRGB(h,s,v,&(rccells[x].red),
X				&(rccells[x].green),&(rccells[x].blue));
X
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,spoints[x].y);
X			spoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,spoints[x].y);
X			
X			}
X			break;
X		case CVALUE: {
X			int max;
X			double ratio;
X			double yval;
X
X			yval = ((double) y) * 
X					(65535.0 / ((double)PALCOMPHEIGHT));
X			max = MAX3(rccells[x].red,rccells[x].green,
X				rccells[x].blue);
X			if (max != 0) {
X				ratio =((double) rccells[x].red)/(double) max;
X				rccells[x].red = (int) (ratio *  yval);
X				ratio =((double) rccells[x].green)/(double)max;
X				rccells[x].green = (int) (ratio *  yval);
X				ratio =((double) rccells[x].blue)/(double) max;
X				rccells[x].blue = (int) (ratio *  yval);
X				}
X			else {
X				rccells[x].red = rccells[x].blue = 
X					rccells[x].green = yval;
X				}
X			SetPenColor(dpy,pal_comp_gc,white);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,vpoints[x].y);
X			vpoints[x].y = PALCOMPHEIGHT - y;
X			SetPenColor(dpy,pal_comp_gc,comp_pen_dcolor);
X			XDrawPoint(dpy,win,pal_comp_gc,
X					x,vpoints[x].y);
X			}
X			break;
X
X		default:
X			break;
X		}
X		
X	return;
X} /* PlotComp() */
X
X
X
Xstatic void CBChangeComponent(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XWindow root, child;
Xint     root_x,root_y;
Xint     win_x,win_y;
Xunsigned int    keys_buttons;
Xint	x;
Xfloat	y;
Xfloat	yinc,ydiff;
XDisplay	*dpy; 
XWindow	win;
X
X	if (!comp_pen)		/* No component selected */
X		return;
X
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X        if (!XQueryPointer(dpy,win,&root,&child,
X                &root_x,&root_y,&win_x,&win_y,&keys_buttons)) 
X		return;
X
X	win_x = (win_x > 255)? 255 : (win_x <0)? 0 : win_x;
X	win_y = (win_y > PALCOMPHEIGHT)? PALCOMPHEIGHT: 
X					(win_y < 0)? 0 : win_y;
X
X	win_y = PALCOMPHEIGHT - win_y; /* 4th quadrant -> 1st quadrant */
X
X	if (comp_last_x == 0)
X		PlotComp(pal_comp,win_x,win_y,comp_pen);
X	else {
X		ydiff = (comp_last_x > win_x)?(comp_last_y - win_y):
X				(win_y - comp_last_y);
X
X		if (comp_last_x > win_x) {
X			yinc = (float) ydiff /((comp_last_x == win_x)?1.0:
X					((float)(comp_last_x - win_x)));
X			for (x = win_x,y=win_y; x < comp_last_x; x++,y=y+yinc)
X				PlotComp(pal_comp,x,(int) y,comp_pen);
X			}
X		else{
X			yinc = (float) ydiff / ((comp_last_x == win_x)?1.0:
X					((float)( win_x - comp_last_x)));
X			for (x = comp_last_x, y=comp_last_y; x < win_x; x++,y=y+yinc)
X				PlotComp(pal_comp,x,(int) y,comp_pen);
X			}
X		}
X	comp_last_x = win_x;
X	comp_last_y = win_y;
X	StoreColors(rccells,FALSE,fcmap);
X} /* CBChangeComponent() */
X			
X
X
Xstatic void CBPrepChangeComp(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	comp_last_x = 0;
X	comp_last_y = 0;
X	comp_pen_dcolor = ChooseColor(rccells,comp_pen);
X	SaveForUndo(rccells);
X	CBChangeComponent(w,client_data,call_data);
X}
X
Xstatic void CBEndChangeComp(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	if (comp_last_x || comp_last_y)
X		RedrawComponent();
X	comp_last_x = 0;
X	comp_last_y = 0;
X	PaletteChangeComplete();
X}
X
Xstatic int ChooseColor(ccells,whichone)
X/* pick the best entry in the palette to match color */
XXColor	ccells[];	/* the palette */
Xint	whichone;	/* which color to find in palette */
X{
Xint best;
Xint best_cmpval;
Xint cmpval;
Xint x;
Xint r,b,g;
X
X	best = black;
X	best_cmpval = -1 - (1 >> 18);
X	switch (whichone) {
X	case CRED:	/* find purest red */
X		for(x=0; x < 256 ; x++) {
X			g = ccells[x].green;
X			b = ccells[x].blue;
X			cmpval = ccells[x].red - g - b - abs(g-b);
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CGREEN:	/* find purest green */
X		for(x=0; x < 256 ; x++) {
X			r = ccells[x].red;
X			b = ccells[x].blue;
X			cmpval = ccells[x].green - r - b - abs(r-b);
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CBLUE:	/* find purest blue */
X		for(x=0; x < 256 ; x++) {
X			r = ccells[x].red;
X			g = ccells[x].green;
X			cmpval = ccells[x].blue - r - g - abs(r-g);
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CCYAN:	/* find purest cyan */
X		for(x=0; x < 256 ; x++) {
X			cmpval = ccells[x].green + ccells[x].blue
X						- ccells[x].red;
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CMAGENTA:	/* find purest magenta */
X		for(x=0; x < 256 ; x++) {
X			cmpval = ccells[x].red + ccells[x].blue
X						- ccells[x].green;
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CYELLOW:	/* find purest yellow */
X		for(x=0; x < 256 ; x++) {
X			cmpval = ccells[x].red + ccells[x].green
X						- ccells[x].blue;
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CHUE:	/* find purest orange */
X		for(x=0; x < 256 ; x++) {
X			r = ccells[x].red;
X			b = ccells[x].blue;
X			cmpval = r-b - abs(((r+b)>>1) - ccells[x].green);
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	case CSATURATION:	/* find purest purplish color?? */
X		for(x=0; x < 256 ; x++) {
X			r = ccells[x].red;
X			g = ccells[x].green;
X			cmpval = b-g - abs(((b+g)>>1) - ccells[x].red);
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	
X	case CVALUE:	
X	default:
X		/* find purest black */
X		for(x=0; x < 256 ; x++) {
X			cmpval = b-r - abs(((b+r)>>1) - ccells[x].green);
X			/*cmpval = 65535 - ((ccells[x].red + ccells[x].green
X					+ccells[x].blue)/3);
X			*/
X			if (cmpval > best_cmpval) {
X				best_cmpval = cmpval;
X				best = x;
X				}
X			}
X		break;
X	} /* switch */
X
X	return(best);
X}
X
Xstatic void CBPalSave(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X
X	WriteSEQPalette(Get_Save_Pal(),rccells);
X}
X
X
X
Xstatic void CBUndo(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	x;
XXColor	real_undo[256];
X
X	for(x=0;x < 256; x++) {
X		rccells[x].pixel = x;
X		cpccell(real_undo[x],uccells[x]);
X		}
X
X	SaveForUndo(rccells);
X
X	for(x=0;x < 256; x++) {
X		rccells[x].pixel = x;
X		cpccell(rccells[x],real_undo[x]);
X		}
X	StoreColors(rccells,TRUE,fcmap);
X	PaletteChangeComplete();
X}
X
Xstatic void SaveForUndo(rccells)
XXColor	rccells[];
X{
Xint	x;
X
X	for(x=0;x < 256; x++) {
X		uccells[x].pixel = x;
X		cpccell(uccells[x],rccells[x]);
X		}
X	
X}
X
Xstatic void CBSmooth(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;	/* contains a pointer to the component*/
Xcaddr_t call_data;
X{
Xint x;
Xint	comp_pen;	/* Drawing color; smooth this one */
Xdouble	h,s,v,h1,s1,v1,h2,s2,v2,newH,newS,newV,r,g,b;
X
X	SaveForUndo(rccells);
X
X	comp_pen = *( (int *) client_data);
X	if (!comp_pen) {
X		PrintMesg("Please select a component to manipulate first\n");
X		return;
X		}
X
X	switch (comp_pen){
X		case CRED:
X		case CCYAN:
X		    rccells[0].red = (rccells[255].red +rccells[1].red)/2;
X		    for(x=1; x< 255; x++)
X			rccells[x].red = 
X				(rccells[x-1].red + rccells[x+1].red)/2;
X		    rccells[255].red = (rccells[254].red +rccells[0].red)/2;
X		    break;
X		case CGREEN:
X		case CMAGENTA:
X		    rccells[0].green = 
X				(rccells[255].green + rccells[1].green)/2;
X		    for(x=1; x< 255; x++)
X			rccells[x].green = 
X				(rccells[x-1].green + rccells[x+1].green)/2;
X		    rccells[255].green = 
X				(rccells[254].green + rccells[0].green)/2;
X		    break;
X		case CBLUE:
X		case CYELLOW:
X		    rccells[0].blue = 
X				(rccells[255].blue + rccells[1].blue)/2;
X		    for(x=1; x< 255; x++)
X			rccells[x].blue = 
X				(rccells[x-1].blue + rccells[x+1].blue)/2;
X		    rccells[255].blue = 
X				(rccells[254].blue + rccells[0].blue)/2;
X		    break;
X		case CHUE:
X			break;
X/*
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[1].red,
X					rccells[1].green,
X					rccells[1].blue,
X					&h2,&s2,&v2);
X			newH = h1 + h2 / 2.0;
X			ConvertHSVtoRGB(newH,s,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X		    for(x=1; x< 255; x++) {
X			ConvertRGBtoHSV(rccells[x-1].red,
X					rccells[x-1].green,
X					rccells[x-1].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[x].red,
X					rccells[x].green,
X					rccells[x].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[x+1].red,
X					rccells[x+1].green,
X					rccells[x+1].blue,
X					&h2,&s2,&v2);
X			newH = h1 + h2 / 2.0;
X			ConvertHSVtoRGB(newH,s,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X			}
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[255].red,
X					rccells[255].green,
X					rccells[255].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h2,&s2,&v2);
X			newH = h1 + h2 / 2.0;
X			ConvertHSVtoRGB(newH,s,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X			break;
X*/
X		case CSATURATION:
X			break;
X/*
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[1].red,
X					rccells[1].green,
X					rccells[1].blue,
X					&h2,&s2,&v2);
X			newS = s1 + s2 / 2.0;
X			ConvertHSVtoRGB(h,newS,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X		    for(x=1; x< 255; x++) {
X			ConvertRGBtoHSV(rccells[x-1].red,
X					rccells[x-1].green,
X					rccells[x-1].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[x].red,
X					rccells[x].green,
X					rccells[x].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[x+1].red,
X					rccells[x+1].green,
X					rccells[x+1].blue,
X					&h2,&s2,&v2);
X			newS = s1 + s2 / 2.0;
X			ConvertHSVtoRGB(h,newS,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X			}
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[255].red,
X					rccells[255].green,
X					rccells[255].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h2,&s2,&v2);
X			newS = s1 + s2 / 2.0;
X			ConvertHSVtoRGB(h,newS,v,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X			break;
X*/
X		case CVALUE:
X			break;
X/*
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[1].red,
X					rccells[1].green,
X					rccells[1].blue,
X					&h2,&s2,&v2);
X			newV = v1 + v2 / 2.0;
X			ConvertHSVtoRGB(h,s,newV,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X		    for(x=1; x< 255; x++) {
X			ConvertRGBtoHSV(rccells[x-1].red,
X					rccells[x-1].green,
X					rccells[x-1].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[x].red,
X					rccells[x].green,
X					rccells[x].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[x+1].red,
X					rccells[x+1].green,
X					rccells[x+1].blue,
X					&h2,&s2,&v2);
X			newV = v1 + v2 / 2.0;
X			ConvertHSVtoRGB(h,s,newV,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X			}
X			ConvertRGBtoHSV(rccells[254].red,
X					rccells[254].green,
X					rccells[254].blue,
X					&h1,&s1,&v1);
X			ConvertRGBtoHSV(rccells[255].red,
X					rccells[255].green,
X					rccells[255].blue,
X					&h,&s,&v);
X			ConvertRGBtoHSV(rccells[0].red,
X					rccells[0].green,
X					rccells[0].blue,
X					&h2,&s2,&v2);
X			newV = v1 + v2 / 2.0;
X			ConvertHSVtoRGB(h,s,newV,
X					&(rccells[x].red),
X					&(rccells[x].green),
X					&(rccells[x].blue));
X		    break;
X*/
X		} /*switch */
X		
X	StoreColors(rccells,TRUE,fcmap);
X	PaletteChangeComplete();
X} /* CBSmooth() */
X
Xvoid ConvertCMapToPalette(ccells,pal)
X/* Converts a 8 bit X ccells to 256R,256G,256B */
XXColor ccells[];
Xunsigned char *pal;
X{
Xregister int x;
X
X	for (x=0 ; x<256; x++)
X		*pal++ = (unsigned char) (ccells[x].red >> 8);
X	for (x=0 ; x<256; x++)
X		*pal++ = (unsigned char) (ccells[x].green >> 8);
X	for (x=0 ; x<256; x++)
X		*pal++ = (unsigned char) (ccells[x].blue >> 8);
X}
END-of-palette.c
echo file: profile.c
sed 's/^X//' >profile.c << 'END-of-profile.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled
X * to make a contribution for the use of this software, please send
X * comments as to what you like or don't like about the software,
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Dave Thompson, National Center for Supercomputing Applications
X * davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#ifdef XtSpecificationRelease
X/*R4 */
X#include <X11/Xaw/Form.h>
X#else
X#include <X11/Form.h>
X#endif
X#include "ximage.h"
X#include "i.h"
X#include "xstuff.h"
X
X#define DEFDIMX 400
X#define DEFDIMY 300
X#define	FONTWIDTH 6 
X#define	FONTHEIGHT 11
X
Xextern  Widget  toplevelform;
Xextern  unsigned long   black,white;
Xextern  XFontStruct *ximageFont;
Xextern	Display *myDpy;
X/**/extern struct IMAGE *ci; /* debugging */
X
Xvoid CBProfileExpose(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xstruct	IMAGE *i;
XGC	gc;
XXGCValues gcval;
XWindow	win;
XXWindowAttributes winAttrib;
Xint	width,height;
Xchar	buff[80];
Xint	x,y;
Xint	gwidth; /* graph width */
Xint	gheight; /* graph height */
Xint	dwidth; /* data width */
Xint	dheight; /* data height */
Xdouble	dXInc;	/*data X Increment */
Xdouble	dYInc;  /*data Y Increment */
Xdouble	dX,dY; /*data X and Y location */
Xint	value;
Xint	lvalue;	/* last value */
Xdouble  fvalue;
Xdouble  flvalue;
Xdouble  frange;
Xint	x1,y1,x2,y2;
Xint	plotY1,plotY2;
Xint	textplace;
Xdouble	realTick;
X
X
X	i = (struct IMAGE *) client_data;
X	gcval.foreground = black;
X	gcval.background = white;
X	gc = XtGetGC(i->gpws.box3,GCForeground|GCBackground,&gcval);
X
X	win = XtWindow(i->gpws.box3);
X	XGetWindowAttributes(myDpy,win,&winAttrib);
X	width = winAttrib.width;
X	height = winAttrib.height;
X	
X	XClearWindow(myDpy,win);
X
X        if (ximageFont) {
X                XSetFont(myDpy,gc,ximageFont->fid);
X                }
X
X	if ((i->iws.select == LINE) &&
X		(!((i->iws.selBegX == i->iws.selEndX) 
X		&& (i->iws.selBegY == i->iws.selEndY)))) {
X		if (i->minvalue == i->maxvalue) {
X		   sprintf(buff,"Minimum value equals maximum value: no plot");
X			textplace = (width - FONTWIDTH*strlen(buff))/2;
X			textplace =(textplace > 0)? textplace:0;
X			XDrawString(myDpy,win,gc,textplace,height/2,
X				buff,strlen(buff));
X			return;
X			}
X		XDrawLine(myDpy,win,gc,60,20,60,height-40); /*vert*/
X		XDrawLine(myDpy,win,gc,60,height-40,width-60,height-40);/*hor*/
X
X		if (i->iws.selBegX < i->iws.selEndX) {
X			x1 = i->iws.selBegX;
X			y1 = i->iws.selBegY;
X			x2 = i->iws.selEndX;
X			y2 = i->iws.selEndY;
X			}
X		else {
X			x1 = i->iws.selEndX;
X			y1 = i->iws.selEndY;
X			x2 = i->iws.selBegX;
X			y2 = i->iws.selBegY;
X			}
X		sprintf(buff,"Selected Line (%d,%d) to (%d,%d)",
X				x1,y1,x2,y2);
X		textplace = (width - FONTWIDTH*strlen(buff))/2;
X		textplace =(textplace > 0)? textplace:0;
X		XDrawString(myDpy,win,gc,textplace,height-20,
X                        buff,strlen(buff));
X		gwidth = width - 60 /*left*/ - 70 /*right */;
X		gheight = height - 40 /*bottom*/ - 20 /*top*/;
X		dwidth = ABS(x2 - x1);
X		dheight = ABS(y2 - y1);
X/*		dX =(double) ((i->iws.selBegX < i->iws.selEndX)?i->iws.selBegX:
X				i->iws.selEndX);
X*/
X		dX = x1;
X/*
X		dY =(double) ((i->iws.selBegY < i->iws.selEndY)?i->iws.selBegY:
X				i->iws.selEndY);
X*/
X		dY = y1;
X		dXInc = ((double)dwidth) / ((double)gwidth);
X		dYInc = ((double)(y2 - y1)) / ((double) (gwidth));
X
X		if (i->isFloat)
X		    flvalue=(double)(i->fdataset[i->xdim*ROUND(dY)+ROUND(dX)]
X					- i->minvalue);
X		else
X		    lvalue = (int) (i->ri[i->xdim*ROUND(dY)+ROUND(dX)]);
X
X		frange = (double) (i->maxvalue - i->minvalue);
X
X		for(x = 70;x < 70 + gwidth; x++) {
X
X			if (i->isFloat){
X			    fvalue = (double) (i->fdataset[i->xdim*ROUND(dY)
X					+ROUND(dX)] - i->minvalue);
X			    plotY1 = gheight- (int)(((double)gheight)*((double)
X				((double)flvalue) / frange));
X			    plotY2 = gheight- (int)(((double)gheight)*((double)
X				((double)fvalue) / frange));
X			    }
X			else {
X			    value = (int) (i->ri[i->xdim*ROUND(dY)+ROUND(dX)]);
X			    plotY1 = gheight- (int)(((double)gheight)*((double)
X				((double)lvalue) / ((double)255.0)));
X			    plotY2 = gheight- (int)(((double)gheight)*((double)
X				((double)value) / (((double)255.0))));
X			    }
X
X			XDrawLine(myDpy,win,gc,x-1,plotY1+20,x,plotY2+20);
X					/* 20 == distance from top */
X
X			flvalue = fvalue;
X			lvalue = value;
X			dX = dX + dXInc;
X			dY = dY + dYInc;
X			}
X		
X		realTick= (double) i->minvalue;
X		for(y=0; y < gheight; y = y + gheight/10) {
X			if (i->isFloat)
X				sprintf(buff,i->format,(float) realTick);
X			else
X				sprintf(buff,i->format,(int) realTick);
X			XDrawString(myDpy,win,gc,55-FONTWIDTH*strlen(buff),
X					gheight + 20 - y + (FONTHEIGHT/2),
X					buff,strlen(buff));
X			realTick = realTick + (((double) i->maxvalue) 
X					- ((double)i->minvalue)) 
X					/ ((double)10.0);
X			XDrawLine(myDpy,win,gc,57,
X				gheight + 20 - y, 
X				63,gheight + 20 - y);
X			}
X			
X		}
X	else {
X		sprintf(buff,"No Line Selected");
X		textplace = (width - FONTWIDTH*strlen(buff))/2;
X		textplace =(textplace > 0)? textplace:0;
X		XDrawString(myDpy,win,gc,textplace,height/2,
X			buff,strlen(buff));
X		return;
X		}
X} /* CBProfileExpose */
X
Xvoid CBDoneProfile(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	struct IMAGE *i;
X        i = (struct IMAGE *) client_data;
X
X        XtDestroyWidget(i->gpws.toplevel);
X	i->gpws.amIShowing = FALSE;
X}
X
Xvoid DoProfile(i)
Xstruct IMAGE *i;
X{
Xint	xpos,ypos;
Xstatic  Arg box3Arg[]={{XtNbottom,(XtArgVal) XtChainBottom},
X                        {XtNvertDistance,(XtArgVal) 35}};
Xstatic  Arg doneArg[]={{XtNright,(XtArgVal) XtChainRight},
X                        {XtNhorizDistance,(XtArgVal) DEFDIMX-40}};
X
X	i=ci;
X
X
X#ifdef DEBUG
X/**/	printf("DoProfile(): i=%d,ci=%d\n",(int)i,(int) ci);
X/**/	printf("DoProfile():i->name=%s\n",i->name);
X/**/	printf("DoProfile():i->isHDF=%d\n",i->isHDF);
X/**/	printf("DoProfile():i->xdim=%d  i->ydim=%d\n",i->xdim,i->ydim);
X/**/	printf("DoProfile():i->maxvalue=%f  i->minvalue=%f\n",i->maxvalue,
X/**/			i->minvalue);
X/**/	printf("DoProfile():i->gpws.amIShowing:%d\n",i->gpws.amIShowing);
X#endif
X
X	if (i->gpws.amIShowing) {
X		PrintMesg("Profile graph already displayed.\n");
X		XRaiseWindow(myDpy,XtWindow(i->gpws.toplevel));
X		return;
X		}
X
X
X	PlaceWindow(&xpos,&ypos);
X
X	i->gpws.toplevel =MakeATopLevel("X Image [Image.Graph.Profile]",
X                        toplevelform,xpos,ypos,
X                        DEFDIMX,DEFDIMY);
X	i->gpws.composite = MakeForm(i->name,i->gpws.toplevel,0,0,
X                        DEFDIMX,DEFDIMY,0,0);
X        i->gpws.box1 = Make_Board("Profile",i->gpws.composite,5,5,
X				DEFDIMX-50,25);
X        i->gpws.label = Make_Label(i->label,i->gpws.box1,2,2,30);
X        i->gpws.title = Make_Label(i->name,i->gpws.box1,33,2,DEFDIMX-85);
X
X/*        i->gpws.box3 = MakeWorkSpace("Profile",i->gpws.composite,5,35,
X                        DEFDIMX-10,DEFDIMY-40,
X                        CBProfileExpose,i,NULL,NULL);
X*/
X        i->gpws.box3 = MakeForm("Profile",i->gpws.composite,5,35,
X                        DEFDIMX-10,DEFDIMY-40,box3Arg,2);
X	XtAddEventHandler(i->gpws.box3,ExposureMask,False,CBProfileExpose,i);
X        (void) MakeConstrainedButton("Done",i->gpws.composite,
X                        DEFDIMX-40,6,CBDoneProfile,i,0,0,doneArg,2);
X
X	i->gpws.amIShowing = TRUE;
X
X} /* DoProfile() */
END-of-profile.c
echo file: polar.c
sed 's/^X//' >polar.c << 'END-of-polar.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Dave Thompson, National Center for Supercomputing Applications
X * davet@ncsa.uiuc.edu
X */
X/* Author: Dave Thompson & Dave Whittington*/
X
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X
X#include <stdio.h>
X#include <math.h>
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "i.h"
X
X#define	XLOC	400
X#define	YLOC	400
X
Xstruct	POINT {
X	short	int	x,y;
X	};
X
Xextern	unsigned long white;
Xextern	Widget	toplevelform;
X
Xvoid	CreatePolarImage();
Xvoid	CreateInterPolar();
X
X
Xint DrawPolar2(i)
Xstruct IMAGE *i;
X/* return NULL if error */
X{
Xint	ydim_x_2;
X
X	ydim_x_2 = i->ydim << 1;
X	if(!(i->polarimage=(unsigned char *)XIMalloc((ydim_x_2)*(ydim_x_2)))) {
X		PrintMesg("Couldn't allocate memory for polar image \n");
X		return(NULL);
X		}
X	
X	/* calculate for non float */
X	/*CreateInterPolar(i->ri,i->xdim,i->ydim,i->polarimage);*/
X	CreatePolarImage(i->ri,i->xdim,i->ydim,i->polarimage);
X
X	return(1);
X
X}
X
Xstatic void CreatePolarImage(dataset,xdim,ydim,imagebuff)
Xchar	dataset[];
Xint	xdim;
Xint	ydim;
Xchar	imagebuff[];
X{
Xlong	x,y,rad;		/* for stepping trhough dataset */
Xlong	ys,rs;			/* squared value holders	*/
Xdouble	angle,radius;		/* cartesian->polar values	*/
Xdouble	dx;			/* dataset x & y		*/
Xint	dy;
X
X	PrintMesg("Generating polar image\n");
X
X	rs = ydim*ydim;		/* actually radius^2 for speed	*/
X
X	for (y = 0; y < 2*ydim; y++)
X	{
X		ys = (y - ydim) * (y - ydim);
X		for (x = 0; x < 2 * ydim; x++)
X		{
X			rad = (x - ydim)*(x - ydim) + ys;
X			if (rad <= rs)
X			{
X				radius = sqrt((double) rad);
X				if (radius < 1.0) angle = 0.0; else
X				angle = acos((double) (x - ydim) / radius);
X				if (y > ydim) angle = 2.0*PI - angle;
X				dx = (angle * xdim) / (2.0 * PI);
X				dy = radius;
X				imagebuff[(long)(x + 2*ydim*y)] =
X					dataset[(long)(dx + xdim*dy)];
X			}
X			else
X				imagebuff[x + 2*ydim*y] = 0;
X		}
X	}
X}
X
Xstatic void CreateInterPolar(dataset,xdim,ydim,imagebuff)
Xchar	dataset[];
Xint	xdim;
Xint	ydim;
Xchar	imagebuff[];
X{
Xlong	x,y,rad;		/* for stepping trhough dataset */
Xlong	ys,rs;			/* squared value holders	*/
Xdouble	angle,radius;		/* cartesian->polar values	*/
Xdouble	dx,dy;			/* dataset x & y		*/
Xlong	lx,ly;
Xint	data1,data2;
X
X	PrintMesg("Generating polar image\n");
X
X	rs = ydim*ydim;		/* actually radius^2 for speed	*/
X
X	for (y = 0; y < 2*ydim; y++)
X	{
X		ys = (y - ydim) * (y - ydim);
X		for (x = 0; x < 2 * ydim; x++)
X		{
X			rad = (x - ydim)*(x - ydim) + ys;
X			if (rad <= rs)
X			{
X				radius = sqrt((double) rad);
X				if (radius < 1.0) angle = 0.0; else
X				angle = acos((double) (x - ydim) / radius);
X				if (y > ydim) angle = 2.0*PI - angle;
X				dx = (angle * xdim) / (2.0 * PI);
X				dy = radius;
X				lx = (long) dx;
X				ly = (long) dy;
X				dx = dx - (double) lx;
X				dy = dy - (double) ly;
X				data1 = (dataset[lx+ly*xdim]*(1.0-dx) +
X					dataset[lx+1+ly*xdim]*dx);
X				ly++;
X				data2 = (dataset[lx+ly*xdim]*(1.0-dx) +
X					dataset[lx+1+ly*xdim]*dx);
X				data1 = data1*(1.0-dy) + data2*dy;
X				imagebuff[(long)(x + 2*ydim*y)] =
X					data1;
X			}
X			else
X				imagebuff[x + 2*ydim*y] = 0;
X		}
X	}
X}
END-of-polar.c
echo file: read.c
sed 's/^X//' >read.c << 'END-of-read.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include "ximage.h"
X#include "i.h"
X
X/* The following if for HDF stuff */
X#ifdef AIX
X#define SUN
X#endif
X
X#ifdef ULTRIX
X#define MIPSEL
X#endif
X
X#include <hdf/dfi.h>
X#include <hdf/df.h>
X#include <hdf/dfi.h>
X#include <hdf/dfrig.h>
X#include <hdf/dfsd.h>
X
Xint ReadHDFPalette();
X
Xint ReadSEQImage(i)
X/* Read in an SEQ image, return size of image read in */
X/* return NULL if couldn't find it */
Xstruct IMAGE *i;
X{
Xint     fd;
Xunsigned char    *imagebuff;
Xint	length;
Xint	lengthToRead;
Xchar	msgbuff[256];
X
X
X	sprintf(msgbuff,"Reading in SEQ image %s\n",i->fname);
X	PrintMesg(msgbuff);
X
X	if ((fd = open(i->fname,O_RDONLY)) < 0 ) {
X		sprintf(msgbuff,"Can't open %s\n",i->fname);
X		PrintMesg(msgbuff);
X		return(NULL);
X		}
X
X	lengthToRead = i->xdim * i->ydim;
X	if ( ! (imagebuff = (unsigned char *) XIMalloc(lengthToRead))) {
X		PrintMesg("Couldn't XIMalloc memory for image\n");
X		close(fd);
X		return(NULL);   /* couldn't get memory */
X		}
X
X	if ((length = read(fd,imagebuff,lengthToRead)) != lengthToRead) {
X		PrintMesg("Image file is too small for given dimensions\n");
X		XIFree((char *) imagebuff);
X		return(NULL);
X		}
X
X	close(fd);
X
X	i->ri = imagebuff;
X	i->isFloat = FALSE;
X	i->fdataset = NULL;
X	i->format = "%3d";
X	i->fwidth = 3;
X	i->maxvalue = 255;
X	i->minvalue = 0;
X	i->hasPalette = FALSE;
X	i->palette = (XColor *) NULL;
X	
X	return(length);
X
X} /* ReadSEQImage() */
X
Xint ReadSEQAnimation(fname,imagebuff,xdim,ydim)
X/* return NULL on failure */
Xchar	*fname;
Xchar	*imagebuff;
Xint	xdim,ydim;
X{
Xint	fd;
Xint	length;
Xint	lengthToRead;
Xchar	msgbuff[256];
X
X        if ((fd = open(fname,O_RDONLY)) < 0 ) {
X		sprintf(msgbuff,"Can't open %s\n",fname);
X		PrintMesg(msgbuff);
X		return(NULL);
X		}
X
X	lengthToRead = xdim * ydim;
X	if ((length = read(fd,imagebuff,lengthToRead)) != lengthToRead) {
X		sprintf(msgbuff,"%s is too small for given dimensions\n",fname);
X		PrintMesg(msgbuff);
X		return(NULL);
X		}
X
X	close(fd);
X	return(length);
X}
X
X
Xint ReadHDFImage(i)
X/* return NULL if problem */
Xstruct IMAGE *i;
X{
Xint     lengthToRead;
Xchar	msgbuff[256];
X
X	sprintf(msgbuff,"Reading in HDF image %s\n",i->fname);
X	PrintMesg(msgbuff);
X
X        lengthToRead = i->xdim * i->ydim;
X        if ( ! (i->ri = (unsigned char *) XIMalloc(lengthToRead))) {
X                PrintMesg("Couldn't XIMalloc memory for image\n");
X                return(NULL);   /* couldn't get memory */
X                }
X	DFR8restart();
X	if (DFR8getimage(i->fname,i->ri,i->xdim,i->ydim,NULL) == -1) {
X		PrintMesg("Couldn't read in HDF image\n");
X		return(NULL);   /* failed */
X		}
X
X
X	i->palette = (XColor  *) NULL;
X	i->hasPalette = FALSE;
X	if(DFPnpals(i->fname) > 0) {
X        	if ( ! (i->palette=(XColor *) XICalloc(256,sizeof(XColor)))) {
X			PrintMesg("Couldn't XIMalloc memory for palette\n");
X			return(NULL);   /* couldn't get memory */
X			}
X		if (ReadHDFPalette(i->fname,i->palette))
X			i->hasPalette = TRUE;
X		else
X			XIFree((char *)i->palette);
X		}
X
X
X	i->isFloat = FALSE;
X	i->fdataset = NULL;
X	i->format = "%3d";
X	i->fwidth = 3;
X	i->maxvalue = 255;
X	i->minvalue = 0;
X
X	sprintf(msgbuff,"Dimension of this HDF image: %dx%d\n",i->xdim,i->ydim);
X	PrintMesg(msgbuff);
X
X	return(i->xdim * i->ydim);	/* return length if ok */
X} /* ReadHDFImage() */
X
X
XMakeHDFImageIndex(file,index,size)
X/* make an index table for accessing the images out of HDF*/
X/* return NULL if can't */
Xchar *file;
Xint index[];
Xint size;
X{
Xint x;
Xint32	xdim,ydim;
Xint	ispalette;
X
X	DFR8restart();
X	for(x = 0; x < size; x++)  {
X		if ( -1 == DFR8getdims(file,&xdim,&ydim,&ispalette))
X			return(NULL);
X		index[x] = DFR8lastref();
X		}
X	
X	return(1);
X}
X
X
Xint ReadHDFAnimationImage(file,raster,frameNum)
Xchar *file;
Xunsigned char *raster;
Xint	frameNum; /* must be an HDF ref number (see MakeHDFImageIndex()) */
X{
Xint x;
X/*
Xint32	xdim,ydim;
Xint	ispalette;
X	DFR8restart();
X	for (x=0;x<frameNum;x++) 
X		if ( -1 == DFR8getdims(file,&xdim,&ydim,&ispalette)) {
X			return(0);
X			}
X
X	if (-1 == DFR8getimage(file,raster,xdim,ydim,NULL)) {
X		return(0);
X		}
X
X	return(xdim*ydim);
X*/
X/* doesn't do uncompression 
XDF *dfile;
X
X	if (!(dfile = DFopen(file,DFACC_READ,1000)))
X		return(0);
X	if (-1 == DFgetelement(dfile,DFTAG_RI8,frameNum,raster)) {
X	    if (-1 == DFgetelement(dfile,DFTAG_CI8,frameNum,raster)) {
X		if (-1 == DFgetelement(dfile,DFTAG_II8,frameNum,raster)) {
X			DFclose(dfile);
X			return(0);
X			}
X		}
X	   }
X	DFclose(dfile);
X	return(1);
X*/
X 
Xint32	xdim,ydim;
Xint	ispalette;
Xint	n;
X
X	DFR8restart();
X
X	if ( 1 < (n = DFR8nimages(file))) {
X		if ( -1 == DFR8readref(file,frameNum)){
X#ifdef DEBUG
X	                printf("ReadHDFAnim():Error on DFR8readref(file=\"%s\",frameNum=%d):Err#%d\n",
X			file,frameNum,DFerror);
X#endif
X			return(0);
X			}
X		}
X	else {
X		DFR8restart();
X		}
X
X	if ( -1 == DFR8getdims(file,&xdim,&ydim,&ispalette)) {
X#ifdef DEBUG
X		printf("ReadHDFAnim():Error on DFR8getdims(file=\"%s\",...):Err#%d\n",
X			file,DFerror);
X#endif
X		return(0);
X		}
X
X	if (-1 == DFR8getimage(file,raster,xdim,ydim,NULL)) {
X#ifdef DEBUG
X		printf("ReadHDFAnim():Error on DFR8getimage(file=\"%s\",..):Err#%d\n",
X				file,DFerror);
X#endif
X		return(0);
X		}
X
X	return(xdim*ydim);
X
X} /* ReadHDFAnimationImage() */
X
X
Xvoid SetMinMax(data,xdim,ydim,min,max)
X/*scan float dataset and set min & max */
Xfloat	*data;
Xint	xdim,ydim;
Xfloat	*min,*max;
X{
Xregister int x,last;
Xregister float *pf;
X
X                pf = data;
X                *min = *max = *data;
X                last = xdim*ydim-1;
X
X                for (x = 0; x < last ; x++,pf++) {
X                        *min = (*pf < *min)? *pf : *min;
X                        *max = (*pf > *max)? *pf : *max;
X                        }
X} /*SetMinMax() */
X
X
X
X
X
Xint CreateRasterFromFloat(fdata,raster,xdim,ydim,min,max,shouldMalloc)
Xfloat	*fdata;
Xunsigned char **raster;	/* returned */
Xint	xdim,ydim;
Xfloat	min,max;
Xchar	shouldMalloc;	/* Should it create new space? or use existing raster*/
X/* return 0 on Failure */
X{
Xint length;
Xint x;
Xfloat range;
Xunsigned char *pc;
Xfloat *pf;
X
X        length = xdim * ydim;
X	if (shouldMalloc){
X		if (! (*raster = (unsigned char *) XIMalloc(length))) {
X			PrintMesg("Can't allocate memory for raster image\n");
X			return(NULL);
X			}
X		}
X        range = max - min;
X	if (range)
X	        for (x = 0, pc= *raster, pf=fdata; x < length; x++,pc++,pf++ ){
X			*pc =(unsigned char) ((( *pf - min ) / range) *255.0);
X			}
X	else
X	        for (x = 0, pc= *raster, pf=fdata; x < length; x++,pc++,pf++ ){
X			*pc =(unsigned char) 0;
X			}
X
X	return(1);
X} /*CreateRasterFromFloat() */
X
X
X
X
X
X
Xint ReadHDFSDS(i,x,y,z)
Xstruct IMAGE *i;
Xint	x,y,z;		/* contains dimension of image */
X			/* x,y,z: one of these must be set to 1 */
X			/* (2D plane along [xyz] must be set to 1) */
X/* return 1 if ok */
X/* return 0 on failure */
X{
X/*
Xint rank;
Xint32 sizes[100];
Xint	maxrank;
X*/
Xchar	msgbuff[256];
Xstatic 	int32	s1[] = {1,1,1};
Xint32	s2[3];
Xint32	dims[3];
Xint	tmp;
X
X#ifdef DEBUG
X	printf("ReadHDFSDS(): %d,%d,%d\n",x,y,z);
X#endif
X	tmp = x;
X	x = y;
X	y = tmp;
X	
X	sprintf(msgbuff,"Reading in HDF data set %s\n",i->fname);
X	PrintMesg(msgbuff);
X
X	DFSDrestart();
X/*	DFSDgetdims(i->fname,&rank,sizes,maxrank);*/
X/*******if (DFSDgetdata(i->fname,1,sizes,i->fdataset))*****fill me in **/
X	s2[0]=x;
X	s2[1]=y;
X	s2[2]=z;
X	if (x==1) {
X		dims[0]=y;
X		dims[1]=z;
X		}
X	else {
X		if (y==1) {
X			dims[0]=x;
X			dims[1]=z;
X			}
X		else {
X			dims[0]=x;
X			dims[1]=y;
X			}
X		}
X	dims[2]=1;
X
X	if (!(i->fdataset=(float32 *)XIMalloc(dims[0]*dims[1]*sizeof(float32)))){
X	    sprintf(msgbuff,"Could not allocate memory for HDF data set%s\n",
X			i->fname);
X	    PrintMesg(msgbuff);
X	    return(NULL);
X	    }
X	
X	i->isFloat = TRUE;
X/*
X	i->xdim = dims[0];
X	i->ydim = dims[1];
X*/
X	i->xdim = dims[1];
X	i->ydim = dims[0];
X
X	if (DFSDgetslice(i->fname,s1,s2,i->fdataset,dims) == -1 ) {
X		PrintMesg("Can't read in HDF data set\n");
X		return(NULL);
X		}
X	
X	if (DFSDgetmaxmin(&(i->maxvalue),&(i->minvalue)) == -1) {
X		SetMinMax(i->fdataset,i->xdim,i->ydim,
X				&(i->minvalue),&(i->maxvalue));
X		}
X	
X	/*if (DFSDgetdatastrs())*/
X	/* set format */
X	i->format = "% 6.3f";
X	i->fwidth = 7;
X
X	i->palette = (XColor *) NULL;
X	i->hasPalette = FALSE;
X	if(DFPnpals(i->fname) > 0) {
X        	if ( ! (i->palette=(XColor *) 
X				XICalloc(256,sizeof(XColor)))) {
X			PrintMesg("Couldn't XIMalloc memory for palette\n");
X			return(NULL);   /* couldn't get memory */
X			}
X		if (ReadHDFPalette(i->fname,i->palette))
X			i->hasPalette = TRUE;
X		else
X			XIFree((char *)i->palette);
X		}
X
X
X	/* Create raster image */
X	if (!CreateRasterFromFloat(i->fdataset,&(i->ri),
X		i->xdim,i->ydim,i->minvalue,i->maxvalue,1)){
X			return(NULL);
X			}
X
X	sprintf(msgbuff,"Dimension of this slice: %dx%d\n",i->xdim,i->ydim);
X	PrintMesg(msgbuff);
X
X	return(1); /* return non-NULL if ok */
X} /* ReadHDFSDS() */
X
X
X
X
XIsItHDF(filename,dimx,dimy,isfloat)
Xchar *filename;
Xint *dimx,*dimy;
Xchar *isfloat;
X/* return null if not HDF */
X{
Xint r;
Xint32	sizes[3];
Xint ret;
Xint ispal;
X
X	DFR8restart();
X	ret = DFR8getdims(filename,dimx,dimy,&ispal);
X	*isfloat = FALSE;
X	if (DFerror == DFE_NOTDFFILE) {
X		/* Not HDF file */
X		*dimx = *dimy = 0;
X		return(0);
X		}
X	else {
X		if (ret == -1) {
X			/* Not a DFR8 image, is it a DFSD? */
X			DFSDrestart();
X			ret = DFSDgetdims(filename,&r,sizes,3);
X			*dimx=sizes[1];
X			*dimy=sizes[0];
X			/* dimz=sizes[2]; */
X			*isfloat = TRUE;
X			}
X		}
X		
X	if (ret == -1) /* if not a DFSD image */
X		*dimx = *dimy = 0;
X
X	return(!ret);
X
X} /* IsItHDF() */
X
X
Xint ReadHDFHasPalette(name)
Xchar *name;
X/* returns number of pals hdf file has */
X/* returns -1 on error */
X{
X	return(DFPnpals(name));
X}
X
Xvoid ConvertToXColors(rgb,ccells)
Xunsigned char rgb[768];
XXColor	 ccells[256];
X/*  Convert 8 bit palette to XColor array */
X/*  8 bit palette is arranged 256 entries of red followed by green & blue */
X{
Xint x;
X        for (x=0; x < 256;x++) {
X                ccells[x].pixel = x;
X                ccells[x].red   = (unsigned short) rgb[x*3] << 8;
X                ccells[x].green = (unsigned short) rgb[x*3+1] << 8;
X                ccells[x].blue  = (unsigned short) rgb[x*3+2] << 8;
X                ccells[x].flags = DoRed|DoGreen|DoBlue;
X                }
X}
X
X
Xint ReadHDFPalette(name,ccells)
X/* return 1 if ok */
X/* return 0 on failure */
Xchar	*name;
XXColor	ccells[256];
X{
Xunsigned char pal[256*3];
Xint	x;
Xchar	buff[512];
X
X
X/*	if (DFR8getimage(name,"garbage",1,1,pal) == -1) {*/
X	DFPrestart();
X	if (DFPgetpal(name,pal) == -1) {
X                sprintf(buff,"Couldn't read in HDF palette %s\n",name);
X		PrintMesg(buff);
X                return(NULL);   /* failed */
X		}
X
X	ConvertToXColors(pal,ccells);
X
X	sprintf(buff,"Just read in HDF palette %s\n",name);
X	PrintMesg(buff);
X	return(1);
X} /* ReadHDFPalette() */
X
X
X
X
X
X
Xint ReadSEQPalette(name,ccells)
X/* Return NULL if could not read SEQ colormap */
Xchar *name;
XXColor ccells[256];
X{
Xchar	rbuff[256];
Xchar	gbuff[256];
Xchar	bbuff[256];
Xint	fd;		/* file descriptor */
Xint	x;
Xchar 	errbuff[260];
X
X	if ((fd = open(name,O_RDONLY,NULL)) < 0) {
X		(void) sprintf(errbuff,"Can't open colormap file %s\n",name);
X		PrintMesg(errbuff);
X		return(NULL);
X		}
X
X	if (read(fd,rbuff,256) != 256) {
X		sprintf(errbuff,"%s is not a seq colormap\n",name);
X		PrintMesg(errbuff);
X		return(NULL);
X		}
X	if (read(fd,gbuff,256) != 256) {
X		sprintf(errbuff,"%s is not a seq colormap\n",name);
X		PrintMesg(errbuff);
X		return(NULL);
X		}
X	if (read(fd,bbuff,256) != 256) {
X		sprintf(errbuff,"%s is not a seq colormap\n",name);
X		PrintMesg(errbuff);
X		return(NULL);
X		}
X
X	(void) close(fd);
X	
X
X	for (x = 0; x < 256; x++) {
X		ccells[x].pixel = x;
X		ccells[x].red   = (unsigned short) rbuff[x] << 8;
X		ccells[x].green = (unsigned short) gbuff[x] << 8;
X		ccells[x].blue  = (unsigned short) bbuff[x] << 8;
X		ccells[x].flags = DoRed|DoGreen|DoBlue;
X		}
X
X	return(1);
X
X} /* ReadSEQColormap() */
X
X
Xint HowManyImagesInHDF(file)
Xchar *file;
X{
XDF *df;
Xint num;
X	if(!(df = DFopen(file,DFACC_READ,0)))
X		return(0); /* Can't open file */
X	if (!(num = DFnumber(df,DFTAG_RI8)))
X		if(!(num = DFnumber(df,DFTAG_CI8)))
X			num = DFnumber(df,DFTAG_II8);
X	DFclose(df);
X	return(num);
X}
X
Xint HowManySDSInHDF(file)
Xchar *file;
X{
XDF *df;
Xint num;
X
X	df = DFopen(file,DFACC_READ,0);
X	num = DFnumber(file,DFTAG_SD);
X	DFclose(df);
X	return(num);
X}
END-of-read.c
echo file: shade.c
sed 's/^X//' >shade.c << 'END-of-shade.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Dave Thompson, National Center for Supercomputing Applications
X * davet@ncsa.uiuc.edu
X */
X
X/*	ImageTool "Shade" plot   --				*/
X/*	makes an n "grey-level" black and white plot of data	*/
X/* 	Author: Dave Whittington */
X
X#include	<stdio.h>
X#include	<X11/Xlib.h>
X#include	<X11/Intrinsic.h>
X#include 	"ximage.h"
X#include	"patterns.h"
X
X#ifndef	TRUE
X#define TRUE 1
X#endif
X#define FALSE 0
X#define	DIVISOR	(8 - SHIFTBITS)
X#define DONERTN	((unsigned char) 255)
X
Xtypedef	struct	{
X	int	x;
X	int	y;
X	int	width;
X	int	height;
X	} Rect;
X
Xextern	unsigned long	black,white;
Xstatic	Display	*disp;
Xstatic	Drawable d;
Xstatic	GC	the_gc;
Xstatic	char	*ri;
Xstatic	Pixmap	patList[NUMPATTERNS];
Xstatic	Rect	plotRect;
Xstatic	short	xmax,ymax;
Xstatic	float	dimv,dimh;
Xstatic	short	lmar,tmar;
X
Xstatic	unsigned char data(x,y)
Xint	x,y;
X{
X	return(ri[y*xmax+x]);
X}
X
Xvoid PlotRect(r,pat)
XRect	*r;
Xunsigned char	pat;
X{
X	XSetStipple(disp,the_gc,patList[pat]);
X	XFillRectangle(disp,d,the_gc,r->x,r->y,r->width,r->height);
X}
X
Xvoid InitShade(w)
XWidget w;
X{
X	int	count;
X
X	disp = XtDisplay(w);
X	d = XtWindow(w);
X	for (count = 0; count < NUMPATTERNS; count++)
X	patList[count] = XCreateBitmapFromData(disp,d,pats[count],16,16);
X}
X
Xunsigned char horizontal(y,xl,xr)
Xshort	y,xl,xr;
X{
Xshort	count;
Xunsigned char	old,temp;
XBoolean	biff;
XRect	r;
X
X	old = (data(xl,y)>>DIVISOR);
X	biff = TRUE;
X	for(count = 1; count<(xr-xl); count++)
X	{
X		temp = (data((xl+count),y)>>DIVISOR);
X		if (old != temp) biff = FALSE;
X		old = temp;
X	}
X	if (biff) return(old);
X	else
X	{
X		for(count = 0; count <(xr-xl); count++)
X		{
X			r.y = ((y-plotRect.y)*dimv + tmar);
X			r.height = dimv;
X			r.x = ((xl+count-plotRect.x)*dimh + lmar);
X			r.width = dimh;
X			PlotRect(&r,data((xl,count),y)>>DIVISOR);
X		}
X		return(DONERTN);
X	}
X}
X
Xunsigned char vertical(x,yt,yb)
Xshort	x,yt,yb;
X{
Xshort	count;
Xunsigned char	old,temp;
XBoolean	biff;
XRect	r;
X
X	old = (data(x,yt)>>DIVISOR);
X	biff = TRUE;
X	for(count = 1; count<(yb-yt); count++)
X	{
X		temp = (data(x,(yt+count))>>DIVISOR);
X		if (old != temp) biff = FALSE;
X		old = temp;
X	}
X	if (biff) return(old);
X	else
X	{
X		for(count = 0; count <(yb-yt); count++)
X		{
X			r.y = ((yt+count-plotRect.y)*dimv + tmar);
X			r.height = dimv;
X			r.x = ((x-plotRect.x)*dimh + lmar);
X			r.width = dimh;
X			PlotRect(&r,data(x,(yt+count))>>DIVISOR);
X		}
X		return(DONERTN);
X	}
X}
X
Xunsigned char shadePlot(left,top,right,bottom)
Xshort	left,top,right,bottom;
X{
Xshort	lwidth,rwidth,theight,bheight;
Xunsigned char	ul,ur,ll,lr;
XRect	m;
X
X	lwidth = (right-left)/2;
X	rwidth = (right-left+1)/2;
X	theight = (bottom-top)/2;
X	bheight = (bottom-top+1)/2;
X
X	if (lwidth == 1)
X	{
X		if (theight == 1)
X		{
X			ul = (data(left,top)>>DIVISOR);
X			if (rwidth == 1)
X			{
X				ur = (data((left+1),top)>>DIVISOR);
X				if (bheight == 1)
X				{
X					ll = (data(left,(top+1))>>DIVISOR);
X					lr = (data((left+1),(top+1))>>DIVISOR);
X				}
X				else
X				{
X					ll = vertical(left,(top+1),bottom);
X					lr = vertical((left+1),(top+1),bottom);
X				}
X			}
X			else
X			{
X				ur = horizontal(top,(left+1),right);
X				if (bheight == 1)
X				{
X					ll = data(left,(top+1))>>DIVISOR;
X					lr = horizontal((top+1),(left+1),right);
X				}
X				else
X				{
X					ll = vertical(left,(top+1),bottom);
X					lr = shadePlot((left+1),(top+1),right,bottom);
X				}
X			}
X		}
X		else
X		{
X			if (!theight) return(DONERTN);
X			ul = vertical(left,top,(top+theight));
X			ll = vertical(left,(top+theight),bottom);
X			if (rwidth != 1)
X			{
X				ur = shadePlot((left+1),top,right,(top+theight));
X				lr = shadePlot((left+1),(top+theight),right,bottom);
X			}
X			else
X			{
X				ur = vertical((left+1),top,(top+theight));
X				lr = vertical((left+1),(top+theight),bottom);
X			}
X		}
X	}
X	else
X	{
X		if (!lwidth) return(DONERTN);
X		if (theight == 1)
X		{
X			ul = horizontal(top,left,(left+lwidth));
X			ur = horizontal(top,(left+lwidth),right);
X			if (bheight != 1)
X			{
X				ll = shadePlot(left,(top+1),(left+lwidth),bottom);
X				lr = shadePlot((left+lwidth),(top+1),right,bottom);
X			}
X			else
X			{
X				ll = horizontal((top+1),left,(left+lwidth));
X				lr = horizontal((top+1),(left+lwidth),right);
X			}
X		}
X		else
X		{
X			if (!theight) return(DONERTN);
X			ul = shadePlot(left,top,(left+lwidth),(top+theight));
X			ur = shadePlot((left+lwidth),top,right,(top+theight));
X			ll = shadePlot(left,(top + theight),(left + lwidth),bottom);
X			lr = shadePlot((left+lwidth),(top+theight),right,bottom);
X		}
X	}
X
X	if ((ll == ul) && (ur == ul) && (lr == ul)) return(ul);
X	else
X	{
X		if (ul != DONERTN)
X		{
X			m.y = ((top-plotRect.y)*dimv + tmar);
X			m.x = ((left-plotRect.x)*dimh + lmar);
X			m.width = lwidth*dimh;
X			m.height = theight*dimv;
X			PlotRect(&m,ul);
X		}
X		if (ur != DONERTN)
X		{
X			m.y = ((top-plotRect.y)*dimv + tmar);
X			m.x = ((left+lwidth-plotRect.x)*dimh + lmar);
X			m.width = (right-left-lwidth)*dimh;
X			m.height = theight*dimv;
X			PlotRect(&m,ur);
X		}
X		if (ll != DONERTN)
X		{
X			m.y = ((top+theight-plotRect.y)*dimv + tmar);
X			m.x = ((left-plotRect.x)*dimh + lmar);
X			m.width = lwidth*dimh;
X			m.height = (bottom-top-theight)*dimv;
X			PlotRect(&m,ll);
X		}
X		if (lr != DONERTN)
X		{
X			m.y = ((top+theight-plotRect.y)*dimv + tmar);
X			m.x = ((left+lwidth-plotRect.x)*dimh + lmar);
X			m.width = (right-left-lwidth)*dimh;
X			m.height = (bottom-top-theight)*dimv;
X			PlotRect(&m,lr);
X		}
X		return(DONERTN);
X	}
X}
X
X
Xvoid Updt_Shaded(w,data,xdim,ydim,lx,ty,rx,by)
XWidget w;
Xchar *data;
Xint xdim,ydim,lx,ty,rx,by;
X{
X	unsigned char	myPat;
X	XGCValues	values;
X
X	xmax = xdim;
X	ymax = ydim;
X	ri = data;
X
X	disp = XtDisplay(w);
X	d = XtWindow(w);
X	InitShade(w);
X
X	values.stipple = patList[5];
X	values.foreground = black;
X	values.background = white;
X	the_gc = XCreateGC(disp,d,(GCStipple | GCForeground | GCBackground
X		),&values);
X	XSetFillStyle(disp,the_gc,FillOpaqueStippled);
X	dimv = 1;
X	dimh = 1;
X	plotRect.x = lx;
X	plotRect.y = ty;
X	plotRect.width = rx - lx;
X	plotRect.height = by - ty;
X	if (plotRect.width > xdim - lx) plotRect.width = xdim - lx;
X	if (plotRect.width < 0) plotRect.width = 1;
X	if (plotRect.height > ydim - ty) plotRect.height = ydim - ty;
X	if (plotRect.height < 0) plotRect.height = 1;
X
X	lmar = lx;
X	tmar = ty;
X
X	myPat = shadePlot(plotRect.x,plotRect.y,plotRect.x + plotRect.width,
X		plotRect.y + plotRect.height);
X	if (myPat != DONERTN) PlotRect(&plotRect,myPat);
X	XFreeGC(disp,the_gc);
X}
X 
END-of-shade.c
echo file: sliceSDS.c
sed 's/^X//' >sliceSDS.c << 'END-of-sliceSDS.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X
X#ifdef XtSpecificationRelease
X#include <X11/Xw/Xw.h>
X#include <X11/Xw/Toggle.h>
X#else
X/*R4 or later*/
X#include <Xw/Xw.h>
X#include <Xw/Toggle.h>
X#endif
X
X#include "ximage.h"
X#include "buttons.h"
X#include "xstuff.h"
X
X#define	ARROW_TURN1	1
X#define ARROW_FLIP	2
X#define ARROW_TURN2	3
X
X#define ROT_CLOCKW	1
X#define ROT_FLIP	2
X#define ROT_COUNTCW	3
X
X#define	X_AXIS	1
X#define Y_AXIS	2
X#define Z_AXIS	3
X
Xextern  Display	*myDpy;
Xextern  Widget  toplevelform;
Xextern	unsigned long black,white;
X
Xvoid CBDrawDiagram();
Xvoid CBRedrawArrows();
Xvoid CBRedrawArrows1();
Xvoid CBRedrawArrows2();
Xvoid CBRedrawArrows3();
Xvoid CBHighlight();
Xvoid CBUnhighlight();
Xvoid CBRotate();
Xvoid CBInvert();
Xvoid CBNewPlane();
Xvoid DrawPlane();
Xvoid CBOk();
X
Xstatic	int	diagramOrientation;
Xstatic	char	flipped;
Xstatic	int	axis =Z_AXIS;
Xstatic	Widget	diagram;
Xstatic	char	isSDSBoxDrawn = FALSE;
X
XDrawSDSBox(name)
Xchar *name;		/* name of file */
X{
XWidget	composite;
XWidget	box1,box2,box3;
XWidget	toplevel;
Xstatic	char	title[256];
XDisplay	*dpy;
Xint	screen;
XWidget	b1,b2,b3;
X
X	if (isSDSBoxDrawn)
X		 return;
X
X	sprintf(title,"X Image [SDS Selector]: %s",name);
X
X/*	PlaceWindow(&xpos,&ypos);*/
X	dpy = XtDisplay(toplevelform);
X	screen = XDefaultScreen(dpy);
X
X	toplevel = MakeATopLevelOverride(title,toplevelform,
X				(DisplayWidth(dpy,screen)-305)/2,
X				(DisplayHeight(dpy,screen)-180)/2,
X				305,180);
X
X	Set_Pointer(toplevel,XC_gumby);
X	
X/*	composite = Make_Board(title, toplevel, 0,0,305,180);*/
X	composite = Make_Window("X Image: [SDS selector]",toplevel,
X				0,0,305,180);
X
X/*	(void) Make_Label("X Image: SDS selector",composite,2,2,295);*/
X
X	diagramOrientation = 1;
X	flipped = FALSE;
X	diagram = MakeWorkSpace("Diagram",composite,2,25,150,150,
X				CBDrawDiagram,NULL,
X				NULL,NULL);
X
X	box1 = Make_Board("controls",composite,155,25,145,150);
X
X	box2 = Make_Board("plane",box1,2,2,140,50);
X	(void) MakeAltToggle("Z Plane",box2,5,30,
X			CBNewPlane,NULL,CBNewPlane,NULL);
X	axis =Z_AXIS;
X	(void) Make_Dialog("plane #",box2,"Plane #","0    ",4,
X				75,2,60,45);
X
X	box3 = Make_Board("Orientation",box1,2,55,140,70);
X	(void) Make_Label("Orientation",box3,2,2,135);
X	b1 = MakeWorkSpace("turn1",box3,2,25,40,40,
X				CBRedrawArrows1,ARROW_TURN1,
X				NULL,NULL);
X	XtAddEventHandler(b1,EnterWindowMask,0,CBHighlight,NULL);
X	XtAddEventHandler(b1,LeaveWindowMask,0,CBUnhighlight,NULL);
X	XtAddEventHandler(b1,ButtonReleaseMask,0,CBRotate,ROT_CLOCKW);
X	XtAddEventHandler(b1,ButtonPressMask,0,CBInvert,0);
X	XtAddEventHandler(b1,ButtonReleaseMask,0,CBInvert,0);
X	Set_Pointer(b1,XC_hand2);
X
X	b2 = MakeWorkSpace("flip",box3,48,25,40,40,
X				CBRedrawArrows2,ARROW_FLIP,
X				NULL,NULL);
X	XtAddEventHandler(b2,EnterWindowMask,0,CBHighlight,NULL);
X	XtAddEventHandler(b2,LeaveWindowMask,0,CBUnhighlight,NULL);
X	XtAddEventHandler(b2,ButtonReleaseMask,0,CBRotate,ROT_FLIP);
X	XtAddEventHandler(b2,ButtonPressMask,0,CBInvert,0);
X	XtAddEventHandler(b2,ButtonReleaseMask,0,CBInvert,0);
X	Set_Pointer(b2,XC_hand2);
X
X	b3 = MakeWorkSpace("turn2",box3,94,25,40,40,
X				CBRedrawArrows3,ARROW_TURN2,
X				NULL,NULL);
X	XtAddEventHandler(b3,EnterWindowMask,0,CBHighlight,NULL);
X	XtAddEventHandler(b3,LeaveWindowMask,0,CBUnhighlight,NULL);
X	XtAddEventHandler(b3,ButtonReleaseMask,0,CBRotate,ROT_COUNTCW);
X	XtAddEventHandler(b3,ButtonPressMask,0,CBInvert,0);
X	XtAddEventHandler(b3,ButtonReleaseMask,0,CBInvert,0);
X	Set_Pointer(b3,XC_hand2);
X
X	(void) MakeButton("          OK          ",box1,2,130,
X			CBOk,toplevel,0,0);
X
X	isSDSBoxDrawn = TRUE;
X}
X
Xvoid CBDrawSDSBox(w,bla,bla2)
XWidget w;
Xint	bla;
Xint	bla2;
X{
XDrawSDSBox("/file/name/goes/here");
X}
X
X
Xvoid CBDrawDiagram(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xint	todraw;
X
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
Xint	xydim = 150;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = white;
X	gc = XtGetGC(w,GCForeground, &gcvalues);
X	
X	XSetForeground(dpy,gc,white);
X	XDrawLine(dpy,win,gc,20,xydim-20,20,50); /*vert */
X	XDrawLine(dpy,win,gc,20,xydim-20,xydim-50,xydim-20);
X	XDrawLine(dpy,win,gc,20,xydim-20,50,xydim-60); /*diag*/
X	XDrawLine(dpy,win,gc,20,xydim-20,20,50);
X	XDrawLine(dpy,win,gc,20,50,xydim-50,50);
X	XDrawLine(dpy,win,gc,20,50,50,10);
X	XDrawLine(dpy,win,gc,xydim-50,xydim-20,xydim-50,50); /*vert */
X	XDrawLine(dpy,win,gc,20,50,xydim-50,50); /* horiz*/
X	XDrawLine(dpy,win,gc,xydim-50,50,xydim-20,10); /*diag*/
X	XDrawLine(dpy,win,gc,xydim-50,xydim-20,xydim-50,50); /*vert */
X	XDrawLine(dpy,win,gc,20,xydim-20,xydim-50,xydim-20);
X	XDrawLine(dpy,win,gc,xydim-50,xydim-20,xydim-20,xydim-60);
X
X	XDrawString(dpy,win,gc,55,10,"z",1);
X	XDrawString(dpy,win,gc,55,xydim-61,"z",1);
X	XDrawString(dpy,win,gc,xydim-15,10,"z",1);
X	XDrawString(dpy,win,gc,xydim-15,xydim-60,"z",1);
X			    XDrawString(dpy,win,gc,xydim-45,xydim-20,"x",1);
X			    XDrawString(dpy,win,gc,20,45,"y",1);
X			    XDrawString(dpy,win,gc,20,xydim-10,"x",1);
X			    XDrawString(dpy,win,gc,xydim-45,50,"y",1);
X                            XDrawString(dpy,win,gc,10,50,"x",1);
X                            XDrawString(dpy,win,gc,xydim-50,xydim-10,"y",1);
X			    XDrawString(dpy,win,gc,xydim-45,50,"x",1);
X			    XDrawString(dpy,win,gc,20,xydim-10,"y",1);
X
X			    XDrawString(dpy,win,gc,xydim-45,xydim-20,"y",1);
X			    XDrawString(dpy,win,gc,20,45,"x",1);
X			    XDrawString(dpy,win,gc,10,50,"y",1);
X			    XDrawString(dpy,win,gc,xydim-50,xydim-10,"x",1);
X	XSetForeground(dpy,gc,black);
X
X	todraw = diagramOrientation;
X
X	if (flipped) {
X		switch (diagramOrientation) {
X			case 1: todraw = 2;
X			    XDrawString(dpy,win,gc,20,xydim-10,"y",1);
X			    XDrawString(dpy,win,gc,xydim-45,50,"x",1);
X				break;
X			case 2: todraw = 1;
X			    XDrawString(dpy,win,gc,xydim-45,xydim-20,"y",1);
X			    XDrawString(dpy,win,gc,20,45,"x",1);
X				break;
X			case 3: todraw = 4;
X			    XDrawString(dpy,win,gc,xydim-45,50,"y",1);
X			    XDrawString(dpy,win,gc,20,xydim-10,"x",1);
X				break;
X			case 4: todraw = 3;
X			    XDrawString(dpy,win,gc,10,50,"y",1);
X			    XDrawString(dpy,win,gc,xydim-50,xydim-10,"x",1);
X				break;
X			}
X		}
X	else {
X		switch (diagramOrientation) {
X			case 1:
X			    XDrawString(dpy,win,gc,xydim-45,xydim-20,"x",1);
X			    XDrawString(dpy,win,gc,20,45,"y",1);
X				break;
X			case 2:
X			    XDrawString(dpy,win,gc,20,xydim-10,"x",1);
X			    XDrawString(dpy,win,gc,xydim-45,50,"y",1);
X				break;
X			case 3:
X			    XDrawString(dpy,win,gc,10,50,"x",1);
X			    XDrawString(dpy,win,gc,xydim-50,xydim-10,"y",1);
X				break;
X			case 4:
X			    XDrawString(dpy,win,gc,xydim-45,50,"x",1);
X			    XDrawString(dpy,win,gc,20,xydim-10,"y",1);
X				break;
X		}
X		}
X	switch(todraw) {
X		case 1: 
X			XDrawLine(dpy,win,gc,20,xydim-20,20,50); /*vert */
X			XDrawLine(dpy,win,gc,20,xydim-20,xydim-50,xydim-20);
X			XDrawLine(dpy,win,gc,20,xydim-20,50,xydim-60); /*diag*/
X			XDrawString(dpy,win,gc,55,xydim-61,"z",1);
X			break;
X		case 2:
X			XDrawLine(dpy,win,gc,20,xydim-20,20,50);
X			XDrawLine(dpy,win,gc,20,50,xydim-50,50);
X			XDrawLine(dpy,win,gc,20,50,50,10); /* diag */
X			XDrawString(dpy,win,gc,55,10,"z",1);
X			break;
X		case 3:
X			XDrawLine(dpy,win,gc,xydim-50,xydim-20,xydim-50,50);
X			XDrawLine(dpy,win,gc,20,50,xydim-50,50); /* horiz*/
X			XDrawLine(dpy,win,gc,xydim-50,50,xydim-20,10); /*diag*/
X			XDrawString(dpy,win,gc,xydim-15,10,"z",1);
X			break;
X		case 4:
X			XDrawLine(dpy,win,gc,xydim-50,xydim-20,xydim-50,50); 
X			XDrawLine(dpy,win,gc,20,xydim-20,xydim-50,xydim-20);
X			XDrawLine(dpy,win,gc,xydim-50,xydim-20,
X					xydim-20,xydim-60);
X			XDrawString(dpy,win,gc,xydim-15,xydim-60,"z",1);
X			break;
X		}
X		DrawPlane(w,axis,black,white);
X}
X
Xvoid CBRedrawArrows(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = black;
X	gcvalues.background = white;
X	gc = XtGetGC(w,(GCForeground|GCBackground), &gcvalues);
X	
X/**/	printf("CBRedrawArrows():I've been called: call_data = %d\n",
X/**/				(int)call_data);
X	switch ((int) call_data) {
X		case ARROW_TURN1:
X				XDrawArc(dpy,win,gc,0,0,30,20,
X						135/64,225/64);
X				break;
X		case ARROW_FLIP:
X				XDrawLine(dpy,win,gc,20,5,20,15);
X				XDrawLine(dpy,win,gc,20,20,20,35);
X				break;
X		case ARROW_TURN2:
X				XDrawArc(dpy,win,gc,0,0,30,20,
X						135/64,235/64);
X				break;
X		}
X		
X}
X
Xvoid CBRedrawArrows1(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = black;
X	gcvalues.background = white;
X	gc = XtGetGC(w,(GCForeground|GCBackground), &gcvalues);
X	
X	XDrawArc(dpy,win,gc,15,0,40,40,135*64,90*64);
X/*	XDrawLine(dpy,win,gc,22,5,22,9);
X	XDrawLine(dpy,win,gc,22,5,18,6);
X*/
X	XDrawLine(dpy,win,gc,21,6,21,10);
X	XDrawLine(dpy,win,gc,21,6,17,7);
X}
X
X
Xvoid CBRedrawArrows2(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = black;
X	gcvalues.background = white;
X	gc = XtGetGC(w,(GCForeground|GCBackground), &gcvalues);
X	
X	XDrawLine(dpy,win,gc,20,5,20,18);
X	XDrawLine(dpy,win,gc,20,5,17,8);
X	XDrawLine(dpy,win,gc,20,5,23,8);
X	XDrawLine(dpy,win,gc,20,22,20,35);
X	XDrawLine(dpy,win,gc,17,33,20,35);
X	XDrawLine(dpy,win,gc,23,33,20,35);
X}
X
X
Xvoid CBRedrawArrows3(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = black;
X	gcvalues.background = white;
X	gc = XtGetGC(w,(GCForeground|GCBackground), &gcvalues);
X	
X	XDrawArc(dpy,win,gc,-15,0,40,40, 315*64,90*64);
X	XDrawLine(dpy,win,gc,18,5,18,9);
X	XDrawLine(dpy,win,gc,18,5,22,6);
X}
X
X
X
Xvoid CBHighlight(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = black;
X	gcvalues.line_width= 3;
X	gc = XtGetGC(w,(GCForeground|GCLineWidth), &gcvalues);
X	
X	XDrawLine(dpy,win,gc,0,0,39,0);
X	XDrawLine(dpy,win,gc,0,0,0,39);
X	XDrawLine(dpy,win,gc,39,0,39,39);
X	XDrawLine(dpy,win,gc,0,39,39,39);
X}
X
X
X
Xvoid CBUnhighlight(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
X	
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = white;
X	gcvalues.line_width= 3;
X	gc = XtGetGC(w,(GCForeground|GCLineWidth), &gcvalues);
X	
X	XDrawLine(dpy,win,gc,0,0,39,0);
X	XDrawLine(dpy,win,gc,0,0,0,39);
X	XDrawLine(dpy,win,gc,39,0,39,39);
X	XDrawLine(dpy,win,gc,0,39,39,39);
X}
X
X
Xstatic void CBRotate(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	switch ((int) client_data) {
X		case ROT_CLOCKW:
X				if (! flipped) {
X				    diagramOrientation++;
X				    diagramOrientation = 
X						(diagramOrientation >4)?
X						1:diagramOrientation;
X					}
X				else {
X				    diagramOrientation--;
X				    diagramOrientation = 
X						(diagramOrientation < 1)?
X						4:diagramOrientation;
X				     }
X				break;
X		case ROT_FLIP:
X				flipped = ! flipped;
X				break;
X		case ROT_COUNTCW:
X				if (! flipped) {
X				    diagramOrientation--;
X				    diagramOrientation = 
X						(diagramOrientation < 1)?
X						4:diagramOrientation;
X					}
X				else {
X				    diagramOrientation++;
X				    diagramOrientation = 
X						(diagramOrientation >4)?
X						1:diagramOrientation;
X				     }
X				break;
X		}
X	
X	CBDrawDiagram(diagram,NULL,NULL);
X}
X
X
Xvoid DrawPlane(w,plane,fcolor,bcolor)
XWidget w;
Xint plane; 
Xunsigned long fcolor,bcolor;	/* foreground and background color */
X{
XDisplay	*dpy;
XWindow	win;
XGC	gc;
XXGCValues	gcvalues;
Xstatic	unsigned char	dashlist[]={(char)3,(char)4,(char)3,(char)1};
Xint	xydim = 150;
X
X	dpy = XtDisplay(w);
X	win = XtWindow(w);
X
X	gcvalues.foreground = fcolor;
X	gcvalues.background= bcolor;
X	gcvalues.dash_offset = 0;
X	gcvalues.dashes = 4;
X	gc = XtGetGC(w,(GCForeground|GCBackground|GCDashOffset|GCDashList), 
X			&gcvalues);
X
X	XSetDashes(dpy,gc,0,dashlist,4);
X	XSetForeground(dpy,gc,fcolor);
X	XSetBackground(dpy,gc,bcolor);
X
X	XSync(dpy,False);
X
X	switch (plane) {
X	    case X_AXIS: /* X Axis */
X		XDrawLine(dpy,win,gc,60,xydim-20,60,50);
X		XDrawLine(dpy,win,gc,60,xydim-20,90,xydim-60);
X		XDrawLine(dpy,win,gc,60,50,90,10);
X		XDrawLine(dpy,win,gc,90,10,90,xydim-60);
X		break;
X	    case Y_AXIS: /* Y Axis */
X		XDrawLine(dpy,win,gc,20,xydim-60,xydim-50,xydim-60); /*front*/
X		XDrawLine(dpy,win,gc,20,xydim-60,50,xydim-101);	/*left*/
X		XDrawLine(dpy,win,gc,xydim-50,xydim-60,xydim-20,xydim-101); 
X		XDrawLine(dpy,win,gc,50,xydim-101,xydim-20,xydim-101); /*back*/
X		break;
X	    case Z_AXIS: /* Z Axis */
X		XDrawLine(dpy,win,gc,40,xydim-47,40,35);
X		XDrawLine(dpy,win,gc,xydim-30,xydim-47,xydim-30,35);
X		XDrawLine(dpy,win,gc,40,xydim-47,xydim-30,xydim-47);
X		XDrawLine(dpy,win,gc,40,35,xydim-30,35);
X	    }
X}
X
Xvoid CBNewPlane(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	switch (axis) {
X		case X_AXIS:
X			DrawPlane(diagram,X_AXIS,white,white);
X			DrawPlane(diagram,Y_AXIS,black,white);
X			axis = Y_AXIS;
X			SetToggle(w,True);
X			SetToggleString(w,"Y Plane");
X			break;
X		case Y_AXIS:
X			DrawPlane(diagram,Y_AXIS,white,white);
X			DrawPlane(diagram,Z_AXIS,black,white);
X			axis = Z_AXIS;
X			SetToggle(w,True);
X			SetToggleString(w,"Z Plane");
X			break;
X		case Z_AXIS:
X			DrawPlane(diagram,Z_AXIS,white,white);
X			DrawPlane(diagram,X_AXIS,black,white);
X			axis = X_AXIS;
X			SetToggle(w,True);
X			SetToggleString(w,"X Plane");
X			break;
X		}
X}
X
X
Xstatic void CBOk(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	XtDestroyWidget((Widget) client_data);
X	isSDSBoxDrawn = FALSE;
X}
X
Xstatic void CBInvert(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XGC		gc;
XXGCValues       gcvalues;
X	
X
X	printf("CBInvert(): I've been called \n");
X	gcvalues.function = GXxor;
X	gcvalues.foreground = white|black;
X	gc = XtGetGC(w,GCFunction|GCForeground,&gcvalues);
X/*	XSetFunction(myDpy,gc,GXinvert);
X	XSetForeground(myDpy,gc,black);
X*/
X	XFillRectangle(myDpy,XtWindow(w),gc,0,0,40,40);
X}
END-of-sliceSDS.c
echo file: write.c
sed 's/^X//' >write.c << 'END-of-write.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include "ximage.h"
X
Xint WriteSEQPalette(name,ccells)
Xchar	*name;
XXColor	ccells[256];
X{
XFILE	*fp;
Xint	x;
Xchar	buff[256];
X	if (!(fp = fopen(name,"w"))) {
X		sprintf(buff,"Can't open for writing file %s\n",name);
X		PrintMesg(buff);
X		return(NULL);
X		}
X
X	for (x=0; x < 256; x++)
X		putc(((char )(ccells[x].red >> 8)),fp);
X	for (x=0; x < 256; x++)
X		putc(((char )(ccells[x].green >> 8)),fp);
X	for (x=0; x < 256; x++)
X		putc(((char )(ccells[x].blue >> 8)),fp);
X
X	fclose(fp);
X
X	sprintf(buff,"Palette saved in SEQ format as %s\n",name);
X	PrintMesg(buff);
X
X	return(768);
X}
END-of-write.c
echo file: xstuff.c
sed 's/^X//' >xstuff.c << 'END-of-xstuff.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/cursorfont.h>
X#include <X11/Shell.h>
X
X#include "ximage.h"
X
X#ifdef XtSpecificationRelease
X/*R4 or later */
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Box.h>
X#include <X11/Xaw/Form.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xaw/Viewport.h>
X#include <X11/Xaw/List.h>
X#include <X11/Xaw/AsciiSrc.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/Xw/Xw.h>
X#include <X11/Xw/Arrow.h>
X#include <X11/Xw/PButton.h>
X#include <X11/Xw/BBoard.h>
X#include <X11/Xw/Toggle.h>
X#include <X11/Xw/SRaster.h>
X#include <X11/Xw/Valuator.h>
X#include <X11/Xw/TextEdit.h>
X#include <X11/Xw/WorkSpace.h>
X#include <X11/Xw/ScrollBar.h>
X#include <X11/Xw/SWindow.h>
X#else
X/*R3 */
X#include <X11/Command.h>
X#include <X11/Box.h>
X#include <X11/Form.h>
X#include <X11/Label.h>
X#include <X11/Dialog.h>
X#include <X11/Viewport.h>
X#include <X11/List.h>
X#include <X11/AsciiText.h>
X#include <Xw/Xw.h>
X#include <Xw/Arrow.h>
X#include <Xw/PButton.h>
X#include <Xw/BBoard.h>
X#include <Xw/Toggle.h>
X#include <Xw/SRaster.h>
X#include <Xw/Valuator.h>
X#include <Xw/TextEdit.h>
X#include <Xw/WorkSpace.h>
X#include <Xw/ScrollBar.h>
X#include <Xw/SWindow.h>
X#endif
X
X#define	SCREEN_DEPTH	8
X#define LABELFONT	"8x13bold"
X
Xextern Widget	toplevelform;
Xextern Widget	gr_DialogGetTextWind();
Xextern void	InsertInCBTable();
X
X
Xstatic char ETTextInpTrans[]="<Key>Return:    ETTextInpReturn()";
X
Xvoid Set_Pointer();
X
X
XVisual *GetVisual(dpy)
XDisplay *dpy;
X{
Xstatic char haveIComplainedYet = FALSE;
XXVisualInfo vinfo;
X
X	if (!XMatchVisualInfo(dpy,XDefaultScreen(dpy),8,PseudoColor,&vinfo)) {
X		if (! haveIComplainedYet) {
X/*		PrintMesg("Couldn't get a PseudoColor 8 bit visual\n");*/
X			haveIComplainedYet = TRUE;
X			}
X		return(XDefaultVisual(dpy,XDefaultScreen(dpy)));
X		}
X	return(vinfo.visual);
X}
X
Xvoid PlaceWindow(xpos,ypos)
Xint	*xpos,*ypos;
X{
Xstatic	char	start = 20;
Xstatic	int	x = 50;
Xstatic	int	y = 50;
XDisplay	*dpy;
Xint	screen;
X
X	*xpos = x;
X	*ypos = y;
X	x+=100;
X	y+=100;
X
X	dpy = XtDisplay(toplevelform);
X	screen = XDefaultScreen(dpy);
X	if (x > DisplayWidth(dpy,screen)-300){
X		x = y = 50 + start;
X		start = (start > 100)? 20 :start + 20;
X		}
X	if (y > DisplayHeight(dpy,screen)-300){
X		x = y = 50 + start;
X		start = (start > 100)? 20 :start + 20;
X		}
X
X	return;
X}
X
Xstatic void CBSetInputFocus(w,client_data,call_data)
X/* called when on an Enter window event*/
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
X	XSetInputFocus(XtDisplay(w),XtWindow(w),RevertToNone,CurrentTime);
X}
X
X
XWidget MakeButton(label,parent,xloc,yloc,cbp,client_data,xdim,ydim)
Xchar	*label;			/* Button Label */
XWidget	parent;			/* Parent widget of the button */
Xint	xloc,yloc;		/* Location in Parent widget */
XXtCallbackProc cbp;		/* Procedure to call back when button press */
Xcaddr_t	client_data;		/* data for call back */
Xint	xdim,ydim;		/* dimensions of button; 0 if default */
X{
XArg             arglist[10];
XCardinal        i=0;
XWidget		the_button;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	if (xdim) {
X		XtSetArg(arglist[i],XtNwidth,xdim);	i++;
X		}
X	if (ydim) {
X		XtSetArg(arglist[i],XtNheight,ydim);	i++;
X		}
X	
X	the_button = XtCreateManagedWidget("XIButton", 
X			commandWidgetClass, parent, arglist, i);
X	if (cbp)
X		 XtAddCallback(the_button,"callback",cbp,client_data);
X	Set_Pointer(the_button,XC_hand2);
X
X	return(the_button);
X
X} /* Make_Button() */
X
X
XWidget MakeConstrainedButton(label,parent,xloc,yloc,cbp,client_data,
X				xdim,ydim,moreOps,numOps)
X/* This is the same as Make button, but with the moreOps for adding
X   constraint when putting in a Form widget.  Rather than change all
X   calls to MakeButton, I'm going to be lazy and just make a new proc */
Xchar	*label;			/* Button Label */
XWidget	parent;			/* Parent widget of the button */
Xint	xloc,yloc;		/* Location in Parent widget */
XXtCallbackProc cbp;		/* Procedure to call back when button press */
Xcaddr_t	client_data;		/* data for call back */
Xint	xdim,ydim;		/* dimensions of button; 0 if default */
XArg     moreOps[];
Xint     numOps;
X{
XArg             arglist[20];
XCardinal        i=0;
XWidget		the_button;
Xint		x;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	if (xdim) {
X		XtSetArg(arglist[i],XtNwidth,xdim);	i++;
X		}
X	if (ydim) {
X		XtSetArg(arglist[i],XtNheight,ydim);	i++;
X		}
X        if (moreOps)
X            for (x=0; x < numOps; x++)
X                XtSetArg(arglist[i],moreOps[x].name,moreOps[x].value); i++;
X
X	the_button = XtCreateManagedWidget("XIButton", 
X			commandWidgetClass, parent, arglist, i);
X	if (cbp)
X		 XtAddCallback(the_button,"callback",cbp,client_data);
X	Set_Pointer(the_button,XC_hand2);
X
X	return(the_button);
X
X} /* Make_Button() */
X
XWidget Make_Window(label,parent,xloc,yloc,width,height)
Xchar	*label;
XWidget	parent;
Xint	xloc,yloc;
Xint	width,height;
X{
XXFontStruct	*labelfont;
XWidget		the_window;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	XtSetArg(arglist[i],XtNborderWidth,3);	i++;
X	XtSetArg(arglist[i],XtNborder,
X            WhitePixel(XtDisplay(parent),DefaultScreen(XtDisplay(parent))));i++;
X
X	the_window = XtCreateManagedWidget("XIWindow",
X				XwbulletinWidgetClass, parent, arglist, i);
X
X	labelfont = XLoadQueryFont(XtDisplay(the_window),LABELFONT);
X	i=0;
X	XtSetArg(arglist[i],XtNx,1);		i++;
X	XtSetArg(arglist[i],XtNy,1);		i++;
X	XtSetArg(arglist[i],XtNwidth,width-2);	i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	if (labelfont)
X		XtSetArg(arglist[i],XtNfont,labelfont); i++;
X	(void) XtCreateManagedWidget("XILabel",labelWidgetClass,
X				the_window, arglist, i);
X
X	Set_Pointer(the_window,XC_gumby);
X
X	return(the_window);
X
X} /* Make_Window() */
X
X
XWidget Make_ButtonBox(parent,xloc,yloc,width,height)
XWidget	parent;		/* Parent Widget */
Xint	xloc,yloc;	/* location inside of parent widget */
Xint	width,height;	/* Size of the box */
X{
XWidget		the_window;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	
X	the_window = XtCreateManagedWidget("XIWindow",
X				/*boxWidgetClass, parent, arglist, i);*/
X				XwbulletinWidgetClass, parent, arglist, i);
X	return(the_window);
X
X} /* Make_ButtonBox() */
X
XWidget MakeBox(name,parent,xloc,yloc,width,height)
Xchar	*name;
XWidget	parent;		/* Parent Widget */
Xint	xloc,yloc;	/* location inside of parent widget */
Xint	width,height;	/* Size of the box */
X{
XWidget		the_window;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	
X	the_window = XtCreateManagedWidget(name,
X				boxWidgetClass, parent, arglist, i);
X	return(the_window);
X
X} /* MakeBox() */
X
X
X
X
X
X
XWidget MakeWorkSpace(name,parent,xloc,yloc,width,height,exp_cbp,exp_param,
X							key_cbp,key_param)
Xchar	*name;
XWidget	parent;		/* Parent Widget */
Xint	xloc,yloc;	/* location inside of parent widget */
Xint	width,height;	/* Size of the box */
XXtCallbackProc exp_cbp;	/* expose call back procedure */
Xcaddr_t exp_param;	/* expose call back procedure parameter */
XXtCallbackProc key_cbp;	/* key press call back procedure */
Xcaddr_t key_param;	/* key press call back procedure parameter */
X{
XWidget		w;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	
X	w = XtCreateManagedWidget(name,
X				XwworkSpaceWidgetClass, parent, arglist, i);
X	if (exp_cbp)
X		 XtAddCallback(w,"expose",exp_cbp,exp_param);
X	if (key_cbp)
X		 XtAddCallback(w,"keyDown",key_cbp,key_param);
X
X	return(w);
X
X} /* MakeWorkSpace() */
X
X
X
X
XWidget MakeTextInput(parent,xloc,yloc,width,height,string)
XWidget	parent;
Xint	xloc,yloc;
Xint	width,height;
Xchar	*string;
X{
XWidget		the_window;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	XtSetArg(arglist[i],XtNstring,string);	i++;
X
X	
X/*	the_window = XtCreateManagedWidget("XIWindow",
X				asciiStringWidgetClass, parent, arglist, i);
X*/
X	the_window = XtCreateManagedWidget("XIWindow",
X				XwtexteditWidgetClass, parent, arglist, i);
X	return(the_window);
X
X} /* MakeTextInput() */
X
XWidget Make_Toggle(label,parent,xloc,yloc,cbp,data,cbp2,data2,square,set)
Xchar	*label;			/* Toggle Label */
XWidget	parent;			/* Parent widget of the toggle*/
Xint	xloc,yloc;		/* Location in Parent widget */
XXtCallbackProc cbp,cbp2;	/* Procedure to call back when toggled*/
Xcaddr_t	data,data2;
Xint	square;			/* Should it be a square? */
Xunsigned char set;		/* should toggle be set? */
X{
XArg             arglist[10];
XCardinal        i=0;
XWidget		the_toggle;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	XtSetArg(arglist[i],XtNsquare,square);	i++;
X	XtSetArg(arglist[i],XtNset,set);	i++;
X	
X		the_toggle = XtCreateManagedWidget("XIToggle", 
X				XwtoggleWidgetClass, parent, arglist, i);
X		if (cbp)
X			 XtAddCallback(the_toggle,"select",cbp,data);
X		if (cbp2)
X			 XtAddCallback(the_toggle,"release",cbp2,data2);
X
X	Set_Pointer(the_toggle,XC_hand2);
X
X	return(the_toggle);
X
X} /* Make_Toggle() */
X
XWidget MakeAltToggle(label,parent,xloc,yloc,cbp,data,cbp2,data2)
Xchar	*label;			/* Toggle Label */
XWidget	parent;			/* Parent widget of the toggle*/
Xint	xloc,yloc;		/* Location in Parent widget */
XXtCallbackProc cbp,cbp2;	/* Procedure to call back when toggled*/
Xcaddr_t	data,data2;
X{
XArg             arglist[10];
XCardinal        i=0;
XWidget		the_toggle;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	XtSetArg(arglist[i],XtNsquare,False);	i++;
X	XtSetArg(arglist[i],XtNset,True);	i++;
X	the_toggle = XtCreateManagedWidget("toggle", 
X			XwtoggleWidgetClass, parent, arglist, i);
X	if (cbp)
X		 XtAddCallback(the_toggle,"select",cbp,data);
X	if (cbp2)
X		 XtAddCallback(the_toggle,"release",cbp2,data2);
X
X	Set_Pointer(the_toggle,XC_hand2);
X
X	return(the_toggle);
X}
X
X
XWidget Make_Label(label,parent,xloc,yloc,width)
Xchar    *label;
XWidget  parent;
Xint     xloc,yloc;
Xint	width;
X{
XWidget          the_label;
XArg             arglist[10];
XCardinal        i=0;
X
X        XtSetArg(arglist[i],XtNx,xloc);         i++;
X        XtSetArg(arglist[i],XtNy,yloc);         i++;
X        XtSetArg(arglist[i],XtNwidth,width-2);  i++;
X        XtSetArg(arglist[i],XtNlabel,label);    i++;
X
X        the_label = XtCreateManagedWidget("XILabel",labelWidgetClass,
X                                parent, arglist, i);
X
X	return(the_label);
X
X} /* Make_Label() */
X
X
XWidget MakeForm(widget_name,parent,xloc,yloc,width,height,moreOps,numOps)
Xchar    *widget_name;
XWidget  parent;
Xint     xloc,yloc;
Xint	width;
Xint	height;
XArg	moreOps[];
Xint	numOps;
X{
XWidget          w;
XArg             arglist[20];
XCardinal        i=0;
Xint		x;
X
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	if (moreOps)
X	    for (x=0; x < numOps; x++) {
X		XtSetArg(arglist[i],moreOps[x].name,moreOps[x].value); i++;
X		}
X
X	w = XtCreateManagedWidget(widget_name,formWidgetClass,
X                                parent, arglist, i);
X
X	return(w);
X
X} /* MakeForm() */
X
X
X
X
XWidget Make_Dialog(widget_name,parent,label,defstring,maxlength,
X			x,y,width,height)
Xchar	*widget_name;
XWidget	parent;
Xchar	*label;
Xchar	*defstring;
Xint	maxlength;
Xint	x,y;
Xint	width,height;
X{
XWidget          w;
XArg             arglist[20];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,x);		i++;
X	XtSetArg(arglist[i],XtNy,y);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	XtSetArg(arglist[i],XtNlabel,label);	i++;
X	XtSetArg(arglist[i],XtNvalue,defstring);	i++;
X#ifndef XtSpecificationRelease
X/* doesn't exist in R4 */
X	XtSetArg(arglist[i],XtNmaximumLength,maxlength);i++;
X#else
X        XtSetArg(arglist[i],XtNleft,XtChainLeft);       i++;
X        XtSetArg(arglist[i],XtNright,XtChainLeft);      i++;
X        XtSetArg(arglist[i],XtNtop,XtChainTop);		i++;
X        XtSetArg(arglist[i],XtNbottom,XtChainTop);      i++;
X#endif
X
X
X	XtSetArg(arglist[i],XtNsensitive,True);	i++;
X
X	w = XtCreateManagedWidget(widget_name,dialogWidgetClass,
X				parent,arglist,i);
X
X	XtAddEventHandler(w,EnterWindowMask,0,CBSetInputFocus,NULL);
X	return(w);
X
X}/* Make_Dialog() */
X
XWidget Make_Board(widget_name,parent,x,y,width,height)
Xchar	*widget_name;
XWidget parent;
Xint	x,y;
Xint	width,height;
X{
XWidget          w;
XArg             arglist[10];
XCardinal        i=0;
X
X	XtSetArg(arglist[i],XtNx,x);		i++;
X	XtSetArg(arglist[i],XtNy,y);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X	w = XtCreateManagedWidget(widget_name,XwbulletinWidgetClass,
X				parent,arglist,i);
X
X	return(w);
X}
X
X
Xvoid ETTextInpReturn(w,event,params,num_params)
XWidget w;
XXEvent *event;
XString *params;
XCardinal *num_params;
X{
X	CallCallBack(w);
X}
X
X
XWidget Make_Text_Inp(widget_name,parent,string,strmaxlen,x,y,width,height,
X			cbp,cbdata)
X/* A Null in string deliminates the end of 
X * the prompt and the rest of string space */
Xchar	*widget_name;
XWidget	parent;
Xchar	*string;
Xint	strmaxlen;
Xint x,y;
Xint width,height;
XXtCallbackProc cbp;	/* Procedure to call back when <RETURN> hit*/
Xcaddr_t	cbdata;
X
X{
XWidget	w;
XArg	arglist[10];
XCardinal i=0;
XXtTranslations	transTable;
X
X	XtSetArg(arglist[i],XtNx,x);			i++;
X	XtSetArg(arglist[i],XtNy,y);			i++;
X	XtSetArg(arglist[i],XtNheight,height);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);		i++;
X	XtSetArg(arglist[i],XtNstring,string);		i++;
X	XtSetArg(arglist[i],XtNlength,strmaxlen);	i++;
X
X#ifdef XtSpecificationRelease /*R4 or later*/
X	XtSetArg(arglist[i],XtNeditType,XawtextEdit);	i++;
X#else
X	XtSetArg(arglist[i],XtNeditType,XttextEdit);	i++;
X#endif
X
X	w = XtCreateManagedWidget(widget_name,asciiStringWidgetClass,
X		parent,arglist,i);
X
X	if (cbp) {
X		InsertInCBTable(w,cbp,cbdata);
X		transTable = XtParseTranslationTable(ETTextInpTrans);
X		XtOverrideTranslations(w,transTable);
X		}
X
X
X	XtAddEventHandler(w,EnterWindowMask,0,CBSetInputFocus,NULL);
X
X	return(w);
X
X} /* Make_Text_Inp() */
X
Xvoid Get_Text_Inp(w,startpos,endpos,string,stringsize)
XWidget w;
Xchar *string;
X{
Xint i;
X
X	XwTextReadSubString(w,startpos,endpos,string,stringsize,&i);
X
X	return;
X
X} /* Get_Text_Inp() */
X
X
XWidget Make_Pal_Window(parent,xloc,yloc,xdim,ydim)
XWidget	parent;			/* parent widget */
Xint	xloc,yloc;		/* location to be placed in parent widget */
Xint	xdim,ydim;		/* size of widget */
X{
Xstatic	char	*pbuff;			/* palette image in here */
Xstatic	XImage	*pal;			/* palette image struct in here */
XWidget	palw;				/* The final product */
Xint	x,y;
XVisual	*vis;		
XArg arglist[5];
XCardinal i;
X
X	xdim = (xdim > 255)?255:xdim;
X	pbuff = (char *) XIMalloc(xdim*ydim);
X	for (y = 0; y < ydim ; y++) {
X		for(x = 0; x < xdim ; x++)
X			pbuff[y*xdim+x]=x;
X		}
X	
X	/* Make palette structure */
X	vis = GetVisual(XtDisplay(parent));
X	pal = XCreateImage(XtDisplay(parent),vis,SCREEN_DEPTH,ZPixmap,0,
X		pbuff,xdim,ydim,8,xdim);
X
X	/* Create a HP Static Raster widget */
X	i=0;
X        XtSetArg(arglist[i],XtNsRimage,pal);	i++;
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X        palw = XtCreateManagedWidget("XIWindow",
X                        XwsrasterWidgetClass,parent,arglist,i);
X
X	return(palw);
X
X} /* Make_Pal_Window() */
X
X
XXImage *MakePalette(myDpy,pal_width,isHoriz)
X/* Make an XImage of a palette */
XDisplay	*myDpy;
Xint	pal_width;
Xchar	isHoriz; /* should palette progress 0 to 255 horizontally */
X{
XVisual *myVis;
Xregister int x;
Xregister int y;
Xregister int z;
Xint planes;	/* number of planes the default screen has */
Xint screen;
Xregister int dooda;	 /*number of bytes needed per pixel */
Xregister unsigned char *p;
XXImage *palXImage;
Xunsigned char	*palImage;
X
X	myVis  = GetVisual(myDpy);
X	screen = XDefaultScreen(myDpy);
X	planes = XDisplayPlanes(myDpy,screen);
X
X	dooda = (planes > 7) ? (planes / 8 + ((planes%8)?1:0)) :1;
X	if (dooda >= 3)
X		dooda = 4;
X
X	if ( ! (palImage = (unsigned char *) XIMalloc(pal_width*256*dooda))) {
X		printf("Couldn't allocate enough memory\n");
X		return(0);
X		}
X
X	p = palImage;
X
X	if (isHoriz) {
X		for(y = 0; y < pal_width; y++)
X			for(x = 0; x < 256; x++) {
X				for (z = 1; z < dooda; z++) {
X					*p = 0;
X					p++;
X					}
X				*p = x;
X				p++;
X				}
X		palXImage = XCreateImage(myDpy,myVis,planes,ZPixmap,0,
X				palImage,256,pal_width,8*dooda,
X				256*dooda);
X		}
X	else {
X		for(y = 0; y < 256; y++) 
X			for(x = 0; x < pal_width; x++){
X				for (z = 1; z < dooda; z++) {
X					*p = 0;
X					p++;
X					}
X				*p = 255-y;
X				p++;
X				}
X	palXImage = XCreateImage(myDpy,myVis,planes,ZPixmap,0,palImage,
X				pal_width,256,8*dooda,pal_width*dooda);
X		}
X
X
X	return(palXImage); 
X
X} /* MakePalette() */
X
X
X
X
XWidget MakeImageWindow(widget_name,ximage,defpixel,parent,xloc,yloc,xdim,ydim)
Xchar	*widget_name;
XXImage	**ximage;
Xunsigned long defpixel;
XWidget	parent;			/* parent widget */
Xint	xloc,yloc;		/* location to be placed in parent widget */
Xint	xdim,ydim;		/* size of widget */
X{
Xchar	*pbuff;	
XWidget	w;		
Xint	x;
XVisual	*vis;		
XArg arglist[5];
XCardinal i;
X
X	pbuff = (char *) XIMalloc(xdim*ydim);
X/*	for (y = 0; y < ydim ; y++) {
X		for(x = 0; x < xdim ; x++)
X			pbuff[y*xdim+x]=x;
X		}
X*/
X	for(x=0; x < xdim*ydim; x++)
X		pbuff[x]=defpixel;
X	
X	/* Make palette structure */
X	vis = GetVisual(XtDisplay(parent));
X	*ximage = XCreateImage(XtDisplay(parent),vis,SCREEN_DEPTH,ZPixmap,0,
X		pbuff,xdim,ydim,8,xdim);
X
X	/* Create a HP Static Raster widget */
X	i=0;
X        XtSetArg(arglist[i],XtNsRimage,*ximage);	i++;
X	XtSetArg(arglist[i],XtNx,xloc);		i++;
X	XtSetArg(arglist[i],XtNy,yloc);		i++;
X        w= XtCreateManagedWidget(widget_name,
X                        XwsrasterWidgetClass,parent,arglist,i);
X
X	return(w);
X}
X
X
Xvoid Set_Pointer(w,cursorfont)
X/* Set pointer to cursorfont if widget has been mapped */
X/* (see X11/cursorfont.h for cursorfonts)( */
XWidget	w;
Xint	cursorfont;
X{
XCursor  cursor;
XWindow  win = XtWindow(w);
XDisplay *dpy = XtDisplay(w);
X
X        if(win) {
X            cursor = XCreateFontCursor(dpy,cursorfont);
X            XDefineCursor(dpy,win,cursor);
X            }
X
X        return;
X
X} /* Set_Pointer() */
X
XWidget MakeScrolledWindow(shellName,parent,scrollType,x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XA_Scroll_t	scrollType;
Xint			x,y;
Xint			width,height;
X{
XWidget		scrollWidget;
XArg		argList[10];
XCardinal	i=0;
X
X	XtSetArg(argList[i],XtNx,x); i++;
X	XtSetArg(argList[i],XtNy,y); i++;
X	XtSetArg(argList[i],XtNwidth,width); i++;
X	XtSetArg(argList[i],XtNheight,height); i++;
X
X	switch (scrollType)
X	{
X		case NOSCROLL:
X			break;
X		case VERTONLY:
X			XtSetArg(argList[i],XtNforceVerticalSB,True); i++;
X			break;
X		case HORIZONLY:
X			XtSetArg(argList[i],XtNforceHorizontalSB,True); i++;
X			break;
X		case VERTHORIZ:
X			XtSetArg(argList[i],XtNforceVerticalSB,True); i++;
X			XtSetArg(argList[i],XtNforceHorizontalSB,True); i++;
X			break;
X	}
X
X	scrollWidget = XtCreateManagedWidget(shellName,XwswindowWidgetClass,
X				parent,argList,i);
X	return(scrollWidget);
X
X} /* MakeScrolledWindow() */
X
XWidget MakeVPort(shellName,parent,scrollType,x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XA_Scroll_t	scrollType;
Xint			x,y;
Xint			width,height;
X{
X	Widget		shellWind;
X	Arg			argList[10];
X	Cardinal	i=0;
X
X	XtSetArg(argList[i],XtNx,x); i++;
X	XtSetArg(argList[i],XtNy,y); i++;
X	XtSetArg(argList[i],XtNwidth,width); i++;
X	XtSetArg(argList[i],XtNheight,height); i++;
X
X	switch (scrollType)
X	{
X		case NOSCROLL:
X			break;
X		case VERTONLY:
X			XtSetArg(argList[i],XtNallowVert,True); i++;
X			XtSetArg(argList[i],XtNforceBars,True); i++;
X			break;
X		case HORIZONLY:
X			XtSetArg(argList[i],XtNallowHoriz,TRUE); i++;
X			XtSetArg(argList[i],XtNforceBars,TRUE); i++;
X			break;
X		case VERTHORIZ:
X			XtSetArg(argList[i],XtNallowVert,TRUE); i++;
X			XtSetArg(argList[i],XtNallowHoriz,TRUE); i++;
X			XtSetArg(argList[i],XtNforceBars,TRUE); i++;
X			break;
X	}
X
X	shellWind = XtCreateManagedWidget(shellName,viewportWidgetClass,parent,
X				  argList,i);
X
X	return(shellWind);
X}
X
X
XWidget MakeList(shellName,parent,scrollType,vportWind,ncols,callBackProc,
X			strings,x,y,width,height,nitems,rowspacing)
Xchar		*shellName;
XWidget		parent;
XA_Scroll_t	scrollType;
XWidget 		*vportWind;	/* returned */
Xchar		*strings[];
Xint			ncols;
XXtCallbackProc	callBackProc;
Xint			x,y;
Xint			width,height;
Xint		nitems;
Xint		rowspacing;
X{
X	Widget		listWind;
X	Arg			argList[15];
X	Cardinal	i=0;
X
X/*	*vportWind = MakeVPort("XTDvport",parent,scrollType,
X				 x,y,width,height);
X*/
X	*vportWind = MakeScrolledWindow("XTDvport",parent,scrollType,
X				 x,y,width,height);
X	XtSetArg(argList[i],XtNx,x);	i++;
X	XtSetArg(argList[i],XtNy,y);	i++;
X	XtSetArg(argList[i],XtNwidth,width);	i++; 
X/*	XtSetArg(argList[i],XtNheight,height);	i++;*/
X
X	XtSetArg(argList[i],XtNdefaultColumns,ncols);	i++;
X	XtSetArg(argList[i],XtNforceColumns,TRUE);	i++;
X/*	XtSetArg(argList[i],XtNverticalList,True);	i++; */
X	XtSetArg(argList[i],XtNpasteBuffer,True);	i++;
X	XtSetArg(argList[i],XtNlist,strings);	i++;
X	if (nitems) {
X		XtSetArg(argList[i],XtNnumberStrings,nitems);	i++;
X		}
X	if (rowspacing) {
X		XtSetArg(argList[i],XtNrowSpacing,rowspacing);	i++;
X		}
X
X	listWind = XtCreateManagedWidget(shellName,
X				listWidgetClass, *vportWind, argList, i);
X						
X	if (callBackProc)
X		XtAddCallback(listWind,"callback",callBackProc,NULL);
X
X	return(listWind);
X} /* MakeList */
X
XWidget MakeATopLevel(widget_name,parent,x,y,width,height)
Xchar	*widget_name;
XWidget	parent;
Xint	x,y;
Xint	width,height;
X
X{
XArg             arglist[10];
XCardinal        i=0;
XWidget		w;
X
X	XtSetArg(arglist[i],XtNx,x);		i++;
X	XtSetArg(arglist[i],XtNy,y);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X
X/*	w = XtCreateManagedWidget(widget_name, transientShellWidgetClass, */
X	w = XtCreateManagedWidget(widget_name, applicationShellWidgetClass,
X				parent, arglist, i);
X
X/*	XtAddEventHandler(w,EnterWindowMask,0,CBSetInputFocus,NULL);*/
X/*	XtAddEventHandler(w,LeaveWindowMask,0,CBSetInputFocus,NULL);*/
X	return(w);
X} /* MakeATopLevel() */
X
XWidget MakeATopLevelOverride(widget_name,parent,x,y,width,height)
Xchar	*widget_name;
XWidget	parent;
Xint	x,y;
Xint	width,height;
X
X{
XArg             arglist[10];
XCardinal        i=0;
XWidget		w;
X
X	XtSetArg(arglist[i],XtNx,x);		i++;
X	XtSetArg(arglist[i],XtNy,y);		i++;
X	XtSetArg(arglist[i],XtNwidth,width);	i++;
X	XtSetArg(arglist[i],XtNheight,height);	i++;
X
X	w = XtCreateManagedWidget(widget_name, overrideShellWidgetClass,
X				parent, arglist, i);
X
X	XtAddEventHandler(w,EnterWindowMask,0,CBSetInputFocus,NULL);
X
X	return(w);
X} /* MakeATopLevelOverride() */
X
X
XWidget MakeRasterImage(shellName,parent,x,y,image,callBackProc,cbp_param)
Xchar		*shellName;
XWidget		parent;
Xint		x,y;
XXImage		*image;
XXtCallbackProc	callBackProc;
Xcaddr_t		cbp_param;
X{
XWidget	w;
XArg	argList[10];
XCardinal i=0;
X
X	XtSetArg(argList[i],XtNx,x);	i++;
X	XtSetArg(argList[i],XtNy,y);	i++;
X	XtSetArg(argList[i],XtNsRimage,image);	i++;
X	XtSetArg(argList[i],XtNinvertOnSelect,False);	i++;
X	w = XtCreateManagedWidget(shellName,XwsrasterWidgetClass,
X				parent,argList,i);
X	if (callBackProc)
X		XtAddCallback(w,"select",callBackProc,cbp_param);
X
X	return(w);
X
X} /* MakeRasterImage() */
X
XSetValuatorMax(w,max)
X{
XArg	argList[10];
XCardinal i=0;
X
X	XtSetArg(argList[i],XtNsliderMax,max);	i++;
X	XtSetValues(w,argList,i);
X	
X}
X
XWidget MakeValuator(shellName,parent,x,y,width,height,vert,min,max,origin,
X			extent,
X			cbpMoved,mdata,cbpReleased,rdata,cbpSelected,sdata)
Xchar		*shellName;
XWidget		parent;
Xint		x,y;
Xint		width,height;
Xchar		vert;		/*is it vertical ? */
Xint		min,max,origin;
XXtCallbackProc	cbpMoved;
Xcaddr_t		mdata;
XXtCallbackProc	cbpReleased;
Xcaddr_t		rdata;
XXtCallbackProc	cbpSelected;
Xcaddr_t		sdata;
X{
XWidget	w;
XArg	argList[10];
XCardinal i=0;
X	XtSetArg(argList[i],XtNx,x);	i++;
X	XtSetArg(argList[i],XtNy,y);	i++;
X	XtSetArg(argList[i],XtNwidth,width);	i++;
X	XtSetArg(argList[i],XtNheight,height);	i++;
X	XtSetArg(argList[i],XtNsliderMin,min);	i++;
X	XtSetArg(argList[i],XtNsliderMax,max);	i++;
X	XtSetArg(argList[i],XtNsliderOrigin,origin);	i++;
X	XtSetArg(argList[i],XtNsliderExtent,extent);	i++;
X	if (!vert)
X		XtSetArg(argList[i],XtNslideOrientation,XwHORIZONTAL);	i++;
X
X	w = XtCreateManagedWidget(shellName,XwvaluatorWidgetClass,
X				parent,argList,i);
X	if (cbpMoved)
X		XtAddCallback(w,"sliderMoved",cbpMoved,mdata);
X	if (cbpReleased)
X		XtAddCallback(w,"sliderReleased",cbpReleased,rdata);
X	if (cbpSelected)
X		XtAddCallback(w,"areaSelected",cbpSelected,sdata);
X
X	return(w);
X
X} /* MakeValuator() */
X
X
X
XDialogAddTrans(w,trans)
XWidget w;
Xchar *trans;
X{
XXtTranslations	transTable;
X	
X	transTable = XtParseTranslationTable(trans);
X	XtOverrideTranslations(gr_DialogGetTextWind(w),transTable);
X}
X
X
X
X
XWidget MakeText(shellName,parent,scrollType,textSelect,textSource,
X			string,slength,x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XA_Scroll_t	scrollType;
XA_TextSelect_t	textSelect;
XA_TextSource_t	textSource;
Xchar		*string;
Xint		slength;	/* length of string */
Xint		x,y;
Xint		width,height;
X{
X
XWidget	textWidget;
XArg	argList[15];
XCardinal i=0;
X
X	XtSetArg(argList[i],XtNx,x);	i++;
X	XtSetArg(argList[i],XtNy,y);	i++;
X	XtSetArg(argList[i],XtNwidth,width);	i++;
X	XtSetArg(argList[i],XtNheight,height);	i++;
X
X	switch (scrollType) {
X		case NOSCROLL:
X			break;
X		case VERTONLY:
X			XtSetArg(argList[i],XtNtextOptions,
X					scrollVertical); i++;
X			break;
X		case HORIZONLY:
X			XtSetArg(argList[i],XtNtextOptions,
X					scrollHorizontal); i++;
X			break;
X		case VERTHORIZ:
X			XtSetArg(argList[i],XtNtextOptions,
X				scrollHorizontal|scrollVertical); i++;
X			break;
X		}
X
X	if (textSelect == SELECTABLE)
X		XtSetArg(argList[i],XtNsensitive,TRUE);
X	else
X		XtSetArg(argList[i],XtNsensitive,FALSE);
X	i++;
X
X	if (textSource == STRINGSOURCE) {
X		XtSetArg(argList[i],XtNlength,slength);	i++;
X		XtSetArg(argList[i],XtNstring,string);	i++;
X                XtSetArg(argList[i],XtNeditType,XttextEdit);  i++;
X
X		textWidget= XtCreateManagedWidget(shellName,
X				asciiStringWidgetClass, parent, argList, i);
X		}
X	else {
X                XtSetArg(argList[i],XtNeditType,XttextAppend);  i++;
X		if (string)
X			XtSetArg(argList[i],XtNfile,string);	i++;
X
X		textWidget= XtCreateManagedWidget(shellName,
X				asciiDiskWidgetClass, parent, argList, i);
X		}
X
X	XtAddEventHandler(textWidget,EnterWindowMask,0,CBSetInputFocus,NULL);
X
X
X	XtTextEnableRedisplay(textWidget);
X
X	return(textWidget);
X} /* MakeText() */
END-of-xstuff.c
echo file: xstuff2.c
sed 's/^X//' >xstuff2.c << 'END-of-xstuff2.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <X11/Xlib.h>
X#include <X11/StringDefs.h>
X#include <X11/IntrinsicP.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X
X#ifdef XtSpecificationRelease
X/*R4 or later */
X#include <X11/Xaw/Viewport.h>
X#include <X11/Xaw/List.h>
X#include <X11/Xaw/Text.h>
X#include <X11/Xw/Xw.h>
X#include <X11/Xw/XwP.h>
X#include <X11/Xw/Arrow.h>
X#include <X11/Xw/List.h>
X#include <X11/Xw/Valuator.h>
X#include <X11/Xw/BBoard.h>
X#include <X11/Xw/ScrollBarP.h>
X#include <X11/Xw/ScrollBar.h>
X#include <X11/Xw/SWindowP.h>
X#include <X11/Xw/SWindow.h>
X#include <X11/Xw/Toggle.h>
X#else
X#include <X11/Viewport.h>
X#include <X11/List.h>
X#include <X11/Text.h>
X#include <Xw/Xw.h>
X#include <Xw/XwP.h>
X#include <Xw/Arrow.h>
X#include <Xw/List.h>
X#include <Xw/Valuator.h>
X#include <Xw/BBoard.h>
X#include <Xw/ScrollBarP.h>
X#include <Xw/ScrollBar.h>
X#include <Xw/SWindowP.h>
X#include <Xw/SWindow.h>
X#include <Xw/Toggle.h>
X#endif
X
X#include "ximage.h"
X#include "xstuff.h"
X#include "xstuff2.h"
X
XWidget NewMakeVPort(shellName,parent,scrollType,vscrlEv,hscrlEv,grain,
X				client_data,
X				x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XA_Scroll_t	scrollType;
XXtCallbackProc	vscrlEv,hscrlEv;
Xcaddr_t		client_data;
Xint		grain;
Xint		x,y;
Xint		width,height;
X{
XWidget		shellWind;
XArg		argList[15];
XCardinal	i=0;
X
X	XtSetArg(argList[i],XtNx,x); i++;
X	XtSetArg(argList[i],XtNy,y); i++;
X	XtSetArg(argList[i],XtNwidth,width); i++;
X	XtSetArg(argList[i],XtNheight,height); i++;
X	XtSetArg(argList[i],XtNgranularity,grain); i++;
X	XtSetArg(argList[i],XtNinitialDelay,1000); i++;
X	XtSetArg(argList[i],XtNrepeatRate,500); i++;
X	switch (scrollType)
X	{
X		case NOSCROLL:
X			XtSetArg(argList[i],XtNforceVerticalSB,FALSE); i++;
X			XtSetArg(argList[i],XtNforceHorizontalSB,FALSE); i++;
X			break;
X		case VERTONLY:
X			XtSetArg(argList[i],XtNforceVerticalSB,TRUE); i++;
X			XtSetArg(argList[i],XtNforceHorizontalSB,FALSE); i++;
X			break;
X		case HORIZONLY:
X			XtSetArg(argList[i],XtNforceVerticalSB,FALSE); i++;
X			XtSetArg(argList[i],XtNforceHorizontalSB,TRUE); i++;
X			break;
X		case VERTHORIZ:
X			XtSetArg(argList[i],XtNforceVerticalSB,TRUE); i++;
X			XtSetArg(argList[i],XtNforceHorizontalSB,TRUE); i++;
X			break;
X	}
X
X	shellWind = XtCreateManagedWidget(shellName,
X				XwswindowWidgetClass,parent,argList,i);
X	if (vscrlEv)
X		XtAddCallback(shellWind,"vScrollEvent",vscrlEv,client_data);
X	if (hscrlEv)
X		XtAddCallback(shellWind,"hScrollEvent",hscrlEv,client_data);
X	return(shellWind);
X}
X
X
XWidget NewMakeListSimple(shellName,vportWind,ncols,callBackProc,
X			client_data,strings,x,y)
Xchar		*shellName;
XWidget		*vportWind;
Xint			ncols;
XXtCallbackProc	callBackProc;
Xcaddr_t		client_data;
Xchar		*strings[];
Xint			x,y;
X{
X	Widget		listWind;
X	Arg			argList[10];
X	Cardinal	i=0;
X
X	XtSetArg(argList[i],XtNx,x);	i++;
X	XtSetArg(argList[i],XtNy,y);	i++;
X	XtSetArg(argList[i],XtNlist,strings);	i++;
X	XtSetArg(argList[i],XtNborderWidth,0); i++;
X	XtSetArg(argList[i],XtNdefaultColumns,ncols);	i++;
X	XtSetArg(argList[i],XtNforceColumns,True);	i++;
X	listWind = XtCreateManagedWidget(shellName,
X			listWidgetClass, *vportWind, argList, i);
X						
X	if (callBackProc)
X		XtAddCallback(listWind,"callback",callBackProc,client_data);
X
X	return(listWind);
X}
X
XWidget NewMakeList(shellName,parent,vportWind,scrollType,ncols,grain,
X			vscrlEv,hscrlEv,callBackProc,client_data,
X			strings,x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XWidget		*vportWind; /* returned */
XA_Scroll_t	scrollType;
Xchar		*strings[];
Xint		ncols,grain;
XXtCallbackProc	callBackProc,vscrlEv,hscrlEv;
Xcaddr_t		client_data;
Xint		x,y;
Xint		width,height;
X{
XWidget		listWind;
X
X	*vportWind = NewMakeVPort("XTDvport",parent,scrollType,
X				 vscrlEv,hscrlEv,grain,client_data,
X				 x,y,width,height);
X
X	listWind = NewMakeListSimple(shellName,vportWind,
X				 ncols,callBackProc,
X				 client_data,strings,1,1);
X
X	return(listWind);
X}
X
X
XWidget NewMakeListStatic(shellName,parent,vportWind,ncols,callBackProc,
X			client_data,strings,x,y,width,height)
Xchar		*shellName;
XWidget		parent;
XWidget		*vportWind;
Xchar		*strings[];
Xint		ncols;
XXtCallbackProc	callBackProc;
Xcaddr_t		client_data;
Xint		x,y;
Xint		width,height;
X{
XWidget		listWind;
X
X	*vportWind = Make_Board(shellName,parent,x,y,width,height);
X
X	listWind = NewMakeListSimple(shellName,vportWind,
X				 ncols,callBackProc,
X				 client_data,strings,1,1);
X
X	return(listWind);
X}
X
X
XSetToggle(toggle,value)
XWidget toggle;
Xchar value; /* True or False */
X{
Xstatic  Arg setTrue[]={{XtNset,(XtArgVal)True}};
Xstatic  Arg setFalse[]={{XtNset,(XtArgVal)False}};
X
X	if (value) 
X		XtSetValues(toggle,setTrue,1);
X	else
X		XtSetValues(toggle,setFalse,1);
X}
X
XSetToggleString(toggle,string)
XWidget toggle;
Xchar *string;
X{
XArg arglist[2];
X
X	XtSetArg(arglist[0],XtNlabel,string);
X	XtSetValues(toggle,arglist,1);
X}
X
XSetButtonString(button,string)
XWidget button;
Xchar *string;
X{
XArg arglist[2];
X
X	XtSetArg(arglist[0],XtNlabel,string);
X	XtSetValues(button,arglist,1);
X}
X
XSetLabelString(w,string)
XWidget w;
Xchar *string;
X{
XArg arglist[2];
X
X	XtSetArg(arglist[0],XtNlabel,string);
X	XtSetValues(w,arglist,1);
X}
X
X
XAppendText(w,s)
XWidget w;
Xchar *s;
X{
X#ifndef XtSpecificationRelease
X/* previous to R4 */
XXtTextBlock text;
XXtTextPosition ptr;
X#else
XXawTextBlock text;
XXawTextPosition ptr;
X#endif
X	ptr = XtTextGetInsertionPoint(w);
X
X        text.ptr = s;
X        text.firstPos = 0;
X        text.length = strlen(s);
X        text.format = FMT8BIT;
X        (void) XtTextReplace(w,ptr,strlen(s)+ptr,&text);
X
X        XtTextDisplay(w);
X}
X
XRedisplayTextEdit(w,string,size)
X/* This redisplays the text edit string and removes trailing garbage */
XWidget w;
Xchar *string;
Xint size;
X{
Xint x,end;
X
X        end = strlen(string);
X        for (x=end;x <size; x++)
X                string[x]=' ';
X        string[size-1] = '\0';
X
X	XtTextSetInsertionPoint(w,end);
X/* this works with R4 but not with R3 */
X/* R3  dumps core */
X
X#ifdef XtSpecificationRelease  
X	/* then R4 or later */
X	XtTextEnableRedisplay(w);
X	XtTextInvalidate(w,0,size);
X#endif
X/***************/
X
X        string[end]='\0';
X	XtTextSetInsertionPoint(w,end);
X
X}
X
X
XSetVPortVertScrollBar(w,pos)
X/* only works with HP widgets */
XWidget	w;
Xint	pos;
X{
Xint i;
XArg arglist[1];
XArg arglist2[10];
X
X	XtSetArg(arglist2[0],XtNsliderOrigin,&i);
X	XtSetArg(arglist2[1],NULL,NULL);
X	XtGetValues(((XwSWindowWidget)w)->swindow.vScrollBar,arglist2,1);
X/*	printf("Before: value is %d\n",i);*/
X
X	XtSetArg(arglist[0],XtNsliderOrigin,pos);
X	XtSetValues(((XwSWindowWidget)w)->swindow.vScrollBar,arglist,1);
X
X	XtSetArg(arglist2[0],XtNsliderOrigin,&i);
X	XtSetArg(arglist2[1],NULL,NULL);
X	XtGetValues(((XwSWindowWidget)w)->swindow.vScrollBar,arglist2,1);
X/*	printf("After: value is %d\n",i);*/
X
X}
END-of-xstuff2.c
echo file: xinit.c
sed 's/^X//' >xinit.c << 'END-of-xinit.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include <stdio.h>
X#include <netdb.h>
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/StringDefs.h>
X#include <X11/Xatom.h>
X
X#ifdef XtSpecificationRelease
X/*R4 or later */
X#include <X11/Xaw/Box.h>
X#include <X11/Xw/BBoard.h>
X#else
X#include <X11/Box.h>
X#include <Xw/BBoard.h>
X#endif
X
X#include "ximage.h"
X#include "xstuff.h"
X
X#define XIMAGEFONT      "6x13"
X#define ALTFONT1        "6x12"
X#define ALTFONT2        "6x10"
X#define ALTFONT3        "fixed"
X#define DEFAULT_DTM_INPORT "7777"
X
XXFontStruct *ximageFont;
X
Xint	expand = 1;
X
XWidget toplevel;	/* The top dude of everything ...really everything..*/
XWidget toplevelform;	/* The top composite widget, parent of all the shells*/
XDisplay *myDpy;
X
Xchar   *dtmPortId;
Xextern char *palPortId;
Xextern char sendPalette;
X
Xextern void ETDirReturn();
Xextern void ETRetOpen();
Xextern void ETJumpToYDimDialog();
Xextern void ETJumpToOk();
Xextern void ETTextInpReturn();
XXtActionsRec XIactionTable[] = {{"ETDirReturn",ETDirReturn},
X				{"ETRetOpen",ETRetOpen},
X				{"ETJumpToYDimDialog",ETJumpToYDimDialog},
X				{"ETJumpToOk",ETJumpToOk},
X				{"ETTextInpReturn",ETTextInpReturn}};
X
Xstatic XtResource resources[]= {
X		{ "installCMap","InstallCMap",XtRBoolean,sizeof(Boolean),
X		XtOffset(XIResourcesPtr,installCMap), 
X		XtRBoolean, False }
X	};
X
XXIResources appResources;
XBoolean defStaticVisual;
Xextern palPortID;
X
X
X
X
Xstatic void PrintUsage()
X{
X	printf("usage: ximage [ -DTMIN host:port ] [-sendpal host:port] [(X options)]\n");
X
X}
X
X
X
Xstatic void PrintParams(argc,argv)
Xint argc;
Xchar *argv[];
X{
Xint n;
X
X	n = argc;
X	while (argc) {
X		printf("argv[%d] = %s\n",n-argc,*argv);
X		argc--;
X		argv++;
X		}
X}
X
X
X
X
XParseParameters(argc,argv)
Xint argc;
Xchar *argv[];
X{
Xint  l;
Xchar buff[256];
X
X#ifdef DEBUG
X	PrintParams(argc,argv);
X#endif
X
X	while (argc) {
X	    	if ((!strcmp(*argv,"-DTMIN"))||(!strcmp(*argv,"-DTM"))) {
X			argc--;
X			argv++;
X			if (!argc) {
X				PrintUsage();
X				return;
X				}
X			else {
X				l = strlen(*argv);
X				if (l > 80) {
X					strncpy(dtmPortId,*argv,80);
X					dtmPortId[79] = '\0'; 
X					}
X				else
X					sprintf(dtmPortId,"%s",*argv);
X				sprintf(buff,"portID = %s\n",dtmPortId);
X				PrintMesg(buff);
X				}
X		 	}
X		if (!strcmp(*argv,"-sendpal")) {
X			argc--;
X			argv++;
X			if (!argc) {
X				PrintUsage();
X				return;
X				}
X			else {
X				palPortId = *argv;
X				sendPalette = TRUE;
X				sprintf(buff,
X					"send Pallette DTM port ID = %s\n",
X					palPortId);
X				PrintMesg(buff);
X				}
X			}
X		argc--;
X		argv++;
X		} 
X}
X
Xvoid DevNull(name,type,class,defaultp,params,num_params)
XString name;
XString type;
XString class;
XString defaultp;
XString *params;
XCardinal *num_params;
X{
X/* Dev Null error handler .... shhhh*/
X}
X
X
Xstatic void LoadFont(myDpy)
XDisplay *myDpy;
X{
X	ximageFont = XLoadQueryFont(myDpy,XIMAGEFONT);
X	if (!ximageFont) {
X		fprintf(stderr,"font %s is not available\n",XIMAGEFONT);
X		fprintf(stderr,"will use font %s\n",ALTFONT1);
X		ximageFont = XLoadQueryFont(myDpy,ALTFONT1);
X		}
X	if (!ximageFont) {
X		fprintf(stderr,"font %s is not available\n",ALTFONT1);
X		fprintf(stderr,"will use font %s\n",ALTFONT2);
X		ximageFont = XLoadQueryFont(myDpy,ALTFONT2);
X		}
X	if (!ximageFont) {
X		fprintf(stderr,"font %s is not available\n",ALTFONT2);
X		fprintf(stderr,"will use font %s\n",ALTFONT3);
X		ximageFont = XLoadQueryFont(myDpy,ALTFONT3);
X		}
X	if (!ximageFont) {
X		fprintf(stderr,"font %s is not available\n",ALTFONT3);
X		fprintf(stderr,"ximage will use default font\n");
X		}
X}
X
X
XInitialize(argc,argv)
Xint argc;
Xchar *argv[];
X{
XArg		arglist[10];
XCardinal	i=0;
Xchar		buff[128];
Xchar		buff2[256];
XDisplay		*dpy;
Xint		screen;
XVisual		*myVis;
Xchar		name[80];
Xstruct	hostent	*hostInfo;
Xunsigned char	*bla;
X
X	if (!(dtmPortId = XIMalloc(256))) {
X		printf("Coulnd't malloc .... exiting \n");
X		exit(0);
X		}
X
X	if (!gethostname(name,80)) {
X		if (hostInfo = gethostbyname(name)) {
X		/*	bla = (unsigned char *) hostInfo->h_addr_list[0];*/
X                        bla = (unsigned char *) hostInfo->h_addr;
X
X			sprintf(dtmPortId,"%d.%d.%d.%d:%s",
X				bla[0],bla[1],bla[2],bla[3],
X				DEFAULT_DTM_INPORT);
X			}
X		else {
X			sprintf(dtmPortId,"%s:%s",name,DEFAULT_DTM_INPORT);
X			sprintf(buff,"gethostbyname(%s) failed\n",name);
X			PrintMesg(buff);
X			}
X		}
X	else {
X		sprintf(dtmPortId,":%s",DEFAULT_DTM_INPORT);
X		PrintMesg("gethostname() failed\n");
X		}
X
X	if (argc)
X		ParseParameters(argc,argv);
X
X	toplevel = XtInitialize(argv[0],"ximage",NULL,0,&argc,argv);
X#ifndef DEBUG
X/*
X                XtSetErrorMsgHandler(DevNull);
X                XtSetErrorHandler(DevNull);
X*/
X                /* nothing user can do... only developer */
X                /* so don't print it */
X                XtSetWarningMsgHandler(DevNull);
X                XtSetWarningHandler(DevNull);
X#endif
X
X	XtGetApplicationResources(toplevel, &appResources, resources,
X				XtNumber(resources),(ArgList) NULL,0);
X
X	toplevelform = XtCreateManagedWidget(argv[0],XwbulletinWidgetClass,
X					toplevel,arglist,i);
X
X	XtAddActions(XIactionTable,XtNumber(XIactionTable));
X
X	dpy    = XtDisplay(toplevel);
X	screen = DefaultScreen(dpy);
X	myDpy = dpy;
X
X	{
X	Visual *vis;
X	vis = DefaultVisual(dpy,screen);
X	if (vis->class == StaticColor)
X		defStaticVisual=TRUE;
X	else
X		defStaticVisual=FALSE;
X	}
X
X	LoadFont(dpy);
X
X	if (! InitImage(dpy))
X		exit(0);
X	if (! InitPalette(dpy))
X		exit(0);
X	if (! InitPalEntry(dpy))
X		exit(0);
X	if (! InitGetAFile(dpy))
X		exit(0);
X	if (! InitData(dpy))
X		exit(0);
X	if (! InitAnimation(dpy))
X		exit(0);
X	if (! InitNotebook(dpy))
X		exit(0);
X	if (! InitDTM())
X		exit(0);
X
X	{
X	char *garbage;
X	garbage = (char *) XIMalloc(1025);
X	XIFree(garbage);
X	}
X
X	Init_Ctrl_Window(toplevelform);
X
X	/* Print the Display Info*/
X
X  if (8 == DisplayPlanes(dpy,screen)) /* perfectionism at it's wosrt*/
X    sprintf(buff,"Display is an %d plane %%s with %d entries in Colormap\n",
X			DisplayPlanes(dpy,screen),XDisplayCells(dpy,screen));
X  else
X    sprintf(buff,"Display is a %d plane %%s with %d entries in Colormap\n",
X			DisplayPlanes(dpy,screen),XDisplayCells(dpy,screen));
X
X	myVis = GetVisual(dpy);
X	switch (myVis->class) {
X		case StaticGray:
X			sprintf(buff2,buff,"StaticGray");
X			break;
X		case GrayScale:
X			sprintf(buff2,buff,"GrayScale");
X			break;
X		case StaticColor:
X			sprintf(buff2,buff,"StaticColor");
X			break;
X		case PseudoColor:
X			sprintf(buff2,buff,"PseudoColor");
X			break;
X		case TrueColor:
X			sprintf(buff2,buff,"TrueColor");
X			break;
X		case DirectColor:
X			sprintf(buff2,buff,"DirectColor");
X			break;
X		}
X	PrintMesg(buff2);
X	PrintMesg("Done initializing NCSA X Image.\n");
X
X} /* Initialize() */
X
END-of-xinit.c
echo file: y.tab.c
sed 's/^X//' >y.tab.c << 'END-of-y.tab.c'
Xextern char *malloc(), *realloc();
X
X# line 2 "gram.y"
X#include "sem_stack.h"
X#include "value.h"
X#include "data.h"
X#include "parseSupport.h"
X
X#define MALLOC	XIMalloc
X#define FREE	XIFree
X#define FALSE	0
X#define TRUE	1
X#ifdef DEBUG
X#define DEBUGPRINT	printf
X#else
X#define	DEBUGPRINT	DevNull
X#endif
X
X
Xchar    lexIdent[1024]; /* contains last identifier read in */
Xfloat   lexFloat;       /* contains last float read in */
Xstatic	union sem_stack_type *tmp;
Xunion sem_stack_type *addressVar;
X
Xint     yylval;
Xint	numParams;
Xchar	errorDuringParsing = FALSE;
X
Xstatic void DevNull(s)
Xchar *s;
X{
X}
X
X
X# define TASGN 257
X# define TIDENT 258
X# define TFLOAT 259
X# define TSTRING 260
X# define TLPAREN 261
X# define TRPAREN 262
X# define TCOMMA 263
X# define TERROR 264
X# define TSIN 265
X# define TCOS 266
X# define TTAN 267
X# define TASIN 268
X# define TACOS 269
X# define TATAN 270
X# define TSINH 271
X# define TCOSH 272
X# define TTANH 273
X# define TDSIN 274
X# define TDCOS 275
X# define TDTAN 276
X# define TDASIN 277
X# define TDACOS 278
X# define TDATAN 279
X# define TDSINH 280
X# define TDCOSH 281
X# define TDTANH 282
X# define TDTOR 283
X# define TRTOD 284
X# define TSQRT 285
X# define TLOG 286
X# define TLOG10 287
X# define TEXP 288
X# define TABS 289
X# define TMEAN 290
X# define TMAX 291
X# define TMIN 292
X# define TPTS 293
X# define TCOLS 294
X# define TROWS 295
X# define TCOLRANGE 296
X# define TROWRANGE 297
X# define TCOLMEAN 298
X# define TROWMEAN 299
X# define TCOLSDEV 300
X# define TROWSDEV 301
X# define TSHL 302
X# define TSHR 303
X# define TSHU 304
X# define TSHD 305
X# define TREMOTE 306
X# define TREXEC 307
X# define TADDOP 308
X# define TMULOP 309
X#define yyclearin yychar = -1
X#define yyerrok yyerrflag = 0
Xextern int yychar;
Xextern int yyerrflag;
X#ifndef YYMAXDEPTH
X#define YYMAXDEPTH 150
X#endif
X#ifndef YYSTYPE
X#define YYSTYPE int
X#endif
XYYSTYPE yylval, yyval;
X# define YYERRCODE 256
X
X# line 520 "gram.y"
X
X
X#include "lex.yy.c"
X#include "parse2.c"
X
Xyyerror(mesg)
Xchar *mesg;
X{
Xchar buff[256];
X	sprintf(buff,"Error parsing: %s\n",mesg);
X	WriteText(buff);
X}
Xint yyexca[] ={
X-1, 1,
X	0, -1,
X	-2, 0,
X-1, 12,
X	261, 24,
X	-2, 23,
X	};
X# define YYNPROD 62
X# define YYLAST 135
Xint yyact[]={
X
X     4,    13,    52,    10,     4,    59,    56,    17,    18,    19,
X    20,    21,    22,    23,    24,    25,    38,    39,    40,    41,
X    42,    43,    44,    45,    46,    47,    48,    26,    27,    28,
X    29,    30,    31,    32,    33,    51,    52,    75,    74,    73,
X    74,     4,    13,    71,    34,    35,    36,    37,    49,    50,
X    16,    51,    52,    55,     5,    12,     3,     8,    66,     7,
X    65,    69,    62,    15,    61,    14,    54,    11,    58,     6,
X    57,     9,     2,     1,     0,     0,     0,     0,     0,     0,
X    53,     0,     0,     0,     0,     0,     0,     0,     0,     0,
X     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
X     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
X     0,     0,     0,     0,     0,     0,     0,    70,    70,    68,
X    68,    67,    67,    72,    60,     0,     0,    63,    64,     0,
X    70,     0,    68,    76,    67 };
Xint yypact[]={
X
X  -254, -1000,  -203, -1000, -1000,  -258,  -273, -1000, -1000, -1000,
X  -258, -1000, -1000, -1000,  -208,  -255, -1000, -1000, -1000, -1000,
X -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
X -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
X -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
X -1000, -1000, -1000,  -257,  -258, -1000, -1000,  -258,  -258, -1000,
X  -273,  -217,  -217,  -307, -1000,  -223, -1000, -1000, -1000, -1000,
X -1000, -1000,  -225, -1000,  -217, -1000, -1000 };
Xint yypgo[]={
X
X     0,    73,    72,    69,    59,    57,    71,    70,    68,    67,
X    66,    65,    64,    60,    63,    62,    58,    61,    55 };
Xint yyr1[]={
X
X     0,     1,     3,     3,     3,     3,     7,     3,     8,     3,
X    10,     3,    12,     6,    15,     6,    13,    13,    16,    16,
X    16,     5,    17,     4,    11,     2,    18,     9,    14,    14,
X    14,    14,    14,    14,    14,    14,    14,    14,    14,    14,
X    14,    14,    14,    14,    14,    14,    14,    14,    14,    14,
X    14,    14,    14,    14,    14,    14,    14,    14,    14,    14,
X    14,    14 };
Xint yyr2[]={
X
X     0,     7,     2,     3,     3,     7,     1,     9,     1,     9,
X     1,     7,     1,    11,     1,    11,     3,     7,     3,     3,
X     3,     3,     3,     3,     3,     3,     3,     2,     3,     3,
X     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
X     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
X     3,     3,     3,     3,     3,     3,     3,     3,     3,     3,
X     3,     3 };
Xint yychk[]={
X
X -1000,    -1,    -2,   -18,   258,   257,    -3,    -4,    -5,    -6,
X   261,    -9,   -18,   259,   -11,   -14,   308,   265,   266,   267,
X   268,   269,   270,   271,   272,   273,   285,   286,   287,   288,
X   289,   290,   291,   292,   302,   303,   304,   305,   274,   275,
X   276,   277,   278,   279,   280,   281,   282,   283,   284,   306,
X   307,   308,   309,    -3,   -10,   261,   261,    -7,    -8,   262,
X    -3,   -12,   -15,    -3,    -3,   -13,   -16,    -4,    -5,   -17,
X   -18,   260,   -13,   262,   263,   262,   -16 };
Xint yydef[]={
X
X     0,    -2,     0,    25,    26,     0,     1,     2,     3,     4,
X     0,    10,    -2,    21,     0,     0,    27,    28,    29,    30,
X    31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
X    41,    42,    43,    44,    45,    46,    47,    48,    49,    50,
X    51,    52,    53,    54,    55,    56,    57,    58,    59,    60,
X    61,     6,     8,     0,     0,    12,    14,     0,     0,     5,
X    11,     0,     0,     7,     9,     0,    16,    18,    19,    20,
X    23,    22,     0,    13,     0,    15,    17 };
Xtypedef struct { char *t_name; int t_val; } yytoktype;
X#ifndef YYDEBUG
X#	define YYDEBUG	0	/* don't allow debugging */
X#endif
X
X#if YYDEBUG
X
Xyytoktype yytoks[] =
X{
X	"TASGN",	257,
X	"TIDENT",	258,
X	"TFLOAT",	259,
X	"TSTRING",	260,
X	"TLPAREN",	261,
X	"TRPAREN",	262,
X	"TCOMMA",	263,
X	"TERROR",	264,
X	"TSIN",	265,
X	"TCOS",	266,
X	"TTAN",	267,
X	"TASIN",	268,
X	"TACOS",	269,
X	"TATAN",	270,
X	"TSINH",	271,
X	"TCOSH",	272,
X	"TTANH",	273,
X	"TDSIN",	274,
X	"TDCOS",	275,
X	"TDTAN",	276,
X	"TDASIN",	277,
X	"TDACOS",	278,
X	"TDATAN",	279,
X	"TDSINH",	280,
X	"TDCOSH",	281,
X	"TDTANH",	282,
X	"TDTOR",	283,
X	"TRTOD",	284,
X	"TSQRT",	285,
X	"TLOG",	286,
X	"TLOG10",	287,
X	"TEXP",	288,
X	"TABS",	289,
X	"TMEAN",	290,
X	"TMAX",	291,
X	"TMIN",	292,
X	"TPTS",	293,
X	"TCOLS",	294,
X	"TROWS",	295,
X	"TCOLRANGE",	296,
X	"TROWRANGE",	297,
X	"TCOLMEAN",	298,
X	"TROWMEAN",	299,
X	"TCOLSDEV",	300,
X	"TROWSDEV",	301,
X	"TSHL",	302,
X	"TSHR",	303,
X	"TSHU",	304,
X	"TSHD",	305,
X	"TREMOTE",	306,
X	"TREXEC",	307,
X	"TADDOP",	308,
X	"TMULOP",	309,
X	"-unknown-",	-1	/* ends search */
X};
X
Xchar * yyreds[] =
X{
X	"-no such reduction-",
X	"statement : addr_variable TASGN expression",
X	"expression : valued_variable",
X	"expression : float_const",
X	"expression : function",
X	"expression : TLPAREN expression TRPAREN",
X	"expression : expression TADDOP",
X	"expression : expression TADDOP expression",
X	"expression : expression TMULOP",
X	"expression : expression TMULOP expression",
X	"expression : unary_minus",
X	"expression : unary_minus expression",
X	"function : func_name TLPAREN",
X	"function : func_name TLPAREN parameter_list TRPAREN",
X	"function : function1_id TLPAREN",
X	"function : function1_id TLPAREN parameter_list TRPAREN",
X	"parameter_list : parameter",
X	"parameter_list : parameter_list TCOMMA parameter",
X	"parameter : valued_variable",
X	"parameter : float_const",
X	"parameter : string_const",
X	"float_const : TFLOAT",
X	"string_const : TSTRING",
X	"valued_variable : ident",
X	"func_name : ident",
X	"addr_variable : ident",
X	"ident : TIDENT",
X	"unary_minus : TADDOP",
X	"function1_id : TSIN",
X	"function1_id : TCOS",
X	"function1_id : TTAN",
X	"function1_id : TASIN",
X	"function1_id : TACOS",
X	"function1_id : TATAN",
X	"function1_id : TSINH",
X	"function1_id : TCOSH",
X	"function1_id : TTANH",
X	"function1_id : TSQRT",
X	"function1_id : TLOG",
X	"function1_id : TLOG10",
X	"function1_id : TEXP",
X	"function1_id : TABS",
X	"function1_id : TMEAN",
X	"function1_id : TMAX",
X	"function1_id : TMIN",
X	"function1_id : TSHL",
X	"function1_id : TSHR",
X	"function1_id : TSHU",
X	"function1_id : TSHD",
X	"function1_id : TDSIN",
X	"function1_id : TDCOS",
X	"function1_id : TDTAN",
X	"function1_id : TDASIN",
X	"function1_id : TDACOS",
X	"function1_id : TDATAN",
X	"function1_id : TDSINH",
X	"function1_id : TDCOSH",
X	"function1_id : TDTANH",
X	"function1_id : TDTOR",
X	"function1_id : TRTOD",
X	"function1_id : TREMOTE",
X	"function1_id : TREXEC",
X};
X#endif /* YYDEBUG */
X#line 1 "/usr/lib/yaccpar"
X/*	@(#)yaccpar 1.10 89/04/04 SMI; from S5R3 1.10	*/
X
X/*
X** Skeleton parser driver for yacc output
X*/
X
X/*
X** yacc user known macros and defines
X*/
X#define YYERROR		goto yyerrlab
X#define YYACCEPT	{ free(yys); free(yyv); return(0); }
X#define YYABORT		{ free(yys); free(yyv); return(1); }
X#define YYBACKUP( newtoken, newvalue )\
X{\
X	if ( yychar >= 0 || ( yyr2[ yytmp ] >> 1 ) != 1 )\
X	{\
X		yyerror( "syntax error - cannot backup" );\
X		goto yyerrlab;\
X	}\
X	yychar = newtoken;\
X	yystate = *yyps;\
X	yylval = newvalue;\
X	goto yynewstate;\
X}
X#define YYRECOVERING()	(!!yyerrflag)
X#ifndef YYDEBUG
X#	define YYDEBUG	1	/* make debugging available */
X#endif
X
X/*
X** user known globals
X*/
Xint yydebug;			/* set to 1 to get debugging */
X
X/*
X** driver internal defines
X*/
X#define YYFLAG		(-1000)
X
X/*
X** static variables used by the parser
X*/
Xstatic YYSTYPE *yyv;			/* value stack */
Xstatic int *yys;			/* state stack */
X
Xstatic YYSTYPE *yypv;			/* top of value stack */
Xstatic int *yyps;			/* top of state stack */
X
Xstatic int yystate;			/* current state */
Xstatic int yytmp;			/* extra var (lasts between blocks) */
X
Xint yynerrs;			/* number of errors */
X
Xint yyerrflag;			/* error recovery flag */
Xint yychar;			/* current input token number */
X
X
X/*
X** yyparse - return 0 if worked, 1 if syntax error not recovered from
X*/
Xint
Xyyparse()
X{
X	register YYSTYPE *yypvt;	/* top of value stack for $vars */
X	unsigned yymaxdepth = YYMAXDEPTH;
X
X	/*
X	** Initialize externals - yyparse may be called more than once
X	*/
X	yyv = (YYSTYPE*)malloc(yymaxdepth*sizeof(YYSTYPE));
X	yys = (int*)malloc(yymaxdepth*sizeof(int));
X	if (!yyv || !yys)
X	{
X		yyerror( "out of memory" );
X		return(1);
X	}
X	yypv = &yyv[-1];
X	yyps = &yys[-1];
X	yystate = 0;
X	yytmp = 0;
X	yynerrs = 0;
X	yyerrflag = 0;
X	yychar = -1;
X
X	goto yystack;
X	{
X		register YYSTYPE *yy_pv;	/* top of value stack */
X		register int *yy_ps;		/* top of state stack */
X		register int yy_state;		/* current state */
X		register int  yy_n;		/* internal state number info */
X
X		/*
X		** get globals into registers.
X		** branch to here only if YYBACKUP was called.
X		*/
X	yynewstate:
X		yy_pv = yypv;
X		yy_ps = yyps;
X		yy_state = yystate;
X		goto yy_newstate;
X
X		/*
X		** get globals into registers.
X		** either we just started, or we just finished a reduction
X		*/
X	yystack:
X		yy_pv = yypv;
X		yy_ps = yyps;
X		yy_state = yystate;
X
X		/*
X		** top of for (;;) loop while no reductions done
X		*/
X	yy_stack:
X		/*
X		** put a state and value onto the stacks
X		*/
X#if YYDEBUG
X		/*
X		** if debugging, look up token value in list of value vs.
X		** name pairs.  0 and negative (-1) are special values.
X		** Note: linear search is used since time is not a real
X		** consideration while debugging.
X		*/
X		if ( yydebug )
X		{
X			register int yy_i;
X
X			(void)printf( "State %d, token ", yy_state );
X			if ( yychar == 0 )
X				(void)printf( "end-of-file\n" );
X			else if ( yychar < 0 )
X				(void)printf( "-none-\n" );
X			else
X			{
X				for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
X					yy_i++ )
X				{
X					if ( yytoks[yy_i].t_val == yychar )
X						break;
X				}
X				(void)printf( "%s\n", yytoks[yy_i].t_name );
X			}
X		}
X#endif /* YYDEBUG */
X		if ( ++yy_ps >= &yys[ yymaxdepth ] )	/* room on stack? */
X		{
X			/*
X			** reallocate and recover.  Note that pointers
X			** have to be reset, or bad things will happen
X			*/
X			int yyps_index = (yy_ps - yys);
X			int yypv_index = (yy_pv - yyv);
X			int yypvt_index = (yypvt - yyv);
X			yymaxdepth += YYMAXDEPTH;
X			yyv = (YYSTYPE*)realloc((char*)yyv,
X				yymaxdepth * sizeof(YYSTYPE));
X			yys = (int*)realloc((char*)yys,
X				yymaxdepth * sizeof(int));
X			if (!yyv || !yys)
X			{
X				yyerror( "yacc stack overflow" );
X				return(1);
X			}
X			yy_ps = yys + yyps_index;
X			yy_pv = yyv + yypv_index;
X			yypvt = yyv + yypvt_index;
X		}
X		*yy_ps = yy_state;
X		*++yy_pv = yyval;
X
X		/*
X		** we have a new state - find out what to do
X		*/
X	yy_newstate:
X		if ( ( yy_n = yypact[ yy_state ] ) <= YYFLAG )
X			goto yydefault;		/* simple state */
X#if YYDEBUG
X		/*
X		** if debugging, need to mark whether new token grabbed
X		*/
X		yytmp = yychar < 0;
X#endif
X		if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
X			yychar = 0;		/* reached EOF */
X#if YYDEBUG
X		if ( yydebug && yytmp )
X		{
X			register int yy_i;
X
X			(void)printf( "Received token " );
X			if ( yychar == 0 )
X				(void)printf( "end-of-file\n" );
X			else if ( yychar < 0 )
X				(void)printf( "-none-\n" );
X			else
X			{
X				for ( yy_i = 0; yytoks[yy_i].t_val >= 0;
X					yy_i++ )
X				{
X					if ( yytoks[yy_i].t_val == yychar )
X						break;
X				}
X				(void)printf( "%s\n", yytoks[yy_i].t_name );
X			}
X		}
X#endif /* YYDEBUG */
X		if ( ( ( yy_n += yychar ) < 0 ) || ( yy_n >= YYLAST ) )
X			goto yydefault;
X		if ( yychk[ yy_n = yyact[ yy_n ] ] == yychar )	/*valid shift*/
X		{
X			yychar = -1;
X			yyval = yylval;
X			yy_state = yy_n;
X			if ( yyerrflag > 0 )
X				yyerrflag--;
X			goto yy_stack;
X		}
X
X	yydefault:
X		if ( ( yy_n = yydef[ yy_state ] ) == -2 )
X		{
X#if YYDEBUG
X			yytmp = yychar < 0;
X#endif
X			if ( ( yychar < 0 ) && ( ( yychar = yylex() ) < 0 ) )
X				yychar = 0;		/* reached EOF */
X#if YYDEBUG
X			if ( yydebug && yytmp )
X			{
X				register int yy_i;
X
X				(void)printf( "Received token " );
X				if ( yychar == 0 )
X					(void)printf( "end-of-file\n" );
X				else if ( yychar < 0 )
X					(void)printf( "-none-\n" );
X				else
X				{
X					for ( yy_i = 0;
X						yytoks[yy_i].t_val >= 0;
X						yy_i++ )
X					{
X						if ( yytoks[yy_i].t_val
X							== yychar )
X						{
X							break;
X						}
X					}
X					(void)printf( "%s\n", yytoks[yy_i].t_name );
X				}
X			}
X#endif /* YYDEBUG */
X			/*
X			** look through exception table
X			*/
X			{
X				register int *yyxi = yyexca;
X
X				while ( ( *yyxi != -1 ) ||
X					( yyxi[1] != yy_state ) )
X				{
X					yyxi += 2;
X				}
X				while ( ( *(yyxi += 2) >= 0 ) &&
X					( *yyxi != yychar ) )
X					;
X				if ( ( yy_n = yyxi[1] ) < 0 )
X					YYACCEPT;
X			}
X		}
X
X		/*
X		** check for syntax error
X		*/
X		if ( yy_n == 0 )	/* have an error */
X		{
X			/* no worry about speed here! */
X			switch ( yyerrflag )
X			{
X			case 0:		/* new error */
X				yyerror( "syntax error" );
X				goto skip_init;
X			yyerrlab:
X				/*
X				** get globals into registers.
X				** we have a user generated syntax type error
X				*/
X				yy_pv = yypv;
X				yy_ps = yyps;
X				yy_state = yystate;
X				yynerrs++;
X			skip_init:
X			case 1:
X			case 2:		/* incompletely recovered error */
X					/* try again... */
X				yyerrflag = 3;
X				/*
X				** find state where "error" is a legal
X				** shift action
X				*/
X				while ( yy_ps >= yys )
X				{
X					yy_n = yypact[ *yy_ps ] + YYERRCODE;
X					if ( yy_n >= 0 && yy_n < YYLAST &&
X						yychk[yyact[yy_n]] == YYERRCODE)					{
X						/*
X						** simulate shift of "error"
X						*/
X						yy_state = yyact[ yy_n ];
X						goto yy_stack;
X					}
X					/*
X					** current state has no shift on
X					** "error", pop stack
X					*/
X#if YYDEBUG
X#	define _POP_ "Error recovery pops state %d, uncovers state %d\n"
X					if ( yydebug )
X						(void)printf( _POP_, *yy_ps,
X							yy_ps[-1] );
X#	undef _POP_
X#endif
X					yy_ps--;
X					yy_pv--;
X				}
X				/*
X				** there is no state on stack with "error" as
X				** a valid shift.  give up.
X				*/
X				YYABORT;
X			case 3:		/* no shift yet; eat a token */
X#if YYDEBUG
X				/*
X				** if debugging, look up token in list of
X				** pairs.  0 and negative shouldn't occur,
X				** but since timing doesn't matter when
X				** debugging, it doesn't hurt to leave the
X				** tests here.
X				*/
X				if ( yydebug )
X				{
X					register int yy_i;
X
X					(void)printf( "Error recovery discards " );
X					if ( yychar == 0 )
X						(void)printf( "token end-of-file\n" );
X					else if ( yychar < 0 )
X						(void)printf( "token -none-\n" );
X					else
X					{
X						for ( yy_i = 0;
X							yytoks[yy_i].t_val >= 0;
X							yy_i++ )
X						{
X							if ( yytoks[yy_i].t_val
X								== yychar )
X							{
X								break;
X							}
X						}
X						(void)printf( "token %s\n",
X							yytoks[yy_i].t_name );
X					}
X				}
X#endif /* YYDEBUG */
X				if ( yychar == 0 )	/* reached EOF. quit */
X					YYABORT;
X				yychar = -1;
X				goto yy_newstate;
X			}
X		}/* end if ( yy_n == 0 ) */
X		/*
X		** reduction by production yy_n
X		** put stack tops, etc. so things right after switch
X		*/
X#if YYDEBUG
X		/*
X		** if debugging, print the string that is the user's
X		** specification of the reduction which is just about
X		** to be done.
X		*/
X		if ( yydebug )
X			(void)printf( "Reduce by (%d) \"%s\"\n",
X				yy_n, yyreds[ yy_n ] );
X#endif
X		yytmp = yy_n;			/* value to switch over */
X		yypvt = yy_pv;			/* $vars top of value stack */
X		/*
X		** Look in goto table for next state
X		** Sorry about using yy_state here as temporary
X		** register variable, but why not, if it works...
X		** If yyr2[ yy_n ] doesn't have the low order bit
X		** set, then there is no action to be done for
X		** this reduction.  So, no saving & unsaving of
X		** registers done.  The only difference between the
X		** code just after the if and the body of the if is
X		** the goto yy_stack in the body.  This way the test
X		** can be made before the choice of what to do is needed.
X		*/
X		{
X			/* length of production doubled with extra bit */
X			register int yy_len = yyr2[ yy_n ];
X
X			if ( !( yy_len & 01 ) )
X			{
X				yy_len >>= 1;
X				yyval = ( yy_pv -= yy_len )[1];	/* $$ = $1 */
X				yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
X					*( yy_ps -= yy_len ) + 1;
X				if ( yy_state >= YYLAST ||
X					yychk[ yy_state =
X					yyact[ yy_state ] ] != -yy_n )
X				{
X					yy_state = yyact[ yypgo[ yy_n ] ];
X				}
X				goto yy_stack;
X			}
X			yy_len >>= 1;
X			yyval = ( yy_pv -= yy_len )[1];	/* $$ = $1 */
X			yy_state = yypgo[ yy_n = yyr1[ yy_n ] ] +
X				*( yy_ps -= yy_len ) + 1;
X			if ( yy_state >= YYLAST ||
X				yychk[ yy_state = yyact[ yy_state ] ] != -yy_n )
X			{
X				yy_state = yyact[ yypgo[ yy_n ] ];
X			}
X		}
X					/* save until reenter driver code */
X		yystate = yy_state;
X		yyps = yy_ps;
X		yypv = yy_pv;
X	}
X	/*
X	** code supplied by user is placed in this switch
X	*/
X	switch( yytmp )
X	{
X		
Xcase 1:
X# line 51 "gram.y"
X{
X	char buff[256];
X	union sem_stack_type *answer;
X	union sem_stack_type *answerName;
X
X	DEBUGPRINT("Applying statement: addr_variable TASGN expression\n");
X
X	if (!errorDuringParsing){
X	    answer = SS_Pop();
X	    answerName = SS_Pop();
X	    if (answer->float_const.kind == FLOAT_CONST_ID) {
X		sprintf(buff,"Answer is %f\n",answer->float_const.value);
X		DEBUGPRINT("%s",buff);
X		WriteText(buff);
X		}
X	    else {
X	    	if (answer->data.kind == DATA_ID) {
X			if (answerName->var.kind != VAR_ID) {
X				DEBUGPRINT("Internal error in parsing\n");
X				NewDataSet(answer->data.value,"answer");
X				}
X			else
X				NewDataSet(answer->data.value,
X					   answerName->var.value);
X			} 
X		}
X	    }
X	
X	} break;
Xcase 3:
X# line 84 "gram.y"
X{
X	  	DEBUGPRINT("Applying expression: TFLOAT \n");
X		} break;
Xcase 4:
X# line 88 "gram.y"
X{
X
X	  	DEBUGPRINT("Applying expression: function\n");
X
X                tmp = SS_Pop();
X		if (tmp->known_func.kind == KNOWN_FUNC_ID) {
X			ExecKnownFunction(tmp->known_func.value,numParams);
X                	}
X		else {
X		    if (tmp->known_func.kind == FUNCTION_ID) {
X			ExecUnknownFunction(tmp->known_func.value,numParams);
X			}
X		    else {
X			DEBUGPRINT("function: Internal error parsing");
X			}
X		    }
X		} break;
Xcase 5:
X# line 106 "gram.y"
X{
X	  	DEBUGPRINT(
X		"Applying expression: TLPAREN expression TRPAREN\n");
X		} break;
Xcase 6:
X# line 111 "gram.y"
X{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		} break;
Xcase 7:
X# line 117 "gram.y"
X{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecAddOp(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: expression TADDOP expression \n");
X		} break;
Xcase 8:
X# line 126 "gram.y"
X{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		} break;
Xcase 9:
X# line 132 "gram.y"
X{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecMulOp(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: expression TMULLOP expression\n");
X		} break;
Xcase 10:
X# line 141 "gram.y"
X{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		} break;
Xcase 11:
X# line 147 "gram.y"
X{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecUnaryMinus(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: unary_minus expression\n");
X		} break;
Xcase 12:
X# line 158 "gram.y"
X{numParams=0;} break;
Xcase 13:
X# line 160 "gram.y"
X{
X		/* unknown simple functions */
X	  	DEBUGPRINT(
X		"Applying func: func_name TLPAREN parameter_list TRPAREN\n");
X		DEBUGPRINT("Function has %d parameters\n",numParams);
X		} break;
Xcase 14:
X# line 167 "gram.y"
X{numParams=0;} break;
Xcase 15:
X# line 169 "gram.y"
X{
X		/* known simple functions */
X	  	DEBUGPRINT(
X		"Applying func: function1_id TLPAREN parameter_list TRPAREN\n");
X		DEBUGPRINT("Function has %d parameters\n",numParams);
X		} break;
Xcase 16:
X# line 181 "gram.y"
X{
X	  	DEBUGPRINT("Applying param_list: parameter \n");
X		} break;
Xcase 17:
X# line 185 "gram.y"
X{
X		DEBUGPRINT("Applying param_list: param_list TCOMMA parameter \n");
X		} break;
Xcase 18:
X# line 191 "gram.y"
X{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		} break;
Xcase 19:
X# line 200 "gram.y"
X{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		} break;
Xcase 20:
X# line 209 "gram.y"
X{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		} break;
Xcase 21:
X# line 220 "gram.y"
X{
X
X		tmp = SS_New();
X		tmp->float_const.value = lexFloat;
X		tmp->float_const.kind= FLOAT_CONST_ID;
X		SS_Push(tmp);
X		DEBUGPRINT("float_const: TFLOAT = %f\n",lexFloat);
X		} break;
Xcase 22:
X# line 231 "gram.y"
X{
X		tmp = SS_New();
X		tmp->var.value = (char *)MALLOC(strlen(lexIdent)+1);
X		tmp->var.kind=VAR_ID;
X		strcpy(tmp->var.value,lexIdent);
X		SS_Push(tmp);
X		/*DEBUGPRINT("Applying ident: TSTRING (%s)\n",lexIdent);*/
X		} break;
Xcase 23:
X# line 242 "gram.y"
X{
X		tmp = SS_Top();
X		tmp->type.kind=VAR_ID;
X		DEBUGPRINT("Applying valued_variable: TIDENT (%s)\n",lexIdent);
X		} break;
Xcase 24:
X# line 250 "gram.y"
X{
X		tmp = SS_Top();
X		tmp->type.kind=FUNCTION_ID;
X		DEBUGPRINT("Applying func_name: TIDENT (%s)\n",lexIdent);
X		} break;
Xcase 25:
X# line 258 "gram.y"
X{
X		tmp = SS_Top();
X		tmp->type.kind=VAR_ID;
X		addressVar = tmp;
X		DEBUGPRINT("Applying addr_variable: TIDENT (%s)\n",lexIdent);
X		} break;
Xcase 26:
X# line 267 "gram.y"
X{
X	
X		tmp = SS_New();
X		tmp->var.value = (char *)MALLOC(strlen(lexIdent)+1);
X		strcpy(tmp->var.value,lexIdent);
X		SS_Push(tmp);
X		/*DEBUGPRINT("Applying ident: TIDENT (%s)\n",lexIdent);*/
X		} break;
Xcase 28:
X# line 281 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 29:
X# line 288 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TCOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 30:
X# line 295 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TTAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 31:
X# line 302 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TASIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 32:
X# line 309 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TACOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 33:
X# line 316 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TATAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 34:
X# line 323 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSINH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 35:
X# line 330 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TCOSH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 36:
X# line 337 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TTANH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 37:
X# line 344 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSQRT;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 38:
X# line 351 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TLOG;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 39:
X# line 358 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TLOG10;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 40:
X# line 365 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TEXP;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 41:
X# line 372 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TABS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 42:
X# line 379 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TMEAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 43:
X# line 386 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TMAX;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 44:
X# line 393 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TMIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 45:
X# line 400 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSHL;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 46:
X# line 407 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSHR;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 47:
X# line 414 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSHU;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 48:
X# line 421 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TSHD;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 49:
X# line 428 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDSIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 50:
X# line 435 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDCOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 51:
X# line 442 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDTAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 52:
X# line 449 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDASIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 53:
X# line 456 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDACOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 54:
X# line 463 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDATAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 55:
X# line 470 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDSINH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 56:
X# line 477 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDCOSH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 57:
X# line 484 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDTANH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 58:
X# line 491 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TDTOR;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 59:
X# line 498 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TRTOD;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 60:
X# line 505 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TREMOTE;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
Xcase 61:
X# line 512 "gram.y"
X{
X		tmp = SS_New();
X		tmp->known_func.value = TREXEC;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		} break;
X	}
X	goto yystack;		/* reset registers in driver code */
X}
END-of-y.tab.c
echo file: parse.c
sed 's/^X//' >parse.c << 'END-of-parse.c'
X#include <stdio.h>
X#include "sem_stack_t.h"
X
X#define MALLOC	XIMalloc
X#define FREE	XIFree
X
X#define	nil	0
X#define NULL	0
X
Xstatic char *parseExpr;
Xstatic int  parseExprLength;
Xextern	char errorDuringParsing;
X
X
Xint ParseExpr(expr)
Xchar *expr;
X{
X
X	errorDuringParsing = 0;
X	parseExpr = expr;
X	parseExprLength = strlen(expr);
X	
X	yyparse();
X
X	return(1); /* return 1 on success */
X}
X
Xint GetExprChar(garbage)
X/*  This routine replace getc used in the lexical analyzer */
XFILE *garbage;
X{
X	if (parseExprLength <= 0)
X		return(EOF);
X	parseExprLength--;
X	return((int) *parseExpr++);
X
X}
X
X
Xint PutExprChar(garbage,garbage2)
Xint     garbage;
XFILE    *garbage2;
X{
X        /* /dev/null for lexical analyzer output */
X        return(0);
X}
X
X
Xunion sem_stack_type *SS_New()
X{
X	return((union sem_stack_type *)MALLOC(sizeof(union sem_stack_type)));
X}
X
X/**************** Stack stuff *******************/
X
Xstatic struct sval {
X	union sem_stack_type	*value;
X	struct	sval	*prev;
X	};
X
Xstatic	struct	sval	*top_stack = nil;
X
Xvoid SS_Push(new_val) 
Xunion	sem_stack_type	*new_val;
X{
Xstruct	sval	*new_space;
X
X/**/	printf("Just PUSHED: ");
X	switch(new_val->type.kind) {
X		case FLOAT_CONST_ID: printf("float_const %f",
X					    new_val->float_const.value);
X					break;
X		case KNOWN_FUNC_ID: printf("known_func_id");
X					break;
X		case FUNCTION_ID: printf("function_id");
X					break;
X		case VAR_ID: printf("var_id");
X					break;
X		default: printf("Unknown type");
X		}
X	printf("\n");
X	new_space = (struct sval *) MALLOC(sizeof(struct sval));
X	new_space->value = new_val;
X	new_space->prev = top_stack;
X	top_stack = new_space;
X} /* SS_Push() */
X
Xunion sem_stack_type *SS_Pop()
X{
Xunion	sem_stack_type	*to_be_returned;
Xstruct	sval	*tmp;
X	if (top_stack != nil) {
X		to_be_returned = top_stack->value;
X		tmp = top_stack;
X		top_stack = top_stack->prev;
X		FREE(tmp);
X/**/	printf("Just POPd: ");
X	switch(to_be_returned->type.kind) {
X		case FLOAT_CONST_ID: printf("float_const %f",
X					    to_be_returned->float_const.value);
X					break;
X		case KNOWN_FUNC_ID: printf("known_func_id");
X					break;
X		case FUNCTION_ID: printf("function_id");
X					break;
X		case VAR_ID: printf("var_id");
X					break;
X		default: printf("Unknown type");
X		}
X	printf("\n");
X		return(to_be_returned);
X		}
X	else
X		{ /* Error */
X		fprintf(stderr,"SS_Pop(): Tried to pop when sem_stack was empty\n");
X		/* return nothing here */
X		}
X} /* SS_Pop() */
X		
X
X
X
Xunion sem_stack_type *SS_Top()
X{
X	if (top_stack != nil) 
X		return(top_stack->value);
X	else
X		{ /* Error */
X		fprintf(stderr,"SS_Top(): Tried to return top when sem_stack was empty\n");
X		/* return nothing here */
X		}
X} /* SS_Top() */
X
X/******************** end of stack stuff ********************/
END-of-parse.c
echo file: parseSupport.c
sed 's/^X//' >parseSupport.c << 'END-of-parseSupport.c'
X/* this file is suppose to contain all the parse stuff that is ximage dep */
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X
X#include "i.h"
X#include "data.h"
X
X#define	NIL	(char *) 0
X#define TRUE	1
X#define FALSE	0
X
Xextern struct IMAGE *SearchByNameIMAGE();
Xextern struct IMAGE *NewIMAGE();
X
XDATA_ARRAY *GetDataSet(name)
X/* return data if found else 0 */
Xchar *name;	/* name of data set to retrieve */
X{
Xchar	buff[256];
Xstruct IMAGE	*i;
XDATA_ARRAY	*d;
X
X	if (i = SearchByNameIMAGE(name)) {
X		if (!(d = (DATA_ARRAY *) XIMalloc(sizeof(DATA_ARRAY)))) {
X			PrintMesg("Out of memory\n");
X			return(0);
X			}
X		d->xdim = i->xdim;
X		d->ydim = i->ydim;
X		if (d->isFloat = i->isFloat)
X			d->fdata = i->fdataset;
X		else
X			d->cdata = i->ri;
X		d->temp = FALSE;
X		return(d);
X		}
X	else {
X		sprintf(buff,"No such variable: %s",name);
X		PrintMesg(buff);
X		return(0);
X		}
X
X
X} /* GetDataSet() */
X
Xvoid WriteText(s)
Xchar *s;
X{
X	WriteNotebookText(s);
X}
X
Xvoid WriteErrMesg(s)
Xchar *s;
X{
X	PrintMesg(s);
X	/* write to notebook also */
X}
X
X
Xvoid NewDataSet(data,name)
XDATA_ARRAY *data;
Xchar *name;
X{
Xstruct IMAGE *i;
X
X	if (!(i = NewIMAGE())) {
X		PrintMesg("Can't allocate memory for new data set\n");
X		return;
X		}
X	i->name = name;
X	i->fname = NIL;
X	i->xdim = data->xdim;
X	i->ydim = data->ydim;
X	i->isHDF = FALSE;
X	i->hasPalette = FALSE;
X	i->palette = (XColor *) 0;
X	if (i->isFloat = data->isFloat) {
X		i->fdataset = data->fdata;
X		SetMinMax(i->fdataset,i->xdim,i->ydim,
X			&(i->minvalue),&(i->maxvalue));
X		if (!CreateRasterFromFloat(i->fdataset,&(i->ri),
X			      i->xdim,i->ydim,i->minvalue,i->maxvalue,1)) {
X			PrintMesg("Can't allocate memory for new data set\n");
X			return;
X			}
X		i->format = "% 6.3f";
X		i->fwidth = 7;
X		}
X	else {
X		i->ri = data->cdata;
X		i->minvalue = 0.0;
X		i->maxvalue = 255.0;
X		i->format = "%3d";
X		i->fwidth = 3;
X		}
X	CreateImageCtrlBox(i);
X} /*NewDataSet()*/
END-of-parseSupport.c
echo file: fcmp1.c
sed 's/^X//' >fcmp1.c << 'END-of-fcmp1.c'
X/**************************************************************************/
X/*  NCSA DataScope
X*   An experiment with real numbers.
X*   by Tim Krauskopf
X*   
X*   National Center for Supercomputing Applications
X*   University of Illinois at Urbana-Champaign
X*   605 E. Springfield Ave.
X*   Champaign, IL  61820
X*
X*   email:  		softdev@ncsa.uiuc.edu
X*   bug reports:	bugs@ncsa.uiuc.edu
X*   server:         ftp.ncsa.uiuc.edu  (128.174.20.50)
X*
X*   NCSA DataScope is in the public domain.  See the manual for a complete
X*   permissions statement.  We ask that the following message be included
X*   in all derivative works:
X*   Portions developed at the National Center for Supercomputing Applications
X*   University of Illinois at Urbana-Champaign.
X*
X*   version                      comments
X*   -----------                -------------
X*   1.0 TKK  December 1988
X*   1.1 TKK  May 1989       -- new polar, computations, interpolation
X*/
X
X#include <stdio.h>
X#include <math.h>
X
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_coef2	get coefficients used in computing varying-stepped
X				second order derivatives
X				
X				p2 = pointer to first element of source vector
X				t  = pointer to first element of target vector
X				n  = number of elements in the source vector
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_coef2(p2,t,n)	register float		*p2;
X							register double	*t;
X							int					n;
X{
X		register double	z;
X		register float		*p1,*p3,*q;
X		register double	*u,two;
X		   
X		p1 = p2;
X		p3 = p2 + 1;
X		q  = p2 + n - 1;
X		u  = t + n;
X		two = 2.;
X		 	
X		z    = 1. / ((double)(*p3++) - (double)(*p2++));
X		*t++ = z * z;
X		*u++ = - 1.;
X
X		while (p3 < q)
X			  {z	= two / ((double)(*p3) - (double)(*p1));
X			   *t++ = z / ((double)(*p3) - (double)(*p2));
X			   *u++ = - ((double)(*p3++) - (double)(*p2)) /
X			   		    ((double)(*p2) - (double)(*p1++));
X			   p2++;
X			  }
X			  
X		z	= two / ((double)(*p3) - (double)(*p1));
X		*t++ = z / ((double)(*p3) - (double)(*p2));
X		*u++ = - ((double)(*p3) - (double)(*p2)) /
X			   	 ((double)(*p2) - (double)(*p1));
X		
X		z  = 1. / ((double)(*p3) - (double)(*p2));
X		*t = z * z;
X		*u = - 1.;
X		
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_coef1	get coefficients used in computing varying-stepped
X				first order derivatives
X				
X				p2 = pointer to first element of source vector
X				t  = pointer to first element of target vector
X				n  = number of elements in the source vector
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_coef1(p2,t,n)	register float		*p2;
X							register double	*t;
X							int					n;
X{
X		register double	z;
X		register float		*p1,*p3,*q;
X		register double	*u;
X		
X		p1 = p2;
X		p3 = p2 + 1;
X		q  = p2 + n - 1;
X		u  = t + n;
X		 	
X		*t++ = .5 / ((double)(*p3) - (double)(*p2));
X		*u++ = 1.;
X		if (n == 2)
X		   {*t = *(t - 1);
X		    *u = *(u - 1);
X			return;
X		   }
X		p2++;
X		p3++;
X		while (p3 < q)
X			  {z = ((double)(*p2) - (double)(*p1)) / 
X			  	   ((double)(*p3) - (double)(*p2));
X			   *t++ = z / ((double)(*p3++) - (double)(*p1++));
X			   *u++ = 1. / (z * z);
X			   p2++;
X			  }
X			  
X		z = ((double)(*p2) - (double)(*p1)) / 
X			 ((double)(*p3) - (double)(*p2));
X		*t++ = z / ((double)(*p3) - (double)(*p1));
X		*u++ = 1. / (z * z);
X		
X		*t = .5 / ((double)(*p3) - (double)(*p2));
X		*u = 1.;
X		
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_shr		shift array one to the right
X	
X				p = pointer to first element of source array
X				q = pointer to last  element of source array
X				t = pointer to first element of target array
X				x = number of elements in each row
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid fn_shr(p,q,t,x)	register float	*p,*t,*q;
X						register int	x;
X{
X		register float	*u;
X		
X		if (x == 1)
X		   {while (p < q)	*t++ = *p++;
X		    *t = *p;
X		   }
X		else
X			{u = q - (x - 1);
X			 t += q - p;
X			 q--;
X			 while (u > p)
X			 	   {while (q > u) *t-- = *q--;
X				    *t-- = *q;
X					*t-- = *q--;
X					q--;
X					u -= x;
X				   }
X			 while (q > p) *t-- = *q--;
X			 *t-- = *q;
X			 *t = *q;
X			}
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_shd		shift array down one
X	
X				p = pointer to first element of source array
X				q = pointer to last  element of source array
X				t = pointer to first element of target array
X				x = number of elements in each row
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid fn_shd(p,q,t,x)	register float	*p,*t,*q;
X						register int	x;
X{
X		register float	*u;
X		
X		if (x == q - p + 1)
X		   {while (p < q)	*t++ = *p++;
X		    *t = *p;
X		   }
X		else
X			{t += q - p;
X			 q -= x;
X			 while (p < q)	*t-- = *q--;
X			 *t-- = *q--;
X			 q += x;
X			 while (p < q)	*t-- = *q--;
X			 *t = *q;
X			}
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_shl		shift array one to the left
X	
X				p = pointer to first element of source array
X				q = pointer to last  element of source array
X				t = pointer to first element of target array
X				x = number of elements in each row
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid fn_shl(p,q,t,x)	register float	*p,*t,*q;
X						register int	x;
X{
X		register float	*u;
X		
X		if (x == 1)
X		   {while (p < q)	*t++ = *p++;
X		    *t = *p;
X		   }
X		else
X			{u = p + x - 1;
X			 p++;
X			 while (u < q)
X			 	   {while (p < u) *t++ = *p++;
X				    *t++ = *p;
X					*t++ = *p++;
X					p++;
X					u += x;
X				   }
X			 while (p < q) *t++ = *p++;
X			 *t++ = *p;
X			 *t = *p;
X			}
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_shu		shift array up one
X	
X				p = pointer to first element of source array
X				q = pointer to last  element of source array
X				t = pointer to first element of target array
X				x = number of elements in each row
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid fn_shu(p,q,t,x)	register float	*p,*t,*q;
X						register int	x;
X{
X		register float	*u;
X		
X		if (x == q - p + 1)
X		   {while (p < q)	*t++ = *p++;
X		    *t = *p;
X		   }
X		else
X			{p += x;
X			 while (p < q)	*t++ = *p++;
X			 *t++ = *p++;
X			 p -= x;
X			 while (p < q)	*t++ = *p++;
X			 *t = *p;
X			}
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_max		return max of an array
X	
X				p = pointer to first element of array
X				n = number of elements in the array
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xfloat	fn_max(p,n)		register float	*p;
X						register int	n;
X{
X		register float	t,*q;
X		
X		q = p + n - 1;
X		t = *q;
X		while (p < q)
X			  {if (*p > t)	t = *p++;
X			   else		  	p++;
X			  }
X		return(t);
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_min		return min of an array
X	
X				p = pointer to array
X				n = number of array elements
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xfloat	fn_min(p,n)		register float	*p;
X						register int	n;
X{
X		register float		t,*q;
X		
X		q = p + n - 1;
X		t = *q;
X		while (p < q)
X			  {if (*p < t)	t = *p++;
X			   else		  	p++;
X			  }
X		return(t);
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_mean		return mean of an array
X	
X				p = pointer to array
X				n = number of array elements
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xfloat	fn_mean(p,n)	register float	*p;
X						register int	n;
X{
X		register float	*q;
X		register double	t;
X		
X		q = p + n - 1;
X		t = 0.;
X		while (p < q) t += (double)(*p++);
X		t += (double)(*p);
X		return ((float)(t / (double)(n)));
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	fn_sdev		return standard deviation of an array
X	
X				p = pointer to array
X				n = number of array elements
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xfloat	fn_sdev(p,n)	register float	*p;
X						register int	n;
X{
X		register float		*q;
X		register double	t,u;
X		
X		q = p + n - 1;
X		t = 0.;
X		u = t;
X		
X		while (p < q)
X			  {t += (double)(*p) * (double)(*p);
X			   u += (double)(*p++);
X			  }
X		t += (double)(*p) * (double)(*p);
X		u += (double)(*p++);
X		
X		t -= u * u / (double)(n);
X		t /= (double)(n - 1);
X		return ((float)(sqrt(t)));
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	float fn_stpsd	calc standard deviation of the increments of a vector
X	
X					p = pointer to first element of vector
X					n = number of elements in the vector
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xfloat	fn_stpsd(p,n)	register float	*p;
X						register int	n;
X{
X	register double	s,u;
X	register float		*q,*t;
X	
X	q = p + n - 1;
X	t = p + 1;
X	
X	u = (double)(*q) - (double)(*p);
X	s = - u * u / (double)(n - 1);
X	
X	while (t < q)
X		  {u = (double)(*t++) - (double)(*p++);
X		   s += u * u;
X		  }
X	u = (double)(*t) - (double)(*p);
X	s += u * u;
X	
X	s /= (double)(n - 2);
X	return((float)(sqrt(s)));
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dx1c	1st derivative with respect to x, constant stepsize
X	
X					p = pointer to first element of input array
X					t = pointer to first element of target array
X					x = number of elements in each row of the input array
X					n = number of elements in the input array
X					d = stepsize factor = .5 / delta-x
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dx1c(p,t,x,n,d)
X		float				*p,*t;
X		int					x,n;
X		register double	d;
X{
X		register float		*t2,*p1,*p3,*u,*q;
X
X		p1 = p;
X		p3 = p + 2;
X		u  = p + x - 1;
X		q  = p + n - 1;
X		t2 = t + 1;
X/*
X		****************************************************
X		calculate values for interior points
X		****************************************************
X*/
X		while (u < q)
X			  {while (p3 < u)
X			  		 *t2++ = (float)(d * ((double)(*p3++) -
X					 					  (double)(*p1++)));
X			   *t2 = (float)(d * ((double)(*p3) - (double)(*p1)));
X			   u  += x;
X			   t2 += 3;
X			   p1 += 3;
X			   p3 += 3;
X			  }
X		while (p3 < q)
X			  *t2++ = (float)(d * ((double)(*p3++) - (double)(*p1++)));
X		*t2 = (float)(d * ((double)(*p3) - (double)(*p1)));
X/*
X		****************************************************
X		copy 1st column from second column
X		****************************************************
X*/
X		t2 = t;
X		p1 = t + 1;
X		p3 = t + n - x;
X		while (t2 < p3)
X			  {*t2 = *p1;
X			   t2 += x;
X			   p1 += x;
X			  }
X		*t2 = *p1;
X/*
X		****************************************************
X		copy last column from next-to-last column
X		****************************************************
X*/
X		t2 = t + x - 1;
X		p1 = t2 - 1;
X		p3 = t + n - 1;
X		while (t2 < p3)
X			  {*t2 = *p1;
X			   t2 += x;
X			   p1 += x;
X			  }
X		*t2 = *p1;
X
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dx2c	2nd derivative with respect to x, constant stepsize
X	
X					p = pointer to first element of input array
X					t = pointer to first element of target array
X					x = number of elements in each row of the input array
X					n = number of elements in the input array
X					d = stepsize factor = 1 / (delta-x * delta-x)
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dx2c(p,t,x,n,d)
X		float				*p,*t;
X		int					x,n;
X		register double	d;
X{
X		register float		*t2,*p2,*p1,*p3,*u,*q;
X
X		p1 = p;
X		p2 = p + 1;
X		p3 = p + 2;
X		u  = p + x - 1;
X		q  = p + n - 1;
X		t2 = t + 1;
X/*
X		****************************************************
X		calculate values for interior points
X		****************************************************
X*/
X		while (u < q)
X			  {while (p3 < u)
X			  		 {*t2++ = (float)(d * ((double)(*p3++) +
X					 					   (double)(*p1++) -
X										   (double)(*p2)   -
X										   (double)(*p2)   ));
X					  p2++;
X					 }
X			   *t2 = (float)(d * ((double)(*p3) + (double)(*p1) -
X			   					  (double)(*p2) - (double)(*p2)));
X			   u  += x;
X			   t2 += 3;
X			   p1 += 3;
X			   p2 += 3;
X			   p3 += 3;
X			  }
X		while (p3 < q)
X			  {*t2++ = (float)(d * ((double)(*p3++) +
X					 				(double)(*p1++) -
X									(double)(*p2)   -
X									(double)(*p2)   ));
X			   p2++;
X			  }
X		*t2 = (float)(d * ((double)(*p3) + (double)(*p1) -
X			   			   (double)(*p2) - (double)(*p2)));
X/*
X		****************************************************
X		copy 1st column from second column
X		****************************************************
X*/
X		t2 = t;
X		p1 = t + 1;
X		p3 = t + n - x;
X		while (t2 < p3)
X			  {*t2 = *p1;
X			   t2 += x;
X			   p1 += x;
X			  }
X		*t2 = *p1;
X/*
X		****************************************************
X		copy last column from next-to-last column
X		****************************************************
X*/
X		t2 = t + x - 1;
X		p1 = t2 - 1;
X		p3 = t + n - 1;
X		while (t2 < p3)
X			  {*t2 = *p1;
X			   t2 += x;
X			   p1 += x;
X			  }
X		*t2 = *p1;
X
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dy1c	1st derivative with respect to y, constant stepsize
X	
X					p = pointer to first element of input array
X					t = pointer to first element of target array
X					x = number of elements in each row of the input array
X					n = number of elements in the input array
X					d = stepsize factor = .5 / delta-y
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dy1c(p,t,x,n,d)
X		float				*p,*t;
X		int					x,n;
X		register double	d;
X{
X		register float		*t2,*p1,*p3,*q;
X
X		p1 = p;
X		p3 = p + x + x;
X		q  = p + n - 1;
X		t2 = t + x;
X/*
X		****************************************************
X		calculate values for interior points
X		****************************************************
X*/
X		while (p3 < q)
X			  *t2++ = (float)(d * ((double)(*p3++) - (double)(*p1++)));
X		*t2 = (float)(d * ((double)(*p3) - (double)(*p1)));
X/*
X		****************************************************
X		copy top row from second row
X		****************************************************
X*/
X		t2 = t;
X		p1 = t + x;
X		p3 = t + x - 1;
X		while (t2 < p3)	*t2++ = *p1++;
X		*t2 = *p1;
X/*
X		****************************************************
X		copy bottom row from next-to-bottom row
X		****************************************************
X*/
X		p3 = t + n - 1;
X		t2 = p3 - x + 1;
X		p1 = t2 - x;
X		while (t2 < p3)	*t2++ = *p1++;
X		*t2 = *p1;
X
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dy2c	2nd derivative with respect to y, constant stepsize
X	
X					p = pointer to first element of input array
X					t = pointer to first element of target array
X					x = number of elements in each row of the input array
X					n = number of elements in the input array
X					d = stepsize factor = 1 / (delta-y * delta-y)
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dy2c(p,t,x,n,d)
X		float				*p,*t;
X		int					x,n;
X		register double	d;
X{
X		register float		*t2,*p1,*p2,*p3,*q;
X
X		p1 = p;
X		p2 = p1 + x;
X		p3 = p2 + x;
X		q  = p + n - 1;
X		t2 = t + x;
X/*
X		****************************************************
X		calculate values for interior points
X		****************************************************
X*/
X		while (p3 < q)
X			  {*t2++ = (float)(d * ((double)(*p3++) + (double)(*p1++)
X			  					  - (double)(*p2) - (double)(*p2)));
X			   p2++;
X			  }
X		*t2 = (float)(d * ((double)(*p3) + (double)(*p1)
X			  			 - (double)(*p2) - (double)(*p2)));
X/*
X		****************************************************
X		copy top row from second row
X		****************************************************
X*/
X		t2 = t;
X		p1 = t + x;
X		p3 = t + x - 1;
X		while (t2 < p3)	*t2++ = *p1++;
X		*t2 = *p1;
X/*
X		****************************************************
X		copy bottom row from next-to-bottom row
X		****************************************************
X*/
X		p3 = t + n - 1;
X		t2 = p3 - x + 1;
X		p1 = t2 - x;
X		while (t2 < p3)	*t2++ = *p1++;
X		*t2 = *p1;
X
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dyv		1st derivative with respect to y, varying stepsize
X	
X					p = pointer to first element of input array
X					t1 = pointer to first element of target array
X					x = number of x-points
X					y = number of y-points
X					m1 = coefficient vector
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dyv(p,t1,x,y,m1)
X		float				*p,*t1;
X		int					x,y;
X		double			*m1;
X{
X		register float		*t,*p1,*p2,*p3,*q,*u;
X		register double	*m2;
X		
X		t = t1;
X		p1 = p;
X		p2 = p1;
X		p3 = p2 + x;
X		u  = p1 + x + x - 1;
X		q  = p1 + (int)(x * y - 1);
X		m2 = m1 + y;
X		
X		t  += (x - 1);
X		p3 += (x - 1);
X		p2 += x;
X		
X		u += x;
X		while (u < q)
X			  {p3++;
X			   t++;
X			   m1++;
X			   m2++;
X			   while (p3 < u)
X			  		 {*t++ = (float)(*m1 * ((double)(*p3++) -
X					 		 (double)(*p2) + *m2 *
X							 ((double)(*p2) - (double)(*p1++))));
X					  p2++;
X					 }
X			   *t = (float)(*m1 * ((double)(*p3) - (double)(*p2) +
X			   				*m2 * ((double)(*p2) - (double)(*p1++))));
X			   p2++;
X			   u += x;
X			  }
X		p3++;
X		t++;
X		m1++;
X		m2++;
X		while (p3 < q)
X			  {*t++ = (float)(*m1 * ((double)(*p3++) -
X			  				 (double)(*p2) + *m2 *
X							 ((double)(*p2) - (double)(*p1++))));
X			   p2++;
X			  }
X		*t = (float)(*m1 * ((double)(*p3) - (double)(*p2) +
X					 *m2 * ((double)(*p2) - (double)(*p1++))));
X/*
X		****************************************************
X		copy top row from second row
X		****************************************************
X*/
X		t = t1;
X		p = t1 + x;
X		u = t1 + x - 1;
X		while (t < u)	*t++ = *p++;
X		*t = *p;
X/*
X		****************************************************
X		copy bottom row from next-to-bottom row
X		****************************************************
X*/
X		u = t1 + (int)(x * y) - 1;
X		t = u - x + 1;
X		p = t - x;
X		while (t < u)	*t++ = *p++;
X		*t = *p;
X
X		return;
X}
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	void fn_dxv		1st derivative with respect to x, varying stepsize
X	
X					p = pointer to first element of input array
X					t1 = pointer to first element of target array
X					x = number of x-points
X					y = number of y-points
X					m1 = coefficient vector
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
Xvoid	fn_dxv(p,t1,x,y,m1)
X		register float		*p,*t1;
X		int					x,y;
X		register double	*m1;
X{
X		register float		*t,*q,*u,*v,*w;
X		register double	*m2;
X		
X		t = t1;
X		q = p + (int)(x * y - 1);
X		m2 = m1 + x;
X
X		v = p;
X		w = p;
X		p++;
X		   
X		u = v + x - 1;
X		while (u < q)
X			  {t++;
X			   m1++;
X			   p++;
X			   w++;
X			   m2++;
X			   while (p < u)
X					 {*t++ = (float)(*m1++ * ((double)(*p++) -
X					 		 (double)(*w) + *m2++ * ((double)(*w) -
X							 (double)(*v++))));
X					  w++;
X					 }
X			   *t++ = (float)(*m1++ * ((double)(*p) - (double)(*w) +
X			   		  *m2++ * ((double)(*w) - (double)(*v++))));
X			   if (y == 1) return;
X			   p++;	p++;
X			   v++;	v++;
X			   t++;
X			   w++; w++;
X			   u += x;
X			   m1 -= (x - 1);
X			   m2 -= (x - 1);
X			  }
X
X		t++;
X		m1++;
X		p++;
X		w++;
X		m2++;
X		while (p < u)
X			  {*t++ = (float)(*m1++ * ((double)(*p++) -
X					 		 (double)(*w) + *m2++ * ((double)(*w) -
X							 (double)(*v++))));
X			   w++;
X			  }
X		*t++ = (float)(*m1++ * ((double)(*p) - (double)(*w) +
X			   		  *m2++ * ((double)(*w) - (double)(*v++))));
X/*
X		****************************************************
X		copy 1st column from second column
X		****************************************************
X*/
X		u = t1;
X		v = t1 + 1;
X		w = t1 + (int)(x * y) - x;
X		while (u < w)
X			  {*u = *v;
X			   u += x;
X			   v += x;
X			  }
X		*u = *v;
X/*
X		****************************************************
X		copy last column from next-to-last column
X		****************************************************
X*/
X		u = t1 + x - 1;
X		v = u - 1;
X		w = t1 + (int)(x * y) - 1;
X		while (u < w)
X			  {*u = *v;
X			   u += x;
X			   v += x;
X			  }
X		*u = *v;
X
X		return;
X}
X/*
X		****************************************************
X		Transpose the x and y-ness of the array.
X		****************************************************
X*/
Xvoid
Xfn_transpose(src,dst,x,y)
X	float *src,*dst;
X	int x,y;
X{
X	register float *f;
X	register int i,j;
X	
X	
X	for (i=0; i<y; i++) {
X		f = dst + i;					/* start of new column, going down */
X
X		for (j=0; j<x; j++) {			/* go in order of source array */
X			*f = *src++;
X			f += y;						/* increment to next row in dest */
X		}
X	}
X
X}
END-of-fcmp1.c
echo file: remote.c
sed 's/^X//' >remote.c << 'END-of-remote.c'
X#include <stdio.h>
X#include <netdb.h>
X#include <sys/ioctl.h>
X
X#include <X11/Xlib.h>
X#include <X11/Intrinsic.h>
X#include <X11/cursorfont.h>
X
X#include "sem_stack.h"
X#include "xstuff.h"
X#include "data.h"
X#include "list.h"
X
X#ifndef SYSV
X#include <sys/time.h>
X#endif
X
X#ifdef M3200
X#define CANTDOREXEC
X#endif 
X
X#define MALLOC		XIMalloc
X#define FREE		XIFree
X
X#define LOGINXDIM	300
X#define LOGINYDIM	150
X#define HOSTYDIM	 30
X#define	USERYDIM	 60
X#define PASSWDYDIM	 90
X#define STRINGSIZE	256
X
X#define POLL_TIME_INTERVAL 3000
X
Xtypedef struct {
X		DATA_ARRAY *data;
X		Widget topLoginWidget;
X		char host[STRINGSIZE];
X		char user[STRINGSIZE];
X		char passwd[STRINGSIZE];
X		char *command;
X		void (*okCallBack)();
X		void (*cancelCallBack)();
X		char done;
X		char success;
X
X		} LOGIN;
X
Xstruct Poll {
X	int	fd;			/* file descriptor */
X	char	*name;			/* name of this stream */
X	void	(*inputCallBackFunc)();	/* callback on input */
X		/* inputCallBackFunc(struct POLL)*/
X	void	(*systemErrCallBackFunc)();	/* callback on sys Err*/
X		/* systemErrCallBackFunc(struct POLL) */
X	void	(*closeCallBackFunc)();	/* callback on input */
X		/* closeCallBackFunc(struct POLL) */
X	};
X
X
Xstatic List remotePollList;
Xextern void PutErrorValueOnStack();
Xextern Display *myDpy;
Xextern Widget toplevelform;
Xextern char *dtmPortId;  /* dtm inport name */
Xextern DATA_ARRAY *GetDataSet();
Xextern char *addressVar;
X
Xvoid GetLogin();
Xvoid CheckRemotePollList();
X
X
X
X
XInitRemote()
X{
X
X	remotePollList = ListCreate();
X	XtAddTimeOut(POLL_TIME_INTERVAL,CheckRemotePollList,remotePollList);
X}
X
X
Xstatic void CheckRemotePollList(client_data,id)
Xcaddr_t		client_data;
XXtIntervalId	id;
X{
XList	pollList;
Xstruct  Poll	*pollEntry;
Xint	smask;
Xint	bytes;
Xstruct	timeval timeout;
Xchar	buff[1024];
X
X
X	pollList = (List) client_data;
X
X#ifdef DEBUG
X/*
X		printf("CheckRemotePollList(): I've been called\n");
X*/
X		fprintf(stderr,"*");
X#endif
X
X	timeout.tv_sec = 0; /* no wait */
X	timeout.tv_usec = 0;
X
X	pollEntry = (struct Poll *) ListHead(pollList);
X	while(pollEntry) {
X		smask = 1 << pollEntry->fd;
X		while (select(1,&smask,0,0,&timeout)) {
X#ifdef DEBUG
X		printf("CheckRemotePollList(): input for %s\n",
X				pollEntry->name);
X#endif
X			if (ioctl(pollEntry->fd,FIONREAD, &bytes) < 0) {
X				close(pollEntry->fd); /* system Err */
X				pollEntry->systemErrCallBackFunc(pollEntry);
X				ListDeleteEntry(pollList,pollEntry);
X				}
X			else
X				if (bytes == 0) {
X					/*connection closed*/
X					close(pollEntry->fd); 
X					pollEntry->closeCallBackFunc(pollEntry);
X					ListDeleteEntry(pollList,pollEntry);
X					}
X				else 
X					pollEntry->inputCallBackFunc(pollEntry);
X			}
X		pollEntry = (struct Poll *) ListNext(pollList);
X		}
X	XtAddTimeOut(POLL_TIME_INTERVAL,CheckRemotePollList,pollList);
X
X} /* CheckRemotePollList() */
X
X
XRemoteMessage(s)
Xchar *s;
X{
X	fprintf(stderr,"RemoteMessage(): %s\n",s);
X}
X
X
X
X
X
XSendDataVariable(port,data)
Xchar *port;
XDATA_ARRAY *data;
X/* This routine is called when remote procedure sends back it's
X   dtm port */
X{
Xint outPortNum;
Xchar buff[256];
X
X	if (-1 == (outPortNum = MakeWriteConnection(port))) {
X		sprintf(buff,"Can't make DTM out port %s\n",port);
X		RemoteMessage(buff);
X		}
X	
X
X	if (data->isFloat) 
X		SendData(outPortNum,data->fdata,data->xdim,data->ydim,
X			data->isFloat,addressVar);
X	else
X		SendData(outPortNum,data->cdata,data->xdim,data->ydim,
X			data->isFloat,addressVar);
X	
X}
X
Xstatic void PrintRExecOutput(p)
Xstruct Poll *p;
X{
Xchar	buff[1024];
Xchar	outMessage[1024];
Xint	bytes;
X
X	if (-1 < (bytes = read(p->fd,buff,1024))) {
X		buff[bytes] = '\0';
X		sprintf(outMessage,"output from %s calculation:\n",
X			p->name);
X		RemoteMessage(outMessage);
X		RemoteMessage(buff);
X		}
X	else  {
X		sprintf(outMessage,"Error reading output for %s calculation\n",
X			p->name);
X		RemoteMessage(buff);
X		}
X	
X}
X
Xstatic void SystemErrOnRExec(p)
Xstruct Poll *p;
X{
Xchar outMessage[1024];
X	RemoteMessage("An error in reading output of remote function\n");
X	sprintf(outMessage,"in calculation %s has occured\n",p->name);
X	RemoteMessage(outMessage);
X}
X
Xstatic void CloseRExec(p)
Xstruct Poll *p;
X{
X#ifdef DEBUG
Xchar outMessage[1024];
X	sprintf(outMessage,"socket for remote operation %s has closed\n",
X		p->name);
X	RemoteMessage(outMessage);
X#endif
X}
X
Xstatic void DoRemote(l)
XLOGIN *l;
X{
Xchar mbuff[256];
Xint rem;
Xstruct servent *s;
Xchar *ahost;
Xstruct Poll	*p;
Xint	fd2p;
X
X	if (!(s = getservbyname("exec","tcp"))) {
X		RemoteMessage("Can't get exec service\n");
X		l->success = FALSE;
X		return;
X		}
X#ifdef DEBUG
X	printf("About to rexec to %s with command: \"%s\"\n",
X				l->host,l->command);
X#endif
X	RegisterSpecialDTMMesgReturn(SendDataVariable,l->data);
X
X	ahost = l->host;
X
X#ifndef CANTDOREXEC
X	rem = rexec(&ahost,s->s_port,l->user,l->passwd,l->command,&fd2p);
X#endif
X
X	if (rem == -1) {
X		sprintf(mbuff,"unknown host: %s\n",l->host);
X		RemoteMessage(mbuff);
X		l->success = FALSE;
X		return;
X		}
X	if (p = (struct Poll *) MALLOC(sizeof(struct Poll))) {
X		p->fd = rem;
X		p->name = addressVar;
X		p->inputCallBackFunc = PrintRExecOutput;
X		p->systemErrCallBackFunc = SystemErrOnRExec;
X		p->closeCallBackFunc = CloseRExec;
X		ListAddEntry(remotePollList,p);
X		}
X	else
X		RemoteMessage("Out of Memory\n");
X	if (p = (struct Poll *) MALLOC(sizeof (struct Poll))) {
X		p->fd = fd2p;
X		p->name = addressVar;
X		p->inputCallBackFunc = PrintRExecOutput;
X		p->systemErrCallBackFunc = SystemErrOnRExec;
X		p->closeCallBackFunc = CloseRExec;
X		ListAddEntry(remotePollList,p);
X		}
X	else
X		RemoteMessage("Out of Memory\n");
X
X	PutErrorValueOnStack(); /* put something on there for now */
X
X	
X	l->success= TRUE;
X
X} /* DoRemote() */
X
X
Xstatic void DoRExec(l)
XLOGIN *l;
X{
Xchar mbuff[256];
Xint rem;
Xstruct servent *s;
Xchar *ahost;
Xstruct Poll *p;
Xint fd2p;
X
X	if (!(s = getservbyname("exec","tcp"))) {
X		RemoteMessage("Can't get exec service\n");
X		l->success = FALSE;
X		return;
X		}
X#ifdef DEBUG
X	printf("About to rexec to %s with command: \"%s\"\n",
X				l->host,l->command);
X#endif
X
X	ahost = l->host;
X#ifndef CANTDOREXEC
X	rem = rexec(&ahost,s->s_port,l->user,l->passwd,l->command,fd2p);
X#endif
X
X	if (rem == -1) {
X		sprintf(mbuff,"unknown host: %s\n",l->host);
X		RemoteMessage(mbuff);
X		l->success = FALSE;
X		return;
X		}
X
X	if (p = (struct Poll *) MALLOC(sizeof(struct Poll))) {
X		p->fd = rem;
X		p->name = addressVar;
X		p->inputCallBackFunc = PrintRExecOutput;
X		p->systemErrCallBackFunc = SystemErrOnRExec;
X		p->closeCallBackFunc = CloseRExec;
X		ListAddEntry(remotePollList,p);
X		}
X	else
X		RemoteMessage("Out of Memory\n");
X
X	if (p = (struct Poll *) MALLOC(sizeof(struct Poll))) {
X		p->fd = fd2p;
X		p->name = addressVar;
X		p->inputCallBackFunc = PrintRExecOutput;
X		p->systemErrCallBackFunc = SystemErrOnRExec;
X		p->closeCallBackFunc = CloseRExec;
X		ListAddEntry(remotePollList,p);
X		}
X	else
X		RemoteMessage("Out of Memory\n");
X
X
X	PutErrorValueOnStack(); /* put something on there for now */
X
X	
X	l->success= TRUE;
X
X}
X
X
X
Xstatic void DontDoRExec(l)
XLOGIN *l;
X{
X	
X	l->success = FALSE;
X}
X
Xint ExecuteRemoteProc(numParams)
Xint numParams;
X{
Xchar	*ahost;
Xunion	sem_stack_type *param1,*param2,*param3;
Xunion	sem_stack_type *addressVar;
Xint	x;
Xint	fd2p;
XLOGIN	*l;
Xint	retVal;
XXEvent	event_return;
Xchar 	*cmd,newcmd[1024];
X
X#ifdef CANTDOREXEC
X	RemoteMessage("This platform can't do an rexec() \n");
X	for(x=0; x<numParams; x++)
X		(void) SS_Pop(); /* clear params first */
X	return(0);
X#endif
X
X	addressVar = SS_Pop();
X
X	if (numParams != 4) {
X		for(x=0; x<numParams; x++)
X			(void) SS_Pop(); /* clear params first */
X		/* Print Usage */
X		RemoteMessage(
X		"usage: remote(host,\"command [param ...]\",variable)\n");
X#ifdef DEBUG
X		printf("ExecuteRemoteProc():numParams != 4\n");
X#endif
X		return(0);
X		}
X	
X	param3 = SS_Pop();
X	param2 = SS_Pop();
X	param1 = SS_Pop();
X
X	if (!(l = (LOGIN *) MALLOC(sizeof(LOGIN)))) {
X		RemoteMessage("Out of memory\n");
X		return(0);
X		}
X	
X	if (param1->type.kind == VAR_ID) {
X		ahost = param1->var.value;
X		}
X	else {
X		RemoteMessage(
X		"usage: remote(host,\"command [param ...]\",variable)\n");
X#ifdef DEBUG
X		printf("ExecuteRemoteProc():host != VAR_ID\n");
X#endif
X		return(0);
X		}
X	if (param2->type.kind == VAR_ID) {
X		cmd  = param2->var.value;
X		}
X	else {
X		RemoteMessage(
X		"usage: remote(host,\"command [param ...]\",variable)\n");
X#ifdef DEBUG
X		printf("ExecuteRemoteProc():cmd != VAR_ID\n");
X#endif
X		return(0);
X		}
X
X	if (param3->type.kind == VAR_ID) {
X		if (!(l->data = GetDataSet(param3->var.value)))
X			return(0);
X#ifdef DEBUG
X		printf("GetDataSet(%s) returned %d\n",param3->var.value,
X				l->data);
X#endif
X		}
X	else 
X	     if (param3->type.kind == DATA_ID) {
X		l->data = param3->data.value;
X		}
X	     else {
X		RemoteMessage(
X		"usage: remote(host,\"command param1 param2 ...\",variable)\n");
X#ifdef DEBUG
X		printf("ExecuteRemoteProc():data!= DATA_IDor VAR_ID\n");
X#endif
X		return(0);
X		}
X
X
X	sprintf(newcmd,"%s -DTM %s",cmd,dtmPortId);
X
X#ifdef DEBUG
X	printf("cmd = %s\n",cmd);
X	printf("dtmPortId = %s\n",dtmPortId);
X#endif
X
X	strcpy(l->host,ahost);
X	strcpy(l->user,getlogin());
X	l->passwd[0]='\0';
X	l->command = newcmd;
X	l->okCallBack = DoRemote;
X	l->cancelCallBack = DontDoRExec;
X
X	l->done = False;
X
X	GetLogin(l);
X	while(! l->done) {
X		while(XtPending()) {
X			XtNextEvent(&event_return);
X			XtDispatchEvent(&event_return);
X			}
X		}
X
X	
X	retVal = l->success;
X	FREE(l);
X	return(retVal);
X
X} /* ExecuteRemoteProc() */
X
X
Xint ExecuteRExecProc(numParams)
X	/* return 0 on failure ; clear stack first*/
Xint	numParams;
X/* The parameters for this are on the stack */
X{
Xchar	*ahost;
Xunion	sem_stack_type *param1,*param2;
Xint	x;
Xint	fd2p;
XLOGIN	*l;
Xint	retVal;
XXEvent	event_return;
Xchar 	*cmd;
X
X#ifdef CANTDOREXEC
X	RemoteMessage("This platform can't do an rexec() \n");
X	for(x=0; x<numParams; x++)
X		(void) SS_Pop(); /* clear params first */
X	return(0);
X#endif
X
X	if (numParams != 2) {
X		for(x=0; x<numParams; x++)
X			(void) SS_Pop(); /* clear params first */
X		/* Print Usage */
X		RemoteMessage(
X			"usage: rexec(host,\"command param1 param2 ...\")");
X#ifdef DEBUG
X		printf("ExecuteRExecProc: numParams != 2\n");
X#endif
X		return(0);
X		}
X	
X	param2 = SS_Pop();
X	param1 = SS_Pop();
X
X	
X	if (param1->type.kind == VAR_ID) {
X		ahost = param1->var.value;
X		}
X	else {
X		RemoteMessage(
X			"usage: rexec(host,\"command param1 param2 ...\")");
X#ifdef DEBUG
X		printf("ExecuteRExecProc: host is not type VAR_ID\n");
X#endif
X		return(0);
X		}
X	if (param2->type.kind == VAR_ID) {
X		cmd  = param2->var.value;
X		}
X	else {
X		RemoteMessage(
X			"usage: rexec(host,\"command param1 param2 ...\")");
X#ifdef DEBUG
X		printf("ExecuteRExecProc: command is not type VAR_ID\n");
X#endif
X		return(0);
X		}
X
X	if (!(l = (LOGIN *) MALLOC(sizeof(LOGIN)))) {
X		RemoteMessage("Out of memory\n");
X		return(0);
X		}
X
X
X	strcpy(l->host,ahost);
X	strcpy(l->user,getlogin());
X	l->passwd[0]='\0';
X	l->command = cmd;
X	l->okCallBack = DoRExec;
X	l->cancelCallBack = DontDoRExec;
X
X	l->done = False;
X
X	GetLogin(l);
X	while(! l->done) {
X		while(XtPending()) {
X			XtNextEvent(&event_return);
X			XtDispatchEvent(&event_return);
X			}
X		}
X
X	
X	retVal = l->success;
X	FREE(l);
X	return(retVal);
X
X
X} /*ExecuteRExecProc()*/
X
X
Xint WarpPointerWithin(win,x,y)
X/* move pointer within a window */ 
X/* return 1 if success */
XWindow win;
Xint x,y;
X{
XWindow root, child;
Xint     root_x,root_y;  /* X & Y coordinates with respect to root */
Xint     win_x,win_y;    /* X & Y coordinates with respect to window */
Xunsigned int    keys_buttons;
XXWindowAttributes win_attrib;
X
X        XGetWindowAttributes(myDpy,win,&win_attrib);
X
X	if (XQueryPointer(myDpy,win,&root,&child,
X		&root_x,&root_y,&win_x,&win_y,&keys_buttons)) {
X
X		XWarpPointer(myDpy,win,win,win_x,win_y,
X		win_attrib.width,win_attrib.height,x,y);
X		return(1);
X		}
X	else
X		return(0);
X}
X
X
Xstatic void CBHostChange(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar buff[256];
XLOGIN *l;
X
X
X	l = (LOGIN *) client_data;
X	sprintf(buff,"Host is now %s\n",l->host);
X	/**/ RemoteMessage(buff);
X        WarpPointerWithin(XtWindow(l->topLoginWidget),
X			LOGINXDIM-20,USERYDIM+10);
X
X}
X
Xstatic void CBUserChange(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar buff[256];
XLOGIN *l;
X
X	l = (LOGIN *) client_data;
X	sprintf(buff,"User is now %s\n",l->user);
X	/**/ RemoteMessage(buff);
X        WarpPointerWithin(XtWindow(l->topLoginWidget),
X			LOGINXDIM-20,PASSWDYDIM+10);
X}
X
Xstatic void CBOk(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
Xchar buff[256];
XLOGIN *l;
X
X	l = (LOGIN *) client_data;
X	sprintf(buff,"will use host %s user %s\n",l->host,l->user);
X	RemoteMessage(buff);
X
X	XUngrabPointer(myDpy,CurrentTime);
X	XtDestroyWidget(l->topLoginWidget);
X
X	l->done = TRUE;
X	l->okCallBack(l);
X
X}
X
Xstatic void CBPasswdChange(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XLOGIN *l;
X
X	l = (LOGIN *) client_data;
X	/**/ RemoteMessage("Password is set\n");
X	CBOk(w,client_data,call_data);
X}
X
X
Xstatic void CBCancel(w,client_data,call_data)
XWidget w;
Xcaddr_t client_data;
Xcaddr_t call_data;
X{
XLOGIN *l;
X
X	l = (LOGIN *) client_data;
X
X	RemoteMessage("Remote called cancelled\n");
X
X	XUngrabPointer(myDpy,CurrentTime);
X	XtDestroyWidget(l->topLoginWidget);
X
X	l->done = TRUE;
X	l->cancelCallBack(l);
X}
X
X
X
Xstatic void GetLogin(l)
XLOGIN *l;
X{
XWidget composite;
Xint	screen;
X
X	screen = DefaultScreen(myDpy);
X	l->topLoginWidget = MakeATopLevel("loginWindow", toplevelform, 
X				(DisplayWidth(myDpy,screen)-LOGINXDIM)/2, 
X				(DisplayHeight(myDpy,screen)-LOGINYDIM)/2, 
X				LOGINXDIM,LOGINYDIM);
X	
X	composite = Make_Board("loginWindow",l->topLoginWidget,
X				0,0,LOGINXDIM,LOGINYDIM);
X
X	
X	Make_Label("Please enter your login",composite,5,5,LOGINXDIM-10);
X	Make_Label("Host",composite,5,HOSTYDIM,90);
X	Make_Text_Inp("host",composite,l->host,STRINGSIZE,
X				100,HOSTYDIM,LOGINXDIM-110,20,
X				CBHostChange,l);
X	Make_Label("Username",composite,5,USERYDIM,90);
X	Make_Text_Inp("username",composite,l->user,STRINGSIZE,
X				100,USERYDIM,LOGINXDIM-110,20,
X				CBUserChange,l);
X	Make_Label("Password",composite,5,PASSWDYDIM,90);
X	Make_Text_Inp("password",composite,l->passwd,STRINGSIZE,
X				100,PASSWDYDIM,LOGINXDIM-110,20,
X				CBPasswdChange,l);
X
X	MakeButton("Ok",composite,100,LOGINYDIM - 25,CBOk,l,50,20);
X	MakeButton("Cancel",composite,200,LOGINYDIM - 25,CBCancel,l,50,20);
X
X	XGrabPointer(myDpy,XtWindow(l->topLoginWidget),False,0,
X				GrabModeAsync, GrabModeAsync,
X				XtWindow(l->topLoginWidget),
X				XCreateFontCursor(myDpy,XC_question_arrow),
X				CurrentTime);
X
X}
END-of-remote.c
echo file: list.c
sed 's/^X//' >list.c << 'END-of-list.c'
X#include <stdio.h>
X#include "listP.h"
X
X#define	MALLOC	XIMalloc
X#define	FREE	XIFree
X#define NIL	0
X
Xstatic void ListPrintErr(s)
Xchar *s;
X{
X	fprintf(stderr,"%s",s);
X}
X
Xchar *ListHead(theList)
XList theList;
X{
X	theList->current = theList->head;
X	if (theList->head)
X		return(theList->head->value);
X	else
X		return(NIL);
X}
X
Xchar *ListTail(theList)
XList theList;
X{
X	theList->current = theList->tail;
X	if (theList->tail)
X		return(theList->head->value);
X	else
X		return(NIL);
X}
X
Xchar *ListCurrent(theList)
XList theList;
X{
X	if (theList->current)
X		return(theList->current->value);
X	else
X		return(NIL);
X}
X
Xchar *ListNext(theList)
XList theList;
X{
X	if (theList->current) {
X		theList->current = theList->current->next;
X		return(ListCurrent(theList));
X		}
X	else
X		return(NIL);
X}
X
Xchar *ListPrev(theList)
XList theList;
X{
X	if (theList->current) {
X		theList->current = theList->current->prev;
X		return(ListCurrent(theList));
X		}
X	else
X		return(NIL);
X}
X
XList ListCreate()
X{
XList retVal;
X
X	retVal = (List) MALLOC(sizeof(struct LISTSTRUCT));
X	retVal->head = NIL;
X	retVal->tail = NIL;
X	retVal->current = NIL;
X	return(retVal);
X}
X
Xvoid ListDestroy(theList)
XList theList;
X{
Xstruct LISTINSTANCE *l;
Xstruct LISTINSTANCE *m;
X
X	l = theList->head;
X	while(l) {
X		m = l;
X		l = l->next;
X		FREE(m);
X		}
X	FREE(theList);
X		
X}
X
X
Xint ListAddEntry(theList,v)
X/* return 0 on failure */
XList theList;
Xchar *v; /* data to be added */
X{
Xstruct LISTINSTANCE *l;
X
X	if (!(l =(struct LISTINSTANCE *) MALLOC(sizeof(struct LISTINSTANCE)))){
X		ListPrintErr("Out of Memory\n");
X		return(0);
X		}
X
X	l->value = v;
X
X	l->next = NIL;
X	l->prev = NIL;
X
X	if (theList->head == NIL)
X		theList->tail = theList->head = l;
X	else {
X		theList->tail->next = l;
X		l->prev = theList->tail;
X		theList->tail = l;
X		}
X
X	theList->current = l;
X	
X	return(1);
X}
X
Xstatic struct LISTINSTANCE *SearchListByValue(theList,v)
XList theList;
Xchar *v;
X{
Xstruct LISTINSTANCE *l;
X
X	l = theList->head;
X	while (l != NIL) {
X		if (l->value == v)
X			return(l);
X		else
X			l = l->next;
X		}
X	theList->current = l;
X
X	return(NIL);
X	
X}
X
Xint ListDeleteEntry(theList,v)
X/* removes the first occurance of v from the list */
X/* return 0 if value not in list else 1 */
XList theList;
Xchar *v;
X{
Xstruct LISTINSTANCE *l;
Xchar *retV;
X
X	if (!(l = SearchListByValue(theList,v)))
X		return(0);
X
X	if (l->prev)
X		l->prev->next = l->next;
X	else
X		theList->head = l->next;
X
X	if (l->next)
X		l->next->prev = l->prev;
X	else
X		theList->tail = l->prev;
X
X	theList->current = l->next;
X
X	retV = l->value;
X	FREE(l);
X
X	return(1);
X}
X
END-of-list.c
echo file: date.c
sed 's/^X//' >date.c << 'END-of-date.c'
X/*
X * This NCSA software product is public domain software.  Permission
X * is granted to do whatever you like with it. Should you feel compelled 
X * to make a contribution for the use of this software, please send 
X * comments as to what you like or don't like about the software, 
X * how you use it, how it helps your work, etc. to softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Dave Thompson, National Center for Supercomputing Applications
X *         davet@ncsa.uiuc.edu
X */
X
X#include "mem.h"
X
X#ifndef VERSION
X#define VERSION	"NCSA X Image Version 1.2.1"
X#endif
X
X#ifndef VERSIONDATE
X#define VERSIONDATE "11/1/91"
X#endif
X
X
Xstatic char vinfo[80];
Xstatic char vinfo2[80];
X
Xchar *GetVersionDate()
X{
Xchar vdate[80];
X
Xvinfo2[0]='(';
Xvinfo2[1]='\0';
X
X#define MACHINE_TYPE_UNKNOWN
X#ifdef SYSV
X	strcat(vinfo2,"System V ");
X#endif
X
X#if defined(UNICOS) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"UNICOS");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X
X#if defined(AIX) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"AIX");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X
X#if defined(ULTRIX) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"ULTRIX");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X
X#if defined(IRIS4) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"IRIS");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X
X#if defined(SUN) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"SunOS");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X
X#if defined(M3200) && defined(MACHINE_TYPE_UNKNOWN)
X	strcat(vinfo2,"Motorola 3200");
X#undef define MACHINE_TYPE_UNKNOWN
X#endif
X	strcat(vinfo2,")");
X
X	strcpy(vdate,VERSIONDATE);
X
X	if (vinfo2[1]==')')
X		sprintf(vinfo,"%s %s\n",VERSION,vdate);
X	else
X		sprintf(vinfo,"%s %s %s\n",VERSION,vinfo2,vdate);
X	return(vinfo);
X}
X
Xchar *GetVersion()
X{
X	return(VERSION);
X}
END-of-date.c
echo file: gram.y
sed 's/^X//' >gram.y << 'END-of-gram.y'
X%{
X#include "sem_stack.h"
X#include "value.h"
X#include "data.h"
X#include "parseSupport.h"
X
X#define MALLOC	XIMalloc
X#define FREE	XIFree
X#define FALSE	0
X#define TRUE	1
X#ifdef DEBUG
X#define DEBUGPRINT	printf
X#else
X#define	DEBUGPRINT	DevNull
X#endif
X
X
Xchar    lexIdent[1024]; /* contains last identifier read in */
Xfloat   lexFloat;       /* contains last float read in */
Xstatic	union sem_stack_type *tmp;
Xunion sem_stack_type *addressVar;
X
Xint     yylval;
Xint	numParams;
Xchar	errorDuringParsing = FALSE;
X
Xstatic void DevNull(s)
Xchar *s;
X{
X}
X
X
X%}
X
X%token TASGN TIDENT TFLOAT TSTRING
X%token TLPAREN TRPAREN TCOMMA TERROR
X%token TSIN TCOS TTAN TASIN TACOS TATAN TSINH TCOSH TTANH 
X%token TDSIN TDCOS TDTAN TDASIN TDACOS TDATAN TDSINH TDCOSH TDTANH 
X%token TDTOR TRTOD
X%token TSQRT TLOG TLOG10 TEXP TABS TMEAN TMAX TMIN 
X%token TPTS TCOLS TROWS TCOLRANGE TROWRANGE TCOLMEAN TROWMEAN TCOLSDEV TROWSDEV
X%token TSHL TSHR TSHU TSHD
X%token TREMOTE TREXEC
X%left TADDOP /* +,- */
X%left TMULOP /* *,/ */
X
X
X
X%%
Xstatement : addr_variable TASGN expression
X	{
X	char buff[256];
X	union sem_stack_type *answer;
X	union sem_stack_type *answerName;
X
X	DEBUGPRINT("Applying statement: addr_variable TASGN expression\n");
X
X	if (!errorDuringParsing){
X	    answer = SS_Pop();
X	    answerName = SS_Pop();
X	    if (answer->float_const.kind == FLOAT_CONST_ID) {
X		sprintf(buff,"Answer is %f\n",answer->float_const.value);
X		DEBUGPRINT("%s",buff);
X		WriteText(buff);
X		}
X	    else {
X	    	if (answer->data.kind == DATA_ID) {
X			if (answerName->var.kind != VAR_ID) {
X				DEBUGPRINT("Internal error in parsing\n");
X				NewDataSet(answer->data.value,"answer");
X				}
X			else
X				NewDataSet(answer->data.value,
X					   answerName->var.value);
X			} 
X		}
X	    }
X	
X	}
X	;
X
Xexpression :  valued_variable
X	| float_const
X		{
X	  	DEBUGPRINT("Applying expression: TFLOAT \n");
X		}
X	| function
X		{
X
X	  	DEBUGPRINT("Applying expression: function\n");
X
X                tmp = SS_Pop();
X		if (tmp->known_func.kind == KNOWN_FUNC_ID) {
X			ExecKnownFunction(tmp->known_func.value,numParams);
X                	}
X		else {
X		    if (tmp->known_func.kind == FUNCTION_ID) {
X			ExecUnknownFunction(tmp->known_func.value,numParams);
X			}
X		    else {
X			DEBUGPRINT("function: Internal error parsing");
X			}
X		    }
X		}
X	| TLPAREN expression TRPAREN
X		{
X	  	DEBUGPRINT(
X		"Applying expression: TLPAREN expression TRPAREN\n");
X		}
X	| expression TADDOP 
X		{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		}
X	  expression
X		{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecAddOp(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: expression TADDOP expression \n");
X		}
X	| expression TMULOP 
X		{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		}
X	  expression
X		{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecMulOp(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: expression TMULLOP expression\n");
X		}
X	| unary_minus
X		{ 
X		tmp = SS_New();
X		tmp->integer.value=yylval;
X		SS_Push(tmp);
X		} 
X	  expression
X		{
X		union sem_stack_type *tmp2;
X		tmp = SS_Pop();
X		tmp2= SS_Pop();
X		SS_Push(tmp);
X		ExecUnaryMinus(tmp2->integer.value);
X	  	DEBUGPRINT("Applying expression: unary_minus expression\n");
X		}
X	;
X
Xfunction : func_name TLPAREN 
X		{numParams=0;}
X	parameter_list TRPAREN
X		{
X		/* unknown simple functions */
X	  	DEBUGPRINT(
X		"Applying func: func_name TLPAREN parameter_list TRPAREN\n");
X		DEBUGPRINT("Function has %d parameters\n",numParams);
X		}
X	| function1_id TLPAREN 
X		{numParams=0;}
X	  parameter_list TRPAREN
X		{
X		/* known simple functions */
X	  	DEBUGPRINT(
X		"Applying func: function1_id TLPAREN parameter_list TRPAREN\n");
X		DEBUGPRINT("Function has %d parameters\n",numParams);
X		}
X	;
X
X
X	
Xparameter_list : 
X	parameter
X		{
X	  	DEBUGPRINT("Applying param_list: parameter \n");
X		}
X	| parameter_list TCOMMA parameter
X		{
X		DEBUGPRINT("Applying param_list: param_list TCOMMA parameter \n");
X		}
X	;
X
Xparameter : valued_variable
X		{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		}
X	| float_const
X		{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		}
X	| string_const
X		{
X		union sem_stack_type *s1,*s2;
X		s1 = SS_Pop();
X		s2 = SS_Pop();
X		SS_Push(s1);
X		SS_Push(s2);
X		numParams++; 
X		}
X	;
X
Xfloat_const : TFLOAT
X		{
X
X		tmp = SS_New();
X		tmp->float_const.value = lexFloat;
X		tmp->float_const.kind= FLOAT_CONST_ID;
X		SS_Push(tmp);
X		DEBUGPRINT("float_const: TFLOAT = %f\n",lexFloat);
X		}
X	;
X
Xstring_const: TSTRING
X		{
X		tmp = SS_New();
X		tmp->var.value = (char *)MALLOC(strlen(lexIdent)+1);
X		tmp->var.kind=VAR_ID;
X		strcpy(tmp->var.value,lexIdent);
X		SS_Push(tmp);
X		/*DEBUGPRINT("Applying ident: TSTRING (%s)\n",lexIdent);*/
X		}
X	;
X
Xvalued_variable : ident
X		{
X		tmp = SS_Top();
X		tmp->type.kind=VAR_ID;
X		DEBUGPRINT("Applying valued_variable: TIDENT (%s)\n",lexIdent);
X		}
X	;
X
Xfunc_name : ident
X		{
X		tmp = SS_Top();
X		tmp->type.kind=FUNCTION_ID;
X		DEBUGPRINT("Applying func_name: TIDENT (%s)\n",lexIdent);
X		}
X	;
X
Xaddr_variable : ident
X		{
X		tmp = SS_Top();
X		tmp->type.kind=VAR_ID;
X		addressVar = tmp;
X		DEBUGPRINT("Applying addr_variable: TIDENT (%s)\n",lexIdent);
X		}
X	;
X
Xident :  TIDENT
X		{
X	
X		tmp = SS_New();
X		tmp->var.value = (char *)MALLOC(strlen(lexIdent)+1);
X		strcpy(tmp->var.value,lexIdent);
X		SS_Push(tmp);
X		/*DEBUGPRINT("Applying ident: TIDENT (%s)\n",lexIdent);*/
X		}
X	;
X
Xunary_minus : TADDOP
X	;
X
Xfunction1_id : TSIN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TCOS
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TCOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TTAN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TTAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TASIN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TASIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TACOS
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TACOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TATAN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TATAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSINH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSINH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TCOSH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TCOSH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TTANH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TTANH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSQRT
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSQRT;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TLOG
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TLOG;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TLOG10
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TLOG10;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TEXP
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TEXP;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TABS
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TABS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TMEAN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TMEAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TMAX
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TMAX;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TMIN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TMIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSHL
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSHL;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSHR
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSHR;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSHU
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSHU;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TSHD
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TSHD;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDSIN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDSIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDCOS
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDCOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDTAN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDTAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDASIN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDASIN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDACOS
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDACOS;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDATAN
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDATAN;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDSINH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDSINH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDCOSH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDCOSH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDTANH
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDTANH;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TDTOR
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TDTOR;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TRTOD
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TRTOD;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TREMOTE
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TREMOTE;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	| TREXEC
X		{
X		tmp = SS_New();
X		tmp->known_func.value = TREXEC;
X		tmp->known_func.kind = KNOWN_FUNC_ID;
X		SS_Push(tmp);
X		}
X	;
X
X%%
X
X#include "lex.yy.c"
X#include "parse2.c"
X
Xyyerror(mesg)
Xchar *mesg;
X{
Xchar buff[256];
X	sprintf(buff,"Error parsing: %s\n",mesg);
X	WriteText(buff);
X}
END-of-gram.y
echo file: exp.l
sed 's/^X//' >exp.l << 'END-of-exp.l'
X%{
X#include "parse.h"
X
X	/*
X	Stick this in at a later date 
X	colrange|COLRANGE	{return(TCOLRANGE);}
X	rowrange|ROWRANGE	{return(TROWRANGE);}
X	colmean|COLMEAN		{return(TCOLMEAN);}
X	rowmean|ROWMEAN		{return(TROWMEAN);}
X	colsdev|COLSDEV		{return(TCOLSDEV);}
X	rowsdev|ROWSDEV		{return(TROWSDEV);}
X	*/
X%}
X
Xdelim	[ \t\n]
Xws	{delim}+
Xletter	[A-Za-z]
Xdigit	[0-9]
X
Xtident	{letter}(({letter}|{digit})|\.)*
Xtfloat	{digit}+(\.{digit}+)?([eE][+\-]?{digit}+)?
X
X%START	INSTRING
X%p      5000
X%a      4000
X%n      400
X%o      4000
X%%
X
X{ws}		{ /* No action on a white space */}
X{tfloat}	{sscanf(yytext,"%f",&lexFloat); return(TFLOAT); }
X
Xsin|SIN		{return(TSIN);}
Xcos|COS		{return(TCOS);}
Xtan|TAN		{return(TTAN);}
Xasin|ASIN	{return(TASIN);}
Xacos|ACOS	{return(TACOS);}
Xatan|ATAN	{return(TATAN);}
Xsinh|SINH	{return(TSINH);}
Xcosh|COSH	{return(TCOSH);}
Xtanh|TANH	{return(TTANH);}
X
Xdsin|DSIN	{return(TDSIN);}
Xdcos|DCOS	{return(TDCOS);}
Xdtan|DTAN	{return(TDTAN);}
Xdasin|DASIN	{return(TDASIN);}
Xdacos|DACOS	{return(TDACOS);}
Xdatan|DATAN	{return(TDATAN);}
Xdsinh|DSINH	{return(TDSINH);}
Xdcosh|DCOSH	{return(TDCOSH);}
Xdtanh|DTANH	{return(TDTANH);}
Xdtor|DTOR	{return(TDTOR);}
Xrtod|RTOD	{return(TRTOD);}
X
Xsqrt|SQRT	{return(TSQRT);}
Xlog|LOG		{return(TLOG);}
Xlog10|LOG10	{return(TLOG10);}
Xexp|EXP		{return(TEXP);}
Xabs|ABS		{return(TABS);}
Xmean|MEAN	{return(TMEAN);}
Xmax|MAX		{return(TMAX);}
Xmin|MIN		{return(TMIN);}
X
Xpts|PTS		{return(TPTS);}
Xcols|COLS	{return(TCOLS);}
Xrows|ROWS	{return(TROWS);}
X
Xshl|SHL		{return(TSHL);}
Xshr|SHR		{return(TSHR);}
Xshu|SHU		{return(TSHU);}
Xshd|SHD		{return(TSHD);}
X
Xremote|REMOTE	{return(TREMOTE);}
Xrexec|REXEC	{return(TREXEC);}
X
X"+"		{yylval = VADD; return(TADDOP); }
X"-"		{yylval = VSUB; return(TADDOP); }
X"*"		{yylval = VMUL; return(TMULOP); }
X"/"		{yylval = VDIV;	return(TMULOP); }
X"="		{return(TASGN);}
X"("		{return(TLPAREN);}
X")"		{return(TRPAREN);}
X","		{return(TCOMMA);}
X
X{tident}	{strcpy(lexIdent,yytext); return(TIDENT); }
X
X
X\"				{BEGIN INSTRING;}
X<INSTRING>([^"\n]|(\\\"))*\"	{
X				BEGIN 0;
X				strcpy(lexIdent,yytext); 
X				lexIdent[strlen(lexIdent)-1]='\0';
X				/* lexIdent contains string minus the quotes*/
X				return(TSTRING);
X				}
X<INSTRING>[^\n]*\nalkjsdf		{
X				BEGIN 0;
X				WriteText("string not terminated before EOL\n");
X				/*printf("%s\n",yytext);*/
X				strcpy(lexIdent,yytext+1*sizeof(char)); 
X				return(TSTRING);
X				}
X.		{
X		char buff[256];
X		sprintf(buff,"Illegal character: %s\n",yytext);
X		WriteText(buff);
X		errorDuringParsing = TRUE;
X		return(TERROR); 
X		}
X
X%%
X
Xyywrap()
X{
X	return(1);
X}
X
X
END-of-exp.l
echo file: lex.yy.c
sed 's/^X//' >lex.yy.c << 'END-of-lex.yy.c'
X# include "stdio.h"
X# define U(x) ((x)&0377)
X# define NLSTATE yyprevious=YYNEWLINE
X# define BEGIN yybgin = yysvec + 1 +
X# define INITIAL 0
X# define YYLERR yysvec
X# define YYSTATE (yyestate-yysvec-1)
X# define YYOPTIM 1
X# define YYLMAX 200
X# define output(c) putc(c,yyout)
X# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
X# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
X# define yymore() (yymorfg=1)
X# define ECHO fprintf(yyout, "%s",yytext)
X# define REJECT { nstr = yyreject(); goto yyfussy;}
Xint yyleng; extern char yytext[];
Xint yymorfg;
Xextern char *yysptr, yysbuf[];
Xint yytchar;
XFILE *yyin ={stdin}, *yyout ={stdout};
Xextern int yylineno;
Xstruct yysvf { 
X	struct yywork *yystoff;
X	struct yysvf *yyother;
X	int *yystops;};
Xstruct yysvf *yyestate;
Xextern struct yysvf yysvec[], *yybgin;
X#include "parse.h"
X
X	/*
X	Stick this in at a later date 
X	colrange|COLRANGE	{return(TCOLRANGE);}
X	rowrange|ROWRANGE	{return(TROWRANGE);}
X	colmean|COLMEAN		{return(TCOLMEAN);}
X	rowmean|ROWMEAN		{return(TROWMEAN);}
X	colsdev|COLSDEV		{return(TCOLSDEV);}
X	rowsdev|ROWSDEV		{return(TROWSDEV);}
X	*/
X# define INSTRING 2
X# define YYNEWLINE 10
Xyylex(){
Xint nstr; extern int yyprevious;
Xwhile((nstr = yylook()) >= 0)
Xyyfussy: switch(nstr){
Xcase 0:
Xif(yywrap()) return(0); break;
Xcase 1:
X	{ /* No action on a white space */}
Xbreak;
Xcase 2:
X{sscanf(yytext,"%f",&lexFloat); return(TFLOAT); }
Xbreak;
Xcase 3:
X	{return(TSIN);}
Xbreak;
Xcase 4:
X	{return(TCOS);}
Xbreak;
Xcase 5:
X	{return(TTAN);}
Xbreak;
Xcase 6:
X{return(TASIN);}
Xbreak;
Xcase 7:
X{return(TACOS);}
Xbreak;
Xcase 8:
X{return(TATAN);}
Xbreak;
Xcase 9:
X{return(TSINH);}
Xbreak;
Xcase 10:
X{return(TCOSH);}
Xbreak;
Xcase 11:
X{return(TTANH);}
Xbreak;
Xcase 12:
X{return(TDSIN);}
Xbreak;
Xcase 13:
X{return(TDCOS);}
Xbreak;
Xcase 14:
X{return(TDTAN);}
Xbreak;
Xcase 15:
X{return(TDASIN);}
Xbreak;
Xcase 16:
X{return(TDACOS);}
Xbreak;
Xcase 17:
X{return(TDATAN);}
Xbreak;
Xcase 18:
X{return(TDSINH);}
Xbreak;
Xcase 19:
X{return(TDCOSH);}
Xbreak;
Xcase 20:
X{return(TDTANH);}
Xbreak;
Xcase 21:
X{return(TDTOR);}
Xbreak;
Xcase 22:
X{return(TRTOD);}
Xbreak;
Xcase 23:
X{return(TSQRT);}
Xbreak;
Xcase 24:
X	{return(TLOG);}
Xbreak;
Xcase 25:
X{return(TLOG10);}
Xbreak;
Xcase 26:
X	{return(TEXP);}
Xbreak;
Xcase 27:
X	{return(TABS);}
Xbreak;
Xcase 28:
X{return(TMEAN);}
Xbreak;
Xcase 29:
X	{return(TMAX);}
Xbreak;
Xcase 30:
X	{return(TMIN);}
Xbreak;
Xcase 31:
X	{return(TPTS);}
Xbreak;
Xcase 32:
X{return(TCOLS);}
Xbreak;
Xcase 33:
X{return(TROWS);}
Xbreak;
Xcase 34:
X	{return(TSHL);}
Xbreak;
Xcase 35:
X	{return(TSHR);}
Xbreak;
Xcase 36:
X	{return(TSHU);}
Xbreak;
Xcase 37:
X	{return(TSHD);}
Xbreak;
Xcase 38:
X{return(TREMOTE);}
Xbreak;
Xcase 39:
X{return(TREXEC);}
Xbreak;
Xcase 40:
X	{yylval = VADD; return(TADDOP); }
Xbreak;
Xcase 41:
X	{yylval = VSUB; return(TADDOP); }
Xbreak;
Xcase 42:
X	{yylval = VMUL; return(TMULOP); }
Xbreak;
Xcase 43:
X	{yylval = VDIV;	return(TMULOP); }
Xbreak;
Xcase 44:
X	{return(TASGN);}
Xbreak;
Xcase 45:
X	{return(TLPAREN);}
Xbreak;
Xcase 46:
X	{return(TRPAREN);}
Xbreak;
Xcase 47:
X	{return(TCOMMA);}
Xbreak;
Xcase 48:
X{strcpy(lexIdent,yytext); return(TIDENT); }
Xbreak;
Xcase 49:
X			{BEGIN INSTRING;}
Xbreak;
Xcase 50:
X{
X				BEGIN 0;
X				strcpy(lexIdent,yytext); 
X				lexIdent[strlen(lexIdent)-1]='\0';
X				/* lexIdent contains string minus the quotes*/
X				return(TSTRING);
X				}
Xbreak;
Xcase 51:
X	{
X				BEGIN 0;
X				WriteText("string not terminated before EOL\n");
X				/*printf("%s\n",yytext);*/
X				strcpy(lexIdent,yytext+1*sizeof(char)); 
X				return(TSTRING);
X				}
Xbreak;
Xcase 52:
X	{
X		char buff[256];
X		sprintf(buff,"Illegal character: %s\n",yytext);
X		WriteText(buff);
X		errorDuringParsing = TRUE;
X		return(TERROR); 
X		}
Xbreak;
Xcase -1:
Xbreak;
Xdefault:
Xfprintf(yyout,"bad switch yylook %d",nstr);
X} return(0); }
X/* end of yylex */
X
Xyywrap()
X{
X	return(1);
X}
X
X
Xint yyvstop[] ={
X0,
X
X52,
X0,
X
X1,
X52,
X0,
X
X1,
X0,
X
X49,
X52,
X0,
X
X45,
X52,
X0,
X
X46,
X52,
X0,
X
X42,
X52,
X0,
X
X40,
X52,
X0,
X
X47,
X52,
X0,
X
X41,
X52,
X0,
X
X43,
X52,
X0,
X
X2,
X52,
X0,
X
X44,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X52,
X0,
X
X1,
X52,
X0,
X
X1,
X0,
X
X49,
X50,
X52,
X0,
X
X45,
X52,
X0,
X
X46,
X52,
X0,
X
X42,
X52,
X0,
X
X40,
X52,
X0,
X
X47,
X52,
X0,
X
X41,
X52,
X0,
X
X43,
X52,
X0,
X
X2,
X52,
X0,
X
X44,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X48,
X52,
X0,
X
X2,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X50,
X0,
X
X1,
X0,
X
X2,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X50,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X2,
X0,
X
X2,
X0,
X
X27,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X4,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X26,
X48,
X0,
X
X24,
X48,
X0,
X
X29,
X48,
X0,
X
X48,
X0,
X
X30,
X48,
X0,
X
X31,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X37,
X48,
X0,
X
X34,
X48,
X0,
X
X35,
X48,
X0,
X
X36,
X48,
X0,
X
X3,
X48,
X0,
X
X48,
X0,
X
X5,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X4,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X24,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X3,
X48,
X0,
X
X48,
X0,
X
X5,
X48,
X0,
X
X2,
X0,
X
X2,
X0,
X
X27,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X4,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X26,
X48,
X0,
X
X24,
X48,
X0,
X
X29,
X48,
X0,
X
X48,
X0,
X
X30,
X48,
X0,
X
X31,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X37,
X48,
X0,
X
X34,
X48,
X0,
X
X35,
X48,
X0,
X
X36,
X48,
X0,
X
X3,
X48,
X0,
X
X48,
X0,
X
X5,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X4,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X24,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X3,
X48,
X0,
X
X48,
X0,
X
X5,
X48,
X0,
X
X7,
X48,
X0,
X
X6,
X48,
X0,
X
X8,
X48,
X0,
X
X32,
X48,
X0,
X
X10,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X13,
X48,
X0,
X
X12,
X48,
X0,
X
X14,
X48,
X0,
X
X21,
X48,
X0,
X
X48,
X0,
X
X28,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X33,
X48,
X0,
X
X22,
X48,
X0,
X
X9,
X48,
X0,
X
X23,
X48,
X0,
X
X11,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X13,
X48,
X0,
X
X12,
X48,
X0,
X
X14,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X7,
X48,
X0,
X
X6,
X48,
X0,
X
X8,
X48,
X0,
X
X32,
X48,
X0,
X
X10,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X13,
X48,
X0,
X
X12,
X48,
X0,
X
X14,
X48,
X0,
X
X21,
X48,
X0,
X
X48,
X0,
X
X28,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X33,
X48,
X0,
X
X22,
X48,
X0,
X
X9,
X48,
X0,
X
X23,
X48,
X0,
X
X11,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X13,
X48,
X0,
X
X12,
X48,
X0,
X
X14,
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X48,
X0,
X
X16,
X48,
X0,
X
X15,
X48,
X0,
X
X17,
X48,
X0,
X
X19,
X48,
X0,
X
X18,
X48,
X0,
X
X20,
X48,
X0,
X
X25,
X48,
X0,
X
X48,
X0,
X
X39,
X48,
X0,
X
X48,
X0,
X
X16,
X48,
X0,
X
X15,
X48,
X0,
X
X17,
X48,
X0,
X
X19,
X48,
X0,
X
X18,
X48,
X0,
X
X20,
X48,
X0,
X
X25,
X48,
X0,
X
X48,
X0,
X
X39,
X48,
X0,
X
X48,
X0,
X
X38,
X48,
X0,
X
X38,
X48,
X0,
X
X51,
X0,
X0};
X# define YYTYPE int
Xstruct yywork { YYTYPE verify, advance; } yycrank[] ={
X0,0,	0,0,	1,5,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	1,6,	1,7,	
X0,0,	6,7,	6,7,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	1,8,	
X6,7,	0,0,	0,0,	0,0,	
X0,0,	1,9,	1,10,	1,11,	
X1,12,	1,13,	1,14,	0,0,	
X1,15,	1,16,	40,126,	40,41,	
X74,178,	74,178,	74,178,	74,178,	
X74,178,	74,178,	74,178,	74,178,	
X74,178,	74,178,	1,17,	126,126,	
X126,41,	0,0,	1,18,	1,19,	
X1,20,	1,21,	1,22,	1,19,	
X1,19,	1,19,	1,19,	1,19,	
X1,19,	1,23,	1,24,	1,19,	
X1,19,	1,25,	1,19,	1,26,	
X1,27,	1,28,	1,19,	1,19,	
X1,19,	1,19,	1,19,	1,19,	
X0,0,	43,125,	44,125,	45,125,	
X46,125,	47,125,	1,29,	1,19,	
X1,30,	1,31,	1,32,	1,19,	
X1,19,	1,19,	1,19,	1,19,	
X1,19,	1,33,	1,34,	1,19,	
X1,19,	1,35,	1,19,	1,36,	
X1,37,	1,38,	1,19,	1,19,	
X1,19,	1,19,	1,19,	1,19,	
X2,9,	2,10,	2,11,	41,127,	
X2,13,	2,14,	48,125,	2,15,	
X49,125,	40,125,	51,125,	122,125,	
X123,127,	127,232,	155,125,	232,317,	
X317,358,	358,370,	370,372,	372,373,	
X178,76,	2,17,	126,125,	0,0,	
X0,0,	0,0,	2,19,	2,20,	
X2,21,	0,0,	2,19,	2,19,	
X2,19,	2,19,	2,19,	2,19,	
X2,23,	2,24,	2,19,	2,19,	
X2,25,	2,19,	2,26,	2,27,	
X2,28,	2,19,	2,19,	2,19,	
X2,19,	2,19,	2,19,	63,155,	
X178,76,	129,233,	234,235,	0,0,	
X125,155,	2,29,	2,19,	2,30,	
X2,31,	2,32,	2,19,	2,19,	
X2,19,	2,19,	2,19,	2,19,	
X2,33,	2,34,	2,19,	2,19,	
X2,35,	2,19,	2,36,	2,37,	
X2,38,	2,19,	2,19,	2,19,	
X2,19,	2,19,	2,19,	3,39,	
X19,77,	19,77,	20,77,	20,77,	
X21,83,	21,77,	21,84,	3,40,	
X3,41,	22,77,	22,77,	23,77,	
X23,77,	129,125,	234,125,	20,82,	
X235,235,	19,77,	19,77,	20,77,	
X20,77,	0,0,	21,85,	21,86,	
X23,88,	63,125,	22,77,	22,77,	
X23,77,	23,77,	125,125,	22,87,	
X3,42,	25,77,	25,77,	28,99,	
X28,77,	28,77,	3,43,	3,44,	
X3,45,	3,46,	3,47,	3,48,	
X131,234,	3,49,	3,50,	0,0,	
X0,0,	131,235,	25,77,	25,92,	
X0,0,	28,77,	28,77,	0,0,	
X0,0,	0,0,	0,0,	3,51,	
X235,125,	0,0,	0,0,	3,52,	
X3,53,	3,54,	3,55,	3,56,	
X3,53,	3,53,	3,53,	3,53,	
X3,53,	3,53,	3,57,	3,58,	
X3,53,	3,53,	3,59,	3,53,	
X3,60,	3,61,	3,62,	3,53,	
X3,53,	3,53,	3,53,	3,53,	
X3,53,	0,0,	3,63,	0,0,	
X0,0,	131,125,	0,0,	3,64,	
X3,53,	3,65,	3,66,	3,67,	
X3,53,	3,53,	3,53,	3,53,	
X3,53,	3,53,	3,68,	3,69,	
X3,53,	3,53,	3,70,	3,53,	
X3,71,	3,72,	3,73,	3,53,	
X3,53,	3,53,	3,53,	3,53,	
X3,53,	4,43,	4,44,	4,45,	
X0,0,	4,47,	4,48,	76,179,	
X4,49,	76,179,	0,0,	0,0,	
X76,180,	76,180,	76,180,	76,180,	
X76,180,	76,180,	76,180,	76,180,	
X76,180,	76,180,	4,51,	0,0,	
X0,0,	0,0,	0,0,	4,53,	
X4,54,	4,55,	0,0,	4,53,	
X4,53,	4,53,	4,53,	4,53,	
X4,53,	4,57,	4,58,	4,53,	
X4,53,	4,59,	4,53,	4,60,	
X4,61,	4,62,	4,53,	4,53,	
X4,53,	4,53,	4,53,	4,53,	
X0,0,	4,63,	0,0,	0,0,	
X0,0,	0,0,	4,64,	4,53,	
X4,65,	4,66,	4,67,	4,53,	
X4,53,	4,53,	4,53,	4,53,	
X4,53,	4,68,	4,69,	4,53,	
X4,53,	4,70,	4,53,	4,71,	
X4,72,	4,73,	4,53,	4,53,	
X4,53,	4,53,	4,53,	4,53,	
X16,74,	0,0,	16,75,	16,75,	
X16,75,	16,75,	16,75,	16,75,	
X16,75,	16,75,	16,75,	16,75,	
X24,89,	24,77,	24,77,	0,0,	
X24,90,	0,0,	27,77,	27,77,	
X24,91,	0,0,	0,0,	16,76,	
X27,96,	27,97,	0,0,	0,0,	
X0,0,	0,0,	24,77,	24,77,	
X0,0,	27,98,	0,0,	27,77,	
X27,77,	18,77,	0,0,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	16,76,	
X18,77,	18,78,	18,79,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,80,	18,81,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	18,77,	18,77,	
X18,77,	18,77,	26,77,	26,77,	
X0,0,	26,93,	29,77,	29,77,	
X30,77,	30,77,	31,77,	31,77,	
X32,77,	32,77,	0,0,	26,94,	
X33,77,	33,77,	0,0,	26,77,	
X26,95,	233,233,	0,0,	29,77,	
X29,77,	30,77,	30,77,	31,77,	
X31,77,	32,77,	32,77,	35,77,	
X35,77,	33,77,	33,77,	0,0,	
X0,0,	0,0,	29,100,	29,101,	
X0,0,	31,105,	233,131,	31,106,	
X0,0,	34,77,	34,77,	0,0,	
X35,77,	35,77,	36,77,	36,77,	
X0,0,	30,104,	0,0,	29,102,	
X29,103,	38,77,	38,77,	31,107,	
X31,108,	33,110,	34,77,	34,77,	
X39,122,	233,125,	32,109,	36,77,	
X36,77,	37,77,	37,77,	0,0,	
X39,122,	39,123,	38,77,	38,77,	
X34,111,	0,0,	0,0,	0,0,	
X34,112,	35,114,	42,128,	0,0,	
X34,113,	36,115,	37,77,	37,77,	
X38,121,	0,0,	42,128,	42,123,	
X77,77,	77,77,	50,129,	36,116,	
X50,130,	39,124,	0,0,	0,0,	
X36,117,	78,77,	78,77,	53,132,	
X0,0,	53,132,	39,122,	37,118,	
X37,119,	77,77,	77,77,	39,122,	
X52,122,	82,77,	82,77,	42,128,	
X37,120,	50,131,	78,181,	78,77,	
X52,122,	52,123,	53,132,	82,185,	
X42,128,	54,132,	53,132,	54,132,	
X39,122,	42,128,	82,186,	82,77,	
X39,122,	56,132,	0,0,	56,132,	
X0,0,	0,0,	0,0,	0,0,	
X50,125,	0,0,	0,0,	0,0,	
X54,132,	52,124,	42,128,	0,0,	
X54,132,	53,125,	42,128,	57,132,	
X56,132,	57,132,	52,122,	39,125,	
X56,132,	52,132,	54,137,	52,132,	
X55,122,	0,0,	59,132,	60,132,	
X59,132,	60,132,	0,0,	0,0,	
X55,122,	55,123,	57,132,	54,125,	
X83,77,	83,187,	57,132,	56,142,	
X52,132,	52,133,	52,134,	56,125,	
X52,132,	59,132,	60,132,	0,0,	
X57,143,	59,132,	60,148,	0,0,	
X0,0,	83,188,	83,189,	0,0,	
X0,0,	55,124,	52,135,	52,136,	
X60,149,	57,125,	79,77,	79,77,	
X59,147,	60,150,	55,122,	52,125,	
X0,0,	55,132,	0,0,	55,132,	
X59,125,	60,125,	0,0,	79,182,	
X0,0,	0,0,	0,0,	79,77,	
X79,77,	0,0,	60,132,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X55,138,	55,132,	55,139,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,140,	55,141,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	0,0,	55,125,	
X0,0,	0,0,	0,0,	0,0,	
X55,132,	55,132,	55,132,	55,132,	
X0,0,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	55,132,	55,132,	
X55,132,	55,132,	58,132,	179,180,	
X179,180,	179,180,	179,180,	179,180,	
X179,180,	179,180,	179,180,	179,180,	
X179,180,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	58,144,	58,132,	58,132,	
X58,132,	58,145,	58,132,	58,132,	
X58,132,	58,146,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	0,0,	
X58,125,	0,0,	0,0,	0,0,	
X0,0,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	58,132,	
X58,132,	58,132,	58,132,	61,132,	
X0,0,	61,132,	80,77,	80,77,	
X0,0,	81,184,	81,77,	81,77,	
X0,0,	80,183,	0,0,	0,0,	
X88,77,	88,77,	0,0,	84,77,	
X84,77,	88,195,	61,132,	80,77,	
X80,77,	0,0,	61,132,	81,77,	
X81,77,	61,151,	61,152,	62,132,	
X84,190,	88,77,	88,77,	0,0,	
X84,77,	84,77,	61,153,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	61,125,	62,154,	62,132,	
X62,132,	62,132,	0,0,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X0,0,	62,125,	0,0,	0,0,	
X0,0,	0,0,	62,132,	62,132,	
X62,132,	62,132,	0,0,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X62,132,	62,132,	62,132,	62,132,	
X64,122,	0,0,	65,132,	67,132,	
X65,132,	67,132,	85,77,	85,77,	
X64,122,	64,123,	66,122,	92,77,	
X92,77,	85,191,	0,0,	68,132,	
X0,0,	68,132,	66,122,	66,123,	
X0,0,	65,132,	67,132,	85,77,	
X85,77,	65,132,	67,132,	0,0,	
X92,199,	92,77,	130,129,	0,0,	
X130,130,	64,124,	68,132,	69,132,	
X0,0,	69,132,	68,132,	0,0,	
X0,0,	0,0,	64,122,	66,124,	
X0,0,	64,132,	0,0,	64,132,	
X65,125,	67,125,	0,0,	0,0,	
X66,122,	130,131,	69,132,	66,132,	
X0,0,	66,132,	69,132,	0,0,	
X0,0,	68,125,	0,0,	0,0,	
X64,132,	87,77,	87,77,	65,160,	
X64,132,	0,0,	70,132,	0,0,	
X70,132,	71,132,	66,132,	71,132,	
X130,125,	67,165,	66,132,	87,194,	
X68,166,	69,125,	87,77,	87,77,	
X0,0,	0,0,	69,167,	0,0,	
X0,0,	70,132,	69,168,	64,125,	
X71,132,	70,132,	69,169,	0,0,	
X71,132,	64,156,	64,157,	0,0,	
X0,0,	66,125,	0,0,	72,132,	
X0,0,	72,132,	66,161,	0,0,	
X66,162,	0,0,	0,0,	0,0,	
X0,0,	0,0,	64,158,	64,159,	
X70,125,	0,0,	73,132,	71,125,	
X73,132,	0,0,	72,132,	0,0,	
X66,163,	66,164,	72,132,	0,0,	
X71,171,	0,0,	89,77,	89,77,	
X86,192,	86,77,	86,77,	0,0,	
X0,0,	73,132,	71,172,	0,0,	
X70,170,	73,132,	0,0,	71,173,	
X0,0,	0,0,	86,193,	89,77,	
X89,77,	72,125,	86,77,	86,77,	
X89,196,	90,197,	90,77,	90,77,	
X91,77,	91,77,	0,0,	0,0,	
X0,0,	72,174,	72,175,	0,0,	
X73,125,	93,77,	93,77,	0,0,	
X91,198,	73,177,	72,176,	90,77,	
X90,77,	91,77,	91,77,	0,0,	
X93,200,	94,77,	94,77,	95,77,	
X95,77,	0,0,	93,77,	93,77,	
X0,0,	0,0,	0,0,	93,201,	
X0,0,	96,77,	96,77,	96,204,	
X95,203,	0,0,	94,77,	94,77,	
X95,77,	95,77,	94,202,	96,205,	
X97,77,	97,77,	0,0,	98,77,	
X98,77,	96,206,	96,77,	96,77,	
X96,207,	0,0,	99,77,	99,77,	
X97,208,	100,77,	100,77,	101,77,	
X101,77,	97,77,	97,77,	98,209,	
X98,77,	98,77,	99,210,	0,0,	
X102,77,	102,77,	0,0,	99,77,	
X99,77,	0,0,	100,77,	100,77,	
X101,77,	101,77,	103,77,	103,77,	
X104,77,	104,77,	105,77,	105,77,	
X0,0,	102,77,	102,77,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	106,77,	106,77,	103,77,	
X103,77,	104,77,	104,77,	105,77,	
X105,77,	107,77,	107,77,	0,0,	
X101,211,	0,0,	100,181,	102,212,	
X0,0,	103,213,	106,77,	106,77,	
X0,0,	0,0,	0,0,	105,216,	
X108,77,	108,77,	107,77,	107,77,	
X0,0,	0,0,	104,214,	0,0,	
X109,77,	109,77,	110,77,	110,77,	
X0,0,	104,215,	0,0,	105,217,	
X105,218,	108,77,	108,77,	111,77,	
X111,77,	0,0,	106,219,	0,0,	
X107,220,	109,77,	109,77,	110,77,	
X110,77,	0,0,	0,0,	108,221,	
X112,77,	112,77,	113,77,	113,77,	
X111,77,	111,77,	114,77,	114,77,	
X115,77,	115,77,	116,77,	116,77,	
X0,0,	108,222,	0,0,	110,223,	
X0,0,	112,77,	112,77,	113,77,	
X113,77,	0,0,	109,194,	114,77,	
X114,77,	115,77,	115,77,	116,77,	
X116,77,	0,0,	0,0,	112,224,	
X117,77,	117,77,	0,0,	0,0,	
X118,77,	118,77,	0,0,	119,77,	
X119,77,	111,196,	120,77,	120,77,	
X0,0,	0,0,	113,198,	121,77,	
X121,77,	117,77,	117,77,	115,225,	
X0,0,	118,77,	118,77,	114,199,	
X119,77,	119,77,	0,0,	120,77,	
X120,77,	0,0,	115,226,	116,227,	
X121,77,	121,77,	132,132,	0,0,	
X132,132,	133,132,	118,204,	133,132,	
X0,0,	0,0,	134,132,	0,0,	
X134,132,	117,228,	118,205,	137,132,	
X142,132,	137,132,	142,132,	119,229,	
X118,206,	132,132,	0,0,	118,207,	
X133,132,	132,132,	120,230,	121,231,	
X133,132,	134,132,	135,132,	0,0,	
X135,132,	134,132,	137,132,	142,132,	
X0,0,	0,0,	137,132,	142,132,	
X0,0,	0,0,	133,236,	134,237,	
X0,0,	137,240,	181,77,	181,77,	
X132,125,	135,132,	142,249,	133,125,	
X137,241,	135,132,	182,77,	182,77,	
X134,125,	135,238,	136,132,	0,0,	
X0,0,	137,125,	142,125,	181,77,	
X181,77,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	182,287,	
X182,77,	0,0,	0,0,	0,0,	
X135,125,	136,239,	136,132,	136,132,	
X136,132,	0,0,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	0,0,	
X136,125,	0,0,	0,0,	0,0,	
X0,0,	136,132,	136,132,	136,132,	
X136,132,	0,0,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	136,132,	
X136,132,	136,132,	136,132,	138,132,	
X139,132,	138,132,	139,132,	0,0,	
X0,0,	140,132,	143,132,	140,132,	
X143,132,	183,77,	183,77,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	138,132,	139,132,	
X138,242,	183,288,	138,132,	139,132,	
X140,132,	143,132,	183,77,	183,77,	
X140,132,	143,132,	0,0,	143,250,	
X140,246,	139,245,	141,132,	0,0,	
X138,243,	138,244,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	138,125,	139,125,	0,0,	
X0,0,	0,0,	0,0,	140,125,	
X143,125,	141,247,	141,132,	141,132,	
X141,132,	0,0,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,248,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	0,0,	
X141,125,	0,0,	0,0,	0,0,	
X0,0,	141,132,	141,132,	141,132,	
X141,132,	0,0,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	141,132,	
X141,132,	141,132,	141,132,	144,132,	
X0,0,	144,132,	184,77,	184,77,	
X0,0,	0,0,	185,77,	185,77,	
X187,77,	187,77,	0,0,	186,77,	
X186,77,	0,0,	184,289,	190,77,	
X190,77,	186,291,	144,132,	184,77,	
X184,77,	187,292,	144,132,	185,290,	
X185,77,	187,77,	187,77,	145,132,	
X186,77,	186,77,	0,0,	0,0,	
X190,295,	190,77,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	144,251,	0,0,	0,0,	
X0,0,	144,125,	145,252,	145,132,	
X145,132,	145,132,	0,0,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X0,0,	145,125,	0,0,	0,0,	
X0,0,	0,0,	145,132,	145,132,	
X145,132,	145,132,	0,0,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X145,132,	145,132,	145,132,	145,132,	
X146,132,	147,132,	146,132,	147,132,	
X191,77,	191,77,	148,132,	0,0,	
X148,132,	151,122,	0,0,	150,132,	
X149,132,	150,132,	149,132,	0,0,	
X191,296,	151,122,	151,123,	146,132,	
X147,132,	191,77,	191,77,	146,132,	
X147,132,	148,132,	0,0,	0,0,	
X0,0,	148,132,	150,132,	149,132,	
X146,253,	0,0,	150,132,	149,132,	
X0,0,	148,255,	147,254,	0,0,	
X0,0,	0,0,	151,124,	152,132,	
X150,258,	152,132,	146,125,	147,125,	
X148,256,	0,0,	0,0,	151,122,	
X148,125,	149,257,	151,132,	0,0,	
X151,132,	150,125,	149,125,	153,132,	
X0,0,	153,132,	152,132,	0,0,	
X0,0,	0,0,	152,132,	0,0,	
X156,132,	154,132,	156,132,	154,132,	
X0,0,	151,132,	0,0,	152,263,	
X151,259,	151,132,	153,132,	157,132,	
X0,0,	157,132,	153,132,	0,0,	
X151,260,	0,0,	0,0,	156,132,	
X154,132,	152,125,	151,261,	156,132,	
X154,132,	151,262,	158,132,	153,264,	
X158,132,	159,132,	157,132,	159,132,	
X151,125,	154,265,	157,132,	0,0,	
X160,132,	153,125,	160,132,	0,0,	
X0,0,	161,132,	162,132,	161,132,	
X162,132,	158,132,	156,125,	154,125,	
X159,132,	158,132,	0,0,	164,132,	
X159,132,	164,132,	163,132,	160,132,	
X163,132,	157,125,	0,0,	160,132,	
X161,132,	162,132,	0,0,	0,0,	
X161,132,	162,132,	192,77,	192,77,	
X0,0,	156,236,	164,132,	0,0,	
X158,125,	163,132,	164,132,	159,125,	
X157,266,	163,132,	192,297,	0,0,	
X159,268,	0,0,	160,125,	192,77,	
X192,77,	158,267,	0,0,	161,125,	
X162,125,	165,132,	0,0,	165,132,	
X0,0,	0,0,	161,271,	0,0,	
X0,0,	164,125,	160,269,	166,132,	
X163,125,	166,132,	164,276,	0,0,	
X167,132,	160,270,	167,132,	162,274,	
X165,132,	0,0,	161,272,	161,273,	
X165,132,	163,275,	0,0,	168,132,	
X164,277,	168,132,	166,132,	194,77,	
X194,77,	0,0,	166,132,	167,132,	
X169,132,	0,0,	169,132,	167,132,	
X0,0,	170,132,	171,132,	170,132,	
X171,132,	0,0,	168,132,	165,125,	
X194,77,	194,77,	168,132,	172,132,	
X173,132,	172,132,	173,132,	169,132,	
X0,0,	166,125,	0,0,	169,132,	
X170,132,	171,132,	167,125,	0,0,	
X170,132,	171,132,	0,0,	165,249,	
X166,278,	0,0,	172,132,	173,132,	
X0,0,	168,125,	172,132,	173,132,	
X174,122,	0,0,	168,279,	0,0,	
X0,0,	0,0,	169,125,	0,0,	
X174,122,	174,123,	0,0,	170,125,	
X171,125,	175,132,	167,251,	175,132,	
X176,132,	0,0,	176,132,	0,0,	
X0,0,	172,125,	173,125,	0,0,	
X169,253,	0,0,	0,0,	0,0,	
X0,0,	171,280,	0,0,	0,0,	
X175,132,	174,124,	170,254,	176,132,	
X175,132,	0,0,	0,0,	176,132,	
X171,281,	173,283,	174,122,	0,0,	
X177,132,	174,132,	177,132,	174,132,	
X172,282,	0,0,	0,0,	0,0,	
X0,0,	188,77,	188,77,	189,294,	
X189,77,	189,77,	195,299,	175,125,	
X188,293,	0,0,	176,125,	177,132,	
X174,132,	193,77,	193,77,	177,132,	
X174,132,	0,0,	188,77,	188,77,	
X0,0,	189,77,	189,77,	195,77,	
X195,77,	175,284,	196,77,	196,77,	
X0,0,	193,298,	193,77,	193,77,	
X176,285,	197,77,	197,77,	198,77,	
X198,77,	0,0,	177,125,	174,125,	
X195,77,	195,77,	0,0,	196,77,	
X196,77,	197,300,	0,0,	174,259,	
X199,77,	199,77,	197,77,	197,77,	
X198,77,	198,77,	0,0,	174,260,	
X177,286,	200,77,	200,77,	201,77,	
X201,77,	174,261,	201,302,	0,0,	
X174,262,	199,77,	199,77,	202,77,	
X202,77,	0,0,	200,301,	203,77,	
X203,77,	203,304,	200,77,	200,77,	
X201,77,	201,77,	204,77,	204,77,	
X205,77,	205,77,	206,77,	206,77,	
X202,303,	202,77,	207,77,	207,77,	
X203,77,	203,77,	0,0,	209,77,	
X209,77,	0,0,	0,0,	204,77,	
X204,77,	205,77,	205,77,	206,77,	
X206,77,	208,77,	208,77,	207,77,	
X207,77,	210,77,	210,77,	208,305,	
X209,77,	209,306,	0,0,	210,307,	
X211,77,	211,77,	212,77,	212,77,	
X213,77,	213,77,	208,77,	208,77,	
X214,77,	214,77,	210,77,	210,77,	
X215,77,	215,77,	216,77,	216,77,	
X0,0,	211,77,	211,77,	212,77,	
X212,77,	213,77,	213,77,	217,77,	
X217,77,	214,77,	214,77,	218,77,	
X218,77,	215,77,	215,77,	216,77,	
X216,77,	0,0,	219,77,	219,77,	
X220,77,	220,77,	221,77,	221,77,	
X217,77,	217,77,	0,0,	0,0,	
X218,77,	218,77,	212,288,	0,0,	
X213,289,	211,287,	215,291,	219,77,	
X219,77,	220,77,	220,77,	221,77,	
X221,77,	214,290,	218,310,	216,308,	
X222,77,	222,77,	217,309,	0,0,	
X0,0,	0,0,	0,0,	223,314,	
X0,0,	224,77,	224,77,	225,77,	
X225,77,	0,0,	226,77,	226,77,	
X0,0,	222,77,	222,77,	0,0,	
X220,312,	0,0,	221,313,	219,311,	
X223,77,	223,77,	224,77,	224,77,	
X225,77,	225,77,	0,0,	226,77,	
X226,77,	227,77,	227,77,	0,0,	
X0,0,	228,77,	228,77,	0,0,	
X0,0,	223,77,	223,77,	229,77,	
X229,77,	230,77,	230,77,	0,0,	
X222,298,	226,316,	227,77,	227,77,	
X0,0,	224,300,	228,77,	228,77,	
X225,315,	0,0,	231,77,	231,77,	
X229,77,	229,77,	230,77,	230,77,	
X236,132,	237,132,	236,132,	237,132,	
X287,77,	287,77,	0,0,	228,304,	
X0,0,	0,0,	0,0,	231,77,	
X231,77,	0,0,	240,132,	0,0,	
X240,132,	229,305,	227,303,	236,132,	
X237,132,	287,77,	287,77,	236,132,	
X237,132,	238,132,	239,132,	238,132,	
X239,132,	0,0,	0,0,	230,306,	
X231,307,	240,132,	0,0,	0,0,	
X0,0,	240,132,	237,318,	0,0,	
X241,132,	0,0,	241,132,	0,0,	
X238,132,	239,132,	236,125,	237,125,	
X238,132,	239,132,	242,132,	240,321,	
X242,132,	0,0,	0,0,	0,0,	
X0,0,	238,319,	239,320,	241,132,	
X240,125,	0,0,	243,132,	241,132,	
X243,132,	0,0,	241,322,	0,0,	
X0,0,	242,132,	0,0,	238,125,	
X239,125,	242,132,	288,77,	288,77,	
X289,77,	289,77,	0,0,	0,0,	
X0,0,	243,132,	0,0,	242,323,	
X0,0,	243,132,	241,125,	290,77,	
X290,77,	243,324,	244,132,	288,77,	
X288,77,	289,77,	289,77,	0,0,	
X242,125,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X290,77,	290,77,	0,0,	0,0,	
X243,125,	244,325,	244,132,	244,132,	
X244,132,	0,0,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	0,0,	
X244,125,	0,0,	0,0,	0,0,	
X0,0,	244,132,	244,132,	244,132,	
X244,132,	0,0,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	244,132,	
X244,132,	244,132,	244,132,	245,132,	
X246,132,	245,132,	246,132,	291,77,	
X291,77,	247,132,	248,132,	247,132,	
X248,132,	292,77,	292,77,	249,132,	
X250,132,	249,132,	250,132,	250,330,	
X0,0,	0,0,	245,132,	246,132,	
X291,77,	291,77,	245,132,	246,132,	
X247,132,	248,132,	292,348,	292,77,	
X247,132,	248,132,	249,132,	250,132,	
X246,327,	0,0,	249,132,	250,132,	
X245,326,	247,328,	0,0,	0,0,	
X0,0,	251,132,	248,329,	251,132,	
X0,0,	245,125,	246,125,	252,132,	
X253,132,	252,132,	253,132,	247,125,	
X248,125,	254,132,	256,132,	254,132,	
X256,132,	249,125,	250,125,	255,132,	
X251,132,	255,132,	0,0,	0,0,	
X251,132,	0,0,	252,132,	253,132,	
X0,0,	0,0,	252,132,	253,132,	
X254,132,	256,132,	0,0,	0,0,	
X254,132,	256,333,	255,132,	252,331,	
X0,0,	0,0,	255,132,	257,132,	
X0,0,	257,132,	0,0,	251,125,	
X258,132,	259,132,	258,132,	259,132,	
X255,332,	252,125,	253,125,	260,132,	
X261,132,	260,132,	261,132,	254,125,	
X256,125,	0,0,	257,132,	0,0,	
X0,0,	255,125,	257,132,	258,132,	
X259,132,	256,132,	258,335,	258,132,	
X259,132,	0,0,	260,132,	261,132,	
X0,0,	0,0,	260,132,	261,132,	
X257,334,	262,132,	0,0,	262,132,	
X263,132,	0,0,	263,132,	0,0,	
X0,0,	257,125,	264,132,	0,0,	
X264,132,	0,0,	258,125,	259,125,	
X265,132,	266,132,	265,132,	266,132,	
X262,132,	260,125,	261,125,	263,132,	
X262,132,	0,0,	267,132,	263,132,	
X267,132,	264,132,	263,336,	0,0,	
X268,132,	264,132,	268,132,	265,132,	
X266,132,	0,0,	0,0,	265,132,	
X266,132,	269,132,	265,338,	269,132,	
X0,0,	267,132,	0,0,	262,125,	
X264,337,	267,132,	263,125,	268,132,	
X271,132,	0,0,	271,132,	268,132,	
X264,125,	270,132,	0,0,	270,132,	
X269,132,	0,0,	265,125,	266,125,	
X269,132,	272,132,	274,132,	272,132,	
X274,132,	0,0,	0,0,	271,132,	
X267,125,	0,0,	0,0,	271,132,	
X270,132,	0,0,	268,125,	0,0,	
X270,132,	273,132,	0,0,	273,132,	
X272,132,	274,132,	266,318,	269,125,	
X272,132,	274,132,	267,319,	0,0,	
X0,0,	0,0,	0,0,	275,132,	
X268,320,	275,132,	271,125,	0,0,	
X273,132,	0,0,	0,0,	270,125,	
X273,132,	0,0,	276,132,	277,132,	
X276,132,	277,132,	269,321,	272,125,	
X274,125,	0,0,	275,132,	270,322,	
X0,0,	271,339,	275,132,	278,132,	
X0,0,	278,132,	278,345,	0,0,	
X272,340,	276,132,	277,132,	273,125,	
X0,0,	276,132,	277,132,	279,132,	
X273,341,	279,132,	0,0,	274,342,	
X0,0,	280,132,	278,132,	280,132,	
X0,0,	275,125,	278,132,	281,132,	
X282,132,	281,132,	282,132,	0,0,	
X0,0,	0,0,	279,132,	0,0,	
X276,125,	277,125,	279,132,	283,132,	
X280,132,	283,132,	0,0,	275,343,	
X280,132,	0,0,	281,132,	282,132,	
X0,0,	278,125,	281,132,	282,132,	
X0,0,	284,132,	276,344,	284,132,	
X0,0,	0,0,	283,132,	277,329,	
X0,0,	279,125,	283,132,	0,0,	
X285,132,	0,0,	285,132,	280,125,	
X0,0,	286,132,	0,0,	286,132,	
X284,132,	281,125,	282,125,	0,0,	
X284,132,	293,77,	293,77,	279,331,	
X0,0,	0,0,	281,347,	285,132,	
X0,0,	283,125,	280,346,	285,132,	
X286,132,	293,349,	294,77,	294,77,	
X286,132,	283,335,	293,77,	293,77,	
X0,0,	282,334,	0,0,	284,125,	
X295,77,	295,77,	294,350,	296,77,	
X296,77,	0,0,	295,351,	294,77,	
X294,77,	296,352,	285,125,	284,336,	
X0,0,	297,77,	297,77,	286,125,	
X0,0,	295,77,	295,77,	297,353,	
X296,77,	296,77,	298,77,	298,77,	
X299,354,	0,0,	0,0,	286,338,	
X300,77,	300,77,	297,77,	297,77,	
X301,77,	301,77,	285,337,	302,77,	
X302,356,	303,77,	303,77,	298,77,	
X298,77,	0,0,	299,77,	299,77,	
X0,0,	300,77,	300,77,	304,77,	
X304,77,	301,77,	301,355,	0,0,	
X302,77,	302,77,	303,77,	303,77,	
X305,77,	305,77,	0,0,	299,77,	
X299,77,	306,77,	306,77,	0,0,	
X304,77,	304,77,	307,77,	307,77,	
X308,77,	308,77,	309,77,	309,77,	
X0,0,	305,77,	305,77,	310,77,	
X310,77,	0,0,	306,77,	306,77,	
X311,77,	311,77,	0,0,	307,77,	
X307,77,	308,77,	308,77,	309,77,	
X309,77,	312,77,	312,77,	0,0,	
X310,77,	310,77,	313,77,	313,77,	
X0,0,	311,77,	311,77,	0,0,	
X0,0,	0,0,	314,354,	0,0,	
X0,0,	0,0,	312,77,	312,77,	
X315,77,	315,77,	0,0,	313,77,	
X313,77,	0,0,	309,349,	0,0,	
X0,0,	308,348,	311,351,	310,350,	
X314,77,	314,77,	316,77,	316,77,	
X0,0,	315,77,	315,77,	312,352,	
X318,132,	319,132,	318,132,	319,132,	
X313,353,	0,0,	320,132,	0,0,	
X320,132,	314,77,	314,77,	316,77,	
X316,77,	321,132,	322,132,	321,132,	
X322,132,	348,77,	348,77,	318,132,	
X319,132,	0,0,	0,0,	318,132,	
X319,132,	320,132,	323,132,	316,356,	
X323,132,	320,132,	315,357,	0,0,	
X321,132,	322,132,	348,77,	348,77,	
X321,132,	322,132,	324,132,	325,132,	
X324,132,	325,132,	0,0,	0,0,	
X0,0,	323,132,	318,125,	319,125,	
X0,0,	323,132,	349,77,	349,77,	
X320,125,	0,0,	326,132,	0,0,	
X326,132,	324,132,	325,132,	321,125,	
X322,125,	324,132,	325,132,	323,359,	
X327,132,	0,0,	327,132,	349,77,	
X349,77,	0,0,	324,360,	325,361,	
X323,125,	326,132,	0,0,	0,0,	
X328,132,	326,132,	328,132,	0,0,	
X326,362,	0,0,	0,0,	327,132,	
X324,125,	325,125,	329,132,	327,132,	
X329,132,	331,132,	327,363,	331,132,	
X332,132,	0,0,	332,132,	328,132,	
X350,77,	350,77,	330,122,	328,132,	
X326,125,	0,0,	328,364,	0,0,	
X0,0,	329,132,	330,122,	330,123,	
X331,132,	329,132,	327,125,	332,132,	
X331,132,	350,77,	350,77,	332,132,	
X351,77,	351,77,	333,132,	0,0,	
X333,132,	0,0,	328,125,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	332,366,	330,124,	
X329,125,	351,77,	351,77,	331,125,	
X0,0,	333,132,	332,125,	333,367,	
X330,122,	333,132,	334,132,	330,132,	
X334,132,	330,365,	330,132,	330,132,	
X330,132,	330,132,	330,132,	330,132,	
X330,132,	330,132,	330,132,	335,132,	
X336,132,	335,132,	336,132,	352,77,	
X352,77,	334,132,	330,132,	0,0,	
X333,125,	334,132,	330,132,	337,132,	
X338,132,	337,132,	338,132,	0,0,	
X0,0,	0,0,	335,132,	336,132,	
X352,77,	352,77,	335,132,	336,132,	
X339,132,	340,132,	339,132,	340,132,	
X0,0,	0,0,	337,132,	338,132,	
X334,125,	330,125,	337,132,	338,132,	
X341,132,	342,132,	341,132,	342,132,	
X0,0,	0,0,	0,0,	339,132,	
X340,132,	335,125,	336,125,	339,132,	
X340,132,	0,0,	343,132,	0,0,	
X343,132,	0,0,	0,0,	341,132,	
X342,132,	337,125,	338,125,	341,132,	
X342,132,	344,132,	0,0,	344,132,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	343,132,	339,125,	340,125,	
X0,0,	343,132,	0,0,	346,132,	
X0,0,	346,132,	0,0,	0,0,	
X344,132,	0,0,	341,125,	342,125,	
X344,132,	0,0,	0,0,	353,77,	
X353,77,	340,360,	0,0,	0,0,	
X0,0,	339,359,	346,132,	342,362,	
X343,125,	0,0,	346,132,	0,0,	
X341,361,	347,132,	0,0,	347,132,	
X353,77,	353,77,	345,132,	344,125,	
X343,363,	345,132,	345,132,	345,132,	
X345,132,	345,132,	345,132,	345,132,	
X345,132,	345,132,	0,0,	344,364,	
X347,132,	346,125,	354,77,	354,77,	
X347,132,	355,77,	355,77,	0,0,	
X355,369,	0,0,	0,0,	356,77,	
X356,77,	357,77,	357,77,	0,0,	
X359,132,	0,0,	359,132,	354,77,	
X354,77,	0,0,	355,77,	355,77,	
X360,132,	346,368,	360,132,	347,125,	
X356,77,	356,77,	357,77,	357,77,	
X345,125,	0,0,	347,367,	359,132,	
X361,132,	0,0,	361,132,	359,132,	
X0,0,	0,0,	362,132,	360,132,	
X362,132,	0,0,	0,0,	360,132,	
X357,369,	363,132,	364,132,	363,132,	
X364,132,	0,0,	0,0,	361,132,	
X365,132,	0,0,	365,132,	361,132,	
X0,0,	362,132,	359,125,	0,0,	
X366,132,	362,132,	366,132,	0,0,	
X363,132,	364,132,	360,125,	0,0,	
X363,132,	364,132,	367,132,	365,132,	
X367,132,	0,0,	0,0,	365,132,	
X0,0,	0,0,	361,125,	366,132,	
X368,132,	0,0,	368,132,	366,371,	
X362,125,	0,0,	0,0,	369,77,	
X369,77,	367,132,	0,0,	363,125,	
X364,125,	367,132,	371,132,	0,0,	
X371,132,	0,0,	365,125,	368,132,	
X0,0,	0,0,	0,0,	368,132,	
X369,77,	369,77,	366,125,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	371,132,	0,0,	366,132,	
X367,125,	371,132,	0,0,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	368,125,	0,0,	
X0,0,	0,0,	0,0,	0,0,	
X0,0,	0,0,	0,0,	368,371,	
X0,0,	0,0,	0,0,	0,0,	
X371,125,	0,0,	0,0,	0,0,	
X0,0};
Xstruct yysvf yysvec[] ={
X0,	0,	0,
Xyycrank+-1,	0,		0,	
Xyycrank+-84,	yysvec+1,	0,	
Xyycrank+-206,	0,		0,	
Xyycrank+-289,	yysvec+3,	0,	
Xyycrank+0,	0,		yyvstop+1,
Xyycrank+4,	0,		yyvstop+3,
Xyycrank+0,	yysvec+6,	yyvstop+6,
Xyycrank+0,	0,		yyvstop+8,
Xyycrank+0,	0,		yyvstop+11,
Xyycrank+0,	0,		yyvstop+14,
Xyycrank+0,	0,		yyvstop+17,
Xyycrank+0,	0,		yyvstop+20,
Xyycrank+0,	0,		yyvstop+23,
Xyycrank+0,	0,		yyvstop+26,
Xyycrank+0,	0,		yyvstop+29,
Xyycrank+366,	0,		yyvstop+32,
Xyycrank+0,	0,		yyvstop+35,
Xyycrank+403,	0,		yyvstop+38,
Xyycrank+142,	yysvec+18,	yyvstop+41,
Xyycrank+144,	yysvec+18,	yyvstop+44,
Xyycrank+147,	yysvec+18,	yyvstop+47,
Xyycrank+151,	yysvec+18,	yyvstop+50,
Xyycrank+153,	yysvec+18,	yyvstop+53,
Xyycrank+359,	yysvec+18,	yyvstop+56,
Xyycrank+175,	yysvec+18,	yyvstop+59,
Xyycrank+460,	yysvec+18,	yyvstop+62,
Xyycrank+364,	yysvec+18,	yyvstop+65,
Xyycrank+178,	yysvec+18,	yyvstop+68,
Xyycrank+464,	yysvec+18,	yyvstop+71,
Xyycrank+466,	yysvec+18,	yyvstop+74,
Xyycrank+468,	yysvec+18,	yyvstop+77,
Xyycrank+470,	yysvec+18,	yyvstop+80,
Xyycrank+474,	yysvec+18,	yyvstop+83,
Xyycrank+503,	yysvec+18,	yyvstop+86,
Xyycrank+489,	yysvec+18,	yyvstop+89,
Xyycrank+508,	yysvec+18,	yyvstop+92,
Xyycrank+527,	yysvec+18,	yyvstop+95,
Xyycrank+515,	yysvec+18,	yyvstop+98,
Xyycrank+-587,	0,		yyvstop+101,
Xyycrank+-41,	yysvec+39,	yyvstop+103,
Xyycrank+30,	yysvec+6,	yyvstop+106,
Xyycrank+-605,	0,		yyvstop+108,
Xyycrank+-1,	yysvec+39,	yyvstop+112,
Xyycrank+-2,	yysvec+39,	yyvstop+115,
Xyycrank+-3,	yysvec+39,	yyvstop+118,
Xyycrank+-4,	yysvec+39,	yyvstop+121,
Xyycrank+-5,	yysvec+39,	yyvstop+124,
Xyycrank+-38,	yysvec+39,	yyvstop+127,
Xyycrank+-40,	yysvec+39,	yyvstop+130,
Xyycrank+-572,	yysvec+39,	yyvstop+133,
Xyycrank+-42,	yysvec+39,	yyvstop+136,
Xyycrank+-635,	0,		yyvstop+139,
Xyycrank+-581,	yysvec+39,	yyvstop+142,
Xyycrank+-603,	yysvec+39,	yyvstop+145,
Xyycrank+-683,	0,		yyvstop+148,
Xyycrank+-611,	yysvec+39,	yyvstop+151,
Xyycrank+-629,	yysvec+39,	yyvstop+154,
Xyycrank+-760,	yysvec+55,	yyvstop+157,
Xyycrank+-640,	yysvec+39,	yyvstop+160,
Xyycrank+-641,	yysvec+39,	yyvstop+163,
Xyycrank+-837,	yysvec+39,	yyvstop+166,
Xyycrank+-865,	yysvec+55,	yyvstop+169,
Xyycrank+-141,	yysvec+39,	yyvstop+172,
Xyycrank+-987,	0,		yyvstop+174,
Xyycrank+-944,	yysvec+39,	yyvstop+177,
Xyycrank+-997,	0,		yyvstop+180,
Xyycrank+-945,	yysvec+39,	yyvstop+183,
Xyycrank+-957,	yysvec+39,	yyvstop+186,
Xyycrank+-977,	yysvec+39,	yyvstop+189,
Xyycrank+-1012,	yysvec+39,	yyvstop+192,
Xyycrank+-1015,	yysvec+39,	yyvstop+195,
Xyycrank+-1045,	yysvec+39,	yyvstop+198,
Xyycrank+-1060,	yysvec+39,	yyvstop+201,
Xyycrank+4,	0,		0,	
Xyycrank+0,	yysvec+16,	yyvstop+204,
Xyycrank+292,	0,		0,	
Xyycrank+550,	yysvec+18,	yyvstop+206,
Xyycrank+559,	yysvec+18,	yyvstop+208,
Xyycrank+656,	yysvec+18,	yyvstop+210,
Xyycrank+820,	yysvec+18,	yyvstop+212,
Xyycrank+824,	yysvec+18,	yyvstop+214,
Xyycrank+571,	yysvec+18,	yyvstop+216,
Xyycrank+630,	yysvec+18,	yyvstop+218,
Xyycrank+833,	yysvec+18,	yyvstop+220,
Xyycrank+928,	yysvec+18,	yyvstop+222,
Xyycrank+1055,	yysvec+18,	yyvstop+224,
Xyycrank+987,	yysvec+18,	yyvstop+226,
Xyycrank+830,	yysvec+18,	yyvstop+228,
Xyycrank+1052,	yysvec+18,	yyvstop+230,
Xyycrank+1076,	yysvec+18,	yyvstop+232,
Xyycrank+1078,	yysvec+18,	yyvstop+234,
Xyycrank+933,	yysvec+18,	yyvstop+236,
Xyycrank+1087,	yysvec+18,	yyvstop+238,
Xyycrank+1099,	yysvec+18,	yyvstop+240,
Xyycrank+1101,	yysvec+18,	yyvstop+242,
Xyycrank+1111,	yysvec+18,	yyvstop+244,
Xyycrank+1122,	yysvec+18,	yyvstop+246,
Xyycrank+1125,	yysvec+18,	yyvstop+248,
Xyycrank+1132,	yysvec+18,	yyvstop+250,
Xyycrank+1135,	yysvec+18,	yyvstop+252,
Xyycrank+1137,	yysvec+18,	yyvstop+254,
Xyycrank+1146,	yysvec+18,	yyvstop+256,
Xyycrank+1156,	yysvec+18,	yyvstop+258,
Xyycrank+1158,	yysvec+18,	yyvstop+260,
Xyycrank+1160,	yysvec+18,	yyvstop+262,
Xyycrank+1171,	yysvec+18,	yyvstop+264,
Xyycrank+1179,	yysvec+18,	yyvstop+266,
Xyycrank+1194,	yysvec+18,	yyvstop+268,
Xyycrank+1202,	yysvec+18,	yyvstop+270,
Xyycrank+1204,	yysvec+18,	yyvstop+272,
Xyycrank+1213,	yysvec+18,	yyvstop+274,
Xyycrank+1226,	yysvec+18,	yyvstop+276,
Xyycrank+1228,	yysvec+18,	yyvstop+278,
Xyycrank+1232,	yysvec+18,	yyvstop+280,
Xyycrank+1234,	yysvec+18,	yyvstop+282,
Xyycrank+1236,	yysvec+18,	yyvstop+284,
Xyycrank+1258,	yysvec+18,	yyvstop+286,
Xyycrank+1262,	yysvec+18,	yyvstop+288,
Xyycrank+1265,	yysvec+18,	yyvstop+290,
Xyycrank+1268,	yysvec+18,	yyvstop+292,
Xyycrank+1273,	yysvec+18,	yyvstop+294,
Xyycrank+-43,	yysvec+39,	0,	
Xyycrank+39,	0,		0,	
Xyycrank+0,	yysvec+42,	yyvstop+296,
Xyycrank+-146,	yysvec+39,	0,	
Xyycrank+-54,	yysvec+39,	yyvstop+298,
Xyycrank+29,	0,		0,	
Xyycrank+0,	yysvec+42,	0,	
Xyycrank+-129,	yysvec+39,	0,	
Xyycrank+-972,	yysvec+39,	yyvstop+300,
Xyycrank+-209,	yysvec+39,	0,	
Xyycrank+-1312,	yysvec+39,	yyvstop+302,
Xyycrank+-1315,	yysvec+39,	yyvstop+304,
Xyycrank+-1320,	yysvec+39,	yyvstop+306,
Xyycrank+-1340,	yysvec+39,	yyvstop+308,
Xyycrank+-1368,	yysvec+55,	yyvstop+310,
Xyycrank+-1325,	yysvec+39,	yyvstop+312,
Xyycrank+-1445,	yysvec+39,	yyvstop+314,
Xyycrank+-1446,	yysvec+39,	yyvstop+316,
Xyycrank+-1451,	yysvec+39,	yyvstop+318,
Xyycrank+-1480,	yysvec+55,	yyvstop+320,
Xyycrank+-1326,	yysvec+39,	yyvstop+322,
Xyycrank+-1452,	yysvec+39,	yyvstop+324,
Xyycrank+-1557,	yysvec+39,	yyvstop+326,
Xyycrank+-1585,	yysvec+55,	yyvstop+328,
Xyycrank+-1662,	yysvec+39,	yyvstop+330,
Xyycrank+-1663,	yysvec+39,	yyvstop+332,
Xyycrank+-1668,	yysvec+39,	yyvstop+334,
Xyycrank+-1674,	yysvec+39,	yyvstop+336,
Xyycrank+-1673,	yysvec+39,	yyvstop+338,
Xyycrank+-1716,	0,		yyvstop+340,
Xyycrank+-1705,	yysvec+39,	yyvstop+342,
Xyycrank+-1721,	yysvec+39,	yyvstop+344,
Xyycrank+-1731,	yysvec+39,	yyvstop+346,
Xyycrank+-46,	yysvec+39,	yyvstop+348,
Xyycrank+-1730,	yysvec+39,	yyvstop+350,
Xyycrank+-1741,	yysvec+39,	yyvstop+352,
Xyycrank+-1756,	yysvec+39,	yyvstop+354,
Xyycrank+-1759,	yysvec+39,	yyvstop+356,
Xyycrank+-1766,	yysvec+39,	yyvstop+358,
Xyycrank+-1771,	yysvec+39,	yyvstop+360,
Xyycrank+-1772,	yysvec+39,	yyvstop+362,
Xyycrank+-1784,	yysvec+39,	yyvstop+364,
Xyycrank+-1781,	yysvec+39,	yyvstop+366,
Xyycrank+-1819,	yysvec+39,	yyvstop+368,
Xyycrank+-1829,	yysvec+39,	yyvstop+370,
Xyycrank+-1834,	yysvec+39,	yyvstop+372,
Xyycrank+-1845,	yysvec+39,	yyvstop+374,
Xyycrank+-1854,	yysvec+39,	yyvstop+376,
Xyycrank+-1859,	yysvec+39,	yyvstop+378,
Xyycrank+-1860,	yysvec+39,	yyvstop+380,
Xyycrank+-1869,	yysvec+39,	yyvstop+382,
Xyycrank+-1870,	yysvec+39,	yyvstop+384,
Xyycrank+-1939,	0,		yyvstop+386,
Xyycrank+-1907,	yysvec+39,	yyvstop+388,
Xyycrank+-1910,	yysvec+39,	yyvstop+390,
Xyycrank+-1938,	yysvec+39,	yyvstop+392,
Xyycrank+75,	yysvec+74,	yyvstop+394,
Xyycrank+759,	0,		0,	
Xyycrank+0,	yysvec+179,	yyvstop+396,
Xyycrank+1336,	yysvec+18,	yyvstop+398,
Xyycrank+1344,	yysvec+18,	yyvstop+401,
Xyycrank+1435,	yysvec+18,	yyvstop+403,
Xyycrank+1540,	yysvec+18,	yyvstop+405,
Xyycrank+1544,	yysvec+18,	yyvstop+407,
Xyycrank+1549,	yysvec+18,	yyvstop+409,
Xyycrank+1546,	yysvec+18,	yyvstop+412,
Xyycrank+1927,	yysvec+18,	yyvstop+414,
Xyycrank+1930,	yysvec+18,	yyvstop+416,
Xyycrank+1553,	yysvec+18,	yyvstop+418,
Xyycrank+1646,	yysvec+18,	yyvstop+420,
Xyycrank+1776,	yysvec+18,	yyvstop+422,
Xyycrank+1939,	yysvec+18,	yyvstop+424,
Xyycrank+1829,	yysvec+18,	yyvstop+426,
Xyycrank+1949,	yysvec+18,	yyvstop+429,
Xyycrank+1952,	yysvec+18,	yyvstop+432,
Xyycrank+1959,	yysvec+18,	yyvstop+435,
Xyycrank+1961,	yysvec+18,	yyvstop+437,
Xyycrank+1974,	yysvec+18,	yyvstop+440,
Xyycrank+1983,	yysvec+18,	yyvstop+443,
Xyycrank+1985,	yysvec+18,	yyvstop+445,
Xyycrank+1993,	yysvec+18,	yyvstop+447,
Xyycrank+1997,	yysvec+18,	yyvstop+449,
Xyycrank+2004,	yysvec+18,	yyvstop+451,
Xyycrank+2006,	yysvec+18,	yyvstop+454,
Xyycrank+2008,	yysvec+18,	yyvstop+457,
Xyycrank+2012,	yysvec+18,	yyvstop+460,
Xyycrank+2027,	yysvec+18,	yyvstop+463,
Xyycrank+2017,	yysvec+18,	yyvstop+466,
Xyycrank+2031,	yysvec+18,	yyvstop+468,
Xyycrank+2038,	yysvec+18,	yyvstop+471,
Xyycrank+2040,	yysvec+18,	yyvstop+473,
Xyycrank+2042,	yysvec+18,	yyvstop+475,
Xyycrank+2046,	yysvec+18,	yyvstop+477,
Xyycrank+2050,	yysvec+18,	yyvstop+479,
Xyycrank+2052,	yysvec+18,	yyvstop+482,
Xyycrank+2061,	yysvec+18,	yyvstop+484,
Xyycrank+2065,	yysvec+18,	yyvstop+486,
Xyycrank+2072,	yysvec+18,	yyvstop+488,
Xyycrank+2074,	yysvec+18,	yyvstop+490,
Xyycrank+2076,	yysvec+18,	yyvstop+492,
Xyycrank+2098,	yysvec+18,	yyvstop+494,
Xyycrank+2122,	yysvec+18,	yyvstop+496,
Xyycrank+2107,	yysvec+18,	yyvstop+499,
Xyycrank+2109,	yysvec+18,	yyvstop+501,
Xyycrank+2112,	yysvec+18,	yyvstop+503,
Xyycrank+2131,	yysvec+18,	yyvstop+505,
Xyycrank+2135,	yysvec+18,	yyvstop+507,
Xyycrank+2141,	yysvec+18,	yyvstop+509,
Xyycrank+2143,	yysvec+18,	yyvstop+512,
Xyycrank+2156,	yysvec+18,	yyvstop+514,
Xyycrank+32,	0,		0,	
Xyycrank+-497,	yysvec+39,	yyvstop+517,
Xyycrank+-130,	yysvec+39,	0,	
Xyycrank+-176,	yysvec+39,	yyvstop+519,
Xyycrank+-2182,	yysvec+39,	yyvstop+521,
Xyycrank+-2183,	yysvec+39,	yyvstop+524,
Xyycrank+-2207,	yysvec+39,	yyvstop+526,
Xyycrank+-2208,	yysvec+39,	yyvstop+528,
Xyycrank+-2196,	yysvec+39,	yyvstop+530,
Xyycrank+-2222,	yysvec+39,	yyvstop+532,
Xyycrank+-2232,	yysvec+39,	yyvstop+535,
Xyycrank+-2244,	yysvec+39,	yyvstop+537,
Xyycrank+-2272,	yysvec+55,	yyvstop+539,
Xyycrank+-2349,	yysvec+39,	yyvstop+541,
Xyycrank+-2350,	yysvec+39,	yyvstop+543,
Xyycrank+-2355,	yysvec+39,	yyvstop+545,
Xyycrank+-2356,	yysvec+39,	yyvstop+547,
Xyycrank+-2361,	yysvec+39,	yyvstop+549,
Xyycrank+-2362,	yysvec+39,	yyvstop+552,
Xyycrank+-2391,	yysvec+39,	yyvstop+555,
Xyycrank+-2397,	yysvec+39,	yyvstop+558,
Xyycrank+-2398,	yysvec+39,	yyvstop+560,
Xyycrank+-2403,	yysvec+39,	yyvstop+563,
Xyycrank+-2409,	yysvec+39,	yyvstop+566,
Xyycrank+-2404,	yysvec+39,	yyvstop+568,
Xyycrank+-2433,	yysvec+39,	yyvstop+570,
Xyycrank+-2438,	yysvec+39,	yyvstop+572,
Xyycrank+-2439,	yysvec+39,	yyvstop+574,
Xyycrank+-2445,	yysvec+39,	yyvstop+577,
Xyycrank+-2446,	yysvec+39,	yyvstop+580,
Xyycrank+-2471,	yysvec+39,	yyvstop+583,
Xyycrank+-2474,	yysvec+39,	yyvstop+586,
Xyycrank+-2480,	yysvec+39,	yyvstop+589,
Xyycrank+-2486,	yysvec+39,	yyvstop+591,
Xyycrank+-2487,	yysvec+39,	yyvstop+594,
Xyycrank+-2496,	yysvec+39,	yyvstop+596,
Xyycrank+-2502,	yysvec+39,	yyvstop+598,
Xyycrank+-2511,	yysvec+39,	yyvstop+600,
Xyycrank+-2527,	yysvec+39,	yyvstop+602,
Xyycrank+-2522,	yysvec+39,	yyvstop+605,
Xyycrank+-2535,	yysvec+39,	yyvstop+607,
Xyycrank+-2551,	yysvec+39,	yyvstop+609,
Xyycrank+-2536,	yysvec+39,	yyvstop+611,
Xyycrank+-2565,	yysvec+39,	yyvstop+613,
Xyycrank+-2576,	yysvec+39,	yyvstop+615,
Xyycrank+-2577,	yysvec+39,	yyvstop+617,
Xyycrank+-2589,	yysvec+39,	yyvstop+619,
Xyycrank+-2601,	yysvec+39,	yyvstop+622,
Xyycrank+-2607,	yysvec+39,	yyvstop+624,
Xyycrank+-2613,	yysvec+39,	yyvstop+626,
Xyycrank+-2614,	yysvec+39,	yyvstop+628,
Xyycrank+-2625,	yysvec+39,	yyvstop+630,
Xyycrank+-2639,	yysvec+39,	yyvstop+632,
Xyycrank+-2650,	yysvec+39,	yyvstop+635,
Xyycrank+-2655,	yysvec+39,	yyvstop+637,
Xyycrank+2166,	yysvec+18,	yyvstop+640,
Xyycrank+2236,	yysvec+18,	yyvstop+643,
Xyycrank+2238,	yysvec+18,	yyvstop+646,
Xyycrank+2249,	yysvec+18,	yyvstop+649,
Xyycrank+2333,	yysvec+18,	yyvstop+652,
Xyycrank+2339,	yysvec+18,	yyvstop+655,
Xyycrank+2643,	yysvec+18,	yyvstop+657,
Xyycrank+2656,	yysvec+18,	yyvstop+659,
Xyycrank+2666,	yysvec+18,	yyvstop+661,
Xyycrank+2669,	yysvec+18,	yyvstop+664,
Xyycrank+2679,	yysvec+18,	yyvstop+667,
Xyycrank+2688,	yysvec+18,	yyvstop+670,
Xyycrank+2708,	yysvec+18,	yyvstop+673,
Xyycrank+2694,	yysvec+18,	yyvstop+675,
Xyycrank+2698,	yysvec+18,	yyvstop+678,
Xyycrank+2701,	yysvec+18,	yyvstop+680,
Xyycrank+2703,	yysvec+18,	yyvstop+682,
Xyycrank+2713,	yysvec+18,	yyvstop+685,
Xyycrank+2722,	yysvec+18,	yyvstop+688,
Xyycrank+2727,	yysvec+18,	yyvstop+691,
Xyycrank+2732,	yysvec+18,	yyvstop+694,
Xyycrank+2734,	yysvec+18,	yyvstop+697,
Xyycrank+2736,	yysvec+18,	yyvstop+699,
Xyycrank+2741,	yysvec+18,	yyvstop+701,
Xyycrank+2746,	yysvec+18,	yyvstop+703,
Xyycrank+2755,	yysvec+18,	yyvstop+706,
Xyycrank+2760,	yysvec+18,	yyvstop+709,
Xyycrank+2786,	yysvec+18,	yyvstop+712,
Xyycrank+2774,	yysvec+18,	yyvstop+714,
Xyycrank+2788,	yysvec+18,	yyvstop+716,
Xyycrank+34,	0,		0,	
Xyycrank+-2814,	yysvec+39,	yyvstop+718,
Xyycrank+-2815,	yysvec+39,	yyvstop+721,
Xyycrank+-2820,	yysvec+39,	yyvstop+724,
Xyycrank+-2827,	yysvec+39,	yyvstop+727,
Xyycrank+-2828,	yysvec+39,	yyvstop+730,
Xyycrank+-2840,	yysvec+39,	yyvstop+733,
Xyycrank+-2852,	yysvec+39,	yyvstop+735,
Xyycrank+-2853,	yysvec+39,	yyvstop+737,
Xyycrank+-2868,	yysvec+39,	yyvstop+739,
Xyycrank+-2878,	yysvec+39,	yyvstop+742,
Xyycrank+-2890,	yysvec+39,	yyvstop+745,
Xyycrank+-2900,	yysvec+39,	yyvstop+748,
Xyycrank+-2957,	0,		yyvstop+751,
Xyycrank+-2903,	yysvec+39,	yyvstop+753,
Xyycrank+-2906,	yysvec+39,	yyvstop+756,
Xyycrank+-2932,	yysvec+39,	yyvstop+758,
Xyycrank+-2956,	yysvec+39,	yyvstop+760,
Xyycrank+-2969,	yysvec+39,	yyvstop+763,
Xyycrank+-2970,	yysvec+39,	yyvstop+766,
Xyycrank+-2981,	yysvec+39,	yyvstop+769,
Xyycrank+-2982,	yysvec+39,	yyvstop+772,
Xyycrank+-2994,	yysvec+39,	yyvstop+775,
Xyycrank+-2995,	yysvec+39,	yyvstop+777,
Xyycrank+-3006,	yysvec+39,	yyvstop+779,
Xyycrank+-3007,	yysvec+39,	yyvstop+781,
Xyycrank+-3020,	yysvec+39,	yyvstop+784,
Xyycrank+-3031,	yysvec+39,	yyvstop+787,
Xyycrank+-3076,	yysvec+330,	yyvstop+790,
Xyycrank+-3045,	yysvec+39,	yyvstop+792,
Xyycrank+-3071,	yysvec+39,	yyvstop+794,
Xyycrank+2811,	yysvec+18,	yyvstop+796,
Xyycrank+2844,	yysvec+18,	yyvstop+799,
Xyycrank+2890,	yysvec+18,	yyvstop+802,
Xyycrank+2910,	yysvec+18,	yyvstop+805,
Xyycrank+2953,	yysvec+18,	yyvstop+808,
Xyycrank+3037,	yysvec+18,	yyvstop+811,
Xyycrank+3072,	yysvec+18,	yyvstop+814,
Xyycrank+3075,	yysvec+18,	yyvstop+817,
Xyycrank+3081,	yysvec+18,	yyvstop+819,
Xyycrank+3083,	yysvec+18,	yyvstop+822,
Xyycrank+26,	0,		0,	
Xyycrank+-3106,	yysvec+39,	yyvstop+824,
Xyycrank+-3114,	yysvec+39,	yyvstop+827,
Xyycrank+-3126,	yysvec+39,	yyvstop+830,
Xyycrank+-3132,	yysvec+39,	yyvstop+833,
Xyycrank+-3139,	yysvec+39,	yyvstop+836,
Xyycrank+-3140,	yysvec+39,	yyvstop+839,
Xyycrank+-3146,	yysvec+39,	yyvstop+842,
Xyycrank+-3154,	yysvec+39,	yyvstop+845,
Xyycrank+-3164,	yysvec+39,	yyvstop+847,
Xyycrank+-3174,	yysvec+39,	yyvstop+850,
Xyycrank+3161,	yysvec+18,	yyvstop+852,
Xyycrank+42,	0,		0,	
Xyycrank+-3188,	yysvec+39,	yyvstop+855,
Xyycrank+41,	0,		0,	
Xyycrank+0,	0,		yyvstop+858,
X0,	0,	0};
Xstruct yywork *yytop = yycrank+3280;
Xstruct yysvf *yybgin = yysvec+1;
Xchar yymatch[] ={
X00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X011 ,01  ,'"' ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,'+' ,01  ,'+' ,01  ,01  ,
X'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
X'0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,'A' ,'A' ,'A' ,'A' ,'E' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,01  ,
X01  ,'A' ,'A' ,'A' ,'A' ,'E' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
X'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
X0};
Xchar yyextra[] ={
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0,0,0,0,0,0,0,0,
X0};
X/*	ncform	4.1	83/08/11	*/
X
Xint yylineno =1;
X# define YYU(x) x
X# define NLSTATE yyprevious=YYNEWLINE
Xchar yytext[YYLMAX];
Xstruct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
Xchar yysbuf[YYLMAX];
Xchar *yysptr = yysbuf;
Xint *yyfnd;
Xextern struct yysvf *yyestate;
Xint yyprevious = YYNEWLINE;
Xyylook(){
X	register struct yysvf *yystate, **lsp;
X	register struct yywork *yyt;
X	struct yysvf *yyz;
X	int yych;
X	struct yywork *yyr;
X# ifdef LEXDEBUG
X	int debug;
X# endif
X	char *yylastch;
X	/* start off machines */
X# ifdef LEXDEBUG
X	debug = 0;
X# endif
X	if (!yymorfg)
X		yylastch = yytext;
X	else {
X		yymorfg=0;
X		yylastch = yytext+yyleng;
X		}
X	for(;;){
X		lsp = yylstate;
X		yyestate = yystate = yybgin;
X		if (yyprevious==YYNEWLINE) yystate++;
X		for (;;){
X# ifdef LEXDEBUG
X			if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
X# endif
X			yyt = yystate->yystoff;
X			if(yyt == yycrank){		/* may not be any transitions */
X				yyz = yystate->yyother;
X				if(yyz == 0)break;
X				if(yyz->yystoff == yycrank)break;
X				}
X			*yylastch++ = yych = input();
X		tryagain:
X# ifdef LEXDEBUG
X			if(debug){
X				fprintf(yyout,"unsigned char ");
X				allprint(yych);
X				putchar('\n');
X				}
X# endif
X			yyr = yyt;
X			if ( (int)yyt > (int)yycrank){
X				yyt = yyr + yych;
X				if (yyt <= yytop && yyt->verify+yysvec == yystate){
X					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
X						{unput(*--yylastch);break;}
X					*lsp++ = yystate = yyt->advance+yysvec;
X					goto contin;
X					}
X				}
X# ifdef YYOPTIM
X			else if((int)yyt < (int)yycrank) {		/* r < yycrank */
X				yyt = yyr = yycrank+(yycrank-yyt);
X# ifdef LEXDEBUG
X				if(debug)fprintf(yyout,"compressed state\n");
X# endif
X				yyt = yyt + yych;
X				if(yyt <= yytop && yyt->verify+yysvec == yystate){
X					if(yyt->advance+yysvec == YYLERR)	/* error transitions */
X						{unput(*--yylastch);break;}
X					*lsp++ = yystate = yyt->advance+yysvec;
X					goto contin;
X					}
X				yyt = yyr + YYU(yymatch[yych]);
X# ifdef LEXDEBUG
X				if(debug){
X					fprintf(yyout,"try fall back character ");
X					allprint(YYU(yymatch[yych]));
X					putchar('\n');
X					}
X# endif
X				if(yyt <= yytop && yyt->verify+yysvec == yystate){
X					if(yyt->advance+yysvec == YYLERR)	/* error transition */
X						{unput(*--yylastch);break;}
X					*lsp++ = yystate = yyt->advance+yysvec;
X					goto contin;
X					}
X				}
X			if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
X# ifdef LEXDEBUG
X				if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
X# endif
X				goto tryagain;
X				}
X# endif
X			else
X				{unput(*--yylastch);break;}
X		contin:
X# ifdef LEXDEBUG
X			if(debug){
X				fprintf(yyout,"state %d char ",yystate-yysvec-1);
X				allprint(yych);
X				putchar('\n');
X				}
X# endif
X			;
X			}
X# ifdef LEXDEBUG
X		if(debug){
X			fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
X			allprint(yych);
X			putchar('\n');
X			}
X# endif
X		while (lsp-- > yylstate){
X			*yylastch-- = 0;
X			if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
X				yyolsp = lsp;
X				if(yyextra[*yyfnd]){		/* must backup */
X					while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
X						lsp--;
X						unput(*yylastch--);
X						}
X					}
X				yyprevious = YYU(*yylastch);
X				yylsp = lsp;
X				yyleng = yylastch-yytext+1;
X				yytext[yyleng] = 0;
X# ifdef LEXDEBUG
X				if(debug){
X					fprintf(yyout,"\nmatch ");
X					sprint(yytext);
X					fprintf(yyout," action %d\n",*yyfnd);
X					}
X# endif
X				return(*yyfnd++);
X				}
X			unput(*yylastch);
X			}
X		if (yytext[0] == 0  /* && feof(yyin) */)
X			{
X			yysptr=yysbuf;
X			return(0);
X			}
X		yyprevious = yytext[0] = input();
X		if (yyprevious>0)
X			output(yyprevious);
X		yylastch=yytext;
X# ifdef LEXDEBUG
X		if(debug)putchar('\n');
X# endif
X		}
X	}
Xyyback(p, m)
X	int *p;
X{
Xif (p==0) return(0);
Xwhile (*p)
X	{
X	if (*p++ == m)
X		return(1);
X	}
Xreturn(0);
X}
X	/* the following are only used in the lex library */
Xyyinput(){
X	return(input());
X	}
Xyyoutput(c)
X  int c; {
X	output(c);
X	}
Xyyunput(c)
X   int c; {
X	unput(c);
X	}
END-of-lex.yy.c
echo file: parse2.c
sed 's/^X//' >parse2.c << 'END-of-parse2.c'
X#include <math.h>
X#include <stdio.h>
X
X#include "data.h"
X#include "parseSupport.h"
X
Xvoid DisposeData(d)
XDATA_ARRAY	*d;
X{
X		if (d->temp) {
X			if (d->isFloat) 
X				FREE(d->fdata);
X			else
X				FREE(d->cdata);
X			}
X		FREE(d);
X}
X
Xvoid DisposeSemStack(s)  /* free the space */
Xunion sem_stack_type *s;
X{
X	if (s->data.kind == DATA_ID) 
X		DisposeData(s->data.value);
X	FREE(s);
X}
X
XMakeFloat(data)
X/* Change char data in DATA_ARRAY to float */
X/* return 0 on failure */
XDATA_ARRAY *data;
X{
Xregister float *fp;
Xregister unsigned char  *cp,*cend;
X
X	if (!(data->fdata = (float *)MALLOC(data->xdim * data->ydim 
X		    * sizeof(float)))) {
X		WriteErrMesg("Out of memory\n");
X		return(0);
X		}
X
X	cend = &( data->cdata[data->xdim * data->ydim - 1]);
X	fp = data->fdata;
X	cp = data->cdata;
X	while (cp < cend)
X		*fp++ = (float) *cp++;
X
X	data->isFloat = TRUE;
X	if (data->temp)
X		FREE(data->cdata);
X
X	return(1);
X
X} /* MakeFloat() */
X
XExecKnownFuncW1Const(tokenID,value)
Xint tokenID;
Xfloat value;
X{
Xunion	sem_stack_type *ret;
Xfloat	retValue;
Xdouble	d;
X
X	d = asin(0.5) / 30.0;
X
X	switch(tokenID) {
X	case TSIN:
X		retValue = (float) sin((double) value);
X		break;
X	case TCOS:
X		retValue = (float) cos((double) value);
X		break;
X	case TTAN:
X		retValue = (float) tan((double) value);
X		break;
X	case TASIN:
X		retValue = (float) asin((double) value);
X		break;
X	case TACOS:
X		retValue = (float) acos((double) value);
X		break;
X	case TATAN:
X		retValue = (float) atan((double) value);
X		break;
X	case TSINH:
X		retValue = (float) sinh((double) value);
X		break;
X	case TCOSH:
X		retValue = (float) cosh((double) value);
X		break;
X	case TTANH:
X		retValue = (float) tanh((double) value);
X		break;
X	case TSQRT:
X		retValue = (float) sqrt((double) value);
X		break;
X	case TLOG:
X		retValue = (float) log((double) value);
X		break;
X	case TLOG10:
X		retValue = (float) log10((double) value);
X		break;
X	case TEXP:
X		retValue = (float) exp((double) value);
X		break;
X	case TABS:
X		retValue = (float) abs((double) value);
X		break;
X	case TMEAN:
X		retValue = (float) value;
X		break;
X	case TMAX:
X		retValue = (float) value;
X		break;
X	case TMIN:
X		retValue = (float) value;
X		break;
X	case TSHL:
X		retValue = (float) value;
X		break;
X	case TSHR:
X		retValue = (float) value;
X		break;
X	case TSHU:
X		retValue = (float) value;
X		break;
X	case TSHD:
X		retValue = (float) value;
X		break;
X	case TDSIN:
X		retValue = (float) sin((double) value *d);
X		break;
X	case TDCOS:
X		retValue = (float) cos((double) value *d);
X		break;
X	case TDTAN:
X		retValue = (float) tan((double) value *d);
X		break;
X	case TDASIN:
X		retValue = (float) asin((double) value *d);
X		break;
X	case TDACOS:
X		retValue = (float) acos((double) value *d);
X		break;
X	case TDATAN:
X		retValue = (float) atan((double) value *d);
X		break;
X	case TDSINH:
X		retValue = (float) sinh((double) value *d);
X		break;
X	case TDCOSH:
X		retValue = (float) cosh((double) value *d);
X		break;
X	case TDTANH:
X		retValue = (float) tanh((double) value *d);
X		break;
X	case TDTOR:
X		retValue = (float) ((double) value *d);
X		break;
X	case TRTOD:
X		retValue = (float) ((double) value / d);
X		break;
X	case TPTS:
X		retValue = 1.0;
X		break;
X	case TCOLS:
X		retValue = 1.0;
X		break;
X	case TROWS:
X		retValue = 1.0;
X		break;
X	case TCOLRANGE:
X		retValue = 0.0;
X		break;
X	case TROWRANGE:
X		retValue = 0.0;
X		break;
X	case TCOLMEAN:
X		retValue = value;
X		break;
X	case TROWMEAN:
X		retValue = value;
X		break;
X	case TCOLSDEV:
X		retValue = value;
X		break;
X	case TROWSDEV:
X		retValue = value;
X		break;
X		
X	default:
X		printf("ExecKnownFuncW1Param: Unknown Func(internal err)\n");
X		retValue = 0.0;
X	};
X
X	ret=SS_New();
X	ret->float_const.kind = FLOAT_CONST_ID;
X	ret->float_const.value = retValue;
X	SS_Push(ret);
X
X} /* ExecKnownFuncW1Const() */
X
X
XExecKnownFuncW1Var(tokenID,paramString)
X/* return 0 on failure */
Xint tokenID;
Xchar *paramString;
X{
XDATA_ARRAY *data;
Xchar	buff[256];
Xregister	float *t,*p,*q;
Xregister	unsigned char *j,*k,l;
Xchar	returnFloat;	/* should I return a float or an array (retData)?*/
Xfloat	retValue;
XDATA_ARRAY *retData;
Xdouble d,y,z;
Xunion sem_stack_type *ret;
X
X    if (!(data = GetDataSet(paramString))) {
X	/* error getting data set */
X        returnFloat = TRUE;
X	retValue = 0.0;
X	errorDuringParsing = TRUE;
X	}
X    else {
X	
X        returnFloat = TRUE;
X	if (data->isFloat) {
X		p = data->fdata;
X		q = &(data->fdata[data->xdim * data->ydim -1]);
X		switch (tokenID) {
X			case TMEAN:
X				while (p < q)
X					d = d + (double) *p++;
X				retValue = (float) (d / 
X					(double) (data->xdim*data->ydim));
X				break;
X			case TMAX:
X				retValue = *p;
X				while (p++ < q) {
X					if (retValue < *p)
X						retValue = *p;
X					}
X				break;
X			case TMIN:
X				retValue = *p;
X				while (p++ < q) {
X					if (retValue > *p)
X						retValue = *p;
X					}
X				break;
X			case TPTS:
X				retValue = (float) (data->xdim * data->ydim);
X				break;
X			case TCOLS:
X				retValue = (float) data->xdim;
X				break;
X			case TROWS:
X				retValue = (float) data->ydim;
X				break;
X			default:
X        			returnFloat = FALSE;
X			};
X		}
X	else { /* it's a char data set */
X		j = data->cdata;
X		k = &(data->cdata[data->xdim * data->ydim -1]);
X		switch (tokenID) {
X			case TMEAN:
X				while (j < k)
X					d = d + (double) *j++;
X				retValue = (float) (d / 
X					(double) (data->xdim*data->ydim));
X				break;
X			case TMAX:
X				l = *j;
X				while (j++ < k) {
X					if (l < *j)
X						l = *j;
X					}
X				retValue = (float) l;
X				break;
X			case TMIN:
X				l = *p;
X				while (j++ < k) {
X					if (l > *j)
X						l = *j;
X					}
X				retValue = (float) l;
X				break;
X			default:
X        			returnFloat = FALSE;
X			};
X		} /*else*/
X		
X	if (!returnFloat) {
X		if (!data->isFloat) {
X			if (!MakeFloat(data)) {
X				returnFloat = TRUE;
X				retValue = 0.0;
X				errorDuringParsing = TRUE;
X				}
X			}
X		}
X
X	if (!returnFloat) 
X		if (!(retData = (DATA_ARRAY *) MALLOC(sizeof(DATA_ARRAY)))){
X			WriteErrMesg("Out of Memory\n");
X			returnFloat = TRUE;
X			retValue = 0.0;
X			errorDuringParsing = TRUE;
X			}
X
X	if (!returnFloat) 
X		if (!(retData->fdata = (float *) MALLOC(data->xdim
X					* data->ydim * sizeof(float)))) {
X			WriteErrMesg("Out of Memory\n");
X			returnFloat = TRUE;
X			retValue = 0.0;
X			errorDuringParsing = TRUE;
X			}
Xif (!returnFloat) {
X	retData->isFloat = TRUE;
X	retData->xdim = data->xdim;
X	retData->ydim = data->ydim;
X	retData->temp = TRUE;
X
X	y = log(10.0);
X	z = asin(0.5) / 30.0;
X	t = retData->fdata;
X	p = data->fdata;
X
X	q = &(p[data->xdim*data->ydim-1]);
X
X	switch(tokenID) {
X	case TSIN:
X                         {while (p < q)
X                              *t++ = (float)(sin((double)(*p++)));
X                           *t = (float)(sin((double)(*p)));
X			}
X		break;
X	case TCOS:
X                          {while (p < q)
X                              *t++ = (float)(cos((double)(*p++)));
X                          *t = (float)(cos((double)(*p)));
X                         }
X		break;
X	case TTAN:
X                          {while (p < q)
X                              *t++ = (float)(tan((double)(*p++)));
X                          *t = (float)(tan((double)(*p)));
X                         }
X		break;
X	case TASIN:
X                          {while (p < q)
X                              *t++ = (float)(asin((double)(*p++)));
X                           *t = (float)(asin((double)(*p)));
X                         }
X		break;
X	case TACOS:
X                          {while (p < q)
X                              *t++ = (float)(acos((double)(*p++)));
X                          *t = (float)(acos((double)(*p)));
X                         }
X		break;
X	case TATAN:
X                          {while (p < q)
X                              *t++ = (float)(atan((double)(*p++)));
X                          *t = (float)(atan((double)(*p)));
X                         }
X		break;
X	case TSINH:
X                        {while (p < q)
X                              *t++ = (float)(sinh((double)(*p++)));
X                           *t = (float)(sinh((double)(*p)));
X                         }
X		break;
X	case TCOSH:
X                          {while (p < q)
X                              *t++ = (float)(cosh((double)(*p++)));
X                          *t = (float)(cosh((double)(*p)));
X                         }
X		break;
X	case TTANH:
X                          {while (p < q)
X                              *t++ = (float)(tanh((double)(*p++)));
X                          *t = (float)(tanh((double)(*p)));
X                         }
X		break;
X	case TSQRT:
X                          {while (p < q)
X                              *t++ = (float)(sqrt((double)(*p++)));
X                          *t = (float)(sqrt((double)(*p)));
X                         }
X		break;
X	case TLOG:
X                          {while (p < q)
X                              *t++ = (float)(log((double)(*p++)));
X                          *t = (float)(log((double)(*p)));
X                         }
X		break;
X	case TLOG10:
X                         {while (p < q)
X                              *t++ = (float)(log((double)(*p++)) / y);
X                          *t = (float)(log((double)(*p)) / y);
X                         }
X		break;
X	case TEXP:
X                          {while (p < q)
X                              *t++ = (float)(exp((double)(*p++)));
X                          *t = (float)(exp((double)(*p)));
X                         }
X		break;
X	case TABS:
X                          {while (p < q)
X                              *t++ = (float)(abs((double)(*p++)));
X                          *t = (float)(abs((double)(*p)));
X                         }
X		break;
X	case TSHL:
X		(void) fn_shl(p,q,t,data->xdim);
X		break;
X	case TSHR:
X		(void) fn_shr(p,q,t,data->xdim);
X		break;
X	case TSHU:
X		(void) fn_shu(p,q,t,data->xdim);
X		break;
X	case TSHD:
X		(void) fn_shd(p,q,t,data->xdim);
X		break;
X	case TDSIN:
X                          {while (p < q)
X                              *t++ = (float)(sin((double)(*p++) * z));
X                           *t = (float)(sin((double)(*p) * z));
X                         }
X		break;
X	case TDCOS:
X                         {while (p < q)
X                              *t++ = (float)(cos((double)(*p++) * z));
X                          *t = (float)(cos((double)(*p) * z));
X                         }
X		break;
X	case TDTAN:
X                         {while (p < q)
X                              *t++ = (float)(tan((double)(*p++) * z));
X                          *t = (float)(tan((double)(*p) * z));
X                         }
X		break;
X	case TDASIN:
X                        {while (p < q)
X                              *t++ = (float)(asin((double)(*p++)) / z);
X                           *t = (float)(asin((double)(*p)) / z);
X                         }
X		break;
X	case TDACOS:
X                          {while (p < q)
X                              *t++ = (float)(acos((double)(*p++)) / z);
X                          *t = (float)(acos((double)(*p)) / z);
X                         }
X		break;
X	case TDATAN:
X                        {while (p < q)
X                              *t++ = (float)(atan((double)(*p++)) / z);
X                          *t = (float)(atan((double)(*p)) / z);
X                         }
X		break;
X	case TDSINH:
X                          {while (p < q)
X                              *t++ = (float)(sinh((double)(*p++) * z));
X                           *t = (float)(sinh((double)(*p) * z));
X                         }
X		break;
X	case TDCOSH:
X                       {while (p < q)
X                              *t++ = (float)(cosh((double)(*p++) * z));
X                          *t = (float)(cosh((double)(*p) * z));
X                         }
X		break;
X	case TDTANH:
X                          {while (p < q)
X                              *t++ = (float)(tanh((double)(*p++) * z));
X                          *t = (float)(tanh((double)(*p) * z));
X                         }
X		break;
X	case TDTOR:
X                         {while (p < q)
X                              *t++ = (float)((double)(*p++) * z);
X                          *t = (float)((double)(*p) * z);
X                         }
X		break;
X	case TRTOD:
X                        {while (p < q)
X                              *t++ = (float)((double)(*p++) / z);
X                          *t = (float)((double)(*p) / z);
X                         }
X		break;
X	default:
X		printf("ExecKnownFuncW1Param: Unknown Func(internal err)\n");
X		}
X	}; 
X    } /* if (!returnFloat) */
X
X	ret=SS_New();
X	if (returnFloat) {
X		ret->float_const.kind = FLOAT_CONST_ID;
X		ret->float_const.value = retValue;
X		}
X	else {
X		ret->float_const.kind = DATA_ID;
X		ret->data.value = retData;
X		}
X	SS_Push(ret);
X	return(1); /* success */
X	
X}
X
Xvoid PutErrorValueOnStack()
X{
Xunion sem_stack_type *ret;
X
X	ret=SS_New();
X	ret->float_const.kind = FLOAT_CONST_ID;
X	ret->float_const.value = 0.0;
X	SS_Push(ret);
X}
X
XIsItASingleParamFunc(tokenID)
Xint	tokenID;
X{
Xchar uhuh;
X
X	uhuh= FALSE;
X	switch(tokenID) {
X		case TSIN:
X		case TCOS:
X		case TTAN:
X		case TASIN:
X		case TACOS:
X		case TATAN:
X		case TSINH:
X		case TCOSH:
X		case TTANH:
X		case TDSIN:
X		case TDCOS:
X		case TDTAN:
X		case TDASIN:
X		case TDACOS:
X		case TDATAN:
X		case TDSINH:
X		case TDCOSH:
X		case TDTANH:
X		case TDTOR:
X		case TRTOD:
X		case TSQRT:
X		case TLOG:
X		case TLOG10:
X		case TEXP:
X		case TABS:
X		case TMEAN:
X		case TMAX:
X		case TMIN:
X		case TSHL:
X		case TSHR:
X		case TSHU:
X		case TSHD:
X			uhuh = TRUE;
X			break;
X		default:
X			break;
X		};
X	return(uhuh);
X}
X
XExecKnownFunction(tokenID,numParams)
X/* executes function specified by tokenID using numParams number of
X * parameters.  The parameters are stored on the stack.
X * they should be removed before this returns.
X * answer should be stored on the stack.
X */
Xint tokenID;
Xint numParams;
X{
Xint	x;
Xunion sem_stack_type *param1;
Xchar	buff[256];
X
X
X	if (numParams == 1) {
X		param1 = SS_Pop();
X		if (!IsItASingleParamFunc(tokenID)) {
X			sprintf(buff,"incorrect number of parameters\n");
X			WriteErrMesg(buff);
X			errorDuringParsing = TRUE;
X			PutErrorValueOnStack();
X			}
X		if (param1->float_const.kind == FLOAT_CONST_ID) {
X		    ExecKnownFuncW1Const(tokenID,param1->float_const.value);
X		    }
X		else {
X		    ExecKnownFuncW1Var(tokenID,param1->var.value);
X		    }
X		}
X	else {
X		switch(tokenID) {
X		    case TREXEC:
X			if (!ExecuteRExecProc(numParams)) {
X				errorDuringParsing = TRUE;
X				PutErrorValueOnStack();
X				}
X			break;
X		    case TREMOTE:
X			SS_Push(addressVar);
X			if (!ExecuteRemoteProc(numParams+1)) {
X				errorDuringParsing = TRUE;
X				PutErrorValueOnStack();
X				}
X			break;
X		    default:
X			for(x=0; x<numParams; x++) /* clear params on stack */
X			    (void) SS_Pop();
X			if (!IsItASingleParamFunc(tokenID)) {
X			    sprintf(buff,"incorrect number of parameters\n");
X			    WriteErrMesg(buff);
X			    errorDuringParsing = TRUE;
X			    PutErrorValueOnStack();
X			    }
X			else {
X			    printf("Unknown function");
X			    printf("params cleared\n");
X			    PutErrorValueOnStack();
X			    errorDuringParsing = TRUE;
X			    }
X		    }/*switch*/
X		}/*else*/
X
X}
X
X
X
X
XExecUnknownFunction(funcString,numParams)
X/* Executes function specified in string using numParams number of
X * parameters.  The parameters are stored on the stack.
X * they should be removed before this returns.
X * answer should be stored on the stack.
X */
Xchar *funcString;
Xint  numParams;
X{
Xchar buff[256];
X		int x;
X		fprintf(buff,"Unknown function: %s()\n",funcString);
X		WriteErrMesg(buff);
X		for(x=0; x<numParams; x++) /* clear params on stack */
X			(void) SS_Pop();
X		WriteErrMesg("params cleared\n");
X	{
X	/* return 0 */
X	union sem_stack_type *ret;
X	ret=SS_New();
X	ret->float_const.kind = FLOAT_CONST_ID;
X	ret->float_const.value = 0.0;
X	SS_Push(ret);
X	}
X
X}
X
X
XExecAddOp(addOp) 
X/* perform add operation (addOp) on values on stack and then puts answer
X   on stack */
Xint addOp;
X{
Xunion sem_stack_type *op1,*op2,*tmp;
XDATA_ARRAY	*data,*data2;
XDATA_ARRAY	*retData;
Xfloat		addValue;
Xregister	float 		*fpTarget,*fpSource,*fpSource2,*fend; 
Xchar		caddValue;
Xregister	char		*cpTarget,*cpSource,*cpSource2,*cend; 
Xchar		arrayFirst;
Xchar		dimDontMatch;
Xint		xdim,ydim;
Xregister	int x,y;
X
X	op1 = SS_Pop();
X	op2 = SS_Pop();
X
X	if ((op1->float_const.kind == FLOAT_CONST_ID)
X	    && (op2->float_const.kind == FLOAT_CONST_ID)) {
X		if (addOp == VADD)
X			op1->float_const.value = op2->float_const.value
X				+ op1->float_const.value;
X		else if (addOp == VSUB) /* VSUB */
X			op1->float_const.value = op2->float_const.value
X				- op1->float_const.value;
X			else
X				printf("ExecAddOp(): internal error\n");
X		SS_Push(op1);
X		DisposeSemStack(op2);
X		return;
X		}
X
X	else {
X		if (((op1->var.kind == VAR_ID)|| (op1->data.kind == DATA_ID))
X            	    ^((op2->var.kind == VAR_ID)||(op2->data.kind == DATA_ID))){
X		    /* one but not both is an array */
X		    if (((op2->var.kind==VAR_ID)||(op2->var.kind==DATA_ID))){
X			tmp = op1;
X			op1 = op2;
X			op2 = tmp;
X			arrayFirst = TRUE;
X			}
X		    else{
X			arrayFirst = FALSE;
X			}
X		    if (op1->var.kind==VAR_ID) {
X			    if (!(data = GetDataSet(op1->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X			    }
X		    else 
X			data = op1->data.value;
X
X                    if(!(retData=(DATA_ARRAY *)MALLOC(sizeof(DATA_ARRAY)))){
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X
X		    retData->xdim = data->xdim;
X		    retData->ydim = data->ydim;
X		    retData->temp = TRUE;
X			
X		    if (data->isFloat){
X		    	if (!(retData->fdata = (float *) MALLOC(data->xdim
X					* data->ydim * sizeof(float)))) {
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X		        retData->isFloat = TRUE;
X
X			addValue = op2->float_const.value;
X			fpTarget = retData->fdata;
X			fpSource = data->fdata;
X			fend = &(fpSource[data->xdim*data->ydim]); /*end+1*/
X
X			if (arrayFirst) {
X				if (addOp == VSUB)
X                        	    while (fpSource < fend)
X					*fpTarget++ = *fpSource++ - addValue;
X				else
X                        	    while (fpSource < fend)
X					*fpTarget++ = *fpSource++ + addValue;
X				}
X			else {
X				if (addOp == VSUB)
X                        	    while (fpSource < fend)
X					*fpTarget++ = addValue - *fpSource++;
X				else
X                        	    while (fpSource < fend)
X					*fpTarget++ = addValue + *fpSource++;
X				}
X			}
X		    else { /* it's a char dataset */
X		    	if (!(retData->cdata=(unsigned char *)MALLOC(data->xdim
X					* data->ydim * sizeof(char)))) {
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X		        retData->isFloat = FALSE;
X
X			caddValue = (char) op2->float_const.value;
X			cpTarget = (char *) retData->cdata;
X			cpSource = (char *) data->cdata;
X			cend = &(cpSource[data->xdim*data->ydim]); /*end+1*/
X
X			if (arrayFirst) {
X				if (addOp == VSUB)
X                        	    while (cpSource < cend)
X					*cpTarget++ =  *cpSource++ - caddValue;
X				else
X                        	    while (cpSource < cend)
X					*cpTarget++ = *cpSource++ + caddValue;
X				}
X			else {
X				if (addOp == VSUB)
X                        	    while (cpSource < cend)
X					*cpTarget++ = caddValue - *cpSource++;
X				else
X                        	    while (cpSource < cend)
X					*cpTarget++ = caddValue + *cpSource++;
X				}
X			} /* else */
X
X			op2->data.kind = DATA_ID;	
X			op2->data.value = retData;
X			SS_Push(op2);
X			DisposeSemStack(op1);
X
X		    } /* if one but not both*/
X		else { /* Both datasets are arrays */
X
X
X
X                  if (((op1->var.kind == VAR_ID)&&(op1->data.kind == DATA_ID))
X                    ^((op2->var.kind == VAR_ID)&&(op2->data.kind == DATA_ID))){
X			WriteErrMesg("addop: Internal error during parsing\n");
X			errorDuringParsing = TRUE;
X			op1->float_const.kind = FLOAT_CONST_ID;
X			op1->float_const.value = 0.0;
X			SS_Push(op1);
X			}
X		  else { /*not error */
X                    if (op1->var.kind==VAR_ID) {
X                            if (!(data = GetDataSet(op1->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op1->float_const.value = 0.0;
X				SS_Push(op1);
X				return;
X				}
X			    }
X		    else
X			    data = op1->data.value;
X
X                    if (op2->var.kind==VAR_ID) {
X                            if (!(data2 = GetDataSet(op2->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X			    }
X		    else
X			    data2 = op2->data.value;
X
X		    if ((data->xdim != data2->xdim) || 
X			(data->ydim != data2->ydim)) {
X			WriteErrMesg("Warning dimensions of data sets do not match\n");
X			xdim=(data->xdim > data2->xdim)?data2->xdim:data->xdim;
X			ydim=(data->ydim > data2->ydim)?data2->ydim:data->ydim;
X			}
X		    else {
X			xdim = data->xdim;
X			ydim = data->ydim;
X			}
X
X                    if(!(retData=(DATA_ARRAY *)MALLOC(sizeof(DATA_ARRAY)))){
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                    retData->xdim = xdim;
X                    retData->ydim = ydim;
X                    retData->temp = TRUE;
X
X		    /* Make sure they are compatible types */
X		    if (data->isFloat ^ data2->isFloat) {
X			char succeed;
X			if (data->isFloat)
X				succeed = MakeFloat(data2);
X			else
X				succeed = MakeFloat(data);
X
X			if (!succeed) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X			}
X
X                    if (data->isFloat){
X                        if (!(retData->fdata = (float *) MALLOC(xdim
X                                        * ydim * sizeof(float)))) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                        retData->isFloat = TRUE;
X
X			if (addOp == VSUB) {
X				fpSource = data->fdata;
X				fpSource2 = data2->fdata;
X				fpTarget = retData->fdata;
X				for (y=0; y < ydim; y++) {
X				    fpSource = &(data->fdata[y*data->xdim]);
X				    fpSource2 = &(data2->fdata[y*data2->xdim]);
X				    fpTarget = &(retData->fdata[y*xdim]);
X					
X				    for (x=0; x < xdim; x++)
X				      *fpTarget++ = *fpSource2++ - *fpSource++;
X				    }
X				}
X			else { /* VADD */
X				fpSource = data->fdata;
X				fpSource2 = data2->fdata;
X				fpTarget = retData->fdata;
X				for (y=0; y < ydim; y++) {
X				    fpSource = &(data->fdata[y*data->xdim]);
X				    fpSource2 = &(data2->fdata[y*data2->xdim]);
X				    fpTarget = &(retData->fdata[y*xdim]);
X					
X				    for(x=0; x < xdim; x++)
X				      *fpTarget++ = *fpSource2++ + *fpSource++;
X				    }
X			       } /* else VADD*/
X			} /* if float */
X		    else { /* it's char */
X                        if (!(retData->cdata = (unsigned char *) MALLOC(xdim
X                                        * ydim * sizeof(char)))) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                        retData->isFloat = FALSE;
X
X			if (addOp == VSUB) {
X				cpSource = (char *) data->cdata;
X				cpSource2 = (char *) data2->cdata;
X				cpTarget = (char *) retData->cdata;
X				for (y=0; y < ydim; y++) {
X				    cpSource = (char *) 
X						&(data->cdata[y*data->xdim]);
X				    cpSource2=(char *) 
X						&(data2->cdata[y*data2->xdim]);
X				    cpTarget=(char *)&(retData->cdata[y*xdim]);
X					
X				    for (x=0; x < xdim; x++)
X				      *cpTarget++ = *cpSource2++ - *cpSource++;
X				    }
X				}
X			else {
X				cpSource = (char *) data->cdata;
X				cpSource2 = (char *) data2->cdata;
X				cpTarget = (char *) retData->cdata;
X				for (y=0; y < ydim; y++) {
X				    cpSource = (char *) 
X						&(data->cdata[y*data->xdim]);
X				    cpSource2=(char *) 
X						&(data2->cdata[y*data2->xdim]);
X				    cpTarget=(char *)&(retData->cdata[y*xdim]);
X					
X				    for(x=0; x < xdim; x++)
X				      *cpTarget++ = *cpSource2++ + *cpSource++;
X				    }
X			        } /* else VSUB*/
X			} /* else char */
X			DisposeSemStack(op1);
X			DisposeData(op2->data.value);
X			op2->data.kind = DATA_ID;	
X			op2->data.value = retData;
X			SS_Push(op2);
X		    }	/* else not error */
X		} /* if one float & var else */
X	} /* if two floats else */
X} /* ExecAddOp() */
X
X
X
X
X
XExecMulOp(mulOp) 
X/* perform mult operation (mulOp) on values on stack and then puts answer
X   on stack */
Xint mulOp;
X{
Xunion sem_stack_type *op1,*op2,*tmp;
XDATA_ARRAY	*data,*data2;
XDATA_ARRAY	*retData;
Xfloat		mulValue;
Xregister	float 		*fpTarget,*fpSource,*fpSource2,*fend; 
Xchar		cmulValue;
Xregister	char		*cpTarget,*cpSource,*cpSource2,*cend; 
Xchar		arrayFirst;
Xchar		dimDontMatch;
Xint		xdim,ydim;
Xregister	int x,y;
X
X	op1 = SS_Pop();
X	op2 = SS_Pop();
X
X	if ((op1->float_const.kind == FLOAT_CONST_ID)
X	    && (op2->float_const.kind == FLOAT_CONST_ID)) {
X		if (mulOp == VMUL)
X			op1->float_const.value = op2->float_const.value
X				* op1->float_const.value;
X		else 
X		    if (mulOp == VDIV) 
X			op1->float_const.value = op2->float_const.value
X					/ op1->float_const.value;
X		    else
X				printf("ExecMulOp(): internal error\n");
X		SS_Push(op1);
X		DisposeSemStack(op2);
X		return;
X		}
X
X	else {
X		if (((op1->var.kind == VAR_ID)|| (op1->data.kind == DATA_ID))
X            	    ^((op2->var.kind == VAR_ID)||(op2->data.kind == DATA_ID))){
X		    /* one but not both is an array */
X		    if (((op2->var.kind==VAR_ID)||(op2->var.kind==DATA_ID))){
X			tmp = op1;
X			op1 = op2;
X			op2 = tmp;
X			arrayFirst = TRUE;
X			}
X		    else{
X			arrayFirst = FALSE;
X			}
X		    if (op1->var.kind==VAR_ID) {
X			    if (!(data = GetDataSet(op1->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X			    }
X		    else 
X			data = op1->data.value;
X
X                    if(!(retData=(DATA_ARRAY *)MALLOC(sizeof(DATA_ARRAY)))){
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X
X		    retData->xdim = data->xdim;
X		    retData->ydim = data->ydim;
X		    retData->temp = TRUE;
X			
X		    if (data->isFloat){
X		    	if (!(retData->fdata = (float *) MALLOC(data->xdim
X					* data->ydim * sizeof(float)))) {
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X		        retData->isFloat = TRUE;
X
X			mulValue = op2->float_const.value;
X			fpTarget = retData->fdata;
X			fpSource = data->fdata;
X			fend = &(fpSource[data->xdim*data->ydim]); /*end+1*/
X
X			if (arrayFirst) {
X				if (mulOp == VMUL)
X                        	    while (fpSource < fend)
X					*fpTarget++ = *fpSource++ * mulValue;
X				else 
X                        	    while (fpSource < fend) 
X					*fpTarget++ = *fpSource++ / mulValue;
X				}
X			else {
X				if (mulOp == VMUL)
X                        	    while (fpSource < fend)
X					*fpTarget++ = mulValue * *fpSource++;
X				else
X                        	    while (fpSource < fend)
X					*fpTarget++ = mulValue / *fpSource++;
X				}
X			}
X		    else { /* it's a char dataset */
X		    	if (!(retData->cdata=(unsigned char *)MALLOC(data->xdim
X					* data->ydim * sizeof(char)))) {
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X		        retData->isFloat = FALSE;
X
X			cmulValue = (char) op2->float_const.value;
X			cpTarget = (char *) retData->cdata;
X			cpSource = (char *) data->cdata;
X			cend = &(cpSource[data->xdim*data->ydim]); /*end+1*/
X
X			if (arrayFirst) {
X				if (mulOp == VMUL)
X                        	    while (cpSource < cend)
X					*cpTarget++ =  *cpSource++ * cmulValue;
X				else
X                        	    while (cpSource < cend)
X					*cpTarget++ = *cpSource++ / cmulValue;
X				}
X			else {
X				if (mulOp == VMUL)
X                        	    while (cpSource < cend)
X					*cpTarget++ = cmulValue * *cpSource++;
X				else
X                        	    while (cpSource < cend)
X					*cpTarget++ = cmulValue / *cpSource++;
X				}
X			} /* else */
X
X			op2->data.kind = DATA_ID;	
X			op2->data.value = retData;
X			SS_Push(op2);
X			DisposeSemStack(op1);
X
X		    } /* if one but not both*/
X		else { /* Both datasets are arrays */
X
X
X
X                  if (((op1->var.kind == VAR_ID)&&(op1->data.kind == DATA_ID))
X                    ^((op2->var.kind == VAR_ID)&&(op2->data.kind == DATA_ID))){
X			WriteErrMesg("mulop: Internal error during parsing\n");
X			errorDuringParsing = TRUE;
X			op1->float_const.kind = FLOAT_CONST_ID;
X			op1->float_const.value = 0.0;
X			SS_Push(op1);
X			}
X		  else { /*not error */
X                    if (op1->var.kind==VAR_ID) {
X                            if (!(data = GetDataSet(op1->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op1->float_const.value = 0.0;
X				SS_Push(op1);
X				return;
X				}
X			    }
X		    else
X			    data = op1->data.value;
X
X                    if (op2->var.kind==VAR_ID) {
X                            if (!(data2 = GetDataSet(op2->var.value))) {
X				/* error getting data set */
X				errorDuringParsing = TRUE;
X				op2->float_const.value = 0.0;
X				SS_Push(op2);
X				return;
X				}
X			    }
X		    else
X			    data2 = op2->data.value;
X
X		    if ((data->xdim != data2->xdim) || 
X			(data->ydim != data2->ydim)) {
X			WriteErrMesg("Warning dimensions of data sets do not match\n");
X			xdim=(data->xdim > data2->xdim)?data2->xdim:data->xdim;
X			ydim=(data->ydim > data2->ydim)?data2->ydim:data->ydim;
X			}
X		    else {
X			xdim = data->xdim;
X			ydim = data->ydim;
X			}
X
X                    if(!(retData=(DATA_ARRAY *)MALLOC(sizeof(DATA_ARRAY)))){
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                    retData->xdim = xdim;
X                    retData->ydim = ydim;
X                    retData->temp = TRUE;
X
X		    /* Make sure they are compatible types */
X		    if (data->isFloat ^ data2->isFloat) {
X			char succeed;
X			if (data->isFloat)
X				succeed = MakeFloat(data2);
X			else
X				succeed = MakeFloat(data);
X
X			if (!succeed) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X			}
X
X                    if (data->isFloat){
X                        if (!(retData->fdata = (float *) MALLOC(xdim
X                                        * ydim * sizeof(float)))) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                        retData->isFloat = TRUE;
X
X			if (mulOp == VMUL) {
X				fpSource = data->fdata;
X				fpSource2 = data2->fdata;
X				fpTarget = retData->fdata;
X				for (y=0; y < ydim; y++) {
X				    fpSource = &(data->fdata[y*data->xdim]);
X				    fpSource2 = &(data2->fdata[y*data2->xdim]);
X				    fpTarget = &(retData->fdata[y*xdim]);
X					
X				    for (x=0; x < xdim; x++)
X				      *fpTarget++ = *fpSource2++ * *fpSource++;
X				    }
X				}
X			else { /* VDIV */
X				fpSource = data->fdata;
X				fpSource2 = data2->fdata;
X				fpTarget = retData->fdata;
X				for (y=0; y < ydim; y++) {
X				    fpSource = &(data->fdata[y*data->xdim]);
X				    fpSource2 = &(data2->fdata[y*data2->xdim]);
X				    fpTarget = &(retData->fdata[y*xdim]);
X					
X				    for(x=0; x < xdim; x++)
X				      *fpTarget++ = *fpSource2++ / *fpSource++;
X				    }
X			       } /* else VDIV*/
X			} /* if float */
X		    else { /* it's char */
X                        if (!(retData->cdata = (unsigned char *) MALLOC(xdim
X                                        * ydim * sizeof(char)))) {
X                                WriteErrMesg("Out of Memory\n");
X                                errorDuringParsing = TRUE;
X                                op2->float_const.value = 0.0;
X                                SS_Push(op2);
X                                return;
X                                }
X                        retData->isFloat = FALSE;
X
X			if (mulOp == VMUL) {
X				cpSource = (char *) data->cdata;
X				cpSource2 = (char *) data2->cdata;
X				cpTarget = (char *) retData->cdata;
X				for (y=0; y < ydim; y++) {
X				    cpSource = (char *) 
X						&(data->cdata[y*data->xdim]);
X				    cpSource2=(char *) 
X						&(data2->cdata[y*data2->xdim]);
X				    cpTarget=(char *)&(retData->cdata[y*xdim]);
X					
X				    for (x=0; x < xdim; x++)
X				      *cpTarget++ = *cpSource2++ * *cpSource++;
X				    }
X				}
X			else {
X				cpSource = (char *) data->cdata;
X				cpSource2 = (char *) data2->cdata;
X				cpTarget = (char *) retData->cdata;
X				for (y=0; y < ydim; y++) {
X				    cpSource = (char *) 
X						&(data->cdata[y*data->xdim]);
X				    cpSource2=(char *) 
X						&(data2->cdata[y*data2->xdim]);
X				    cpTarget=(char *)&(retData->cdata[y*xdim]);
X					
X				    for(x=0; x < xdim; x++)
X				      *cpTarget++ = *cpSource2++ / *cpSource++;
X				    }
X			        } /* else VDIV*/
X			} /* else char */
X			DisposeSemStack(op1);
X			DisposeData(op2->data.value);
X			op2->data.kind = DATA_ID;	
X			op2->data.value = retData;
X			SS_Push(op2);
X		    }	/* else not error */
X		} /* if one float & var else */
X	} /* if two floats else */
X} /* ExecMulOp() */
X
X
X
X
XExecUnaryMinus(addOp) 
Xint addOp;
X{
Xunion sem_stack_type *op1;
XDATA_ARRAY *data,*retData;
Xregister float	*fp,*fvp;
Xint	end;
Xregister int x;
X
X	op1 = SS_Pop();
X
X	if (op1->float_const.kind == FLOAT_CONST_ID) {
X		if (addOp == VSUB)
X			op1->float_const.value = - op1->float_const.value;
X		SS_Push(op1);
X		}
X	else {
X	    /* it's an array */
X	    if (addOp == VSUB) {
X
X		if (op1->var.kind==VAR_ID) {
X		    if (!(data = GetDataSet(op1->var.value))) {
X			/* error getting data set */
X			errorDuringParsing = TRUE;
X			PutErrorValueOnStack();
X			return;
X			}
X		    }
X		else  
X		    if (op1->var.kind==DATA_ID) 
X			data = op1->data.value;
X		    else {
X			WriteErrMesg("Internal error caught at Unary minus\n");
X			PutErrorValueOnStack();
X			return;
X			}
X			
X			
X
X		if (! data->isFloat) 
X			MakeFloat(data);
X
X/**/ printf("about to apply unary minus, xdim=%d,ydim=%d\n",data->xdim,data->ydim);
X		if (data->temp)
X		    retData = data;
X		else {
X                    if(!(retData=(DATA_ARRAY *)MALLOC(sizeof(DATA_ARRAY)))){
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				PutErrorValueOnStack();
X				return;
X				}
X
X		    retData->xdim = data->xdim;
X		    retData->ydim = data->ydim;
X		    retData->temp = TRUE;
X			
X		    if (!(retData->fdata = (float *) MALLOC(data->xdim
X					* data->ydim * sizeof(float)))) {
X				WriteErrMesg("Out of Memory\n");
X				errorDuringParsing = TRUE;
X				PutErrorValueOnStack();
X				return;
X				}
X		    retData->isFloat = TRUE;
X		    }
X
X		end = data->xdim * data->ydim;
X		fp = data->fdata;
X		fvp = retData->fdata;
X		for (x = 0; x < end; x++) 
X			*fvp++ = - *fp++;
X
X		op1->data.value = retData;
X		op1->data.kind = DATA_ID;	
X		SS_Push(op1);
X/**/ printf("Just applied unary minus, xdim=%d,ydim=%d\n",retData->xdim,retData->ydim);
X		}/* if addOp == VSUB */
X	    } /* else it's an array */
X} /* ExecUnaryMinus() */
X
END-of-parse2.c
echo file: DScope.h
sed 's/^X//' >DScope.h << 'END-of-DScope.h'
X/**************************************************************************/
X/*  NCSA DataScope
X*   An experiment with real numbers.
X*   by Tim Krauskopf
X*   
X*   National Center for Supercomputing Applications
X*   University of Illinois at Urbana-Champaign
X*   605 E. Springfield Ave.
X*   Champaign, IL  61820
X*
X*   email:  		softdev@ncsa.uiuc.edu
X*   bug reports:	bugs@ncsa.uiuc.edu
X*   server:         ftp.ncsa.uiuc.edu  (128.174.20.50)
X*
X*   version                      comments
X*   -----------                -------------
X*   1.0 TKK  December 1988
X*   1.1 TKK  May 1989       -- new polar, computations, interpolation
X*							-- computational routines by Mark Stupar
X*/
X
X/*
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X	Data structure for external functions.
X	
X	The field "kind" determines whether the array contains a valid
X	cval or a valid set of ncols,nrows,rows,cols,vals.
X	
X	External functions are called as:
X	your_fn(lft,rgt,answer)
X	scope_array *lft,			 left parameter 
X				*rgt,			 right parameter 
X				*answer;		 place to put the answer 
X				
X	Answer will always contain pre-allocated space for an array of
X	resulting values, including the rows and cols arrays.  You may
X	change any value (and should) in the rows,cols and vals arrays.
X	Do not change any values in the lft or rgt storage.
X	
X	If your routine returns only a constant, set kind == DS_CONSTANT
X	and put the answer in cval.
X	
X	DON'T allocate anything you don't free yourself.
X	FREE everything you allocate.
X	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X*/
X
X#define DS_ERROR -1
X#define DS_CONSTANT 0
X#define DS_ARRAY 1
X
Xtypedef struct 
X		{float	
X				cval,	/* constant value when we are carrying a constant */
X				*rows,	/* row labels, scale values:  count = ncols   */
X				*cols,	/* col labels, scale values:  count = nrows   */
X				*vals;	/* data values in the array, if there is an array 
X							size = ncols*nrows                        */
X		
X		 int	ncols,
X				nrows;	/* dimensions of the array */
X	
X		 char	
X				kind;	/* ERROR, CONSTANT, ARRAY */
X		} 
X		
X		scope_array;
X
END-of-DScope.h
echo file: animate.h
sed 's/^X//' >animate.h << 'END-of-animate.h'
X
X#define A_STOP	0
X#define	A_CFOR	1
X#define	A_CREV	2
X#define	DSTRINGSIZE	10		/* dialog string size */
X
Xstruct	ANIMATION {
X	Widget	topLevel;
X	Widget	composite;
X	Widget	pal_win;
X	Widget	slidebar;		/* valuator widget */
X
X	char	*name;
X	int	xdim,ydim;
X	char	isHDF;
X	char	isFloat;
X	char	*directory;
X	char	**files;
X	int	frameNum;	/* which frame are we on? */
X	int	numFrames;	/* number of frames */
X	int	numFiles;
X	char	inMemory;	/* images will be stored in pixmaps */
X	int	*frameIndex;	/* only used with HDF single file animations*/
X
X	unsigned char	*dataCube;	/* animation data is in this cube */
X
X	char	ctrl_showing;	/* is animate control window showing? */
X
X	unsigned char *raster;
X	unsigned char *expRaster;	/* expanded raster */
X	unsigned char isExpanded;	/* is raster expanded */
X	XImage	*image;
X	Pixmap	*pixmaps;
X
X	char	hasPalette;
X	XColor	*palette;	/* XColor[256] (colors for window)*/
X	Colormap cmap;
X	char	lockcmap;
X
X	char	status;	
X	int	skip;		/* what is the skip factor */
X	int	delay;
X	char	repeat;		/* should repeat */
X
X	Widget	bcrev;	/*button continuous reverse*/
X	Widget	bsrev;	/*button single reverse*/
X	Widget	bstop;	/*button stop */
X	Widget	bsfor;	/*button single forward */
X	Widget	bcfor;	/*button continous forward */
X	Widget	dFrame;
X	char	dFrameString[DSTRINGSIZE];
X	Widget	dSkip;
X	char	dSkipString[DSTRINGSIZE];
X	Widget	dDelay;
X	char	dDelayString[DSTRINGSIZE];
X
X	Widget	awin;	/* animation window */
X	GC	awinGC;
X
X	Widget	topQbox;	/* top widget for question box */
X
X
X	struct ANIMATION *next;
X	struct ANIMATION *prev;
X};
X
END-of-animate.h
echo file: buttons.h
sed 's/^X//' >buttons.h << 'END-of-buttons.h'
Xextern	Widget	b[];		/* Butttons (b[]) are defined in main.c */
X
X#define	CTRL_IMAGE	0
X#define	CTRL_PALETTE	1
X#define	CTRL_ANIMATE	2
X#define IMAGE_DONE	3
X#define CTRL_CALC	4
X#define	CTRL_QUIT	5
X#define IMAGE_CART	6
X#define IMAGE_POLAR	7
X#define IMAGE_DATA	8
X#define IMAGE_GRAPH	9
X#define	IMAGE_CDONE	10
X#define IMAGE_PDONE	11
X#define PAL_LOAD	12
X#define PAL_FIDDLE	13
X#define	PAL_INVERT	14
X#define	PAL_ROTATE	15
X#define PAL_T_ROTATE	16
X#define PAL_SAVE	17
X#define	PAL_DONE	18
X#define	FILE_HDF	19
X#define FILE_RASTER	20
X#define FILE_SUNRASTER	21
X#define	FILE_DONE	22
X#define	CTRL_NOTEBOOK	23
X#define IMAGE_W_DONE	24
X#define PAL_CYAN	25
X#define PAL_MAGENTA	26
X#define PAL_YELLOW	27
X#define PAL_HUE		28
X#define	PAL_VALUE	29
X#define	PAL_SATURATION	30
X#define PAL_RED		31
X#define	PAL_BLUE	32
X#define PAL_GREEN	33
X#define PAL_PCYAN	34
X#define PAL_PMAGENTA	35
X#define PAL_PYELLOW	36
X#define PAL_PHUE	37
X#define	PAL_PVALUE	38
X#define	PAL_PSATURATION	39
X#define PAL_PRED	40
X#define	PAL_PBLUE	41
X#define PAL_PGREEN	42
X#define	PAL_EVAL	43
X#define	PAL_RESET	44
X#define	PAL_SMOOTH	45
END-of-buttons.h
echo file: data.h
sed 's/^X//' >data.h << 'END-of-data.h'
X#ifndef __DATA_ARRAY__
X
Xtypedef struct {
X	int	xdim,ydim;
X	char	temp;		/* Am I a temporary answer? */
X	char	isFloat;
X	float	*fdata;
X	unsigned char	*cdata;
X	} DATA_ARRAY;
X
X#define __DATA_ARRAY__
X
X#endif
END-of-data.h
echo file: dataObject.h
sed 's/^X//' >dataObject.h << 'END-of-dataObject.h'
X#include "types.h"
X
X#ifndef VOID_PTR
X#define	VOID_PTR	char *
X#endif
X
Xtypedef struct {
X		Type	type;
X		char 	*name;
X		char	*additionalInfo;
X		VOID_PTR	data;
X		union
X		} DataObject;
END-of-dataObject.h
echo file: fview.h
sed 's/^X//' >fview.h << 'END-of-fview.h'
X/**************************************************************************/
X/*  NCSA DataScope
X*   An experiment with real numbers.
X*   by Tim Krauskopf
X*   
X*   National Center for Supercomputing Applications
X*   University of Illinois at Urbana-Champaign
X*   605 E. Springfield Ave.
X*   Champaign, IL  61820
X*
X*   email:        softdev@ncsa.uiuc.edu
X*   bug reports:   bugs@ncsa.uiuc.edu
X*   server:         ftp.ncsa.uiuc.edu  (128.174.20.50)
X*
X*   NCSA DataScope is in the public domain.  See the manual for a complete
X*   permissions statement.  We ask that the following message be included
X*   in all derivative works:
X*   Portions developed at the National Center for Supercomputing Applications
X*   University of Illinois at Urbana-Champaign.
X*
X*   version                      comments
X*   -----------                -------------
X*   1.0 TKK  December 1988
X*   1.1 TKK  May 1989       -- new polar, computations, interpolation
X*
X*   compiles and links under MPW C 2.0.2
X*   The following two lines are in my stdio.h:
X*  #define malloc(A) NewPtr(A)
X*  #define free(A) DisposPtr(A)
X*/
X
X#include <stdio.h>
X/*#include "vdevice.h"*/
X
X/*
X*  Window types are:
X*    Notebook with a text representation of the user's notes and eqn's
X*    Text window displaying the numbers as a spreadsheet-type array.
X*    Simple image window with integral pixel expansion.
X*    Bi-linear interpolation window - an image of the data.
X*    Polar data generated into a Cartesian window.
X*
X*   fdatawin holds the binary dataset.
X*/
X
Xstruct fdatawin {
X   float 
X      valmax,            /* maximum value in the set */
X      valmin,            /* minimum value in the set */
X      *xvals,            /* values of the x independent var along axis */
X      *yvals,            /* increments in the independent vars */
X      *vals;            /* floating point data set */
X   int 
X      top, bottom,      /* selection region in dataset */
X      left, right,
X      angleshift,         /* zero axis shift in pi/2 increments */
X      xsize,ysize,      /* how big to make image (independent of integer expansion) */
X      cmin,cmax,         /* color range to use when color scaling the data */
X      exx,exy,         /* expansion factors for generating the image */
X      refcount,         /* keep track of references for freeing later */
X      contentlen,         /* length of content field */
X      xdim,ydim;         /* x and y dimensions of data set */
X   char 
X      needsave,         /* have changes been made which require saving? */
X      dvar[20],         /* dependent var */
X      xvar[20],         /* x axis label */
X      yvar[20],         /* y axis label */
X      fname[100],         /* filename that data came from */
X      labfmt[50],         /* row/col label format for use in sprintf */
X      fmt[50];         /* printing format to use in sprintf */
X
X   Rect
X      viewport;         /* visible port in imaging window */
X      
X   CharsHandle
X      content;         /* handle to contents of notebook */
X      
X   struct Mwin            /* which image windows were generated from this data? */
X      *notes,            /* notebook window which goes with this data */
X      *text,            /* text display of the floating point numbers */
X      *image,            /* simple image scaling */
X      *interp,         /* interpolated image, using bilinear interpolation */
X      *polar;            /* polar transformation */
X};
X   
X/******************************************************************************/
X/*  The window type defines.
X*/
X#define FTEXT 1
X#define FIMG 2
X#define FBI 3
X#define FPOL 4
X#define FNOTES 5
X
END-of-fview.h
echo file: getfile.h
sed 's/^X//' >getfile.h << 'END-of-getfile.h'
X#define	FTYPE_PAL	1
X#define	FTYPE_IMAGE	2
X
Xstruct GetFile {
X/******* Passed to GetAFile ************/
X	char	type;		/* What type of file to get */
X	void	(*yesfile)();	/* procedure to call when done */
X	void	(*nofile)();	/* procededure to call if cancelled */
X	char	*param;		/* parameter to pass back */
X
X/******* Returned values ***************/
X	char	*directory;	/* directory of file */
X	char	*base;		/* unexpanded base name */
X	char	**file;		/* list of files */
X	int	numFiles;
X	char	isHDF;		/* is it an HDF file */
X	char	isFloat;
X	int	xdim;
X	int	ydim;
X	};
END-of-getfile.h
echo file: gr_com.h
sed 's/^X//' >gr_com.h << 'END-of-gr_com.h'
X/*
X *	File:		gr_com.h
X *	Contents:	Includes all the necessary headers for the
X *				graphics module
X */
X
X#include "gr_def.h"
X#include "gr_inc.h"
X#include "gr_var.h"
END-of-gr_com.h
echo file: gr_def.h
sed 's/^X//' >gr_def.h << 'END-of-gr_def.h'
X/*
X *	File:		gr_def.h
X *	Contents:	Header file containing all the typedefs and defs used
X *				by the graphics module.
X */
X
X#define STRNG40				40
X#define STRNG80				80
X#define STRNG160			160
X
X#define MAX_CUBLEV_WINDS	1
X#define MAX_DSPLEV_WINDS	1
X
X#define MAX_TOPLEV_WIDTH	400
X#define MAX_TOPLEV_HEIGHT	500
X#define MAX_CUBLEV_WIDTH	400
X#define MAX_CUBLEV_HEIGHT	500
X
X#define DEF_BORDER_WIDTH	3
X
X#define DEF_LABEL_FONT		"8x13bold"
X
Xtypedef enum {
X	CNTRLWIND, CUBEWIND, DSPLWIND
X} A_Wind_t;
X
Xtypedef enum {
X	NOSCROLL, VERTONLY, HORIZONLY, VERTHORIZ
X} A_Scroll_t;
X
Xtypedef enum {
X	SELECTABLE, NONSELECTABLE
X} A_TextSelect_t;
X
Xtypedef enum {
X	FILESOURCE, STRINGSOURCE
X} A_TextSource_t;
X
X/*
Xtypedef struct {
X	Widget			id;
X	char			*label;
X	XtCallbackProc	callBackProc;
X	int				x,y;
X	int				width,height;
X} A_Button_t;
X*/
END-of-gr_def.h
echo file: gr_ext.h
sed 's/^X//' >gr_ext.h << 'END-of-gr_ext.h'
X/*
X *	File:		gr_ext.h
X *	Contents:	Header file containing all the externs
X *				of the graphics module.
X */
X
X/*
X * Local externs
X */
X
Xextern void		gr_BossDisplay();
Xextern void		gr_BossSetAxes();
Xextern void		gr_BossSetArb();
Xextern void		gr_CloseBossLevel();
Xextern void		gr_CloseCubeLevel();
Xextern void		gr_CloseDsplLevel();
Xextern void		gr_CloseTileLevel();
Xextern void		gr_CubeDisplayAuto();
Xextern void		gr_CubeDisplaySingle();
Xextern void		gr_CubeDisplaySelected();
Xextern void		gr_CubeFlipVert();
Xextern void		gr_CubeFlipHoriz();
Xextern void		gr_CubeRotLeft();
Xextern void		gr_CubeRotRight();
Xextern void		gr_CubeSetFrame();
Xextern void		gr_CubeSetInterp();
Xextern void		gr_CubeSetNonInterp();
Xextern void		gr_CubeSetXY();
Xextern void		gr_CubeSetXZ();
Xextern void		gr_CubeSetYZ();
Xextern void		gr_DsplListHScroll();
Xextern void		gr_DsplListVScroll();
Xextern void		gr_DsplSetVal();
Xextern void		gr_DsplSliderSelected();
Xextern void		gr_FileDirAccept();
Xextern void		gr_FileCheck();
Xextern void		gr_FileLoad();
Xextern void		gr_ImageSelect();
Xextern void		gr_PalletLoad();
Xextern void		gr_Terminate();
Xextern void		gr_TileSelect();
Xextern A_BossWind_t *gr_InitBossLevel();
Xextern A_BossWind_t *gr_MallocBoss();
Xextern A_CubeWind_t *gr_InitCubeLevel();
Xextern A_CubeWind_t *gr_MallocCube();
Xextern A_DsplWind_t *gr_InitDsplLevel();
Xextern A_DsplWind_t *gr_MallocDspl();
Xextern A_TileWind_t *gr_InitTileLevel();
Xextern A_TileWind_t *gr_MallocTile();
Xextern Widget	gr_DialogGetTextWind();
Xextern Widget	gr_MakeBox();
Xextern Widget	gr_MakeButton();
Xextern Widget	gr_MakeBulletin();
Xextern Widget	gr_MakeDialog();
Xextern Widget	gr_MakeImage();
Xextern Widget	gr_MakeImageStatic();
Xextern Widget	gr_MakeList();
Xextern Widget	gr_MakeListSimple();
Xextern Widget	gr_MakeListStatic();
Xextern Widget	gr_MakeRowColumn();
Xextern Widget	gr_MakeSlider();
Xextern Widget	gr_MakeText();
Xextern Widget	gr_MakeTitleBar();
Xextern Widget	gr_MakeToggle();
Xextern Widget	gr_MakeVPort();
Xextern Widget	gr_MakeWindow();
Xextern Widget	gr_MakeWorkSpace();
Xextern XImage	*gr_ImageCreate();
Xextern char		*gr_DialogGetValue();
Xextern char		*gr_ListgetStruct();
Xextern char		*gr_TextGetStr();
X
Xextern int		gr_CubegetCurIncr();
Xextern int		gr_CubegetCurPlane();
Xextern int		gr_CubegetCurScale();
Xextern int		gr_CubegetCurNumPlanes();
Xextern short	gr_CubegetCurTile();
X
X/*
X * Inter-module externs
X */
X
Xextern char		**td_FileDirStrings();
Xextern char		*td_CurrentDate();
Xextern char		*td_getDirName();
Xextern char		*td_getLogFileName();
Xextern char		*td_getToolName();
Xextern char		*td_HdfgetStats();
Xextern char		*td_HdfgetPixData();
Xextern char		**td_HdfgetHScale();
Xextern char		**td_HdfgetVScale();
Xextern char		**td_HdfgetPlaneData();
Xextern int		td_HdfgetScale();
Xextern int		td_HdfgetDim();
Xextern int		td_HdfCheck();
Xextern int		td_HdfLoad();
Xextern double	td_getVersion();
END-of-gr_ext.h
echo file: gr_inc.h
sed 's/^X//' >gr_inc.h << 'END-of-gr_inc.h'
X/*
X * National Center for SuperComputing Applications, University of Illinois
X *
X * This NCSA software product is public domain software.  Permission
X * is hereby granted to do whatever you like with it. Should you wish
X * to make a contribution towards the production of this software, please
X * send us your comments about your experience with the software,  why
X * you liked or disliked it, how you use it, and most importantly, how it
X * helps your work. We will receive your comments at softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Eng-Whatt Toh, National Center for Supercomputing Applications
X *         ewtoh@ncsa.uiuc.edu
X */
X
X/*
X *	File:		gr_inc.h
X *	Contents:	Header file containing all the includes and externs
X *				by the graphics module.
X */
X
X#include <stdio.h>
X#include <X11/cursorfont.h>
X#include <X11/Xatom.h>
X#include <X11/StringDefs.h>
X#include <X11/Intrinsic.h>
X/*#include <X11/Cardinals.h>*/
X#ifdef XtSpecificationRelease
X#include <X11/Xw/Xw.h>
X#else
X#include <Xw/Xw.h>
X#endif
END-of-gr_inc.h
echo file: gr_var.h
sed 's/^X//' >gr_var.h << 'END-of-gr_var.h'
X/*
X *	File:		gr_var.h
X *	Contents:	Header file containing all global variables used
X *				by the graphics module.
X */
X
XWidget		gr_topLevel;
XWidget		gr_topLevelForm;
XWidget		gr_cubeLevelForm[MAX_CUBLEV_WINDS];
XWidget		gr_dsplLevelForm[MAX_DSPLEV_WINDS];
XWidget		gr_topMsgWind;
XWidget		gr_topFileWind;
XWidget		gr_topDirDialog;
XWidget		gr_topButtons[2];
XWidget		gr_cubMsgWind;
XWidget		gr_cubButtons[4];
XWidget		gr_cubDialogs[3];
XWidget		gr_dspListWind;
XWidget		gr_dspViewWind;
XWidget		gr_dspViewShell;
X
Xshort		gr_cubNumWinds;
Xshort		gr_dspNumWinds;
END-of-gr_var.h
echo file: gr_xwi.h
sed 's/^X//' >gr_xwi.h << 'END-of-gr_xwi.h'
X/*
X * National Center for SuperComputing Applications, University of Illinois
X *
X * This NCSA software product is public domain software.  Permission
X * is hereby granted to do whatever you like with it. Should you wish
X * to make a contribution towards the production of this software, please
X * send us your comments about your experience with the software,  why
X * you liked or disliked it, how you use it, and most importantly, how it
X * helps your work. We will receive your comments at softdev@ncsa.uiuc.edu.
X *
X * Please send bug reports to bugs@ncsa.uiuc.edu
X *
X * Author: Eng-Whatt Toh, National Center for Supercomputing Applications
X *         ewtoh@ncsa.uiuc.edu
X */
X
X/*
X *	File:		gr_xwi.h
X *	Contents:	Header file containing all the includes and externs
X *				by the X-Windows Athena and HP widget sets.
X */
X
X#include <X11/Xos.h>
X#include <X11/Shell.h>
X
X#ifdef XtSpecificationRelease
X#include <X11/Xaw/Text.h>
X#include <X11/Xaw/AsciiText.h>
X#include <X11/Xaw/Box.h>
X#include <X11/Xaw/Command.h>
X#include <X11/Xaw/Dialog.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/List.h>
X#include <X11/Xaw/Viewport.h>
X#else
X#include <X11/Text.h>
X#include <X11/AsciiText.h>
X#include <X11/Box.h>
X#include <X11/Command.h>
X#include <X11/Dialog.h>
X#include <X11/Label.h>
X#include <X11/List.h>
X#include <X11/Viewport.h>
X#endif
X
X#ifdef XtSpecificationRelease
X#include <X11/Xw/Arrow.h>
X#include <X11/Xw/BBoard.h>
X#include <X11/Xw/RCManager.h>
X#include <X11/Xw/ScrollBar.h>
X#include <X11/Xw/SRaster.h>
X#include <X11/Xw/TitleBar.h>
X#include <X11/Xw/Toggle.h>
X#include <X11/Xw/SWindow.h>
X#include <X11/Xw/Valuator.h>
X#include <X11/Xw/WorkSpace.h>
X#else
X#include <Xw/Arrow.h>
X#include <Xw/BBoard.h>
X#include <Xw/RCManager.h>
X#include <Xw/ScrollBar.h>
X#include <Xw/SRaster.h>
X#include <Xw/TitleBar.h>
X#include <Xw/Toggle.h>
X#include <Xw/SWindow.h>
X#include <Xw/Valuator.h>
X#include <Xw/WorkSpace.h>
X#endif
X
XArg	argList[15];
END-of-gr_xwi.h
echo file: i.h
sed 's/^X//' >i.h << 'END-of-i.h'
X#define DISPLAY_CART    1
X#define DISPLAY_POLAR   2
X
X#include "notebook.h"
X
Xtypedef enum {
X	POINT,LINE,AREA
X	} SelectionType;
X
Xstruct	IWS {
X	int	amIShowing;
X	Widget	toplevel;
X	Widget	composite;
X	Widget	box1;
X	Widget	box2;
X	Widget	box3;
X	Widget	box4;
X	Widget	box5;
X	Widget	box6;
X	Widget	box7;
X	Widget	label;
X	Widget	title;
X	Widget	pal_win;
X	Colormap cmap;
X	char	lockcmap;
X	char	*pdata;
X	char	*pdata2;
X	char	*pdata3;
X	char	*pdata4;
X	char	*pdata5;
X	char	*pdata6;
X	int	data1;
X	int	data2;
X	int	data3;
X	SelectionType select;	/* what type of area will be selected */
X	int	selBegX,selBegY,selEndX,selEndY; /*selected point,line,region*/
X	GC	box3gc;
X	};
X
Xstruct	IMAGE {
X	char	*name;		/* name of image */
X	char	*fname;		/* file name of image */
X	int	isHDF;		/* file format of image */
X	int	xdim,ydim;	/* X and Y dimensions */
X
X	char	label[20];
X
X	char	isFloat;	/* is this IMAGE in float? */
X	float	*fdataset;	/* floating point data set */
X	float	maxvalue;	/* maximum value only used if float*/
X	float	minvalue;	/* minimum value only used if float*/
X
X	char	*format;	/* printf format for printing */
X	int	fwidth;		/* format width (maximum # char of output) */
X
X	unsigned char	*ri;	/* raster image data set stored here */
X	unsigned char *dExpRI;	/* depth expantion ri (16,24,etc bit)*/
X	char	isDExpRI;	/* is ri depth expanded */
X	XImage	*cimage;	/* cartesian XImage structure here */
X
X				/* expand image */
X	unsigned char	*riExpand;	/* raster image data set stored here */
X	unsigned char *dExpRIExpand;	/* depth expantion ri (16,24,etc bit)*/
X	char	isDExpRIExpand;	/* is ri depth expanded */
X	XImage	*cimageExpand;	/* cartesian XImage structure here */
X	
X
X	unsigned char	*polarimage;	/* polar image */
X	unsigned char	*dExpPI; /* depth expantion polar (16,24,etc bit)*/
X	char	isDExpPI;	/* is polar Image depth expanded */
X	XImage  *pimage;	/* polar XImage structure here */
X
X	char	plotCartesian;	/* Plot cartesian image */
X	char	plotSepWindow;	/* Plot graphs in seperate window */
X	unsigned char	*contourLevels;
X
X	struct	IWS	cws;	/* control window widgets */
X	struct	IWS	iws;	/* image window widgets */
X	struct	IWS	pws;	/* polar window widgets */
X	struct	IWS	dws;	/* data window widgets */
X	struct	IWS	gws;	/* Graph control box */
X	struct	IWS	gcws;	/* graph contour widgets */
X	struct	IWS	gpws;	/* graph profile widgets */
X	struct	IWS	gsws;	/* graph shaded widgets */
X	struct	IWS	ghws;	/* graph histogram widgets */
X	struct	IWS	chaws;	/* change attrib widgets */
X
X	char	hasPalette;
X	XColor	*palette;
X
X	char	expand;		 /* expand image ? */
X	float	expansionFactor; /* expansion factor */
X	char	interpExpansion; /* is this an interpolated expansion? */
X
X	Widget	pal_win;	/* palette image */
X	GC	iwgc;		/* image widget GC */
X	Visual	*ivis;		/* image visual */
X	XImage	*i;		/* X image struct */
X	char	image_loaded;	/* is the image loaded? */
X	char	image_showing;	/* is the image window showing? */
X
X	struct	NOTEBOOK notebook;	/* Notebook */
X
X	struct IMAGE *prev;	/* next image structure */
X	struct IMAGE *next;	/* next image structure */
X
X	};
END-of-i.h
echo file: libmgrP.h
sed 's/^X//' >libmgrP.h << 'END-of-libmgrP.h'
X#define VOID_PTR	void *
X
X#include "list.h"
X#include "types.h"
X
Xtypedef enum {
X		OPTIONAL_USER_PARAM,
X		REQUIRED_USER_PARAM,
X		STATIC_PARAM
X		} ParamStatus;
X
Xtypedef struct {
X		char 		*paramName;
X		char		*paramFormat;
X		Type		paramType;
X		ParamStatus	paramStatus;
X		
X		VOID_PTR	value;
X		VOID_PTR	defaultParamValue;
X		} ParamTemplate;
X
Xtypedef List ParamList;
X
Xtypedef struct {
X	char 		*funcName;
X	char		*executableName;
X	int		numOfParams;
X	ParamList	params;
X	} FunctionRecord;
X
Xtypedef List FunctionList; 
END-of-libmgrP.h
echo file: list.h
sed 's/^X//' >list.h << 'END-of-list.h'
X#include "listP.h"
X
Xextern List ListCreate();
Xextern void ListDestroy();
Xextern int  ListAddEntry();
Xextern int  ListDeleteEntry();
X
Xextern char *ListHead();
Xextern char *ListTail();
Xextern char *ListCurrent();
Xextern char *ListNext();
Xextern char *ListPrev();
END-of-list.h
echo file: listP.h
sed 's/^X//' >listP.h << 'END-of-listP.h'
Xstruct LISTINSTANCE {
X	char *value;
X	struct LISTINSTANCE *next;
X	struct LISTINSTANCE *prev;
X	};
X
Xstruct LISTSTRUCT {
X	struct LISTINSTANCE  *head;
X	struct LISTINSTANCE  *tail;
X	struct LISTINSTANCE  *current;  
X	};
X
Xtypedef struct LISTSTRUCT  *List;
END-of-listP.h
echo file: mac.h
sed 's/^X//' >mac.h << 'END-of-mac.h'
X#define	extended	double
END-of-mac.h
echo file: mem.h
sed 's/^X//' >mem.h << 'END-of-mem.h'
Xextern	char *XIMalloc();
Xextern	char *XICalloc();
Xextern	void XIFree();
END-of-mem.h
echo file: notebook.h
sed 's/^X//' >notebook.h << 'END-of-notebook.h'
X#ifndef __XINOTEBOOK__
X
Xstruct NOTEBOOK {
X	Widget	topLevel;
X	Widget	topComp;
X	Widget	topForm;
X	Widget	editWidget;
X	Widget	box1;
X	Widget	calcButton;
X	Widget	saveButton;
X	Widget	doneButton;
X
X	char	*text;
X	char    hasNotebook;            /*Notebook associated with this data?*/
X	char    notebookUsed;           /*Notebook dirty bit */
X	char	notebookShowing;
X
X	Atom	selectionProperty;
X	Widget	requestorWidget;
X	Window	requestorWindow;
X};
X
X#define __XINOTEBOOK__
X#endif
END-of-notebook.h
echo file: palentry.h
sed 's/^X//' >palentry.h << 'END-of-palentry.h'
X#define	DSTRINGSIZE	20
X
Xstruct PALEDIT {
X	Widget	topLevel;
X	Widget	composite;
X	Widget	box1;
X	Widget	box2;
X	Widget	slide1;
X	Widget	slide2;
X	Widget	slide3;
X	Widget	label1;
X	Widget	label2;
X	Widget	label3;
X	Widget	val1;
X	Widget	val2;
X	Widget	val3;
X	Widget	palImage;
X	
X	XColor	*ccells;
X	Widget	dEntry;
X	char	dEntryString[DSTRINGSIZE];
X	int	entry;
X	Widget	vce;	/*View color entry */
X};
END-of-palentry.h
echo file: paletteP.h
sed 's/^X//' >paletteP.h << 'END-of-paletteP.h'
X#define	CRED		(1 << 9)
X#define	CGREEN		(1 << 8)
X#define	CBLUE		(1 << 7)
X#define	CCYAN		(1 << 6)
X#define	CMAGENTA	(1 << 5)
X#define	CYELLOW		(1 << 4)
X#define	CHUE		(1 << 3)
X#define	CSATURATION	(1 << 2)
X#define	CVALUE		(1 << 1)
X#define	CLIGHTNESS	1
END-of-paletteP.h
echo file: parse.h
sed 's/^X//' >parse.h << 'END-of-parse.h'
X#define	getc(a)   GetExprChar(a)
X#define putc(a,b) PutExprChar(a,b)
END-of-parse.h
echo file: parseSupport.h
sed 's/^X//' >parseSupport.h << 'END-of-parseSupport.h'
Xextern DATA_ARRAY *GetDataSet();
Xextern void WriteText();
Xextern void WriteErrMesg();
Xextern void NewDataSet();
END-of-parseSupport.h
echo file: patterns.h
sed 's/^X//' >patterns.h << 'END-of-patterns.h'
X/*  XImageTool patterns for stipple creation  --  dsw14feb89  */
X/*								*/
X/*  Note:  in order to make use of binary shift operations for	*/
X/*	   maximum possible speed, the number of patterns below */
X/*	   should be some power of two.  Set SHIFTBITS to the	*/
X/*	   the power of 2 that you are using.			*/
X/* Warning:  If you choose not to implement a 2^n array of	*/
X/*	   patterns, the file "Shade.c" will need to be mod	*/
X/*	   ified to allow for integer division.  This can be	*/
X/*	   considerably slower.					*/
X
X#define	NUMPATTERNS	8
X#define	SHIFTBITS	3
X
Xstatic	char	pats[][32] = {
X	{
X	  0,   0,   0,   0,   0,   0,   0,   0,
X	  0,   0,   0,   0,   0,   0,   0,   0,
X	  0,   0,   0,   0,   0,   0,   0,   0,
X	  0,   0,   0,   0,   0,   0,   0,   0
X	},
X	{
X	128, 128,   0,   0,   0,   0,   0,   0,
X	  0,   0,   0,   0,   0,   0,   0,   0,
X	128, 128,   0,   0,   0,   0,   0,   0,
X	  0,   0,   0,   0,   0,   0,   0,   0
X	},
X	{
X	128, 128,   0,   0,   8,   8,   0,   0,
X	128, 128,   0,   0,   8,   8,   0,   0,
X	128, 128,   0,   0,   8,   8,   0,   0,
X	128, 128,   0,   0,   8,   8,   0,   0
X	},
X	{
X	136, 136,   0,   0,  34,  34,   0,   0,
X	136, 136,   0,   0,  34,  34,   0,   0,
X	136, 136,   0,   0,  34,  34,   0,   0,
X	136, 136,   0,   0,  34,  34,   0,   0
X	},
X	{
X	136, 136,  34,  34, 136, 136,  34,  34,
X	136, 136,  34,  34, 136, 136,  34,  34,
X	136, 136,  34,  34, 136, 136,  34,  34,
X	136, 136,  34,  34, 136, 136,  34,  34,
X	},
X	{
X	170, 170,  85,  85, 170, 170,  85,  85,
X	170, 170,  85,  85, 170, 170,  85,  85,
X	170, 170,  85,  85, 170, 170,  85,  85,
X	170, 170,  85,  85, 170, 170,  85,  85,
X	},
X	{
X	119, 119, 221, 221, 119, 119, 221, 221,
X	119, 119, 221, 221, 119, 119, 221, 221,
X	119, 119, 221, 221, 119, 119, 221, 221,
X	119, 119, 221, 221, 119, 119, 221, 221,
X	},
X	{
X	119, 119, 255, 255, 221, 221, 255, 255,
X	119, 119, 255, 255, 221, 221, 255, 255,
X	119, 119, 255, 255, 221, 221, 255, 255,
X	119, 119, 255, 255, 221, 221, 255, 255,
X	} };
X
END-of-patterns.h
echo file: process.h
sed 's/^X//' >process.h << 'END-of-process.h'
X#include <sys/types.h>
X
X#include "libmgrP.h"
X
Xtypedef struct {
X	FunctionRecord *function;
X	char	**argv;
X	char	*host;			/* host name:  "LOCAL" if local */
X	int	pid;
X	char	*inAddress;
X	char	*outAddress;
X	int	procSTDIN;
X	int	procSTDOUT;
X	int	procSTDERR;
X	time_t	startUpTime;
X	} Process;
END-of-process.h
echo file: resources.h
sed 's/^X//' >resources.h << 'END-of-resources.h'
END-of-resources.h
echo file: sem_stack.h
sed 's/^X//' >sem_stack.h << 'END-of-sem_stack.h'
X#include "sem_stack_t.h"
X
Xextern	void		SS_Push();
Xextern	union sem_stack_type *SS_Pop();
Xextern	union sem_stack_type *SS_Top();
Xextern	union sem_stack_type *SS_New();
X
END-of-sem_stack.h
echo file: sem_stack_t.h
sed 's/^X//' >sem_stack_t.h << 'END-of-sem_stack_t.h'
X#include "data.h"
X
Xtypedef enum { FLOAT_CONST_ID,
X		KNOWN_FUNC_ID,
X		FUNCTION_ID,
X		VAR_ID,
X		INTEGER_ID,
X		DATA_ID,
X		} ID_KIND;
X
Xtypedef struct {
X		ID_KIND kind;
X		} TYPE;
Xtypedef struct {
X		ID_KIND kind;
X		int	value;
X		} INTEGER;
X
Xtypedef struct {
X		ID_KIND kind;
X		DATA_ARRAY *value;
X		} DATA;
X
Xtypedef struct {
X		ID_KIND	kind;
X		float	value;	 /* const float value */
X		} FLOAT_CONST;
X
Xtypedef struct {
X		ID_KIND	kind;
X		int	value;	 /* function ID token */
X		} KNOWN_FUNC;
X		
Xtypedef struct {
X		ID_KIND	kind;
X		char	*value; /* function id name */
X		} FUNCTION;
X
Xtypedef struct {
X		ID_KIND	kind;
X		char	*value; /* variable id name */
X		} VAR;
X
Xunion sem_stack_type {
X		TYPE		type;
X		INTEGER		integer;
X		DATA		data;
X		FLOAT_CONST	float_const;
X		KNOWN_FUNC	known_func;
X		FUNCTION	function;
X		VAR		var;
X		};
END-of-sem_stack_t.h
echo file: types.h
sed 's/^X//' >types.h << 'END-of-types.h'
Xtypedef enum {  STRING,
X		INT,
X		FLOAT,
X		ANOTHER_TYPE,
X		ANOTHER_TYPE2
X		} Type;
END-of-types.h
echo file: value.h
sed 's/^X//' >value.h << 'END-of-value.h'
X#define VADD    600
X#define VSUB    601
X#define VMUL    602
X#define VDIV    603
END-of-value.h
echo file: ximage.h
sed 's/^X//' >ximage.h << 'END-of-ximage.h'
X/* This is a global header file for all of ximage, meaning that it is
X * included in all the .c files. 
X */
X
X#include "mem.h"
X
Xtypedef struct {
X	Boolean installCMap;
X	} XIResources, *XIResourcesPtr;
X
Xextern XIResources appResources;
Xextern Boolean	defStaticVisual;	/* do windows default to stat visual?*/
X
X
Xtypedef enum {
X	NOSCROLL, VERTONLY, HORIZONLY, VERTHORIZ
X} A_Scroll_t;
X
Xtypedef enum {
X	SELECTABLE, NONSELECTABLE
X} A_TextSelect_t;
X
Xtypedef enum {
X	FILESOURCE, STRINGSOURCE
X} A_TextSource_t;
X
X
X#define	ABS(x)	((x)>0) ? (x): (-1.0*(x))
X#define SQUARE(x)	(x*x)
X#define ROUND(x)        ((int) (x + 0.5))
X#define PI              3.1415927   /* <- defined here for convenience, should
X                                          the value of PI ever change :-) */
END-of-ximage.h
echo file: xstuff.h
sed 's/^X//' >xstuff.h << 'END-of-xstuff.h'
Xextern Widget MakeButton();
Xextern Widget MakeConstrainedButton();
Xextern Widget Make_Window();
Xextern Widget Make_ButtonBox();
Xextern Widget Make_Toggle();
Xextern Widget Make_Label();
Xextern Widget Make_Pal_Window();
Xextern Widget Make_Text_Inp();
Xextern Widget Make_Dialog();
Xextern Widget Make_Board();
Xextern Widget MakeForm();
Xextern Widget MakeImageWindow();
Xextern Widget MakeList();
Xextern Widget MakeATopLevel();
Xextern Widget MakeATopLevelOverride();
Xextern Widget MakeRasterImage();
Xextern Widget MakeWorkSpace();
Xextern Widget MakeAltToggle();
Xextern Widget MakeValuator();
Xextern Widget MakeBox();
Xextern Widget MakeVPort();
Xextern Widget MakeText();
X
Xextern XImage *MakePalette();
Xextern Visual *GetVisual();
X
Xextern void Get_Text_Inp();
Xextern void Set_Pointer();
Xextern void PlaceWindow();
END-of-xstuff.h
echo file: xstuff2.h
sed 's/^X//' >xstuff2.h << 'END-of-xstuff2.h'
XWidget NewMakeVPort();
XWidget NewMakeListSimple();
XWidget NewMakeList();
XWidget NewMakeListStatic();
END-of-xstuff2.h
echo file: ximage.icon
sed 's/^X//' >ximage.icon << 'END-of-ximage.icon'
X#define XIMAGE_WIDTH 64
X#define XIMAGE_HEIGHT 64
X#define XIMAGE_X_HOT -1
X#define XIMAGE_Y_HOT -1
Xstatic char XIMAGE_ICON[] = {
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0xfc, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x3f, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0xe0, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78,
X   0x00, 0xc0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x70, 0x07, 0x00,
X   0x00, 0x00, 0x00, 0x0e, 0xf0, 0xff, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x03,
X   0xf8, 0xff, 0x18, 0x00, 0x00, 0x00, 0x80, 0x0f, 0xfc, 0xff, 0x30, 0x00,
X   0x00, 0x00, 0xc0, 0x0f, 0x0e, 0x70, 0x70, 0x00, 0x00, 0x00, 0xc0, 0x0f,
X   0x03, 0x70, 0x60, 0x00, 0x00, 0x00, 0x60, 0x80, 0xf9, 0xff, 0xe0, 0x00,
X   0x00, 0x00, 0x60, 0xc0, 0xfc, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x30, 0x40,
X   0x02, 0x70, 0xf0, 0x01, 0x00, 0x00, 0x30, 0x40, 0x01, 0x70, 0xf0, 0x01,
X   0x06, 0x06, 0x3f, 0xc0, 0xfc, 0xff, 0x70, 0x0b, 0x0e, 0xc6, 0x1f, 0xc0,
X   0xfe, 0xff, 0x70, 0x1f, 0x0e, 0xe6, 0x18, 0x40, 0x01, 0x70, 0x70, 0x3f,
X   0x1e, 0x66, 0x18, 0xc0, 0x40, 0x00, 0x38, 0x73, 0x16, 0x66, 0x18, 0xc0,
X   0xe0, 0x40, 0x38, 0x63, 0x36, 0x66, 0x18, 0x40, 0xe0, 0x60, 0xf8, 0x63,
X   0x26, 0x66, 0x18, 0x00, 0x40, 0x60, 0xf8, 0x7f, 0x66, 0x66, 0x18, 0xc0,
X   0x01, 0x50, 0xf8, 0x7f, 0x46, 0x66, 0x18, 0xe0, 0xff, 0x6f, 0x18, 0x63,
X   0xc6, 0x66, 0x18, 0xe0, 0xff, 0x67, 0x18, 0x63, 0x86, 0x66, 0x30, 0xc0,
X   0x01, 0x50, 0x98, 0x61, 0x86, 0xe7, 0x30, 0xc0, 0x01, 0x48, 0x98, 0x61,
X   0x06, 0xc7, 0x3f, 0xe0, 0xff, 0x67, 0x98, 0x61, 0x06, 0x06, 0x7f, 0xe0,
X   0xff, 0x33, 0xd8, 0x60, 0x00, 0x00, 0x60, 0xc0, 0x01, 0x18, 0xd8, 0x00,
X   0x00, 0x00, 0xc0, 0xcf, 0x01, 0x0c, 0x78, 0x00, 0x00, 0x00, 0xc0, 0xef,
X   0xff, 0x07, 0x38, 0x00, 0x00, 0x00, 0xc0, 0xef, 0xff, 0x03, 0x38, 0x00,
X   0x00, 0x00, 0x60, 0xe3, 0xff, 0x01, 0x18, 0x00, 0x00, 0x00, 0x30, 0xce,
X   0x01, 0x00, 0x0e, 0x00, 0x08, 0x00, 0x60, 0x1c, 0x00, 0x00, 0x07, 0x00,
X   0x14, 0x00, 0xf0, 0x78, 0x00, 0xc0, 0x03, 0x00, 0x22, 0x00, 0xf8, 0xed,
X   0x03, 0xf8, 0x00, 0x00, 0x74, 0x00, 0xec, 0x87, 0xff, 0x3f, 0x00, 0x00,
X   0xf8, 0x00, 0xde, 0x02, 0xfc, 0x07, 0x00, 0x00, 0xb0, 0x01, 0x7b, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x60, 0x83, 0x37, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0xc0, 0xc6, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xed, 0x0d, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0xbb, 0x07, 0x1f, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x76, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x01, 0x04,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0xde, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0xbb, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x80, 0x77, 0x03, 0x04,
X   0x00, 0x00, 0x00, 0x00, 0xc0, 0xde, 0x06, 0x44, 0x10, 0x04, 0x7e, 0x7e,
X   0xe0, 0x8d, 0x0d, 0xc4, 0x18, 0x0a, 0x01, 0x02, 0xb0, 0x07, 0x1b, 0x44,
X   0x15, 0x11, 0x01, 0x02, 0x78, 0x03, 0x16, 0x44, 0x92, 0x3f, 0x79, 0x7e,
X   0xf8, 0x01, 0x1c, 0x44, 0x90, 0x20, 0x41, 0x02, 0xf8, 0x00, 0x20, 0x44,
X   0x90, 0x20, 0x41, 0x02, 0x78, 0x00, 0x40, 0x5f, 0x90, 0x20, 0x7e, 0x7e,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
END-of-ximage.icon
echo file: ximage.1
sed 's/^X//' >ximage.1 << 'END-of-ximage.1'
X.TH XIMAGE 1 "1 November 1989"
X.SH NAME
XNCSA ximage \- interactive data analysis tool
X.SH SYNOPSIS
X.B ximage
X.RB [ " \-options \|.\|.\|." ]
X.LP
X.SH DESCRIPTION
X.IX  ximage  ""  "\fLximage\fR \(em interactive data analysis tool"
X.IP  
Xximage is 2D interactive data analysis tool that features displaying
Xcolor images of data sets in cartesian and polar form.  It can 
Xdisplay the actual data values in a spread sheet manner and create
Xcolor contour plots, shaded images, color histograms, and profile plots. 
X.LP
X.IP
Xximage provides functions for dynamically manipulating palettes.  
XPalette manipulation may be done by changing the component values in RGB, 
XCMY or HSV color models.  In addition, the palette may be changed by 
Xexpansion, compression, rotation or transposition. 
X.LP
X.IP
XThe user may animate multiple raster images from disk or the X server's memory.
X.LP
X.IP
XAs input data, ximage takes either 8-bit raster files or HDF files containing 
Xeither 8-bit raster data or 32 bit floating point data.  HDF 
X(Hierarchical Data Format) is a standard data format originally developed
Xat NCSA.  As Input palettes, it takes in HDF palettes, and 8 bit palettes
Xwhere the first 256 bytes specify the 256 entries of red, followed by
X256 entries of green and then blue.  
X.LP
X.SH X DEFAULTS
X.LP
X.IP
Xximage*installCMap:	(True or False)
X.IP
XinstallCMap tells ximage whether or not to follow ICCCM rules for setting 
Xcolormap.  If you are using an old or non ICCCM compliant window manager, 
Xthis option should be set to True.  The default is False.  If the color map 
Xdoes not appear to be changing when a colormap is loaded then changing 
Xthis option will usually fix the problem.
X.LP
X.SH SEE ALSO
X.IP
Xxds(1)	- NCSA XDataSlice
X.LP
X.IP
XFull documentation of NCSA XImage is provided along with the distribution.
XThe latest version of this software and documentation may always be
Xobtained from the anonymous ftp server ftp.ncsa.uiuc.edu (128.174.20.50)
X.LP
X.SH BUGS
XPlease send bug reports to bugs@ncsa.uiuc.edu.
X.IP
X.SH ORIGIN
XNational Center for Supercomputing Applications at the University of Illinois
Xin Urbana Champaign.
END-of-ximage.1
echo file: Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X#########################################################################
X#
X#  Makefile for X Image Version 1.2.1 
X#  Before make(ing)  you will need to configure this Makefile to your system.
X#  You need to specify where libraries and header files are stored
X#  on your system.  
X#
X#
X##########################################################################
X#  HDF or Hierarchical Data File format is a tag based file format
X# 	developed at NCSA.  If you don't have HDF, you need to get 
X#	it from NCSA either via anonymous ftp (141.142.20.50) or
X#	or by calling (217) 244-0072
X#
X#  HDFLIB - where is your HDF library?  It should be called libdf.a
X#  HDFINCLUDE - where are your HDF header files (so that they can be 
X#		accessed by <hdf/????.h>
X
XHDFLIB=-ldf
XHDFINCLUDE=-I/usr/local/include
X
X########################################################################
X# Are you using DTM (Data Transfer Mechanism)?
X# If you don't have the dtm library, you can get it in the same manner
X# as HDF.  Don't forget to set -DUSE_DTM in the DEFINES below
X# DTMLIB= where is the dtm library
X# DTMINCLUDE = -I(where are the include files access by <dtm/????.h>)
X
X#DTMLIB=-ldtm
XDTMLIB=
XDTMINCLUDE=
X
X
X#################################
X#  Where are your X window libraries?  In particular:
X#  		libXw.a, libXaw.a, libXt.a, libXmu.a, libX11.a
X#
X#  libXw.a	- 2D HP widget set library.
X#  libXaw.a	- Athena widget set.
X#  libXext.a	- X11R4 extensions
X#  libXt.a	- Xt Intrinsic Toolkit
X#  libXmu.a	- the Mu stuff
X#  libX11.a	- X11 Library
X#
X# Note: If you do not have the HP widget set, you may download it
X# from the NCSA anonymous ftp server ftp.ncsa.uiuc.edu (141.142.20.50)
X# If you are missing any of the other libraries, you may download
X# the latest distribution of X11 from expo.lcs.mit.edu (18.30.0.212)
X#
X# Specify the directories these libraries are in.
X#
X
XULIBS= 
X
X#################################
X# Specify where your include files are for the above libraries 
X#
X
XINCLUDES= $(HDFINCLUDE) $(DTMINCLUDE)
X
X
X#################################
X# DEFINES=  possible values listed below 
X# for compiling under SysV use: -DSYSV
X# for compiling on Cray (UNICOS) use:  -DSYSV -DUNICOS -DUSG
X# for compiling on SGI, use: -DSYSV -DIRIS4
X# for compiling on a Sun use: -DSUN
X# for compiling on a DEC Ultrix machine: -DULTRIX
X# for compiling on a IBM RS600 machine: -DAIX
X# add -DXAW_BC if compiling with X11R4. 
X# add -DUSE_DTM if you want to use the DTM features
X
XDEFINES= -DXAW_BC -DSUN 
X
X
X####################################################################
X# DESTDIR - final destination of executable
X#
X
XDESTDIR = /usr/local/bin
X
X
X####################################################################
X#  Take out -lXext if compiling with X11R3.
X#
X# Hint: for SGI, change -lm to -lm43 and include -lbsd
X#
X
XSLIBS= $(HDFLIB) $(DTMLIB) -lXw -lXaw -lXt -lXext -lXmu -lX11 -lm 
X
X
X
X
X
X####################################################################
X# if compiling on UNICOS add a '-h pagelm'
X#CFLAGS= -O $(INCLUDES) $(DEFINES)
XCFLAGS= -g $(INCLUDES) $(DEFINES) 
X
X
X######################################################################
X########## You shouldn't need to edit anything below here ############
X######################################################################
X
X
XPROGRAM= ximage
XSRCS= 			a.c \
X			animate.c \
X			chattrib.c \
X			cbtable.c \
X			control.c \
X			contour.c \
X			contourlevel.c \
X			ctlcontour.c \
X			data.c \
X			dtmstuff.c \
X			getfile.c \
X			glob.c \
X			gr_xwi.c \
X			graph.c \
X			i.c \
X			image.c \
X			intensity.c \
X			main.c \
X			mem.c \
X			notebook.c \
X			palentry.c \
X			palette.c \
X			profile.c \
X			polar.c \
X			read.c \
X			shade.c \
X			sliceSDS.c \
X			write.c \
X			xstuff.c \
X			xstuff2.c \
X			xinit.c \
X			y.tab.c \
X			parse.c \
X			parseSupport.c \
X			fcmp1.c \
X			remote.c \
X			list.c 
X
X
XOBJS= $(SRCS:.c=.o) 
X
X###########################################
X# CURDATE&VERSION used to log compilation date & version No. in module date.c
X#
XCURDATE = `date '+"%D"'`
X#CURDATE = `date '+"%D@%T"'`
XVERSION = '"NCSA X Image Version 1.2.1"'
X
X###########################################
X#
X
XBACKUP = `date '+xi.%m.%d.%y.shar'`
X
X
X##########################################
X
X$(PROGRAM):  $(OBJS) date.o 
X	rm -f $@
X	$(CC) -o $@ $(CFLAGS) $(OBJS) date.o $(ULIBS) $(SLIBS)
X
X$(HDFLIB):
X	cd ../hdf; make
X
Xsaber_src: $(SRCS)
X	#load $(CFLAGS) $(SRCS)
X
Xsaber_obj: $(OBJS)
X	#load $(CFLAGS) $(OBJS)
X
Xbackup: $(SRCS) 
X	shar README VERSIONLOG $(SRCS) date.c gram.y exp.l lex.yy.c \
X		parse2.c *.h ximage.icon ximage.1 Makefile > $(BACKUP)
X	cp $(BACKUP) archive
X	compress archive/$(BACKUP)
X
Xinstall: $(PROGRAM)
X	install -m 755 $(PROGRAM) $(DESTDIR)
X	cp ximage.1 /usr/man/man1
X
Xclean:
X	rm -f $(PROGRAM) $(OBJS) date.o
X
Xa.o:		a.c animate.h ximage.h
X
Xanimate.o:	animate.c animate.h xstuff.h getfile.h ximage.h
X
Xcontrol.o:	control.c xstuff.h buttons.h gr_def.h gr_var.h ximage.h
X
Xctlcontour.o:	ctlcontour.c i.h xstuff.h ximage.h
X
Xdata.o:		data.c i.h xstuff.h xstuff2.h ximage.h
X
Xgetfile.o:	getfile.c xstuff.h getfile.h ximage.h
X
Xgraph.o:	graph.c i.h xstuff.h ximage.h
X
Xgr_xwi.o:	gr_xwi.c gr_xwi.h ximage.h
X
Xi.o:		i.c i.h ximage.h
X
Ximage.o: 	image.c i.h buttons.h xstuff.h getfile.h ximage.h
X
Xmain.o:		main.c xstuff.h ximage.icon ximage.h
X
Xnotebook.o:	notebook.c notebook.h xstuff.h ximage.h
X
Xpalentry.o:	palentry.c xstuff.h palentry.h ximage.h
X
Xpalette.o:	palette.c buttons.h xstuff.h paletteP.h getfile.h ximage.h
X
Xpolar.o:	polar.c i.h xstuff.h ximage.h
X
Xprofile.o:	xstuff.h i.h ximage.h
X
Xread.o:		read.c i.h ximage.h
X
Xshade.o:	shade.c patterns.h ximage.h
X
XsliceSDS.o:	sliceSDS.c buttons.h xstuff.h ximage.h
X
Xxstuff.o:	xstuff.c ximage.h
X
Xxstuff2.o:	xstuff2.c xstuff.h xstuff2.h ximage.h
X
Xxinit.o:	xstuff.h ximage.h
X
Xdate.o: 	$(OBJS) 
X		cc -c $(DEFINES) -DVERSIONDATE=$(CURDATE) -DVERSION=$(VERSION) date.c
X
Xlex.yy.c:	exp.l
X		lex exp.l
X
Xy.tab.o:	y.tab.c parse2.c lex.yy.c
X
Xy.tab.c:	gram.y parse.h data.h value.h sem_stack.h parseSupport.h
X		yacc gram.y
X
Xparse.c:	parse.h
END-of-Makefile
exit
