v21i040: 2D graphic system with table beautifier, Part09/14
Rich Salz
rsalz at uunet.uu.net
Sat Mar 24 06:21:26 AEST 1990
Submitted-by: Steve Grubb <uunet!lsr-vax!scg>
Posting-number: Volume 21, Issue 40
Archive-name: ipl/part09
# ipl part09
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
#---------------------- cut here -----------------------------
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# src/page.c
# src/pcode.c
# src/pick.c
# src/pie.c
# src/point.c
# src/polygon.c
# src/proc_call.c
# src/rangebar.c
# src/rect.c
cat << \SHAR_EOF > src/page.c
#include "ipl.x"
/* Page-wide things, page title, etc.
Note that user does not have to execute this.
*/
Page( )
{
int i = 1, c;
char paper[20];
double ofs;
FILE *fp;
/* paper orientation */
gget( paper, "Paperway" );
if( strcmp( paper, "landscape" )==0 ) {
NTpaper( 1 );
if( member( Dev, "sv" ))ab_rect( 0.0, 8.5, 11.0, 11.0, 0.5, 0 );
}
else if( strcmp( paper, "portrait" )==0 ) {
NTpaper( 0 );
if( member( Dev, "sv" ))ab_rect( 8.5, 0.0, 11.0, 11.0, 0.5, 0 );
}
else NTpaper( 0 );
/* standard line width */
gget( Buf2, "Standard.linethick" );
if( atof( Buf2 ) > 0 ) StdLw = atof( Buf2 );
NTnormline();
gget( Buf2, "Standard.font" ); strcpy( Stdfont, Buf2 );
gget( Buf2, "Title.font" ); NTfont( Buf2 );
gget( Buf2, "Title.size" ); NTptsize( atof( Buf2 ) );
gget( Buf2, "Title.belowtop" ); ofs = atof( Buf2 );
gget( Buf, "Title.file" );
if( strlen( Buf ) > 0 ) {
fp = fopen( Buf, "r" );
if( fp == NULL ) fp = popen( Buf, "r" );
if( fp == NULL ) { fprintf( stderr, "Can't open title file.\n" ); gdp_exit(); }
while( fgets( Buf, 512, fp ) != NULL ) {
strip_ws( Buf );
/* if( strlen( Buf ) < 1 ) continue; */
if( Paper == 0 ) NTmov( 0.0, 10.5-ofs );
else NTmov( 0.0, 8-ofs );
if( Paper == 0 && strlen( Buf ) >= 1 )NTcentext( Buf, 8 );
if( Paper == 1 && strlen( Buf ) >= 1 )NTcentext( Buf, 10.5 );
ofs += Chh;
}
fclose( fp );
}
gget( Buf, "Title" );
if( strlen( Buf ) > 0 ) {
getln( "" );
for( i = 0; i < countln( Buf ); i++ ) {
if( Paper == 0 ) NTmov( 0.0, 10.5-ofs );
else NTmov( 0.0, 8-ofs );
if( Paper == 0 )NTcentext( getln( Buf ), 8 );
if( Paper == 1 )NTcentext( getln( Buf ), 10.5 );
ofs += Chh;
}
}
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/pcode.c
#include <stdio.h>
/* ============================ */
/* IPL device interface (c) 1989 Steve Grubb */
/* This must be compiled either with or without flag NOSUNVIEW */
static char pdev;
static int vertchar = 0;
pcode( op, x, y, s )
char op; /* op code */
double x, y; /* coordinates */
char s[]; /* optional character string */
{
int outx, outy, move;
char ans[10], pbuf[400];
static double curx = 0, cury = 0;
static int doclip = 0;
double p1[2], p2[2];
double x1, y1, x2, y2;
double width, realx, chh;
static int new = 0, drawing = 0;
/* interface to postscript driver */
if( pdev == 't' ) {
if( op != 'L' ) {
if( drawing ) PSstroke();
drawing = 0;
}
if( op == 'L' ) {
if( new ) PSmoveto( curx, cury );
PSlineto( x, y );
new = 0;
drawing = 1;
}
else if( op == 'M' ) { new = 1; curx = x; cury = y; }
else if( op == 'P' ) {
if( new ) PSmoveto( curx, cury );
PSpath( x, y );
new = 0;
}
else if( op == 'T' ) PStext( op, curx, cury, s, 0.0 );
else if( op == 'C' ) PStext( op, curx, cury, s, x );
else if( op == 'J' ) PStext( op, curx, cury, s, x );
else if( op == 'S' ) PSshade( x );
else if( op == 'O' ) PSpaper( (int)x );
else if( op == 'I' ) PSpointsize( (int)x );
else if( op == 'F' ) PSfont( s );
else if( op == 'D' ) PSchardir( (int)x );
else if( op == 'Y' ) PSlinetype( s, x, y );
else if( op == 'Z' ) PSshow();
else if( op == 'K' ) doclip = 1;
else if( op == 'k' ) doclip = 0;
}
/* interface to sunview driver */
/* the routines SVtext, SVcentext, and SVrightjust return information
for keeping a bounding box list. */
#ifndef NOSUNVIEW
else if( pdev == 's' ) {
if( op == 'L' ) SVlineto( x, y );
else if( op == 'P' ) SVpath( x, y );
else if( op == 'M' ) SVmoveto( x, y );
else if( op == 'T' && !vertchar ) SVtext( s, &width );
else if( op == 'B' ) SVbatch_on();
else if( op == 'b' ) SVbatch_off();
else if( op == 'Y' ) SVlinetype( s, x, y );
else if( op == 'S' ) SVshade( x );
else if( op == 'I' || op == 'F' ) { SVpointsize( (int)(x) ); chh = (x+2)/72.0; }
else if( op == 'C' && !vertchar ) SVcentext( s, x, &curx, &width );
else if( op == 'J' && !vertchar ) SVrightjust( s, x, &curx, &width );
else if( op == 'W' ) SVwait();
else if( op == 'D' ) {
if( x == 90 || x == 270 ) vertchar = 1;
else vertchar = 0;
}
else if( op == 'Z' ) {
SVclear();
}
else if( op == 'K' ) doclip = 1;
else if( op == 'k' ) doclip = 0;
}
#endif
else if( pdev == 'm' ) return( 1 ); /* term-oriented composer-- no graphics */
else { fprintf( stderr, "pcode: %c: no such device\n", pdev ); exit(); }
}
/* ========================================================== */
/* initialize */
NTinit( dev )
char dev;
{
int yr, mon, day, hr, min, sec, i;
char host[30];
sysdate( &mon, &day, &yr ); systime( &hr, &min, &sec );
fprintf( stderr, "IPL graphics system version 1.0 by Steve Grubb\n" );
/* initialize devices */
if( dev == 's' || dev == 'v' ) {
SVsetup( 11.0, 11.0 );
SVclear();
pdev = 's';
}
else if( dev == 't' ) {
PSsetup( );
pdev = 't';
}
else if( dev == 'm' ) { pdev = 'm'; return( 1 ); }
else { fprintf( stderr, "NTinit: %c: no such device\n", dev ); exit(); }
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/pick.c
/* These routines are for getting user input. If Dev is 'v' (indicating
sunview composer), window and mouse-oriented input is used. If Dev is
'm' (indicating terminal composer), terminal oriented input is used.
*/
#include "ipl.x"
#define MAXBB 80
/* event modes */
#define PICK 1 /* getting a menu selection */
#define STRING 2 /* getting a \n terminated string */
#define EVENTS 3 /* getting any mouse-button or keyboard event */
static FILE *fp = NULL;
static double bb[MAXBB][4];
static double bbxlo, bbylo, bbxhi, bbyhi;
static char name[MAXBB][80];
static char selection[80];
static int nbb,
menu_mode,
event_mode;
static double evx, evy;
static int eid;
static int getting_text;
static double Y;
int box_given = 0;
int transparent = 0;
double BX1, BY1, BX2, BY2;
/* ======================================== */
/* getpick - draws a menu then gets user response and
sends back the name of the menu box selected. Menu
can be defined in a file or by a string of tokens.
New is normally 1, but can be set to 0 to append to
an existing bounding box list. Draw is normally 1
but can be set to 0 to "overlay" graphics.
*/
getpick( rtn, proc, new, draw )
char rtn[]; /* user's selection placed here */
char proc[]; /* name of menu def file */
int new; /* if yes, start a new bounding box list */
int draw; /* if yes, draw menu; if no, don't draw menu */
{
int ix, fromstring, ixx, e;
char coords[80], label[80], buf[200];
double x, y;
fromstring = 0;
if( strlen( proc ) < 1 ) goto SKIP; /* for null argument.. */
sprintf( buf, "%s/%s", Templatepath, proc );
fp = fopen( buf, "r" );
if( fp == NULL ) {
fromstring = 1;
y = 10;
ixx = 0;
}
if( new ) {
nbb = 0;
bbxlo = 999; bbxhi = -999; bbylo = 999; bbyhi = -999;
}
if( draw ) {
NTbatch_on();
NTfont( "/Helvetica-Oblique" );
NTptsize( 10 );
NTlinetype( "0", 3, 1 );
}
if( Dev == 'm' ) fprintf( stderr, "=====================\n" );
while( 1 ) {
if( fromstring ) {
bb[nbb][0] = 8.0; bb[nbb][1] = y-0.4; bb[nbb][2] = 11.0; bb[nbb][3] = y;
strcpy( name[nbb], getok( proc, &ixx ));
if( strlen( name[nbb] ) < 1 ) break;
strcpy( label, name[nbb] );
y -= 0.5;
}
else { /* from file */
if( fgets( buf, 200, fp ) == NULL ) break;
ix = 0;
getfld( coords, buf, &ix );
getfld( label, buf, &ix );
getfld( name[nbb], buf, &ix );
sscanf( coords, "%lf %lf %lf %lf", &bb[nbb][0], &bb[nbb][1], &bb[nbb][2], &bb[nbb][3] );
}
if( draw ) {
ab_rect( bb[nbb][0], bb[nbb][1], bb[nbb][2], bb[nbb][3], 1.0, 1 );
NTmov( bb[nbb][0], bb[nbb][1] + ((bb[nbb][3]-bb[nbb][1])/2.0) );
NTcentext( label, bb[nbb][2]-bb[nbb][0] );
}
if( bb[nbb][0] < bbxlo ) bbxlo = bb[nbb][0];
if( bb[nbb][1] < bbylo ) bbylo = bb[nbb][1];
if( bb[nbb][2] > bbxhi ) bbxhi = bb[nbb][2];
if( bb[nbb][3] > bbyhi ) bbyhi = bb[nbb][3];
if( Dev == 'm' ) fprintf( stderr, "%-2d) %s\n", nbb+1, name[nbb] ); /* term menu */
nbb ++;
}
if( fp != NULL ) fclose( fp );
if( draw ) {
NTnormline();
NTbatch_off();
}
SKIP:
event_mode = PICK;
NTwait(); /* let user pick */
get_event( &x, &y, &e ); /* spurious event */
if( Dev == 'm' ) while( 1 ) { /* term menu */
fprintf( stderr, "Selection: " );
fgets( buf, 10, stdin );
if( atoi( buf ) > 0 && atoi( buf ) <= nbb )
{ strcpy( selection, name[ atoi( buf ) -1 ] ); break; }
}
strcpy( rtn, selection );
}
/* ================================ */
/* This gets called by the driver when 1) we are waiting for an event by calling NTwait(),
and 2) a key or mouse event happens. */
/* NOTE: menu picking is in effect while getting a string */
handle_event( x, y, e )
double x, y;
int e;
{
int i;
/* for menus.. */
if( event_mode == PICK ) {
/* look up (x,y) in bounding box list */
if( x > bbxlo && x < bbxhi && y > bbylo && y < bbyhi ) {
for( i = nbb-1; i >= 0; i-- ) {
if( x > bb[i][0] && y > bb[i][1] && x < bb[i][2] && y < bb[i][3] ) break;
}
if( i == nbb ) return( 0 ); /* not found */
strcpy( selection, name[i] ); return( 1 ); /* found */
}
}
/* for strings */
else if( event_mode == STRING && e > 0 && e < 128 ) {
selection[0] = (char) e;
selection[1] = '\0';
return( 1 );
}
else if( event_mode == EVENTS ) {
evx = x; evy = y; eid = e;
return( 1 );
}
return( 0 );
}
/* ================================== */
message( s1, s2, s3, s4 )
char s1[], s2[], s3[], s4[];
{
NTptsize( 10 );
ab_rect( 8.0, 10.0, 11.0, 11.0, 1.0, 1 );
NTmov( 8.1, 10.7 ); NTtext( s1 );
NTmov( 8.1, 10.5 ); NTtext( s2 );
NTmov( 8.1, 10.3 ); NTtext( s3 );
NTmov( 8.1, 10.1 ); NTtext( s4 );
if( Dev == 'm' ) fprintf( stderr, "\t\t* %s\n\t\t* %s\n\t\t* %s\n\t\t* %s\n", s1, s2, s3, s4 );
}
/* ==================================== */
get_event( x, y, e )
double *x, *y;
int *e;
{
char ans[20];
event_mode = EVENTS;
NTwait();
*x = evx; *y = evy; *e = eid;
}
/* ==================================== */
/* prompts user for one line of text */
get_string( s, p )
char s[], p[];
{
int i;
double x, y;
if( Dev == 'm' ) { /* terminal interface */
fprintf( stderr, "%s: ", p );
fgets( s, 100, stdin );
return( 1 );
}
if( !box_given ) { BX1 = 0.3; BY1 = 0.1; BX2 = 9; BY2 = 0.5; }
if( getting_text ) y = Y; /* Y set in get_text() */
else y = BY1;
x = BX1 + 0.2 + ( strlen( p ) * Chh * 0.5 );
/* do box and prompt */
NTlinetype( "0", 3, 1 );
if( getting_text && !transparent ) ab_rect( BX1, y-0.1, BX2, y+Chh, 1.0, 0 );
else if( !transparent )ab_rect( BX1, y-0.1, BX2, y+0.4, 1.0, 1 );
NTnormline();
NTmov( BX1+0.1, y );
NTtext( p );
NTmov( x, y );
i = 0;
while( 1 ) {
NTmov( x, y );
event_mode = STRING;
NTwait(); /* let user enter char */
if( selection[0] == '\b' || selection[0] == '\177' ) {
if( i == 0 ) continue;
i--;
ab_rect( (x-(Chh*0.5)), y-(Chh*0.28), x, (y+(Chh*0.85)), 1.0, 0 );
x -= ( Chh * 0.5 );
continue;
}
else if( selection[0] == '\015' || selection[0] == '\012' ) break;
else if( selection[0] == '\004' ) { /* control-D stops */
strcpy( s, "\004" );
return( 1 );
}
else NTtext( selection );
s[i++] = selection[0];
x += (Chh * 0.5 );
}
s[i] = '\0';
if( !getting_text && !transparent )ab_rect( BX1, y-0.1, BX2, y+0.4, 0.98, 0 );
}
/* ========================================= */
/* gets multi-row text. */
get_text( buf, p )
char buf[], p[];
{
int i, j, maxlen;
double x;
char uin[20];
if( Dev == 'm' ) { /* for terminal interface */
fprintf( stderr, "=======================\n" );
sprintf( buf, "%s Enter \".\" to stop..\n", p );
fprintf( stderr, "%s", buf );
i = 0;
while( 1 ) {
fgets( &buf[i], 100, stdin );
if( strcmp( &buf[i], ".\n" )==0 ) break;
i += strlen( &buf[i] );
}
buf[ i-1 ] = '\0';
return( 1 );
}
sprintf( buf, "%s Press Control-D to stop..\n", p );
maxlen = 80; /* max length of any line */
if( !box_given ) { BX1 = 0.3; BY1 = 0.3; BX2 = 9; BY2 = 8.0; }
x = BX1;
Y = BY2;
if( !transparent )ab_rect( x-0.1, BY1, BX2+0.1, Y+0.2, 1.0, 1 );
NTmov( x, Y );
if( !transparent) { NTcentext( buf, BX2-BX1 ); Y -= Chh; }
getting_text = 1;
nbb = 0;
/* control D quits */
for( i = 0; i < MAXBB; i++ ) {
bb[i][0] = BX1; bb[i][1] = Y-(Chh*1.6); bb[i][2] = BX2; bb[i][3] = Y; sprintf( name[i], "%d", i );
get_string( &(buf[i*maxlen]), "" );
if( buf[i*maxlen] == '\004' ) break;
for( j = (i*maxlen)+ strlen( &buf[i*maxlen] ); j < ((i+1)*maxlen)-1; j++ ) buf[j] = ' ';
buf[ ((i+1)*maxlen) -1 ] = '\n';
Y -= Chh;
}
buf[i*maxlen] = '\0';
bbxlo = 0; bbxhi = 11; bbylo = 0; bbyhi = 11;
getting_text = 0;
}
/* =============================== */
get_string_box( s, p, x1, y1, x2, y2 )
char s[], p[];
double x1, y1, x2, y2;
{
box_given = 1;
BX1 = x1; BY1 = y1; BX2 = x2; BY2 = y2;
get_string( s, p );
box_given = 0;
}
/* =============================== */
get_text_box( s, p, x1, y1, x2, y2 )
char s[], p[];
double x1, y1, x2, y2;
{
box_given = 1;
BX1 = x1; BY1 = y1; BX2 = x2; BY2 = y2;
get_text( s, p );
box_given = 0;
}
/* =============================== */
get_text_box_tp( s, p, x1, y1, x2, y2 )
char s[], p[];
double x1, y1, x2, y2;
{
transparent = 1;
get_text_box( s, p, x1, y1, x2, y2 );
transparent = 0;
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/pie.c
#include "ipl.x"
Pie( )
{
int i, f, first, ns, explode;
double theta, val, stop;
double hx, hy, x, y, r;
double sh[20], lt;
double u, ux, uy, adj;
gget( Buf, "Field" );
f = atoi( Buf );
gget( Buf, "Center" );
sscanf( Buf, "%lf %lf", &hx, &hy );
gget( Buf, "Radius" );
r = atof( Buf );
gget( Buf, "Linethick" );
lt = atof( Buf );
NTlinetype( "0", lt, 1.0 );
gget( Buf, "Explode" );
u = atof( Buf );
gget( Buf, "Rotate" );
adj = atof( Buf );
gget( Buf, "Shade" );
ns = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
&sh[0],&sh[1],&sh[2],&sh[3],&sh[4],&sh[5],&sh[6],&sh[7],&sh[8],&sh[9],
&sh[10],&sh[11],&sh[12],&sh[13],&sh[14],&sh[15],&sh[16],&sh[17],&sh[18],&sh[19] );
/* do shades */
theta = adj * (3.1415927/180.0) ;
for( i = 0; i < N_d_rows; i++ ) {
val = atof( D[i][f-1] );
/* convert val (percentage) to radians.. */
val = ( val/100.0 ) * 6.28319;
stop = theta + val;
ux = u * cos( theta+(val/2.0) );
uy = u * sin( theta+(val/2.0) );
first = 1;
for( ; theta < (stop+0.001); theta += 0.02 ) {
x = hx + (r * cos( theta ));
y = hy + (r * sin( theta ));
if( first ) { NTmov( hx+ux, hy+uy ); NTpath( x+ux, y+uy ); first = 0; }
NTpath( x+ux, y+uy );
}
if( i < ns )NTshade( sh[i] );
else NTshade( 1.0 );
theta = stop;
}
/* do lines */
theta = adj * (3.1415927/180.0);
for( i = 0; i < N_d_rows; i++ ) {
val = atof( D[i][f-1] );
/* convert val (percentage) to radians.. */
val = ( val/100.0 ) * 6.28319;
stop = theta + val;
ux = u * cos( theta+(val/2.0) );
uy = u * sin( theta+(val/2.0) );
first = 1;
for( ; theta < (stop+0.001); theta += 0.02 ) {
x = hx + (r * cos( theta ));
y = hy + (r * sin( theta ));
if( first ) { NTmov( hx+ux, hy+uy ); NTlin( x+ux, y+uy ); first = 0; }
NTlin( x+ux, y+uy );
}
NTlin( hx+ux, hy+uy );
theta = stop;
}
NTnormline();
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/point.c
#include "ipl.x"
/* draw a data point */
/* point styles are selected by the code string "symNSf.ff", where N is an integer
0-9 selecting the shape, S is a lower-case character selecting the style, and
f.ff is an optional shade, which overrides that selected as part of the style.
N and S are required. See point1.g in the examples.
*/
#define NVARIAT 18
#define NSHAPE 6
Point( )
{
double x, y, r;
char code[20];
gget( Buf, "Mark" );
strcpy( code, Buf );
gget( Buf, "Position" );
sscanf( Buf, "%lf %lf", &x, &y );
gget( Buf, "Size" );
sscanf( Buf, "%lf", &r );
NTptsize( r );
r = Chh * 0.4;
point( x, y, code, r );
}
point( x, y, code, r )
double x, y; /* point location in abs space */
char code[]; /* pre-set symbol name */
double r; /* radius of dot in absolute units */
{
int i;
double g, theta;
static char prevcode[10] = "";
static double prev_r, shade;
static int inc, ins;
static int nc[] = { 3, 3, 4, 4, 5, 12 }; /* number of corners */
static int nt[] = { 90,270, 0, 45, 90, 90, 90 }; /* location (in deg) to start building point */
/* preset outline thicknesses.. */
static double ol[] = { .5, 1,1.5, 2, .5, .5, .5, .5, .5, 0, 0, 0, 0, 0, -0.5, -1, -1.5, -2 };
/* preset shades.. */
static double sh[] = { -1, -1, -1, -1, 1, .9, .7, .5, .3, .9, .7, .5, .3, 0, -1, -1, -1, -1 };
static double h[14][2]; /* the offsets */
/* no-op code */
if( strcmp( code, "sym00" ) == 0 ) return( 0 );
if( strcmp( code, prevcode ) != 0 || r != prev_r ) {
strcpy( prevcode, code );
prev_r = r;
inc = ((code[3] - '0') -1 ) % NSHAPE;
if( code[4] == '\0' ) code[4] = 'a';
ins = (code[4] - 'a') % NVARIAT;
if( strlen( code ) > 5 )shade = atof( &code[5] );
else shade = sh[ins];
theta = 360.0 / (double)nc[inc];
/* get offsets */
g = nt[inc];
for( i = 0; i < nc[inc]; i++ ) {
h[i][0] = r * cos( (g*3.1415927)/180.0 );
h[i][1] = r * sin( (g*3.1415927)/180.0 );
g += theta;
}
}
/* lock-on */
/* shade point */
if( shade >= 0 ) {
NTmov( x+h[0][0], y+h[0][1] );
for( i = 1; i < nc[inc]; i++ ) NTpath( x+h[i][0], y+h[i][1] );
NTshade( shade );
}
/* draw perimeter point */
if( ol[ins] > 0.0 ) {
NTlinetype( "0", ol[ins], 1.0 );
NTmov( x+h[0][0], y+h[0][1] );
for( i = 1; i < nc[inc]; i++ ) NTlin( x+h[i][0], y+h[i][1] );
NTlin( x+h[0][0], y+h[0][1] );
NTnormline();
}
/* draw spokes */
if( ol[ins] < 0.0 ) {
double fabs();
NTlinetype( "0", fabs(ol[ins]), 1.0 );
for( i = 0; i < nc[inc]; i++ ) { NTmov( x, y ); NTlin( x+h[i][0], y+h[i][1] ); }
NTnormline();
}
/* lock-off */
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/polygon.c
/* polygon - for creating polygons, optionally shaded and outlined */
#include "ipl.x"
#define ABSOLUTE 0
#define DATA 1
Polygon( )
{
int sys, n, i, p, outline;
double mag, thick, x, y, fx, fy;
char ltype[10], s1[12], s2[12], s3[12], s4[12];
gget( Buf, "System" );
if( strcmp( Buf, "absolute" )==0 ) sys = ABSOLUTE;
else {
sys = DATA;
if( DXlo == 0 && DXhi == 0 ) { fprintf( stderr, "No graphics area.\n" ); gdp_exit(); }
}
gget( Buf, "Outline" );
if( Buf[0] == 'y' ) outline = 1;
else outline = 0;
/* get line style parameters */
gget( Buf, "Linetype" ); strcpy( ltype, Buf );
gget( Buf, "Linetype.magnify" );
if( goodnum( Buf, &p )) mag = atof( Buf );
else mag = 1;
gget( Buf, "Linethick" ); thick = atof( Buf );
/* set line style */
NTlinetype( ltype, thick, mag );
/* get points */
gget( Buf2, "Rectangle" );
if( strlen( Buf2 ) > 0 ) {
sscanf( Buf2, "%s %s %s %s", s1, s2, s3, s4 );
sprintf( Buf, "%s %s\n%s %s\n%s %s\n%s %s", s1, s2, s1, s4, s3, s4, s3, s2 );
}
else gget( Buf, "Points" );
if( strlen( Buf ) < 1 ) { fprintf( stderr, "Points or Rectangle not specified.\n" ); gdp_exit(); }
getln( "" );
for( i = 0; i < countln( Buf ); i++ ) {
n = sscanf( getln( Buf ), "%lf %lf", &x, &y );
if( sys == DATA && i == 0 ) NTm( x, y );
else if( sys == ABSOLUTE && i == 0 ) NTmov( x, y );
else if( sys == DATA ) NTp( x, y );
else if( sys == ABSOLUTE ) NTpath( x, y );
else { fprintf( stderr, "Points should contain one coord pair per line.\n" ); gdp_exit(); }
}
gget( Buf2, "Shade" );
if( strlen( Buf2 ) > 0 ) NTshade( atof( Buf2 ) );
if( outline ) {
getln( "" ); /* reset getln() */
for( i = 0; i < countln( Buf ); i++ ) {
n = sscanf( getln( Buf ), "%lf %lf", &x, &y );
if( sys == DATA && i == 0 ) { NTm( x, y ); fx = x; fy = y; }
else if( sys == ABSOLUTE && i == 0 ) { NTmov( x, y ); fx = x; fy = y; }
else if( sys == DATA ) NTl( x, y );
else if( sys == ABSOLUTE ) NTlin( x, y );
else { fprintf( stderr, "Points should contain one coord pair per line.\n" ); gdp_exit(); }
}
if( sys == DATA ) NTl( fx, fy );
else if( sys == ABSOLUTE ) NTlin( fx, fy );
}
NTnormline(); /* return line to normal */
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/proc_call.c
/* proc_call() - calls the appropriate funtion, given the proc name. */
#include "ipl.h"
proc_call( proc )
char proc[];
{
char p1[30], p2[30];
/* make sure there's data if we're plotting */
if( smember( proc, "Distribution Bargraph Vbargraph Lineplot Rangebar Vrangebar Vector Boxplot Errorbars Map" ) ) {
if( strcmp( proc, "Map" )!= 0 && N_d_rows <= 0 )
{ fprintf( stderr, "No data yet, use Proc Getdata to read some.\n" ); gdp_exit(); }
if( Xlo == 0 && Xhi == 0 )
{ fprintf( stderr, "No graphics area, use Proc Areadef to define one.\n" ); gdp_exit(); }
}
if( Dev == 's' ) siplmenu( proc ); /* sipl menu at end of page */
if( strcmp( proc, "Initialize" )!= 0 )NTbatch_on();
if( strcmp( proc, "Initialize" )==0 ) Initialize( );
else if( strcmp( proc, "Exit" )==0 ); /* see below */
else if( strcmp( proc, "Page" )==0 ) Page( );
else if( strcmp( proc, "Areadef" )==0 ) Areadef( );
else if( strcmp( proc, "Getdata" )==0 ) Getdata( );
else if( strcmp( proc, "Distribution" )==0 ) Distribution( );
else if( strcmp( proc, "Bargraph" )==0 ) Bargraph( );
else if( strcmp( proc, "Vbargraph" )==0 ) Vbargraph( );
else if( strcmp( proc, "Lineplot" )==0 ) Lineplot( );
else if( strcmp( proc, "Legend" )==0 ) Legend( );
else if( strcmp( proc, "Map" )==0 ) Map( );
else if( strcmp( proc, "Rangebar" )==0 ) Rangebar();
else if( strcmp( proc, "Vrangebar" )==0 ) Vrangebar();
else if( strcmp( proc, "Vector" )==0 ) Vector();
else if( strcmp( proc, "Pie" )==0 ) Pie();
else if( strcmp( proc, "Errorbars" )==0 ) Errorbars();
else if( strcmp( proc, "Nicetab" )==0 ) Nicetab( );
else if( strcmp( proc, "Boxplot" )==0 ) Boxplot( );
else if( strcmp( proc, "Text" )==0 ) Text( );
else if( strcmp( proc, "Draw" )==0 ) Draw( );
else if( strcmp( proc, "Arrow" )==0 ) Arrow( );
else if( strcmp( proc, "Polygon" )==0 ) Polygon( );
else if( strcmp( proc, "Point" )==0 ) Point();
else if( strcmp( proc, "Pagebreak" )== 0 ) { NTshow(); }
else if( strcmp( proc, "QuitAppend" )==0 ) { Hold = 1; }
else if( strcmp( proc, "Endoffile" )==0 ) ; /* no op */
else fprintf( stderr, "proc_call: %s is unrecognized.. continuing\n", proc );
NTbatch_off();
if( strcmp( proc, "Exit" )==0 ) Exit();
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/rangebar.c
#include "ipl.x"
Rangebar( )
{
int f[8], row, i, doends, nf, nv, ir, mlrightonly, label, xf;
double val[8];
double w, x, shade, lblpos, mlw;
gget( Buf, "Nval" );
nv = atoi( Buf );
gget( Buf, "Field" );
if( nv == 1 ) { nf = sscanf( Buf, "%d", &f[1] ); f[2] = f[3] = f[1]; f[4] = f[5] = f[1]; }
else if( nv == 2 ) { nf = sscanf( Buf, "%d %d", &f[1], &f[4] ); f[2] = f[3] = f[1]; f[5] = f[4]; }
else if( nv == 3 ) { nf = sscanf( Buf, "%d %d %d", &f[1], &f[3], &f[5] ); f[2] = f[1]; f[4] = f[5]; }
else if( nv == 4 ) { nf = sscanf( Buf, "%d %d %d %d", &f[1], &f[2], &f[4], &f[5] ); f[3] = f[4]; }
else if( nv == 5 ) { nf = sscanf( Buf, "%d %d %d %d %d", &f[1], &f[2], &f[3], &f[4], &f[5] ); }
if( nf != nv ) { fprintf( stderr, "Expecting %d Field values.\n", nv ); gdp_exit(); }
gget( Buf, "Width" ); w = atof( Buf );
gget( Buf, "Linethick" );
NTlinetype( "0", atof( Buf ), 1.0 );
label = 0;
gget( Buf, "Idfield" );
f[0] = atoi( Buf );
if( f[0] > 0 ) {
label = 1;
gget( Buf, "Label.size" );
if( atoi( Buf ) > 0 ) NTptsize( atoi( Buf ) );
gget( Buf, "Label.position" );
lblpos = atof( Buf );
}
doends = 0;
if( nf == 4 || nf == 5 ) {
gget( Buf, "Ends" );
if( Buf[0] == 'y' ) doends = 1;
}
mlw = w;
mlrightonly = 0;
if( nf == 3 || nf == 5 ) {
gget( Buf, "Midlinewidth" );
if( atof( Buf ) > 0 )mlw = atof( Buf );
gget( Buf, "Midlineright" );
if( Buf[0] == 'y' ) mlrightonly = 1;
}
gget( Buf, "Shade" );
shade = atof( Buf );
gget( Buf, "Xfield" );
xf = atoi( Buf );
x = DXlo;
for( ir = 0; ir < N_d_rows; ir++ ) {
for( i = 1; i <= 5; i++ ) val[i] = atof( D[ ir ][ f[i]-1 ] );
if( nv == 1 ) { val[1] = val[2] = 0; }
if( xf > 0 ) x = atof( D[ir][ xf-1 ] );
else x++;
NTm( x-(w/2), val[2] ); /* lower edge of box */
NTp( x+(w/2), val[2] );
NTp( x+(w/2), val[4] );
NTp( x-(w/2), val[4] );
NTp( x-(w/2), val[2] ); /* upper edge */
NTshade( shade );
NTm( x, val[1] ); /* lower tail */
NTl( x, val[2] );
if( doends ) { NTm( x-(w/2.7), val[1] ); NTl( x+(w/2.7), val[1] ); }
NTm( x-(w/2), val[2] ); /* lower edge of box */
NTl( x+(w/2), val[2] );
NTl( x+(w/2), val[4] );
NTl( x-(w/2), val[4] );
NTl( x-(w/2), val[2] ); /* upper edge */
NTm( x, val[4] );
NTl( x, val[5] ); /* upper tail */
if( doends ) { NTm( x-(w/2.7), val[5] ); NTl( x+(w/2.7), val[5] ); }
if( mlrightonly )NTm( x-(w/2), val[3] ); /* median line */
else NTm( x-(mlw/2), val[3] );
NTl( x+(mlw/2), val[3] );
if( label ) {
NTmov( da_x(x) -1, da_y(lblpos) ); /* print label */
sprintf( Buf, "%s", D[ir][f[0]-1 ] );
NTcentext( Buf, 2 );
}
}
NTnormline();
}
SHAR_EOF
############################
cat << \SHAR_EOF > src/rect.c
/* do a rectangle, with shading and/or outline */
/* only used internally, user proc is Polygon */
#include "ipl.x"
/* rect() - all coords in data space */
rect( xlo, ylo, xhi, yhi, shade, outline )
double xlo, ylo, xhi, yhi, shade;
int outline;
{
if( shade >= 0 ) {
NTm( xlo, ylo );
NTp( xlo, yhi );
NTp( xhi, yhi );
NTp( xhi, ylo );
NTshade( shade );
}
if( outline ) {
NTm( xlo, ylo );
NTl( xlo, yhi );
NTl( xhi, yhi );
NTl( xhi, ylo );
NTl( xlo, ylo );
}
}
/* ab_rect() - all coords in absolute space */
ab_rect( xlo, ylo, xhi, yhi, shade, outline )
double xlo, ylo, xhi, yhi, shade;
int outline;
{
if( shade >= 0 ) {
NTmov( xlo, ylo );
NTpath( xlo, yhi );
NTpath( xhi, yhi );
NTpath( xhi, ylo );
NTshade( shade );
}
if( outline ) {
NTmov( xlo, ylo );
NTlin( xlo, yhi );
NTlin( xhi, yhi );
NTlin( xhi, ylo );
NTlin( xlo, ylo );
}
}
SHAR_EOF
############################
--
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.
More information about the Comp.sources.unix
mailing list