home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-07-24 | 28.5 KB | 1,104 lines |
- Subject: v21i038: 2D graphic system with table beautifier, Part07/14
- Newsgroups: comp.sources.unix
- Approved: rsalz@uunet.UU.NET
- X-Checksum-Snefru: 480615d0 b4f2cf29 e2047f7b de987b57
-
- Submitted-by: Steve Grubb <uunet!lsr-vax!scg>
- Posting-number: Volume 21, Issue 38
- Archive-name: ipl/part07
-
- # ipl part07
- # 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/initialize.c
- # src/ipl.d
- # src/ipl.h
- # src/ipl.icon
- # src/ipl.x
- # src/iplps.c
- # src/legend.c
- # src/lib.c
- # src/lineplot.c
- cat << \SHAR_EOF > src/initialize.c
- /* IPL will be invoked by:
- tipl for postscript (to standard output)
- sipl for sunview previewer
- vipl for window-oriented composer
- mipl for terminal-oriented composer
- */
-
- #include "ipl.x"
- #include "gdp.x" /* for command line arguments */
-
- static char fnm[PATHNAME_LEN];
- static int filecount;
-
- Initialize( )
- {
- int yr, mon, day, hr, min, sec, i;
- char host[30];
-
- sysdate( &mon, &day, &yr ); systime( &hr, &min, &sec );
-
- strcpy( Templatepath, TEMPLATE_PATH );
-
- sprintf( Tempfile, "%s/NTtmp%05d", INSTALL_TMP, getpid() );
-
- Dev = Arg[0][ strlen( Arg[0] ) -4 ]; /* get output type */
- Hold = 0;
- if( !member( Dev, "tsvm" )) { fprintf( stderr, "Use tipl, sipl, vipl or mipl.\n" ); gdp_exit(); }
-
- /* composers take off from here.. */
- if( smember( Arg[0], "vipl" )) {
- if( Argc < 2 ) { fprintf( stderr, "A control file name argument must be given.\n" ); gdp_exit(); }
- NTinit( Dev );
- vipl_sequence( Arg[1] );
- gdp_exit();
- }
-
- /* control file argument given.. */
- if( Argc > 1 ) {
- filecount = 1;
- strcpy( fnm, Arg[1] );
- Sfp = fopen( fnm, "r" );
- }
-
- if( Dev == 't' && Sfp == NULL ) { fprintf( stderr, "Control file not found.\n" ); exit(); }
-
- else if( Sfp == NULL ) {
- NTinit( Dev );
- if( Dev == 's' )siplmenu( "Endoffile" );
- return( 1 );
- }
-
- strcpy( Controlfile, fnm );
-
- NTinit( Dev );
-
-
- DXlo = DXhi = 0; /* null out data dimensions */
- DYlo = DYhi = 0;
- sprintf( Buf, "%s %s (%02d%02d%02d %02d:%02d)", getlogin(), (Argc>1)?Arg[1]:"", yr, mon, day, hr, min );
-
- strcpy( Stdfont, "/Helvetica" );
- StdLw = 1.0;
- NTfont( "/Helvetica" );
- NTptsize( 6 );
- NTmov( 0.1, 0.1 );
- NTtext( Buf );
-
- }
-
-
- /* ============================================= */
- /* start a new control file */
- restart( s )
- char s[];
- {
- FILE *fp;
-
- if( Sfp != NULL ) fclose( Sfp );
-
- if( strcmp( s, "" )==0 ) {
- filecount++;
- if( filecount >= Argc ) gdp_exit();
- strcpy( fnm, Arg[ filecount ] ); /* next file */
- }
-
- else if( strlen( s ) > 0 ) strcpy( fnm, s );
-
- Sfp = fopen( fnm, "r" );
-
- if( Sfp == NULL ) {
- message( fnm, "File not found.", "", "" );
- return( 0 );
- }
-
- strcpy( Controlfile, fnm );
- return( 1 );
- }
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/ipl.d
- /* constants */
- #include "../install.h"
- #define FONTNAME_LEN 30
- #define TMPFILE_PATH INSTALL_TMP
- #define NSLOTS 24 /* number of slots in ASmax[] */
-
- #define MOUSE_LEFT 1001
- #define MOUSE_MIDDLE 1002
- #define MOUSE_RIGHT 1003
-
- extern char *getln();
- extern FILE *popen();
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/ipl.h
- #include "graphic.x"
- #include "ipl.d"
-
- char Dev; /* output device */
- char D[ MAX_D_ROWS ][ MAX_D_COLS ][ DATAITEM_LEN ]; /* plot data */
- int N_d_fields; /* number of data fields per row */
- int N_d_rows; /* number of data rows */
- char Buf[HBUFSIZ]; /* general purpose buffers */
- char Buf2[512];
-
- double Chsz; /* character size */
- double Chh; /* height of a line of text */
- double Chw; /* character spacing */
- double Chd; /* character direction vector, x comp. */
- int Paper = 0; /* paper orientation */
- double Lw; /* current line width */
- double StdLw = 1.0; /* standard line width */
- double Rgb; /* color identifier */
- double Rgbint; /* color intensity identifier */
-
- /* maxes for autoscaling -- currently not used */
- double ASmaxes[30] = { 0.1, 0.5, 1, 5, 10, 20, 30, 50, 75, 100, 200, 300, 500, 750, 1000, 1250, 1500, 2000, 2500, 3000, 5000,
- 10000, 20000, 30000, 50000, 100000 };
-
- /* default tic increments */
- double Incs[30] = { 0.01, 0.05, 0.1, 1, 1, 2, 5, 5, 5, 10, 20, 20, 50, 50, 50, 50,
- 100, 100, 100, 200, 500, 500, 1000, 2000, 5000, 5000 };
-
- /* default tic stub number formats */
- char *Tformats[30]= { "%2.2f", "%2.2f", "%2.1f", "%2.1f", "%2.0f", "%2.0f", "%2.0f", "%2.0f", "%2.0f", "%3.0f",
- "%3.0f", "%3.0f", "%3.0f", "%3.0f", "%4.0f", "%4.0f", "%4.0f", "%4.0f", "%4.0f", "%4.0f",
- "%4.0f", "%5.0f", "%5.0f", "%5.0f", "%5.0f", "%6.0f" };
-
- double DXtic, DYtic; /* tic increments */
-
- char DXticfmt[12], DYticfmt[12]; /* printf format for numeric stubs */
-
- char Tempfile[PATHNAME_LEN]; /* name of uniquely named temp file */
-
- double Xmin, Xmax, Ymin, Ymax; /* ranges of the input data, set by proc, before calling global() */
-
- int Hold; /* TRUE if QuitAppend was called */
-
- char Templatepath[PATHNAME_LEN]; /* location of templates and aux. files */
-
- char Stdfont[FONTNAME_LEN]; /* page-wide default font */
-
- char Controlfile[PATHNAME_LEN] = ""; /* name of control file */
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/ipl.icon
- /* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
- */
- 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
- 0x0018,0x003C,0x0000,0x0000,0x0000,0x000C,0x0000,0x0000,
- 0x3C78,0x6C0C,0x0000,0x0000,0x6618,0x760C,0x00FC,0x0000,
- 0x6018,0x660C,0x00FC,0x0000,0x3C18,0x660C,0x00CC,0x7E00,
- 0x0618,0x660C,0x00CC,0x7E00,0x6618,0x760C,0x00CC,0x6600,
- 0x3C18,0x6C0C,0x00CC,0x6600,0x0000,0x6000,0x00CC,0x6600,
- 0x0000,0x6000,0x00CC,0x6600,0x0000,0x6000,0x00CC,0x6600,
- 0x0660,0x0000,0x00CC,0x6600,0x0660,0x0000,0x00CC,0x6600,
- 0x0660,0x03F0,0x00CC,0x6600,0x0660,0x03F0,0x00CC,0x6600,
- 0x0660,0x0330,0x00CC,0x6600,0x0660,0x0330,0x00CC,0x663F,
- 0x0667,0xE330,0x00CC,0x663F,0x0667,0xE330,0x00CC,0x6633,
- 0x0666,0x6330,0x00CC,0x6633,0x0666,0x6330,0x00CC,0x6633,
- 0x0666,0x6331,0xF8CC,0x6633,0x0666,0x6331,0xF8CC,0x6633,
- 0x0666,0x6331,0x98CC,0x6633,0x0666,0x6331,0x98CC,0x6633,
- 0x0666,0x6331,0x98CC,0x6633,0x07E7,0xE3F1,0xF8FC,0x7E3F,
- 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0x8040,0x1004,0x0100,0x4010,
- 0x8040,0x1004,0x0100,0x4010,0x8040,0x1004,0x0100,0x4010,
- 0xAE40,0x1004,0x0100,0x4010,0xE1FE,0x1004,0x0100,0x5810,
- 0xF801,0xFFFF,0xDFF7,0xE5FF,0xC800,0x000F,0xC100,0x6410,
- 0xC000,0x0000,0x4100,0x4010,0xC000,0x0000,0xBD00,0x4410,
- 0xC000,0x0000,0xA501,0xC410,0xC000,0x0000,0xC7F6,0x0DFF,
- 0xC000,0x0000,0xC818,0x1810,0xC000,0x0001,0x49E0,0x0810,
- 0x8000,0x0001,0xCE80,0x1C10,0x8000,0x0000,0x0000,0x6010,
- 0x8000,0x0000,0x0000,0xC010,0x8000,0x0000,0x0000,0xFDFF,
- 0x8000,0x0000,0x0001,0x4010,0x8000,0x0000,0x0001,0x4010,
- 0xC000,0x0000,0x0002,0x4010,0xC000,0x0000,0x0002,0x43FF,
- 0xE000,0x0000,0x0004,0x4201,0xA000,0x0000,0x0007,0xFE01,
- 0x9000,0x0000,0x0008,0x427D,0x9000,0x0000,0x0000,0x4201,
- 0x8800,0x0000,0x0010,0x427D,0x8600,0x0000,0x0020,0x4201,
- 0xF7E0,0x0000,0x0077,0xFE7D,0x8050,0x00C7,0x1840,0x4201,
- 0x8050,0x0134,0xE440,0x427D,0x8049,0x820C,0x2220,0x4201,
- 0x804E,0x4208,0x2220,0x4201,0xFFFF,0xFFFF,0xFF3F,0xFFFF
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/ipl.x
- #include "graphic.x"
- #include "ipl.d"
-
- extern char Dev;
- extern char D[ MAX_D_ROWS ][ MAX_D_COLS ][ DATAITEM_LEN ]; /* plot data */
- extern int N_d_fields; /* number of data fields per row */
- extern int N_d_rows; /* number of data rows */
- extern char Buf[]; /* general purpose buffers */
- extern char Buf2[];
-
- extern double Chsz; /* character size */
- extern double Chw; /* character spacing */
- extern double Chh; /* height of a line of text */
- extern double Chd; /* character direction vector, x comp. */
- extern int Paper; /* paper orientation */
- extern double Lw; /* current line width */
- extern double StdLw; /* standard line width */
- extern double Rgb; /* color identifier */
- extern double Rgbint; /* color intensity identifier */
-
- extern double ASmaxes[];
- extern double Incs[];
- extern char *Tformats[];
-
- extern double DXtic, DYtic;
- extern char DXticfmt[], DYticfmt[];
- extern char Tempfile[];
- extern double Xmin, Xmax, Ymin, Ymax;
- extern int Hold;
- extern char Templatepath[];
- extern char Stdfont[];
- extern char Controlfile[];
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/iplps.c
- /* Postscript driver for IPL.
- (c) 1989 Steve Grubb
- */
-
- #include <stdio.h>
- #define YES 1
- #define NO 0
- #define PORTRAIT 0
- #define LANDSCAPE 1
- #define MARG_X 14
- #define MARG_Y 8
- #define PAGWIDTH 600;
-
- static int orient; /* paper orientation */
- static int orgx, orgy; /* location of origin on page */
- static int theta; /* current rotation for page orientation */
- static char font[50]; /* current font name */
- static int chdir; /* char direction in degrees */
- static int curpointsz; /* current char size in points */
- char *getok();
- double atof();
-
- /* ============================= */
- PSsetup( ) /* initialize */
- {
- /* set globals */
- orient = -1;
- strcpy( font, "/Helvetica" );
- theta = 0;
- chdir = 0;
- curpointsz = 10;
-
- /* print header */
- printf(
- "%%!PS-Adobe-1.0\n%%%%Creator: IPL V1.0(c) 1989 Steve Grubb\n%%%%Pages: (atend)\n" );
-
-
- /* set up macros (mainly to reduce output verbosity) */
- printf( "/sset\n" );
- printf( "{ translate rotate } def \n" );
- printf( "/sclr\n" );
- printf( "{ rotate translate } def \n" );
- printf( "/mv { moveto } def\n" );
- printf( "/np { newpath } def\n" );
- printf( "/ln { lineto } def\n" );
- printf( "/st { stroke } def\n" );
- printf( "/sh { show } def\n" );
- printf( "/cent { stringwidth pop sub 2 div 0 rmoveto } def\n" );
- printf( "/rjust { stringwidth pop sub 0 rmoveto } def\n" );
-
- /* load default font */
- printf( "%s findfont\n", font );
- printf( "%d scalefont setfont\n", (int) curpointsz );
-
- /* set up standard line width */
- printf( "1 setlinewidth\n" );
-
- printf( "%%%%EndProlog\n%%%%Page: ? 1\nsave\n" ); /* begin first page */
- }
-
-
- /* ============================= */
- PSmoveto( x, y )
- double x, y;
- {
-
- /* convert to p.s. units (1/72 inch) */
- x = ( x * 72.0 ) +MARG_X; y = ( y * 72.0 ) + MARG_Y;
- printf( "np\n%-5.2f %-5.2f mv\n", x, y );
- }
-
-
- /* ============================= */
- PSlineto( x, y )
- double x, y;
- {
- /* convert to p.s. units */
- x = ( x * 72 ) +MARG_X;
- y = ( y * 72 ) +MARG_Y;
- printf( "%-5.2f %-5.2f ln\n", x, y );
- }
-
- /* ============================== */
- PSstroke( )
- {
- printf( "st\n" );
- }
-
-
- /* ============================= */
- PSpath( x, y )
- double x, y;
- {
- /* convert to p.s. units */
- x = ( x * 72 ) +MARG_X; y = ( y * 72 ) + MARG_Y;
- printf( "%-5.2f %-5.2f ln\n", x, y );
- }
-
-
- /* ============================= */
- PSshade( s )
- double s;
- {
- printf( "closepath\n%3.2f setgray\nfill\n0 setgray\n", s );
- }
-
- /* ============================== */
- PSpaper( i )
- int i;
- {
- if( orient != -1 ) return( 1 ); /* paper orientation - can only be done once per page */
- if( i == 1 ) { /* handle landscape mode-- it's put into portrait mode before beginning each page */
- orgx = PAGWIDTH;
- orgy = 0;
- theta = 90;
- printf( "%d %d %d sset\n", theta, orgx, orgy );
- }
- orient = (int) i;
- }
-
-
- /* ================================= */
- PStext( com, x, y, s, w )
- char com;
- double x, y;
- char s[];
- double w;
- {
- char str[400];
- int i, j, k;
-
- x = (x*72)+MARG_X; y = (y*72)+MARG_Y; w *= 72;
-
- /* if text direction is not normal do a rotate then move.. */
- if( chdir != 0 ) printf( "%d %-5.2f %-5.2f sset 0 0 mv\n", chdir, x, y );
- /* normal direction-- do a move.. */
- else printf( "%-5.2f %-5.2f mv ", x, y );
-
- if( member( com, "CJ" )) strip_ws( s );
-
- /* escape out parens */
- for( i = 0, j = 0; i < strlen( s ); i++ ) {
- if( s[i] == '(' || s[i] == ')' ) { str[j++] = '\\'; str[j++] = s[i]; }
- else str[j++] = s[i];
- }
- str[j] = '\0';
-
- /* centered text */
- if( com == 'C' ) printf( "%-5.2f (%s) cent ", w, str );
- else if( com == 'J' ) printf( "%-5.2f (%s) rjust ", w, str );
-
- /* do the string */
- printf( "(%s) sh\n", str );
-
- if( chdir != 0 ) printf( "%-5.2f %-5.2f %d sclr\n", -x, -y, -chdir ); /* restore */
- }
-
-
- /* ================================= */
- PSpointsize( p )
- int p;
- {
- if( p != curpointsz ) { /* char size (specified in points) */
- curpointsz = p;
- printf( "%s findfont\n", font );
- printf( "%d scalefont\nsetfont\n", p );
- }
- }
-
-
- /* ================================== */
- PSfont( f )
- char f[];
- {
- if( strcmp( f, font ) != 0 ) {
- strcpy( font, f );
- printf( "%s findfont\n", font );
- printf( "%d scalefont setfont\n", curpointsz );
- }
- }
-
- /* ================================== */
- PSchardir( t )
- int t;
- {
- chdir = t;
- }
-
-
- /* ================================== */
- PSlinetype( s, x, y )
- char s[];
- double x, y;
- {
- /* X = line width; Y = dash pattern magnification (0.1 to 10)
- * S indicates dash pattern. If S is "0", an unbroken (normal) line is produced.
- * If S is "1" through "8", a preset dash pattern is used. Otherwise, S is
- * assumed to hold the dash pattern string "[ n1 n2 n3.. ]".
- */
- static int dash[10][6]= { {0,0,0,0,0,0}, {1,1}, {3,1}, {5,1}, {2,1,1,1}, {4,1,1,1}, {6,1,1,1},
- {2,1,1,1,1,1}, {4,1,1,1,1,1}, {6,1,1,1,1,1} };
- int ltype, i;
-
- printf( "%3.1f setlinewidth\n", x );
- if( strlen( s ) < 1 || strcmp( s, "0" )==0 ) printf( "[] 0 setdash\n" );
- else {
- if( strlen( s ) > 1 ) {
- ltype = 0;
- sscanf( s, "%d %d %d %d %d %d", &dash[0][0], &dash[0][1], &dash[0][2],
- &dash[0][3], &dash[0][4], &dash[0][5] );
- }
- else ltype = atoi( s );
- printf( "[" );
- for( i = 0; i < 6; i++ )
- if( dash[ ltype ][ i ] > 0 ) printf( "%3.1f ", dash[ ltype ][ i ] * y );
- printf( "] 0 setdash\n" );
- }
- }
-
-
- /* =================================== */
-
- PSshow()
- {
- if( orient == 1 )printf( "%d %d %d sclr\n", -orgx, -orgy, -theta ); /* restore rotation */
- orient = -1;
- printf( "showpage\nrestore\nsave\n" );
- }
-
- /* =================================== */
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/legend.c
- /* legend() - creates legend for line and bar graphs */
- #include "ipl.x"
- #define SHADE 1
- #define MARK 4
- #define LINE 8
- #define MAXENTRIES 10
-
- Legend( )
- {
- double val[MAXENTRIES],
- locx, locy,
- margin,
- piclen,
- lablen,
- depth,
- x, ylo, yhi,
- lx, ly, cx, cy, bxw, ty,
- mrksize,
- stdsize,
- pm[MAXENTRIES],
- ms[MAXENTRIES],
- th[MAXENTRIES],
- thick = 1,
- magnify;
- int i,
- n,
- format,
- lenmax,
- outline,
- nms,
- nlt,
- npm,
- nth,
- nmf,
- nent;
- char ent[MAXENTRIES][100],
- poscode[4],
- stdfont[FONTNAME_LEN],
- mrkfont[FONTNAME_LEN],
- lt[MAXENTRIES][3],
- mrk[MAXENTRIES][10],
- mf[MAXENTRIES][20],
- linetype[3];
-
-
-
- gget( Buf, "Entry.font" );
- strcpy( stdfont, Buf ); NTfont( Buf ); /* go to standard font */
-
- strcpy( mrkfont, Stdfont ); /* default mark font */
-
- /* position of legend can either be specified using a corner A,B,C,D or by giving an
- x,y location for the upper left corner of the legend.
- */
- gget( poscode, "Corner" );
- gget( Buf, "Location" );
- if( strlen( Buf ) > 0 ) sscanf( Buf, "%lf %lf", &locx, &locy );
- else { locx = 0; locy = 0; }
-
- gget( Buf, "Location.system" );
- if( strcmp( Buf, "data" )==0 ) { locx = da_x( locx ); locy = da_y( locy ); }
-
-
-
- /* get entries and find longest one */
- gget( Buf, "Entry" );
- lenmax = 0;
- nent = countln( Buf );
- if( nent > MAXENTRIES ) { fprintf( stderr, "Maximum of 10 legend entries" ); nent = 10; }
- getln( "" );
- for( i = 0; i < nent; i++ ) {
- strcpy( ent[i], getln( Buf ) );
- if( strlen( ent[i] ) > lenmax ) lenmax = strlen( ent[i] );
- }
-
- /* figure if we're doing lines or shades, and get 'em */
- format = 0;
- gget( Buf, "Shade" );
- if( strlen( Buf ) > 0 ) {
- format = SHADE;
- n = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &val[0],&val[1],&val[2],&val[3],&val[4],&val[5],&val[6],&val[7],&val[8],&val[9] );
- if( n < nent ) { fprintf( stderr, "need %d shades.\n", nent ); gdp_exit(); }
- }
- gget( Buf, "Linetype" );
- if( strlen( Buf ) > 0 ) {
- format = LINE;
- nlt = sscanf( Buf, "%s %s %s %s %s %s %s %s %s %s",
- lt[0],lt[1],lt[2],lt[3],lt[4],lt[5],lt[6],lt[7],lt[8],lt[9] );
- gget( Buf, "Linetype.magnify" );
- npm = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &pm[0],&pm[1],&pm[2],&pm[3],&pm[4],&pm[5],&pm[6],&pm[7],&pm[8],&pm[9] );
- gget( Buf, "Linethick" );
- nth = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &th[0],&th[1],&th[2],&th[3],&th[4],&th[5],&th[6],&th[7],&th[8],&th[9] );
- }
-
-
- gget( Buf, "Mark" );
- if( strlen( Buf ) > 0 ) {
- format += MARK;
- n = sscanf( Buf, "%s %s %s %s %s %s %s %s %s %s",
- mrk[0],mrk[1],mrk[2],mrk[3],mrk[4],mrk[5],mrk[6],mrk[7],mrk[8],mrk[9] );
- if( n < nent ) { fprintf( stderr, "need %d marks\n", nent ); gdp_exit(); }
-
- gget( Buf, "Mark.font" );
- nmf = sscanf( Buf, "%s %s %s %s %s %s %s %s %s %s",
- mf[0], mf[1], mf[2], mf[3], mf[4], mf[5], mf[6], mf[7], mf[8], mf[9] );
-
- gget( Buf, "Mark.size" );
- nms = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &ms[0],&ms[1],&ms[2], &ms[3], &ms[4], &ms[5], &ms[6], &ms[7], &ms[8], &ms[9] );
- }
-
-
- margin = .20;
- lablen = lenmax * (Chh*0.6); /* lenmax = space in plot units of longest label */
-
- if( format == SHADE || format == MARK ) piclen = .20; /* piclen = size in x of line or swatch */
- else piclen = 1.10;
-
- depth = (Chh*1.2) * (nent+1);
- if( format == SHADE ) depth *= 1.65;
-
- /* generate legend */
- if( locx != 0 || locy != 0 ) { lx = locx; ly = locy; }
- else if( poscode[0] == 'A' ) { lx = Xlo + 0.1; ly = Yhi - 0.1; }
- else if( poscode[0] == 'B' ) { lx = Xhi - (lablen+piclen+margin); ly = Yhi - 0.1; }
- else if( poscode[0] == 'C' ) { lx = Xhi - (lablen+piclen+margin); ly = Ylo + depth; }
- else if( poscode[0] == 'D' ) { lx = Xlo + 0.1; ly = Ylo + depth ; }
- else { fprintf( stderr, "Legend location must be given. Use either Corner or Location parameter." ); gdp_exit(); }
-
- /* do a legend title */
- gget( Buf, "Title.size" );
- NTptsize( atof( Buf ) );
- gget( Buf, "Title" );
- ty = ly + (countln( Buf ) * Chh);
- getln( "" );
- for( i = 0; i < countln( Buf ); i++ ) {
- NTmov( lx, ty );
- NTcentext( getln( Buf ), (lablen+piclen) );
- ty -= Chh;
- }
-
- gget( Buf, "Entry.size" ); stdsize = atof( Buf ); NTptsize( stdsize );
-
- gget( Buf, "Backshade" );
- if( strlen( Buf ) > 0 ) {
- ab_rect( lx-.08, ly - (depth)+0.02, lx+(lablen+piclen), ly+.08, atof( Buf ), 0 );
- }
- gget( Buf, "Outlinebars" );
- if( Buf[0] == 'y' ) outline = YES;
- else outline = NO;
-
- cx = lx; cy = ly;
- for( i = 0; i < nent; i++ ) {
-
- if( format >= MARK && i < nms ) mrksize = ms[i];
- if( format >= LINE && i < nlt ) strcpy( linetype, lt[i] );
- if( format >= LINE && i < npm ) magnify = pm[i];
- if( format >= LINE && i < nth ) thick = th[i];
- if( format >= MARK && i < nmf ) strcpy( mrkfont, mf[i] );
-
- /* trap */ if( format >= LINE && ( thick < 0.01 || thick > 20 )) {
- fprintf( stderr, "Internal error. Try again.\n" ); gdp_exit();
- }
-
- if( format == SHADE || format == MARK ) {
- if( format == SHADE ) {
- cy -= 0.1; x = cx; bxw = 0.2; ylo = cy - 0.1; yhi = cy + 0.1;
- if( outline || val[i] == 1.0 )ab_rect( x, ylo, x+bxw, yhi, val[i], 1 );
- else ab_rect( x, ylo, x+bxw, yhi, val[i], 0 );
- }
- else if( format == MARK ) {
- NTfont( mrkfont ); NTptsize( mrksize );
- if( strncmp( mrk[i], "sym", 3 )==0 ) point( cx, cy, mrk[i], Chh*0.4 );
- else {
- NTmov( cx, cy-0.06 );
- NTtext( mrk[i] );
- NTfont( stdfont );
- }
- NTmov( cx, cy );
- NTfont( stdfont ); NTptsize( stdsize );
- }
- NTmov( cx+0.4, cy-0.06 );
- NTtext( ent[i] );
- }
- else if( format >= LINE ) {
- NTlinetype( linetype, thick, magnify );
- NTmov( cx, cy );
- NTlin( cx+1.0, cy );
- if( format == LINE + MARK ) {
- NTfont( mrkfont ); NTptsize( mrksize );
- if( strncmp( mrk[i], "sym", 3 )==0 ) {
- point( cx+0.2, cy, mrk[i], Chh*0.4 );
- point( cx+0.8, cy, mrk[i], Chh*0.4 );
- }
- else {
- NTfont( mrkfont ); NTptsize( mrksize );
- NTmov( cx+0.2, cy-0.03 ); NTtext( mrk[i] );
- NTmov( cx+0.8, cy-0.03 ); NTtext( mrk[i] );
- NTfont( stdfont ); NTptsize( stdsize );
- }
- NTfont( stdfont ); NTptsize( stdsize );
- }
- NTmov( cx+1.1, cy-0.06 );
- NTtext( ent[i] );
- NTnormline();
- }
- cy -= (Chh*1.2);
- }
- }
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/lib.c
- #include <stdio.h>
- #include <ctype.h>
-
-
- /* ================================ */
- /* getfld()
- /* Gets fields which are separated by ":". */
- /* Natural ":" which appear in text must be prefixed by a backslash. */
- /* Deletes the ':' and all leading and trailing white space. */
- /* Leaves index pointing at next char. */
-
- getfld( out, line, index )
- char out[], line[];
- int *index;
- {
- int i, j, esc;
-
- j = 0;
- for( i = *index; i < strlen( line ); i++ ) {
- if( line[i] == ' ' || line[i] == '\t' ) continue;
- else break;
- }
- for( ; i < strlen( line ); i++ ) {
- if( line[i] == '\\' ) { esc = 1; continue; }
- if( line[i] == ':' && ! esc ) { i++; esc = 0; break; }
- else out[j++] = line[i];
- esc = 0;
- }
- j--;
- for( ; j > 0; j-- ) {
- if( out[j] == ':' || out[j] == ' ' || out[j] == '\t' || out[j] == '\n' || out[j] == '\0' ) continue;
- else break;
- }
- out[ j+1 ] = '\0';
- *index = i;
- }
-
-
- /* ==========================================
- * getok( )
- */
- #define GETOKMAX 100
- char *getok( string, index )
- char string[]; /* array to obtain token from */
- int *index;
- {
- static char tok[GETOKMAX+1];
- register n;
- while( member( string[(*index)], " \t\n" ) ) (*index)++;
- /* EAT( SPACE, TAB, EOR, string, (*index) ); */
- for( n=0;
- n <= GETOKMAX &&
- string[*index] != ' ' &&
- string[*index] != '\t' &&
- string[*index] != '\n' &&
- string[*index] != '\0' ;
- tok[n++] = string[(*index)++] ) ;
- tok[n] = '\0' ;
- if( n > GETOKMAX ) fprintf( stderr, "token %s too long\n", tok );
- return(tok);
- }
-
- /* ================================== */
- /* goodnum() - checks a token to see if it is a legal number,
- either float or integer, returns 1 if so, 0 if not a
- legal number. 2nd arg is precision, ie the position of
- the decimal point
- */
- #include <ctype.h>
- #define YES 1
- #define NO 0
- goodnum( str, prec )
- char str[];
- int *prec;
- {
- int l, p, bad, point;
- l = strlen( str );
- if( l < 1 ) return( 0 );
- bad = NO; *prec = -1;
- for( p = 0; p < l; p++ ) {
- if( str[p] == '.' ) { if( *prec == -1 ) *prec = p; else bad=YES; }
- else if( p == 0 && l > 1 && ( str[p] == '-' || str[p] == '+' ) );
- else if( ! isdigit( str[p]) ) bad=YES;
- }
- if( bad ) return( 0 );
- else return( 1 );
- }
-
-
- /* =================================== */
- /* member() - returns char position if character c is a member of string s,
- 0 otherwise. Char positions start with 1 for this purpose. */
- member( c, s )
- char c, s[];
- {
- int i;
- for( i = 0; i < strlen( s ); i++ ) if( s[i] == c ) return( i+1 );
- return( 0 );
- }
-
-
-
- /* =================================== */
- /* smember() - returns 1 if string s is present as a token in string t,
- 0 otherwise. */
- smember( s, t )
- char s[], t[];
- {
- char tok[100], *getok();
- int i;
- i = 0;
- while( 1 ) {
- strcpy( tok, getok( t, &i ) );
- if( tok[0] == '\0' ) break;
- if( strcmp( tok, s ) == 0 ) return( 1 );
- }
- return( 0 );
- }
-
-
- /* =================================== */
- /* strip white-space off of front and end of string s */
- strip_ws( s )
- char s[];
- {
- int i, j;
- /* find last significant char and put a null after it */
- for( j = strlen( s ) -1; j >= 0; j-- )
- if( !member( s[j], " \t\n" )) break;
- s[j+1] = '\0';
- /* find 1st significant char at position i */
- for( i = 0; i < strlen( s ); i++ )
- if( !member( s[i], " \t\n" )) break;
- strcpy( s, &s[i] );
- }
-
- /* ================= */
- sysdate( mon, day, yr )
- int *mon, *day, *yr ;
- {
- int tvec[2], *dtime ;
-
- time( tvec );
- dtime = (int *)(localtime( tvec ));
- *mon = *(dtime+4) + 1 ;
- *day = *(dtime+3) ;
- *yr = *(dtime+5) ;
- }
- /* ================= */
- systime( hour, min, sec )
- int *hour, *min, *sec ;
- {
- int tvec[2], *dtime ;
-
- time( tvec );
- dtime = (int *)localtime( tvec );
- *hour = *(dtime+2) ;
- *min = *(dtime+1) ;
- *sec = *(dtime) ;
- }
-
-
- SHAR_EOF
- ############################
-
- cat << \SHAR_EOF > src/lineplot.c
- #include "ipl.x"
-
- Lineplot( )
- {
- int i, j, p,
- ncurves,
- xfield, yf[10],
- nlab,
- nmrk,
- nsh,
- number,
- nums,
- accum,
- stair,
- x0or1,
- stairbars;
-
- double prvx, prvy,
- x, y,
- cx, cy,
- lblsiz,
- mrksiz,
- size,
- nofs,
- zer,
- pm[10],
- th[10],
- sh[10];
-
- char lt[10][3],
- lb[10][20],
- str[12],
- mk[10][10];
-
-
- /* get data fields */
- gget( Buf, "Xfield" );
- xfield = atoi( Buf );
-
- gget( Buf, "Xstart.0or1" );
- x0or1 = atoi( Buf );
-
- gget( Buf, "Yfield" );
- ncurves = sscanf( Buf, "%d %d %d %d %d %d %d %d %d %d",
- &yf[0], &yf[1], &yf[2], &yf[3], &yf[4], &yf[5], &yf[6], &yf[7], &yf[8], &yf[9] );
- for( i = 0; i < ncurves; i++ ) if( yf[i] < 1 || yf[i] > N_d_fields ) { fprintf( stderr, "Yfield bad.\n" ); gdp_exit(); }
- if( ncurves < 1 ) { fprintf( stderr, "Yfield must be specified.\n" ); gdp_exit(); }
-
- gget( Buf, "Accum" ); if( Buf[0] == 'y' ) accum = YES; else accum = NO;
-
-
- /* get line parameters for curves */
- gget( Buf, "Linetype" );
- sscanf( Buf, "%s %s %s %s %s %s %s %s %s %s",
- lt[0],lt[1],lt[2],lt[3],lt[4],lt[5],lt[6],lt[7],lt[8],lt[9] );
- gget( Buf, "Linetype.magnify" );
- sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &pm[0],&pm[1],&pm[2],&pm[3],&pm[4],&pm[5],&pm[6],&pm[7],&pm[8],&pm[9] );
- gget( Buf, "Linethick" );
- sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
- &th[0],&th[1],&th[2],&th[3],&th[4],&th[5],&th[6],&th[7],&th[8],&th[9] );
- gget( Buf, "Mark" );
- nmrk = sscanf( Buf, "%s %s %s %s %s %s %s %s %s %s",
- mk[0],mk[1],mk[2],mk[3],mk[4],mk[5],mk[6],mk[7],mk[8],mk[9] );
- gget( Buf, "Mark.size" ); mrksiz = atof( Buf );
- NTptsize( mrksiz );
- size = Chh * 0.4;
-
- gget( Buf, "Shade" );
- nsh = sscanf( Buf, "%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] );
- gget( Buf, "Zeroat" ); zer = atof( Buf );
-
- gget( Buf, "Label" );
- nlab = countln( Buf );
- getln( "" );
- for( i = 0; i < nlab; i++ ) {
- strcpy( lb[i], getln( Buf ) );
- }
-
- gget( Buf, "Stairstep" ); if( Buf[0] == 'y' ) stair = YES; else stair = NO;
- gget( Buf, "Stairstep.bars" );
- if( Buf[0] == 'y' ) { stairbars = YES; stair = YES; }
- else stairbars = NO; /* for steps over bars */
-
- gget( Buf, "Label.size" ); lblsiz = atof( Buf );
-
- gget( Buf, "Numberfinal" ); if( Buf[0] == 'y' ) number = YES; else number = NO;
- gget( Buf, "Numbers" ); if( Buf[0] == 'y' ) nums = YES; else nums = NO;
- gget( Buf, "Numbers.offset" ); nofs = atof( Buf );
-
- NTptsize( lblsiz );
-
- /* do shading */
- for( j = 0; j < ncurves; j ++ ) {
- if( nsh >= j ) {
- if( stair ) fprintf( stderr, "warning, stairstep can't be combined with shading\n" );
- y = atof( D[0][yf[j]-1] );
- if( x0or1 ) x = 1;
- else x = atof( D[0][xfield-1] );
- NTm( x, zer );
- NTp( x, y );
- for( i = 0; i < N_d_rows-1; i++ ) {
- /* get current x, y */
- if( xfield < 1 ) x = i + 2;
- else x = atof( D[i+1][xfield-1] );
- if( accum ) y += atof( D[i+1][yf[j]-1] );
- else y = atof( D[i+1][yf[j]-1] );
- NTp( x, y );
- }
- NTp( x, zer );
- NTshade( sh[j] );
- }
- }
-
- /* do the curves */
- for( j = 0; j < ncurves; j ++ ) {
-
-
- NTlinetype( lt[j], th[j], pm[j] );
-
- /* find 1st y */
- y = atof( D[0][yf[j]-1] );
- /* find 1st x */
- if( x0or1 ) {
- if( stairbars ) x = 0.5;
- else x = 1;
- }
- else x = atof( D[0][xfield-1] );
- prvx = x;
- prvy = y;
-
- /* move to beginning of line */
- NTm( x, y );
-
- for( i = 0; i < N_d_rows-1; i++ ) {
-
- /* skip bad values.. */
- if( ! goodnum( D[i+1][yf[j]-1], &p ) ) {
- fprintf( stderr, "Warning, row %d field %d is bad (%s)\n", i+2, yf[j], D[i+1][yf[j]-1] );
- continue;
- }
-
-
- /* get current x, y */
- if( xfield < 1 ) {
- if( stairbars ) x = i+1.5;
- else x = i+2;
- }
- else x = atof( D[i+1][xfield-1] );
- if( accum ) y += atof( D[i+1][yf[j]-1] );
- else y = atof( D[i+1][yf[j]-1] );
-
- /* if doing stairsteps, get last x and y */
- if( stair ) {
- if( xfield < 1 ) {
- if( stairbars ) prvx = i + .5 ;
- else prvx = i+1;
- }
- else prvx = atof( D[i][xfield-1] );
- if( accum ) prvy += atof( D[i][yf[j]-1] );
- else prvy = atof( D[i][yf[j]-1] );
-
- NTl( x, prvy );
- if( nums ) {
- NTmov( da_x(prvx), da_y(prvy)+nofs );
- sprintf( str, DYticfmt, prvy );
- NTcentext( str, da_x(x)-da_x(prvx) );
- NTm( x, prvy );
- }
- }
- NTl( x, y );
- if( nums && ! stair ) {
- sprintf( str, DYticfmt, y );
- NTmov( da_x(x)-1, da_y(y)+nofs );
- NTcentext( str, 2 ); NTm( x, y );
- }
- }
-
- if( stair ) { /* give line a tail */
- if( nums ) { sprintf( str, DYticfmt, y ); NTmov( da_x( x ), da_y( y )+nofs ); NTtext( str ); }
- NTm( x, y );
- x += (DXtic*.7);
- NTl( x, y );
- }
- if( nlab > 0 ) {
- NTmov( da_x( x )+ 0.05, da_y( y ) - (Chh/2) );
- NTtext( lb[j] );
- }
- if( number ) {
- sprintf( str, DYticfmt, y );
- NTmov( da_x( x )+ 0.05, da_y( y ) + (Chh/1.8) );
- NTtext( str );
- }
- /* put marks on lines */
- if( nmrk >= j ) {
- if( stair )fprintf( stderr, "warning, stairstep can't be combined with point marks\n");
- y = atof( D[0][yf[j]-1] );
- if( x0or1 ) x = 1;
- else x = atof( D[0][xfield-1] );
- if( strncmp( mk[j], "sym", 3 )==0 ) point( da_x( x ), da_y( y ), mk[j], size );
- for( i = 0; i < N_d_rows-1; i++ ) {
- /* get current x, y */
- if( xfield < 1 ) x = i + 2;
- else x = atof( D[i+1][xfield-1] );
- if( accum ) y += atof( D[i+1][yf[j]-1] );
- else y = atof( D[i+1][yf[j]-1] );
- if( strncmp( mk[j], "sym", 3 )==0 ) point( da_x( x ), da_y( y ), mk[j], size );
- }
- }
- }
- NTnormline();
- }
- SHAR_EOF
- ############################
-
-
-