#include #include #include #define GREYSCALE -1 #define REDBLUE 0 #define ROYGBIV 1 #define PERIODIC 2 typedef struct { float xmin,xmax,ymin,ymax; float xscale,yscale,xoff,yoff; float tx,ty,angle,slant; /* text attributes */ float linecol,letx,lety; int linewid; } DEVSCALE; FILE *my_plot_file; DEVSCALE ps_scale; array_print(filename,xtitle,ytitle,bottom,nacross,ndown,col0,row0,nskip, ncskip, maxrow,maxcol,data,zmin,zmax,tlo,thi,type) char *xtitle,*ytitle,*bottom,*filename; int nacross,ndown; int col0,row0,nskip,ncskip,maxrow,maxcol; int type; float **data; double zmin,zmax,tlo,thi; { float xx,yy; xx=(float)ndown; yy=(float)(nacross/ncskip); my_plot_file=fopen(filename,"w"); if(my_plot_file==NULL){ return -1; } ps_begin(0.0,0.0,xx,yy,10.,7.); ps_replot(data,col0,row0,nskip,ncskip,maxrow,maxcol,nacross,ndown,zmin,zmax,type); ps_boxit(tlo,thi,0.0,yy,zmin,zmax,xtitle,ytitle,bottom,type); ps_close(); return 0; } ps_replot(z,col0,row0,nskip,ncskip,maxrow,maxcol,nacross,ndown,zmin,zmax,type) float **z; double zmin,zmax; int ndown,nacross,maxcol,maxrow,row0,col0,nskip,ncskip,type; { int i,j,ib,jb; float scale=1./(zmax-zmin); float fill,x,y; float dx=(ps_scale.xmax-ps_scale.xmin); float dy=(ps_scale.ymax-ps_scale.ymin); float xlo=.15*dx,ylo=.05*dy,xhi=.95*dx,yhi=.85*dy; float delx,dely; delx=.8*dx/(float)ndown; dely=.8*dy/(float)(nacross/ncskip); for(i=0;imaxcol)return; for(j=0;j=0){ fill=(z[ib][jb]-zmin)/(zmax-zmin); if(fill<0.0)fill=0.0; if(fill>1.0)fill=1.0; fill=1-fill; x=xhi-delx-j*delx; y=yhi-dely-i*dely; if(type==GREYSCALE) ps_bar(x,y,delx,dely,fill,0); else ps_rgb_bar(x,y,delx,dely,fill,0,type); } } } } ps_begin(xlo,ylo,xhi,yhi,sx,sy) double xlo,ylo,xhi,yhi; float sx,sy; { float x0,y0,x1,y1; ps_scale.xmin=xlo; ps_scale.ymin=ylo; ps_scale.ymax=yhi; ps_scale.xmax=xhi; ps_scale.xoff=300; ps_scale.yoff=300; ps_scale.angle=-90.; ps_scale.xscale=1800.*sx*.2/(xhi-xlo); ps_scale.yscale=1800.*sy*.2/(yhi-ylo); ps_set_text(-90.,0.0,18.0,18.0); ps_scale.letx=ps_scale.tx/ps_scale.xscale; ps_scale.lety=ps_scale.ty/ps_scale.yscale; ps_convert(xlo,ylo,&x0,&y0); ps_convert(xhi,yhi,&x1,&y1); fprintf(my_plot_file,"%s\n","%!"); fprintf(my_plot_file,"%s %g %g %g %g\n", "%%BoundingBox: ", .2*x0,.2*y0,.2*x1,.2*y1); fprintf(my_plot_file,"20 dict begin\n"); fprintf(my_plot_file,"gsave\n"); fprintf(my_plot_file,"/m {moveto} def\n"); fprintf(my_plot_file,"/l {lineto} def\n"); fprintf(my_plot_file,"/Cshow { currentpoint stroke moveto\n"); fprintf(my_plot_file," dup stringwidth pop -2 div vshift rmoveto show } def\n"); fprintf(my_plot_file,"/Lshow { currentpoint stroke moveto\n"); fprintf(my_plot_file," 0 vshift rmoveto show } def\n"); fprintf(my_plot_file,"/Rshow { currentpoint stroke moveto\n"); fprintf(my_plot_file," dup stringwidth pop neg vshift rmoveto show } def\n"); fprintf(my_plot_file,"/C {setrgbcolor} def\n"); fprintf(my_plot_file,"/G {setgray} def\n"); fprintf(my_plot_file,"/S {stroke} def\n"); fprintf(my_plot_file,"/HSB {sethsbcolor} def\n"); fprintf(my_plot_file,"/RGB {setrgbcolor} def\n"); fprintf(my_plot_file,"/FS {fill stroke} def\n"); fprintf(my_plot_file,"630 -20 translate\n"); fprintf(my_plot_file,"90 rotate\n"); fprintf(my_plot_file,".2 .2 scale\n"); fprintf(my_plot_file,"/basefont /Times-Roman findfont def\n"); ps_setline(0.0,4); } ps_convert(x,y,xs,ys) float x,y, *xs,*ys; { *xs=(x-ps_scale.xmin)*ps_scale.xscale+ps_scale.xoff; *ys=(y-ps_scale.ymin)*ps_scale.yscale+ps_scale.yoff; } ps_col_scale(y0,x0,dy,dx,n,zlo,zhi,type,mx) double y0,x0,dy,dx,zlo,zhi; float mx; int n,type; { int i; char s[100]; float dz=1./(float)(n-1); float dely=ps_scale.ymax-ps_scale.ymin; for(i=0;i1.0)fill=1.0; switch(rgb) { case 0: fill=1.-fill; b=(float)sqrt((double)(1.0-fill*fill)); r=(float)sqrt((double)(fill*(2.0-fill))); break; case 1: if(fill>.4999)r=0.0; else r=(float)sqrt((float)(1.-4*fill*fill)); g=(float)2*sqrt((double)fill*(1.-fill)); if(fill<.5001)b=0.0; else b=(float)sqrt((float)(4*(fill-.5)*(1.5-fill))); break; } fprintf(my_plot_file,"%f %f %f RGB\n",r,g,b); ps_convert(x,y,&x1,&y1); ps_convert(x+wid,y+len,&x2,&y2); /* fprintf(my_plot_file,"%f %f m \n %f %f l \n %f %f l \n %f %f l \n FS\n", x1,y1,x2,y1,x2,y2,x1,y2); */ fprintf(my_plot_file,"%d %d m \n %d %d l \n %d %d l \n %d %d l \n FS\n", (int)x1,(int)y1,(int)x2,(int)y1,(int)x2,(int)y2,(int)x1,(int)y2); if(flag){ fprintf(my_plot_file,"0 G\n"); ps_rect(x,y,wid,len); } } ps_hsb_bar(x,y,wid,len,fill,flag) float x,y,wid,len,fill; int flag; { float x1,y1,x2,y2; fprintf(my_plot_file,"%f 1.0 1.0 HSB\n",fill); ps_convert(x,y,&x1,&y1); ps_convert(x+wid,y+len,&x2,&y2); /* fprintf(my_plot_file,"%f %f m \n %f %f l \n %f %f l \n %f %f l \n FS\n", x1,y1,x2,y1,x2,y2,x1,y2); */ fprintf(my_plot_file,"%d %d m \n %d %d l \n %d %d l \n %d %d l \n FS\n", (int)x1,(int)y1,(int)x2,(int)y1,(int)x2,(int)y2,(int)x1,(int)y2); if(flag){ fprintf(my_plot_file,"0 G\n"); ps_rect(x,y,wid,len); } }