xref: /petsc/src/sys/classes/viewer/impls/draw/drawv.c (revision 10699b917c2ca523f62b603029bfcc018e13d799)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith #include <../src/sys/classes/viewer/impls/draw/vdraw.h> /*I "petscdraw.h" I*/
3665c2dedSJed Brown #include <petscviewer.h>                                /*I "petscviewer.h" I*/
45c6c1daeSBarry Smith 
5e0877f53SBarry Smith static PetscErrorCode PetscViewerDestroy_Draw(PetscViewer v)
65c6c1daeSBarry Smith {
75c6c1daeSBarry Smith   PetscErrorCode   ierr;
85c6c1daeSBarry Smith   PetscInt         i;
95c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
105c6c1daeSBarry Smith 
115c6c1daeSBarry Smith   PetscFunctionBegin;
125c6c1daeSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Destroying PetscViewer without first restoring singleton");
135c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
145c6c1daeSBarry Smith     ierr = PetscDrawAxisDestroy(&vdraw->drawaxis[i]);CHKERRQ(ierr);
155c6c1daeSBarry Smith     ierr = PetscDrawLGDestroy(&vdraw->drawlg[i]);CHKERRQ(ierr);
165c6c1daeSBarry Smith     ierr = PetscDrawDestroy(&vdraw->draw[i]);CHKERRQ(ierr);
175c6c1daeSBarry Smith   }
185c6c1daeSBarry Smith   ierr = PetscFree(vdraw->display);CHKERRQ(ierr);
195c6c1daeSBarry Smith   ierr = PetscFree(vdraw->title);CHKERRQ(ierr);
205c6c1daeSBarry Smith   ierr = PetscFree3(vdraw->draw,vdraw->drawlg,vdraw->drawaxis);CHKERRQ(ierr);
215c6c1daeSBarry Smith   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
22d1da0b69SBarry Smith   ierr = PetscFree(vdraw->drawtype);CHKERRQ(ierr);
23e5ab1681SLisandro Dalcin   ierr = PetscFree(v->data);CHKERRQ(ierr);
245c6c1daeSBarry Smith   PetscFunctionReturn(0);
255c6c1daeSBarry Smith }
265c6c1daeSBarry Smith 
27e0877f53SBarry Smith static PetscErrorCode PetscViewerFlush_Draw(PetscViewer v)
285c6c1daeSBarry Smith {
295c6c1daeSBarry Smith   PetscErrorCode   ierr;
305c6c1daeSBarry Smith   PetscInt         i;
315c6c1daeSBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)v->data;
325c6c1daeSBarry Smith 
335c6c1daeSBarry Smith   PetscFunctionBegin;
345c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
355b399a63SLisandro Dalcin     if (vdraw->draw[i]) {ierr = PetscDrawFlush(vdraw->draw[i]);CHKERRQ(ierr);}
365c6c1daeSBarry Smith   }
375c6c1daeSBarry Smith   PetscFunctionReturn(0);
385c6c1daeSBarry Smith }
395c6c1daeSBarry Smith 
405c6c1daeSBarry Smith /*@C
415c6c1daeSBarry Smith     PetscViewerDrawGetDraw - Returns PetscDraw object from PetscViewer object.
425c6c1daeSBarry Smith     This PetscDraw object may then be used to perform graphics using
435c6c1daeSBarry Smith     PetscDrawXXX() commands.
445c6c1daeSBarry Smith 
45d94959e9SLisandro Dalcin     Collective on PetscViewer
465c6c1daeSBarry Smith 
475c6c1daeSBarry Smith     Input Parameters:
485c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
495c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
505c6c1daeSBarry Smith 
515c6c1daeSBarry Smith     Ouput Parameter:
525c6c1daeSBarry Smith .   draw - the draw object
535c6c1daeSBarry Smith 
545c6c1daeSBarry Smith     Level: intermediate
555c6c1daeSBarry Smith 
565c6c1daeSBarry Smith 
575c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
585c6c1daeSBarry Smith @*/
595c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDraw(PetscViewer viewer,PetscInt windownumber,PetscDraw *draw)
605c6c1daeSBarry Smith {
61e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
625c6c1daeSBarry Smith   PetscErrorCode   ierr;
635c6c1daeSBarry Smith   PetscBool        isdraw;
645c6c1daeSBarry Smith 
655c6c1daeSBarry Smith   PetscFunctionBegin;
665c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
67e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
685c6c1daeSBarry Smith   if (draw) PetscValidPointer(draw,3);
695c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
705c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
715c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
72e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
73e5ab1681SLisandro Dalcin 
745c6c1daeSBarry Smith   windownumber += vdraw->draw_base;
755c6c1daeSBarry Smith   if (windownumber >= vdraw->draw_max) {
765c6c1daeSBarry Smith     /* allocate twice as many slots as needed */
775c6c1daeSBarry Smith     PetscInt      draw_max  = vdraw->draw_max;
785c6c1daeSBarry Smith     PetscDraw     *tdraw    = vdraw->draw;
795c6c1daeSBarry Smith     PetscDrawLG   *drawlg   = vdraw->drawlg;
805c6c1daeSBarry Smith     PetscDrawAxis *drawaxis = vdraw->drawaxis;
815c6c1daeSBarry Smith 
825c6c1daeSBarry Smith     vdraw->draw_max = 2*windownumber;
83a297a907SKarl Rupp 
841795a4d1SJed Brown     ierr = PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);CHKERRQ(ierr);
85580bdb30SBarry Smith     ierr = PetscArraycpy(vdraw->draw,tdraw,draw_max);CHKERRQ(ierr);
86580bdb30SBarry Smith     ierr = PetscArraycpy(vdraw->drawlg,drawlg,draw_max);CHKERRQ(ierr);
87580bdb30SBarry Smith     ierr = PetscArraycpy(vdraw->drawaxis,drawaxis,draw_max);CHKERRQ(ierr);
885c6c1daeSBarry Smith     ierr = PetscFree3(tdraw,drawlg,drawaxis);CHKERRQ(ierr);
895c6c1daeSBarry Smith   }
905c6c1daeSBarry Smith 
915c6c1daeSBarry Smith   if (!vdraw->draw[windownumber]) {
92e5ab1681SLisandro Dalcin     char *title = vdraw->title, tmp_str[128];
9310f3a0f4SLisandro Dalcin     if (windownumber) {
9410f3a0f4SLisandro Dalcin       ierr = PetscSNPrintf(tmp_str,sizeof(tmp_str),"%s:%d",vdraw->title?vdraw->title:"",windownumber);CHKERRQ(ierr);
955c6c1daeSBarry Smith       title = tmp_str;
965c6c1daeSBarry Smith     }
97ce94432eSBarry Smith     ierr = PetscDrawCreate(PetscObjectComm((PetscObject)viewer),vdraw->display,title,PETSC_DECIDE,PETSC_DECIDE,vdraw->w,vdraw->h,&vdraw->draw[windownumber]);CHKERRQ(ierr);
98e5ab1681SLisandro Dalcin     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->draw[windownumber]);CHKERRQ(ierr);
99d1da0b69SBarry Smith     if (vdraw->drawtype) {
100d1da0b69SBarry Smith       ierr = PetscDrawSetType(vdraw->draw[windownumber],vdraw->drawtype);CHKERRQ(ierr);
101d1da0b69SBarry Smith     }
102afe78b3cSBarry Smith     ierr = PetscDrawSetPause(vdraw->draw[windownumber],vdraw->pause);CHKERRQ(ierr);
103d94959e9SLisandro Dalcin     ierr = PetscDrawSetOptionsPrefix(vdraw->draw[windownumber],((PetscObject)viewer)->prefix);CHKERRQ(ierr);
1045c6c1daeSBarry Smith     ierr = PetscDrawSetFromOptions(vdraw->draw[windownumber]);CHKERRQ(ierr);
1055c6c1daeSBarry Smith   }
1065c6c1daeSBarry Smith   if (draw) *draw = vdraw->draw[windownumber];
1075c6c1daeSBarry Smith   if (draw) PetscValidHeaderSpecific(*draw,PETSC_DRAW_CLASSID,-1);
1085c6c1daeSBarry Smith   PetscFunctionReturn(0);
1095c6c1daeSBarry Smith }
1105c6c1daeSBarry Smith 
1115c6c1daeSBarry Smith /*@C
1125c6c1daeSBarry Smith     PetscViewerDrawBaseAdd - add to the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1135c6c1daeSBarry Smith 
114d94959e9SLisandro Dalcin     Logically Collective on PetscViewer
1155c6c1daeSBarry Smith 
1165c6c1daeSBarry Smith     Input Parameters:
1175c6c1daeSBarry Smith +  viewer - the PetscViewer (created with PetscViewerDrawOpen())
1185c6c1daeSBarry Smith -   windownumber - how much to add to the base
1195c6c1daeSBarry Smith 
1205c6c1daeSBarry Smith     Level: developer
1215c6c1daeSBarry Smith 
1225c6c1daeSBarry Smith 
1235c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseSet()
1245c6c1daeSBarry Smith @*/
1255c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseAdd(PetscViewer viewer,PetscInt windownumber)
1265c6c1daeSBarry Smith {
127e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
1285c6c1daeSBarry Smith   PetscErrorCode   ierr;
1295c6c1daeSBarry Smith   PetscBool        isdraw;
1305c6c1daeSBarry Smith 
1315c6c1daeSBarry Smith   PetscFunctionBegin;
1325c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
133e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
1345c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1355c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
136e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
137e5ab1681SLisandro Dalcin 
1385c6c1daeSBarry Smith   if (windownumber + vdraw->draw_base < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber+vdraw->draw_base);
1395c6c1daeSBarry Smith   vdraw->draw_base += windownumber;
1405c6c1daeSBarry Smith   PetscFunctionReturn(0);
1415c6c1daeSBarry Smith }
1425c6c1daeSBarry Smith 
1435c6c1daeSBarry Smith /*@C
1445c6c1daeSBarry Smith     PetscViewerDrawBaseSet - sets the base integer that is added to the windownumber passed to PetscViewerDrawGetDraw()
1455c6c1daeSBarry Smith 
146d94959e9SLisandro Dalcin     Logically Collective on PetscViewer
1475c6c1daeSBarry Smith 
1485c6c1daeSBarry Smith     Input Parameters:
1495c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
1505c6c1daeSBarry Smith -   windownumber - value to set the base
1515c6c1daeSBarry Smith 
1525c6c1daeSBarry Smith     Level: developer
1535c6c1daeSBarry Smith 
1545c6c1daeSBarry Smith 
1555c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PetscViewerDrawBaseAdd()
1565c6c1daeSBarry Smith @*/
1575c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawBaseSet(PetscViewer viewer,PetscInt windownumber)
1585c6c1daeSBarry Smith {
159e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
1605c6c1daeSBarry Smith   PetscErrorCode   ierr;
1615c6c1daeSBarry Smith   PetscBool        isdraw;
1625c6c1daeSBarry Smith 
1635c6c1daeSBarry Smith   PetscFunctionBegin;
1645c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
165e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
1665c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
1675c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
168e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
169e5ab1681SLisandro Dalcin 
1705c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Resulting base %D cannot be negative",windownumber);
1715c6c1daeSBarry Smith   vdraw->draw_base = windownumber;
1725c6c1daeSBarry Smith   PetscFunctionReturn(0);
1735c6c1daeSBarry Smith }
1745c6c1daeSBarry Smith 
1755c6c1daeSBarry Smith /*@C
1765c6c1daeSBarry Smith     PetscViewerDrawGetDrawLG - Returns PetscDrawLG object from PetscViewer object.
1775c6c1daeSBarry Smith     This PetscDrawLG object may then be used to perform graphics using
1785c6c1daeSBarry Smith     PetscDrawLGXXX() commands.
1795c6c1daeSBarry Smith 
180d94959e9SLisandro Dalcin     Collective on PetscViewer
1815c6c1daeSBarry Smith 
1825c6c1daeSBarry Smith     Input Parameter:
1835c6c1daeSBarry Smith +   PetscViewer - the PetscViewer (created with PetscViewerDrawOpen())
1845c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
1855c6c1daeSBarry Smith 
1865c6c1daeSBarry Smith     Ouput Parameter:
1875c6c1daeSBarry Smith .   draw - the draw line graph object
1885c6c1daeSBarry Smith 
1895c6c1daeSBarry Smith     Level: intermediate
1905c6c1daeSBarry Smith 
1915c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
1925c6c1daeSBarry Smith @*/
1935c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawLG(PetscViewer viewer,PetscInt windownumber,PetscDrawLG *drawlg)
1945c6c1daeSBarry Smith {
1955c6c1daeSBarry Smith   PetscErrorCode   ierr;
1965c6c1daeSBarry Smith   PetscBool        isdraw;
197e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith   PetscFunctionBegin;
2005c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
201e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
2025c6c1daeSBarry Smith   PetscValidPointer(drawlg,3);
2035c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
2045c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
2055c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
206e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
2075c6c1daeSBarry Smith 
2085c6c1daeSBarry Smith   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
2090298fd71SBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr);
2105c6c1daeSBarry Smith   }
2115c6c1daeSBarry Smith   if (!vdraw->drawlg[windownumber+vdraw->draw_base]) {
2125c6c1daeSBarry Smith     ierr = PetscDrawLGCreate(vdraw->draw[windownumber+vdraw->draw_base],1,&vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2133bb1ff40SBarry Smith     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
214de1a4edeSLisandro Dalcin     ierr = PetscDrawLGSetFromOptions(vdraw->drawlg[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2155c6c1daeSBarry Smith   }
2165c6c1daeSBarry Smith   *drawlg = vdraw->drawlg[windownumber+vdraw->draw_base];
2175c6c1daeSBarry Smith   PetscFunctionReturn(0);
2185c6c1daeSBarry Smith }
2195c6c1daeSBarry Smith 
2205c6c1daeSBarry Smith /*@C
2215c6c1daeSBarry Smith     PetscViewerDrawGetDrawAxis - Returns PetscDrawAxis object from PetscViewer object.
2225c6c1daeSBarry Smith     This PetscDrawAxis object may then be used to perform graphics using
2235c6c1daeSBarry Smith     PetscDrawAxisXXX() commands.
2245c6c1daeSBarry Smith 
225d94959e9SLisandro Dalcin     Collective on PetscViewer
2265c6c1daeSBarry Smith 
2275c6c1daeSBarry Smith     Input Parameter:
2285c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen()
2295c6c1daeSBarry Smith -   windownumber - indicates which subwindow (usually 0)
2305c6c1daeSBarry Smith 
2315c6c1daeSBarry Smith     Ouput Parameter:
2325c6c1daeSBarry Smith .   drawaxis - the draw axis object
2335c6c1daeSBarry Smith 
2345c6c1daeSBarry Smith     Level: advanced
2355c6c1daeSBarry Smith 
2365c6c1daeSBarry Smith .seealso: PetscViewerDrawGetDraw(), PetscViewerDrawGetLG(), PetscViewerDrawOpen()
2375c6c1daeSBarry Smith @*/
2385c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetDrawAxis(PetscViewer viewer,PetscInt windownumber,PetscDrawAxis *drawaxis)
2395c6c1daeSBarry Smith {
2405c6c1daeSBarry Smith   PetscErrorCode   ierr;
2415c6c1daeSBarry Smith   PetscBool        isdraw;
242e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
2435c6c1daeSBarry Smith 
2445c6c1daeSBarry Smith   PetscFunctionBegin;
2455c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
246e5ab1681SLisandro Dalcin   PetscValidLogicalCollectiveInt(viewer,windownumber,2);
2475c6c1daeSBarry Smith   PetscValidPointer(drawaxis,3);
2485c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
2495c6c1daeSBarry Smith   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
2505c6c1daeSBarry Smith   if (windownumber < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Window number cannot be negative");
251e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
2525c6c1daeSBarry Smith 
2535c6c1daeSBarry Smith   if (windownumber+vdraw->draw_base >= vdraw->draw_max || !vdraw->draw[windownumber+vdraw->draw_base]) {
2540298fd71SBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,windownumber,NULL);CHKERRQ(ierr);
2555c6c1daeSBarry Smith   }
2565c6c1daeSBarry Smith   if (!vdraw->drawaxis[windownumber+vdraw->draw_base]) {
2575c6c1daeSBarry Smith     ierr = PetscDrawAxisCreate(vdraw->draw[windownumber+vdraw->draw_base],&vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2583bb1ff40SBarry Smith     ierr = PetscLogObjectParent((PetscObject)viewer,(PetscObject)vdraw->drawaxis[windownumber+vdraw->draw_base]);CHKERRQ(ierr);
2595c6c1daeSBarry Smith   }
2605c6c1daeSBarry Smith   *drawaxis = vdraw->drawaxis[windownumber+vdraw->draw_base];
2615c6c1daeSBarry Smith   PetscFunctionReturn(0);
2625c6c1daeSBarry Smith }
2635c6c1daeSBarry Smith 
2645c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawResize(PetscViewer v,int w,int h)
2655c6c1daeSBarry Smith {
266e5ab1681SLisandro Dalcin   PetscErrorCode   ierr;
267e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
268e5ab1681SLisandro Dalcin   PetscBool        isdraw;
2695c6c1daeSBarry Smith 
2705c6c1daeSBarry Smith   PetscFunctionBegin;
271e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
272e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
273e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
274e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
275e5ab1681SLisandro Dalcin 
276e5ab1681SLisandro Dalcin   if (w >= 1) vdraw->w = w;
277e5ab1681SLisandro Dalcin   if (h >= 1) vdraw->h = h;
2785c6c1daeSBarry Smith   PetscFunctionReturn(0);
2795c6c1daeSBarry Smith }
2805c6c1daeSBarry Smith 
2815c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetInfo(PetscViewer v,const char display[],const char title[],int x,int y,int w,int h)
2825c6c1daeSBarry Smith {
2835c6c1daeSBarry Smith   PetscErrorCode   ierr;
284e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
285e5ab1681SLisandro Dalcin   PetscBool        isdraw;
2865c6c1daeSBarry Smith 
2875c6c1daeSBarry Smith   PetscFunctionBegin;
288e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
289e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
290e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
291e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
292e5ab1681SLisandro Dalcin 
2935c6c1daeSBarry Smith   ierr = PetscStrallocpy(display,&vdraw->display);CHKERRQ(ierr);
2945c6c1daeSBarry Smith   ierr = PetscStrallocpy(title,&vdraw->title);CHKERRQ(ierr);
295e5ab1681SLisandro Dalcin   if (w >= 1) vdraw->w = w;
296e5ab1681SLisandro Dalcin   if (h >= 1) vdraw->h = h;
2975c6c1daeSBarry Smith   PetscFunctionReturn(0);
2985c6c1daeSBarry Smith }
2995c6c1daeSBarry Smith 
300d1da0b69SBarry Smith PetscErrorCode  PetscViewerDrawSetDrawType(PetscViewer v,PetscDrawType drawtype)
301d1da0b69SBarry Smith {
302d1da0b69SBarry Smith   PetscErrorCode   ierr;
303e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
304e5ab1681SLisandro Dalcin   PetscBool        isdraw;
305d1da0b69SBarry Smith 
306d1da0b69SBarry Smith   PetscFunctionBegin;
307e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
308e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
309e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
310e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
311e5ab1681SLisandro Dalcin 
312d1da0b69SBarry Smith   ierr = PetscFree(vdraw->drawtype);CHKERRQ(ierr);
313d1da0b69SBarry Smith   ierr = PetscStrallocpy(drawtype,(char**)&vdraw->drawtype);CHKERRQ(ierr);
314d1da0b69SBarry Smith   PetscFunctionReturn(0);
315d1da0b69SBarry Smith }
316d1da0b69SBarry Smith 
3171f49e1f7SLisandro Dalcin PetscErrorCode PetscViewerDrawGetDrawType(PetscViewer v,PetscDrawType *drawtype)
3181f49e1f7SLisandro Dalcin {
3191f49e1f7SLisandro Dalcin   PetscErrorCode   ierr;
3201f49e1f7SLisandro Dalcin   PetscViewer_Draw *vdraw;
3211f49e1f7SLisandro Dalcin   PetscBool        isdraw;
3221f49e1f7SLisandro Dalcin 
3231f49e1f7SLisandro Dalcin   PetscFunctionBegin;
3241f49e1f7SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
3251f49e1f7SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
3261f49e1f7SLisandro Dalcin   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
3271f49e1f7SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
3281f49e1f7SLisandro Dalcin 
3291f49e1f7SLisandro Dalcin   *drawtype = vdraw->drawtype;
3301f49e1f7SLisandro Dalcin   PetscFunctionReturn(0);
3311f49e1f7SLisandro Dalcin }
3321f49e1f7SLisandro Dalcin 
333f55236e4SLisandro Dalcin PetscErrorCode PetscViewerDrawSetTitle(PetscViewer v,const char title[])
334f55236e4SLisandro Dalcin {
335f55236e4SLisandro Dalcin   PetscErrorCode   ierr;
336f55236e4SLisandro Dalcin   PetscViewer_Draw *vdraw;
337f55236e4SLisandro Dalcin   PetscBool        isdraw;
338f55236e4SLisandro Dalcin 
339f55236e4SLisandro Dalcin   PetscFunctionBegin;
340f55236e4SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
341f55236e4SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
342f55236e4SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
343f55236e4SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
344f55236e4SLisandro Dalcin 
345f55236e4SLisandro Dalcin   ierr = PetscFree(vdraw->title);CHKERRQ(ierr);
346f55236e4SLisandro Dalcin   ierr = PetscStrallocpy(title,&vdraw->title);CHKERRQ(ierr);
347f55236e4SLisandro Dalcin   PetscFunctionReturn(0);
348f55236e4SLisandro Dalcin }
349f55236e4SLisandro Dalcin 
350f55236e4SLisandro Dalcin PetscErrorCode PetscViewerDrawGetTitle(PetscViewer v,const char *title[])
351f55236e4SLisandro Dalcin {
352f55236e4SLisandro Dalcin   PetscErrorCode   ierr;
353f55236e4SLisandro Dalcin   PetscViewer_Draw *vdraw;
354f55236e4SLisandro Dalcin   PetscBool        isdraw;
355f55236e4SLisandro Dalcin 
356f55236e4SLisandro Dalcin   PetscFunctionBegin;
357f55236e4SLisandro Dalcin   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
358f55236e4SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)v,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
359f55236e4SLisandro Dalcin   if (!isdraw) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must be draw type PetscViewer");
360f55236e4SLisandro Dalcin   vdraw = (PetscViewer_Draw*)v->data;
361f55236e4SLisandro Dalcin 
362f55236e4SLisandro Dalcin   *title = vdraw->title;
363f55236e4SLisandro Dalcin   PetscFunctionReturn(0);
364f55236e4SLisandro Dalcin }
365f55236e4SLisandro Dalcin 
3665c6c1daeSBarry Smith /*@C
3675c6c1daeSBarry Smith    PetscViewerDrawOpen - Opens a window for use as a PetscViewer. If you want to
3685c6c1daeSBarry Smith    do graphics in this window, you must call PetscViewerDrawGetDraw() and
3695c6c1daeSBarry Smith    perform the graphics on the PetscDraw object.
3705c6c1daeSBarry Smith 
371d083f849SBarry Smith    Collective
3725c6c1daeSBarry Smith 
3735c6c1daeSBarry Smith    Input Parameters:
3745c6c1daeSBarry Smith +  comm - communicator that will share window
3755c6c1daeSBarry Smith .  display - the X display on which to open, or null for the local machine
3765c6c1daeSBarry Smith .  title - the title to put in the title bar, or null for no title
3775c6c1daeSBarry Smith .  x, y - the screen coordinates of the upper left corner of window, or use PETSC_DECIDE
3785c6c1daeSBarry Smith -  w, h - window width and height in pixels, or may use PETSC_DECIDE or PETSC_DRAW_FULL_SIZE, PETSC_DRAW_HALF_SIZE,
3795c6c1daeSBarry Smith           PETSC_DRAW_THIRD_SIZE, PETSC_DRAW_QUARTER_SIZE
3805c6c1daeSBarry Smith 
3815c6c1daeSBarry Smith    Output Parameters:
3825c6c1daeSBarry Smith . viewer - the PetscViewer
3835c6c1daeSBarry Smith 
3845c6c1daeSBarry Smith    Format Options:
3855c6c1daeSBarry Smith +  PETSC_VIEWER_DRAW_BASIC - displays with basic format
3865c6c1daeSBarry Smith -  PETSC_VIEWER_DRAW_LG    - displays using a line graph
3875c6c1daeSBarry Smith 
3885c6c1daeSBarry Smith    Options Database Keys:
389*10699b91SBarry Smith +  -draw_type - use x or null
3905c6c1daeSBarry Smith .  -nox - Disables all x-windows output
3915c6c1daeSBarry Smith .  -display <name> - Specifies name of machine for the X display
3925c6c1daeSBarry Smith .  -geometry <x,y,w,h> - allows setting the window location and size
3935c6c1daeSBarry Smith -  -draw_pause <pause> - Sets time (in seconds) that the
3945c6c1daeSBarry Smith      program pauses after PetscDrawPause() has been called
3955c6c1daeSBarry Smith      (0 is default, -1 implies until user input).
3965c6c1daeSBarry Smith 
3975c6c1daeSBarry Smith    Level: beginner
3985c6c1daeSBarry Smith 
399*10699b91SBarry Smith    Notes:
400*10699b91SBarry Smith      PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual pages for PetscDrawCreate()
401*10699b91SBarry Smith 
4025c6c1daeSBarry Smith    Note for Fortran Programmers:
4035c6c1daeSBarry Smith    Whenever indicating null character data in a Fortran code,
404cf90aa19SBarry Smith    PETSC_NULL_CHARACTER must be employed; using NULL is not
405cf90aa19SBarry Smith    correct for character data!  Thus, PETSC_NULL_CHARACTER can be
4065c6c1daeSBarry Smith    used for the display and title input parameters.
4075c6c1daeSBarry Smith 
4085c6c1daeSBarry Smith 
4095c6c1daeSBarry Smith 
4105c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
4115c6c1daeSBarry Smith           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
4125c6c1daeSBarry Smith @*/
4135c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
4145c6c1daeSBarry Smith {
4155c6c1daeSBarry Smith   PetscErrorCode ierr;
4165c6c1daeSBarry Smith 
4175c6c1daeSBarry Smith   PetscFunctionBegin;
4185c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
4195c6c1daeSBarry Smith   ierr = PetscViewerSetType(*viewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
4205c6c1daeSBarry Smith   ierr = PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);CHKERRQ(ierr);
4215c6c1daeSBarry Smith   PetscFunctionReturn(0);
4225c6c1daeSBarry Smith }
4235c6c1daeSBarry Smith 
424a9db196aSBarry Smith #include <petsc/private/drawimpl.h>
425a9db196aSBarry Smith 
4263f08860eSBarry Smith PetscErrorCode PetscViewerGetSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4275c6c1daeSBarry Smith {
4285c6c1daeSBarry Smith   PetscErrorCode   ierr;
4295c6c1daeSBarry Smith   PetscMPIInt      rank;
4305c6c1daeSBarry Smith   PetscInt         i;
431c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4325c6c1daeSBarry Smith 
4335c6c1daeSBarry Smith   PetscFunctionBegin;
4343f08860eSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get SubViewer without first restoring previous");
4355c6c1daeSBarry Smith   /* only processor zero can use the PetscViewer draw singleton */
436fefe69c3SStefano Zampini   if (sviewer) *sviewer = NULL;
437ffc4695bSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRMPI(ierr);
4385c6c1daeSBarry Smith   if (!rank) {
439e5afcf28SBarry Smith     PetscMPIInt flg;
440a9db196aSBarry Smith     PetscDraw   draw,sdraw;
441e5afcf28SBarry Smith 
442ffc4695bSBarry Smith     ierr = MPI_Comm_compare(PETSC_COMM_SELF,comm,&flg);CHKERRMPI(ierr);
443e5afcf28SBarry Smith     if (flg != MPI_IDENT && flg != MPI_CONGRUENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"PetscViewerGetSubViewer() for PETSCVIEWERDRAW requires a singleton MPI_Comm");
444e5afcf28SBarry Smith     ierr = PetscViewerCreate(comm,sviewer);CHKERRQ(ierr);
4455c6c1daeSBarry Smith     ierr = PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
446c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
447c6228bbaSLisandro Dalcin     (*sviewer)->format = viewer->format;
448c6228bbaSLisandro Dalcin     for (i=0; i<vdraw->draw_max; i++) { /* XXX this is wrong if svdraw->draw_max (initially 5) < vdraw->draw_max */
449c6228bbaSLisandro Dalcin       if (vdraw->draw[i]) {ierr = PetscDrawGetSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);}
4505c6c1daeSBarry Smith     }
451a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
452a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(*sviewer,0,&sdraw);CHKERRQ(ierr);
453a9db196aSBarry Smith     if (draw->savefilename) {
454a9db196aSBarry Smith       ierr = PetscDrawSetSave(sdraw,draw->savefilename);CHKERRQ(ierr);
455a9db196aSBarry Smith       sdraw->savefilecount = draw->savefilecount;
456a9db196aSBarry Smith       sdraw->savesinglefile = draw->savesinglefile;
457a9db196aSBarry Smith       sdraw->savemoviefps = draw->savemoviefps;
458a9db196aSBarry Smith       sdraw->saveonclear = draw->saveonclear;
459a9db196aSBarry Smith       sdraw->saveonflush = draw->saveonflush;
460a9db196aSBarry Smith     }
461a9db196aSBarry Smith     if (draw->savefinalfilename) {ierr = PetscDrawSetSaveFinalImage(sdraw,draw->savefinalfilename);CHKERRQ(ierr);}
462a9db196aSBarry Smith   } else {
463a9db196aSBarry Smith     PetscDraw draw;
464a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
4655c6c1daeSBarry Smith   }
4665c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_TRUE;
4675c6c1daeSBarry Smith   PetscFunctionReturn(0);
4685c6c1daeSBarry Smith }
4695c6c1daeSBarry Smith 
4703f08860eSBarry Smith PetscErrorCode PetscViewerRestoreSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4715c6c1daeSBarry Smith {
4725c6c1daeSBarry Smith   PetscErrorCode   ierr;
4735c6c1daeSBarry Smith   PetscMPIInt      rank;
4745c6c1daeSBarry Smith   PetscInt         i;
475c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4765c6c1daeSBarry Smith 
4775c6c1daeSBarry Smith   PetscFunctionBegin;
4785c6c1daeSBarry Smith   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
479ffc4695bSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRMPI(ierr);
4805c6c1daeSBarry Smith   if (!rank) {
481a9db196aSBarry Smith     PetscDraw draw,sdraw;
482a9db196aSBarry Smith 
483a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
484a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(*sviewer,0,&sdraw);CHKERRQ(ierr);
485a9db196aSBarry Smith     if (draw->savefilename) {
486a9db196aSBarry Smith       draw->savefilecount = sdraw->savefilecount;
48755b25c41SPierre Jolivet       ierr = MPI_Bcast(&draw->savefilecount,1,MPIU_INT,0,PetscObjectComm((PetscObject)draw));CHKERRMPI(ierr);
488a9db196aSBarry Smith     }
489c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
4905c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
491c6228bbaSLisandro Dalcin       if (vdraw->draw[i] && svdraw->draw[i]) {
492c6228bbaSLisandro Dalcin         ierr = PetscDrawRestoreSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);
4935c6c1daeSBarry Smith       }
4945c6c1daeSBarry Smith     }
495c6228bbaSLisandro Dalcin     ierr = PetscFree3(svdraw->draw,svdraw->drawlg,svdraw->drawaxis);CHKERRQ(ierr);
4965c6c1daeSBarry Smith     ierr = PetscFree((*sviewer)->data);CHKERRQ(ierr);
4975c6c1daeSBarry Smith     ierr = PetscHeaderDestroy(sviewer);CHKERRQ(ierr);
498a9db196aSBarry Smith   } else {
499a9db196aSBarry Smith     PetscDraw draw;
500a9db196aSBarry Smith 
501a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
502a9db196aSBarry Smith     if (draw->savefilename) {
50355b25c41SPierre Jolivet       ierr = MPI_Bcast(&draw->savefilecount,1,MPIU_INT,0,PetscObjectComm((PetscObject)draw));CHKERRMPI(ierr);
5045c6c1daeSBarry Smith     }
505a9db196aSBarry Smith   }
506a9db196aSBarry Smith 
5075c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
5085c6c1daeSBarry Smith   PetscFunctionReturn(0);
5095c6c1daeSBarry Smith }
5105c6c1daeSBarry Smith 
5114416b707SBarry Smith PetscErrorCode PetscViewerSetFromOptions_Draw(PetscOptionItems *PetscOptionsObject,PetscViewer v)
512e9457bf7SBarry Smith {
513e9457bf7SBarry Smith   PetscErrorCode ierr;
514e9457bf7SBarry Smith   PetscReal      bounds[16];
515e9457bf7SBarry Smith   PetscInt       nbounds = 16;
516e9457bf7SBarry Smith   PetscBool      flg;
517e9457bf7SBarry Smith 
518e9457bf7SBarry Smith   PetscFunctionBegin;
519e55864a3SBarry Smith   ierr = PetscOptionsHead(PetscOptionsObject,"Draw PetscViewer Options");CHKERRQ(ierr);
520e9457bf7SBarry Smith   ierr = PetscOptionsRealArray("-draw_bounds","Bounds to put on plots axis","PetscViewerDrawSetBounds",bounds,&nbounds,&flg);CHKERRQ(ierr);
521e9457bf7SBarry Smith   if (flg) {
522e9457bf7SBarry Smith     ierr = PetscViewerDrawSetBounds(v,nbounds/2,bounds);CHKERRQ(ierr);
523e9457bf7SBarry Smith   }
524e9457bf7SBarry Smith   ierr = PetscOptionsTail();CHKERRQ(ierr);
525e9457bf7SBarry Smith   PetscFunctionReturn(0);
526e9457bf7SBarry Smith }
527e9457bf7SBarry Smith 
5280076e027SBarry Smith PetscErrorCode PetscViewerView_Draw(PetscViewer viewer,PetscViewer v)
5290076e027SBarry Smith {
5300076e027SBarry Smith   PetscErrorCode   ierr;
5310076e027SBarry Smith   PetscDraw        draw;
5320076e027SBarry Smith   PetscInt         i;
5330076e027SBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
5340076e027SBarry Smith 
5350076e027SBarry Smith   PetscFunctionBegin;
5360076e027SBarry Smith   /*  If the PetscViewer has just been created then no vdraw->draw yet
5370076e027SBarry Smith       exists so this will not actually call the viewer on any draws. */
5380076e027SBarry Smith   for (i=0; i<vdraw->draw_base; i++) {
5390076e027SBarry Smith     if (vdraw->draw[i]) {
5400076e027SBarry Smith       ierr = PetscViewerDrawGetDraw(viewer,i,&draw);CHKERRQ(ierr);
5410076e027SBarry Smith       ierr = PetscDrawView(draw,v);CHKERRQ(ierr);
5420076e027SBarry Smith     }
5430076e027SBarry Smith   }
5440076e027SBarry Smith   PetscFunctionReturn(0);
5450076e027SBarry Smith }
5460076e027SBarry Smith 
5478556b5ebSBarry Smith /*MC
5488556b5ebSBarry Smith    PETSCVIEWERDRAW - A viewer that generates graphics, either to the screen or a file
5498556b5ebSBarry Smith 
5508556b5ebSBarry Smith 
5518556b5ebSBarry Smith .seealso:  PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PETSC_VIEWER_DRAW_(),PETSC_VIEWER_DRAW_SELF, PETSC_VIEWER_DRAW_WORLD,
5528556b5ebSBarry Smith            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY,
5538556b5ebSBarry Smith            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
5548556b5ebSBarry Smith            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()
5558556b5ebSBarry Smith 
5561b266c99SBarry Smith   Level: beginner
5571b266c99SBarry Smith 
5588556b5ebSBarry Smith M*/
5598cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerCreate_Draw(PetscViewer viewer)
5605c6c1daeSBarry Smith {
5615c6c1daeSBarry Smith   PetscErrorCode   ierr;
5625c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
5635c6c1daeSBarry Smith 
5645c6c1daeSBarry Smith   PetscFunctionBegin;
565b00a9115SJed Brown   ierr = PetscNewLog(viewer,&vdraw);CHKERRQ(ierr);
5665c6c1daeSBarry Smith   viewer->data = (void*)vdraw;
5675c6c1daeSBarry Smith 
5685c6c1daeSBarry Smith   viewer->ops->flush            = PetscViewerFlush_Draw;
5690076e027SBarry Smith   viewer->ops->view             = PetscViewerView_Draw;
5705c6c1daeSBarry Smith   viewer->ops->destroy          = PetscViewerDestroy_Draw;
571e9457bf7SBarry Smith   viewer->ops->setfromoptions   = PetscViewerSetFromOptions_Draw;
572559f443fSBarry Smith   viewer->ops->getsubviewer     = PetscViewerGetSubViewer_Draw;
573559f443fSBarry Smith   viewer->ops->restoresubviewer = PetscViewerRestoreSubViewer_Draw;
5745c6c1daeSBarry Smith 
5755c6c1daeSBarry Smith   /* these are created on the fly if requested */
5765c6c1daeSBarry Smith   vdraw->draw_max  = 5;
5775c6c1daeSBarry Smith   vdraw->draw_base = 0;
578ccad63c3SBarry Smith   vdraw->w         = PETSC_DECIDE;
579ccad63c3SBarry Smith   vdraw->h         = PETSC_DECIDE;
580a297a907SKarl Rupp 
5811795a4d1SJed Brown   ierr = PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);CHKERRQ(ierr);
5825c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
5835c6c1daeSBarry Smith   PetscFunctionReturn(0);
5845c6c1daeSBarry Smith }
5855c6c1daeSBarry Smith 
5865c6c1daeSBarry Smith /*@
5875c6c1daeSBarry Smith     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.
5885c6c1daeSBarry Smith 
5895c6c1daeSBarry Smith     Not Collective
5905c6c1daeSBarry Smith 
5915c6c1daeSBarry Smith     Input Parameter:
5925c6c1daeSBarry Smith .  viewer - the PetscViewer
5935c6c1daeSBarry Smith 
5945c6c1daeSBarry Smith     Level: intermediate
5955c6c1daeSBarry Smith 
5965c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5975c6c1daeSBarry Smith 
5985c6c1daeSBarry Smith @*/
5995c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
6005c6c1daeSBarry Smith {
6015c6c1daeSBarry Smith   PetscErrorCode   ierr;
6025c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
603e5ab1681SLisandro Dalcin   PetscBool        isdraw;
604e5ab1681SLisandro Dalcin   PetscInt         i;
6055c6c1daeSBarry Smith 
6065c6c1daeSBarry Smith   PetscFunctionBegin;
607e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6085c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
609e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
6105c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
611e5ab1681SLisandro Dalcin 
6125c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6135c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawClear(vdraw->draw[i]);CHKERRQ(ierr);}
6145c6c1daeSBarry Smith   }
6155c6c1daeSBarry Smith   PetscFunctionReturn(0);
6165c6c1daeSBarry Smith }
6175c6c1daeSBarry Smith 
6185c6c1daeSBarry Smith /*@
6195c6c1daeSBarry Smith     PetscViewerDrawGetPause - Gets a pause for the first present draw
6205c6c1daeSBarry Smith 
6215c6c1daeSBarry Smith     Not Collective
6225c6c1daeSBarry Smith 
6235c6c1daeSBarry Smith     Input Parameter:
6245c6c1daeSBarry Smith .  viewer - the PetscViewer
6255c6c1daeSBarry Smith 
6265c6c1daeSBarry Smith     Output Parameter:
6275c6c1daeSBarry Smith .  pause - the pause value
6285c6c1daeSBarry Smith 
6295c6c1daeSBarry Smith     Level: intermediate
6305c6c1daeSBarry Smith 
6315c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6325c6c1daeSBarry Smith 
6335c6c1daeSBarry Smith @*/
6345c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
6355c6c1daeSBarry Smith {
6365c6c1daeSBarry Smith   PetscErrorCode   ierr;
6375c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
638e5ab1681SLisandro Dalcin   PetscBool        isdraw;
639e5ab1681SLisandro Dalcin   PetscInt         i;
6405c6c1daeSBarry Smith   PetscDraw        draw;
6415c6c1daeSBarry Smith 
6425c6c1daeSBarry Smith   PetscFunctionBegin;
643e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6445c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
645e5ab1681SLisandro Dalcin   if (!isdraw) {*pause = 0.0; PetscFunctionReturn(0);}
6465c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
647e5ab1681SLisandro Dalcin 
6485c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6495c6c1daeSBarry Smith     if (vdraw->draw[i]) {
6505c6c1daeSBarry Smith       ierr = PetscDrawGetPause(vdraw->draw[i],pause);CHKERRQ(ierr);
6515c6c1daeSBarry Smith       PetscFunctionReturn(0);
6525c6c1daeSBarry Smith     }
6535c6c1daeSBarry Smith   }
6545c6c1daeSBarry Smith   /* none exist yet so create one and get its pause */
6555c6c1daeSBarry Smith   ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
656e5ab1681SLisandro Dalcin   ierr = PetscDrawGetPause(draw,pause);CHKERRQ(ierr);
6575c6c1daeSBarry Smith   PetscFunctionReturn(0);
6585c6c1daeSBarry Smith }
6595c6c1daeSBarry Smith 
6605c6c1daeSBarry Smith /*@
6615c6c1daeSBarry Smith     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer
6625c6c1daeSBarry Smith 
6635c6c1daeSBarry Smith     Not Collective
6645c6c1daeSBarry Smith 
6655c6c1daeSBarry Smith     Input Parameters:
6665c6c1daeSBarry Smith +  viewer - the PetscViewer
6675c6c1daeSBarry Smith -  pause - the pause value
6685c6c1daeSBarry Smith 
6695c6c1daeSBarry Smith     Level: intermediate
6705c6c1daeSBarry Smith 
6715c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6725c6c1daeSBarry Smith 
6735c6c1daeSBarry Smith @*/
6745c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
6755c6c1daeSBarry Smith {
6765c6c1daeSBarry Smith   PetscErrorCode   ierr;
677e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
6785c6c1daeSBarry Smith   PetscBool        isdraw;
679e5ab1681SLisandro Dalcin   PetscInt         i;
6805c6c1daeSBarry Smith 
6815c6c1daeSBarry Smith   PetscFunctionBegin;
682e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6835c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
684e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
685e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
686afe78b3cSBarry Smith 
687afe78b3cSBarry Smith   vdraw->pause = pause;
6885c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6895c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawSetPause(vdraw->draw[i],pause);CHKERRQ(ierr);}
6905c6c1daeSBarry Smith   }
6915c6c1daeSBarry Smith   PetscFunctionReturn(0);
6925c6c1daeSBarry Smith }
6935c6c1daeSBarry Smith 
6945c6c1daeSBarry Smith 
6955c6c1daeSBarry Smith /*@
6965c6c1daeSBarry Smith     PetscViewerDrawSetHold - Holds previous image when drawing new image
6975c6c1daeSBarry Smith 
6985c6c1daeSBarry Smith     Not Collective
6995c6c1daeSBarry Smith 
7005c6c1daeSBarry Smith     Input Parameters:
7015c6c1daeSBarry Smith +  viewer - the PetscViewer
7025c6c1daeSBarry Smith -  hold - indicates to hold or not
7035c6c1daeSBarry Smith 
7045c6c1daeSBarry Smith     Level: intermediate
7055c6c1daeSBarry Smith 
7065c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
7075c6c1daeSBarry Smith 
7085c6c1daeSBarry Smith @*/
7095c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
7105c6c1daeSBarry Smith {
7115c6c1daeSBarry Smith   PetscErrorCode   ierr;
7125c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
7135c6c1daeSBarry Smith   PetscBool        isdraw;
7145c6c1daeSBarry Smith 
7155c6c1daeSBarry Smith   PetscFunctionBegin;
716e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7175c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
718e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
7195c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
720e5ab1681SLisandro Dalcin 
7215c6c1daeSBarry Smith   vdraw->hold = hold;
7225c6c1daeSBarry Smith   PetscFunctionReturn(0);
7235c6c1daeSBarry Smith }
7245c6c1daeSBarry Smith 
7255c6c1daeSBarry Smith /*@
726d97d059aSBarry Smith     PetscViewerDrawGetHold - Checks if holds previous image when drawing new image
7275c6c1daeSBarry Smith 
7285c6c1daeSBarry Smith     Not Collective
7295c6c1daeSBarry Smith 
7305c6c1daeSBarry Smith     Input Parameter:
7315c6c1daeSBarry Smith .  viewer - the PetscViewer
7325c6c1daeSBarry Smith 
7335c6c1daeSBarry Smith     Output Parameter:
7345c6c1daeSBarry Smith .  hold - indicates to hold or not
7355c6c1daeSBarry Smith 
7365c6c1daeSBarry Smith     Level: intermediate
7375c6c1daeSBarry Smith 
7385c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
7395c6c1daeSBarry Smith 
7405c6c1daeSBarry Smith @*/
7415c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
7425c6c1daeSBarry Smith {
7435c6c1daeSBarry Smith   PetscErrorCode   ierr;
7445c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
7455c6c1daeSBarry Smith   PetscBool        isdraw;
7465c6c1daeSBarry Smith 
7475c6c1daeSBarry Smith   PetscFunctionBegin;
748e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7495c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
750e5ab1681SLisandro Dalcin   if (!isdraw) {*hold = PETSC_FALSE; PetscFunctionReturn(0);}
7515c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
752e5ab1681SLisandro Dalcin 
7535c6c1daeSBarry Smith   *hold = vdraw->hold;
7545c6c1daeSBarry Smith   PetscFunctionReturn(0);
7555c6c1daeSBarry Smith }
7565c6c1daeSBarry Smith 
7575c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
7585c6c1daeSBarry Smith /*
7595c6c1daeSBarry Smith     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
7605c6c1daeSBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
7615c6c1daeSBarry Smith */
762d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;
7635c6c1daeSBarry Smith 
7645c6c1daeSBarry Smith /*@C
7655c6c1daeSBarry Smith     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors
7665c6c1daeSBarry Smith                      in a communicator.
7675c6c1daeSBarry Smith 
768d083f849SBarry Smith      Collective
7695c6c1daeSBarry Smith 
7705c6c1daeSBarry Smith      Input Parameter:
7715c6c1daeSBarry Smith .    comm - the MPI communicator to share the window PetscViewer
7725c6c1daeSBarry Smith 
7735c6c1daeSBarry Smith      Level: intermediate
7745c6c1daeSBarry Smith 
7755c6c1daeSBarry Smith      Notes:
7765c6c1daeSBarry Smith      Unlike almost all other PETSc routines, PETSC_VIEWER_DRAW_ does not return
7775c6c1daeSBarry Smith      an error code.  The window is usually used in the form
7785c6c1daeSBarry Smith $       XXXView(XXX object,PETSC_VIEWER_DRAW_(comm));
7795c6c1daeSBarry Smith 
7805c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(),
7815c6c1daeSBarry Smith @*/
7825c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
7835c6c1daeSBarry Smith {
7845c6c1daeSBarry Smith   PetscErrorCode ierr;
7855c6c1daeSBarry Smith   PetscMPIInt    flag;
7865c6c1daeSBarry Smith   PetscViewer    viewer;
7875c6c1daeSBarry Smith   MPI_Comm       ncomm;
7885c6c1daeSBarry Smith 
7895c6c1daeSBarry Smith   PetscFunctionBegin;
79002c9f0b5SLisandro Dalcin   ierr = PetscCommDuplicate(comm,&ncomm,NULL);if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7915c6c1daeSBarry Smith   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
79202c9f0b5SLisandro Dalcin     ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,NULL);
79302c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7945c6c1daeSBarry Smith   }
79547435625SJed Brown   ierr = MPI_Comm_get_attr(ncomm,Petsc_Viewer_Draw_keyval,(void**)&viewer,&flag);
79602c9f0b5SLisandro Dalcin   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7975c6c1daeSBarry Smith   if (!flag) { /* PetscViewer not yet created */
79802c9f0b5SLisandro Dalcin     ierr = PetscViewerDrawOpen(ncomm,NULL,NULL,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
7992cb5e1ccSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);}
8005c6c1daeSBarry Smith     ierr = PetscObjectRegisterDestroy((PetscObject)viewer);
8012cb5e1ccSBarry Smith     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);}
80247435625SJed Brown     ierr = MPI_Comm_set_attr(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
80302c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
8045c6c1daeSBarry Smith   }
8055c6c1daeSBarry Smith   ierr = PetscCommDestroy(&ncomm);
8062cb5e1ccSBarry Smith   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_REPEAT," ");PetscFunctionReturn(NULL);}
8075c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
8085c6c1daeSBarry Smith }
8095c6c1daeSBarry Smith 
8105c6c1daeSBarry Smith /*@
8115c6c1daeSBarry Smith     PetscViewerDrawSetBounds - sets the upper and lower bounds to be used in plotting
8125c6c1daeSBarry Smith 
8135c6c1daeSBarry Smith     Collective on PetscViewer
8145c6c1daeSBarry Smith 
8155c6c1daeSBarry Smith     Input Parameters:
8165c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
8175c6c1daeSBarry Smith .   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
8185c6c1daeSBarry Smith -   bounds - the actual bounds, the size of this is 2*nbounds, the values are stored in the order min F_0, max F_0, min F_1, max F_1, .....
8195c6c1daeSBarry Smith 
820e9457bf7SBarry Smith 
821e9457bf7SBarry Smith     Options Database:
822*10699b91SBarry Smith .   -draw_bounds  minF0,maxF0,minF1,maxF1 - the lower left and upper right bounds
823e9457bf7SBarry Smith 
8245c6c1daeSBarry Smith     Level: intermediate
8255c6c1daeSBarry Smith 
82695452b02SPatrick Sanan     Notes:
82795452b02SPatrick Sanan     this determines the colors used in 2d contour plots generated with VecView() for DMDA in 2d. Any values in the vector below or above the
828f3f0eb19SBarry Smith       bounds are moved to the bound value before plotting. In this way the color index from color to physical value remains the same for all plots generated with
829f3f0eb19SBarry Smith       this viewer. Otherwise the color to physical value meaning changes with each new image if this is not set.
830f3f0eb19SBarry Smith 
8315c6c1daeSBarry Smith 
8325c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
8335c6c1daeSBarry Smith @*/
8345c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
8355c6c1daeSBarry Smith {
836e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
837e5ab1681SLisandro Dalcin   PetscBool        isdraw;
8385c6c1daeSBarry Smith   PetscErrorCode   ierr;
8395c6c1daeSBarry Smith 
8405c6c1daeSBarry Smith 
8415c6c1daeSBarry Smith   PetscFunctionBegin;
8425c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
843e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
844e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
845e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
846a297a907SKarl Rupp 
847e5ab1681SLisandro Dalcin   vdraw->nbounds = nbounds;
848e5ab1681SLisandro Dalcin   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
849785e854fSJed Brown   ierr = PetscMalloc1(2*nbounds,&vdraw->bounds);CHKERRQ(ierr);
850580bdb30SBarry Smith   ierr = PetscArraycpy(vdraw->bounds,bounds,2*nbounds);CHKERRQ(ierr);
8515c6c1daeSBarry Smith   PetscFunctionReturn(0);
8525c6c1daeSBarry Smith }
8535c6c1daeSBarry Smith 
8545c6c1daeSBarry Smith /*@C
8555c6c1daeSBarry Smith     PetscViewerDrawGetBounds - gets the upper and lower bounds to be used in plotting set with PetscViewerDrawSetBounds()
8565c6c1daeSBarry Smith 
8575c6c1daeSBarry Smith     Collective on PetscViewer
8585c6c1daeSBarry Smith 
8595c6c1daeSBarry Smith     Input Parameter:
8605c6c1daeSBarry Smith .   viewer - the PetscViewer (created with PetscViewerDrawOpen())
8615c6c1daeSBarry Smith 
862fd292e60Sprj-     Output Parameters:
8635c6c1daeSBarry Smith +   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
8645c6c1daeSBarry Smith -   bounds - the actual bounds, the size of this is 2*nbounds, the values are stored in the order min F_0, max F_0, min F_1, max F_1, .....
8655c6c1daeSBarry Smith 
8665c6c1daeSBarry Smith     Level: intermediate
8675c6c1daeSBarry Smith 
8685c6c1daeSBarry Smith 
869f3f0eb19SBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawSetBounds()
8705c6c1daeSBarry Smith @*/
8715c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
8725c6c1daeSBarry Smith {
873e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
874e5ab1681SLisandro Dalcin   PetscBool        isdraw;
875e5ab1681SLisandro Dalcin   PetscErrorCode   ierr;
8765c6c1daeSBarry Smith 
8775c6c1daeSBarry Smith   PetscFunctionBegin;
8785c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
879e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
880e5ab1681SLisandro Dalcin   if (!isdraw) {if (nbounds) *nbounds = 0; if (bounds) *bounds = NULL; PetscFunctionReturn(0);}
881e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
882e5ab1681SLisandro Dalcin 
883e5ab1681SLisandro Dalcin   if (nbounds) *nbounds = vdraw->nbounds;
884e5ab1681SLisandro Dalcin   if (bounds)  *bounds  = vdraw->bounds;
8855c6c1daeSBarry Smith   PetscFunctionReturn(0);
8865c6c1daeSBarry Smith }
887