/* maple-plot.c * * Receives a mesh structure and an array u[] of z values at mesh points. * Writes a Maple file that can be used to plot the function u[] over the * mesh. * * Rouben Rostamian * April 2006 */ #include #include #include #include "maple-plot.h" void maple_plot(Mesh *mesh, double *u, const char *filename) { FILE *fp; size_t n = mesh->nelems; size_t i, j; time_t now; fp = fopen(filename, "w"); if (fp==NULL) { fprintf(stderr, "Unable to open file %s for writing\n", filename); return; } time(&now); fprintf(fp, "# Maple file created by Math 625 Finite Element Solver\n" "# on %s", ctime(&now)); fprintf(fp, "#\n"); fprintf(fp, "# View this file in Maple by:\n"); fprintf(fp, "# read \"%s\";\n", filename); fprintf(fp, "\n"); fprintf(fp, "with(plottools,polygon):\n"); fprintf(fp, "plots[display]([\n"); for (i=0; ielems[i].n[j]->x, mesh->elems[i].n[j]->y, u[mesh->elems[i].n[j]->nodeno]); fprintf(fp, "NULL]),\n"); } fprintf(fp, "NULL], axes=BOXED);\n"); fclose(fp); }