xref: /petsc/src/sys/classes/draw/utils/lgc.c (revision bfc4c25e64040512a7cdc7bcb995f785926f51e6)
1 
2 #include <petscviewer.h>
3 #include <../src/sys/classes/draw/utils/lgimpl.h>  /*I   "petscdraw.h"  I*/
4 PetscClassId PETSC_DRAWLG_CLASSID = 0;
5 
6 #undef __FUNCT__
7 #define __FUNCT__ "PetscDrawLGGetAxis"
8 /*@
9    PetscDrawLGGetAxis - Gets the axis context associated with a line graph.
10    This is useful if one wants to change some axis property, such as
11    labels, color, etc. The axis context should not be destroyed by the
12    application code.
13 
14    Not Collective, if PetscDrawLG is parallel then PetscDrawAxis is parallel
15 
16    Input Parameter:
17 .  lg - the line graph context
18 
19    Output Parameter:
20 .  axis - the axis context
21 
22    Level: advanced
23 
24 .seealso: PetscDrawLGCreate(), PetscDrawAxis
25 
26 @*/
27 PetscErrorCode  PetscDrawLGGetAxis(PetscDrawLG lg,PetscDrawAxis *axis)
28 {
29   PetscFunctionBegin;
30   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
31   PetscValidPointer(axis,2);
32   *axis = lg->axis;
33   PetscFunctionReturn(0);
34 }
35 
36 #undef __FUNCT__
37 #define __FUNCT__ "PetscDrawLGGetDraw"
38 /*@
39    PetscDrawLGGetDraw - Gets the draw context associated with a line graph.
40 
41    Not Collective, if PetscDrawLG is parallel then PetscDraw is parallel
42 
43    Input Parameter:
44 .  lg - the line graph context
45 
46    Output Parameter:
47 .  draw - the draw context
48 
49    Level: intermediate
50 
51 .seealso: PetscDrawLGCreate(), PetscDraw
52 @*/
53 PetscErrorCode  PetscDrawLGGetDraw(PetscDrawLG lg,PetscDraw *draw)
54 {
55   PetscFunctionBegin;
56   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
57   PetscValidPointer(draw,2);
58   *draw = lg->win;
59   PetscFunctionReturn(0);
60 }
61 
62 
63 #undef __FUNCT__
64 #define __FUNCT__ "PetscDrawLGSPDraw"
65 /*@
66    PetscDrawLGSPDraw - Redraws a line graph.
67 
68    Collective on PetscDrawLG
69 
70    Input Parameter:
71 .  lg - the line graph context
72 
73    Level: intermediate
74 
75 .seealso: PetscDrawLGDraw(), PetscDrawSPDraw()
76 
77    Developer Notes: This code cheats and uses the fact that the LG and SP structs are the same
78 
79 @*/
80 PetscErrorCode  PetscDrawLGSPDraw(PetscDrawLG lg,PetscDrawSP spin)
81 {
82   PetscDrawLG    sp = (PetscDrawLG)spin;
83   PetscReal      xmin,xmax,ymin,ymax;
84   PetscErrorCode ierr;
85   PetscBool      isnull;
86   PetscMPIInt    rank;
87   PetscDraw      draw;
88 
89   PetscFunctionBegin;
90   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
91   PetscValidHeaderSpecific(sp,PETSC_DRAWSP_CLASSID,2);
92   ierr = PetscDrawIsNull(lg->win,&isnull);CHKERRQ(ierr);
93   if (isnull) PetscFunctionReturn(0);
94   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)lg),&rank);CHKERRQ(ierr);
95 
96   draw = lg->win;
97   ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr);
98   ierr = PetscDrawClear(draw);CHKERRQ(ierr);
99 
100   xmin = PetscMin(lg->xmin,sp->xmin); ymin = PetscMin(lg->ymin,sp->ymin);
101   xmax = PetscMax(lg->xmax,sp->xmax); ymax = PetscMax(lg->ymax,sp->ymax);
102   ierr = PetscDrawAxisSetLimits(lg->axis,xmin,xmax,ymin,ymax);CHKERRQ(ierr);
103   ierr = PetscDrawAxisDraw(lg->axis);CHKERRQ(ierr);
104 
105   ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
106   if (!rank) {
107     int i,j,dim,nopts;
108     dim   = lg->dim;
109     nopts = lg->nopts;
110     for (i=0; i<dim; i++) {
111       for (j=1; j<nopts; j++) {
112         ierr = PetscDrawLine(draw,lg->x[(j-1)*dim+i],lg->y[(j-1)*dim+i],lg->x[j*dim+i],lg->y[j*dim+i],PETSC_DRAW_BLACK+i);CHKERRQ(ierr);
113         if (lg->use_markers) {
114           ierr = PetscDrawMarker(draw,lg->x[j*dim+i],lg->y[j*dim+i],PETSC_DRAW_RED);CHKERRQ(ierr);
115         }
116       }
117     }
118     dim   = sp->dim;
119     nopts = sp->nopts;
120     for (i=0; i<dim; i++) {
121       for (j=0; j<nopts; j++) {
122         ierr = PetscDrawMarker(draw,sp->x[j*dim+i],sp->y[j*dim+i],PETSC_DRAW_RED);CHKERRQ(ierr);
123       }
124     }
125   }
126   ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
127 
128   ierr = PetscDrawFlush(draw);CHKERRQ(ierr);
129   ierr = PetscDrawPause(draw);CHKERRQ(ierr);
130   PetscFunctionReturn(0);
131 }
132 
133 
134 #undef __FUNCT__
135 #define __FUNCT__ "PetscDrawLGCreate"
136 /*@
137     PetscDrawLGCreate - Creates a line graph data structure.
138 
139     Collective on PetscDraw
140 
141     Input Parameters:
142 +   draw - the window where the graph will be made.
143 -   dim - the number of curves which will be drawn
144 
145     Output Parameters:
146 .   outlg - the line graph context
147 
148     Level: intermediate
149 
150     Notes: The MPI communicator that owns the PetscDraw owns this PetscDrawLG, but the calls to set options and add points are ignored on all processes except the
151            zeroth MPI process in the communicator. All MPI processes in the communicator must call PetscDrawLGDraw() to display the updated graph.
152 
153     Concepts: line graph^creating
154 
155 .seealso:  PetscDrawLGDestroy(), PetscDrawLGAddPoint(), PetscDrawLGAddCommonPoint(), PetscDrawLGAddPoints(), PetscDrawLGDraw(), PetscDrawLGSave(),
156            PetscDrawLGView(), PetscDrawLGReset(), PetscDrawLGSetDimension(), PetscDrawLGGetDimension(), PetscDrawLGSetLegend(), PetscDrawLGGetAxis(),
157            PetscDrawLGGetDraw(), PetscDrawLGSetUseMarkers(), PetscDrawLGSetLimits(), PetscDrawLGSetColors(), PetscDrawLGSetOptionsPrefix(), PetscDrawLGSetFromOptions()
158 @*/
159 PetscErrorCode  PetscDrawLGCreate(PetscDraw draw,PetscInt dim,PetscDrawLG *outlg)
160 {
161   PetscDrawLG    lg;
162   PetscErrorCode ierr;
163 
164   PetscFunctionBegin;
165   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
166   PetscValidLogicalCollectiveInt(draw,dim,2);
167   PetscValidPointer(outlg,3);
168 
169   ierr = PetscHeaderCreate(lg,PETSC_DRAWLG_CLASSID,"DrawLG","Line Graph","Draw",PetscObjectComm((PetscObject)draw),PetscDrawLGDestroy,NULL);CHKERRQ(ierr);
170   ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)lg);CHKERRQ(ierr);
171   ierr = PetscDrawLGSetOptionsPrefix(lg,((PetscObject)draw)->prefix);CHKERRQ(ierr);
172 
173   ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr);
174   lg->win = draw;
175 
176   lg->view    = NULL;
177   lg->destroy = NULL;
178   lg->nopts   = 0;
179   lg->dim     = dim;
180   lg->xmin    = 1.e20;
181   lg->ymin    = 1.e20;
182   lg->xmax    = -1.e20;
183   lg->ymax    = -1.e20;
184 
185   ierr = PetscMalloc2(dim*CHUNCKSIZE,&lg->x,dim*CHUNCKSIZE,&lg->y);CHKERRQ(ierr);
186   ierr = PetscLogObjectMemory((PetscObject)lg,2*dim*CHUNCKSIZE*sizeof(PetscReal));CHKERRQ(ierr);
187 
188   lg->len         = dim*CHUNCKSIZE;
189   lg->loc         = 0;
190   lg->use_markers = PETSC_FALSE;
191 
192   ierr = PetscDrawAxisCreate(draw,&lg->axis);CHKERRQ(ierr);
193   ierr = PetscLogObjectParent((PetscObject)lg,(PetscObject)lg->axis);CHKERRQ(ierr);
194 
195   *outlg = lg;
196   PetscFunctionReturn(0);
197 }
198 
199 #undef __FUNCT__
200 #define __FUNCT__ "PetscDrawLGSetColors"
201 /*@
202    PetscDrawLGSetColors - Sets the color of each line graph drawn
203 
204    Logically Collective on PetscDrawLG
205 
206    Input Parameter:
207 +  lg - the line graph context.
208 -  colors - the colors
209 
210    Level: intermediate
211 
212    Concepts: line graph^setting number of lines
213 
214 .seealso: PetscDrawLGCreate()
215 
216 @*/
217 PetscErrorCode  PetscDrawLGSetColors(PetscDrawLG lg,const int colors[])
218 {
219   PetscErrorCode ierr;
220 
221   PetscFunctionBegin;
222   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
223   if (lg->dim) PetscValidIntPointer(colors,2);
224 
225   ierr = PetscFree(lg->colors);CHKERRQ(ierr);
226   ierr = PetscMalloc1(lg->dim,&lg->colors);CHKERRQ(ierr);
227   ierr = PetscMemcpy(lg->colors,colors,lg->dim*sizeof(int));CHKERRQ(ierr);
228   PetscFunctionReturn(0);
229 }
230 
231 #undef __FUNCT__
232 #undef __FUNCT__
233 #define __FUNCT__ "PetscDrawLGSetLegend"
234 /*@C
235    PetscDrawLGSetLegend - sets the names of each curve plotted
236 
237    Logically Collective on PetscDrawLG
238 
239    Input Parameter:
240 +  lg - the line graph context.
241 -  names - the names for each curve
242 
243    Level: intermediate
244 
245    Notes: Call PetscDrawLGGetAxis() and then change properties of the PetscDrawAxis for detailed control of the plot
246 
247    Concepts: line graph^setting number of lines
248 
249 .seealso: PetscDrawLGGetAxis(), PetscDrawAxis, PetscDrawAxisSetColors(), PetscDrawAxisSetLabels(), PetscDrawAxisSetHoldLimits()
250 
251 @*/
252 PetscErrorCode  PetscDrawLGSetLegend(PetscDrawLG lg,const char *const *names)
253 {
254   PetscErrorCode ierr;
255   PetscInt       i;
256 
257   PetscFunctionBegin;
258   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
259   if (names) PetscValidPointer(names,2);
260 
261   if (lg->legend) {
262     for (i=0; i<lg->dim; i++) {
263       ierr = PetscFree(lg->legend[i]);CHKERRQ(ierr);
264     }
265     ierr = PetscFree(lg->legend);CHKERRQ(ierr);
266   }
267   if (names) {
268     ierr = PetscMalloc1(lg->dim,&lg->legend);CHKERRQ(ierr);
269     for (i=0; i<lg->dim; i++) {
270       ierr = PetscStrallocpy(names[i],&lg->legend[i]);CHKERRQ(ierr);
271     }
272   }
273   PetscFunctionReturn(0);
274 }
275 
276 #undef __FUNCT__
277 #define __FUNCT__ "PetscDrawLGGetDimension"
278 /*@
279    PetscDrawLGGetDimension - Change the number of lines that are to be drawn.
280 
281    Not Collective
282 
283    Input Parameter:
284 .  lg - the line graph context.
285 
286    Output Parameter:
287 .  dim - the number of curves.
288 
289    Level: intermediate
290 
291    Concepts: line graph^setting number of lines
292 
293 .seealso: PetscDrawLGCreate(), PetscDrawLGSetDimension()
294 
295 @*/
296 PetscErrorCode  PetscDrawLGGetDimension(PetscDrawLG lg,PetscInt *dim)
297 {
298   PetscFunctionBegin;
299   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
300   PetscValidIntPointer(dim,2);
301   *dim = lg->dim;
302   PetscFunctionReturn(0);
303 }
304 
305 #undef __FUNCT__
306 #define __FUNCT__ "PetscDrawLGSetDimension"
307 /*@
308    PetscDrawLGSetDimension - Change the number of lines that are to be drawn.
309 
310    Logically Collective on PetscDrawLG
311 
312    Input Parameter:
313 +  lg - the line graph context.
314 -  dim - the number of curves.
315 
316    Level: intermediate
317 
318    Concepts: line graph^setting number of lines
319 
320 .seealso: PetscDrawLGCreate(), PetscDrawLGGetDimension()
321 @*/
322 PetscErrorCode  PetscDrawLGSetDimension(PetscDrawLG lg,PetscInt dim)
323 {
324   PetscErrorCode ierr;
325   PetscInt       i;
326 
327   PetscFunctionBegin;
328   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
329   PetscValidLogicalCollectiveInt(lg,dim,2);
330   if (lg->dim == dim) PetscFunctionReturn(0);
331 
332   ierr = PetscFree2(lg->x,lg->y);CHKERRQ(ierr);
333   if (lg->legend) {
334     for (i=0; i<lg->dim; i++) {
335       ierr = PetscFree(lg->legend[i]);CHKERRQ(ierr);
336     }
337     ierr = PetscFree(lg->legend);CHKERRQ(ierr);
338   }
339   ierr    = PetscFree(lg->colors);CHKERRQ(ierr);
340   lg->dim = dim;
341   ierr    = PetscMalloc2(dim*CHUNCKSIZE,&lg->x,dim*CHUNCKSIZE,&lg->y);CHKERRQ(ierr);
342   ierr    = PetscLogObjectMemory((PetscObject)lg,2*dim*CHUNCKSIZE*sizeof(PetscReal));CHKERRQ(ierr);
343   lg->len = dim*CHUNCKSIZE;
344   PetscFunctionReturn(0);
345 }
346 
347 
348 #undef __FUNCT__
349 #define __FUNCT__ "PetscDrawLGSetLimits"
350 /*@
351    PetscDrawLGSetLimits - Sets the axis limits for a line graph. If more
352    points are added after this call, the limits will be adjusted to
353    include those additional points.
354 
355    Logically Collective on PetscDrawLG
356 
357    Input Parameters:
358 +  xlg - the line graph context
359 -  x_min,x_max,y_min,y_max - the limits
360 
361    Level: intermediate
362 
363    Concepts: line graph^setting axis
364 
365 .seealso: PetscDrawLGCreate()
366 
367 @*/
368 PetscErrorCode  PetscDrawLGSetLimits(PetscDrawLG lg,PetscReal x_min,PetscReal x_max,PetscReal y_min,PetscReal y_max)
369 {
370   PetscFunctionBegin;
371   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
372 
373   (lg)->xmin = x_min;
374   (lg)->xmax = x_max;
375   (lg)->ymin = y_min;
376   (lg)->ymax = y_max;
377   PetscFunctionReturn(0);
378 }
379 
380 #undef __FUNCT__
381 #define __FUNCT__ "PetscDrawLGReset"
382 /*@
383    PetscDrawLGReset - Clears line graph to allow for reuse with new data.
384 
385    Logically Collective on PetscDrawLG
386 
387    Input Parameter:
388 .  lg - the line graph context.
389 
390    Level: intermediate
391 
392    Concepts: line graph^restarting
393 
394 .seealso: PetscDrawLGCreate()
395 
396 @*/
397 PetscErrorCode  PetscDrawLGReset(PetscDrawLG lg)
398 {
399   PetscFunctionBegin;
400   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
401   lg->xmin  = 1.e20;
402   lg->ymin  = 1.e20;
403   lg->xmax  = -1.e20;
404   lg->ymax  = -1.e20;
405   lg->loc   = 0;
406   lg->nopts = 0;
407   PetscFunctionReturn(0);
408 }
409 
410 #undef __FUNCT__
411 #define __FUNCT__ "PetscDrawLGDestroy"
412 /*@
413    PetscDrawLGDestroy - Frees all space taken up by line graph data structure.
414 
415    Collective on PetscDrawLG
416 
417    Input Parameter:
418 .  lg - the line graph context
419 
420    Level: intermediate
421 
422 .seealso:  PetscDrawLGCreate()
423 @*/
424 PetscErrorCode  PetscDrawLGDestroy(PetscDrawLG *lg)
425 {
426   PetscErrorCode ierr;
427   PetscInt       i;
428 
429   PetscFunctionBegin;
430   if (!*lg) PetscFunctionReturn(0);
431   PetscValidHeaderSpecific(*lg,PETSC_DRAWLG_CLASSID,1);
432   if (--((PetscObject)(*lg))->refct > 0) {*lg = NULL; PetscFunctionReturn(0);}
433 
434   if ((*lg)->legend) {
435     for (i=0; i<(*lg)->dim; i++) {
436       ierr = PetscFree((*lg)->legend[i]);CHKERRQ(ierr);
437     }
438     ierr = PetscFree((*lg)->legend);CHKERRQ(ierr);
439   }
440   ierr = PetscFree((*lg)->colors);CHKERRQ(ierr);
441   ierr = PetscFree2((*lg)->x,(*lg)->y);CHKERRQ(ierr);
442   ierr = PetscDrawAxisDestroy(&(*lg)->axis);CHKERRQ(ierr);
443   ierr = PetscDrawDestroy(&(*lg)->win);CHKERRQ(ierr);
444   ierr = PetscHeaderDestroy(lg);CHKERRQ(ierr);
445   PetscFunctionReturn(0);
446 }
447 #undef __FUNCT__
448 #define __FUNCT__ "PetscDrawLGSetUseMarkers"
449 /*@
450    PetscDrawLGSetUseMarkers - Causes LG to draw a marker for each data-point.
451 
452    Logically Collective on PetscDrawLG
453 
454    Input Parameters:
455 +  lg - the linegraph context
456 -  flg - should mark each data point
457 
458    Options Database:
459 .  -lg_use_markers  <true,false>
460 
461    Level: intermediate
462 
463    Concepts: line graph^showing points
464 
465 .seealso: PetscDrawLGCreate()
466 
467 @*/
468 PetscErrorCode  PetscDrawLGSetUseMarkers(PetscDrawLG lg,PetscBool flg)
469 {
470   PetscFunctionBegin;
471   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
472   PetscValidLogicalCollectiveBool(lg,flg,2);
473   lg->use_markers = flg;
474   PetscFunctionReturn(0);
475 }
476 
477 #undef __FUNCT__
478 #define __FUNCT__ "PetscDrawLGDraw"
479 /*@
480    PetscDrawLGDraw - Redraws a line graph.
481 
482    Collective on PetscDrawLG
483 
484    Input Parameter:
485 .  lg - the line graph context
486 
487    Level: intermediate
488 
489 .seealso: PetscDrawSPDraw(), PetscDrawLGSPDraw(), PetscDrawLGReset()
490 
491 @*/
492 PetscErrorCode  PetscDrawLGDraw(PetscDrawLG lg)
493 {
494   PetscReal      xmin,xmax,ymin,ymax;
495   PetscErrorCode ierr;
496   PetscMPIInt    rank;
497   PetscDraw      draw;
498   PetscBool      isnull;
499 
500   PetscFunctionBegin;
501   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
502   ierr = PetscDrawIsNull(lg->win,&isnull);CHKERRQ(ierr);
503   if (isnull) PetscFunctionReturn(0);
504   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)lg),&rank);CHKERRQ(ierr);
505 
506   draw = lg->win;
507   ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr);
508   ierr = PetscDrawClear(draw);CHKERRQ(ierr);
509 
510   xmin = lg->xmin; xmax = lg->xmax; ymin = lg->ymin; ymax = lg->ymax;
511   ierr = PetscDrawAxisSetLimits(lg->axis,xmin,xmax,ymin,ymax);CHKERRQ(ierr);
512   ierr = PetscDrawAxisDraw(lg->axis);CHKERRQ(ierr);
513 
514   ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
515   if (!rank) {
516     int i,j,dim=lg->dim,nopts=lg->nopts,cl;
517     for (i=0; i<dim; i++) {
518       for (j=1; j<nopts; j++) {
519         cl   = lg->colors ? lg->colors[i] : (PETSC_DRAW_BLACK + i);
520         ierr = PetscDrawLine(draw,lg->x[(j-1)*dim+i],lg->y[(j-1)*dim+i],lg->x[j*dim+i],lg->y[j*dim+i],cl);CHKERRQ(ierr);
521         if (lg->use_markers) {ierr = PetscDrawMarker(draw,lg->x[j*dim+i],lg->y[j*dim+i],cl);CHKERRQ(ierr);}
522       }
523     }
524   }
525   if (!rank && lg->legend) {
526     int       i,dim=lg->dim,cl;
527     PetscReal xl,yl,xr,yr,tw,th;
528     size_t    slen,len=0;
529     ierr = PetscDrawAxisGetLimits(lg->axis,&xl,&xr,&yl,&yr);CHKERRQ(ierr);
530     ierr = PetscDrawStringGetSize(draw,&tw,&th);CHKERRQ(ierr);
531     for (i=0; i<dim; i++) {
532       ierr = PetscStrlen(lg->legend[i],&slen);CHKERRQ(ierr);
533       len = PetscMax(len,slen);
534     }
535     xr = xr - 1.5*tw; xl = xr - (len + 7)*tw;
536     yr = yr - 1.0*th; yl = yr - (dim + 1)*th;
537     ierr = PetscDrawLine(draw,xl,yl,xr,yl,PETSC_DRAW_BLACK);CHKERRQ(ierr);
538     ierr = PetscDrawLine(draw,xr,yl,xr,yr,PETSC_DRAW_BLACK);CHKERRQ(ierr);
539     ierr = PetscDrawLine(draw,xr,yr,xl,yr,PETSC_DRAW_BLACK);CHKERRQ(ierr);
540     ierr = PetscDrawLine(draw,xl,yr,xl,yl,PETSC_DRAW_BLACK);CHKERRQ(ierr);
541     for  (i=0; i<dim; i++) {
542       cl   = lg->colors ? lg->colors[i] : (PETSC_DRAW_BLACK + i);
543       ierr = PetscDrawLine(draw,xl + 1*tw,yr - (i + 1)*th,xl + 5*tw,yr - (i + 1)*th,cl);CHKERRQ(ierr);
544       ierr = PetscDrawString(draw,xl + 6*tw,yr - (i + 1.5)*th,PETSC_DRAW_BLACK,lg->legend[i]);CHKERRQ(ierr);
545     }
546   }
547   ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
548 
549   ierr = PetscDrawFlush(draw);CHKERRQ(ierr);
550   ierr = PetscDrawPause(draw);CHKERRQ(ierr);
551   PetscFunctionReturn(0);
552 }
553 
554 #undef __FUNCT__
555 #define __FUNCT__ "PetscDrawLGSave"
556 /*@
557   PetscDrawLGSave - Saves a drawn image
558 
559   Collective on PetscDrawLG
560 
561   Input Parameter:
562 . lg - The line graph context
563 
564   Level: intermediate
565 
566   Concepts: line graph^saving
567 
568 .seealso:  PetscDrawLGCreate(), PetscDrawLGGetDraw(), PetscDrawSetSave(), PetscDrawSave()
569 @*/
570 PetscErrorCode  PetscDrawLGSave(PetscDrawLG lg)
571 {
572   PetscErrorCode ierr;
573 
574   PetscFunctionBegin;
575   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
576   ierr = PetscDrawSave(lg->win);CHKERRQ(ierr);
577   PetscFunctionReturn(0);
578 }
579 
580 #undef __FUNCT__
581 #define __FUNCT__ "PetscDrawLGView"
582 /*@
583   PetscDrawLGView - Prints a line graph.
584 
585   Collective on PetscDrawLG
586 
587   Input Parameter:
588 . lg - the line graph context
589 
590   Level: beginner
591 
592 .seealso: PetscDrawLGCreate()
593 
594 .keywords:  draw, line, graph
595 @*/
596 PetscErrorCode  PetscDrawLGView(PetscDrawLG lg,PetscViewer viewer)
597 {
598   PetscReal      xmin=lg->xmin, xmax=lg->xmax, ymin=lg->ymin, ymax=lg->ymax;
599   PetscInt       i, j, dim = lg->dim, nopts = lg->nopts;
600   PetscErrorCode ierr;
601 
602   PetscFunctionBegin;
603   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
604 
605   if (nopts < 1)                  PetscFunctionReturn(0);
606   if (xmin > xmax || ymin > ymax) PetscFunctionReturn(0);
607 
608   if (!viewer){
609     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)lg),&viewer);CHKERRQ(ierr);
610   }
611   ierr = PetscObjectPrintClassNamePrefixType((PetscObject)lg,viewer);CHKERRQ(ierr);
612   for (i = 0; i < dim; i++) {
613     ierr = PetscViewerASCIIPrintf(viewer, "Line %D>\n", i);CHKERRQ(ierr);
614     for (j = 0; j < nopts; j++) {
615       ierr = PetscViewerASCIIPrintf(viewer, "  X: %g Y: %g\n", (double)lg->x[j*dim+i], (double)lg->y[j*dim+i]);CHKERRQ(ierr);
616     }
617   }
618   PetscFunctionReturn(0);
619 }
620 
621 #undef __FUNCT__
622 #define __FUNCT__ "PetscDrawLGSetOptionsPrefix"
623 /*@C
624    PetscDrawLGSetOptionsPrefix - Sets the prefix used for searching for all
625    PetscDrawLG options in the database.
626 
627    Logically Collective on PetscDrawLG
628 
629    Input Parameter:
630 +  lg - the line graph context
631 -  prefix - the prefix to prepend to all option names
632 
633    Level: advanced
634 
635 .keywords: PetscDrawLG, set, options, prefix, database
636 
637 .seealso: PetscDrawLGSetFromOptions(), PetscDrawLGCreate()
638 @*/
639 PetscErrorCode  PetscDrawLGSetOptionsPrefix(PetscDrawLG lg,const char prefix[])
640 {
641   PetscErrorCode ierr;
642 
643   PetscFunctionBegin;
644   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
645   ierr = PetscObjectSetOptionsPrefix((PetscObject)lg,prefix);CHKERRQ(ierr);
646   PetscFunctionReturn(0);
647 }
648 
649 #undef __FUNCT__
650 #define __FUNCT__ "PetscDrawLGSetFromOptions"
651 /*@
652     PetscDrawLGSetFromOptions - Sets options related to the PetscDrawLG
653 
654     Collective on PetscDrawLG
655 
656     Options Database:
657 
658     Level: intermediate
659 
660     Concepts: line graph^creating
661 
662 .seealso:  PetscDrawLGDestroy(), PetscDrawLGCreate()
663 @*/
664 PetscErrorCode  PetscDrawLGSetFromOptions(PetscDrawLG lg)
665 {
666   PetscErrorCode      ierr;
667   PetscBool           usemarkers,set;
668   PetscDrawMarkerType markertype;
669 
670   PetscFunctionBegin;
671   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
672 
673   ierr = PetscDrawGetMarkerType(lg->win,&markertype);CHKERRQ(ierr);
674   ierr = PetscOptionsGetEnum(((PetscObject)lg)->options,((PetscObject)lg)->prefix,"-lg_marker_type",PetscDrawMarkerTypes,(PetscEnum*)&markertype,&set);CHKERRQ(ierr);
675   if (set) {
676     ierr = PetscDrawLGSetUseMarkers(lg,PETSC_TRUE);CHKERRQ(ierr);
677     ierr = PetscDrawSetMarkerType(lg->win,markertype);CHKERRQ(ierr);
678   }
679   usemarkers = lg->use_markers;
680   ierr = PetscOptionsGetBool(((PetscObject)lg)->options,((PetscObject)lg)->prefix,"-lg_use_markers",&usemarkers,&set);CHKERRQ(ierr);
681   if (set) {ierr = PetscDrawLGSetUseMarkers(lg,usemarkers);CHKERRQ(ierr);}
682   PetscFunctionReturn(0);
683 }
684