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

📄 xgprint.c

📁 xgrafix 是PTSG模拟程序中的图形截面库 改版本是最新版本
💻 C
📖 第 1 页 / 共 4 页
字号:
  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);  fprintf(fp, "/Times-Bold findfont 12 scalefont setfont\n");  fprintf(fp, "xps1 yps1 12 sub moveto\n");  fprintf(fp, "(%.3G) prtstrfromlftup\n", label_Ptr->X_Min);  fprintf(fp, "xps2 yps1 12 sub moveto\n");  fprintf(fp, "(%.3G) prtstrfromritup\n", label_Ptr->X_Max);  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", plot_title);  fprintf(fp, "/Times-Bold findfont 12 scalefont setfont\n");  fprintf(fp, "xps1 8 sub yps2 8 sub moveto\n");  fprintf(fp, "(%.3G) prtstrfromritup\n", label_Ptr->Y_Max);  fprintf(fp, "xps1 8 sub yps1 moveto\n");  fprintf(fp, "(%.3G) prtstrfromritlow\n", label_Ptr->Y_Min);  if (label_Ptr->Y_Max == label_Ptr->Y_Min || label_Ptr->X_Max == label_Ptr->X_Min)    return;  /*****************************/  /* Printing the actual plots */  m = *(data_Ptr->mpoints);  n = *(data_Ptr->npoints);  RescaleVectorDWindow(theWindow,&mstart,&mend,&nstart,&nend);  /****************************/  /* find longest vector in the system */  maxvlen = Vlength(VectorZ(data_Ptr,mstart,nstart), 		    VectorW(data_Ptr,mstart,nstart));  for (i = mstart; i <= mend; i++)    for (j = nstart; j <= nend; j++)      maxvlen = max(maxvlen, Vlength(VectorZ(data_Ptr,i,j), 				     VectorW(data_Ptr,i,j)));  mx = (x2 - x1) / (label_Ptr->X_Max - label_Ptr->X_Min + DBL_MIN) * label_Ptr->X_Scale;  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) * label_Ptr->Y_Scale;  by = (label_Ptr->Y_Max * y1 - label_Ptr->Y_Min * y2)    / (label_Ptr->Y_Max - label_Ptr->Y_Min + DBL_MIN) + 0.5;  if (maxvlen != 0.0) {    w1 = (x2 - x1) / (mend - mstart + 1) / maxvlen;    w2 = (y2 - y1) / (nend - nstart + 1) / maxvlen;  } else {    w1 = 0.0;    w2 = 0.0;  }  /* malloc space for the arrays */  if (!(Point = (MeshType **) malloc(m * sizeof(MeshType *))))    printf("PostScript_Vector_Window: malloc failed");  for (i = 0; i < m; i++)    if (!(Point[i] = (MeshType *) malloc(n * sizeof(MeshType))))      printf("PostScript_Vector_Window: malloc failed");  if (!(Vector = (MeshType **) malloc(m * sizeof(MeshType *))))    printf("PostScript_Vector_Window: malloc failed");  for (i = 0; i < m; i++)    if (!(Vector[i] = (MeshType *) malloc(n * sizeof(MeshType))))      printf("PostScript_Vector_Window: malloc failed");  /* calculate what the vectors are */  for (i = mstart; i <= mend; i++)    for (j = nstart; j <= nend; j++) {      Point[i][j].x = X0 = mx * VectorX(data_Ptr,i) + bx;      Point[i][j].y = Y0 = my * VectorY(data_Ptr,j) + by;      Vector[i][j].x = X0 + VectorW(data_Ptr,i,j) * w1;      Vector[i][j].y = Y0 + VectorZ(data_Ptr,i,j) * w2;    }  /* Set up a clipping region */  fprintf(fp, ".25 setlinewidth\n\n");/*  fprintf(fp, "stroke grestore\n\n"); */  fprintf(fp,"/boundary {newpath %d %d moveto %d %d lineto\n", x1, y1, x2, y1);  fprintf(fp, " %d %d lineto %d %d lineto closepath} def\n", x2, y2, x1, y2);  fprintf(fp, "gsave boundary clip\n");  /* calculate what the structures are and draw them */  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");    if(structures->fillFlag == FILLED) {      fprintf(fp, "%f %f %f setrgbcolor\n", 	      RedColor[structures->fillColor],	      GreenColor[structures->fillColor],	      BlueColor[structures->fillColor]);      fprintf(fp, "fill\n");    }    XLookupColor(theDisplay, theColormap, theColorNames[structures->lineColor],		 &theRGBColor, &theHardwareColor);    fprintf(fp, "%f %f %f setrgbcolor\n", RedColor[structures->lineColor],	    GreenColor[structures->lineColor],	    BlueColor[structures->lineColor]);    fprintf(fp, "1 setlinewidth\nstroke\n\n");    free(StructPoints);    structures = structures->next;  }  fprintf(fp, ".25 setlinewidth\n\n");  /* and actually plot some vectors now */  fprintf(fp, "/Times-Bold findfont 4 scalefont setfont\n");  fprintf(fp, "0 setgray\n");  fprintf(fp, "newpath\n");  for (i = mstart; i <= mend; i++)    for (j = nstart; j <= nend; j++) {      fprintf(fp, "%1.0f %1.0f %1.0f %1.0f arw\n", Point[i][j].x,Point[i][j].y,	      Vector[i][j].x, Vector[i][j].y);    }  fprintf(fp, "stroke\n\n");  /*********************/  /* Draw the boundary */  fprintf(fp, "1 setlinewidth\n");  fprintf(fp, "%d %d %d %d rectangle\n", x1, y1, x2, y2);  /***************************/  /* Drawing the tick marks  */  fprintf(fp, "gsave 0 setgray .8 setlinewidth\n");  if ((label_Ptr->Y_Min < 0.0 && 0.0 < label_Ptr->Y_Max) ||      (label_Ptr->Y_Max < 0.0 && 0.0 < label_Ptr->Y_Min)) {    dtick = (y2 - y1) / (label_Ptr->Y_Max - label_Ptr->Y_Min);    fprintf(fp, "%d %g moveto\n", x1, y2 - dtick * (label_Ptr->Y_Max));    fprintf(fp, "%d %g lineto\n", x1 + 4, y2 - dtick * (label_Ptr->Y_Max));    fprintf(fp, "%d %g moveto\n", x2 - 4, y2 - dtick * (label_Ptr->Y_Max));    fprintf(fp, "%d %g lineto\n", x2, y2 - dtick * (label_Ptr->Y_Max));  }  if ((label_Ptr->X_Min < 0.0 && 0.0 < label_Ptr->X_Max) ||      (label_Ptr->X_Max < 0.0 && 0.0 < label_Ptr->X_Min)) {    dtick = (x2 - x1) / (label_Ptr->X_Max - label_Ptr->X_Min);    fprintf(fp, "%g %d moveto\n", x2 - dtick * (label_Ptr->X_Max), y2);    fprintf(fp, "%g %d lineto\n", x2 - dtick * (label_Ptr->X_Max), y2 - 4);    fprintf(fp, "%g %d moveto\n", x2 - dtick * (label_Ptr->X_Max), y1);    fprintf(fp, "%g %d lineto\n", x2 - dtick * (label_Ptr->X_Max), y1 + 4);  }  /* and never, never forget to free up your memory */  for (i = 0; i < m; i++) {    free(Point[i]);    free(Vector[i]);  }  free(Point);  free(Vector);  fprintf(fp, "grestore\n");  fprintf(fp, "showpage\n\n");  if (fclose(fp))    printf("PostScriptOpenWindow(): File was not closed properly!");}/****************************************************************/void PSHeader(char *filename){  FILE *fp;  if((fp = fopen(filename,"w"))==NULL) {      printf("\nError: Postscript file not opened properly.\n");      return;  }  /*****************************/  /* Loading the dictionary... */  fprintf(fp, "%%!PS-Adobe-3.0 EPSF-3.0\n");  fprintf(fp, "%%%%BoundingBox: 72 72 540 730\n");  fprintf(fp, "%%%%Creator: XGrafix %s Copyright 1991-2002 The Regents of the University of California\n",			 xgversion);  fprintf(fp, "%%%%Title: %s\n", filename);  fprintf(fp, "%%%%Pages: 1 1\n");  fprintf(fp, "%%%%EndComments-----\n");  fprintf(fp, "%%%%Begin XGrafix PS Macros\n\n");  fprintf(fp, "/prtstrfrommidlow {dup stringwidth pop\n");  fprintf(fp, " 2 div currentpoint pop exch sub currentpoint\n");  fprintf(fp, " exch pop moveto show} def\n\n");  fprintf(fp, "/prtstrfrommidup {dup stringwidth currentpoint\n");  fprintf(fp, " 3 -1 roll sub exch 3 -1 roll 2 div sub exch\n");  fprintf(fp, " moveto show} def\n\n");  fprintf(fp, "/prtstrfromritlow {dup stringwidth pop\n");  fprintf(fp, " currentpoint pop exch sub currentpoint\n");  fprintf(fp, " exch pop moveto show} def\n\n");  fprintf(fp, "/prtstrfromritup {dup stringwidth currentpoint\n");  fprintf(fp, " 3 -1 roll sub exch 3 -1 roll sub exch\n");  fprintf(fp, " moveto show} def\n\n");  fprintf(fp, "/prtstrfromlftup {dup stringwidth exch pop\n");  fprintf(fp, " currentpoint 3 -1 roll sub moveto show} def\n\n");  fprintf(fp, "/rectangle {4 -1 roll 4 -1 roll\n");  fprintf(fp, " dup 5 1 roll exch dup 6 1 roll exch\n");  fprintf(fp, " moveto 3 1 roll dup 5 1 roll exch lineto dup\n");  fprintf(fp, " 4 -1 roll exch lineto lineto closepath stroke} def\n\n");  fprintf(fp, "/poly {newpath moveto lineto\n");  fprintf(fp, " lineto lineto closepath stroke} def\n\n");  fprintf(fp, "/bbwfpoly {newpath moveto lineto\n");  fprintf(fp, " lineto lineto closepath gsave 1 setgray\n");  fprintf(fp, " fill grestore 0 setgray stroke} def\n\n");  fprintf(fp, "/bbcfpoly {newpath moveto lineto\n");  fprintf(fp, " lineto lineto closepath gsave fill\n");  fprintf(fp, " grestore 0 setgray stroke} def\n\n");  fprintf(fp, "/nbcfpoly {newpath moveto lineto\n");  fprintf(fp, " lineto lineto closepath fill} def\n\n");  fprintf(fp, "/cbwfpoly {newpath moveto lineto\n");  fprintf(fp, " lineto lineto closepath gsave 1\n");  fprintf(fp, " setgray fill grestore stroke} def\n\n");  fprintf(fp, "/sp0 {(.) prtstrfrommidlow} def\n");  fprintf(fp, "/sp1 {(o) prtstrfrommidlow} def\n");  fprintf(fp, "/sp2 {(*) prtstrfrommidlow} def\n");  fprintf(fp, "/sp3 {(x) prtstrfrommidlow} def\n");  fprintf(fp, "/sp4 {(+) prtstrfrommidlow} def\n");  fprintf(fp, "/sp5 {(#) prtstrfrommidlow} def\n");  fprintf(fp, "/sp6 {(@) prtstrfrommidlow} def\n\n");    fprintf(fp, "%%Dash line type definitions\n");   fprintf(fp, "/Dash0 {[] 0 setdash} def\n");  fprintf(fp, "/Dash1 {[2 2] 1 setdash} def\n");  fprintf(fp, "/Dash2 {[5 5] 2 setdash} def\n");  fprintf(fp, "/Dash3 {[5 2 2 2] 2 setdash} def\n");  fprintf(fp, "/Dash4 {[10 5] 5 setdash} def\n");  fprintf(fp, "/Dash5 {[5 2 2 2 2 2] 2 setdash} def\n\n");  fprintf(fp, "%%Define how to draw an arrow\n");  fprintf(fp, "/arw\n");  fprintf(fp, "{\ngsave\n");  fprintf(fp, "/y1 exch def\n");  fprintf(fp, "/x1 exch def\n");  fprintf(fp, "/y0 exch def\n");  fprintf(fp, "/x0 exch def\n");  fprintf(fp, "/dx x1 x0 sub def\n");  fprintf(fp, "/dy y1 y0 sub def\n");  fprintf(fp, "0 dx ne 0 dy ne or {\n");  fprintf(fp, "/angle dy dx atan def\n");  fprintf(fp, "/length dx dx mul dy dy mul add sqrt .35 mul def\n");  fprintf(fp, "x0 y0 moveto\n");  fprintf(fp, "x1 y1 lineto\n");  fprintf(fp, "stroke\n");  fprintf(fp, "x1 y1 translate\n");  fprintf(fp, "angle 70 add rotate\n");  fprintf(fp, "newpath\n");  fprintf(fp, "0 0 moveto\n");  fprintf(fp, "0 length rmoveto\n");  fprintf(fp, "0 length neg rlineto\n");  fprintf(fp, "40 rotate\n");  fprintf(fp, "0 length rlineto\n");  fprintf(fp, "closepath fill\n");  fprintf(fp, "stroke\n");  fprintf(fp, "} {x0 y0 moveto sp0} ifelse grestore\n");  fprintf(fp, "} def\n\n");    fprintf(fp, "%%Scratch string space\n");   fprintf(fp, "/str 20 string def\n\n");     fprintf(fp, "%%Define macro for linear tick marks alog x\n");  fprintf(fp, "/doxlintickmarks {\n");  fprintf(fp, " xps2 xps2 xps1 sub xmax xmin sub div xmax mul sub yps1 moveto\n");  fprintf(fp, " xps2 xps2 xps1 sub xmax xmin sub div xmax mul sub yps1 4 add lineto\n");  fprintf(fp, " xps2 xps2 xps1 sub xmax xmin sub div xmax mul sub yps2 4 sub moveto\n");  fprintf(fp, " xps2 xps2 xps1 sub xmax xmin sub div xmax mul sub yps2 lineto\n");  fprintf(fp, " stroke} def\n\n");  fprintf(fp, "%%Define macro for log tick marks alog x\n");  fprintf(fp, "/doxlogtickmarks {\n");  fprintf(fp, " dup xps2 xps1 sub mul dtklog div xps1 add yps1 moveto\n");  fprintf(fp, " dup xps2 xps1 sub mul dtklog div xps1 add yps1 4 add lineto\n");  fprintf(fp, " dup xps2 xps1 sub mul dtklog div xps1 add yps2 4 sub moveto\n");  fprintf(fp, " xps2 xps1 sub mul dtklog div xps1 add yps2 lineto\n");   fprintf(fp, " stroke} def\n\n");  fprintf(fp, "%%Define macro for linear tick marks alog y\n");  fprintf(fp, "/doylintickmarks {\n");  fprintf(fp, " xps1 yps2 yps2 yps1 sub ymax ymin sub div ymax mul sub moveto\n");  fprintf(fp, " xps1 4 add yps2 yps2 yps1 sub ymax ymin sub div ymax mul sub lineto\n");  fprintf(fp, " xps2 4 sub yps2 yps2 yps1 sub ymax ymin sub div ymax mul sub moveto\n");  fprintf(fp, " xps2 yps2 yps2 yps1 sub ymax ymin sub div ymax mul sub lineto\n");  fprintf(fp, " stroke} def\n\n");  fprintf(fp, "%%Define macro for log tick marks alog y\n");  fprintf(fp, "/doylogtickmarks {\n");  fprintf(fp, " dup yps2 yps1 sub mul dtklog div yps1 add xps1 exch moveto\n");  fprintf(fp, " dup yps2 yps1 sub mul dtklog div yps1 add xps1 4 add exch lineto\n");  fprintf(fp, " dup yps2 yps1 sub mul dtklog div yps1 add xps2 4 sub exch moveto\n");  fprintf(fp, " yps2 yps1 sub mul dtklog div yps1 add xps2 exch lineto\n");   fprintf(fp, " stroke} def\n\n");  fprintf(fp, "%%Print the XGrafix logo\n");  fprintf(fp, "90 rotate\n");  fprintf(fp, "/Times-BoldItalic findfont 6 scalefont setfont\n");  fprintf(fp, "770 -590 moveto (XGrafix %s) prtstrfromritlow\n", xgversion);  fprintf(fp, "-90 rotate\n\n");    fprintf(fp, "%%%%End XGrafix PS Macros\n\n");  fclose(fp);}/****************************************************************/void PostScript_ThreeD_Window(WindowType theWindow, char *eps_file_name,			      char *plot_title){  DataType        data_Ptr;  LabelType       label_Ptr;  MeshType      **theMeshPoint, theBox[8];  StringType      theString[8];  double           n1, n2, n3, v1, v2, v3;  double           u1, u2, u3, up1, up2, up3;  double           a1, a2, a3, b1, b2, b3;  double           xprojmax, xprojmin;  double           yprojmax, yprojmin;  double           mag, c1, c2, d1, d2;  double           xtemp, ytemp, ztemp;  int             m, mstart, mend, n, nend, nstart, colornumber;  int             i, j, x1, y1, x2, y2;  int             phi_flag, theta_flag;  int             xstart, xend, xstep, ystart, yend, ystep;  FILE           *fp;  data_Ptr = theWindow->data;  label_Ptr = theWindow->label;  if (!Is_Scatter(data_Ptr))    m = *(data_Ptr->mpoints);  n = *(data_Ptr->npoints);  /****************************/  /* Rescale the window first */  RescaleThreeDWindow(theWindow,&mstart,&mend,&nstart,&nend);    /******************************************************/  /* Determining the octant where the viewer is located */  theWindow->theta = fmod(180. + theWindow->theta, 180.);  theWindow->phi = fmod(360. + theWindow->phi, 360.);  if (0 <= theWindow->phi && theWindow->phi <= 90)    phi_flag = FIRST_QUAD;  else if (90 < theWindow->phi && theWindow->phi <= 180)    phi_flag = SECOND_QUAD;  else if (180 < theWindow->phi && theWindow->phi <= 270)    phi_flag = THIRD_QUAD;  else if (270 < theWindow->phi && theWindow->phi <= 360)    phi_flag = FOURTH_QUAD;  if (theWindow->theta == 0.0)    theta_flag = ABOVE;  else if (0 < theWindow->theta && theWindow->theta <= 90)    theta_flag = UPPER;  else    theta_flag = LOWER;  /************************************/

⌨️ 快捷键说明

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