jdc@naucse.UUCP (John Campbell) (09/04/89)
#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 6 (of 7)." # Contents: ./command.c ./docs/gnuplot.hlp # Wrapped by jdc@naucse on Mon Sep 4 09:22:36 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f './command.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./command.c'\" else echo shar: Extracting \"'./command.c'\" \(23912 characters\) sed "s/^X//" >'./command.c' <<'END_OF_FILE' X/* X * X * G N U P L O T -- command.c X * X * Copyright (C) 1986, 1987 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 <stdio.h> X#include <math.h> X X#ifdef MSDOS X#include <process.h> X#endif X X#include "plot.h" X X#ifndef STDOUT X#define STDOUT 1 X#endif X X/* X * global variables to hold status of 'set' options X * X */ XBOOLEAN polar = FALSE; XBOOLEAN autoscale = TRUE; Xchar dummy_var[MAX_ID_LEN+1] = "x"; Xenum PLOT_STYLE data_style = POINTS, X func_style = LINES; XBOOLEAN log_x = FALSE, X log_y = FALSE; XFILE* outfile; Xchar outstr[MAX_ID_LEN+1] = "STDOUT"; Xint samples = SAMPLES; Xint term = 0; /* unknown term is 0 */ Xdouble xmin = -10.0, X xmax = 10.0, X ymin = -10.0, X ymax = 10.0; Xdouble loff = 0.0, X roff = 0.0, X toff = 0.0, X boff = 0.0; Xdouble zero = ZERO; /* zero threshold, not 0! */ X X XBOOLEAN screen_ok; XBOOLEAN term_init; XBOOLEAN undefined; X X/* X * instead of <strings.h> X */ X Xchar *gets(),*getenv(); Xchar *strcpy(),*strncpy(),*strcat(); X Xchar *malloc(); X Xdouble magnitude(),angle(),real(),imag(); Xstruct value *const_express(), *pop(), *complex(); Xstruct at_type *temp_at(), *perm_at(); Xstruct udft_entry *add_udf(); Xstruct udvt_entry *add_udv(); X Xextern struct termentry term_tbl[]; X Xstruct lexical_unit token[MAX_TOKENS]; Xchar input_line[MAX_LINE_LEN+1] = "set term "; Xchar c_dummy_var[MAX_ID_LEN+1]; /* current dummy var */ Xint num_tokens, c_token; X Xstruct curve_points *first_plot = NULL; Xstruct udft_entry plot_func, *dummy_func; X Xstatic char replot_line[MAX_LINE_LEN+1]; Xstatic int plot_token; /* start of 'plot' command */ Xstatic char help[MAX_LINE_LEN] = HELP; X Xcom_line() X{ X read_line(); X X screen_ok = TRUE; /* so we can flag any new output */ X X do_line(); X} X X Xdo_line() /* also used in load_file */ X{ X if (is_comment(input_line[0])) X return; X if (is_system(input_line[0])) { X do_system(); X fputs("!\n",stderr); X return; X } X num_tokens = scanner(input_line); X c_token = 0; X while(c_token < num_tokens) { X command(); X if (c_token < num_tokens) /* something after command */ X if (equals(c_token,";")) X c_token++; X else X int_error("';' expected",c_token); X } X} X X X Xcommand() X{ Xstatic char sv_file[MAX_LINE_LEN+1]; X /* string holding name of save or load file */ X X c_dummy_var[0] = '\0'; /* no dummy variable */ X X if (is_definition(c_token)) X define(); X else if (equals(c_token,"help") || equals(c_token,"?")) { X register int len; X register char *help_ptr; X X c_token++; X if ((help_ptr = getenv("GNUHELP"))) /* initial command */ X (void) strncpy(help,help_ptr,sizeof(help) - 1); X else X (void) strncpy(help,HELP,sizeof(help) - 1); X X while (!(END_OF_COMMAND)) { X len = strlen(help); X help[len] = ' '; /* put blank between help segments */ X copy_str(help+len+1,c_token++); X } X do_help(); X screen_ok = FALSE; X c_token++; X } X else if (almost_equals(c_token,"pa$use")) { X struct value a; X int stime, text=0, len; X char buf[MAX_LINE_LEN+1], *ptr; X X c_token++; X stime = (int )real(const_express(&a)); X if (!(END_OF_COMMAND)) { X if (!isstring(c_token)) X int_error("expecting string",c_token); X else { X /* Unfortunately, quote_str has a ID limit. */ X len = token[c_token].length - 2; X ptr = &input_line[token[c_token].start_index+1]; X fprintf (stderr, "%.*s", len,ptr); X text = 1; X } X } X if (stime < 0) fgets (buf,MAX_LINE_LEN,stdin); /* Hold until CR hit. */ X if (stime > 0) sleep(stime); X if (text != 0 && stime >= 0) fprintf (stderr,"\n"); X c_token++; X screen_ok = FALSE; X } X else if (almost_equals(c_token,"pr$int")) { X struct value a; X X c_token++; X (void) const_express(&a); X (void) putc('\t',stderr); X disp_value(stderr,&a); X (void) putc('\n',stderr); X screen_ok = FALSE; X } X else if (almost_equals(c_token,"p$lot")) { X plot_token = c_token++; X plotrequest(); X } X else if (almost_equals(c_token,"rep$lot")) { X if (replot_line[0] == '\0') X int_error("no previous plot",c_token); X (void) strcpy(input_line,replot_line); X screen_ok = FALSE; X num_tokens = scanner(input_line); X c_token = 1; /* skip the 'plot' part */ X plotrequest(); X } X else if (almost_equals(c_token,"se$t")) X set_stuff(); X else if (almost_equals(c_token,"sh$ow")) X show_stuff(); X else if (almost_equals(c_token,"cl$ear")) { X if (!term_init) { X (*term_tbl[term].init)(); X term_init = TRUE; X } X (*term_tbl[term].graphics)(); X (*term_tbl[term].text)(); X (void) fflush(outfile); X screen_ok = FALSE; X c_token++; X } X else if (almost_equals(c_token,"she$ll")) { X do_shell(); X screen_ok = FALSE; X c_token++; X } X else if (almost_equals(c_token,"sa$ve")) { X if (almost_equals(++c_token,"f$unctions")) { X if (!isstring(++c_token)) X int_error("expecting filename",c_token); X else { X quote_str(sv_file,c_token); X save_functions(fopen(sv_file,"w")); X } X } X else if (almost_equals(c_token,"v$ariables")) { X if (!isstring(++c_token)) X int_error("expecting filename",c_token); X else { X quote_str(sv_file,c_token); X save_variables(fopen(sv_file,"w")); X } X } X else if (isstring(c_token)) { X quote_str(sv_file,c_token); X save_all(fopen(sv_file,"w")); X } X else { X int_error( X "filename or keyword 'functions' or 'variables' expected",c_token); X } X c_token++; X } X else if (almost_equals(c_token,"l$oad")) { X if (!isstring(++c_token)) X int_error("expecting filename",c_token); X else { X quote_str(sv_file,c_token); X load_file(fopen(sv_file,"r")); X /* input_line[] and token[] now destroyed! */ X c_token = num_tokens = 0; X } X } X else if (almost_equals(c_token,"ex$it") || X almost_equals(c_token,"q$uit")) { X done(IO_SUCCESS); X } X else if (!equals(c_token,";")) { /* null statement */ X int_error("invalid command",c_token); X } X} X X Xenum PLOT_STYLE Xget_style() X{ Xregister enum PLOT_STYLE ps; X X c_token++; X if (almost_equals(c_token,"l$ines")) X ps = LINES; X else if (almost_equals(c_token,"i$mpulses")) X ps = IMPULSES; X else if (almost_equals(c_token,"p$oints")) X ps = POINTS; X else X int_error("expecting 'lines', 'points', or 'impulses'",c_token); X c_token++; X return(ps); X} X X Xset_stuff() X{ Xstatic char testfile[MAX_LINE_LEN+1]; X X if (almost_equals(++c_token,"a$utoscale")) { X autoscale = TRUE; X c_token++; X } X else if (almost_equals(c_token,"noa$utoscale")) { X autoscale = FALSE; X c_token++; X } X else if (almost_equals(c_token,"po$lar")) { X polar = TRUE; X xmin = 0.0; X xmax = 2*Pi; X c_token++; X } X else if (almost_equals(c_token,"nopo$lar")) { X polar = FALSE; X xmin = -10.0; X xmax = 10.0; X c_token++; X } X else if (almost_equals(c_token,"d$ata")) { X c_token++; X if (!almost_equals(c_token,"s$tyle")) X int_error("expecting keyword 'style'",c_token); X data_style = get_style(); X } X else if (almost_equals(c_token,"d$ummy")) { X c_token++; X copy_str(dummy_var,c_token++); X } X else if (almost_equals(c_token,"f$unction")) { X c_token++; X if (!almost_equals(c_token,"s$tyle")) X int_error("expecting keyword 'style'",c_token); X func_style = get_style(); X } X else if (almost_equals(c_token,"l$ogscale")) { X c_token++; X if (equals(c_token,"x")) { X log_y = FALSE; X log_x = TRUE; X c_token++; X } X else if (equals(c_token,"y")) { X log_x = FALSE; X log_y = TRUE; X c_token++; X } X else if (equals(c_token,"xy") || equals(c_token,"yx")) { X log_x = log_y = TRUE; X c_token++; X } X else X int_error("expecting 'x', 'y', or 'xy'",c_token); X } X else if (almost_equals(c_token,"nol$ogscale")) { X log_x = log_y = FALSE; X c_token++; X } X else if (almost_equals(c_token,"of$fsets")) { X c_token++; X if (END_OF_COMMAND) { X loff = roff = toff = boff = 0.0; /* Reset offsets */ X } X else { X load_offsets (&loff,&roff,&toff,&boff); X } X } X else if (almost_equals(c_token,"o$utput")) { X register FILE *f; X X c_token++; X if (END_OF_COMMAND) { /* no file specified */ X UP_redirect (4); X#ifdef VMS X if (outfile != stdout) /* Never close stdout */ X#endif X (void) fclose(outfile); X#ifdef VMS X outfile = stdout; /* Avoid the dup... */ X#else X outfile = fdopen(dup(STDOUT), "w"); X#endif X term_init = FALSE; X (void) strcpy(outstr,"STDOUT"); X } else if (!isstring(c_token)) X int_error("expecting filename",c_token); X else { X quote_str(testfile,c_token); X if (!(f = fopen(testfile,"w"))) { X os_error("cannot open file; output not changed",c_token); X } X#ifdef VMS X if (outfile != stdout) /* Never close stdout */ X#endif X (void) fclose(outfile); X outfile = f; X term_init = FALSE; X outstr[0] = '\''; X (void) strcat(strcpy(outstr+1,testfile),"'"); X UP_redirect (1); X } X c_token++; X } X else if (almost_equals(c_token,"sa$mples")) { X register int tsamp; X struct value a; X X c_token++; X tsamp = (int)magnitude(const_express(&a)); X if (tsamp < 1) X int_error("sampling rate must be > 0; sampling unchanged", X c_token); X else { X register struct curve_points *f_p = first_plot; X X first_plot = NULL; X cp_free(f_p); X samples = tsamp; X } X } X else if (almost_equals(c_token,"t$erminal")) { X c_token++; X if (END_OF_COMMAND) { X list_terms(); X screen_ok = FALSE; X } X else X term = set_term(c_token); X c_token++; X } X else if (almost_equals(c_token,"x$range")) { X c_token++; X if (!equals(c_token,"[")) X int_error("expecting '['",c_token); X c_token++; X load_range(&xmin,&xmax); X if (!equals(c_token,"]")) X int_error("expecting ']'",c_token); X c_token++; X } X else if (almost_equals(c_token,"y$range")) { X c_token++; X if (!equals(c_token,"[")) X int_error("expecting '['",c_token); X c_token++; X load_range(&ymin,&ymax); X autoscale = FALSE; X if (!equals(c_token,"]")) X int_error("expecting ']'",c_token); X c_token++; X } X else if (almost_equals(c_token,"z$ero")) { X struct value a; X c_token++; X zero = magnitude(const_express(&a)); X } X else X int_error( X "valid set options: '[no]autoscale', 'data', 'dummy', 'function',\n\ X'[no]logscale', 'offsets', 'output', '[no]polar', 'samples',\n\ X'terminal', 'xrange', 'yrange', 'zero'", X c_token); X} X X Xshow_stuff() X{ X if (almost_equals(++c_token,"ac$tion_table") || X equals(c_token,"at") ) { X c_token++; X show_at(); X c_token++; X } X else if (almost_equals(c_token,"au$toscale")) { X (void) putc('\n',stderr); X show_autoscale(); X c_token++; X } X else if (almost_equals(c_token,"d$ata")) { X c_token++; X if (!almost_equals(c_token,"s$tyle")) X int_error("expecting keyword 'style'",c_token); X (void) putc('\n',stderr); X show_style("data",data_style); X c_token++; X } X else if (almost_equals(c_token,"d$ummy")) { X fprintf(stderr,"\n\tdummy variable is %s\n",dummy_var); X c_token++; X } X else if (almost_equals(c_token,"f$unctions")) { X c_token++; X if (almost_equals(c_token,"s$tyle")) { X (void) putc('\n',stderr); X show_style("functions",func_style); X c_token++; X } X else X show_functions(); X } X else if (almost_equals(c_token,"l$ogscale")) { X (void) putc('\n',stderr); X show_logscale(); X c_token++; X } X else if (almost_equals(c_token,"of$fsets")) { X (void) putc('\n',stderr); X show_offsets(); X c_token++; X } X else if (almost_equals(c_token,"o$utput")) { X (void) putc('\n',stderr); X show_output(); X c_token++; X } X else if (almost_equals(c_token,"po$lar")) { X (void) putc('\n',stderr); X show_polar(); X c_token++; X } X else if (almost_equals(c_token,"sa$mples")) { X (void) putc('\n',stderr); X show_samples(); X c_token++; X } X else if (almost_equals(c_token,"t$erminal")) { X (void) putc('\n',stderr); X show_term(); X c_token++; X } X else if (almost_equals(c_token,"v$ariables")) { X show_variables(); X c_token++; X } X else if (almost_equals(c_token,"ve$rsion")) { X show_version(); X c_token++; X } X else if (almost_equals(c_token,"x$range")) { X (void) putc('\n',stderr); X show_range('x',xmin,xmax); X c_token++; X } X else if (almost_equals(c_token,"y$range")) { X (void) putc('\n',stderr); X show_range('y',ymin,ymax); X c_token++; X } X else if (almost_equals(c_token,"z$ero")) { X (void) putc('\n',stderr); X show_zero(); X c_token++; X } X else if (almost_equals(c_token,"a$ll")) { X c_token++; X show_version(); X show_polar(); X fprintf(stderr,"\tdummy variable is %s\n",dummy_var); X show_style("data",data_style); X show_style("functions",func_style); X show_output(); X show_term(); X show_samples(); X show_logscale(); X show_autoscale(); X show_zero(); X show_range('x',xmin,xmax); X show_range('y',ymin,ymax); X show_offsets(); X show_variables(); X show_functions(); X c_token++; X } X else X int_error( X "valid show options: 'action_table', 'all', 'autoscale', 'data',\n\ X'dummy', 'function', 'logscale', 'offsets', 'output', 'polar',\n\ X'samples', 'terminal', 'variables', 'version', 'xrange', 'yrange', 'zero'", Xc_token); X screen_ok = FALSE; X (void) putc('\n',stderr); X} X X Xload_offsets (a, b, c, d) Xdouble *a,*b, *c, *d; X{ Xstruct value t; X X *a = real (const_express(&t)); /* loff value */ X c_token++; X if (equals(c_token,",")) X c_token++; X if (END_OF_COMMAND) X return; X X *b = real (const_express(&t)); /* roff value */ X c_token++; X if (equals(c_token,",")) X c_token++; X if (END_OF_COMMAND) X return; X X *c = real (const_express(&t)); /* toff value */ X c_token++; X if (equals(c_token,",")) X c_token++; X if (END_OF_COMMAND) X return; X X *d = real (const_express(&t)); /* boff value */ X c_token++; X} X X Xload_range(a,b) Xdouble *a,*b; X{ Xstruct value t; X X if (equals(c_token,"]")) X return; X if (END_OF_COMMAND) { X int_error("starting range value or ':' expected",c_token); X } else if (!equals(c_token,"to") && !equals(c_token,":")) { X *a = real(const_express(&t)); X } X if (!equals(c_token,"to") && !equals(c_token,":")) X int_error("':' expected",c_token); X c_token++; X if (!equals(c_token,"]")) X *b = real(const_express(&t)); X} X X Xplotrequest() X{ X X if (!term) /* unknown */ X int_error("use 'set term' to set terminal type first",c_token); X X if (equals(c_token,"[")) { X c_token++; X if (isletter(c_token)) { X copy_str(c_dummy_var,c_token++); X if (equals(c_token,"=")) X c_token++; X else X int_error("'=' expected",c_token); X } X load_range(&xmin,&xmax); X if (!equals(c_token,"]")) X int_error("']' expected",c_token); X c_token++; X } X X if (equals(c_token,"[")) { /* set optional y ranges */ X c_token++; X load_range(&ymin,&ymax); X autoscale = FALSE; X if (!equals(c_token,"]")) X int_error("']' expected",c_token); X c_token++; X } X X eval_plots(); X} X X Xdefine() X{ Xregister int start_token; /* the 1st token in the function definition */ Xregister struct udvt_entry *udv; Xregister struct udft_entry *udf; X X if (equals(c_token+1,"(")) { X /* function ! */ X start_token = c_token; X copy_str(c_dummy_var, c_token + 2); X c_token += 5; /* skip (, dummy, ) and = */ X if (END_OF_COMMAND) X int_error("function definition expected",c_token); X udf = dummy_func = add_udf(start_token); X if (udf->at) /* already a dynamic a.t. there */ X free((char *)udf->at); /* so free it first */ X if (!(udf->at = perm_at())) X int_error("not enough memory for function",start_token); X m_capture(&(udf->definition),start_token,c_token-1); X } X else { X /* variable ! */ X start_token = c_token; X c_token +=2; X udv = add_udv(start_token); X (void) const_express(&(udv->udv_value)); X udv->udv_undef = FALSE; X } X} X X Xget_data(this_plot) Xstruct curve_points *this_plot; X{ Xstatic char data_file[MAX_LINE_LEN+1], line[MAX_LINE_LEN+1]; Xregister int i, overflow, l_num; Xregister FILE *fp; Xfloat x, y; X X quote_str(data_file, c_token); X this_plot->plot_type = DATA; X if (!(fp = fopen(data_file, "r"))) X os_error("can't open data file", c_token); X X l_num = 0; X X overflow = i = 0; X X while (fgets(line, MAX_LINE_LEN, fp)) { X l_num++; X if (is_comment(line[0]) || ! line[1]) /* line[0] will be '\n' */ X continue; /* ignore comments and blank lines */ X X if (i == samples+1) { X overflow = i; /* keep track for error message later */ X i--; /* so we don't fall off end of points[i] */ X } X switch (sscanf(line, "%f %f", &x, &y)) { X case 1: /* only one number on the line */ X y = x; /* so use it as the y value, */ X x = i; /* and use the index as the x */ X /* no break; !!! */ X case 2: X this_plot->points[i].undefined = TRUE; X if (x >= xmin && x <= xmax && (autoscale || X (y >= ymin && y <= ymax))) { X if (log_x) { X if (x <= 0.0) X break; X this_plot->points[i].x = log10(x); X } else X this_plot->points[i].x = x; X if (log_y) { X if (y <= 0.0) X break; X this_plot->points[i].y = log10(y); X } else X this_plot->points[i].y = y; X if (autoscale) { X if (y < ymin) ymin = y; X if (y > ymax) ymax = y; X } X X this_plot->points[i].undefined = FALSE; X } X if (overflow) X overflow++; X else X i++; X break; X X default: X (void) sprintf(line, "bad data on line %d", l_num); X int_error(line,c_token); X } X } X if (overflow) { X (void) sprintf(line, X "%d data points found--samples must be set at least this high",overflow); X /* actually, samples can be one less! */ X int_error(line,c_token); X } X this_plot->p_count = i; X (void) fclose(fp); X} X X Xeval_plots() X{ Xregister int i; Xregister struct curve_points *this_plot, **tp_ptr; Xregister int start_token, mysamples; Xregister double x_min, x_max, y_min, y_max, x; Xregister double xdiff, temp; Xregister int plot_num; Xstatic struct value a; X X /* don't sample higher than output device can handle! */ X mysamples = (samples <= term_tbl[term].xmax) ?samples :term_tbl[term].xmax; X X if (log_x) { X if (xmin < 0.0 || xmax < 0.0) X int_error("x range must be above 0 for log scale!",NO_CARET); X x_min = log10(xmin); X x_max = log10(xmax); X } else { X x_min = xmin; X x_max = xmax; X } X X if (autoscale) { X ymin = HUGE; X ymax = -HUGE; X } else if (log_y && (ymin <= 0.0 || ymax <= 0.0)) X int_error("y range must be above 0 for log scale!", X NO_CARET); X X xdiff = (x_max - x_min) / mysamples; X X tp_ptr = &(first_plot); X plot_num = 0; X X while (TRUE) { X if (END_OF_COMMAND) X int_error("function to plot expected",c_token); X X start_token = c_token; X X if (is_definition(c_token)) { X define(); X } else { X plot_num++; X if (*tp_ptr) X this_plot = *tp_ptr; X else { /* no memory malloc()'d there yet */ X this_plot = (struct curve_points *) X malloc((unsigned int) (sizeof(struct curve_points) - X (MAX_POINTS - (samples+1))*sizeof(struct coordinate))); X if (!this_plot) X int_error("out of memory",c_token); X this_plot->next_cp = NULL; X this_plot->title = NULL; X *tp_ptr = this_plot; X } X X if (isstring(c_token)) { /* data file to plot */ X this_plot->plot_type = DATA; X this_plot->plot_style = data_style; X get_data(this_plot); X c_token++; X } X else { /* function to plot */ X this_plot->plot_type = FUNC; X this_plot->plot_style = func_style; X X (void) strcpy(c_dummy_var,dummy_var); X dummy_func = &plot_func; X X plot_func.at = temp_at(); X X for (i = 0; i <= mysamples; i++) { X if (i == samples+1) X int_error("number of points exceeded samples", X NO_CARET); X x = x_min + i*xdiff; X if (log_x) X x = pow(10.0,x); X (void) complex(&plot_func.dummy_value, x, 0.0); X X evaluate_at(plot_func.at,&a); X X if (this_plot->points[i].undefined = X undefined || (fabs(imag(&a)) > zero)) X continue; X /* X The old code used plot_type to generate x, but with X polar and offset concepts we need to record the x X value. X */ X this_plot->points[i].x = x; X X temp = real(&a); X X if (log_y && temp <= 0.0) { X this_plot->points[i].undefined = TRUE; X continue; X } X if (autoscale) { X if (temp < ymin) ymin = temp; X if (temp > ymax) ymax = temp; X } else if (temp < ymin || temp > ymax) { X this_plot->points[i].undefined = TRUE; X continue; X } X X this_plot->points[i].y = log_y ? log10(temp) : temp; X } X this_plot->p_count = i; /* mysamples + 1 */ X } X m_capture(&(this_plot->title),start_token,c_token-1); X if (almost_equals(c_token,"w$ith")) X this_plot->plot_style = get_style(); X tp_ptr = &(this_plot->next_cp); X } X X if (equals(c_token,",")) X c_token++; X else X break; X } X X if (autoscale && (ymin == ymax)) X ymax += 1.0; /* kludge to avoid divide-by-zero in do_plot */ X X if (log_y) { X y_min = log10(ymin); X y_max = log10(ymax); X } else { X y_min = ymin; X y_max = ymax; X } X capture(replot_line,plot_token,c_token); X do_plot(first_plot,plot_num,x_min,x_max,y_min,y_max); X} X X X Xdone(status) Xint status; X{ X if (term) X (*term_tbl[term].reset)(); X exit(status); X} X X X#ifdef vms X X#include <descrip.h> X#include <rmsdef.h> X#include <errno.h> X Xextern lib$get_input(), lib$put_output(); X Xint vms_len; X Xunsigned int status[2] = {1, 0}; X X$DESCRIPTOR(prompt_desc,PROMPT); X$DESCRIPTOR(line_desc,input_line); X X$DESCRIPTOR(help_desc,help); X$DESCRIPTOR(helpfile_desc,"GNUPLOT$HELP"); X X Xread_line() X{ X switch(status[1] = lib$get_input(&line_desc, &prompt_desc, &vms_len)){ X case RMS$_EOF: X done(IO_SUCCESS); /* ^Z isn't really an error */ X break; X case RMS$_TNS: /* didn't press return in time */ X vms_len--; /* skip the last character */ X break; /* and parse anyway */ X case RMS$_BES: /* Bad Escape Sequence */ X case RMS$_PES: /* Partial Escape Sequence */ X sys$putmsg(status); X vms_len = 0; /* ignore the line */ X break; X case SS$_NORMAL: X break; /* everything's fine */ X default: X done(status[1]); /* give the error message */ X } X input_line[vms_len] = '\0'; X} X X Xdo_help() X{ X help_desc.dsc$w_length = strlen(help); X if ((vaxc$errno = lbr$output_help(lib$put_output,0,&help_desc, X &helpfile_desc,0,lib$get_input)) != SS$_NORMAL) X os_error("can't open GNUPLOT$HELP"); X} X X Xdo_shell() X{ X if ((vaxc$errno = lib$spawn()) != SS$_NORMAL) { X os_error("spawn error",NO_CARET); X } X} X X Xdo_system() X{ X input_line[0] = ' '; /* an embarrassment, but... */ X X if ((vaxc$errno = lib$spawn(&line_desc)) != SS$_NORMAL) X os_error("spawn error",NO_CARET); X X (void) putc('\n',stderr); X} X X#else /* vms */ X Xdo_help() X{ X if (system(help)) X os_error("can't spawn help",c_token); X} X X Xdo_system() X{ X if (system(input_line + 1)) X os_error("system() failed",NO_CARET); X} X X#ifdef MSDOS X Xread_line() X{ Xregister int i; X X input_line[0] = MAX_LINE_LEN - 1; X cputs(PROMPT); X cgets(input_line); /* console input so CED will work */ X (void) putc('\n',stderr); X if (input_line[2] == 26) { X (void) putc('\n',stderr); /* end-of-file */ X done(IO_SUCCESS); X } X X i = 0; X while (input_line[i] = input_line[i+2]) X i++; /* yuck! move everything down two characters */ X} X X Xdo_shell() X{ Xregister char *comspec; X if (!(comspec = getenv("COMSPEC"))) X comspec = "\command.com"; X if (spawnl(P_WAIT,comspec,NULL) == -1) X os_error("unable to spawn shell",NO_CARET); X} X X#else /* MSDOS */ X /* plain old Unix */ X Xread_line() X{ X fputs(PROMPT,stderr); X if (!fgets(input_line, MAX_LINE_LEN, stdin)) { X (void) putc('\n',stderr); /* end-of-file */ X done(IO_SUCCESS); X } X else { X input_line[strlen(input_line)-1] = '\0'; /* Remove trailing \n */ X } X} X X#ifdef VFORK X Xdo_shell() X{ Xregister char *shell; Xregister int p; Xstatic int execstat; X if (!(shell = getenv("SHELL"))) X shell = SHELL; X if ((p = vfork()) == 0) { X execstat = execl(shell,shell,NULL); X _exit(1); X } else if (p == -1) X os_error("vfork failed",c_token); X else X while (wait(NULL) != p) X ; X if (execstat == -1) X os_error("shell exec failed",c_token); X (void) putc('\n',stderr); X} X#else /* VFORK */ X X#define EXEC "exec " Xdo_shell() X{ Xstatic char exec[100] = EXEC; Xregister char *shell; X if (!(shell = getenv("SHELL"))) X shell = SHELL; X X if (system(strncpy(&exec[sizeof(EXEC)-1],shell, X sizeof(exec)-sizeof(EXEC)-1))) X os_error("system() failed",NO_CARET); X X (void) putc('\n',stderr); X} X#endif /* VFORK */ X#endif /* MSDOS */ X#endif /* vms */ END_OF_FILE if test 23912 -ne `wc -c <'./command.c'`; then echo shar: \"'./command.c'\" unpacked with wrong size! fi # end of './command.c' fi if test -f './docs/gnuplot.hlp' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'./docs/gnuplot.hlp'\" else echo shar: Extracting \"'./docs/gnuplot.hlp'\" \(19621 characters\) sed "s/^X//" >'./docs/gnuplot.hlp' <<'END_OF_FILE' X X GNUPLOT is a command-driven interactive function plotting program. It X is case sensitive (commands and function names written in lowercase X are not the same as those written in CAPS). All command names may be X abbreviated, as long as the abbreviation is not ambiguous. Any number X of commands may appear on a line, separated by semicolons (;). X X Type the EOF character (^D for UNIX, ^Z for DOS) to exit the help system X from any level and return to GNUPLOT. <RETURN> goes back to the previous X level and to GNUPLOT from top level help. X1 clear X This command erases the current screen or output device as specified X by 'set output'. This usually generates a formfeed on hardcopy X devices. Use 'set terminal' to set the device type. X1 exit X 'exit', 'quit' and your computer's END-OF-FILE character will exit X GNUPLOT. All these commands will clear the output device (as the X 'clear' command does) before exiting. X1 expressions X2 functions X3 abs X This function returns the absolute value of its argument. The X returned value is of the same type as the argument. X X For complex arguments, abs(x) is defined as the length of x in the X complex plane [i.e. sqrt(real(x)**2 + imag(x)**2) ]. X3 acos X This function returns the arc cosine (inverse cosine) of its X argument. 'acos' returns its argument in radians. X3 arg X This function returns the phase of a complex number, in radians. X3 asin X This function returns the arc sin (inverse sin) of its argument. X 'asin' returns its argument in radians. X3 atan X This function returns the arc tangent (inverse tangent) of its X argument. 'atan' returns its argument in radians. X3 besj0 X This function returns the j0th Bessel function of its argument. X 'besj0' expects its argument to be in radians. X3 besj1 X This function returns the j1st Bessel function of its argument. X 'besj1' expects its argument to be in radians. X3 besy0 X This function returns the y0th Bessel function of its argument. X 'besy0' expects its argument to be in radians. X3 besy1 X This function returns the y1st Bessel function of its argument. X 'besy1' expects its argument to be in radians. X3 ceil X This function returns the largest integer not less than its X argument. For complex numbers, 'ceil' returns the largest integer X not less than the real part of its argument. X3 cos X This function returns the cosine of its argument. 'cos' expects its X argument to be in radians. X3 cosh X This function returns the hyperbolic cosine of its argument. X 'cosh' expects its argument to be in radians. X3 exp X This function returns the exponential function of its argument X (e raised to the power of its argument). X3 floor X This function returns the smallest integer not greater than its X argument. For complex numbers, 'floor' returns the smallest X integer not greater than the real part of its argument. X3 imag X This function returns the imaginary part of its argument as a real number. X3 int X This function returns the integer part of its argument, truncated X toward zero. X3 log X This function returns the natural logarithm (base e) of its X argument. X3 log10 X This function returns the logarithm (base 10) of its argument. X3 real X This function returns the real part of its argument. X3 sgn X This function returns 1 if its argument is positive, -1 if its X argument is negative, and 0 if its argument is 0. If the argument X is a complex value, the imaginary component is ignored. X3 sin X This function returns the sine of its argument. 'sin' expects its X argument to be in radians. X3 sinh X This function returns the hyperbolic sine of its argument. 'sinh' X expects its argument to be in radians. X3 sqrt X This function returns the square root of its argument. X3 tan X This function returns the tangent of its argument. 'tan' expects X its argument to be in radians. X3 tanh X This function returns the hyperbolic tangent of its argument. X 'tanh' expects its argument to be in radians. X2 operators X3 binary X The following is a list of all the binary operators and their X usages: X X Symbol Example Explanation X ** a**b exponentiation X * a*b multiplication X / a/b division X % a%b * modulo X + a+b addition X - a-b subtraction X == a==b equality X != a!=b inequality X & a&b * bitwise and X ^ a^b * bitwise exclusive or X | a|b * bitwise inclusive or X && a&&b * logical and X || a||b * logical or X ?: a?b:c * ternary operation X X (*) Starred explanations indicate that the operator requires X integer arguments. X X Logical AND (&&) and OR (||) short-circuit the way they do in C. X That is, the second && operand is not evaluated if the first is X false; the second || operand is not evaluated if the first is true. X X The ternary operator evaluates its first argument (a). If it is X true (non-zero) the second argument (b) is evaluated and returned, X otherwise the third argument (c) is evaluated and returned. X3 unary X The following is a list of all the unary operators and their X usages: X X Symbol Example Explanation X - -a unary minus X ~ ~a * one's complement X ! !a * logical negation X ! a! * factorial X X (*) Starred explanations indicate that the operator requires an X integer argument. X X The factorial operator returns a real number to allow a greater range. X1 help X The 'help' command displays on-line help. To specify information on a X particular topic use the syntax: X X help <topic> X X Help is actually a separate program. If help doesn't work for you, ask X your administrator how to set up the GNUHELP environment variable (and X possibly the HELPDIR environment variable). X X You may exit the help utility and return to GNUPLOT by either pressing X <Return>(s) at the 'HELP >' prompt or pressing your computer's END-OF-FILE X character at any help prompt. X1 load X This command executes each line of the specified input file as if it X had been typed in interactively. Files created by the 'save' command X can later be 'load'ed. Any text file containing valid commands can be X created and then executed by the 'load' command. Files being 'load'ed X may themselves contain 'load' commands. Lines beginning with # (or ! X if using VMS) will be treated as comments and ignored. X X The 'load' command must be the last command on the line. X X Syntax: X load <input-file> X X The name of the input file must be enclosed in quotes. X X Examples: X X load 'work.gnu' X load "func.dat" X1 pause X Pause is useful in conjunction with `load` files. The command 'pause' X displays any text associated with the command and then waits the X specified amount of time. This allows one to build a 'load' file X and control the amount of time a finished graph is displayed. The X first argument is an expression that can be -1, 0, 1, 2, ... -1 X will wait until a carriage return is hit. 0 won't pause at all, and X 1, 2, etc. will wait the specified number of seconds. X X Note: Since pause is not part of the plot it may interact with X different device drivers differently (depending upon how text and X graphics are mixed). X X Examples: X pause -1 ! Wait until a carriage return is hit X pause 3 ! Wait three seconds X pause -1 "Hit return to continue" X pause 10 "Isn't this pretty? It's a cubic-spline." X X Syntax: X pause <expression> ["string"] X1 plot X2 data_file X Discrete data contained in a file can displayed by specifying the X name of the data file (enclosed in quotes) on the 'plot' command X line. X X Data files should contain one data point per line. A data point may X be specified either as an X and Y value separated by blank space, or X as just the Y value, in which case the program will use the number X of the coordinate as the X value. Coordinate numbers starts at 0 X and are incremented for each data point read. Blank lines and lines X beginning with # will be treated as comments and ignored. X X X This example compares the data in the file population.dat to a X theoretical curve: X X pop(x) = 103*exp((1965-x)/10) X plot [1960:1990] 'population.dat', pop(x) X X The file population.dat might contain: X X # Gnu population in Antarctica since 1965 X 1965 103 X 1970 55 X 1975 34 X 1980 24 X 1985 10 X2 ranges X This option specifies the region of the plot which will be displayed. X X Ranges may be provided on the 'plot' command line as synonyms for X the 'set xrange' and 'set yrange' commands. X X Syntax: X [{dummy-var =} {xmin : xmax}] { [{ymin : ymax}] } X X Where dummy-var is the independent variable (the default is 'x', X but this may be changed with the 'set dummy' command) and the min X and max terms can be expressions or constants. X X Both the min and max terms are optional. The ':' is also optional X if neither a min nor a max term is specified. This allows '[]' to X be used as a null range specification. X X Specifying a Y range turns autoscaling OFF. X X X Examples: X X This uses current ranges: X plot cos(x) X X This sets the xrange only: X plot [-10:30] sin(pi*x)/(pi*x) X X This is the same, but uses t as the dummy-variable: X plot [t = -10 :30] sin(pi*t)/(pi*t) X X This sets both the x and yranges: X plot [-pi:pi] [-3:3] tan(x), 1/x X X This sets only the yrange: X plot [] [-2:sin(5)*-8] sin(x)**besj0(x) X X This sets xmax and ymin only: X plot [:200] [-pi:] exp(sin(x)) X2 style X Plots may be displayed in one of three styles: 'lines', 'points', or X 'impulses'. The 'lines' style connects adjacent points with lines. X The 'points' style displays a small symbol at each point. The X 'impulses' style displays a vertical line from the X axis to each X point. X X Default styles are chosen with the 'set function style' and X 'set data style' commands. X X Syntax: X with <style> X X Where <style> is one of 'lines', 'points', or 'impulses'. These X keywords may be abbreviated. X X X Examples: X X This plots sin(x) with impulses: X plot sin(x) with impulses X X This plots sin(x) with points, cos(x) default: X plot [-9:30] sin(x) w points, cos(x) X X This plots tan(x) with the default function style, "data.1" with lines: X plot [] [-2:5] tan(x), "data.1" with l X X This plots "leastsq.dat" with impulses: X plot 'leastsq.dat' w i X1 print X This command prints the value of <expression> to the screen. X X Syntax: X print <expression> X X See 'expressions'. X1 quit X 'quit' is a synonym for 'exit'. See 'exit'. X1 replot X 'replot' repeats the last 'plot' command. This can be useful for X viewing a plot with different 'set' options, or when generating the X same plot for several devices. X1 save X This command saves either user-defined functions, variables, or both X to the specified file. X X Syntax: X save {option} <filename> X X Where <option> is either 'functions' or 'variables'. If no option is X used GNUPLOT saves both functions and variables. X X 'save'd files are written in text format and may be read by the 'load' X command. X X The filename must be enclosed in quotes. X X Examples: X X save "work.gnu" X save functions 'func.dat' X save var 'var.dat' X1 set-show X Set or show various internal gnuplot settings. X2 all X The command 'show all' will display all the set-show options X currently in effect. X X Syntax: X show all X2 autoscale X If autoscaling is set, the Y axis is automatically scaled to fit the X range of the function or data being plotted. If autoscaling is not X set, the current Y range is used. See 'set yrange'. X X Syntax: X set autoscale X set noautoscale X show autoscale X2 dummy X By default, GNUPLOT assumes that the independent variable is 'x' on X the 'plot' command line. 'x' is called the dummy variable because X it is just a notation to indicate the independent variable. The X 'set dummy' command changes this default dummy variable name. For X example, you may find it more convenient to call the dummy variable X 't' when plotting time functions: X X set dummy t X plot sin(t), cos(t) X X Syntax: X set dummy <dummy-var> X show dummy X2 functions X The 'show functions' command lists all user-defined functions and X their definitions. X X Syntax: X show functions X2 logscale X Log scaling may be set on the X and/or Y axis. X X Syntax: X set logscale <axes> X set nologscale X show logscale X X Where <axes> is either 'x', 'y', or 'xy'. X2 polar X The 'set polar' command changes the meaning of the plot from X rectangular coordinates to polar coordinates. In polar X coordinates, the dummy variable (x) is an angle. The domain X of this angle is changed from whatever it was to [0:2*pi]. X X The command 'set nopolar' changes the meaning of the plot back X to the default rectangular coordinate system. The domain of X x is changed from whatever it was to [-10:10]. X X While in polar coordinates the meaning of an expression in x X is really r = f(x), where x is an angle of rotation. The plot, X however, is plotted on a rectangular grid. Thus the displayed X ranges of x and y are rectanglar values, while the command X 'set xrange' refers to polar values. X X Syntax: X set polar X set nopolar X show polar X2 offsets X The amount of the graph that the plot takes up may be controlled X to some extent with the 'set offsets' command. This command takes X four arguments--left offset, right offset, top offset and bottom X offset. By default, each offset is 0. Left and right offsets are X given in units of the x axis, while top and bottom offsets are X given in units of the y axis. The plot of sin(x), displayed with X offsets of 0, 0, 2, 2 will take up 1/3 of the displayed y axis. X Offsets are particularly useful with polar coordinates as a means X of compensating for aspect ratio distortion. X X Syntax: X set offsets <expr>, <expr>, <expr>, <expr> X show offsets X2 output X By default, plots are displayed to the standard output. The X 'set output' command redirects the displays to the specified file or X device. X X Syntax: X set output {filename} X show output X X The filename must be enclosed in quotes. If the filename is X omitted, output will be sent to the standard output. X2 samples X The sampling rate of functions may be changed by the 'set samples' X command. By default, sampling is set to 160 points. A higher X sampling rate will produce more accurate plots, but will take X longer. In generating plots, GNUPLOT will use either the sampling X rate set or the resolution of the current output device, whichever X is lower. X X Syntax: X set samples <expression> X show samples X2 style X Plots may be displayed in one of three styles: 'lines', 'points', or X 'impulses'. The 'lines' style connects adjacent points with lines. X The 'points' style displays a small symbol at each point. The X 'impulses' style displays a vertical line from the X axis to each X point. X X Default styles are chosen with the 'set function style' and 'set X data style' commands. See 'plot' for information about how to X override the default plotting style for individual functions. X X Syntax: X set function style <style> X set data style <style> X show function style X show data style X X Where style is either 'lines', 'points', or 'impulses'. X2 terminal X GNUPLOT supports many different graphics devices. Use the 'set X terminal' command to select the type of device for which GNUPLOT X will produce output. While your installation may not include all X of these, the following were available in the source code at the X time this help file was written: X X Machines: IBM-PC's (ega, cga, hercules), ATT6300, CORONA325, X UNIXPC (att7300 or 3b1); X Terminals: AED512, AED767, HP2623A, HP7580B, REGIS, SELENAR, X TEK40xx, BBN Bitgraph; X Printers: LASERJET1, LASERJET2, LASERJET3, POSTSCRIPT, QMS, X VECTRIX384; X Other: UNIXPLOT. X X Syntax: X set terminal {terminal-type} X show terminal X X If <terminal-type> is omitted, GNUPLOT will list the available X terminal types. <terminal-type> may be abbreviated. X X Use 'set output' to redirect this output to a file or device. X2 variables X The 'show variables' command lists all user-defined variables and X their values. X X Syntax: X show variables X2 version X Show the current version of gnuplot. This is the same text X that appears when gnuplot starts up. (There is no SET VERSION X command, of course.) X X Syntax: X SHOW VERSION X2 xrange X The 'set xrange' command sets the horizontal range which will be X displayed. X X This range may also be specified on the 'plot' command line. X X Syntax: X set xrange [{xmin : xmax}] X X Where <xmin> and <xmax> terms are expressions or constants. X X Both the <xmin> and <xmax> terms are optional. X2 yrange X The 'set yrange' command sets the vertical range which will be X displayed. This command turns autoscaling OFF. X X This range may also be specified on the 'plot' command line. X X Syntax: X set yrange [{ymin : ymax}] X X Where <ymin> and <ymax> terms are expressions or constants. X X Both the <ymin> and <ymax> terms are optional. X2 zero X GNUPLOT will not plot a point if its imaginary part is greater in X magnitude than the 'zero' threshold. The default 'zero' value is X 1e-8. X X Syntax: X set zero <expression> X show zero X1 shell X The 'shell' command spawns an interactive shell. To return to X GNUPLOT, type 'logout' if using VMS, 'exit' or your END-OF-FILE X character if using Unix, or 'exit' if using MS-DOS. X X A single shell command may be spawned by preceding it with the ! X character ($ if using VMS) at the beginning of a command line. X Control will return immediately to GNUPLOT after this command is X executed. For example, X X ! dir X X prints a directory listing and then returns to GNUPLOT. X1 start_up X When GNUPLOT is run, it looks for an initialization file to load. X This file is called '.gnuplot' on Unix systems, and 'GNUPLOT.INI' on X other systems. If this file is not found in the current directory, X the program will look for it in your home directory (under MS-DOS, the X environment variable GNUPLOT should contain the name of this X directory). X X If this file is found, GNUPLOT executes the commands in this file. X This is most useful for setting your terminal type and defining any X functions or variables which you use often. The variable 'pi' is X already defined for you. X1 substitution X Command-line substitution is specified by a system command enclosed in X backquotes (`). This command is spawned and the output it produces X replaces the name of the command (and backquotes) on the command line. X X Newlines in the output produced by the spawned command are replaced with X blanks. X X Command-line substitution can be used anywhere on the GNUPLOT command X line. X X X Example: X X This will run the program 'leastsq' and substitute `leastsq` on the X command line with its output: X X f(x) = `leastsq` X X or, in VMS X X f(x) = `run leastsq` X1 user_defined X You may define your own functions and variables. User-defined X functions and variables may be used anywhere. X X User-defined function syntax: X <function-name> ( <dummy-var> ) = <expression> X X Where <expression> is defined in terms of <dummy-var>. X X User-defined variable syntax: X <variable-name> = <constant-expression> X X Examples: X w = 2 X q = floor(tan(pi/2 - 0.1)) X f(x) = sin(w*x) X sinc(x) = sin(pi*x)/(pi*x) X delta(t) = (t == 0) X ramp(t) = (t > 0) ? t : 0 X X The variable 'pi' is already defined for you. X X See 'show functions' and 'show variables'. END_OF_FILE if test 19621 -ne `wc -c <'./docs/gnuplot.hlp'`; then echo shar: \"'./docs/gnuplot.hlp'\" unpacked with wrong size! fi # end of './docs/gnuplot.hlp' fi echo shar: End of archive 6 \(of 7\). cp /dev/null ark6isdone MISSING="" for I in 1 2 3 4 5 6 7 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 7 archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- John Campbell ...!arizona!naucse!jdc CAMPBELL@NAUVAX.bitnet unix? Sure send me a dozen, all different colors.