xref: /petsc/src/sys/classes/draw/utils/lgc.c (revision 2b8d69ca7ea5fe9190df62c1dce3bbd66fce84dd)
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 @*/
25 PetscErrorCode  PetscDrawLGGetAxis(PetscDrawLG lg,PetscDrawAxis *axis)
26 {
27   PetscFunctionBegin;
28   PetscValidPointer(axis,2);
29   if (!lg) {*axis = NULL; PetscFunctionReturn(0);}
30   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
31   *axis = lg->axis;
32   PetscFunctionReturn(0);
33 }
34 
35 #undef __FUNCT__
36 #define __FUNCT__ "PetscDrawLGGetDraw"
37 /*@
38    PetscDrawLGGetDraw - Gets the draw context associated with a line graph.
39 
40    Not Collective, if PetscDrawLG is parallel then PetscDraw is parallel
41 
42    Input Parameter:
43 .  lg - the line graph context
44 
45    Output Parameter:
46 .  draw - the draw context
47 
48    Level: intermediate
49 
50 @*/
51 PetscErrorCode  PetscDrawLGGetDraw(PetscDrawLG lg,PetscDraw *draw)
52 {
53   PetscFunctionBegin;
54   PetscValidPointer(draw,2);
55   if (!lg) {*draw = NULL; PetscFunctionReturn(0);}
56   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
57   *draw = lg->win;
58   PetscFunctionReturn(0);
59 }
60 
61 
62 #undef __FUNCT__
63 #define __FUNCT__ "PetscDrawLGSPDraw"
64 /*@
65    PetscDrawLGSPDraw - Redraws a line graph.
66 
67    Collective on PetscDrawLG
68 
69    Input Parameter:
70 .  lg - the line graph context
71 
72    Level: intermediate
73 
74 .seealso: PetscDrawLGDraw(), PetscDrawSPDraw()
75 
76    Developer Notes: This code cheats and uses the fact that the LG and SP structs are the same
77 
78 @*/
79 PetscErrorCode  PetscDrawLGSPDraw(PetscDrawLG lg,PetscDrawSP spin)
80 {
81   PetscDrawLG    sp = (PetscDrawLG)spin;
82   PetscReal      xmin,xmax,ymin,ymax;
83   PetscErrorCode ierr;
84   PetscBool      isnull;
85   PetscMPIInt    rank;
86   PetscDraw      draw;
87 
88   PetscFunctionBegin;
89   if (!lg || !spin) {PetscFunctionReturn(0);}
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     Concepts: line graph^creating
151 
152 .seealso:  PetscDrawLGDestroy()
153 @*/
154 PetscErrorCode  PetscDrawLGCreate(PetscDraw draw,PetscInt dim,PetscDrawLG *outlg)
155 {
156   PetscBool      isnull;
157   PetscDrawLG    lg;
158   PetscErrorCode ierr;
159 
160   PetscFunctionBegin;
161   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
162   PetscValidLogicalCollectiveInt(draw,dim,2);
163   PetscValidPointer(outlg,3);
164   ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr);
165   if (isnull) {*outlg = NULL; PetscFunctionReturn(0);}
166 
167   ierr = PetscHeaderCreate(lg,PETSC_DRAWLG_CLASSID,"PetscDrawLG","Line graph","Draw",PetscObjectComm((PetscObject)draw),PetscDrawLGDestroy,NULL);CHKERRQ(ierr);
168   ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)lg);CHKERRQ(ierr);
169   ierr = PetscDrawLGSetOptionsPrefix(lg,((PetscObject)draw)->prefix);CHKERRQ(ierr);
170 
171   ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr);
172   lg->win = draw;
173 
174   lg->view    = NULL;
175   lg->destroy = NULL;
176   lg->nopts   = 0;
177   lg->dim     = dim;
178   lg->xmin    = 1.e20;
179   lg->ymin    = 1.e20;
180   lg->xmax    = -1.e20;
181   lg->ymax    = -1.e20;
182 
183   ierr = PetscMalloc2(dim*CHUNCKSIZE,&lg->x,dim*CHUNCKSIZE,&lg->y);CHKERRQ(ierr);
184   ierr = PetscLogObjectMemory((PetscObject)lg,2*dim*CHUNCKSIZE*sizeof(PetscReal));CHKERRQ(ierr);
185 
186   lg->len         = dim*CHUNCKSIZE;
187   lg->loc         = 0;
188   lg->use_markers = PETSC_FALSE;
189 
190   ierr = PetscDrawAxisCreate(draw,&lg->axis);CHKERRQ(ierr);
191   ierr = PetscLogObjectParent((PetscObject)lg,(PetscObject)lg->axis);CHKERRQ(ierr);
192 
193   *outlg = lg;
194   PetscFunctionReturn(0);
195 }
196 
197 #undef __FUNCT__
198 #define __FUNCT__ "PetscDrawLGSetColors"
199 /*@
200    PetscDrawLGSetColors - Sets the color of each line graph drawn
201 
202    Logically Collective on PetscDrawLG
203 
204    Input Parameter:
205 +  lg - the line graph context.
206 -  colors - the colors
207 
208    Level: intermediate
209 
210    Concepts: line graph^setting number of lines
211 
212 @*/
213 PetscErrorCode  PetscDrawLGSetColors(PetscDrawLG lg,const int *colors)
214 {
215   PetscErrorCode ierr;
216 
217   PetscFunctionBegin;
218   if (!lg) PetscFunctionReturn(0);
219   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
220 
221   ierr = PetscFree(lg->colors);CHKERRQ(ierr);
222   ierr = PetscMalloc1(lg->dim,&lg->colors);CHKERRQ(ierr);
223   ierr = PetscMemcpy(lg->colors,colors,lg->dim*sizeof(int));CHKERRQ(ierr);
224   PetscFunctionReturn(0);
225 }
226 
227 #undef __FUNCT__
228 #undef __FUNCT__
229 #define __FUNCT__ "PetscDrawLGSetLegend"
230 /*@C
231    PetscDrawLGSetLegend - sets the names of each curve plotted
232 
233    Logically Collective on PetscDrawLG
234 
235    Input Parameter:
236 +  lg - the line graph context.
237 -  names - the names for each curve
238 
239    Level: intermediate
240 
241    Concepts: line graph^setting number of lines
242 
243 @*/
244 PetscErrorCode  PetscDrawLGSetLegend(PetscDrawLG lg,const char *const *names)
245 {
246   PetscErrorCode ierr;
247   PetscInt       i;
248 
249   PetscFunctionBegin;
250   if (!lg) PetscFunctionReturn(0);
251   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
252 
253   if (lg->legend) {
254     for (i=0; i<lg->dim; i++) {
255       ierr = PetscFree(lg->legend[i]);CHKERRQ(ierr);
256     }
257     ierr = PetscFree(lg->legend);CHKERRQ(ierr);
258   }
259   if (names) {
260     ierr = PetscMalloc1(lg->dim,&lg->legend);CHKERRQ(ierr);
261     for (i=0; i<lg->dim; i++) {
262       ierr = PetscStrallocpy(names[i],&lg->legend[i]);CHKERRQ(ierr);
263     }
264   }
265   PetscFunctionReturn(0);
266 }
267 
268 #undef __FUNCT__
269 #define __FUNCT__ "PetscDrawLGGetDimension"
270 /*@
271    PetscDrawLGGetDimension - Change the number of lines that are to be drawn.
272 
273    Not Collective
274 
275    Input Parameter:
276 .  lg - the line graph context.
277 
278    Output Parameter:
279 .  dim - the number of curves.
280 
281    Level: intermediate
282 
283    Concepts: line graph^setting number of lines
284 
285 @*/
286 PetscErrorCode  PetscDrawLGGetDimension(PetscDrawLG lg,PetscInt *dim)
287 {
288   PetscFunctionBegin;
289   if (!lg) PetscFunctionReturn(0);
290   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
291 
292   *dim = lg->dim;
293   PetscFunctionReturn(0);
294 }
295 
296 #undef __FUNCT__
297 #define __FUNCT__ "PetscDrawLGSetDimension"
298 /*@
299    PetscDrawLGSetDimension - Change the number of lines that are to be drawn.
300 
301    Logically Collective on PetscDrawLG
302 
303    Input Parameter:
304 +  lg - the line graph context.
305 -  dim - the number of curves.
306 
307    Level: intermediate
308 
309    Concepts: line graph^setting number of lines
310 
311 @*/
312 PetscErrorCode  PetscDrawLGSetDimension(PetscDrawLG lg,PetscInt dim)
313 {
314   PetscErrorCode ierr;
315   PetscInt       i;
316 
317   PetscFunctionBegin;
318   if (!lg) PetscFunctionReturn(0);
319   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
320   PetscValidLogicalCollectiveInt(lg,dim,2);
321   if (lg->dim == dim) PetscFunctionReturn(0);
322 
323   ierr = PetscFree2(lg->x,lg->y);CHKERRQ(ierr);
324   if (lg->legend) {
325     for (i=0; i<lg->dim; i++) {
326       ierr = PetscFree(lg->legend[i]);CHKERRQ(ierr);
327     }
328     ierr = PetscFree(lg->legend);CHKERRQ(ierr);
329   }
330   ierr    = PetscFree(lg->colors);CHKERRQ(ierr);
331   lg->dim = dim;
332   ierr    = PetscMalloc2(dim*CHUNCKSIZE,&lg->x,dim*CHUNCKSIZE,&lg->y);CHKERRQ(ierr);
333   ierr    = PetscLogObjectMemory((PetscObject)lg,2*dim*CHUNCKSIZE*sizeof(PetscReal));CHKERRQ(ierr);
334   lg->len = dim*CHUNCKSIZE;
335   PetscFunctionReturn(0);
336 }
337 
338 #undef __FUNCT__
339 #define __FUNCT__ "PetscDrawLGReset"
340 /*@
341    PetscDrawLGReset - Clears line graph to allow for reuse with new data.
342 
343    Logically Collective on PetscDrawLG
344 
345    Input Parameter:
346 .  lg - the line graph context.
347 
348    Level: intermediate
349 
350    Concepts: line graph^restarting
351 
352 @*/
353 PetscErrorCode  PetscDrawLGReset(PetscDrawLG lg)
354 {
355   PetscFunctionBegin;
356   if (!lg) PetscFunctionReturn(0);
357   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
358   lg->xmin  = 1.e20;
359   lg->ymin  = 1.e20;
360   lg->xmax  = -1.e20;
361   lg->ymax  = -1.e20;
362   lg->loc   = 0;
363   lg->nopts = 0;
364   PetscFunctionReturn(0);
365 }
366 
367 #undef __FUNCT__
368 #define __FUNCT__ "PetscDrawLGDestroy"
369 /*@
370    PetscDrawLGDestroy - Frees all space taken up by line graph data structure.
371 
372    Collective on PetscDrawLG
373 
374    Input Parameter:
375 .  lg - the line graph context
376 
377    Level: intermediate
378 
379 .seealso:  PetscDrawLGCreate()
380 @*/
381 PetscErrorCode  PetscDrawLGDestroy(PetscDrawLG *lg)
382 {
383   PetscErrorCode ierr;
384   PetscInt       i;
385 
386   PetscFunctionBegin;
387   if (!*lg) PetscFunctionReturn(0);
388   PetscValidHeaderSpecific(*lg,PETSC_DRAWLG_CLASSID,1);
389   if (--((PetscObject)(*lg))->refct > 0) {*lg = NULL; PetscFunctionReturn(0);}
390 
391   if ((*lg)->legend) {
392     for (i=0; i<(*lg)->dim; i++) {
393       ierr = PetscFree((*lg)->legend[i]);CHKERRQ(ierr);
394     }
395     ierr = PetscFree((*lg)->legend);CHKERRQ(ierr);
396   }
397   ierr = PetscFree((*lg)->colors);CHKERRQ(ierr);
398   ierr = PetscFree2((*lg)->x,(*lg)->y);CHKERRQ(ierr);
399   ierr = PetscDrawAxisDestroy(&(*lg)->axis);CHKERRQ(ierr);
400   ierr = PetscDrawDestroy(&(*lg)->win);CHKERRQ(ierr);
401   ierr = PetscHeaderDestroy(lg);CHKERRQ(ierr);
402   PetscFunctionReturn(0);
403 }
404 #undef __FUNCT__
405 #define __FUNCT__ "PetscDrawLGSetUseMarkers"
406 /*@
407    PetscDrawLGSetUseMarkers - Causes LG to draw a marker for each data-point.
408 
409    Logically Collective on PetscDrawLG
410 
411    Input Parameters:
412 +  lg - the linegraph context
413 -  flg - should mark each data point
414 
415    Options Database:
416 .  -lg_use_markers  <true,false>
417 
418    Level: intermediate
419 
420    Concepts: line graph^showing points
421 
422 @*/
423 PetscErrorCode  PetscDrawLGSetUseMarkers(PetscDrawLG lg,PetscBool flg)
424 {
425   PetscFunctionBegin;
426   if (!lg) PetscFunctionReturn(0);
427   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
428 
429   lg->use_markers = flg;
430   PetscFunctionReturn(0);
431 }
432 
433 #undef __FUNCT__
434 #define __FUNCT__ "PetscDrawLGDraw"
435 /*@
436    PetscDrawLGDraw - Redraws a line graph.
437 
438    Collective on PetscDrawLG
439 
440    Input Parameter:
441 .  lg - the line graph context
442 
443    Level: intermediate
444 
445 .seealso: PetscDrawSPDraw(), PetscDrawLGSPDraw()
446 
447 @*/
448 PetscErrorCode  PetscDrawLGDraw(PetscDrawLG lg)
449 {
450   PetscReal      xmin,xmax,ymin,ymax;
451   PetscErrorCode ierr;
452   PetscMPIInt    rank;
453   PetscDraw      draw;
454   PetscBool      isnull;
455 
456   PetscFunctionBegin;
457   if (!lg) PetscFunctionReturn(0);
458   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
459   ierr = PetscDrawIsNull(lg->win,&isnull);CHKERRQ(ierr);
460   if (isnull) PetscFunctionReturn(0);
461   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)lg),&rank);CHKERRQ(ierr);
462 
463   draw = lg->win;
464   ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr);
465   ierr = PetscDrawClear(draw);CHKERRQ(ierr);
466 
467   xmin = lg->xmin; xmax = lg->xmax; ymin = lg->ymin; ymax = lg->ymax;
468   ierr = PetscDrawAxisSetLimits(lg->axis,xmin,xmax,ymin,ymax);CHKERRQ(ierr);
469   ierr = PetscDrawAxisDraw(lg->axis);CHKERRQ(ierr);
470 
471   ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
472   if (!rank) {
473     int i,j,dim=lg->dim,nopts=lg->nopts,cl;
474     for (i=0; i<dim; i++) {
475       for (j=1; j<nopts; j++) {
476         if (lg->colors) cl = lg->colors[i];
477         else cl = PETSC_DRAW_BLACK+i;
478         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);
479         if (lg->use_markers) {
480           ierr = PetscDrawMarker(draw,lg->x[j*dim+i],lg->y[j*dim+i],cl);CHKERRQ(ierr);
481         }
482       }
483     }
484   }
485   if (!rank && lg->legend) {
486     int       i,dim=lg->dim,cl;
487     PetscReal xl,yl,xr,yr,tw,th;
488     size_t    len,mlen = 0;
489     ierr = PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);CHKERRQ(ierr);
490     ierr = PetscDrawStringGetSize(draw,&tw,&th);CHKERRQ(ierr);
491     for (i=0; i<dim; i++) {
492       ierr = PetscStrlen(lg->legend[i],&len);CHKERRQ(ierr);
493       mlen = PetscMax(mlen,len);
494     }
495     ierr = PetscDrawLine(draw,xr - (mlen + 8)*tw,yr - 3*th,xr - 2*tw,yr - 3*th,PETSC_DRAW_BLACK);CHKERRQ(ierr);
496     ierr = PetscDrawLine(draw,xr - (mlen + 8)*tw,yr - 3*th,xr - (mlen + 8)*tw,yr - (4+lg->dim)*th,PETSC_DRAW_BLACK);CHKERRQ(ierr);
497     for  (i=0; i<dim; i++) {
498       cl   = (lg->colors ? lg->colors[i] : i + 1);
499       ierr = PetscDrawLine(draw,xr - (mlen + 6.7)*tw,yr - (4 + i)*th,xr - (mlen + 3.2)*tw,yr - (4 + i)*th,cl);CHKERRQ(ierr);
500       ierr = PetscDrawString(draw,xr - (mlen + 3)*tw,yr - (4.5 + i)*th,PETSC_DRAW_BLACK,lg->legend[i]);CHKERRQ(ierr);
501     }
502     ierr = PetscDrawLine(draw,xr - 2*tw,yr - 3*th,xr - 2*tw,yr - (4+lg->dim)*th,PETSC_DRAW_BLACK);CHKERRQ(ierr);
503     ierr = PetscDrawLine(draw,xr - (mlen + 8)*tw,yr - (4+lg->dim)*th,xr - 2*tw,yr - (4+lg->dim)*th,PETSC_DRAW_BLACK);CHKERRQ(ierr);
504   }
505   ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
506 
507   ierr = PetscDrawFlush(draw);CHKERRQ(ierr);
508   ierr = PetscDrawPause(draw);CHKERRQ(ierr);
509   PetscFunctionReturn(0);
510 }
511 
512 #undef __FUNCT__
513 #define __FUNCT__ "PetscDrawLGSave"
514 /*@
515   PetscDrawLGSave - Saves a drawn image
516 
517   Collective on PetscDrawLG
518 
519   Input Parameter:
520 . lg - The line graph context
521 
522   Level: intermediate
523 
524   Concepts: line graph^saving
525 
526 .seealso:  PetscDrawLGCreate(), PetscDrawLGGetDraw(), PetscDrawSetSave(), PetscDrawSave()
527 @*/
528 PetscErrorCode  PetscDrawLGSave(PetscDrawLG lg)
529 {
530   PetscErrorCode ierr;
531 
532   PetscFunctionBegin;
533   if (!lg) PetscFunctionReturn(0);
534   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
535   ierr = PetscDrawSave(lg->win);CHKERRQ(ierr);
536   PetscFunctionReturn(0);
537 }
538 
539 #undef __FUNCT__
540 #define __FUNCT__ "PetscDrawLGView"
541 /*@
542   PetscDrawLGView - Prints a line graph.
543 
544   Collective on PetscDrawLG
545 
546   Input Parameter:
547 . lg - the line graph context
548 
549   Level: beginner
550 
551 .keywords:  draw, line, graph
552 @*/
553 PetscErrorCode  PetscDrawLGView(PetscDrawLG lg,PetscViewer viewer)
554 {
555   PetscReal      xmin=lg->xmin, xmax=lg->xmax, ymin=lg->ymin, ymax=lg->ymax;
556   PetscInt       i, j, dim = lg->dim, nopts = lg->nopts;
557   PetscErrorCode ierr;
558 
559   PetscFunctionBegin;
560   if (!lg) PetscFunctionReturn(0);
561   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
562 
563   if (nopts < 1)                  PetscFunctionReturn(0);
564   if (xmin > xmax || ymin > ymax) PetscFunctionReturn(0);
565 
566   if (!viewer){
567     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)lg),&viewer);CHKERRQ(ierr);
568   }
569   ierr = PetscObjectPrintClassNamePrefixType((PetscObject)lg,viewer);CHKERRQ(ierr);
570   for (i = 0; i < dim; i++) {
571     ierr = PetscViewerASCIIPrintf(viewer, "Line %D>\n", i);CHKERRQ(ierr);
572     for (j = 0; j < nopts; j++) {
573       ierr = PetscViewerASCIIPrintf(viewer, "  X: %g Y: %g\n", (double)lg->x[j*dim+i], (double)lg->y[j*dim+i]);CHKERRQ(ierr);
574     }
575   }
576   PetscFunctionReturn(0);
577 }
578 
579 #undef __FUNCT__
580 #define __FUNCT__ "PetscDrawLGSetOptionsPrefix"
581 /*@C
582    PetscDrawLGSetOptionsPrefix - Sets the prefix used for searching for all
583    PetscDrawLG options in the database.
584 
585    Logically Collective on PetscDrawLG
586 
587    Input Parameter:
588 +  lg - the line graph context
589 -  prefix - the prefix to prepend to all option names
590 
591    Level: advanced
592 
593 .keywords: PetscDrawLG, set, options, prefix, database
594 
595 .seealso: PetscDrawLGSetFromOptions()
596 @*/
597 PetscErrorCode  PetscDrawLGSetOptionsPrefix(PetscDrawLG lg,const char prefix[])
598 {
599   PetscErrorCode ierr;
600 
601   PetscFunctionBegin;
602   if (!lg) PetscFunctionReturn(0);
603   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
604   ierr = PetscObjectSetOptionsPrefix((PetscObject)lg,prefix);CHKERRQ(ierr);
605   PetscFunctionReturn(0);
606 }
607 
608 #undef __FUNCT__
609 #define __FUNCT__ "PetscDrawLGSetFromOptions"
610 /*@
611     PetscDrawLGSetFromOptions - Sets options related to the PetscDrawLG
612 
613     Collective on PetscDrawLG
614 
615     Options Database:
616 
617     Level: intermediate
618 
619     Concepts: line graph^creating
620 
621 .seealso:  PetscDrawLGDestroy(), PetscDrawLGCreate()
622 @*/
623 PetscErrorCode  PetscDrawLGSetFromOptions(PetscDrawLG lg)
624 {
625   PetscErrorCode ierr;
626   PetscBool      flg=PETSC_FALSE, set;
627 
628   PetscFunctionBegin;
629   if (!lg) PetscFunctionReturn(0);
630   PetscValidHeaderSpecific(lg,PETSC_DRAWLG_CLASSID,1);
631 
632   ierr = PetscOptionsGetBool(((PetscObject)lg)->options,NULL,"-lg_use_markers",&flg,&set);CHKERRQ(ierr);
633   if (set) {ierr = PetscDrawLGSetUseMarkers(lg,flg);CHKERRQ(ierr);}
634   PetscFunctionReturn(0);
635 }
636