graph.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1992, 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#define F .25
struct xy {
int xlbf; /*flag:explicit lower bound*/
int xubf; /*flag:explicit upper bound*/
int xqf; /*flag:explicit quantum*/
double (*xf)(); /*transform function, e.g. log*/
float xquant; /*quantum*/
float xoff; /*screen offset fraction*/
float xsize; /*screen fraction*/
float xmult; /*scaling constant*/
struct val {
float xv;
float yv;
int lblptr;
} *xx;
static char *labs;
static int labsiz;
int tick = 50;
int top = 4000;
int bot = 200;
float absbot;
int n;
int erasf = 1;
int gridf = 2;
int symbf = 0;
int absf = 0;
int transf;
int brkf;
float dx;
char *plotsymb;
double atof();
#define BSIZ 80
char *modes[] = {
"disconnected",
"solid",
"dotted",
"dotdashed",
"shortdashed",
"longdashed"
};
int mode = 1;
char *realloc();
char *malloc();
double ident(x)
double x;
{
return(x);
}
char *argv[];
{
if(erasf)
erase();
readin();
transpose();
axes();
title();
plot();
closevt();
return(0);
}
init(p)
struct xy *p;
{
p->xf = ident;
p->xmult = 1;
}
char *argv[];
{
float temp;
while(--argc > 0) {
argv++;
case '-':
argv[0]++;
goto again;
case 'l': /* label for plot */
if (argc>=2) {
argv++;
argc--;
}
break;
case 'd': /*disconnected,obsolete option*/
case 'm': /*line mode*/
mode = 0;
break;
mode = 1;
else if(temp>=0)
break;
case 'a': /*automatic abscissas*/
absf = 1;
dx = 1;
break;
absf = 2;
break;
case 's': /*save screen, overlay plot*/
erasf = 0;
break;
case 'g': /*grid style 0 none, 1 ticks, 2 full*/
gridf = 0;
break;
case 'c': /*character(s) for plotting*/
if(argc >= 2) {
symbf = 1;
argv++;
argc--;
}
break;
case 't': /*transpose*/
transf = 1;
break;
case 'b': /*breaks*/
brkf = 1;
break;
case 'x': /*x limits */
break;
case 'y':
break;
case 'h': /*set height of plot */
badarg();
break;
case 'w': /*set width of plot */
badarg();
break;
case 'r': /* set offset to right */
badarg();
break;
case 'u': /*set offset up the screen*/
badarg();
break;
default:
badarg();
}
}
}
register struct xy *p;
int *argcp;
char ***argvp;
{
(*argcp)--;
(*argvp)++;
}
return;
p->xlbf = 1;
return;
p->xubf = 1;
return;
p->xqf = 1;
}
int *argcp;
float *np;
register char ***argvp;
{
register char c;
if(*argcp <= 1)
return(0);
(*argvp)[1]++;
return(0);
(*argcp)--;
(*argvp)++;
return(1);
}
readin()
{
register t;
if(absf==1) {
absbot = 1;
}
for(;;) {
(unsigned)(n+1)*sizeof(struct val));
if(temp==0)
return;
if(absf)
else
return;
return;
t = getstring();
if(t>0)
n++;
if(t<0)
return;
}
}
{
register i;
float f;
struct xy t;
if(!transf)
return;
for(i= 0;i<n;i++) {
}
}
copystring(k)
{
register char *temp;
register i;
int q;
if(temp==0)
return(0);
q = labsiz;
for(i=0;i<=k;i++)
return(q);
}
float
modceil(f,t)
float f,t;
{
t = fabs(t);
return(ceil(f/t)*t);
}
float
modfloor(f,t)
float f,t;
{
t = fabs(t);
return(floor(f/t)*t);
}
getlim(p,v)
register struct xy *p;
struct val *v;
{
register i;
i = 0;
do {
i++;
} while(i < n);
}
struct z {
setlim(p)
register struct xy *p;
{
struct z z;
if(p->xqf) {
badarg();
return;
}
sign = 1;
if(delta < 0) {
sign = -1;
t = lb;
ub = t;
t = lbf;
ubf = t;
}
else if(delta == 0) {
if(ub > 0) {
lb = 0;
}
else
if(lb < 0) {
ub = 0;
}
else {
ub = 1;
lb = -1;
}
}
if(setmark(p, 0)<2) {
} else
return;
}
if(sign > 0) {
} else {
}
}
struct z
{
float r,s,t;
struct z z;
lb *= s;
ub *= s;
if(!lbf) {
z.lb *= 5;
z.lb *= 2;
}
if(!ubf) {
z.ub /= 5;
z.ub /= 2;
}
}
z.mult = s;
z.quant = r;
return(z);
}
struct z
{
struct z z;
float r,s,delta;
loop:
/*scale up by s, a power of 10, so range (delta) exceeds 1*/
/*find power of 10 quantum, r, such that delta/10<=r<delta*/
r = s = 1;
while(delta*s < 10)
s *= 10;
delta *= s;
while(10*r < delta)
r *= 10;
lb *= s;
ub *= s;
/*set r=(1,2,5)*10**n so that 3-5 quanta cover range*/
if(r>=delta/2)
r /= 2;
else if(r<delta/5)
r *= 2;
xlb = 0;
goto loop;
}
xub = 0;
goto loop;
}
z.quant = r;
z.mult = s;
return(z);
}
scale(p,v)
register struct xy *p;
struct val *v;
{
float edge;
getlim(p,v);
setlim(p);
}
axes()
{
register i;
if(gridf==0)
return;
}
register struct xy *p;
int doprt; /* 1 == print ticks, 0 == just count */
{
int xn = 0;
float q;
}
}
} else {
q = p->xquant;
if(q>0) {
} else {
}
xn++;
if (doprt)
}
}
return(xn);
}
float x;
struct xy *p;
int doprt;
{
if (doprt)
return 1;
}
else {
return 0;
}
}
float markf;
register struct xy *p;
{
if (p == &xd) {
if(gridf==2)
if(gridf==1) {
}
}
else {
if(gridf==2)
if(gridf==1) {
}
}
}
plot()
{
int i;
int conn;
conn = 0;
if(mode!=0)
for(i=0; i<n; i++) {
conn = 0;
continue;
}
if(mode!=0) {
if(conn != 0)
else
conn = 1;
}
}
}
float xv;
register struct xy *p;
int *ip;
{
long ix;
return(0);
return(1);
}
getfloat(p)
float *p;
{
register i;
i = scanf("%f",p);
return(i==1);
}
{
register i;
char junk[20];
if(i==-1)
return(-1);
switch(*labbuf) {
default:
break;
}
case '.':
case '+':
case '-':
return(0);
case '"':
break;
}
if(i==-1)
return(-1);
}
{
if(symbf==0&&k<0) {
if(mode==0)
return(1);
}
else {
return(!brkf|k<0);
}
}
title()
{
return;
*buf = '\0';
if (titlebuf[0]) {
}
}
}
badarg()
{
exit(1);
}