| | 10 | #include <stdlib.h> |
| | 11 | #include <math.h> |
| | 12 | |
| | 13 | |
| | 14 | /*++++++++++++++++++++++++++++++++++++++ |
| | 15 | This program starts Geomview, displays a single ternary phase diagram, waits |
| | 16 | for user interaction, and closes. Its only argument right now is an optional |
| | 17 | "resolution" of the discretization: "ternary 30" will use a 30x30/2 triangle |
| | 18 | array to display free energy and calculate the phase diagram. |
| | 19 | |
| | 20 | int main It returns zero or an error code. |
| | 21 | |
| | 22 | int argc Number of arguments. |
| | 23 | |
| | 24 | char *argv[] Arguments: right now only the "resolution" of the |
| | 25 | discretization. |
| | 26 | ++++++++++++++++++++++++++++++++++++++*/ |
| 16 | | int i, j, loop_max=50; |
| 17 | | coordT Gmin=REALmax, Gmax=-REALmax; |
| 18 | | |
| 19 | | pipe (gv_pipe); /* from geomview stdout */ |
| 20 | | pipe (to_gv_pipe); /* to geomview stdin */ |
| 21 | | gv_pid = fork (); |
| 22 | | |
| 23 | | if(gv_pid==0) /* child */ |
| 24 | | { |
| 25 | | close (0); |
| 26 | | dup (to_gv_pipe[0]); |
| 27 | | close (to_gv_pipe[0]); |
| 28 | | close (to_gv_pipe[1]); |
| 29 | | close (1); |
| 30 | | dup (gv_pipe[1]); |
| 31 | | close (gv_pipe[0]); |
| 32 | | close (gv_pipe[1]); |
| 33 | | /* signal(SIGINT,SIG_IGN); */ |
| 34 | | execlp (GEOMVIEW,GEOMVIEW,"-c","(interest (pick world))","-",NULL); |
| 35 | | perror (GEOMVIEW); /* only error gets here */ |
| 36 | | } |
| 37 | | |
| 38 | | /* Program execution resumes here */ |
| 39 | | close (gv_pipe[1]); |
| 40 | | close (to_gv_pipe[0]); |
| 41 | | pfd = fdopen (to_gv_pipe[1], "w"); /* hooked to stdin of geomview */ |
| 42 | | fprintf (pfd, "(echo (geomview-version) \"\n\")\n"); |
| 43 | | fflush (pfd); |
| 44 | | read (gv_pipe[0], gv_version, sizeof (gv_version)); |
| 45 | | printf("Geomview version: %s\n", gv_version); |
| | 33 | coordT Gmin, Gmax, *points; |
| 50 | | fprintf (pfd, "(geometry \"Ternary Phase Diagram\" { : tpd })"); |
| 51 | | fprintf (pfd, "(read geometry { define tpd \n"); |
| 52 | | fprintf (pfd, "appearance {}\nCOFF\n"); |
| 53 | | fprintf (pfd, "%d %d 0\n", (loop_max+1)*(loop_max+2)/2, loop_max*loop_max); |
| | 38 | /* Allocate arrays for point coordinates and colors and triangle vertices */ |
| | 39 | if (!(points = calloc ((loop_max+1)*(loop_max+2)/2 * 7, sizeof (coordT)))) |
| | 40 | { printf ("Cannot allocate point coordinate array\n"); exit (1); } |
| 55 | | /* Calculate upper and lower free energy bounds for coloring */ |
| | 42 | if (!(verts = calloc (loop_max*loop_max * 3, sizeof (int)))) |
| | 43 | { printf ("Cannot allocate triangle vertex array\n"); exit (1); } |
| | 44 | |
| | 45 | /* Start Geomview process */ |
| | 46 | if (i=GeomviewBegin (&pfd, gv_version)) |
| | 47 | { printf ("main: Error %d in Geomview Begin\n", i); exit (i); } |
| | 48 | printf("Geomview version: %s\n", gv_version); |
| | 49 | |
| | 50 | #define ROWSTART(row) ((row)*(loop_max+1) - ((row)*((row)-1))/2) |
| | 51 | |
| | 52 | /* Calculate free energies, including upper and lower bounds for coloring */ |
| | 53 | Gmin = Gmax = free_energy (0., 0., 0.); |
| 59 | | coordT C2=(coordT)i/loop_max, C3=(coordT)j/loop_max, G; |
| 60 | | G = free_energy (C2, C3, 0.); |
| 61 | | Gmin = (G<Gmin) ? G : Gmin; |
| 62 | | Gmax = (G>Gmax) ? G : Gmax; |
| | 57 | index = 7 * (ROWSTART (i) + j); |
| | 58 | |
| | 59 | points [index] = (coordT)i/loop_max; |
| | 60 | points [index+1] = (coordT)j/loop_max; |
| | 61 | points [index+2] = free_energy (points[index], points[index+1], 0.); |
| | 62 | Gmin = (points [index+2]<Gmin) ? points [index+2] : Gmin; |
| | 63 | Gmax = (points [index+2]>Gmax) ? points [index+2] : Gmax; |
| 92 | | fprintf (pfd, "3 %d %d %d\n", |
| 93 | | ROWSTART(i)+j, ROWSTART(i)+j+1, ROWSTART(i+1)+j); |
| 94 | | fprintf (pfd, "3 %d %d %d\n", |
| 95 | | ROWSTART(i)+j+1, ROWSTART(i+1)+j, ROWSTART(i+1)+j+1); |
| | 91 | verts [3*index] = ROWSTART(i)+j; |
| | 92 | verts [3*index+1] = ROWSTART(i)+j+1; |
| | 93 | verts [3*index+2] = ROWSTART(i+1)+j; |
| | 94 | index++; |
| | 95 | |
| | 96 | verts [3*index] = ROWSTART(i)+j+1; |
| | 97 | verts [3*index+1] = ROWSTART(i+1)+j+1; |
| | 98 | verts [3*index+2] = ROWSTART(i+1)+j; |
| | 99 | index++; |
| 100 | | fprintf (pfd, "3 %d %d %d\n", |
| 101 | | ROWSTART(i), ROWSTART(i)+1, ROWSTART(i+1)); |
| 102 | | fprintf (pfd, "})\n"); |
| 103 | | fflush (pfd); |
| | 106 | verts [3*index] = ROWSTART(i); |
| | 107 | verts [3*index+1] = ROWSTART(i)+1; |
| | 108 | verts [3*index+2] = ROWSTART(i+1); |
| | 109 | |
| | 110 | /* Send points and triangle vertex data to Geomview */ |
| | 111 | if (i=GeomviewDisplayTriangleCOFF (pfd, (loop_max+1)*(loop_max+2)/2, points, |
| | 112 | loop_max*loop_max, verts)) |
| | 113 | { printf ("main: Error %d in Geomview Display\n", i); exit (i); } |