home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / x / volume16 / xfgxgrph / part01 < prev    next >
Encoding:
Text File  |  1992-03-08  |  22.8 KB  |  770 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!zaphod.mps.ohio-state.edu!mips!msi!dcmartin
  3. From: Konstantinos Konstantinides <kk@hpkronos.hpl.hp.com>
  4. Subject: v16i149: xfig drivers for xgraph, Part01/01
  5. Message-ID: <1992Mar9.161214.18606@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. Date: Mon, 9 Mar 1992 16:12:14 GMT
  10. Approved: dcmartin@msi.com
  11.  
  12. Submitted-by: Konstantinos Konstantinides <kk@hpkronos.hpl.hp.com>
  13. Posting-number: Volume 16, Issue 149
  14. Archive-name: xfig4xgraph/part01
  15.  
  16. The files fig.c and fig2.1.c provide xfig drivers for xgraph.
  17. fig.c is for FIG 2.0 and fig2.1.c for FIG 2.1.
  18. Then you can import and anotate xgraph files using xfig. Or you can
  19. use fig2dev to translate xgraph files into PIC, or Tex format.
  20.  
  21. xgraph is available from ic.berkeley.edu
  22. xfig is  available from export, /contrib/R5fixes/xfig-patches/xfig.*
  23. transfig (fig2dev) is available from ftp.cs.cornell.edu
  24.  
  25. What you need to do (assuming you have xgraph):
  26. 1. Edit the SRC and OBJ lines of the xgraph Makefile to include
  27.    fig.c, fig2.1.c, fig.o, and fig2.1.o.
  28.  
  29. 2. Edit hard_devices.c to include the new drivers. My hard_devices.c
  30.    is included here as an example.
  31.  
  32. 3. Make and install.
  33.  
  34. Bug reports and enhancements are always welcome.
  35.  
  36. Konstantinos Konstantinides
  37.  
  38. Hewlett-Packard Laboratories
  39. P.O. Box 10490
  40. Palo Alto, CA 94303
  41.  
  42. tel: (415) 857-4086
  43. e-mail: kk@hpkronos.hpl.hp.com
  44.  
  45. ---------------------------------------------------------------
  46. # This is a shell archive.  Remove anything before this line,
  47. # then unpack it by saving it in a file and typing "sh file".
  48. #
  49. # Wrapped by Konstantinos Konstantinides <kk@hpkronos> on Wed Feb 19 12:07:24 1992
  50. #
  51. # This archive contains:
  52. #    README.xfig    fig.c        fig2.1.c    hard_devices.c    
  53. #
  54.  
  55. LANG=""; export LANG
  56. PATH=/bin:/usr/bin:$PATH; export PATH
  57.  
  58. echo x - README.xfig
  59. cat >README.xfig <<'@EOF'
  60. The files fig.c and fig2.1.c provide xfig drivers for xgraph.
  61. fig.c is for FIG 2.0 and fig2.1.c for FIG 2.1.
  62. Then you can import and anotate xgraph files using xfig. Or you can
  63. use fig2dev to translate xgraph files into PIC, or Tex format.
  64.  
  65. xgraph is available from ic.berkeley.edu
  66. xfig is  available from export, /contrib/R5fixes/xfig-patches/xfig.*
  67. transfig (fig2dev) is available from ftp.cs.cornell.edu
  68.  
  69. What you need to do (assuming you have xgraph):
  70. 1. Edit the SRC and OBJ lines of the xgraph Makefile to include
  71.    fig.c, fig2.1.c, fig.o, and fig2.1.o.
  72.  
  73. 2. Edit hard_devices.c to include the new drivers. My hard_devices.c
  74.    is included here as an example.
  75.  
  76. 3. Make and install.
  77.  
  78. Bug reports and enhancements are always welcome.
  79.  
  80.  
  81. Konstantinos Konstantinides
  82.  
  83. Hewlett-Packard Laboratories
  84. P.O. Box 10490
  85. Palo Alto, CA 94303
  86.  
  87. tel: (415) 857-4086
  88. e-mail: kk@hpkronos.hpl.hp.com
  89. @EOF
  90.  
  91. chmod 644 README.xfig
  92.  
  93. echo x - fig.c
  94. cat >fig.c <<'@EOF'
  95. /*
  96.  * $Header: fig.c,v 1.1 91/04/17 09:49:32 kk Exp $ 
  97.  * FIG 2.0 output
  98.  *
  99.  * Based on "Transfig: Portable Figures for LateX", by Micah Beck,
  100.  * version 2.1.0.
  101.  * Fig 2.* is available from svax.cs.cornell.edu
  102.  * Konstantinos Konstantinides
  103.  * Hewlett-Packard Labs
  104.  * Palo Alto, CA.
  105.  * kk@hpkronos.hpl.hp.com
  106.  * Copyright (c) Hewlett-Packard, 1991.
  107.  *
  108.  * $Log:    fig.c,v $
  109.  * Revision 1.1  91/04/17  09:49:32  09:49:32  kk (Konstantinos Konstantinides)
  110.  * Initial revision
  111.  * 
  112.  */
  113.  
  114. #define MAPX(state,x) ( (x) + P1X + state->clipminX ) 
  115. #define MAPY(state,y) ( MAXY - (y) + P1Y - state->clipminY)
  116.  
  117. #include "copyright.h"
  118. #include <string.h>
  119. #include "xgout.h"
  120. #include <stdio.h>
  121. #include <math.h>
  122. #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
  123. #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
  124. char *malloc();
  125.  
  126. static void figText();
  127. static void figSeg();
  128. static void figDot();
  129. static void figEnd();
  130.  
  131. static xgOut figInfo = {
  132.     1, /* D_COLOR,    /* device characteristics */
  133.     800,   /* width (pixels) */
  134.     640,   /* height (pixels) */
  135.     40,    /* border padding */
  136.     10,      /* extra space around axis labels */
  137.     20,    /* tick length - approx 1/4 inch */
  138.     10,        /* spacing above legend lables */
  139.     0,      /* axis font width */
  140.     0,      /* axis font height */
  141.     0,      /* title font width */
  142.     0,      /* title font height */
  143.    10,      /* maximum number of segments */
  144.          /* pic fails for large array of segments */
  145.  
  146.     figText,   /* text output function */
  147.     figSeg,    /* segment  drawing function */
  148.     figDot,    /* dot/marker drawing function */
  149.     figEnd,    /* end of plot function */
  150.  
  151.     NULL,   /* userInfo */
  152. };
  153.  
  154. typedef struct {
  155.     int axis_w;
  156.     int axis_h;
  157.     int title_w;
  158.     int title_h;
  159.     int axis_f;
  160.     int title_f;
  161.     FILE *figFile;
  162. } mydata;
  163.  
  164. /*ARGSUSED*/
  165. int
  166. figInit(stream,width,height,title_family, title_size,
  167.         axis_family, axis_size, flags, outInfo,errmsg)
  168.     FILE *stream;    /* output stream */
  169.     int width;        /* desired width of space in microns */
  170.     int height;        /* desired height in microns */
  171.     char *title_family;    /* name of font for titles */
  172.     double title_size;    /* size of font for titles */
  173.     char *axis_family;    /* name of font for axes */
  174.     double axis_size;    /* size of font for axes */
  175.         int flags;        /* predicate values (ignored) */
  176.     xgOut *outInfo;    /* my structure */
  177.     char errmsg[ERRBUFSIZE];    /* a place to complain to */
  178. {
  179.     mydata *myInfo;
  180.  
  181.     myInfo = (mydata*)malloc(sizeof(mydata));
  182.     if(myInfo == NULL) return(NULL);
  183.         *outInfo = figInfo;
  184.     outInfo->area_w = MIN(800,width*0.0064);
  185.     outInfo->area_h = MIN(640,height*0.0064);
  186.     /* magic formulas:  input sizes are in points = 1/72 inch */
  187.     /* my sizes are in 80 pixels/inch : 80/72 = 1.11*/
  188.  
  189.     outInfo->axis_width =  axis_size * 0.74;
  190.     outInfo->axis_height = axis_size*1.11;
  191.     outInfo->title_width = title_size * 0.74;
  192.     outInfo->title_height = title_size * 1.11;
  193.     outInfo->user_state = (char *)myInfo;
  194.     myInfo->figFile = stream;
  195.     myInfo->axis_h = axis_size * 1.11;
  196.     myInfo->axis_f = axis_size ;
  197.     myInfo->title_h = title_size * 1.11;
  198.     myInfo->title_f = title_size ;
  199.     myInfo->axis_w = axis_size * 0.74;   /* two thirds */
  200.     myInfo->title_w = title_size * 0.74;
  201.     fprintf(myInfo->figFile,"%cFIG 2.0\n",'#');
  202.     fprintf(myInfo->figFile,"80 2\n");
  203.     return(1);
  204. }
  205.  
  206. static void 
  207. figText(userState,x,y,text,just,style)
  208.     mydata *userState;    /* my state information  */
  209.     int x,y;    /* coords of text origin (pixels) */
  210.     char *text; /* what to put there */
  211.     int just;   /* how to justify */
  212.     /* where the origin is relative to where the text should go
  213.      * as a function of the various values of just 
  214.  
  215.     T_UPPERLEFT     T_TOP       T_UPPERRIGHT
  216.     T_LEFT          T_CENTER    T_RIGHT
  217.     T_LOWERLEFT     T_BOTTOM    T_LOWERRIGHT
  218.  
  219.     */
  220.     int style;  /* T_AXIS = axis font, T_TITLE = title font */
  221.     /* you can only use Times-Roman and Bold-Roman */
  222.  
  223. {
  224.     int my_just = 0;
  225.     int length;
  226.     int font;
  227.     switch(just) {
  228.     case T_CENTER:
  229.     case T_TOP:
  230.     case T_BOTTOM:
  231.         my_just = 1;
  232.         break;
  233.         case T_LEFT:
  234.     case T_UPPERLEFT:
  235.     case T_LOWERLEFT:
  236.         my_just = 0;
  237.         break;
  238.         case T_RIGHT:
  239.     case T_UPPERRIGHT:
  240.     case T_LOWERRIGHT:
  241.         my_just = 2;
  242.         break;
  243.     default:
  244.         my_just = 0;
  245.     }
  246.  
  247.     switch(style) {
  248.         case T_AXIS:
  249.         length = userState->axis_w * strlen(text);
  250.         font = userState->axis_f;
  251.             fprintf(userState->figFile,"4 %d 0 %d 0 0 0 0.000 1 %d %d %d %d\
  252.         %s\01\n",my_just,font,userState->axis_h, length,x,y,text);
  253.             break;
  254.         case T_TITLE:
  255.         length = userState->title_w * strlen(text);
  256.         font = userState->title_f;
  257.             fprintf(userState->figFile,"4 %d 2 %d 0 0 0 0.000 1 %d %d %d %d\
  258.         %s\01\n",my_just,font,userState->title_h, length, x,y,text);
  259.             break;
  260.         default:
  261.             printf("bad text style %d in figText\n",style);
  262.             exit(1);
  263.             break;
  264.     }
  265. }
  266.  
  267.  
  268.  
  269. static void 
  270. figSeg(userState,ns,segs,width,style,lappr,color)
  271.     mydata *userState;    /* my state information (not used) */
  272.     int ns;         /* number of segments */
  273.     XSegment *segs; /* X array of segments */
  274.     int width;      /* width of lines in pixels */
  275.     int style;      /* L_VAR = dotted, L_AXIS = grid, L_ZERO = axis*/
  276.     int lappr;      /* line style :solid=0, dash=1, dotted=2*/
  277.     int color;      /* line color */
  278. {
  279.     int i=0;
  280.     int line_style=0;
  281.     static int s_val[3] = {0, 4, 3}; 
  282.     int line_val;
  283.  
  284.     if (style == L_ZERO) {
  285.         line_style=0;                      /* solid line style */
  286.     line_val=0;
  287.     } else if (style == L_AXIS) {
  288.         line_style=2;                      /* dotted line style */
  289.     line_val=3;
  290.     } else if (style == L_VAR) {
  291.     line_style=(lappr+color)%3; 
  292.     line_val=s_val[line_style];
  293.     }
  294.     if(i==0) {
  295.         fprintf(userState->figFile,"2 1 %d 1 0 0 0 0 %d.000 0 0\n",line_style,line_val);
  296.             fprintf(userState->figFile,"      %d %d ",segs[i].x1,segs[i].y1);
  297.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  298.         }
  299.     i++;
  300.  
  301.     for(i=1;i<ns;i++) {
  302.         if((segs[i].x1!=segs[i-1].x2) || (segs[i].y1!=segs[i-1].y2) ){
  303.             /* MOVE */
  304.             fprintf(userState->figFile," 9999 9999\n");
  305.         fprintf(userState->figFile,"2 1 %d 1 0 0 0 0 %d.000 0 0\n",line_style,line_val);
  306.             fprintf(userState->figFile,"      %d %d ",segs[i].x1,segs[i].y1);
  307.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  308.         }
  309.     else {
  310.         /* draw */
  311.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  312.     }
  313.     }
  314.     if(i==ns) fprintf(userState->figFile," 9999 9999\n");
  315. }
  316.  
  317. static void 
  318. figDot(userState,x,y,style,type,color)
  319.     mydata *userState;    /* my state information (not used) */
  320.     int x,y;    /* coord of dot */
  321.     int style;  /* type of dot */
  322.     int type;   /* dot style variation */
  323.     int color;  /* color of dot */
  324. {
  325.     static char *mark[8] = { "A", "B", "C", "D", "E", "F", "G", "H"};
  326.     if(style==P_PIXEL) /* print a single pixel = . */
  327.         fprintf(userState->figFile,"4 0 0 12 0 0 0 0.000 1 1 3\
  328.  %d %d .\01\n",x,y);
  329.         else if(style==P_DOT) /* Draw a little circle of radius=4 pixels */
  330.         fprintf(userState->figFile,"1 3 0 1 0 0 0 0 0.000 1\
  331.  0.000 %d %d 4 4 %d %d %d %d\n",x,y,x,y,x,(y-4));
  332.     else if(style==P_MARK) /* Draw a mark */
  333.         switch(type) {
  334.  
  335.         case 0: /* draw a circle */
  336.             fprintf(userState->figFile,"1 3 0 1 0 0 0 0 0.000 1\
  337. 0.000 %d %d 4 4 %d %d %d %d\n",x,y,x,y,x,(y-4));
  338.                    break;
  339.         case 1: /* draw a square */
  340.             fprintf(userState->figFile,"2 2 0 1 0 0 0 0 0.000 0 0\n");
  341.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  342.  %d %d 9999 9999\n", x-4,y+3,x-4,y-3,x+4,y-3, x+4,y+3,x-4,y+3);
  343.             break;
  344.         case 2: /* draw a diamond */
  345.             fprintf(userState->figFile,"2 3 0 1 0 0 0 0 0.000 0 0\n");
  346.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  347.  %d %d 9999 9999\n", x-4,y,x,y-4,x+4,y, x,y+4,x-4,y);
  348.             break;
  349.         case 3: /* draw a triangle */
  350.             fprintf(userState->figFile,"2 3 0 1 0 0 0 0 0.000 0 0\n");
  351.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  352.  9999 9999\n", x-3,y+4,x,y-4,x+3,y+4, x-3,y+4);
  353.             break;
  354.         case 4: /* draw a cross */
  355.             fprintf(userState->figFile,"4 1 0 16 0 0 0 0.000 1 1 3\
  356.  %d %d %s\01\n",x,y,"+");
  357.             break;
  358.         case 5: /* draw a * */
  359.             fprintf(userState->figFile,"4 1 0 16 0 0 0 0.000 1 1 3\
  360.  %d %d %s\01\n",x,y,"*");
  361.             break;
  362.         default:
  363.             fprintf(userState->figFile,"4 0 0 12 0 0 0 0.000 1 1 3\
  364.  %d %d %s\01\n",x,y,mark[type]);
  365.         }
  366.         /*
  367.         fprintf(userState->figFile,"4 0 0 12 0 0 0 0.000 1 1 3\
  368.            %d %d %s\01\n",x,y,mark[type]);
  369.         */
  370.         else  fprintf(userState->figFile,"%cUnknown marker style\n","#");
  371.         
  372. }
  373.  
  374. static void 
  375. figEnd(userState)
  376.     mydata *userState;    /* my state information (not used) */
  377.  
  378. {
  379.     fprintf(userState->figFile,"\n%cEnd of fig file\n",'#');
  380.     fflush(userState->figFile);
  381.     return;
  382. }
  383. @EOF
  384.  
  385. chmod 644 fig.c
  386.  
  387. echo x - fig2.1.c
  388. cat >fig2.1.c <<'@EOF'
  389. /*
  390.  * $Header: fig2.1.c,v 1.2 92/02/19 11:54:53 kk Exp $ 
  391.  * FIG 2.1 output
  392.  *
  393.  * Based on "Transfig: Portable Figures for LateX", by Micah Beck,
  394.  * version 2.1.4.
  395.  * Fig 2.* is available from svax.cs.cornell.edu
  396.  * Konstantinos Konstantinides
  397.  * Hewlett-Packard Labs
  398.  * Palo Alto, CA.
  399.  * kk@hpkronos.hpl.hp.com
  400.  * Copyright (c) Hewlett-Packard, 1991.
  401.  *
  402.  * $Log:    fig2.1.c,v $
  403.  * Revision 1.2  92/02/19  11:54:53  11:54:53  kk (Konstantinos Konstantinides)
  404.  * *** empty log message ***
  405.  * 
  406.  * Revision 1.1  92/02/18  18:32:16  18:32:16  kk (Konstantinos Konstantinides)
  407.  * Initial revision
  408.  * 
  409.  */
  410.  
  411. #define MAPX(state,x) ( (x) + P1X + state->clipminX ) 
  412. #define MAPY(state,y) ( MAXY - (y) + P1Y - state->clipminY)
  413.  
  414. #include "copyright.h"
  415. #include <string.h>
  416. #include "xgout.h"
  417. #include <stdio.h>
  418. #include <math.h>
  419. #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
  420. #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
  421. char *malloc();
  422.  
  423. static void figText2();
  424. static void figSeg2();
  425. static void figDot2();
  426. static void figEnd2();
  427.  
  428. static xgOut figInfo = {
  429.     1, /* D_COLOR,    /* device characteristics */
  430.     800,   /* width (pixels) */
  431.     640,   /* height (pixels) */
  432.     40,    /* border padding */
  433.     10,      /* extra space around axis labels */
  434.     20,    /* tick length - approx 1/4 inch */
  435.     10,        /* spacing above legend lables */
  436.     0,      /* axis font width */
  437.     0,      /* axis font height */
  438.     0,      /* title font width */
  439.     0,      /* title font height */
  440.    10,      /* maximum number of segments */
  441.          /* pic fails for large array of segments */
  442.  
  443.     figText2,   /* text output function */
  444.     figSeg2,    /* segment  drawing function */
  445.     figDot2,    /* dot/marker drawing function */
  446.     figEnd2,    /* end of plot function */
  447.  
  448.     NULL,   /* userInfo */
  449. };
  450.  
  451. typedef struct {
  452.     int axis_w;
  453.     int axis_h;
  454.     int title_w;
  455.     int title_h;
  456.     int axis_f;
  457.     int title_f;
  458.     FILE *figFile;
  459. } mydata;
  460.  
  461. /*ARGSUSED*/
  462. int
  463. figInit2(stream,width,height,title_family, title_size,
  464.         axis_family, axis_size, flags, outInfo,errmsg)
  465.     FILE *stream;    /* output stream */
  466.     int width;        /* desired width of space in microns */
  467.     int height;        /* desired height in microns */
  468.     char *title_family;    /* name of font for titles */
  469.     double title_size;    /* size of font for titles */
  470.     char *axis_family;    /* name of font for axes */
  471.     double axis_size;    /* size of font for axes */
  472.         int flags;        /* predicate values (ignored) */
  473.     xgOut *outInfo;    /* my structure */
  474.     char errmsg[ERRBUFSIZE];    /* a place to complain to */
  475. {
  476.     mydata *myInfo;
  477.  
  478.     myInfo = (mydata*)malloc(sizeof(mydata));
  479.     if(myInfo == NULL) return(NULL);
  480.         *outInfo = figInfo;
  481.     outInfo->area_w = MIN(800,width*0.0064);
  482.     outInfo->area_h = MIN(640,height*0.0064);
  483.     /* magic formulas:  input sizes are in points = 1/72 inch */
  484.     /* my sizes are in 80 pixels/inch : 80/72 = 1.11*/
  485.  
  486.     outInfo->axis_width =  axis_size * 0.74;
  487.     outInfo->axis_height = axis_size*1.11;
  488.     outInfo->title_width = title_size * 0.74;
  489.     outInfo->title_height = title_size * 1.11;
  490.     outInfo->user_state = (char *)myInfo;
  491.     myInfo->figFile = stream;
  492.     myInfo->axis_h = axis_size * 1.11;
  493.     myInfo->axis_f = axis_size ;
  494.     myInfo->title_h = title_size * 1.11;
  495.     myInfo->title_f = title_size ;
  496.     myInfo->axis_w = axis_size * 0.74;   /* two thirds */
  497.     myInfo->title_w = title_size * 0.74;
  498.     fprintf(myInfo->figFile,"%cFIG 2.1\n",'#');
  499.     fprintf(myInfo->figFile,"80 2\n");
  500.     return(1);
  501. }
  502.  
  503. static void 
  504. figText2(userState,x,y,text,just,style)
  505.     mydata *userState;    /* my state information  */
  506.     int x,y;    /* coords of text origin (pixels) */
  507.     char *text; /* what to put there */
  508.     int just;   /* how to justify */
  509.     /* where the origin is relative to where the text should go
  510.      * as a function of the various values of just 
  511.  
  512.     T_UPPERLEFT     T_TOP       T_UPPERRIGHT
  513.     T_LEFT          T_CENTER    T_RIGHT
  514.     T_LOWERLEFT     T_BOTTOM    T_LOWERRIGHT
  515.  
  516.     */
  517.     int style;  /* T_AXIS = axis font, T_TITLE = title font */
  518.     /* you can only use Times-Roman and Bold-Roman */
  519.  
  520. {
  521.     int my_just = 0;
  522.     int length;
  523.     int font;
  524.     switch(just) {
  525.     case T_CENTER:
  526.     case T_TOP:
  527.     case T_BOTTOM:
  528.         my_just = 1;
  529.         break;
  530.         case T_LEFT:
  531.     case T_UPPERLEFT:
  532.     case T_LOWERLEFT:
  533.         my_just = 0;
  534.         break;
  535.         case T_RIGHT:
  536.     case T_UPPERRIGHT:
  537.     case T_LOWERRIGHT:
  538.         my_just = 2;
  539.         break;
  540.     default:
  541.         my_just = 0;
  542.     }
  543.  
  544.     switch(style) {
  545.         case T_AXIS:
  546.         length = userState->axis_w * strlen(text);
  547.         font = userState->axis_f;
  548.             fprintf(userState->figFile,"4 %d 0 %d 0 -1 0 0.000 4 %d %d %d %d\
  549.         %s\01\n",my_just,font,userState->axis_h, length,x,y,text);
  550.             break;
  551.         case T_TITLE:
  552.         length = userState->title_w * strlen(text);
  553.         font = userState->title_f;
  554.             fprintf(userState->figFile,"4 %d 2 %d 0 -1 0 0.000 4 %d %d %d %d\
  555.         %s\01\n",my_just,font,userState->title_h, length, x,y,text);
  556.             break;
  557.         default:
  558.             printf("bad text style %d in figText\n",style);
  559.             exit(1);
  560.             break;
  561.     }
  562. }
  563.  
  564.  
  565.  
  566. static void 
  567. figSeg2(userState,ns,segs,width,style,lappr,color)
  568.     mydata *userState;    /* my state information (not used) */
  569.     int ns;         /* number of segments */
  570.     XSegment *segs; /* X array of segments */
  571.     int width;      /* width of lines in pixels */
  572.     int style;      /* L_VAR = dotted, L_AXIS = grid, L_ZERO = axis*/
  573.     int lappr;      /* line style :solid=0, dash=1, dotted=2*/
  574.     int color;      /* line color */
  575. {
  576.     int i=0;
  577.     int line_style=0;
  578.     static int s_val[3] = {0, 4, 3}; 
  579.     int line_val;
  580.  
  581.     if (style == L_ZERO) {
  582.         line_style=0;                      /* solid line style */
  583.     line_val=0;
  584.     } else if (style == L_AXIS) {
  585.         line_style=2;                      /* dotted line style */
  586.     line_val=3;
  587.     } else if (style == L_VAR) {
  588.     line_style=(lappr+color)%3; 
  589.     line_val=s_val[line_style];
  590.     }
  591.     if(i==0) {
  592.         fprintf(userState->figFile,"2 1 %d 1 -1 0 0 0 %d.000 -1 0 0\n",line_style,line_val);
  593.             fprintf(userState->figFile,"      %d %d ",segs[i].x1,segs[i].y1);
  594.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  595.         }
  596.     i++;
  597.  
  598.     for(i=1;i<ns;i++) {
  599.         if((segs[i].x1!=segs[i-1].x2) || (segs[i].y1!=segs[i-1].y2) ){
  600.             /* MOVE */
  601.             fprintf(userState->figFile," 9999 9999\n");
  602.         fprintf(userState->figFile,"2 1 %d 1 -1 0 0 0 %d.000 -1 0 0\n",line_style,line_val);
  603.             fprintf(userState->figFile,"      %d %d ",segs[i].x1,segs[i].y1);
  604.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  605.         }
  606.     else {
  607.         /* draw */
  608.             fprintf(userState->figFile,"%d %d ",segs[i].x2,segs[i].y2);
  609.     }
  610.     }
  611.     if(i==ns) fprintf(userState->figFile," 9999 9999\n");
  612. }
  613.  
  614. static void 
  615. figDot2(userState,x,y,style,type,color)
  616.     mydata *userState;    /* my state information (not used) */
  617.     int x,y;    /* coord of dot */
  618.     int style;  /* type of dot */
  619.     int type;   /* dot style variation */
  620.     int color;  /* color of dot */
  621. {
  622.     static char *mark[8] = { "A", "B", "C", "D", "E", "F", "G", "H"};
  623.     if(style==P_PIXEL) /* print a single pixel = . */
  624.         fprintf(userState->figFile,"4 0 0 12 0 -1 0 0.000 4 1 3\
  625.  %d %d .\01\n",x,y);
  626.         else if(style==P_DOT) /* Draw a little circle of radius=4 pixels */
  627.         fprintf(userState->figFile,"1 3 0 1 -1 0 0 0 0.000 1\
  628.  0.000 %d %d 4 4 %d %d %d %d\n",x,y,x,y,x,(y-4));
  629.     else if(style==P_MARK) /* Draw a mark */
  630.         switch(type) {
  631.  
  632.         case 0: /* draw a circle */
  633.             fprintf(userState->figFile,"1 3 0 1 -1 0 0 0 0.000 1\
  634. 0.000 %d %d 4 4 %d %d %d %d\n",x,y,x,y,x,(y-4));
  635.                    break;
  636.         case 1: /* draw a square */
  637.             fprintf(userState->figFile,"2 2 0 1 -1 0 0 0 0.000 -1 0 0\n");
  638.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  639.  %d %d 9999 9999\n", x-4,y+3,x-4,y-3,x+4,y-3, x+4,y+3,x-4,y+3);
  640.             break;
  641.         case 2: /* draw a diamond */
  642.             fprintf(userState->figFile,"2 3 0 1 -1 0 0 0 0.000 -1 0 0\n");
  643.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  644.  %d %d 9999 9999\n", x-4,y,x,y-4,x+4,y, x,y+4,x-4,y);
  645.             break;
  646.         case 3: /* draw a triangle */
  647.             fprintf(userState->figFile,"2 3 0 1 -1 0 0 0 0.000 -1 0 0\n");
  648.             fprintf(userState->figFile,"    %d %d %d %d %d %d %d %d\
  649.  9999 9999\n", x-3,y+4,x,y-4,x+3,y+4, x-3,y+4);
  650.             break;
  651.         case 4: /* draw a cross */
  652.             fprintf(userState->figFile,"4 1 0 16 0 -1 0 0.000 4 1 3\
  653.  %d %d %s\01\n",x,y,"+");
  654.             break;
  655.         case 5: /* draw a * */
  656.             fprintf(userState->figFile,"4 1 0 16 0 -1 0 0.000 4 1 3\
  657.  %d %d %s\01\n",x,y,"*");
  658.             break;
  659.         default:
  660.             fprintf(userState->figFile,"4 0 0 12 0 -1 0 0.000 4 1 3\
  661.  %d %d %s\01\n",x,y,mark[type]);
  662.         }
  663.         /*
  664.         fprintf(userState->figFile,"4 0 0 12 0 -1 0 0.000 4 1 3\
  665.            %d %d %s\01\n",x,y,mark[type]);
  666.         */
  667.         else  fprintf(userState->figFile,"%cUnknown marker style\n","#");
  668.         
  669. }
  670.  
  671. static void 
  672. figEnd2(userState)
  673.     mydata *userState;    /* my state information (not used) */
  674.  
  675. {
  676.     fprintf(userState->figFile,"\n%cEnd of fig file\n",'#');
  677.     fflush(userState->figFile);
  678.     return;
  679. }
  680. @EOF
  681.  
  682. chmod 644 fig2.1.c
  683.  
  684. echo x - hard_devices.c
  685. cat >hard_devices.c <<'@EOF'
  686. /*
  687.  * Hardcopy Devices
  688.  *
  689.  * This file contains the basic output device table.  The hardcopy
  690.  * dialog is automatically constructed from this table.
  691.  */
  692.  
  693. #include "copyright.h"
  694. #include "xgout.h"
  695. #include "hard_devices.h"
  696. #include "params.h"
  697.  
  698. extern int hpglInit();
  699. extern int figInit();
  700. extern int figInit2();
  701. extern int psInit();
  702. extern int idrawInit();
  703.  
  704. struct hard_dev hard_devices[] = {
  705.     { "HPGL", hpglInit, "lpr -P%s", "xgraph.hpgl", "paper",
  706.     27.5, "1", 14.0, "1", 12.0, NONE },
  707.     /*{ "Postscript", psInit, "lpr -P%s", "xgraph.ps", "lps40", */
  708.     { "Postscript", psInit, "lp -d%s -oraw", "xgraph.ps", "psjet",
  709.     19.0, "Times-Bold", 18.0, "Times-Roman", 12.0, NO },
  710.     { "Fig2.1", figInit2, "cat > $HOME/xgraph.fig", "xgraph.fig","don't print",
  711.        10.0, "Times-Bold", 14.0, "Times-Roman",12.0, NO },
  712.     { "Fig2.0", figInit, "cat > $HOME/xgraph.fig", "xgraph.fig","don't print",
  713.        10.0, "Times-Bold", 14.0, "Times-Roman",12.0, NO },
  714.     { "Idraw", idrawInit,
  715.     "cat > /usr/tmp/idraw.tmp.ps; %s /usr/tmp/idraw.tmp.ps&",
  716.     "~/.clipboard", "/usr/local/idraw", 19.0, "Times-Bold", 18.0,
  717.     "Times-Roman", 12.0, NONE }
  718. };
  719.  
  720. int hard_count = sizeof(hard_devices)/sizeof(struct hard_dev);
  721.  
  722. #define CHANGE_D(name, field) \
  723. if (param_get(name, &val)) { \
  724.     if (val.type == DBL) { \
  725.        hard_devices[idx].field = val.dblv.value; \
  726.     } \
  727. }
  728.  
  729. #define CHANGE_S(name, field) \
  730. if (param_get(name, &val)) { \
  731.     if (val.type == STR) { \
  732.        (void) strcpy(hard_devices[idx].field, val.strv.value); \
  733.     } \
  734. }
  735.  
  736.  
  737. void hard_init()
  738. /*
  739.  * Changes values in hard_devices structures in accordance with
  740.  * parameters set using the parameters module.
  741.  */
  742. {
  743.     char newname[1024];
  744.     int idx;
  745.     params val;
  746.  
  747.     for (idx = 0;  idx < hard_count;  idx++) {
  748.     (void) sprintf(newname, "%s.Dimension", hard_devices[idx].dev_name);
  749.     CHANGE_D(newname, dev_max_dim);
  750.     (void) sprintf(newname, "%s.OutputTitleFont", hard_devices[idx].dev_name);
  751.     CHANGE_S(newname, dev_title_font);
  752.     (void) sprintf(newname, "%s.OutputTitleSize", hard_devices[idx].dev_name);
  753.     CHANGE_D(newname, dev_title_size);
  754.     (void) sprintf(newname, "%s.OutputAxisFont", hard_devices[idx].dev_name);
  755.     CHANGE_S(newname, dev_axis_font);
  756.     (void) sprintf(newname, "%s.OutputAxisSize", hard_devices[idx].dev_name);
  757.     CHANGE_D(newname, dev_axis_size);
  758.     }
  759. }
  760. @EOF
  761.  
  762. chmod 644 hard_devices.c
  763.  
  764. exit 0
  765. -- 
  766. --
  767. Molecular Simulations, Inc.            mail: dcmartin@msi.com
  768. 796 N. Pastoria Avenue                uucp: uunet!dcmartin
  769. Sunnyvale, California 94086            at&t: 408/522-9236
  770.