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