CCL Home Page
Up Directory CCL ortep.c
/*****************************************************************************
*         ORTEP-II (Oak Ridge Thermal Ellipsoid Plot) for SGI                *
*                                                                            *
* ORTEP-II was originally written by C. K. Johnson (1976). Report ORNL-5138. *
* Oak Ridge National Lab., Oak Ridge, TN, USA.                               *
* ORTEP-II for OpenWindows was written by Norimasa Yamazaki, University of   *
* Electro-Communications, Tokyo, Japan (yam@crystal.pc.uec.ac.jp).           *
*                                                                            *
* ORTEP-II for SGI is based on the above two programs.                       *
* List of Files:                                                             *
*	Makefile: make file                                                  *
*       ort.f:    ORTEP-II main program written by C. K. Johnson             *
*       ortep.c:  interface to ORTEP-II for SGI                              *
* Compilation: Just type 'make'.                                             *
* Usage: ortep filename                                                      *
*        ortep -ps filename                                                  *
*                                                                            *
*        If -ps option is specified, PostScript output is printed on your    *
*        terminal (stdout). To save it in a file, redirect the standard      *
*        output, i.e., do 'ortep -ps filename > file.ps'                     *
* Features:                                                                  *
*	nothing fancy really.                                                *
*       It creates only either graphics window on SGI or PostScript file.    *
* Author: Dongchul Lim, Dept of Chemistry, Yale Univ., New Haven, CT, USA    *
*         (lim@rani.chem.yale.edu), April, 1994.                             *
******************************************************************************/

#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 

#define ROUND(x)	(int)(((x)<0.0)?(x)-.5:(x)+.5)
#define MAX(x, y)	(((x) > (y)) ? (x) : (y))
#define MIN(x, y)	(((x) < (y)) ? (x) : (y))

#define MAXLINES	64000
#define MAXSYMBOLS	2000

typedef struct {
	float	x, y;
	float	height;
	char	str[72];
	float	angle;
	} Symbol;

typedef struct {
	float	x, y;
	int	id;
	} Lines;

static float	pensize = 0.5;
static float	xorigin = 0.0;
static float	yorigin = 0.0;
static Lines	lines[MAXLINES];
static int	nlines = 0;
static Symbol	symbols[MAXSYMBOLS];
static int	nsymbols = 0;
static fmfonthandle	fh = NULL;

/* dummy functions which are called by ortepmain */
void	gpsltm_(void) {}
void	ginit_(void) {}
void	vsini_(void) {}
void	device_(void) {}
void	rwind_(void) {}
void	charac_(void) {}
void	newpen_(void) {}
void	vsterm_(void) {}
void	tinput_(void) {}
void	pinit_(void) {}
void	drawtitle_(void) {}

void	setpensize_ (float *size)
{
	if (*size > 0 && *size < 4) pensize = *size;
	else pensize = 0.5;
}

void	plot_ (float *x, float *y, int *id)
{
	if (nlines >= MAXLINES) {
		fprintf(stderr, "Maximum # of lines reached.\n");
		return;
	}

	lines[nlines].x  = *x + xorigin;
	lines[nlines].y  = *y + yorigin;
	lines[nlines].id = *id;
	nlines++;

	if (*id < 0) {
		xorigin += *x;
		yorigin += *y;
	}
}

static int	trim_str (char *str, char *delim)
{
	trim_head(str, delim);
	return trim_tail(str, delim);
}

static int	trim_head (char *str, char *delim)
{
	char	*bgn, *p, *q;
	if (!str || !str[0]) return 0;
	bgn = str + strspn(str, delim);
	if (!*bgn) {
		str[0] = '\0';
		return 0;
	} else if (bgn == str) return 1;
	for(p=bgn,q=str;*p;p++,q++) *q = *p;
	*q = '\0';
	return 1;
}

static int	trim_tail (char *str, char *delim)
{
	char	*p;
	int	i, len;
	if (!str || !str[0]) return 0;
	len = strlen(str);
	for(i=len-1;i>=0;i--) {
		if (!strchr(delim, str[i])) return 1;
		else str[i] = '\0';
	}
	return 0;
}

void	symbol_ (float *x, float *y, float *height, char *ch, float *angle, int *len)
{
	char	*str;

	if (nsymbols >= MAXSYMBOLS) {
		fprintf(stderr, "Maximum # of symbols reached.\n");
		return;
	}
	symbols[nsymbols].x = *x + xorigin;
	symbols[nsymbols].y = *y + yorigin;
	symbols[nsymbols].height = *height;
	symbols[nsymbols].angle  = *angle;
	str = symbols[nsymbols].str;
	sprintf(str, "%.*s\0", *len, ch);
	trim_str(str, " \t\n");
	nsymbols++;
}

void	number_ (float *x, float *y, float *height, float *val, float *angle, int *num)
{
	char	*str;

	*x += 260;
	*y += 320;

	symbols[nsymbols].x = *x + xorigin;
	symbols[nsymbols].y = *y + yorigin;
	symbols[nsymbols].height = *height;
	symbols[nsymbols].angle = *angle;
	str = symbols[nsymbols].str;
	sprintf(str, "%.*f\0", *num, *val);
	trim_str(str, " \t\n");

	nsymbols++;
}

int	main (int argc, char *argv[])
{
	short	val;
	long	dev;
	char	*filename, *prog;

	if ((prog = strrchr(argv[0], '/'))) prog++; else prog = argv[0];
	if (argc < 2) {
		fprintf(stderr, "Usage: %s filename\n", prog);
		fprintf(stderr, "       %s -ps filename\n", prog);
		exit(1);
	}
	filename = argv[1];
	if (argc > 2) {
		if (strncasecmp(argv[1], "-ps", 3) == 0) {
			filename = argv[2];
			ortepmain_(filename);
			saveas_postscript(filename);
			exit(0);
		}
	}

	prefsize(650, 550);
	maxsize(650, 550);
	minsize(650, 550);
	winopen(filename);
	RGBmode();
	doublebuffer(1);
	backbuffer(1);
	gconfig();

	fminit();
	if (!(fh = fmfindfont("Times-Roman"))) {
		fprintf(stderr, "Can't find Helvetica font.\n");
		exit();
	}

	qdevice(ESCKEY);
	qdevice(WINQUIT);
	qdevice(WINSHUT);
	qreset();
	ortepmain_(filename);
	redraw_scene();
	while (1) {
		if (qtest()) {
			dev = qread(&val);
			switch (dev) {
			case REDRAW:
				ortepmain_(filename);
				redraw_scene();
				break;
			case ESCKEY:
			case WINQUIT:
			case WINSHUT:
				exit(0);
				break;
			}
		}
		sginap(1);
	}
}

static int	redraw_scene (void)
{
	register int	i;
	int	lw;
	double	height;
	float	v1[2], v2[2];
	fmfonthandle	fnt;
	fmfontinfo	info;

	cpack(0xFFFFFF);
	clear();
	cpack(0x0);
	lw = MAX(ROUND(pensize), 1);
	linewidth(lw);

	if (nlines > 0) {
		for(i=0;i 0) {
		height = 12.0;
		fnt = fmscalefont(fh, height);
		fmgetfontinfo(fnt, &info);
		fmsetfont(fnt);
		for(i=0;i
  
Modified: Wed Apr 6 16:00:00 1994 GMT
Page accessed 8649 times since Sat Apr 17 21:23:58 1999 GMT