Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

plot_ps.c File Reference

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>

Go to the source code of this file.


Defines

#define M_PI   3.14159265358979323846

Functions

void ps_move (int, int)
void ps_line (int, int, int, int)
void ps_cont (int, int)
void ps_point (int, int)
void ps_label (char *)
void ps_arc (int, int, int, int, int, int)
void ps_circle (int, int, int)
void ps_erase (void)
void ps_linemod (char *)
void ps_space (int, int, int, int)
int ps_openpl (char *)
void ps_closepl (void)
void ps_setrgb (float, float, float)
void ps_setwidth (float)
void ps_rect (int, int, int, int)
void zzpsco_ (float *, float *, float *)
void zzpsop_ (char *cfl, int ncfl)
void zzpsli_ (int *, int *, int *, int *)
void zzpsfr_ (void)
void zzpscl_ (void)
void ps_maybe_stroke (void)
void ps_stroke (void)
int ps_setfont (void)
void ps_prolog (void)
void ps_epilog (void)
void ps_clear (void)

Variables

int font
int error
int npages = 0
int cx
int cy
int ttcur = 0
int atcur = 0
int inpath = 0
int plot = 0
double scal = 1.0
int prolog_not_output = 1
FILE * psfile = NULL
int psfile_ispipe = 0
char * prolog_text []

Define Documentation

#define M_PI   3.14159265358979323846
 

Definition at line 137 of file plot_ps.c.

Referenced by ps_arc().


Function Documentation

void ps_arc int   ,
int   ,
int   ,
int   ,
int   ,
int   
 

Definition at line 140 of file plot_ps.c.

References atcur, inpath, M_PI, plot, ps_stroke(), psfile, x2, and y1.

00141 {  double dx , dy ;
00142 
00143    if (inpath) ps_stroke() ;
00144    dx=x1-x;
00145    dy=y1-y;
00146    fprintf( psfile , "%d %d %f ", x, y, sqrt(dx*dx+dy*dy) );
00147    fprintf( psfile , "%f ", (double)(atan2(dy,dx)/M_PI)*180.0 );
00148    dx=x2-x;
00149    dy=y2-y;
00150    fprintf( psfile , "%f ", (double)(atan2(dy,dx)/M_PI)*180.0 );
00151    plot=1;
00152    atcur=inpath=0;
00153 }

void ps_circle int   ,
int   ,
int   
 

Definition at line 155 of file plot_ps.c.

References plot, psfile, and r.

00156 {  fprintf( psfile , "%d %d %d C\n",x,y,r);
00157    plot=1;
00158 }

void ps_clear void   
 

Definition at line 298 of file plot_ps.c.

References atcur, inpath, npages, plot, ps_stroke(), psfile, and ttcur.

Referenced by ps_epilog(), and ps_erase().

00299 { if (inpath) ps_stroke() ;
00300   if (plot)
00301   {
00302     fprintf( psfile , "CL\n");
00303     npages++;
00304     atcur=inpath=ttcur=plot=0;
00305   }
00306 }

void ps_closepl void   
 

Definition at line 251 of file plot_ps.c.

References pclose, ps_epilog(), psfile, and psfile_ispipe.

00252 { ps_epilog();
00253 
00254   if( psfile == stdout ){                   /* 29 Nov 2002: don't close stdout */
00255     fflush(psfile) ;                        /*              just flush it */
00256   } else {
00257     if( ! psfile_ispipe ) fclose(psfile) ;
00258     else                  pclose(psfile) ;  /* RWCox */
00259   }
00260 
00261   psfile = NULL ; psfile_ispipe = 0 ;
00262 }

void ps_cont int   ,
int   
 

Definition at line 85 of file plot_ps.c.

References atcur, cx, cy, inpath, plot, ps_maybe_stroke(), ps_move(), psfile, and ttcur.

00086 { if (!inpath) fprintf( psfile , "NP ");
00087   if (!atcur) fprintf( psfile , "%d %d M\n",cx,cy);
00088   ps_move( ix , iy ) ;
00089   fprintf( psfile , "%d %d N\n",cx,cy);
00090   ttcur=0;
00091   atcur=plot=1;
00092   inpath++;
00093   ps_maybe_stroke() ;
00094 }

void ps_epilog void   
 

Definition at line 310 of file plot_ps.c.

References npages, ps_clear(), and psfile.

Referenced by ps_closepl().

00311 { ps_clear();
00312 #ifdef USE_EOT
00313   fprintf( psfile , "%%%%Trailer\n%%%%Pages: %d\n%c", npages,4); /* inc. EOT */
00314 #else
00315   fprintf( psfile , "%%%%Trailer\n%%%%Pages: %d\n", npages); /* no EOT */
00316 #endif
00317 }

void ps_erase void   
 

Definition at line 160 of file plot_ps.c.

References ps_clear().

00161 { ps_clear() ; }

void ps_label char *   
 

Definition at line 118 of file plot_ps.c.

References atcur, c, cx, cy, font, inpath, plot, ps_setfont(), ps_stroke(), psfile, putchar, and ttcur.

00119 { int is ;
00120   char c ;
00121 
00122   if (inpath) ps_stroke() ;
00123   if (!ttcur) fprintf( psfile , "%d %d M\n",cx,cy);
00124   if (!font) font=ps_setfont();
00125   fprintf( psfile , "(");
00126   for( is=0,c=s[is] ; (c!='\0')&&(c!='\n') ; ++is,c=s[is] )
00127   {
00128     if (c=='(' || c==')' || c=='\\')putchar('\\');
00129     putchar(c);
00130   }
00131   fprintf( psfile , ") T\n");
00132   ttcur=plot=1;
00133   atcur=inpath=0;
00134 }

void ps_line int   ,
int   ,
int   ,
int   
 

Definition at line 77 of file plot_ps.c.

References ps_cont(), and ps_move().

00078 { ps_move( ix1 , iy1 ) ;
00079   ps_cont( ix2 , iy2 ) ;
00080 }

void ps_linemod char *   
 

Definition at line 166 of file plot_ps.c.

References ps_stroke(), psfile, and scal.

00167 { double pt ;
00168   pt = 1.0 / scal ;
00169 
00170   if (inpath) ps_stroke() ;  /* draw anything specified before setdash */
00171 
00172   if (strncmp(s,"solid",5) == 0) {
00173      fprintf( psfile , "[] 0 setdash\n") ;
00174   } else if( strncmp(s,"dotted",6) == 0 ) {
00175      fprintf( psfile , "[ %f %f ] 0 setdash\n" , 2.0*pt , 3.0*pt ) ;
00176   } else if( strncmp(s,"dotdashed",9) == 0 ) {
00177      fprintf( psfile , "[ %f %f %f %f ] 0 setdash\n" ,
00178             2.0*pt , 3.0*pt , 6.0*pt , 3.0*pt ) ;
00179   } else if( strncmp(s,"shortdashed",11) == 0 ) {
00180      fprintf( psfile , "[ %f %f ] 0 setdash\n" , 6.0*pt , 3.0*pt ) ;
00181   } else if( strncmp(s,"longdashed",10) == 0 ) {
00182      fprintf( psfile , "[ %f %f ] 0 setdash\n" , 9.0*pt , 4.5*pt ) ;
00183   } else {
00184      fprintf(stderr,
00185              "plotps: linestyle '%s' not implemented.\n",s);
00186      fprintf( psfile , "[] 0 setdash\n") ;
00187   }
00188 }

void ps_maybe_stroke void   
 

Definition at line 63 of file plot_ps.c.

References inpath, and ps_stroke().

Referenced by ps_cont().

00064 { if (inpath>100) ps_stroke();  }

void ps_move int   ,
int   
 

Definition at line 69 of file plot_ps.c.

References atcur, cx, cy, and ttcur.

00070 {
00071   if( atcur && cx == ix && cy == iy ) return ;
00072   cx = ix ;
00073   cy = iy ;
00074   ttcur=atcur=0;
00075 }

int ps_openpl char *   
 

Definition at line 222 of file plot_ps.c.

References popen, ps_prolog(), psfile, and psfile_ispipe.

00223 {
00224   if( strcmp(fname,"-") == 0 ){           /* 29 Nov 2002: to stdout */
00225     psfile = stdout ;
00226     psfile_ispipe = 0 ;
00227   } else if( fname[0] != '|' ){           /* normal file */
00228     psfile = fopen( fname , "w" ) ;
00229     psfile_ispipe = 0 ;
00230   } else {                                /* open a pipe */
00231     psfile = popen( fname+1 , "w" ) ;
00232     psfile_ispipe = 1 ;
00233   }
00234   if( psfile == NULL ) return 0 ;
00235   ps_prolog();
00236   return 1 ;
00237 }

void ps_point int   ,
int   
 

Definition at line 110 of file plot_ps.c.

References atcur, cx, cy, inpath, plot, ps_move(), ps_stroke(), psfile, and ttcur.

00111 { if (inpath) ps_stroke() ;
00112   ps_move( ix , iy ) ;
00113   fprintf( psfile , "%d %d %c\n",cx,cy,'P');
00114   ttcur=atcur=inpath=0;
00115   plot=1;
00116 }

void ps_prolog void   
 

Definition at line 286 of file plot_ps.c.

References font, p, prolog_not_output, prolog_text, psfile, and tt.

Referenced by ps_openpl(), and ps_space().

00287 {
00288     time_t tt = time(NULL);
00289     char **p;
00290 
00291     fprintf( psfile , "%%!PS-Adobe-2.0 EPSF-2.0\n%%%%CreationDate: %s", ctime(&tt));
00292     for (p = prolog_text;  *p;  p++)
00293         fprintf(psfile,"%s\n" , *p);
00294     font=0;
00295     prolog_not_output = 0 ;
00296 }

void ps_rect int   ,
int   ,
int   ,
int   
 

Definition at line 96 of file plot_ps.c.

References ps_stroke(), psfile, x2, and y1.

00097 {
00098    if( inpath ) ps_stroke() ;
00099    fprintf( psfile , "NP ");
00100    fprintf( psfile , "%d %d M ",x1,y1);
00101    fprintf( psfile , "%d %d N ",x2,y1);
00102    fprintf( psfile , "%d %d N ",x2,y2);
00103    fprintf( psfile , "%d %d N ",x1,y2);
00104 #if 0
00105    fprintf( psfile , "%d %d N ",x1,y1);
00106 #endif
00107    fprintf( psfile , "F S\n") ;
00108 }

int ps_setfont void   
 

Definition at line 216 of file plot_ps.c.

References psfile, and scal.

Referenced by ps_label().

00217 {
00218     fprintf( psfile , "%f SF\n",12.0/scal);
00219     return 1;
00220 }

void ps_setrgb float   ,
float   ,
float   
 

Definition at line 208 of file plot_ps.c.

References ps_stroke(), and psfile.

00209 { if( inpath ) ps_stroke() ;
00210   fprintf( psfile , "%f %f %f setrgbcolor\n" , rrr,ggg,bbb ) ;
00211 }

void ps_setwidth float   
 

Definition at line 203 of file plot_ps.c.

References ps_stroke(), and psfile.

00204 { if( inpath ) ps_stroke() ;
00205   fprintf( psfile , "%f setlinewidth\n" , www ) ;
00206 }

void ps_space int   ,
int   ,
int   ,
int   
 

Definition at line 190 of file plot_ps.c.

References atcur, font, inpath, ps_linemod(), ps_prolog(), ps_stroke(), psfile, and scal.

00191 { if( prolog_not_output ) ps_prolog() ;
00192   if (inpath) ps_stroke() ;
00193   fprintf( psfile , "initgraphics\n");
00194   fprintf( psfile , "1 setlinewidth\n");
00195   fprintf( psfile , "66 72 translate\n");
00196   scal=480.0/(ix2-ix1);
00197   fprintf( psfile , "%f %f scale\n",scal,480.0/(iy2-iy1));
00198   if (ix1 || iy1) fprintf( psfile , "%d %d translate\n",-ix1, -iy1);
00199   ps_linemod( "solid" ) ;
00200   atcur=inpath=font=0;
00201 }

void ps_stroke void   
 

Definition at line 66 of file plot_ps.c.

References atcur, inpath, and psfile.

Referenced by ps_arc(), ps_clear(), ps_label(), ps_linemod(), ps_maybe_stroke(), ps_point(), ps_rect(), ps_setrgb(), ps_setwidth(), and ps_space().

00067 { fprintf( psfile , "S\n") ; atcur=inpath=0 ; }

void zzpscl_ void   
 

Definition at line 319 of file plot_ps.c.

References ps_closepl().

00320 { ps_closepl() ; }

void zzpsco_ float *   ,
float *   ,
float *   
 

Definition at line 213 of file plot_ps.c.

References ps_setrgb().

00214 { ps_setrgb( *rrr,*ggg,*bbb ) ; }

void zzpsfr_ void   
 

Definition at line 163 of file plot_ps.c.

References ps_erase().

00164 { ps_erase() ; }

void zzpsli_ int *   ,
int *   ,
int *   ,
int *   
 

Definition at line 82 of file plot_ps.c.

References ps_line().

00083 { ps_line( *ix1,*iy1 , *ix2,*iy2 ) ; }

void zzpsop_ char *    cfl,
int    ncfl
 

Definition at line 239 of file plot_ps.c.

References i, ps_openpl(), ps_space(), and psfile.

00240 { int i ;
00241   char ccc[128] ;
00242 
00243   for( i=0 ; (i < 127) && (i < ncfl) && (cfl[i] != ' ') ; i++ ) {
00244      ccc[i] = cfl[i] ;
00245   }
00246   ccc[i] = '\0' ;
00247   ps_openpl( ccc ) ; if( psfile == NULL ) return ;
00248   ps_space( 0,0,4096,4096 ) ;
00249 }

Variable Documentation

int atcur = 0 [static]
 

Definition at line 53 of file plot_ps.c.

Referenced by ps_arc(), ps_clear(), ps_cont(), ps_label(), ps_move(), ps_point(), ps_space(), and ps_stroke().

int cx [static]
 

Definition at line 51 of file plot_ps.c.

Referenced by ps_cont(), ps_label(), ps_move(), and ps_point().

int cy [static]
 

Definition at line 51 of file plot_ps.c.

Referenced by ps_cont(), ps_label(), ps_move(), and ps_point().

int error [static]
 

Definition at line 49 of file plot_ps.c.

int font [static]
 

Definition at line 48 of file plot_ps.c.

Referenced by ps_label(), ps_prolog(), and ps_space().

int inpath = 0 [static]
 

Definition at line 54 of file plot_ps.c.

Referenced by ps_arc(), ps_clear(), ps_cont(), ps_label(), ps_maybe_stroke(), ps_point(), ps_space(), and ps_stroke().

int npages = 0 [static]
 

Definition at line 50 of file plot_ps.c.

Referenced by ps_clear(), and ps_epilog().

int plot = 0 [static]
 

Definition at line 55 of file plot_ps.c.

Referenced by ps_arc(), ps_circle(), ps_clear(), ps_cont(), ps_label(), and ps_point().

int prolog_not_output = 1 [static]
 

Definition at line 57 of file plot_ps.c.

Referenced by ps_prolog().

char* prolog_text[] [static]
 

Initial value:

 {
    "%%BoundingBox: 36 36 540 690",
    "%%Title: plotps output",
    "%%Creator: plotps 1.0 (RWCox)",
    "%%Pages: (atend)",
    "%%DocumentFonts: Times-Roman",
    "%%EndComments",
    "/S{stroke}bind def",
    "/F{fill}bind def" ,
    "/NP{newpath}bind def",
    "/M{moveto}bind def",
    "/N{lineto}bind def",
    "/A{NP arc S}bind def",
    "/C{0 360 A}bind def",
    "/P{1 0 360 A}bind def",
    "/T{show}bind def",
    "/CL{showpage}bind def",
    "/SF{/Times-Roman findfont exch scalefont setfont}bind def",
    "%%EndProlog",
    NULL
}

Definition at line 264 of file plot_ps.c.

Referenced by ps_prolog().

FILE* psfile = NULL [static]
 

Definition at line 58 of file plot_ps.c.

Referenced by ps_arc(), ps_circle(), ps_clear(), ps_closepl(), ps_cont(), ps_epilog(), ps_label(), ps_linemod(), ps_openpl(), ps_point(), ps_prolog(), ps_rect(), ps_setfont(), ps_setrgb(), ps_setwidth(), ps_space(), ps_stroke(), and zzpsop_().

int psfile_ispipe = 0 [static]
 

Definition at line 59 of file plot_ps.c.

Referenced by ps_closepl(), and ps_openpl().

double scal = 1.0 [static]
 

Definition at line 56 of file plot_ps.c.

Referenced by ps_linemod(), ps_setfont(), and ps_space().

int ttcur = 0 [static]
 

Definition at line 52 of file plot_ps.c.

Referenced by ps_clear(), ps_cont(), ps_label(), ps_move(), and ps_point().

 

Powered by Plone

This site conforms to the following standards: