Path: utzoo!utgpu!watmath!uunet!fernwood!apple!brutus.cs.uiuc.edu!psuvax1!gatech!ncar!asuvax!noao!arizona!naucse!jdc From: jdc@naucse.UUCP (John Campbell) Newsgroups: unix-pc.sources Subject: gnuplot.shar.06 Message-ID: <1685@naucse.UUCP> Date: 4 Sep 89 16:42:32 GMT Organization: Northern Arizona University, Flagstaff, AZ Lines: 1716 #! /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 './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 X#include X X#ifdef MSDOS X#include 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 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 X#include X#include 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. 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 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 (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 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 ["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