1 #include "coxplot.h"
2 
3 /*****************************************************************************
4   This software is copyrighted and owned by the Medical College of Wisconsin.
5   See the file README.Copyright for details.
6 ******************************************************************************/
7 
8 /*------------------------------------------------------------------------
9   Routine to render a memplot into a PostScript file.
10   (Also see the file ps_plot.c.)
11 --------------------------------------------------------------------------*/
12 
13 #ifdef PSIZE
14 #undef PSIZE
15 #endif
16 #define PSIZE 4096
17 
memplot_to_postscript(char * fname,MEM_plotdata * mp)18 void memplot_to_postscript( char *fname , MEM_plotdata *mp )
19 {
20    int ii , nline ;
21    float old_thick , old_color , new_color , new_thick ;
22    int   x1,y1 , x2,y2 ;
23    int   skip ;
24 
25    /*-- sanity checks --*/
26 
27    if( fname == NULL || fname[0] == '\0' || mp == NULL ) return ;
28 
29    nline = MEMPLOT_NLINE(mp) ; if( nline < 1 ) return ;
30 
31    /*-- open the output file --*/
32 
33    if( ! ps_openpl(fname) ) return ;
34    ps_space( 0,0,PSIZE,PSIZE ) ;
35 
36    old_color = -1.0 ;
37    old_thick = -THCODE_INVALID ;
38 
39    /*-- loop over lines, scale and plot --*/
40 
41    for( ii=0 ; ii < nline ; ii++ ){
42 
43       skip = 0 ;
44 
45       /* check if need to change color or thickness of line */
46 
47       new_color = MEMPLOT_COL(mp,ii) ;
48       if( new_color != old_color ){
49          float rr=COL_TO_RRR(new_color) ,
50                gg=COL_TO_GGG(new_color) , bb=COL_TO_BBB(new_color) ;
51          ps_setrgb( rr , gg , bb ) ;
52          old_color = new_color ;
53       }
54       new_thick = MEMPLOT_TH(mp,ii) ;
55       if( new_thick < 0.0 ){           /* 21 Mar 2001: negative thickness codes */
56          int thc = (int)(-new_thick) ;
57          switch( thc ){
58             case THCODE_FRECT:
59             case THCODE_RECT:{        /* rectangle */
60                x1 = 0.499 + PSIZE * (1.0 - MEMPLOT_Y1(mp,ii)) ;
61                x2 = 0.499 + PSIZE * (1.0 - MEMPLOT_Y2(mp,ii)) ;
62                y1 = 0.499 + PSIZE * MEMPLOT_X1(mp,ii) ;
63                y2 = 0.499 + PSIZE * MEMPLOT_X2(mp,ii) ;
64                ps_rect( x1,y1 , x2,y2 ) ;
65                skip = 1 ;
66             }
67             break ;
68 
69             case THCODE_CIRC:{        /* circle */
70                x1 = 0.499 + PSIZE * (1.0 - MEMPLOT_Y1(mp,ii)) ;
71                y1 = 0.499 + PSIZE * MEMPLOT_X1(mp,ii) ;
72                x2 = 0.499 + PSIZE * MEMPLOT_X2(mp,ii) ;
73                ps_circle( x1,y1 , x2 ) ;
74                skip = 1 ;
75             }
76             break ;
77          }
78       } else if( new_thick != old_thick ){  /* old code to change line thickness */
79          float th = PSIZE * new_thick ;
80          if( th <= 0.0 ) th = 1.0 ;
81          ps_setwidth( th ) ;
82          old_thick = new_thick ;
83       }
84 
85       if( !skip ){
86         /* scale coords (also see zzphph.f) */
87 
88         x1 = 0.499 + PSIZE * (1.0 - MEMPLOT_Y1(mp,ii)) ;
89         x2 = 0.499 + PSIZE * (1.0 - MEMPLOT_Y2(mp,ii)) ;
90         y1 = 0.499 + PSIZE * MEMPLOT_X1(mp,ii) ;
91         y2 = 0.499 + PSIZE * MEMPLOT_X2(mp,ii) ;
92 
93         ps_line( x1,y1 , x2,y2 ) ;
94       }
95    }
96 
97    /*-- done --*/
98 
99    ps_closepl() ;
100    return ;
101 }
102