Actual source code: ex3.c
2: static char help[] = "Plots a simple line graph.\n";
4: #if defined(PETSC_APPLE_FRAMEWORK)
5: #import <PETSc/petscsys.h>
6: #import <PETSc/petscdraw.h>
7: #else
9: #include <petscsys.h>
10: #include <petscdraw.h>
11: #endif
13: int main(int argc, char **argv)
14: {
15: PetscDraw draw;
16: PetscDrawLG lg;
17: PetscDrawAxis axis;
18: PetscInt n = 15, i, x = 0, y = 0, width = 400, height = 300, nports = 1;
19: PetscBool useports, flg;
20: const char *xlabel, *ylabel, *toplabel, *legend;
21: PetscReal xd, yd;
22: PetscDrawViewPorts *ports = NULL;
24: toplabel = "Top Label";
25: xlabel = "X-axis Label";
26: ylabel = "Y-axis Label";
27: legend = "Legend";
30: PetscInitialize(&argc, &argv, NULL, help);
31: PetscOptionsGetInt(NULL, NULL, "-x", &x, NULL);
32: PetscOptionsGetInt(NULL, NULL, "-y", &y, NULL);
33: PetscOptionsGetInt(NULL, NULL, "-width", &width, NULL);
34: PetscOptionsGetInt(NULL, NULL, "-height", &height, NULL);
35: PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL);
36: PetscOptionsGetInt(NULL, NULL, "-nports", &nports, &useports);
37: PetscOptionsHasName(NULL, NULL, "-nolegend", &flg);
38: if (flg) legend = NULL;
39: PetscOptionsHasName(NULL, NULL, "-notoplabel", &flg);
40: if (flg) toplabel = NULL;
41: PetscOptionsHasName(NULL, NULL, "-noxlabel", &flg);
42: if (flg) xlabel = NULL;
43: PetscOptionsHasName(NULL, NULL, "-noylabel", &flg);
44: if (flg) ylabel = NULL;
45: PetscOptionsHasName(NULL, NULL, "-nolabels", &flg);
46: if (flg) {
47: toplabel = NULL;
48: xlabel = NULL;
49: ylabel = NULL;
50: }
52: PetscDrawCreate(PETSC_COMM_WORLD, 0, "Title", x, y, width, height, &draw);
53: PetscDrawSetFromOptions(draw);
54: if (useports) {
55: PetscDrawViewPortsCreate(draw, nports, &ports);
56: PetscDrawViewPortsSet(ports, 0);
57: }
58: PetscDrawLGCreate(draw, 1, &lg);
59: PetscDrawLGSetUseMarkers(lg, PETSC_TRUE);
60: PetscDrawLGGetAxis(lg, &axis);
61: PetscDrawAxisSetColors(axis, PETSC_DRAW_BLACK, PETSC_DRAW_RED, PETSC_DRAW_BLUE);
62: PetscDrawAxisSetLabels(axis, toplabel, xlabel, ylabel);
63: PetscDrawLGSetLegend(lg, &legend);
64: PetscDrawLGSetFromOptions(lg);
66: for (i = 0; i <= n; i++) {
67: xd = (PetscReal)(i - 5);
68: yd = xd * xd;
69: PetscDrawLGAddPoint(lg, &xd, &yd);
70: }
71: PetscDrawLGDraw(lg);
72: PetscDrawLGSave(lg);
74: PetscDrawViewPortsDestroy(ports);
75: PetscDrawLGDestroy(&lg);
76: PetscDrawDestroy(&draw);
77: PetscFinalize();
78: return 0;
79: }
81: /*TEST
83: build:
84: requires: x
86: test:
87: output_file: output/ex1_1.out
89: TEST*/