⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xgprint.c

📁 xgrafix 是PTSG模拟程序中的图形截面库 改版本是最新版本
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "xgrafixint.h"#define  BACK         0#define  FRONT        1#define  ABOVE        0#define  UPPER        1#define  LOWER        2#define  FIRST_QUAD   0#define  SECOND_QUAD  1#define  THIRD_QUAD   2#define  FOURTH_QUAD  3#define Vlength(x,y) (sqrt((x)*(x)+(y)*(y)))/****************************************************************/#define	NPOINTMAX   500void PaintWall(MeshType *theBox, SCALAR c1, SCALAR d1, SCALAR c2, SCALAR d2,	       int wall, int side, FILE *fp){  XPoint          thePoint[4];  if (wall == 0) {    thePoint[0].x = c1 * theBox[0].x + d1;    thePoint[0].y = c2 * theBox[0].y + d2;    thePoint[1].x = c1 * theBox[1].x + d1;    thePoint[1].y = c2 * theBox[1].y + d2;    thePoint[2].x = c1 * theBox[2].x + d1;    thePoint[2].y = c2 * theBox[2].y + d2;    thePoint[3].x = c1 * theBox[3].x + d1;    thePoint[3].y = c2 * theBox[3].y + d2;  } else if (wall == 1) {    thePoint[0].x = c1 * theBox[0].x + d1;    thePoint[0].y = c2 * theBox[0].y + d2;    thePoint[1].x = c1 * theBox[1].x + d1;    thePoint[1].y = c2 * theBox[1].y + d2;    thePoint[2].x = c1 * theBox[6].x + d1;    thePoint[2].y = c2 * theBox[6].y + d2;    thePoint[3].x = c1 * theBox[5].x + d1;    thePoint[3].y = c2 * theBox[5].y + d2;  } else if (wall == 2) {    thePoint[0].x = c1 * theBox[1].x + d1;    thePoint[0].y = c2 * theBox[1].y + d2;    thePoint[1].x = c1 * theBox[2].x + d1;    thePoint[1].y = c2 * theBox[2].y + d2;    thePoint[2].x = c1 * theBox[7].x + d1;    thePoint[2].y = c2 * theBox[7].y + d2;    thePoint[3].x = c1 * theBox[6].x + d1;    thePoint[3].y = c2 * theBox[6].y + d2;  } else if (wall == 3) {    thePoint[0].x = c1 * theBox[2].x + d1;    thePoint[0].y = c2 * theBox[2].y + d2;    thePoint[1].x = c1 * theBox[3].x + d1;    thePoint[1].y = c2 * theBox[3].y + d2;    thePoint[2].x = c1 * theBox[4].x + d1;    thePoint[2].y = c2 * theBox[4].y + d2;    thePoint[3].x = c1 * theBox[7].x + d1;    thePoint[3].y = c2 * theBox[7].y + d2;  } else if (wall == 4) {    thePoint[0].x = c1 * theBox[3].x + d1;    thePoint[0].y = c2 * theBox[3].y + d2;    thePoint[1].x = c1 * theBox[0].x + d1;    thePoint[1].y = c2 * theBox[0].y + d2;    thePoint[2].x = c1 * theBox[5].x + d1;    thePoint[2].y = c2 * theBox[5].y + d2;    thePoint[3].x = c1 * theBox[4].x + d1;    thePoint[3].y = c2 * theBox[4].y + d2;  } else if (wall == 5) {    thePoint[0].x = c1 * theBox[4].x + d1;    thePoint[0].y = c2 * theBox[4].y + d2;    thePoint[1].x = c1 * theBox[5].x + d1;    thePoint[1].y = c2 * theBox[5].y + d2;    thePoint[2].x = c1 * theBox[6].x + d1;    thePoint[2].y = c2 * theBox[6].y + d2;    thePoint[3].x = c1 * theBox[7].x + d1;    thePoint[3].y = c2 * theBox[7].y + d2;  }  if (side == BACK)    fprintf(fp, "%d %d %d %d %d %d %d %d bbwfpoly\n",	    thePoint[0].x, thePoint[0].y, thePoint[1].x, thePoint[1].y,	    thePoint[2].x, thePoint[2].y, thePoint[3].x, thePoint[3].y);  else    fprintf(fp, "%d %d %d %d %d %d %d %d poly\n",	    thePoint[0].x, thePoint[0].y, thePoint[1].x, thePoint[1].y,	    thePoint[2].x, thePoint[2].y, thePoint[3].x, thePoint[3].y);}/****************************************************************/void PostScriptOpenWindow(WindowType theWindow, char *eps_file_name,			  char *plot_title){  DataType        data_Ptr, ptr;  LabelType       label_Ptr;  int             i, j, n;  FILE           *fp;  StructType     *structures;  XPoint         *StructPoints;  int             x1, x2, y1, y2;  double          bx, by, mx, my;  if (!(fp = fopen(eps_file_name, "a"))) {    printf("PostScriptOpenWindow(): File was not opened properly!");    return;  }  x1 = 132;  x2 = 684;  y1 = 108;  y2 = 504;  data_Ptr = theWindow->data;  label_Ptr = theWindow->label;    /************************/  /* Translate and rotate */  fprintf(fp, "%%Translate and rotate\n");  fprintf(fp, "612 0 translate\n");  fprintf(fp, "90 rotate\n");    /************************************************/  /* Limits of the bounding box (PS and physical) */    fprintf(fp, "%%Limits of the bounding box (PS and physical)\n");   fprintf(fp, "/xps1 %d def\n",x1);   fprintf(fp, "/yps1 %d def\n",y1);   fprintf(fp, "/xps2 %d def\n",x2);  fprintf(fp, "/yps2 %d def\n",y2);  fprintf(fp, "/xmin %.6G def\n", label_Ptr->X_Min);   fprintf(fp, "/xmax %.6G def\n", label_Ptr->X_Max);  fprintf(fp, "/xscale %.6G def\n", label_Ptr->X_Scale);  fprintf(fp, "/ymin %.6G def\n", label_Ptr->Y_Min);   fprintf(fp, "/ymax %.6G def\n", label_Ptr->Y_Max);  fprintf(fp, "/yscale %.6G def\n\n", label_Ptr->Y_Scale);    /*****************/  /* Draw boundary */    fprintf(fp, "%%Draw boundary, and Draw X and Y limits\n");   fprintf(fp, "1 setlinewidth\n");  fprintf(fp, "0 setgray\n");  fprintf(fp, "%d %d %d %d rectangle\n\n",x1,y1,x2,y2);  /***********************/  /* Draw X and Y limits */    fprintf(fp, "/Times-Bold findfont 12 scalefont setfont\n");  fprintf(fp, "xps1 yps1 16 sub moveto\n");  fprintf(fp, "xmin str cvs prtstrfromlftup\n");  fprintf(fp, "xps2 yps1 16 sub moveto\n");  fprintf(fp, "xmax str cvs prtstrfromritup\n");  fprintf(fp, "xps1 8 sub yps2 9 sub moveto\n");  fprintf(fp, "ymax str cvs prtstrfromritup\n");  fprintf(fp, "xps1 8 sub yps1 moveto\n");  fprintf(fp, "ymin str cvs prtstrfromritlow\n\n");  /************************/  /* Printing the labels */    fprintf(fp, "%%Printing the labels\n");  fprintf(fp, "90 rotate\n");  fprintf(fp, "/Times-BoldItalic findfont 12 scalefont setfont\n");  fprintf(fp, "yps1 yps2 add 2 div 8 xps1 sub moveto\n");  fprintf(fp, "(%s) prtstrfrommidlow\n", label_Ptr->Y_Label);  fprintf(fp, "-90 rotate\n");  fprintf(fp, "xps1 xps2 add 2 div yps1 16 sub moveto\n");  fprintf(fp, "(%s) prtstrfrommidup\n", label_Ptr->X_Label);  if (strcmp(plot_title, label_Ptr->Y_Label)){ /* print title only if different */    fprintf(fp, "xps1 xps2 add 2 div yps2 8 add moveto\n");    fprintf(fp, "/Times-Bold findfont 14 scalefont setfont\n");    fprintf(fp, "(%s) prtstrfrommidlow\n\n", plot_title);  }    /****************************/  /* Rescale the window first */  RescaleTwoDWindow(theWindow);  /************************************************************/  /* If the plot limits are the same, close the file and quit */    if (label_Ptr->Y_Max == label_Ptr->Y_Min || label_Ptr->X_Max == label_Ptr->X_Min) {    fprintf(fp, "grestore\n");    fprintf(fp, "showpage\n\n");    if (fclose(fp))      printf("PostScriptOpenWindow(): File was not closed properly!");    return;  }    /**********************************/  /* Setting up the clipping region */    fprintf(fp, "%%Setting up the clipping region\n");  fprintf(fp, "/boundary {newpath xps1 yps1 moveto xps2 yps1 lineto\n");  fprintf(fp, " xps2 yps2 lineto xps1 yps2 lineto closepath} def\n");  fprintf(fp, "gsave boundary clip\n\n");    /***************************/  /* Drawing the tick marks  */    fprintf(fp, "%%Drawing the tick marks\n");  fprintf(fp, ".8 setlinewidth\n");    if (Is_X_Log(theWindow)) {    fprintf(fp, "/dtklog {xmax xmin div log cvi} def\n");    fprintf(fp, "1 1 dtklog {doxlogtickmarks} for\n");  } else     fprintf(fp, "doxlintickmarks\n");    if (Is_Y_Log(theWindow)) {    fprintf(fp, "/dtklog {ymax ymin div log cvi} def\n");    fprintf(fp, "1 1 dtklog {doylogtickmarks} for\n\n");  } else    fprintf(fp, "doylintickmarks\n\n");    /************************************/  /* Determining scaling coefficients */    fprintf(fp, "%%Determining scaling coefficients\n");  if (Is_Y_Log(theWindow)) {    fprintf(fp, "/my {yps2 yps1 sub ymax ymin div log div} def\n");     fprintf(fp, "/by {yps1 ymax log mul yps2 ymin log mul sub ymax ymin div log div 0.5 add} def\n");  } else {    fprintf(fp, "/my {yps2 yps1 sub ymax ymin sub div yscale mul} def\n");     fprintf(fp, "/by {yps1 ymax mul yps2 ymin mul sub ymax ymin sub div 0.5 add} def\n");  }  if (Is_X_Log(theWindow)) {    fprintf(fp, "/mx {xps2 xps1 sub xmax xmin div log div} def\n");     fprintf(fp, "/bx {xps1 xmax log mul xps2 xmin log mul sub xmax xmin div log div 0.5 add} def\n\n");  } else {    fprintf(fp, "/mx {xps2 xps1 sub xmax xmin sub div xscale mul} def\n");     fprintf(fp, "/bx {xps1 xmax mul xps2 xmin mul sub xmax xmin sub div 0.5 add} def\n\n");  }    if (Is_X_Log(theWindow) && Is_Y_Log(theWindow)) {    fprintf(fp, "/mv {exch xscale mul log mx mul bx add exch yscale mul log my mul by add moveto} def\n");     fprintf(fp, "/ln {exch xscale mul log mx mul bx add exch yscale mul log my mul by add lineto} def\n\n");   }  else if(Is_X_Log(theWindow) && !Is_Y_Log(theWindow)) {    fprintf(fp, "/mv {exch xscale mul log mx mul bx add exch my mul by add moveto} def\n");     fprintf(fp, "/ln {exch xscale mul log mx mul bx add exch my mul by add lineto} def\n\n");  }  else if(!Is_X_Log(theWindow) && Is_Y_Log(theWindow)) {    fprintf(fp, "/mv {exch mx mul bx add exch yscale mul log my mul by add moveto} def\n");     fprintf(fp, "/ln {exch mx mul bx add exch yscale mul log my mul by add lineto} def\n\n");   }  else {    fprintf(fp, "/mv {exch mx mul bx add exch my mul by add moveto} def\n");     fprintf(fp, "/ln {exch mx mul bx add exch my mul by add lineto} def\n\n");   }  /***************************/  /* Printing the structures */    mx = (x2 - x1) / (label_Ptr->X_Max - label_Ptr->X_Min + DBL_MIN);  bx = (label_Ptr->X_Max * x1 - label_Ptr->X_Min * x2)    / (label_Ptr->X_Max - label_Ptr->X_Min + DBL_MIN) + 0.5;  my = (y2 - y1) / (label_Ptr->Y_Max - label_Ptr->Y_Min + DBL_MIN);  by = (label_Ptr->Y_Max * y1 - label_Ptr->Y_Min * y2)    / (label_Ptr->Y_Max - label_Ptr->Y_Min + DBL_MIN) + 0.5;  structures = theWindow->structures;  while(structures) {    n = structures->numberPoints;        if (!(StructPoints = (XPoint *)malloc(n*sizeof(XPoint))))      putchar(7);    if (Is_X_Log(theWindow)) {      for (i = 0; i < n; i++)	StructPoints[i].x = mx * log10(max(label_Ptr->X_Scale *					   structures->x[i],					   DBL_MIN)) + bx;    } else {      for (i = 0; i < n; i++)	StructPoints[i].x = mx * structures->x[i] + bx;    }	     if (Is_Y_Log(theWindow)) {      for (i = 0; i < n; i++)	StructPoints[i].y = my * log10(max(label_Ptr->Y_Scale * 					  structures->y[i],					  DBL_MIN)) + by;    } else {      for (i = 0; i < n; i++)	StructPoints[i].y = my * structures->y[i] + by;    }    fprintf(fp, "%%Printing the structures\n");    fprintf(fp, "/Times-Bold findfont 4 scalefont setfont\n");    fprintf(fp, "newpath\n");    fprintf(fp, "%d %d moveto\n", StructPoints[0].x, StructPoints[0].y);    for (i = 1; i < n; i++) {      fprintf(fp, "%d %d lineto\n", StructPoints[i].x, StructPoints[i].y);    }    fprintf(fp, "1 setlinewidth\n");    fprintf(fp, "0 setgray\n");    if(structures->fillFlag == FILLED) {      fprintf(fp, "fill\n");    }    fprintf(fp, "1 setlinewidth\nstroke\n\n");    free(StructPoints);    structures = structures->next;  }  /*****************************/  /* Printing the actual plots */    fprintf(fp, "%%Printing the actual plots\n");  fprintf(fp, "1.5 setlinewidth\n");  fprintf(fp, "0 setgray\n");    if (label_Ptr->X_Scale != 0)    mx = label_Ptr->X_Offset/label_Ptr->X_Scale;  else mx = 0;  if (label_Ptr->Y_Scale != 0)    my = label_Ptr->Y_Offset/label_Ptr->Y_Scale;  else my = 0;    for (ptr = data_Ptr, j = 0; ptr != NULL; ptr = ptr->next, j++) {    n = *(ptr->npoints);        if (Is_Scatter(ptr)) {      fprintf(fp, "Dash0\n");      fprintf(fp, "/Times-Bold findfont 6 scalefont setfont\n");      for (i = 1; i < n; i++)        fprintf(fp, "%.6G %.6G mv sp%d\n", CurveX(ptr,i) + mx, CurveY(ptr,i) + my, j);      fprintf(fp, "\n\n");    }    else {      fprintf(fp, "Dash%d\n", j);      fprintf(fp, "newpath %.6G %.6G mv\n", CurveX(ptr,0) + mx, CurveY(ptr,0) + my);      for (i = 1; i < n; i++) {       bx = CurveX(ptr,i)+mx;       by = CurveY(ptr,i)+my;	/* COMMENT try to avoid taking log(x <= 0) */       if (bx > 0 || !Is_Y_Log(theWindow)) {        fprintf(fp, "%.6G %.6G ln\n", bx, by);}       else { 	fprintf(fp, "%.6G %.6G\n", bx, by);}       if (!(i % NPOINTMAX)) {          fprintf(fp, "stroke\n\n");          fprintf(fp, "newpath %.6G %.6G mv\n", bx, by);        }      }      fprintf(fp, "stroke\n\n");    }  }  fprintf(fp, "grestore\n");  fprintf(fp, "showpage\n\n");  if (fclose(fp))    printf("PostScriptOpenWindow(): File was not closed properly!");}/****************************************************************/void PostScript_Vector_Window(WindowType theWindow, char *eps_file_name, 			      char *plot_title){  DataType        data_Ptr;  LabelType       label_Ptr;  int             i, j, m, n, nstart = 0, mstart = 0, nend, mend;  int             x1, x2, y1, y2;  double          dtick, bx, by, mx, my, maxvlen = 0.0, w1, w2, X0, Y0;  MeshType      **Point, **Vector;  FILE           *fp;  StructType     *structures;  XPoint         *StructPoints;  XColor          theRGBColor, theHardwareColor;  if (!(fp = fopen(eps_file_name, "a"))) {    printf("PostScriptOpenWindow(): File was not opened properly!");    return;  }  /*****************************/  data_Ptr = theWindow->data;  label_Ptr = theWindow->label;  x1 = 132; /* modified to accomodate wider labels (JohnV) */  x2 = 684;  y1 = 108;  y2 = 504;  fprintf(fp, "\n612 0 translate\n");  fprintf(fp, "90 rotate\n");  fprintf(fp, "%%Limits of the bounding box (PS and physical)\n");   fprintf(fp, "/xps1 %d def\n",x1);   fprintf(fp, "/yps1 %d def\n",y1);   fprintf(fp, "/xps2 %d def\n",x2);  fprintf(fp, "/yps2 %d def\n",y2);  /************************/  /* Printing the labels */  fprintf(fp, "90 rotate\n");  fprintf(fp, "/Times-BoldItalic findfont 12 scalefont setfont\n");  fprintf(fp, "yps1 yps2 add 2 div -100 moveto\n");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -