Actual source code: ex3.c
petsc-3.9.4 2018-09-11
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;
23: PetscErrorCode ierr;
25: toplabel = "Top Label"; xlabel = "X-axis Label"; ylabel = "Y-axis Label"; legend = "Legend";
27: PetscInitialize(&argc,&argv,NULL,help);
28: PetscOptionsGetInt(NULL,NULL,"-x",&x,NULL);
29: PetscOptionsGetInt(NULL,NULL,"-y",&y,NULL);
30: PetscOptionsGetInt(NULL,NULL,"-width",&width,NULL);
31: PetscOptionsGetInt(NULL,NULL,"-height",&height,NULL);
32: PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
33: PetscOptionsGetInt(NULL,NULL,"-nports",&nports,&useports);
34: PetscOptionsHasName(NULL,NULL,"-nolegend",&flg);
35: if (flg) legend = NULL;
36: PetscOptionsHasName(NULL,NULL,"-notoplabel",&flg);
37: if (flg) toplabel = NULL;
38: PetscOptionsHasName(NULL,NULL,"-noxlabel",&flg);
39: if (flg) xlabel = NULL;
40: PetscOptionsHasName(NULL,NULL,"-noylabel",&flg);
41: if (flg) ylabel = NULL;
42: PetscOptionsHasName(NULL,NULL,"-nolabels",&flg);
43: if (flg) {toplabel = NULL; xlabel = NULL; ylabel = NULL;}
45: PetscDrawCreate(PETSC_COMM_WORLD,0,"Title",x,y,width,height,&draw);
46: PetscDrawSetFromOptions(draw);
47: if (useports) {
48: PetscDrawViewPortsCreate(draw,nports,&ports);
49: PetscDrawViewPortsSet(ports,0);
50: }
51: PetscDrawLGCreate(draw,1,&lg);
52: PetscDrawLGSetUseMarkers(lg,PETSC_TRUE);
53: PetscDrawLGGetAxis(lg,&axis);
54: PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);
55: PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);
56: PetscDrawLGSetLegend(lg,&legend);
57: PetscDrawLGSetFromOptions(lg);
59: for (i=0; i<=n; i++) {
60: xd = (PetscReal)(i - 5); yd = xd*xd;
61: PetscDrawLGAddPoint(lg,&xd,&yd);
62: }
63: PetscDrawLGDraw(lg);
64: PetscDrawLGSave(lg);
66: PetscDrawViewPortsDestroy(ports);
67: PetscDrawLGDestroy(&lg);
68: PetscDrawDestroy(&draw);
69: PetscFinalize();
70: return ierr;
71: }
75: /*TEST
77: build:
78: requires: x
80: test:
81: output_file: output/ex1_1.out
83: TEST*/