home *** CD-ROM | disk | FTP | other *** search
/ The UNIX CD Bookshelf / OREILLY_TUCB_UNIX_CD.iso / upt / examples / SOURCES / IPL / PART09.Z / PART09
Encoding:
Text File  |  1998-07-24  |  25.8 KB  |  1,049 lines

  1. Subject:  v21i040:  2D graphic system with table beautifier, Part09/14
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: ea750d9c 8f312a76 006dc3a8 7abca1da
  5.  
  6. Submitted-by: Steve Grubb <uunet!lsr-vax!scg>
  7. Posting-number: Volume 21, Issue 40
  8. Archive-name: ipl/part09
  9.  
  10. # ipl part09
  11. #    This is a shell archive.
  12. #    Remove everything above and including the cut line.
  13. #    Then run the rest of the file through sh.
  14. #---------------------- cut here -----------------------------
  15. #!/bin/sh
  16. # shar:    Shell Archiver
  17. #    Run the following text with /bin/sh to create:
  18. #        src/page.c
  19. #        src/pcode.c
  20. #        src/pick.c
  21. #        src/pie.c
  22. #        src/point.c
  23. #        src/polygon.c
  24. #        src/proc_call.c
  25. #        src/rangebar.c
  26. #        src/rect.c
  27. cat << \SHAR_EOF > src/page.c
  28. #include "ipl.x"
  29. /* Page-wide things, page title, etc.
  30.    Note that user does not have to execute this.
  31. */
  32. Page( )
  33. {
  34. int i = 1, c;
  35. char paper[20];
  36. double ofs;
  37. FILE *fp;
  38.  
  39. /* paper orientation */
  40. gget( paper, "Paperway" );
  41. if( strcmp( paper, "landscape" )==0 ) { 
  42.     NTpaper( 1 ); 
  43.      if( member( Dev, "sv" ))ab_rect( 0.0, 8.5, 11.0, 11.0, 0.5, 0 );
  44.     }
  45. else if( strcmp( paper, "portrait" )==0 ) { 
  46.     NTpaper( 0 ); 
  47.      if( member( Dev, "sv" ))ab_rect( 8.5, 0.0, 11.0, 11.0, 0.5, 0 );
  48.     }
  49. else NTpaper( 0 );
  50.  
  51.  
  52. /* standard line width */
  53. gget( Buf2, "Standard.linethick" );
  54. if( atof( Buf2 ) > 0 ) StdLw = atof( Buf2 );
  55. NTnormline();
  56.  
  57. gget( Buf2, "Standard.font" ); strcpy( Stdfont, Buf2 );
  58.  
  59. gget( Buf2, "Title.font" ); NTfont( Buf2 );
  60. gget( Buf2, "Title.size" ); NTptsize( atof( Buf2 ) );
  61. gget( Buf2, "Title.belowtop" ); ofs = atof( Buf2 );
  62.  
  63. gget( Buf, "Title.file" );
  64. if( strlen( Buf ) > 0 ) {
  65.     fp = fopen( Buf, "r" );
  66.     if( fp == NULL ) fp = popen( Buf, "r" );
  67.      if( fp == NULL ) { fprintf( stderr, "Can't open title file.\n" ); gdp_exit(); }
  68.     while( fgets( Buf, 512, fp ) != NULL ) {
  69.         strip_ws( Buf );
  70. /*        if( strlen( Buf ) < 1 ) continue;        */
  71.         if( Paper == 0 ) NTmov( 0.0, 10.5-ofs ); 
  72.         else NTmov( 0.0, 8-ofs );
  73.         if( Paper == 0 && strlen( Buf ) >= 1 )NTcentext( Buf, 8 );
  74.         if( Paper == 1 && strlen( Buf ) >= 1 )NTcentext( Buf, 10.5 );
  75.         ofs += Chh;
  76.         }
  77.     fclose( fp );
  78.     }
  79.     
  80.  
  81. gget( Buf, "Title" );
  82. if( strlen( Buf ) > 0 ) {
  83.     getln( "" );
  84.     for( i = 0; i < countln( Buf ); i++ ) {
  85.         if( Paper == 0 ) NTmov( 0.0, 10.5-ofs ); 
  86.         else NTmov( 0.0, 8-ofs );
  87.         if( Paper == 0 )NTcentext( getln( Buf ), 8 );
  88.         if( Paper == 1 )NTcentext( getln( Buf ), 10.5 );
  89.         ofs += Chh;
  90.         }
  91.     }
  92. }
  93. SHAR_EOF
  94. ############################
  95.  
  96. cat << \SHAR_EOF > src/pcode.c
  97. #include <stdio.h>
  98.  
  99. /* ============================ */
  100. /* IPL device interface (c) 1989 Steve Grubb */
  101. /* This must be compiled either with or without flag NOSUNVIEW */
  102.  
  103. static char pdev;
  104. static int vertchar = 0;
  105.  
  106. pcode( op, x, y, s )
  107. char op; /* op code */
  108. double x, y;  /* coordinates */
  109. char s[];     /* optional character string */
  110. {
  111. int outx, outy, move;
  112. char ans[10], pbuf[400];
  113. static double curx = 0, cury = 0;
  114. static int doclip = 0;
  115. double p1[2], p2[2];
  116. double x1, y1, x2, y2;
  117. double width, realx, chh;
  118. static int new = 0, drawing = 0;
  119.  
  120.  
  121.  
  122. /* interface to postscript driver */
  123. if( pdev == 't' ) {    
  124.  
  125.     if( op != 'L' ) { 
  126.         if( drawing ) PSstroke(); 
  127.         drawing = 0;
  128.         }
  129.  
  130.     if( op == 'L' ) { 
  131.         if( new ) PSmoveto( curx, cury ); 
  132.         PSlineto( x, y );
  133.         new = 0;
  134.         drawing = 1;
  135.         }
  136.     else if( op == 'M' ) { new = 1; curx = x; cury = y; }
  137.     else if( op == 'P' ) { 
  138.         if( new ) PSmoveto( curx, cury ); 
  139.         PSpath( x, y ); 
  140.         new = 0;
  141.         }
  142.     else if( op == 'T' ) PStext( op, curx, cury, s, 0.0 );
  143.     else if( op == 'C' ) PStext( op, curx, cury, s, x );
  144.     else if( op == 'J' ) PStext( op, curx, cury, s, x );
  145.     else if( op == 'S' ) PSshade( x );
  146.     else if( op == 'O' ) PSpaper( (int)x );
  147.     else if( op == 'I' ) PSpointsize( (int)x );
  148.     else if( op == 'F' ) PSfont( s );
  149.     else if( op == 'D' ) PSchardir( (int)x );
  150.     else if( op == 'Y' ) PSlinetype( s, x, y );
  151.     else if( op == 'Z' ) PSshow();
  152.     else if( op == 'K' ) doclip = 1;
  153.     else if( op == 'k' ) doclip = 0;
  154.     }
  155.  
  156.  
  157. /* interface to sunview driver */
  158. /* the routines SVtext, SVcentext, and SVrightjust return information
  159.    for keeping a bounding box list. */
  160. #ifndef NOSUNVIEW
  161. else if( pdev == 's' ) { 
  162.     if( op == 'L' ) SVlineto( x, y );
  163.     else if( op == 'P' ) SVpath( x, y );
  164.     else if( op == 'M' ) SVmoveto( x, y );
  165.     else if( op == 'T' && !vertchar ) SVtext( s, &width );
  166.     else if( op == 'B' ) SVbatch_on();
  167.     else if( op == 'b' ) SVbatch_off();
  168.     else if( op == 'Y' ) SVlinetype( s, x, y ); 
  169.     else if( op == 'S' ) SVshade( x );
  170.     else if( op == 'I' || op == 'F' ) { SVpointsize( (int)(x) ); chh = (x+2)/72.0; }
  171.     else if( op == 'C' && !vertchar ) SVcentext( s, x, &curx, &width );
  172.     else if( op == 'J' && !vertchar ) SVrightjust( s, x, &curx, &width );
  173.     else if( op == 'W' ) SVwait(); 
  174.     else if( op == 'D' ) {
  175.         if( x == 90 || x == 270 ) vertchar = 1;
  176.         else vertchar = 0;
  177.         }
  178.     else if( op == 'Z' ) { 
  179.         SVclear();
  180.         }
  181.     else if( op == 'K' ) doclip = 1;
  182.     else if( op == 'k' ) doclip = 0;
  183.  
  184.  
  185.     }
  186. #endif
  187.  
  188. else if( pdev == 'm' ) return( 1 );  /* term-oriented composer-- no graphics */
  189. else { fprintf( stderr, "pcode: %c: no such device\n", pdev ); exit(); }
  190.  
  191.  
  192.  
  193. }
  194.  
  195.  
  196. /* ========================================================== */
  197. /* initialize */
  198. NTinit( dev )
  199. char dev;
  200. {
  201.  
  202.  
  203. int yr, mon, day, hr, min, sec, i;
  204. char host[30]; 
  205.  
  206. sysdate( &mon, &day, &yr ); systime( &hr, &min, &sec );
  207.  
  208. fprintf( stderr, "IPL graphics system version 1.0 by Steve Grubb\n" );
  209.  
  210. /* initialize devices */
  211. if( dev == 's' || dev == 'v' ) {  
  212.     SVsetup( 11.0, 11.0 );
  213.     SVclear();
  214.     pdev = 's';
  215.     }
  216.  
  217. else if( dev == 't' ) {
  218.     PSsetup( );
  219.     pdev = 't';
  220.     }
  221.  
  222. else if( dev == 'm' ) { pdev = 'm'; return( 1 ); }
  223.  
  224. else { fprintf( stderr, "NTinit: %c: no such device\n", dev ); exit(); }
  225. }
  226. SHAR_EOF
  227. ############################
  228.  
  229. cat << \SHAR_EOF > src/pick.c
  230. /* These routines are for getting user input.  If Dev is 'v' (indicating
  231.    sunview composer), window and mouse-oriented input is used.  If Dev is
  232.    'm' (indicating terminal composer), terminal oriented input is used.
  233. */
  234.  
  235. #include "ipl.x"
  236. #define MAXBB 80
  237.  
  238. /* event modes */
  239. #define PICK 1        /* getting a menu selection */
  240. #define STRING 2    /* getting a \n terminated string */
  241. #define EVENTS 3    /* getting any mouse-button or keyboard event */
  242.  
  243. static FILE *fp = NULL;
  244. static double bb[MAXBB][4];
  245. static double bbxlo, bbylo, bbxhi, bbyhi;
  246. static char name[MAXBB][80];
  247. static char selection[80];
  248. static int nbb, 
  249.        menu_mode,
  250.        event_mode;
  251. static double evx, evy;
  252. static int eid;
  253. static int getting_text;
  254. static double Y;
  255. int box_given = 0;
  256. int transparent = 0;
  257. double BX1, BY1, BX2, BY2;
  258.  
  259.  
  260. /* ======================================== */
  261. /* getpick - draws a menu then gets user response and
  262.    sends back the name of the menu box selected.  Menu
  263.    can be defined in a file or by a string of tokens.
  264.    New is normally 1, but can be set to 0 to append to
  265.    an existing bounding box list.  Draw is normally 1
  266.    but can be set to 0 to "overlay" graphics.  
  267. */
  268. getpick( rtn, proc, new, draw )
  269. char rtn[]; /* user's selection placed here */
  270. char proc[];     /* name of menu def file */
  271. int new;    /* if yes, start a new bounding box list */
  272. int draw;    /* if yes, draw menu; if no, don't draw menu */
  273.  
  274. {
  275. int ix, fromstring, ixx, e;
  276. char coords[80], label[80], buf[200];
  277. double x, y;
  278.  
  279.  
  280. fromstring = 0;
  281. if( strlen( proc ) < 1 ) goto SKIP; /* for null argument.. */
  282.  
  283. sprintf( buf, "%s/%s", Templatepath, proc );
  284. fp = fopen( buf, "r" );
  285. if( fp == NULL ) {
  286.     fromstring = 1; 
  287.     y = 10; 
  288.     ixx = 0; 
  289.     }
  290.  
  291. if( new ) {
  292.     nbb = 0;
  293.     bbxlo = 999; bbxhi = -999; bbylo = 999; bbyhi = -999;
  294.     }
  295.  
  296. if( draw ) {
  297.     NTbatch_on();
  298.     NTfont( "/Helvetica-Oblique" );
  299.     NTptsize( 10 );
  300.     NTlinetype( "0", 3, 1 );
  301.     }
  302. if( Dev == 'm' ) fprintf( stderr, "=====================\n" );
  303. while( 1 ) { 
  304.     if( fromstring ) {
  305.         bb[nbb][0] = 8.0; bb[nbb][1] = y-0.4; bb[nbb][2] = 11.0; bb[nbb][3] = y;
  306.         strcpy( name[nbb], getok( proc, &ixx ));
  307.         if( strlen( name[nbb] ) < 1 ) break;
  308.         strcpy( label, name[nbb] );
  309.         y -= 0.5;
  310.         }
  311.     else    {  /* from file */
  312.         if( fgets( buf, 200, fp ) == NULL ) break;
  313.         ix = 0;
  314.         getfld( coords, buf, &ix );
  315.         getfld( label, buf, &ix );
  316.         getfld( name[nbb], buf, &ix );
  317.         sscanf( coords, "%lf %lf %lf %lf", &bb[nbb][0], &bb[nbb][1], &bb[nbb][2], &bb[nbb][3] );
  318.         }
  319.     
  320.     if( draw ) {
  321.         ab_rect( bb[nbb][0], bb[nbb][1], bb[nbb][2], bb[nbb][3], 1.0, 1 );
  322.         NTmov( bb[nbb][0], bb[nbb][1] + ((bb[nbb][3]-bb[nbb][1])/2.0) );
  323.         NTcentext( label, bb[nbb][2]-bb[nbb][0] );
  324.         }
  325.  
  326.     if( bb[nbb][0] < bbxlo ) bbxlo = bb[nbb][0];
  327.     if( bb[nbb][1] < bbylo ) bbylo = bb[nbb][1];
  328.     if( bb[nbb][2] > bbxhi ) bbxhi = bb[nbb][2];
  329.     if( bb[nbb][3] > bbyhi ) bbyhi = bb[nbb][3];
  330.  
  331.     if( Dev == 'm' ) fprintf( stderr, "%-2d) %s\n", nbb+1, name[nbb] ); /* term menu */ 
  332.     nbb ++;
  333.     }
  334.  
  335. if( fp != NULL ) fclose( fp );
  336.  
  337. if( draw ) {
  338.     NTnormline();
  339.     NTbatch_off();
  340.     }
  341.     
  342. SKIP:
  343. event_mode = PICK;
  344. NTwait();  /* let user pick */
  345. get_event( &x, &y, &e ); /* spurious event */
  346.  
  347. if( Dev == 'm' ) while( 1 ) {                 /* term menu */
  348.     fprintf( stderr, "Selection: " );
  349.     fgets( buf, 10, stdin ); 
  350.     if( atoi( buf ) > 0 && atoi( buf ) <= nbb )
  351.         { strcpy( selection, name[ atoi( buf ) -1 ] ); break; }
  352.     }
  353.     
  354. strcpy( rtn, selection );
  355. }
  356.  
  357.  
  358. /* ================================ */
  359.  
  360. /* This gets called by the driver when 1) we are waiting for an event by calling NTwait(),
  361.    and 2) a key or mouse event happens. */
  362. /* NOTE:  menu picking is in effect while getting a string */
  363. handle_event( x, y, e )
  364. double x, y;
  365. int e;
  366. {
  367. int i;
  368.  
  369. /* for menus.. */
  370. if( event_mode == PICK ) {
  371.     /* look up (x,y) in bounding box list */
  372.     if( x > bbxlo && x < bbxhi && y > bbylo && y < bbyhi ) {
  373.         for( i = nbb-1; i >= 0; i-- ) {
  374.             if( x > bb[i][0] && y > bb[i][1] && x < bb[i][2] && y < bb[i][3] ) break;
  375.             }
  376.         if( i == nbb ) return( 0 ); /* not found */
  377.         strcpy( selection, name[i] ); return( 1 );  /* found */
  378.         }
  379.     }
  380. /* for strings */
  381. else if( event_mode == STRING && e > 0 && e < 128  ) {
  382.     selection[0] = (char) e;
  383.     selection[1] = '\0';
  384.     return( 1 );
  385.     }
  386. else if( event_mode == EVENTS ) {
  387.     evx = x; evy = y; eid = e;
  388.     return( 1 );
  389.     }
  390. return( 0 );
  391. }
  392.  
  393.  
  394.                 
  395. /* ================================== */
  396.  
  397. message( s1, s2, s3, s4  )
  398. char s1[], s2[], s3[], s4[];
  399. {
  400. NTptsize( 10 );
  401. ab_rect( 8.0, 10.0, 11.0, 11.0, 1.0, 1 );
  402. NTmov( 8.1, 10.7 ); NTtext( s1 );
  403. NTmov( 8.1, 10.5 ); NTtext( s2 );
  404. NTmov( 8.1, 10.3 ); NTtext( s3 );
  405. NTmov( 8.1, 10.1 ); NTtext( s4 );
  406. 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 );
  407. }
  408.  
  409.  
  410. /* ==================================== */
  411.  
  412. get_event( x, y, e )
  413. double *x, *y;
  414. int *e;
  415. {
  416. char ans[20];
  417.     
  418. event_mode = EVENTS;
  419. NTwait();
  420. *x = evx; *y = evy; *e = eid;
  421. }
  422.  
  423.  
  424. /* ==================================== */
  425. /* prompts user for one line of text */
  426.  
  427.  
  428. get_string( s, p )
  429. char s[], p[];
  430. {
  431. int i;
  432. double x, y;
  433.  
  434. if( Dev == 'm' ) { /* terminal interface */
  435.     fprintf( stderr, "%s: ", p );
  436.     fgets( s, 100, stdin );
  437.     return( 1 );
  438.     }
  439.  
  440. if( !box_given ) { BX1 = 0.3; BY1 = 0.1; BX2 = 9; BY2 = 0.5; }
  441.  
  442. if( getting_text ) y = Y; /* Y set in get_text() */
  443. else y = BY1;
  444. x = BX1 + 0.2 + ( strlen( p ) * Chh * 0.5 );
  445.  
  446. /* do box and prompt */
  447. NTlinetype( "0", 3, 1 );
  448.  
  449. if( getting_text && !transparent ) ab_rect( BX1, y-0.1, BX2, y+Chh, 1.0, 0 );
  450. else if( !transparent )ab_rect( BX1, y-0.1, BX2, y+0.4, 1.0, 1 );
  451.  
  452. NTnormline();
  453. NTmov( BX1+0.1, y );
  454. NTtext( p );
  455. NTmov( x, y );    
  456.  
  457. i = 0;
  458. while( 1 ) {
  459.     NTmov( x, y );
  460.     event_mode = STRING;
  461.     NTwait(); /* let user enter char */
  462.     if( selection[0] == '\b' || selection[0] == '\177' ) { 
  463.         if( i == 0 ) continue;
  464.         i--;
  465.         ab_rect( (x-(Chh*0.5)), y-(Chh*0.28), x, (y+(Chh*0.85)), 1.0, 0 ); 
  466.         x -= ( Chh * 0.5 ); 
  467.         continue; 
  468.         }
  469.     else if( selection[0] == '\015' || selection[0] == '\012' ) break;
  470.     else if( selection[0] == '\004' ) {  /* control-D stops */
  471.         strcpy( s, "\004" ); 
  472.         return( 1 ); 
  473.         }
  474.     else NTtext( selection );
  475.  
  476.     s[i++] = selection[0];
  477.     x += (Chh * 0.5 );
  478.     }
  479. s[i] = '\0';
  480. if( !getting_text && !transparent )ab_rect( BX1, y-0.1, BX2, y+0.4, 0.98, 0 );
  481. }
  482.  
  483. /* ========================================= */
  484. /* gets multi-row text. */
  485. get_text( buf, p )
  486. char buf[], p[];
  487. {
  488. int i, j, maxlen;
  489. double x;
  490. char uin[20];
  491.  
  492. if( Dev == 'm' ) { /* for terminal interface */
  493.     fprintf( stderr, "=======================\n" );
  494.     sprintf( buf, "%s  Enter \".\" to stop..\n", p );
  495.     fprintf( stderr, "%s", buf );
  496.     i = 0;
  497.     while( 1 ) {
  498.         fgets( &buf[i], 100, stdin );
  499.         if( strcmp( &buf[i], ".\n" )==0 ) break; 
  500.         i += strlen( &buf[i] );
  501.         }
  502.     buf[ i-1 ] = '\0';
  503.     return( 1 );
  504.     }
  505.  
  506.  
  507. sprintf( buf, "%s  Press Control-D to stop..\n", p );
  508.  
  509. maxlen = 80; /* max length of any line */
  510.  
  511. if( !box_given ) { BX1 = 0.3; BY1 = 0.3; BX2 = 9; BY2 = 8.0; }
  512.  
  513. x = BX1;
  514. Y = BY2;
  515.  
  516. if( !transparent )ab_rect( x-0.1, BY1, BX2+0.1, Y+0.2, 1.0, 1 );
  517. NTmov( x, Y );
  518. if( !transparent) { NTcentext( buf, BX2-BX1 ); Y -= Chh; }
  519.  
  520. getting_text = 1;
  521. nbb = 0;
  522. /* control D quits */
  523. for( i = 0; i < MAXBB; i++ ) {
  524.     bb[i][0] = BX1; bb[i][1] = Y-(Chh*1.6);  bb[i][2] = BX2; bb[i][3] = Y; sprintf( name[i], "%d", i );
  525.     get_string( &(buf[i*maxlen]), "" );
  526.     if( buf[i*maxlen] == '\004' ) break;
  527.     for( j = (i*maxlen)+ strlen( &buf[i*maxlen] ); j < ((i+1)*maxlen)-1; j++ ) buf[j] = ' ';
  528.     buf[ ((i+1)*maxlen) -1 ] = '\n';
  529.     Y -= Chh;
  530.     }
  531. buf[i*maxlen] = '\0';
  532. bbxlo = 0; bbxhi = 11; bbylo = 0; bbyhi = 11;
  533.  
  534. getting_text = 0;
  535. }
  536.  
  537.  
  538. /* =============================== */
  539. get_string_box( s, p, x1, y1, x2, y2 )
  540. char s[], p[];
  541. double x1, y1, x2, y2;
  542. {
  543. box_given = 1;
  544. BX1 = x1; BY1 = y1; BX2 = x2; BY2 = y2;
  545. get_string( s, p );
  546. box_given = 0;
  547. }
  548.  
  549.  
  550. /* =============================== */
  551. get_text_box( s, p, x1, y1, x2, y2 )
  552. char s[], p[];
  553. double x1, y1, x2, y2;
  554. {
  555. box_given = 1;
  556. BX1 = x1; BY1 = y1; BX2 = x2; BY2 = y2;
  557. get_text( s, p );
  558. box_given = 0;
  559. }
  560.  
  561. /* =============================== */
  562. get_text_box_tp( s, p, x1, y1, x2, y2 )
  563. char s[], p[];
  564. double x1, y1, x2, y2;
  565. {
  566. transparent = 1;
  567. get_text_box( s, p, x1, y1, x2, y2 );
  568. transparent = 0;
  569. }
  570.  
  571.  
  572.  
  573. SHAR_EOF
  574. ############################
  575.  
  576. cat << \SHAR_EOF > src/pie.c
  577. #include "ipl.x"
  578.  
  579. Pie( )
  580. {
  581. int i, f, first, ns, explode;
  582. double theta, val, stop;
  583. double hx, hy, x, y, r;
  584. double sh[20], lt;
  585. double u, ux, uy, adj;
  586.  
  587. gget( Buf, "Field" );
  588. f = atoi( Buf );
  589.  
  590. gget( Buf, "Center" );
  591. sscanf( Buf, "%lf %lf", &hx, &hy );
  592.  
  593. gget( Buf, "Radius" );
  594. r = atof( Buf );
  595.  
  596. gget( Buf, "Linethick" );
  597. lt = atof( Buf );
  598. NTlinetype( "0", lt, 1.0 );
  599.  
  600. gget( Buf, "Explode" );
  601. u = atof( Buf );
  602.  
  603. gget( Buf, "Rotate" );
  604. adj = atof( Buf );
  605.  
  606. gget( Buf, "Shade" );
  607. ns = sscanf( Buf, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
  608.   &sh[0],&sh[1],&sh[2],&sh[3],&sh[4],&sh[5],&sh[6],&sh[7],&sh[8],&sh[9],
  609.   &sh[10],&sh[11],&sh[12],&sh[13],&sh[14],&sh[15],&sh[16],&sh[17],&sh[18],&sh[19] );
  610.  
  611. /* do shades */
  612. theta = adj * (3.1415927/180.0) ;
  613. for( i = 0; i < N_d_rows; i++ ) {
  614.  
  615.     val = atof( D[i][f-1] );
  616.     
  617.     /* convert val (percentage) to radians.. */
  618.     val = ( val/100.0 ) * 6.28319;
  619.     stop = theta + val;
  620.     ux = u * cos( theta+(val/2.0) );
  621.     uy = u * sin( theta+(val/2.0) );
  622.  
  623.     first = 1;
  624.     for( ; theta < (stop+0.001); theta += 0.02 ) {
  625.         x = hx + (r * cos( theta ));
  626.         y = hy + (r * sin( theta ));
  627.         if( first ) { NTmov( hx+ux, hy+uy ); NTpath( x+ux, y+uy ); first = 0; }
  628.         NTpath( x+ux, y+uy );
  629.         }
  630.     if( i < ns )NTshade( sh[i] );
  631.     else NTshade( 1.0 );
  632.     theta = stop;
  633.     }
  634.  
  635. /* do lines */
  636. theta = adj * (3.1415927/180.0);
  637. for( i = 0; i < N_d_rows; i++ ) {
  638.  
  639.     val = atof( D[i][f-1] );
  640.     
  641.     /* convert val (percentage) to radians.. */
  642.     val = ( val/100.0 ) * 6.28319;
  643.     stop = theta + val;
  644.     ux = u * cos( theta+(val/2.0) );
  645.     uy = u * sin( theta+(val/2.0) );
  646.  
  647.     first = 1;
  648.     for( ; theta < (stop+0.001); theta += 0.02 ) {
  649.         x = hx + (r * cos( theta ));
  650.         y = hy + (r * sin( theta ));
  651.         if( first ) { NTmov( hx+ux, hy+uy ); NTlin( x+ux, y+uy ); first = 0; }
  652.         NTlin( x+ux, y+uy );
  653.         }
  654.     NTlin( hx+ux, hy+uy );
  655.     theta = stop;
  656.     }
  657.  
  658. NTnormline();
  659. }
  660. SHAR_EOF
  661. ############################
  662.  
  663. cat << \SHAR_EOF > src/point.c
  664. #include "ipl.x"
  665. /* draw a data point */
  666. /* point styles are selected by the code string "symNSf.ff", where N is an integer
  667.    0-9 selecting the shape, S is a lower-case character selecting the style, and
  668.    f.ff is an optional shade, which overrides that selected as part of the style.  
  669.    N and S are required.  See point1.g in the examples.
  670. */
  671. #define NVARIAT 18
  672. #define NSHAPE 6
  673.  
  674. Point( )
  675. {
  676. double x, y, r;
  677. char code[20];
  678.  
  679. gget( Buf, "Mark" );
  680. strcpy( code, Buf );
  681. gget( Buf, "Position" );
  682. sscanf( Buf, "%lf %lf", &x, &y );
  683. gget( Buf, "Size" );
  684. sscanf( Buf, "%lf", &r );
  685. NTptsize( r );
  686. r = Chh * 0.4;
  687. point( x, y, code, r );
  688. }
  689.  
  690.  
  691. point( x, y, code, r )
  692. double x, y;     /* point location in abs space */
  693. char code[];    /* pre-set symbol name */
  694. double r;     /* radius of dot in absolute units */
  695. {
  696. int i;
  697. double g, theta;
  698. static char prevcode[10] = "";
  699. static double prev_r, shade;
  700. static int inc, ins;
  701. static int nc[] =    {  3,  3,  4,  4,  5, 12 };    /* number of corners */
  702. static int nt[] =    { 90,270,  0, 45, 90, 90, 90 };    /* location (in deg) to start building point */
  703. /* preset outline thicknesses.. */
  704. static double ol[] = { .5,  1,1.5,  2, .5, .5, .5, .5, .5,  0,  0,  0,  0, 0, -0.5, -1, -1.5, -2 }; 
  705. /* preset shades..  */
  706. static double sh[] = { -1, -1, -1, -1,  1, .9, .7, .5, .3, .9, .7, .5, .3, 0, -1, -1,  -1,  -1 }; 
  707. static double h[14][2]; /* the offsets */
  708.  
  709. /* no-op code */
  710. if( strcmp( code, "sym00" ) == 0 ) return( 0 );
  711.  
  712. if( strcmp( code, prevcode ) != 0 || r != prev_r ) {
  713.     strcpy( prevcode, code );
  714.     prev_r = r;
  715.     inc = ((code[3] - '0') -1 ) % NSHAPE;
  716.     if( code[4] == '\0' ) code[4] = 'a';
  717.     ins = (code[4] - 'a') % NVARIAT;
  718.     if( strlen( code ) > 5 )shade = atof( &code[5] );
  719.     else shade = sh[ins];
  720.  
  721.     theta = 360.0 / (double)nc[inc];
  722.     /* get offsets */
  723.     g = nt[inc];
  724.     for( i = 0; i < nc[inc]; i++ ) {
  725.         h[i][0] = r * cos( (g*3.1415927)/180.0 );
  726.         h[i][1] = r * sin( (g*3.1415927)/180.0 );
  727.         g += theta;
  728.         }
  729.     }
  730.  
  731. /* lock-on */
  732. /* shade point */
  733. if( shade >= 0 ) {
  734.     NTmov( x+h[0][0], y+h[0][1] );
  735.     for( i = 1; i < nc[inc]; i++ ) NTpath( x+h[i][0], y+h[i][1] );
  736.     NTshade( shade );
  737.     }
  738.  
  739. /* draw perimeter point */
  740. if( ol[ins] > 0.0 ) {
  741.     NTlinetype( "0", ol[ins], 1.0 );
  742.     NTmov( x+h[0][0], y+h[0][1] );
  743.     for( i = 1; i < nc[inc]; i++ ) NTlin( x+h[i][0], y+h[i][1] );
  744.     NTlin( x+h[0][0], y+h[0][1] );
  745.     NTnormline();
  746.     }
  747.  
  748. /* draw spokes */
  749. if( ol[ins] < 0.0 ) {
  750.     double fabs();
  751.     NTlinetype( "0", fabs(ol[ins]), 1.0 );
  752.     for( i = 0; i < nc[inc]; i++ ) { NTmov( x, y ); NTlin( x+h[i][0], y+h[i][1] ); }
  753.     NTnormline();
  754.     }
  755. /* lock-off */
  756.  
  757. }
  758. SHAR_EOF
  759. ############################
  760.  
  761. cat << \SHAR_EOF > src/polygon.c
  762. /* polygon - for creating polygons, optionally shaded and outlined */
  763. #include "ipl.x"
  764. #define ABSOLUTE 0
  765. #define DATA 1
  766.  
  767. Polygon( )
  768. {
  769. int sys, n, i, p, outline;
  770. double mag, thick, x, y, fx, fy;
  771. char ltype[10], s1[12], s2[12], s3[12], s4[12];
  772.  
  773. gget( Buf, "System" );
  774. if( strcmp( Buf, "absolute" )==0 ) sys = ABSOLUTE;
  775. else     {
  776.     sys = DATA;
  777.     if( DXlo == 0 && DXhi == 0 ) { fprintf( stderr, "No graphics area.\n" ); gdp_exit(); }
  778.     }
  779.  
  780. gget( Buf, "Outline" );
  781. if( Buf[0] == 'y' ) outline = 1;
  782. else outline = 0;
  783.  
  784. /* get line style parameters */
  785. gget( Buf, "Linetype" ); strcpy( ltype, Buf );
  786.  
  787. gget( Buf, "Linetype.magnify" ); 
  788. if( goodnum( Buf, &p )) mag = atof( Buf );
  789. else mag = 1;
  790.  
  791. gget( Buf, "Linethick" ); thick = atof( Buf );
  792.  
  793.  
  794. /* set line style */
  795. NTlinetype( ltype, thick, mag );
  796.  
  797. /* get points */
  798. gget( Buf2, "Rectangle" );
  799. if( strlen( Buf2 ) > 0 ) {
  800.     sscanf( Buf2, "%s %s %s %s", s1, s2, s3, s4 );
  801.     sprintf( Buf, "%s %s\n%s %s\n%s %s\n%s %s", s1, s2, s1, s4, s3, s4, s3, s2 );
  802.     }
  803. else gget( Buf, "Points" );
  804. if( strlen( Buf ) < 1 ) { fprintf( stderr, "Points or Rectangle not specified.\n" ); gdp_exit(); }
  805. getln( "" );
  806. for( i = 0; i < countln( Buf ); i++ ) {
  807.     n = sscanf( getln( Buf ), "%lf %lf", &x, &y );
  808.     if( sys == DATA && i == 0 ) NTm( x, y ); 
  809.     else if( sys == ABSOLUTE && i == 0 ) NTmov( x, y );
  810.     else if( sys == DATA ) NTp( x, y ); 
  811.     else if( sys == ABSOLUTE ) NTpath( x, y );
  812.     else { fprintf( stderr, "Points should contain one coord pair per line.\n" ); gdp_exit(); }
  813.     }
  814. gget( Buf2, "Shade" );
  815. if( strlen( Buf2 ) > 0 ) NTshade( atof( Buf2 ) );
  816.  
  817. if( outline ) {
  818.     getln( "" );  /* reset getln() */
  819.     for( i = 0; i < countln( Buf ); i++ ) {
  820.         n = sscanf( getln( Buf ), "%lf %lf", &x, &y );
  821.         if( sys == DATA && i == 0 ) { NTm( x, y ); fx = x; fy = y; }
  822.         else if( sys == ABSOLUTE && i == 0 ) { NTmov( x, y ); fx = x; fy = y; }
  823.         else if( sys == DATA ) NTl( x, y ); 
  824.         else if( sys == ABSOLUTE ) NTlin( x, y );
  825.         else { fprintf( stderr, "Points should contain one coord pair per line.\n" ); gdp_exit(); }
  826.         }
  827.     if( sys == DATA ) NTl( fx, fy ); 
  828.     else if( sys == ABSOLUTE ) NTlin( fx, fy );
  829.     }
  830.  
  831.  
  832. NTnormline(); /* return line to normal */
  833. }    
  834. SHAR_EOF
  835. ############################
  836.  
  837. cat << \SHAR_EOF > src/proc_call.c
  838. /* proc_call() - calls the appropriate funtion, given the proc name. */
  839.  
  840. #include "ipl.h"
  841. proc_call( proc )
  842. char proc[];
  843. {
  844. char p1[30], p2[30];
  845.  
  846. /* make sure there's data if we're plotting */
  847. if( smember( proc, "Distribution Bargraph Vbargraph Lineplot Rangebar Vrangebar Vector Boxplot Errorbars Map" ) ) {
  848.     if( strcmp( proc, "Map" )!= 0 && N_d_rows <= 0 ) 
  849.         { fprintf( stderr, "No data yet, use Proc Getdata to read some.\n" ); gdp_exit(); }
  850.     if( Xlo == 0 && Xhi == 0 ) 
  851.         { fprintf( stderr, "No graphics area, use Proc Areadef to define one.\n" ); gdp_exit(); }
  852.     }
  853.  
  854. if( Dev == 's' ) siplmenu( proc ); /* sipl menu at end of page */
  855.  
  856. if( strcmp( proc, "Initialize" )!= 0 )NTbatch_on();
  857.  
  858. if( strcmp( proc, "Initialize" )==0 ) Initialize( );
  859. else if( strcmp( proc, "Exit" )==0 ); /* see below */
  860. else if( strcmp( proc, "Page" )==0 ) Page( );
  861. else if( strcmp( proc, "Areadef" )==0 ) Areadef( );
  862. else if( strcmp( proc, "Getdata" )==0 ) Getdata( );
  863. else if( strcmp( proc, "Distribution" )==0 ) Distribution( );
  864. else if( strcmp( proc, "Bargraph" )==0 ) Bargraph( );
  865. else if( strcmp( proc, "Vbargraph" )==0 ) Vbargraph( );
  866. else if( strcmp( proc, "Lineplot" )==0 ) Lineplot( );
  867. else if( strcmp( proc, "Legend" )==0 ) Legend( );
  868. else if( strcmp( proc, "Map" )==0 ) Map( );
  869. else if( strcmp( proc, "Rangebar" )==0 ) Rangebar();
  870. else if( strcmp( proc, "Vrangebar" )==0 ) Vrangebar();
  871. else if( strcmp( proc, "Vector" )==0 ) Vector();
  872. else if( strcmp( proc, "Pie" )==0 ) Pie();
  873. else if( strcmp( proc, "Errorbars" )==0 ) Errorbars();
  874. else if( strcmp( proc, "Nicetab" )==0 ) Nicetab( );
  875. else if( strcmp( proc, "Boxplot" )==0 ) Boxplot( );
  876.  
  877. else if( strcmp( proc, "Text" )==0 ) Text( );
  878. else if( strcmp( proc, "Draw" )==0 ) Draw( );
  879. else if( strcmp( proc, "Arrow" )==0 ) Arrow( );
  880. else if( strcmp( proc, "Polygon" )==0 ) Polygon( );
  881. else if( strcmp( proc, "Point" )==0 ) Point();
  882.  
  883. else if( strcmp( proc, "Pagebreak" )== 0 ) { NTshow(); }
  884. else if( strcmp( proc, "QuitAppend" )==0 ) { Hold = 1; }
  885. else if( strcmp( proc, "Endoffile" )==0 ) ; /* no op */
  886. else fprintf( stderr, "proc_call: %s is unrecognized.. continuing\n", proc );
  887.  
  888. NTbatch_off();
  889.  
  890. if( strcmp( proc, "Exit" )==0 ) Exit();
  891. }
  892. SHAR_EOF
  893. ############################
  894.  
  895. cat << \SHAR_EOF > src/rangebar.c
  896. #include "ipl.x"
  897. Rangebar( )
  898. {
  899. int f[8], row, i, doends, nf, nv, ir, mlrightonly, label, xf;
  900. double val[8];
  901. double w, x, shade, lblpos, mlw;
  902.  
  903. gget( Buf, "Nval" );
  904. nv = atoi( Buf );
  905.  
  906. gget( Buf, "Field" );
  907. if( nv == 1 ) { nf = sscanf( Buf, "%d", &f[1] ); f[2] = f[3] = f[1]; f[4] = f[5] = f[1]; }
  908. else if( nv == 2 ) { nf = sscanf( Buf, "%d %d", &f[1], &f[4] ); f[2] = f[3] = f[1]; f[5] = f[4]; }
  909. else if( nv == 3 ) { nf = sscanf( Buf, "%d %d %d", &f[1], &f[3], &f[5] ); f[2] = f[1]; f[4] = f[5]; }
  910. else if( nv == 4 ) { nf = sscanf( Buf, "%d %d %d %d", &f[1], &f[2], &f[4], &f[5] ); f[3] = f[4]; }
  911. else if( nv == 5 ) { nf = sscanf( Buf, "%d %d %d %d %d", &f[1], &f[2], &f[3], &f[4], &f[5] ); }
  912. if( nf != nv ) { fprintf( stderr, "Expecting %d Field values.\n", nv ); gdp_exit(); }
  913.  
  914.  
  915. gget( Buf, "Width" ); w = atof( Buf );
  916.  
  917. gget( Buf, "Linethick" );
  918. NTlinetype( "0", atof( Buf ), 1.0 );
  919.  
  920. label = 0;
  921. gget( Buf, "Idfield" );
  922. f[0] = atoi( Buf );
  923. if( f[0] > 0 ) {
  924.     label = 1;
  925.     gget( Buf, "Label.size" );
  926.     if( atoi( Buf ) > 0 ) NTptsize( atoi( Buf ) );
  927.  
  928.     gget( Buf, "Label.position" );
  929.     lblpos = atof( Buf );
  930.  
  931.     }
  932.  
  933. doends = 0;
  934. if( nf == 4 || nf == 5 ) {
  935.     gget( Buf, "Ends" );
  936.     if( Buf[0] == 'y' ) doends = 1;
  937.     }
  938.  
  939. mlw = w;
  940. mlrightonly = 0;
  941. if( nf == 3 || nf == 5 ) {
  942.     gget( Buf, "Midlinewidth" );
  943.     if( atof( Buf ) > 0 )mlw = atof( Buf );
  944.     gget( Buf, "Midlineright" );
  945.     if( Buf[0] == 'y' ) mlrightonly = 1;
  946.     }
  947.  
  948. gget( Buf, "Shade" );
  949. shade = atof( Buf );
  950.  
  951. gget( Buf, "Xfield" );
  952. xf = atoi( Buf );
  953.  
  954.  
  955. x = DXlo;
  956. for( ir = 0; ir < N_d_rows; ir++ ) {
  957.     for( i = 1; i <= 5; i++ ) val[i] = atof( D[ ir ][ f[i]-1 ] );
  958.     if( nv == 1 ) { val[1] = val[2] = 0; }
  959.     if( xf > 0 ) x = atof( D[ir][ xf-1 ] );
  960.     else x++;
  961.  
  962.     NTm( x-(w/2), val[2] ); /* lower edge of box */
  963.     NTp( x+(w/2), val[2] );
  964.     NTp( x+(w/2), val[4] );
  965.     NTp( x-(w/2), val[4] );
  966.     NTp( x-(w/2), val[2] ); /* upper edge */
  967.     NTshade( shade );
  968.     
  969.     NTm( x, val[1] ); /* lower tail */
  970.     NTl( x, val[2] );
  971.     if( doends ) { NTm( x-(w/2.7), val[1] ); NTl( x+(w/2.7), val[1] ); }
  972.     
  973.     NTm( x-(w/2), val[2] ); /* lower edge of box */
  974.     NTl( x+(w/2), val[2] );
  975.     NTl( x+(w/2), val[4] );
  976.     NTl( x-(w/2), val[4] );
  977.     NTl( x-(w/2), val[2] ); /* upper edge */
  978.     
  979.     NTm( x, val[4] );
  980.     NTl( x, val[5] ); /* upper tail */
  981.     if( doends ) { NTm( x-(w/2.7), val[5] ); NTl( x+(w/2.7), val[5] ); }
  982.     
  983.     if( mlrightonly )NTm( x-(w/2), val[3] ); /* median line */
  984.     else NTm( x-(mlw/2), val[3] ); 
  985.     NTl( x+(mlw/2), val[3] );
  986.     
  987.     if( label ) {
  988.         NTmov( da_x(x) -1, da_y(lblpos) );  /* print label */
  989.         sprintf( Buf, "%s", D[ir][f[0]-1 ] );
  990.         NTcentext( Buf, 2 );
  991.         }
  992.     
  993.     }
  994. NTnormline();
  995. }
  996. SHAR_EOF
  997. ############################
  998.  
  999. cat << \SHAR_EOF > src/rect.c
  1000. /* do a rectangle, with shading and/or outline */
  1001. /* only used internally, user proc is Polygon */
  1002. #include "ipl.x"
  1003.  
  1004. /* rect() - all coords in data space */
  1005. rect( xlo, ylo, xhi, yhi, shade, outline )
  1006. double xlo, ylo, xhi, yhi, shade;
  1007. int outline;
  1008. {
  1009. if( shade >= 0 ) {
  1010.     NTm( xlo, ylo );
  1011.     NTp( xlo, yhi );
  1012.     NTp( xhi, yhi );
  1013.     NTp( xhi, ylo );
  1014.     NTshade( shade );
  1015.     }
  1016. if( outline ) {
  1017.     NTm( xlo, ylo );
  1018.     NTl( xlo, yhi );
  1019.     NTl( xhi, yhi );
  1020.     NTl( xhi, ylo );
  1021.     NTl( xlo, ylo );
  1022.     }
  1023. }
  1024.  
  1025. /* ab_rect() - all coords in absolute space */
  1026. ab_rect( xlo, ylo, xhi, yhi, shade, outline )
  1027. double xlo, ylo, xhi, yhi, shade;
  1028. int outline;
  1029. {
  1030. if( shade >= 0 ) {
  1031.     NTmov( xlo, ylo );
  1032.     NTpath( xlo, yhi );
  1033.     NTpath( xhi, yhi );
  1034.     NTpath( xhi, ylo );
  1035.     NTshade( shade );
  1036.     }
  1037. if( outline ) {
  1038.     NTmov( xlo, ylo );
  1039.     NTlin( xlo, yhi );
  1040.     NTlin( xhi, yhi );
  1041.     NTlin( xhi, ylo );
  1042.     NTlin( xlo, ylo );
  1043.     }
  1044. }
  1045. SHAR_EOF
  1046. ############################
  1047.  
  1048.  
  1049.