home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-25 | 29.2 KB | 1,316 lines |
- Newsgroups: comp.sources.misc
- organization: Pixar -- Marin County, California
- subject: v11i079: Gnuplot 2.0 - 14 of 14
- From: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 11, Issue 79
- Submitted-by: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
- Archive-name: gnuplot2/part14
-
- This is gnuplot.sh14 (whew!!)
-
- --- CUT HERE ---
- #! /bin/sh
- echo x - translate/plot.h
- sed 's/^X//' >translate/plot.h <<'*-*-END-of-translate/plot.h-*-*'
- X/*
- X *
- X * gnutex/gnuplot translator -- plot.h
- X *
- X * By David Kotz, 1990.
- X * Department of Computer Science, Duke University, Durham, NC 27706.
- X * Mail to dfk@cs.duke.edu.
- X */
- X
- X#define PROGRAM "gnut2p"
- X#define PROMPT "gnut2p>"
- X
- X#define TRUE 1
- X#define FALSE 0
- X
- X#define Pi 3.141592653589793
- X
- X#define MAX_PLOTS 16 /* max number of overlapping plots */
- X#define MAX_LINE_LEN 512 /* maximum number of chars allowed on line */
- X#define MAX_TOKENS 200
- X#define MAX_ID_LEN 200 /* max length of an identifier (long for files)*/
- X
- X#ifdef PC
- X#define MAX_UDFS 20 /* max number of user-defined functions */
- X#else /* PC */
- X#define MAX_UDFS 100
- X#endif /* PC */
- X
- X#define MAX_STYLES 20 /* max number of user-defined styles */
- X#define MAX_KEYS 16 /* max number of entries in key */
- X#define MAX_VALUES 50 /* max number of user-defined constants */
- X#define MAX_AT_LEN 100 /* max number of entries in action table */
- X#define STACK_DEPTH 100
- X#define NO_CARET (-1)
- X
- X#define SAMPLES 160 /* default number of samples for a plot */
- X#define ZERO 1e-8 /* default for 'zero' set option */
- X
- X/*
- X * note about HUGE: this number is just used as a flag for really
- X * big numbers, so it doesn't have to be the absolutely biggest number
- X * on the machine.
- X */
- X
- X#ifdef PC
- X#define HUGE 1e38
- X#endif /* PC */
- X
- X#define END_OF_COMMAND (c_token == num_tokens || equals(c_token,";"))
- X#define push(arg) f_pushc(arg) /* same thing! */
- X
- X#define top_of_stack stack[s_p]
- X
- Xtypedef int BOOLEAN;
- Xtypedef int (*FUNC_PTR)();
- X
- Xenum {
- X C_PI, NEXT_VALUE
- X};
- X
- Xenum operators {
- X PUSH, PUSHC, PUSHD, CALL, TERNIARY, LNOT, BNOT, UMINUS, LOR, LAND, BOR,
- X XOR, BAND, EQ, NE, GT, LT, GE, LE, PLUS, MINUS, MULT, DIV, MOD, POWER,
- X SF_START
- X};
- X
- Xenum DATA_TYPES {
- X INT, CMPLX
- X};
- X
- Xenum PLOT_TYPES {
- X FUNC, DATA
- X};
- X
- Xenum PLOT_STYLE {
- X LINES, POINTS, IMPULSES, LINESPOINTS, DOTS
- X};
- X#define FIXED_STYLES ((int)DOTS) /* highest numbered fixed style */
- X
- Xstruct cmplx {
- X double real, imag;
- X};
- X
- Xstruct value {
- X enum DATA_TYPES type;
- X union {
- X char *str_val;
- X int int_val;
- X struct cmplx cmplx_val;
- X } v;
- X};
- X
- Xstruct lexical_unit {
- X BOOLEAN is_token; /* true if token, false if a value */
- X struct value l_val;
- X int start_index; /* index of first char in token */
- X int length; /* length of token in chars */
- X};
- X
- Xstruct at_entry { /* action table entry */
- X int index; /* index into function table */
- X struct value arg;
- X};
- X
- Xstruct at_type {
- X int count;
- X struct at_entry actions[MAX_AT_LEN];
- X};
- X
- Xstruct ft_entry { /* standard function table entry */
- X char *ft_name; /* pointer to name of this function */
- X FUNC_PTR funct; /* address of function to call */
- X};
- X
- Xstruct udft_entry { /* user-defined function table entry */
- X char udft_name[MAX_ID_LEN+1];/* name of this function entry */
- X struct at_type at; /* action table to execute */
- X char definition[MAX_LINE_LEN+1]; /* definition of function as typed */
- X struct value dummy_value;/* current value of dummy variable */
- X};
- X
- Xstruct vt_entry { /* value table entry */
- X char vt_name[MAX_ID_LEN+1];/* name of this value entry */
- X BOOLEAN vt_undef; /* true if not defined yet */
- X struct value vt_value; /* value it has */
- X};
- X
- Xstruct st_entry { /* style table entry */
- X char st_name[MAX_ID_LEN+1];/* name of this style entry */
- X BOOLEAN st_undef; /* true if not defined yet */
- X char st_point[MAX_ID_LEN+1]; /* string for point */
- X float st_spacing; /* spacing of seqence */
- X short st_length; /* length of sequence */
- X#define MAX_STYLE_SEQ_LENGTH 5
- X char st_seq[MAX_STYLE_SEQ_LENGTH][MAX_ID_LEN+1]; /* dot sequence */
- X};
- Xextern int next_style;
- X
- Xstruct curve_points {
- X enum PLOT_TYPES plot_type;
- X unsigned int plot_style; /* now an int to include user-defined styles */
- X char def[MAX_LINE_LEN + 1];
- X char title[MAX_LINE_LEN + 1];
- X};
- X
- Xstruct termentry {
- X char name[MAX_ID_LEN + 1];
- X unsigned int xmax,ymax,v_char,h_char,v_tic,h_tic;
- X FUNC_PTR init,reset,text,graphics,move,vector,linetype,lrput_text,
- X ulput_text,point;
- X FUNC_PTR xyput_text, xtick_text, ytick_text;
- X FUNC_PTR plotstyle;
- X};
- X
- X/*
- X * SS$_NORMAL is "normal completion", STS$M_INHIB_MSG supresses
- X * printing a status message.
- X * SS$_ABORT is the general abort status code.
- X from: Martin Minow
- X decvax!minow
- X */
- X#ifdef vms
- X#include <ssdef.h>
- X#include <stsdef.h>
- X#define IO_SUCCESS (SS$_NORMAL | STS$M_INHIB_MSG)
- X#define IO_ERROR SS$_ABORT
- X#endif /* vms */
- X
- X#ifndef IO_SUCCESS /* DECUS or VMS C will have defined these already */
- X#define IO_SUCCESS 0
- X#endif
- X#ifndef IO_ERROR
- X#define IO_ERROR 1
- X#endif
- *-*-END-of-translate/plot.h-*-*
- echo x - translate/scanner.c
- sed 's/^X//' >translate/scanner.c <<'*-*-END-of-translate/scanner.c-*-*'
- X/*
- X *
- X * G N U P L O T -- scanner.c
- X *
- X * Copyright (C) 1986 Colin Kelley, Thomas Williams
- X *
- X * You may use this code as you wish if credit is given and this message
- X * is retained.
- X *
- X * Please e-mail any useful additions to vu-vlsi!plot so they may be
- X * included in later releases.
- X *
- X * This file should be edited with 4-column tabs! (:set ts=4 sw=4 in vi)
- X */
- X/*
- X * Modifications for LaTeX and other support by David Kotz, 1988.
- X * Department of Computer Science, Duke University, Durham, NC 27706.
- X * Mail to dfk@cs.duke.edu.
- X */
- X
- X#include <stdio.h>
- X#include <ctype.h>
- X#include "plot.h"
- X
- X#ifdef vms
- X
- X#include stdio
- X#include descrip
- X#include errno
- X
- X#define MAILBOX "PLOT$MAILBOX"
- X#define pclose(f) fclose(f)
- X
- X#endif /* vms */
- X
- X
- X#ifndef STDOUT
- X#define STDOUT 1
- X#endif
- X
- X#define LBRACE '{'
- X#define RBRACE '}'
- X
- X#define APPEND_TOKEN {token[t_num].length++; current++;}
- X
- X#define SCAN_IDENTIFIER while (isalpha(expression[current + 1]) ||\
- X isdigit(expression[current + 1]))\
- X APPEND_TOKEN
- X
- Xextern struct lexical_unit token[MAX_TOKENS];
- X
- Xstatic int t_num; /* number of token I'm working on */
- Xint comment_pos; /* position of comment in string (-1 == none) */
- X
- Xchar *strcat(), *strcpy();
- X
- X/*
- X * scanner() breaks expression[] into lexical units, storing them in token[].
- X * The total number of tokens found is returned as the function value.
- X * Scanning will stop when '\0' is found in expression[], or when token[]
- X * is full.
- X *
- X * Scanning is performed by following rules:
- X *
- X * Current char token should contain
- X * ------------- -----------------------
- X * 1. alpha all following alpha-numerics
- X * 2. digit 0 or more following digits, 0 or 1 decimal point,
- X * 0 or more digits, 0 or 1 'e' or 'E',
- X * 0 or more digits.
- X * 3. ^,+,-,/ only current char
- X * %,~,(,)
- X * [,],;,:,
- X * ?,comma
- X * 4. &,|,=,* current char; also next if next is same
- X * 5. !,<,> current char; also next if next is =
- X * 6. ", ' all chars up until matching quote
- X * 7. # this token cuts off scanning of the line (DFK).
- X *
- X * white space between tokens is ignored
- X */
- Xscanner(expression)
- Xchar expression[];
- X{
- Xregister int current; /* index of current char in expression[] */
- Xregister int quote;
- Xchar brace;
- X
- X comment_pos = -1; /* initialize to no comment found */
- X
- X for (current = t_num = 0;
- X t_num < MAX_TOKENS && expression[current] != '\0';
- X current++) {
- Xagain:
- X if (isspace(expression[current]))
- X continue; /* skip the whitespace */
- X token[t_num].start_index = current;
- X token[t_num].length = 1;
- X token[t_num].is_token = TRUE; /* to start with...*/
- X
- X if (expression[current] == '`') {
- X substitute(&expression[current],MAX_LINE_LEN - current);
- X goto again;
- X }
- X if (isalpha(expression[current])) {
- X SCAN_IDENTIFIER;
- X } else if (isdigit(expression[current]) ||
- X expression[current] == '.') {
- X token[t_num].is_token = FALSE;
- X token[t_num].length = get_num(&expression[current]);
- X current += (token[t_num].length - 1);
- X } else if (expression[current] == LBRACE) {
- X token[t_num].is_token = FALSE;
- X token[t_num].l_val.type = CMPLX;
- X if ((sscanf(&expression[++current],"%lf , %lf %c",
- X &token[t_num].l_val.v.cmplx_val.real,
- X &token[t_num].l_val.v.cmplx_val.imag,
- X &brace) != 3) || (brace != RBRACE))
- X int_error("invalid complex constant",t_num);
- X token[t_num].length += 2;
- X while (expression[++current] != RBRACE) {
- X token[t_num].length++;
- X if (expression[current] == '\0')
- X int_error("no matching '}'", t_num);
- X }
- X } else if (expression[current] == '\'' || expression[current] == '\"') {
- X token[t_num].length++;
- X quote = expression[current];
- X while (expression[++current] != quote) {
- X if (expression[current] == '\0')
- X int_error("unmatched quote",t_num);
- X token[t_num].length++;
- X }
- X } else switch (expression[current]) {
- X case '#': /* DFK: add comments to gnutex */
- X comment_pos = current; /* remember position */
- X goto endline; /* ignore the rest of the line */
- X case '^':
- X case '+':
- X case '-':
- X case '/':
- X case '%':
- X case '~':
- X case '(':
- X case ')':
- X case '[':
- X case ']':
- X case ';':
- X case ':':
- X case '?':
- X case ',':
- X break;
- X case '&':
- X case '|':
- X case '=':
- X case '*':
- X if (expression[current] ==
- X expression[current + 1])
- X APPEND_TOKEN;
- X break;
- X case '!':
- X case '<':
- X case '>':
- X if (expression[current + 1] == '=')
- X APPEND_TOKEN;
- X break;
- X default:
- X int_error("invalid character",t_num);
- X }
- X ++t_num; /* next token if not white space */
- X }
- X
- Xendline: /* comments jump here to ignore line */
- X
- X/* Now kludge an extra token which points to '\0' at end of expression[].
- X This is useful so printerror() looks nice even if we've fallen off the
- X line. */
- X
- X token[t_num].start_index = current;
- X token[t_num].length = 0;
- X return(t_num);
- X}
- X
- X
- Xget_num(str)
- Xchar str[];
- X{
- Xdouble atof();
- Xregister int count = 0;
- Xlong atol();
- Xregister long lval;
- X
- X token[t_num].is_token = FALSE;
- X token[t_num].l_val.type = INT; /* assume unless . or E found */
- X while (isdigit(str[count]))
- X count++;
- X if (str[count] == '.') {
- X token[t_num].l_val.type = CMPLX;
- X while (isdigit(str[++count])) /* swallow up digits until non-digit */
- X ;
- X /* now str[count] is other than a digit */
- X }
- X if (str[count] == 'e' || str[count] == 'E') {
- X token[t_num].l_val.type = CMPLX;
- X if (str[++count] == '-')
- X count++;
- X if (!isdigit(str[count])) {
- X token[t_num].start_index += count;
- X int_error("expecting exponent",t_num);
- X }
- X while (isdigit(str[++count]))
- X ;
- X }
- X if (token[t_num].l_val.type == INT) {
- X lval = atol(str);
- X if ((token[t_num].l_val.v.int_val = lval) != lval)
- X int_error("integer overflow; change to floating point",t_num);
- X } else {
- X token[t_num].l_val.v.cmplx_val.imag = 0.0;
- X token[t_num].l_val.v.cmplx_val.real = atof(str);
- X }
- X return(count);
- X}
- X
- X
- X#ifdef MSDOS
- X
- Xsubstitute()
- X{
- X int_error("substitution not supported by MS-DOS!",t_num);
- X}
- X
- X#else /* MSDOS */
- X
- Xsubstitute(str,max) /* substitute output from ` ` */
- Xchar *str;
- Xint max;
- X{
- Xregister char *last;
- Xregister int i,c;
- Xregister FILE *f;
- XFILE *popen();
- Xstatic char pgm[MAX_LINE_LEN],output[MAX_LINE_LEN];
- X
- X#ifdef vms
- Xint chan;
- Xstatic $DESCRIPTOR(pgmdsc,pgm);
- Xstatic $DESCRIPTOR(lognamedsc,MAILBOX);
- X#endif /* vms */
- X
- X i = 0;
- X last = str;
- X while (*(++last) != '`') {
- X if (*last == '\0')
- X int_error("unmatched `",t_num);
- X pgm[i++] = *last;
- X }
- X pgm[i] = '\0'; /* end with null */
- X max -= strlen(last); /* max is now the max length of output sub. */
- X
- X#ifdef vms
- X pgmdsc.dsc$w_length = i;
- X if (!((vaxc$errno = sys$crembx(0,&chan,0,0,0,0,&lognamedsc)) & 1))
- X os_error("sys$crembx failed",NO_CARET);
- X
- X if (!((vaxc$errno = lib$spawn(&pgmdsc,0,&lognamedsc,&1)) & 1))
- X os_error("lib$spawn failed",NO_CARET);
- X
- X if ((f = fopen(MAILBOX,"r")) == NULL)
- X os_error("mailbox open failed",NO_CARET);
- X#else /* vms */
- X if ((f = popen(pgm,"r")) == NULL)
- X os_error("popen failed",NO_CARET);
- X#endif /* vms */
- X
- X i = 0;
- X while ((c = getc(f)) != EOF) {
- X output[i++] = ((c == '\n') ? ' ' : c); /* newlines become blanks*/
- X if (i == max) {
- X (void) pclose(f);
- X int_error("substitution overflow", t_num);
- X }
- X }
- X (void) pclose(f);
- X if (i + strlen(last) > max)
- X int_error("substitution overflowed rest of line", t_num);
- X (void) strcpy(output+i,last+1); /* tack on rest of line to output */
- X (void) strcpy(str,output); /* now replace ` ` with output */
- X}
- X#endif /* MS-DOS */
- *-*-END-of-translate/scanner.c-*-*
- echo x - translate/standard.c
- sed 's/^X//' >translate/standard.c <<'*-*-END-of-translate/standard.c-*-*'
- X/*
- X *
- X * G N U P L O T -- header.c
- X *
- X * Copyright (C) 1986 Thomas Williams, Colin Kelley
- X *
- X * You may use this code as you wish if credit is given and this message
- X * is retained.
- X *
- X * Please e-mail any useful additions to vu-vlsi!plot so they may be
- X * included in later releases.
- X *
- X * This file should be edited with 4-column tabs! (:set ts=4 sw=4 in vi)
- X */
- X
- X#include <math.h>
- X#include <stdio.h>
- X#include "plot.h"
- X
- Xextern BOOLEAN undefined;
- X
- X#ifdef vms
- X#include <errno.h>
- X#else
- Xextern int errno;
- X#endif /* vms */
- X
- X
- Xextern struct value stack[STACK_DEPTH];
- Xextern int s_p;
- X
- Xstruct value *pop(), *complex(), *integer();
- X
- Xdouble magnitude(), angle(), real(), imag();
- X
- X
- Xf_real()
- X{
- Xstruct value a;
- X push( complex(&a,real(pop(&a)), 0.0) );
- X}
- X
- Xf_imag()
- X{
- Xstruct value a;
- X push( complex(&a,imag(pop(&a)), 0.0) );
- X}
- X
- Xf_arg()
- X{
- Xstruct value a;
- X push( complex(&a,angle(pop(&a)), 0.0) );
- X}
- X
- Xf_conjg()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,real(&a),-imag(&a) ));
- X}
- X
- Xf_sin()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,sin(real(&a))*cosh(imag(&a)), cos(real(&a))*sinh(imag(&a))) );
- X}
- X
- Xf_cos()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,cos(real(&a))*cosh(imag(&a)), -sin(real(&a))*sinh(imag(&a))));
- X}
- X
- Xf_tan()
- X{
- Xstruct value a;
- Xregister double den;
- X (void) pop(&a);
- X den = cos(2*real(&a))+cosh(2*imag(&a));
- X push( complex(&a,sin(2*real(&a))/den, sinh(2*imag(&a))/den) );
- X}
- X
- Xf_asin()
- X{
- Xstruct value a;
- Xregister double alpha, beta, x, y;
- X (void) pop(&a);
- X x = real(&a); y = imag(&a);
- X if (y == 0.0) {
- X if (fabs(x) > 1.0) {
- X undefined = TRUE;
- X push(complex(&a,0.0, 0.0));
- X } else
- X push( complex(&a,asin(x),0.0) );
- X } else {
- X beta = sqrt((x + 1)*(x + 1) + y*y)/2 - sqrt((x - 1)*(x - 1) + y*y)/2;
- X alpha = sqrt((x + 1)*(x + 1) + y*y)/2 + sqrt((x - 1)*(x - 1) + y*y)/2;
- X push( complex(&a,asin(beta), log(alpha + sqrt(alpha*alpha-1))) );
- X }
- X}
- X
- Xf_acos()
- X{
- Xstruct value a;
- Xregister double alpha, beta, x, y;
- X (void) pop(&a);
- X x = real(&a); y = imag(&a);
- X if (y == 0.0) {
- X if (fabs(x) > 1.0) {
- X undefined = TRUE;
- X push(complex(&a,0.0, 0.0));
- X } else
- X push( complex(&a,acos(x),0.0) );
- X } else {
- X alpha = sqrt((x + 1)*(x + 1) + y*y)/2 + sqrt((x - 1)*(x - 1) + y*y)/2;
- X beta = sqrt((x + 1)*(x + 1) + y*y)/2 - sqrt((x - 1)*(x - 1) + y*y)/2;
- X push( complex(&a,acos(beta), log(alpha + sqrt(alpha*alpha-1))) );
- X }
- X}
- X
- Xf_atan()
- X{
- Xstruct value a;
- Xregister double x, y;
- X (void) pop(&a);
- X x = real(&a); y = imag(&a);
- X if (y == 0.0)
- X push( complex(&a,atan(x), 0.0) );
- X else if (x == 0.0 && fabs(y) == 1.0) {
- X undefined = TRUE;
- X push(complex(&a,0.0, 0.0));
- X } else
- X push( complex(&a,atan(2*x/(1-x*x-y*y)),
- X log((x*x+(y+1)*(y+1))/(x*x+(y-1)*(y-1)))/4) );
- X}
- X
- Xf_sinh()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,sinh(real(&a))*cos(imag(&a)), cosh(real(&a))*sin(imag(&a))) );
- X}
- X
- Xf_cosh()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,cosh(real(&a))*cos(imag(&a)), sinh(real(&a))*sin(imag(&a))) );
- X}
- X
- Xf_tanh()
- X{
- Xstruct value a;
- Xregister double den;
- X (void) pop(&a);
- X den = cosh(2*real(&a)) + cos(2*imag(&a));
- X push( complex(&a,sinh(2*real(&a))/den, sin(2*imag(&a))/den) );
- X}
- X
- Xf_int()
- X{
- Xstruct value a;
- X push( integer(&a,(int)real(pop(&a))) );
- X}
- X
- X
- Xf_abs()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X switch (a.type) {
- X case INT:
- X push( integer(&a,abs(a.v.int_val)) );
- X break;
- X case CMPLX:
- X push( complex(&a,magnitude(&a), 0.0) );
- X }
- X}
- X
- Xf_sgn()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X switch(a.type) {
- X case INT:
- X push( integer(&a,(a.v.int_val > 0) ? 1 :
- X (a.v.int_val < 0) ? -1 : 0) );
- X break;
- X case CMPLX:
- X push( integer(&a,(a.v.cmplx_val.real > 0.0) ? 1 :
- X (a.v.cmplx_val.real < 0.0) ? -1 : 0) );
- X break;
- X }
- X}
- X
- X
- Xf_sqrt()
- X{
- Xstruct value a;
- X double mag, ang;
- X (void) pop(&a);
- X mag = sqrt(magnitude(&a));
- X if ( (ang = angle(&a)) < 0.0)
- X ang += 2*Pi;
- X ang /= 2;
- X push( complex(&a,mag*cos(ang), mag*sin(ang)) );
- X}
- X
- X
- Xf_exp()
- X{
- Xregister double mag, ang;
- Xstruct value a;
- X (void) pop(&a);
- X mag = exp(real(&a));
- X ang = imag(&a);
- X push( complex(&a,mag*cos(ang), mag*sin(ang)) );
- X}
- X
- X
- Xf_log10()
- X{
- Xstruct value a;
- Xregister double l10;;
- X (void) pop(&a);
- X l10 = log(10.0); /***** replace with a constant! ******/
- X push( complex(&a,log(magnitude(&a))/l10, angle(&a)/l10) );
- X}
- X
- X
- Xf_log()
- X{
- Xstruct value a;
- X (void) pop(&a);
- X push( complex(&a,log(magnitude(&a)), angle(&a)) );
- X}
- X
- Xf_besj0() /* j0(a) = sin(a)/a */
- X{
- Xstruct value a;
- X a = top_of_stack;
- X f_sin();
- X push(&a);
- X f_div();
- X}
- X
- X
- Xf_besj1() /* j1(a) = sin(a)/(a**2) - cos(a)/a */
- X{
- Xstruct value a;
- X a = top_of_stack;
- X f_sin();
- X push(&a);
- X push(&a);
- X f_mult();
- X f_div();
- X push(&a);
- X f_cos();
- X push(&a);
- X f_div();
- X f_minus();
- X}
- X
- X
- Xf_besy0() /* y0(a) = -cos(a)/a */
- X{
- Xstruct value a;
- X a = top_of_stack;
- X f_cos();
- X push(&a);
- X f_div();
- X f_uminus();
- X}
- X
- X
- Xf_besy1() /* y1(a) = -cos(a)/(a**2) - sin(a)/a */
- X{
- Xstruct value a;
- X
- X a = top_of_stack;
- X f_cos();
- X push(&a);
- X push(&a);
- X f_mult();
- X f_div();
- X push(&a);
- X f_sin();
- X push(&a);
- X f_div();
- X f_plus();
- X f_uminus();
- X}
- X
- X
- Xf_floor()
- X{
- Xstruct value a;
- X
- X (void) pop(&a);
- X switch (a.type) {
- X case INT:
- X push( integer(&a,(int)floor((double)a.v.int_val)));
- X break;
- X case CMPLX:
- X push( complex(&a,floor(a.v.cmplx_val.real),
- X floor(a.v.cmplx_val.imag)) );
- X }
- X}
- X
- X
- X
- Xf_ceil()
- X{
- Xstruct value a;
- X
- X (void) pop(&a);
- X switch (a.type) {
- X case INT:
- X push( integer(&a,(int)ceil((double)a.v.int_val)));
- X break;
- X case CMPLX:
- X push( complex(&a,ceil(a.v.cmplx_val.real), ceil(a.v.cmplx_val.imag)) );
- X }
- X}
- *-*-END-of-translate/standard.c-*-*
- echo x - translate/test1
- sed 's/^X//' >translate/test1 <<'*-*-END-of-translate/test1-*-*'
- Xset terminal latex
- Xset output "plot.tex" # a short comment here
- Xset size 4,2.75; help foo; set term latex
- Xset title "Effect of Prefetching Lead on Total execution time"
- X!echo this is a shell command
- Xset ylabel "Total\\Execution\\time\\(seconds)" 1
- Xset xlabel "Minimum prefetching lead in blocks"
- X# full-line comment goes here
- Xset style lp1 "\scriptsize 1" 7 "\circle*{1}"
- Xset style lp2 "\scriptsize 2" 7 "\circle*{1}"
- Xset style lp3 "\scriptsize 3" 7 "\circle*{1}"
- Xset style lp4 "\scriptsize 4" 7 "\circle*{1}"
- Xset noclip
- Xplot [0:90] [0:10] "points.gps" w lp1, "points.gw" w lp2, \
- X "points.lps" w lp3, "points.lw" w lp4
- Xlabel 10,7 "gfp"
- Xlabel 80,5.5 "gw"
- Xlabel 70,3.4 "lfp"
- Xlabel 40,1.8 "lw"
- Xplot [0:pi] sin(x) w points
- Xkey 1,.5 "sin(x)" w points, "" w lines, "dummy" w lp1
- *-*-END-of-translate/test1-*-*
- echo x - translate/test2
- sed 's/^X//' >translate/test2 <<'*-*-END-of-translate/test2-*-*'
- Xset terminal latex
- Xset output "plot.tex" # a short comment here
- Xset size 4,2.75; help foo; set term latex
- Xset title "Effect of Prefetching
- Xset ylabel "Total\\Execution\\time\\(seconds)" 1
- Xset xlabel "Minimum prefetching lead in blocks"
- X# full-line comment goes here
- Xset style lp1 "\scriptsize 1" 7 "\circle*{1}"
- Xset style lp2 "\scriptsize 2" 7 "\circle*{1}"
- Xset style lp3 "\scriptsize 3" 7 "\circle*{1}"
- Xset style lp4 "\scriptsize 4" 7
- Xset noclip
- Xplot [0:90] [0:10] "points.gps" w lp1, "points.gw" w lp2, \
- X "points.lps" w lp3, "points.lw" w lp4,
- Xlabel 10,7 "gfp"
- Xlabel 80,5.5 "gw"
- Xlabel ,3.4 "lfp"
- Xlabel 40,1.8 "lw"
- Xplot [0:pi] sin(x) w points
- Xkey 1,.5 "sin(x)" w points, "" w lines, "dummy" w lp1
- *-*-END-of-translate/test2-*-*
- echo x - translate/util.c
- sed 's/^X//' >translate/util.c <<'*-*-END-of-translate/util.c-*-*'
- X/*
- X *
- X * G N U P L O T -- util.c
- X *
- X * Copyright (C) 1986 Thomas Williams, Colin Kelley
- X *
- X * You may use this code as you wish if credit is given and this message
- X * is retained.
- X *
- X * Please e-mail any useful additions to vu-vlsi!plot so they may be
- X * included in later releases.
- X *
- X * This file should be edited with 4-column tabs! (:set ts=4 sw=4 in vi)
- X */
- X
- X#include <ctype.h>
- X#include <setjmp.h>
- X#include <stdio.h>
- X#include <errno.h>
- X#include "plot.h"
- X
- X#ifndef vms
- Xextern int errno, sys_nerr;
- Xextern char *sys_errlist[];
- X#endif /* vms */
- X
- Xextern int inline; /* line number of input */
- Xextern char input_line[MAX_LINE_LEN];
- Xextern struct lexical_unit token[MAX_TOKENS];
- Xextern jmp_buf env; /* from plot.c */
- X
- X/*
- X * equals() compares string value of token number t_num with str[], and
- X * returns TRUE if they are identical.
- X */
- Xequals(t_num, str)
- Xint t_num;
- Xchar *str;
- X{
- Xregister int i;
- X
- X if (!token[t_num].is_token)
- X return(FALSE); /* must be a value--can't be equal */
- X for (i = 0; i < token[t_num].length; i++) {
- X if (input_line[token[t_num].start_index+i] != str[i])
- X return(FALSE);
- X }
- X /* now return TRUE if at end of str[], FALSE if not */
- X return(str[i] == '\0');
- X}
- X
- X
- X
- X/*
- X * almost_equals() compares string value of token number t_num with str[], and
- X * returns TRUE if they are identical up to the first $ in str[].
- X */
- Xalmost_equals(t_num, str)
- Xint t_num;
- Xchar *str;
- X{
- Xregister int i;
- Xregister int after = 0;
- Xregister start = token[t_num].start_index;
- Xregister length = token[t_num].length;
- X
- X if (!token[t_num].is_token)
- X return(FALSE); /* must be a value--can't be equal */
- X for (i = 0; i < length + after; i++) {
- X if (str[i] != input_line[start + i]) {
- X if (str[i] != '$')
- X return(FALSE);
- X else {
- X after = 1;
- X start--; /* back up token ptr */
- X }
- X }
- X }
- X
- X /* i now beyond end of token string */
- X
- X return(after || str[i] == '$' || str[i] == '\0');
- X}
- X
- X
- X
- Xisstring(t_num)
- Xint t_num;
- X{
- X
- X return(token[t_num].is_token &&
- X (input_line[token[t_num].start_index] == '\'' ||
- X input_line[token[t_num].start_index] == '\"'));
- X}
- X
- X
- Xisnumber(t_num)
- Xint t_num;
- X{
- X return(!token[t_num].is_token);
- X}
- X
- X
- Xisletter(t_num)
- Xint t_num;
- X{
- X return(token[t_num].is_token &&
- X (isalpha(input_line[token[t_num].start_index])));
- X}
- X
- X
- X/*
- X * is_definition() returns TRUE if the next tokens are of the form
- X * identifier =
- X * -or-
- X * identifier ( identifer ) =
- X */
- Xis_definition(t_num)
- Xint t_num;
- X{
- X return (isletter(t_num) &&
- X (equals(t_num+1,"=") || /* variable */
- X (equals(t_num+1,"(") && /* function */
- X isletter(t_num+2) &&
- X equals(t_num+3,")") &&
- X equals(t_num+4,"=") )
- X ));
- X}
- X
- X
- X
- X/*
- X * copy_str() copies the string in token number t_num into str, appending
- X * a null. No more than MAX_ID_LEN chars are copied.
- X */
- Xcopy_str(str, t_num)
- Xchar str[];
- Xint t_num;
- X{
- Xregister int i = 0;
- Xregister int start = token[t_num].start_index;
- Xregister int count;
- X
- X if ((count = token[t_num].length) > MAX_ID_LEN)
- X count = MAX_ID_LEN;
- X do {
- X str[i++] = input_line[start++];
- X } while (i != count);
- X str[i] = '\0';
- X}
- X
- X
- X/*
- X * quote_str() does the same thing as copy_str, except it ignores the
- X * quotes at both ends. This seems redundant, but is done for
- X * efficency.
- X */
- Xquote_str(str, t_num)
- Xchar str[];
- Xint t_num;
- X{
- Xregister int i = 0;
- Xregister int start = token[t_num].start_index + 1;
- Xregister int count;
- X
- X if ((count = token[t_num].length - 2) > MAX_ID_LEN)
- X count = MAX_ID_LEN;
- X while (i != count) {
- X str[i++] = input_line[start++];
- X }
- X str[i] = '\0';
- X}
- X
- X/*
- X * capture() returns in str[] the the part of input_line[] which lies
- X * between the begining of token[start] and end of token[end]
- X */
- Xcapture(str,start,end)
- Xchar str[];
- Xint start,end;
- X{
- Xregister int i,j;
- Xchar *s = str;
- X
- X j = token[end].start_index + token[end].length;
- X for (i = token[start].start_index; i < j && input_line[i] != '\0'; i++)
- X *s++ = input_line[i];
- X *s = '\0';
- X}
- X
- X
- Xconvert(val_ptr, t_num)
- Xstruct value *val_ptr;
- Xint t_num;
- X{
- X *val_ptr = token[t_num].l_val;
- X}
- X
- X
- X
- Xshow_value(fp,val)
- XFILE *fp;
- Xstruct value *val;
- X{
- X switch(val->type) {
- X case INT:
- X fprintf(fp,"%d",val->v.int_val);
- X break;
- X case CMPLX:
- X if (val->v.cmplx_val.imag != 0.0 )
- X fprintf(fp,"{%g, %g}",
- X val->v.cmplx_val.real,val->v.cmplx_val.imag);
- X else
- X fprintf(fp,"%g", val->v.cmplx_val.real);
- X break;
- X default:
- X int_error("unknown type in show_value()",NO_CARET);
- X }
- X}
- X
- X
- Xdouble
- Xreal(val) /* returns the real part of val */
- Xstruct value *val;
- X{
- X switch(val->type) {
- X case INT:
- X return((double) val->v.int_val);
- X break;
- X case CMPLX:
- X return(val->v.cmplx_val.real);
- X }
- X int_error("unknown type in real()",NO_CARET);
- X /* NOTREACHED */
- X}
- X
- X
- Xdouble
- Ximag(val) /* returns the imag part of val */
- Xstruct value *val;
- X{
- X switch(val->type) {
- X case INT:
- X return(0.0);
- X break;
- X case CMPLX:
- X return(val->v.cmplx_val.imag);
- X }
- X int_error("unknown type in real()",NO_CARET);
- X /* NOTREACHED */
- X}
- X
- X
- X
- Xdouble
- Xmagnitude(val) /* returns the magnitude of val */
- Xstruct value *val;
- X{
- X double sqrt();
- X
- X switch(val->type) {
- X case INT:
- X return((double) abs(val->v.int_val));
- X break;
- X case CMPLX:
- X return(sqrt(val->v.cmplx_val.real*
- X val->v.cmplx_val.real +
- X val->v.cmplx_val.imag*
- X val->v.cmplx_val.imag));
- X }
- X int_error("unknown type in magnitude()",NO_CARET);
- X /* NOTREACHED */
- X}
- X
- X
- X
- Xdouble
- Xangle(val) /* returns the angle of val */
- Xstruct value *val;
- X{
- X double atan2();
- X
- X switch(val->type) {
- X case INT:
- X return((val->v.int_val > 0) ? 0.0 : Pi);
- X break;
- X case CMPLX:
- X if (val->v.cmplx_val.imag == 0.0) {
- X if (val->v.cmplx_val.real >= 0.0)
- X return(0.0);
- X else
- X return(Pi);
- X }
- X return(atan2(val->v.cmplx_val.imag,
- X val->v.cmplx_val.real));
- X }
- X int_error("unknown type in angle()",NO_CARET);
- X /* NOTREACHED */
- X}
- X
- X
- Xstruct value *
- Xcomplex(a,realpart,imagpart)
- Xstruct value *a;
- Xdouble realpart, imagpart;
- X{
- X a->type = CMPLX;
- X a->v.cmplx_val.real = realpart;
- X a->v.cmplx_val.imag = imagpart;
- X return(a);
- X}
- X
- X
- Xstruct value *
- Xinteger(a,i)
- Xstruct value *a;
- Xint i;
- X{
- X a->type = INT;
- X a->v.int_val = i;
- X return(a);
- X}
- X
- X/* Lower-case the given string (DFK) */
- X/* Done in place. */
- Xvoid
- Xlower_case(s)
- X char *s;
- X{
- X register char *p = s;
- X
- X while (*p != '\0') {
- X if (*p >= 'A' && *p <= 'Z')
- X *p = *p - 'A' + 'a';
- X p++;
- X }
- X}
- X
- X
- Xint space_count(line, t_num)
- X int line;
- X int t_num;
- X{
- X char string[20];
- X
- X sprintf(string, "---%d: ", line);
- X return(strlen(string) + token[t_num].start_index);
- X}
- X
- Xshow_line(always)
- X BOOLEAN always;
- X{
- X static int last_line_printed = 0; /* number of line printed out last. */
- X
- X if (always || inline != last_line_printed) {
- X /* print line if not printed yet */
- X fprintf(stderr,"\n---%d: %s\n", inline, input_line);
- X last_line_printed = inline;
- X }
- X}
- X
- Xos_error(str,t_num)
- Xchar str[];
- Xint t_num;
- X{
- X#ifdef vms
- Xstatic status[2] = {1, 0}; /* 1 is count of error msgs */
- X#endif
- X
- Xregister int i;
- Xint count;
- X
- X show_line(TRUE);
- X
- X if (t_num != NO_CARET) { /* put caret under error */
- X count = space_count(inline, t_num);
- X for (i = 0; i < count; i++) {
- X (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
- X }
- X (void) putc('^',stderr);
- X (void) putc('\n',stderr);
- X }
- X
- X fprintf(stderr,"###%d: %s\n",str);
- X
- X#ifdef vms
- X status[1] = vaxc$errno;
- X sys$putmsg(status);
- X (void) putc('\n',stderr);
- X#else
- X if (errno >= sys_nerr)
- X fprintf(stderr, "unknown errno %d\n\n", errno);
- X else
- X fprintf(stderr,"(%s)\n",sys_errlist[errno]);
- X#endif
- X
- X longjmp(env, TRUE); /* bail out to command line */
- X}
- X
- X/* fatal error for this line; no return */
- Xint_error(str,t_num)
- Xchar str[];
- Xint t_num;
- X{
- X register int i;
- X int count;
- X
- X show_line(TRUE);
- X
- X if (t_num != NO_CARET) { /* put caret under error */
- X count = space_count(inline, t_num);
- X for (i = 0; i < count; i++) {
- X (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
- X }
- X (void) putc('^',stderr);
- X (void) putc('\n',stderr);
- X }
- X
- X fprintf(stderr,"###%d: %s\n", inline, str);
- X
- X longjmp(env, TRUE); /* bail out to command line */
- X}
- X
- X/* print an error for this line and return */
- Xerr_msg(str)
- X char str[];
- X{
- X show_line(FALSE);
- X fprintf(stderr,"***%d: %s\n", inline, str);
- X}
- X
- X
- X/* find char c in string str; return p such that str[p]==c;
- X * if c not in str then p=strlen(str)
- X */
- Xint
- Xinstring(str, c)
- X char *str;
- X char c;
- X{
- X int pos = 0;
- X
- X while (str != NULL && *str != '\0' && c != *str) {
- X str++;
- X pos++;
- X }
- X return (pos);
- X}
- X
- *-*-END-of-translate/util.c-*-*
- exit
-
-
-