/************************************************************ Generate postscript file to represent the microstructures. Author: M. P. Gururajan Copyright (c) 2003 Computational Materials Science Laboratory, Department of Metallurgy, Indian Institute of Science, Bangalore 560 012. INDIA. See the README file for further details. ************************************************************/ #include #include void generate_snapshot(char *name, int n_x, int n_y, int N, double *c) { FILE *fp; int i, j; int temp; /* open the ps file to be written */ if ((fp = fopen(name, "w")) == NULL) { printf("Unable to open the ps file to write. Exiting\n"); exit(0); } /* The preamble to the ps file */ fprintf(fp, "%%!PS-Adobe-2.0 EPSF-2.0\n"); fprintf(fp, "%%%%Generated by C-program output\n"); fprintf(fp, "%%%%Creator: Guru (inherited from Saswata)\n"); fprintf(fp, "%%%%Title: Microstructure\n"); fprintf(fp, "%%%%BoundingBox: 0 0 256 256\n"); fprintf(fp, "0 0 translate\n"); fprintf(fp, "0 rotate\n"); fprintf(fp, "256 256 scale\n"); fprintf(fp, "/picstr %d string def\n", N); fprintf(fp, "%d %d 8 [%d 0 0 -%d 0 %d]\n", N, N, N, N, N); fprintf(fp, "{currentfile picstr readhexstring pop} image\n"); /* write the ps file proper */ for (i = 0; i < n_x; ++i) { for (j = 0; j < n_y; ++j) { temp = (int) (255.0 * c[j + n_y * i]); if (temp < 0) temp = 0; else if (temp > 255) temp = 255; fprintf(fp, "%02x", temp); } fprintf(fp, "\n"); } fprintf(fp, "grestore\n"); fprintf(fp, "showpage\n"); fprintf(fp, "%%%%EOF\n"); (void) fclose(fp); }