xref: /petsc/src/sys/classes/viewer/impls/draw/drawv.c (revision a9db196a4a01bda76ca5ca78782c0a5c8d24f227)
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:
3895c6c1daeSBarry Smith    PetscViewerDrawOpen() calls PetscDrawCreate(), so see the manual page for
3905c6c1daeSBarry Smith    PetscDrawCreate() for runtime options, including
3915c6c1daeSBarry Smith +  -draw_type x or null
3925c6c1daeSBarry Smith .  -nox - Disables all x-windows output
3935c6c1daeSBarry Smith .  -display <name> - Specifies name of machine for the X display
3945c6c1daeSBarry Smith .  -geometry <x,y,w,h> - allows setting the window location and size
3955c6c1daeSBarry Smith -  -draw_pause <pause> - Sets time (in seconds) that the
3965c6c1daeSBarry Smith      program pauses after PetscDrawPause() has been called
3975c6c1daeSBarry Smith      (0 is default, -1 implies until user input).
3985c6c1daeSBarry Smith 
3995c6c1daeSBarry Smith    Level: beginner
4005c6c1daeSBarry Smith 
4015c6c1daeSBarry Smith    Note for Fortran Programmers:
4025c6c1daeSBarry Smith    Whenever indicating null character data in a Fortran code,
403cf90aa19SBarry Smith    PETSC_NULL_CHARACTER must be employed; using NULL is not
404cf90aa19SBarry Smith    correct for character data!  Thus, PETSC_NULL_CHARACTER can be
4055c6c1daeSBarry Smith    used for the display and title input parameters.
4065c6c1daeSBarry Smith 
4075c6c1daeSBarry Smith 
4085c6c1daeSBarry Smith 
4095c6c1daeSBarry Smith .seealso: PetscDrawCreate(), PetscViewerDestroy(), PetscViewerDrawGetDraw(), PetscViewerCreate(), PETSC_VIEWER_DRAW_,
4105c6c1daeSBarry Smith           PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF
4115c6c1daeSBarry Smith @*/
4125c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawOpen(MPI_Comm comm,const char display[],const char title[],int x,int y,int w,int h,PetscViewer *viewer)
4135c6c1daeSBarry Smith {
4145c6c1daeSBarry Smith   PetscErrorCode ierr;
4155c6c1daeSBarry Smith 
4165c6c1daeSBarry Smith   PetscFunctionBegin;
4175c6c1daeSBarry Smith   ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
4185c6c1daeSBarry Smith   ierr = PetscViewerSetType(*viewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
4195c6c1daeSBarry Smith   ierr = PetscViewerDrawSetInfo(*viewer,display,title,x,y,w,h);CHKERRQ(ierr);
4205c6c1daeSBarry Smith   PetscFunctionReturn(0);
4215c6c1daeSBarry Smith }
4225c6c1daeSBarry Smith 
423*a9db196aSBarry Smith #include <petsc/private/drawimpl.h>
424*a9db196aSBarry Smith 
4253f08860eSBarry Smith PetscErrorCode PetscViewerGetSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4265c6c1daeSBarry Smith {
4275c6c1daeSBarry Smith   PetscErrorCode   ierr;
4285c6c1daeSBarry Smith   PetscMPIInt      rank;
4295c6c1daeSBarry Smith   PetscInt         i;
430c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4315c6c1daeSBarry Smith 
4325c6c1daeSBarry Smith   PetscFunctionBegin;
4333f08860eSBarry Smith   if (vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to get SubViewer without first restoring previous");
4345c6c1daeSBarry Smith   /* only processor zero can use the PetscViewer draw singleton */
435fefe69c3SStefano Zampini   if (sviewer) *sviewer = NULL;
436ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
4375c6c1daeSBarry Smith   if (!rank) {
438e5afcf28SBarry Smith     PetscMPIInt flg;
439*a9db196aSBarry Smith     PetscDraw   draw,sdraw;
440e5afcf28SBarry Smith 
441e5afcf28SBarry Smith     ierr = MPI_Comm_compare(PETSC_COMM_SELF,comm,&flg);CHKERRQ(ierr);
442e5afcf28SBarry Smith     if (flg != MPI_IDENT && flg != MPI_CONGRUENT) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"PetscViewerGetSubViewer() for PETSCVIEWERDRAW requires a singleton MPI_Comm");
443e5afcf28SBarry Smith     ierr = PetscViewerCreate(comm,sviewer);CHKERRQ(ierr);
4445c6c1daeSBarry Smith     ierr = PetscViewerSetType(*sviewer,PETSCVIEWERDRAW);CHKERRQ(ierr);
445c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
446c6228bbaSLisandro Dalcin     (*sviewer)->format = viewer->format;
447c6228bbaSLisandro Dalcin     for (i=0; i<vdraw->draw_max; i++) { /* XXX this is wrong if svdraw->draw_max (initially 5) < vdraw->draw_max */
448c6228bbaSLisandro Dalcin       if (vdraw->draw[i]) {ierr = PetscDrawGetSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);}
4495c6c1daeSBarry Smith     }
450*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
451*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(*sviewer,0,&sdraw);CHKERRQ(ierr);
452*a9db196aSBarry Smith     if (draw->savefilename) {
453*a9db196aSBarry Smith       ierr = PetscDrawSetSave(sdraw,draw->savefilename);CHKERRQ(ierr);
454*a9db196aSBarry Smith       sdraw->savefilecount = draw->savefilecount;
455*a9db196aSBarry Smith       sdraw->savesinglefile = draw->savesinglefile;
456*a9db196aSBarry Smith       sdraw->savemoviefps = draw->savemoviefps;
457*a9db196aSBarry Smith       sdraw->saveonclear = draw->saveonclear;
458*a9db196aSBarry Smith       sdraw->saveonflush = draw->saveonflush;
459*a9db196aSBarry Smith     }
460*a9db196aSBarry Smith     if (draw->savefinalfilename) {ierr = PetscDrawSetSaveFinalImage(sdraw,draw->savefinalfilename);CHKERRQ(ierr);}
461*a9db196aSBarry Smith   } else {
462*a9db196aSBarry Smith     PetscDraw draw;
463*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
4645c6c1daeSBarry Smith   }
4655c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_TRUE;
4665c6c1daeSBarry Smith   PetscFunctionReturn(0);
4675c6c1daeSBarry Smith }
4685c6c1daeSBarry Smith 
4693f08860eSBarry Smith PetscErrorCode PetscViewerRestoreSubViewer_Draw(PetscViewer viewer,MPI_Comm comm,PetscViewer *sviewer)
4705c6c1daeSBarry Smith {
4715c6c1daeSBarry Smith   PetscErrorCode   ierr;
4725c6c1daeSBarry Smith   PetscMPIInt      rank;
4735c6c1daeSBarry Smith   PetscInt         i;
474c6228bbaSLisandro Dalcin   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data,*svdraw;
4755c6c1daeSBarry Smith 
4765c6c1daeSBarry Smith   PetscFunctionBegin;
4775c6c1daeSBarry Smith   if (!vdraw->singleton_made) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ORDER,"Trying to restore a singleton that was not gotten");
478ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)viewer),&rank);CHKERRQ(ierr);
4795c6c1daeSBarry Smith   if (!rank) {
480*a9db196aSBarry Smith     PetscDraw draw,sdraw;
481*a9db196aSBarry Smith 
482*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
483*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(*sviewer,0,&sdraw);CHKERRQ(ierr);
484*a9db196aSBarry Smith     if (draw->savefilename) {
485*a9db196aSBarry Smith       draw->savefilecount = sdraw->savefilecount;
486*a9db196aSBarry Smith       ierr = MPI_Bcast(&draw->savefilecount,1,MPIU_INT,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
487*a9db196aSBarry Smith     }
488c6228bbaSLisandro Dalcin     svdraw = (PetscViewer_Draw*)(*sviewer)->data;
4895c6c1daeSBarry Smith     for (i=0; i<vdraw->draw_max; i++) {
490c6228bbaSLisandro Dalcin       if (vdraw->draw[i] && svdraw->draw[i]) {
491c6228bbaSLisandro Dalcin         ierr = PetscDrawRestoreSingleton(vdraw->draw[i],&svdraw->draw[i]);CHKERRQ(ierr);
4925c6c1daeSBarry Smith       }
4935c6c1daeSBarry Smith     }
494c6228bbaSLisandro Dalcin     ierr = PetscFree3(svdraw->draw,svdraw->drawlg,svdraw->drawaxis);CHKERRQ(ierr);
4955c6c1daeSBarry Smith     ierr = PetscFree((*sviewer)->data);CHKERRQ(ierr);
4965c6c1daeSBarry Smith     ierr = PetscHeaderDestroy(sviewer);CHKERRQ(ierr);
497*a9db196aSBarry Smith   } else {
498*a9db196aSBarry Smith     PetscDraw draw;
499*a9db196aSBarry Smith 
500*a9db196aSBarry Smith     ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
501*a9db196aSBarry Smith     if (draw->savefilename) {
502*a9db196aSBarry Smith       ierr = MPI_Bcast(&draw->savefilecount,1,MPIU_INT,0,PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);
5035c6c1daeSBarry Smith     }
504*a9db196aSBarry Smith   }
505*a9db196aSBarry Smith 
5065c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
5075c6c1daeSBarry Smith   PetscFunctionReturn(0);
5085c6c1daeSBarry Smith }
5095c6c1daeSBarry Smith 
5104416b707SBarry Smith PetscErrorCode PetscViewerSetFromOptions_Draw(PetscOptionItems *PetscOptionsObject,PetscViewer v)
511e9457bf7SBarry Smith {
512e9457bf7SBarry Smith   PetscErrorCode ierr;
513e9457bf7SBarry Smith   PetscReal      bounds[16];
514e9457bf7SBarry Smith   PetscInt       nbounds = 16;
515e9457bf7SBarry Smith   PetscBool      flg;
516e9457bf7SBarry Smith 
517e9457bf7SBarry Smith   PetscFunctionBegin;
518e55864a3SBarry Smith   ierr = PetscOptionsHead(PetscOptionsObject,"Draw PetscViewer Options");CHKERRQ(ierr);
519e9457bf7SBarry Smith   ierr = PetscOptionsRealArray("-draw_bounds","Bounds to put on plots axis","PetscViewerDrawSetBounds",bounds,&nbounds,&flg);CHKERRQ(ierr);
520e9457bf7SBarry Smith   if (flg) {
521e9457bf7SBarry Smith     ierr = PetscViewerDrawSetBounds(v,nbounds/2,bounds);CHKERRQ(ierr);
522e9457bf7SBarry Smith   }
523e9457bf7SBarry Smith   ierr = PetscOptionsTail();CHKERRQ(ierr);
524e9457bf7SBarry Smith   PetscFunctionReturn(0);
525e9457bf7SBarry Smith }
526e9457bf7SBarry Smith 
5270076e027SBarry Smith PetscErrorCode PetscViewerView_Draw(PetscViewer viewer,PetscViewer v)
5280076e027SBarry Smith {
5290076e027SBarry Smith   PetscErrorCode   ierr;
5300076e027SBarry Smith   PetscDraw        draw;
5310076e027SBarry Smith   PetscInt         i;
5320076e027SBarry Smith   PetscViewer_Draw *vdraw = (PetscViewer_Draw*)viewer->data;
5330076e027SBarry Smith 
5340076e027SBarry Smith   PetscFunctionBegin;
5350076e027SBarry Smith   /*  If the PetscViewer has just been created then no vdraw->draw yet
5360076e027SBarry Smith       exists so this will not actually call the viewer on any draws. */
5370076e027SBarry Smith   for (i=0; i<vdraw->draw_base; i++) {
5380076e027SBarry Smith     if (vdraw->draw[i]) {
5390076e027SBarry Smith       ierr = PetscViewerDrawGetDraw(viewer,i,&draw);CHKERRQ(ierr);
5400076e027SBarry Smith       ierr = PetscDrawView(draw,v);CHKERRQ(ierr);
5410076e027SBarry Smith     }
5420076e027SBarry Smith   }
5430076e027SBarry Smith   PetscFunctionReturn(0);
5440076e027SBarry Smith }
5450076e027SBarry Smith 
5468556b5ebSBarry Smith /*MC
5478556b5ebSBarry Smith    PETSCVIEWERDRAW - A viewer that generates graphics, either to the screen or a file
5488556b5ebSBarry Smith 
5498556b5ebSBarry Smith 
5508556b5ebSBarry Smith .seealso:  PetscViewerDrawOpen(), PetscViewerDrawGetDraw(), PETSC_VIEWER_DRAW_(),PETSC_VIEWER_DRAW_SELF, PETSC_VIEWER_DRAW_WORLD,
5518556b5ebSBarry Smith            PetscViewerCreate(), PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), PETSCVIEWERBINARY,
5528556b5ebSBarry Smith            PetscViewerMatlabOpen(), VecView(), DMView(), PetscViewerMatlabPutArray(), PETSCVIEWERASCII, PETSCVIEWERMATLAB,
5538556b5ebSBarry Smith            PetscViewerFileSetName(), PetscViewerFileSetMode(), PetscViewerFormat, PetscViewerType, PetscViewerSetType()
5548556b5ebSBarry Smith 
5551b266c99SBarry Smith   Level: beginner
5561b266c99SBarry Smith 
5578556b5ebSBarry Smith M*/
5588cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PetscViewerCreate_Draw(PetscViewer viewer)
5595c6c1daeSBarry Smith {
5605c6c1daeSBarry Smith   PetscErrorCode   ierr;
5615c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
5625c6c1daeSBarry Smith 
5635c6c1daeSBarry Smith   PetscFunctionBegin;
564b00a9115SJed Brown   ierr = PetscNewLog(viewer,&vdraw);CHKERRQ(ierr);
5655c6c1daeSBarry Smith   viewer->data = (void*)vdraw;
5665c6c1daeSBarry Smith 
5675c6c1daeSBarry Smith   viewer->ops->flush            = PetscViewerFlush_Draw;
5680076e027SBarry Smith   viewer->ops->view             = PetscViewerView_Draw;
5695c6c1daeSBarry Smith   viewer->ops->destroy          = PetscViewerDestroy_Draw;
570e9457bf7SBarry Smith   viewer->ops->setfromoptions   = PetscViewerSetFromOptions_Draw;
571559f443fSBarry Smith   viewer->ops->getsubviewer     = PetscViewerGetSubViewer_Draw;
572559f443fSBarry Smith   viewer->ops->restoresubviewer = PetscViewerRestoreSubViewer_Draw;
5735c6c1daeSBarry Smith 
5745c6c1daeSBarry Smith   /* these are created on the fly if requested */
5755c6c1daeSBarry Smith   vdraw->draw_max  = 5;
5765c6c1daeSBarry Smith   vdraw->draw_base = 0;
577ccad63c3SBarry Smith   vdraw->w         = PETSC_DECIDE;
578ccad63c3SBarry Smith   vdraw->h         = PETSC_DECIDE;
579a297a907SKarl Rupp 
5801795a4d1SJed Brown   ierr = PetscCalloc3(vdraw->draw_max,&vdraw->draw,vdraw->draw_max,&vdraw->drawlg,vdraw->draw_max,&vdraw->drawaxis);CHKERRQ(ierr);
5815c6c1daeSBarry Smith   vdraw->singleton_made = PETSC_FALSE;
5825c6c1daeSBarry Smith   PetscFunctionReturn(0);
5835c6c1daeSBarry Smith }
5845c6c1daeSBarry Smith 
5855c6c1daeSBarry Smith /*@
5865c6c1daeSBarry Smith     PetscViewerDrawClear - Clears a PetscDraw graphic associated with a PetscViewer.
5875c6c1daeSBarry Smith 
5885c6c1daeSBarry Smith     Not Collective
5895c6c1daeSBarry Smith 
5905c6c1daeSBarry Smith     Input Parameter:
5915c6c1daeSBarry Smith .  viewer - the PetscViewer
5925c6c1daeSBarry Smith 
5935c6c1daeSBarry Smith     Level: intermediate
5945c6c1daeSBarry Smith 
5955c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
5965c6c1daeSBarry Smith 
5975c6c1daeSBarry Smith @*/
5985c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawClear(PetscViewer viewer)
5995c6c1daeSBarry Smith {
6005c6c1daeSBarry Smith   PetscErrorCode   ierr;
6015c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
602e5ab1681SLisandro Dalcin   PetscBool        isdraw;
603e5ab1681SLisandro Dalcin   PetscInt         i;
6045c6c1daeSBarry Smith 
6055c6c1daeSBarry Smith   PetscFunctionBegin;
606e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6075c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
608e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
6095c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
610e5ab1681SLisandro Dalcin 
6115c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6125c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawClear(vdraw->draw[i]);CHKERRQ(ierr);}
6135c6c1daeSBarry Smith   }
6145c6c1daeSBarry Smith   PetscFunctionReturn(0);
6155c6c1daeSBarry Smith }
6165c6c1daeSBarry Smith 
6175c6c1daeSBarry Smith /*@
6185c6c1daeSBarry Smith     PetscViewerDrawGetPause - Gets a pause for the first present draw
6195c6c1daeSBarry Smith 
6205c6c1daeSBarry Smith     Not Collective
6215c6c1daeSBarry Smith 
6225c6c1daeSBarry Smith     Input Parameter:
6235c6c1daeSBarry Smith .  viewer - the PetscViewer
6245c6c1daeSBarry Smith 
6255c6c1daeSBarry Smith     Output Parameter:
6265c6c1daeSBarry Smith .  pause - the pause value
6275c6c1daeSBarry Smith 
6285c6c1daeSBarry Smith     Level: intermediate
6295c6c1daeSBarry Smith 
6305c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6315c6c1daeSBarry Smith 
6325c6c1daeSBarry Smith @*/
6335c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetPause(PetscViewer viewer,PetscReal *pause)
6345c6c1daeSBarry Smith {
6355c6c1daeSBarry Smith   PetscErrorCode   ierr;
6365c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
637e5ab1681SLisandro Dalcin   PetscBool        isdraw;
638e5ab1681SLisandro Dalcin   PetscInt         i;
6395c6c1daeSBarry Smith   PetscDraw        draw;
6405c6c1daeSBarry Smith 
6415c6c1daeSBarry Smith   PetscFunctionBegin;
642e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6435c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
644e5ab1681SLisandro Dalcin   if (!isdraw) {*pause = 0.0; PetscFunctionReturn(0);}
6455c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
646e5ab1681SLisandro Dalcin 
6475c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6485c6c1daeSBarry Smith     if (vdraw->draw[i]) {
6495c6c1daeSBarry Smith       ierr = PetscDrawGetPause(vdraw->draw[i],pause);CHKERRQ(ierr);
6505c6c1daeSBarry Smith       PetscFunctionReturn(0);
6515c6c1daeSBarry Smith     }
6525c6c1daeSBarry Smith   }
6535c6c1daeSBarry Smith   /* none exist yet so create one and get its pause */
6545c6c1daeSBarry Smith   ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr);
655e5ab1681SLisandro Dalcin   ierr = PetscDrawGetPause(draw,pause);CHKERRQ(ierr);
6565c6c1daeSBarry Smith   PetscFunctionReturn(0);
6575c6c1daeSBarry Smith }
6585c6c1daeSBarry Smith 
6595c6c1daeSBarry Smith /*@
6605c6c1daeSBarry Smith     PetscViewerDrawSetPause - Sets a pause for each PetscDraw in the viewer
6615c6c1daeSBarry Smith 
6625c6c1daeSBarry Smith     Not Collective
6635c6c1daeSBarry Smith 
6645c6c1daeSBarry Smith     Input Parameters:
6655c6c1daeSBarry Smith +  viewer - the PetscViewer
6665c6c1daeSBarry Smith -  pause - the pause value
6675c6c1daeSBarry Smith 
6685c6c1daeSBarry Smith     Level: intermediate
6695c6c1daeSBarry Smith 
6705c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
6715c6c1daeSBarry Smith 
6725c6c1daeSBarry Smith @*/
6735c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetPause(PetscViewer viewer,PetscReal pause)
6745c6c1daeSBarry Smith {
6755c6c1daeSBarry Smith   PetscErrorCode   ierr;
676e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
6775c6c1daeSBarry Smith   PetscBool        isdraw;
678e5ab1681SLisandro Dalcin   PetscInt         i;
6795c6c1daeSBarry Smith 
6805c6c1daeSBarry Smith   PetscFunctionBegin;
681e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
6825c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
683e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
684e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
685afe78b3cSBarry Smith 
686afe78b3cSBarry Smith   vdraw->pause = pause;
6875c6c1daeSBarry Smith   for (i=0; i<vdraw->draw_max; i++) {
6885c6c1daeSBarry Smith     if (vdraw->draw[i]) {ierr = PetscDrawSetPause(vdraw->draw[i],pause);CHKERRQ(ierr);}
6895c6c1daeSBarry Smith   }
6905c6c1daeSBarry Smith   PetscFunctionReturn(0);
6915c6c1daeSBarry Smith }
6925c6c1daeSBarry Smith 
6935c6c1daeSBarry Smith 
6945c6c1daeSBarry Smith /*@
6955c6c1daeSBarry Smith     PetscViewerDrawSetHold - Holds previous image when drawing new image
6965c6c1daeSBarry Smith 
6975c6c1daeSBarry Smith     Not Collective
6985c6c1daeSBarry Smith 
6995c6c1daeSBarry Smith     Input Parameters:
7005c6c1daeSBarry Smith +  viewer - the PetscViewer
7015c6c1daeSBarry Smith -  hold - indicates to hold or not
7025c6c1daeSBarry Smith 
7035c6c1daeSBarry Smith     Level: intermediate
7045c6c1daeSBarry Smith 
7055c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
7065c6c1daeSBarry Smith 
7075c6c1daeSBarry Smith @*/
7085c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetHold(PetscViewer viewer,PetscBool hold)
7095c6c1daeSBarry Smith {
7105c6c1daeSBarry Smith   PetscErrorCode   ierr;
7115c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
7125c6c1daeSBarry Smith   PetscBool        isdraw;
7135c6c1daeSBarry Smith 
7145c6c1daeSBarry Smith   PetscFunctionBegin;
715e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7165c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
717e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
7185c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
719e5ab1681SLisandro Dalcin 
7205c6c1daeSBarry Smith   vdraw->hold = hold;
7215c6c1daeSBarry Smith   PetscFunctionReturn(0);
7225c6c1daeSBarry Smith }
7235c6c1daeSBarry Smith 
7245c6c1daeSBarry Smith /*@
725d97d059aSBarry Smith     PetscViewerDrawGetHold - Checks if holds previous image when drawing new image
7265c6c1daeSBarry Smith 
7275c6c1daeSBarry Smith     Not Collective
7285c6c1daeSBarry Smith 
7295c6c1daeSBarry Smith     Input Parameter:
7305c6c1daeSBarry Smith .  viewer - the PetscViewer
7315c6c1daeSBarry Smith 
7325c6c1daeSBarry Smith     Output Parameter:
7335c6c1daeSBarry Smith .  hold - indicates to hold or not
7345c6c1daeSBarry Smith 
7355c6c1daeSBarry Smith     Level: intermediate
7365c6c1daeSBarry Smith 
7375c6c1daeSBarry Smith .seealso: PetscViewerDrawOpen(), PetscViewerDrawGetDraw(),
7385c6c1daeSBarry Smith 
7395c6c1daeSBarry Smith @*/
7405c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetHold(PetscViewer viewer,PetscBool *hold)
7415c6c1daeSBarry Smith {
7425c6c1daeSBarry Smith   PetscErrorCode   ierr;
7435c6c1daeSBarry Smith   PetscViewer_Draw *vdraw;
7445c6c1daeSBarry Smith   PetscBool        isdraw;
7455c6c1daeSBarry Smith 
7465c6c1daeSBarry Smith   PetscFunctionBegin;
747e5ab1681SLisandro Dalcin   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
7485c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
749e5ab1681SLisandro Dalcin   if (!isdraw) {*hold = PETSC_FALSE; PetscFunctionReturn(0);}
7505c6c1daeSBarry Smith   vdraw = (PetscViewer_Draw*)viewer->data;
751e5ab1681SLisandro Dalcin 
7525c6c1daeSBarry Smith   *hold = vdraw->hold;
7535c6c1daeSBarry Smith   PetscFunctionReturn(0);
7545c6c1daeSBarry Smith }
7555c6c1daeSBarry Smith 
7565c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
7575c6c1daeSBarry Smith /*
7585c6c1daeSBarry Smith     The variable Petsc_Viewer_Draw_keyval is used to indicate an MPI attribute that
7595c6c1daeSBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
7605c6c1daeSBarry Smith */
761d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Draw_keyval = MPI_KEYVAL_INVALID;
7625c6c1daeSBarry Smith 
7635c6c1daeSBarry Smith /*@C
7645c6c1daeSBarry Smith     PETSC_VIEWER_DRAW_ - Creates a window PetscViewer shared by all processors
7655c6c1daeSBarry Smith                      in a communicator.
7665c6c1daeSBarry Smith 
767d083f849SBarry Smith      Collective
7685c6c1daeSBarry Smith 
7695c6c1daeSBarry Smith      Input Parameter:
7705c6c1daeSBarry Smith .    comm - the MPI communicator to share the window PetscViewer
7715c6c1daeSBarry Smith 
7725c6c1daeSBarry Smith      Level: intermediate
7735c6c1daeSBarry Smith 
7745c6c1daeSBarry Smith      Notes:
7755c6c1daeSBarry Smith      Unlike almost all other PETSc routines, PETSC_VIEWER_DRAW_ does not return
7765c6c1daeSBarry Smith      an error code.  The window is usually used in the form
7775c6c1daeSBarry Smith $       XXXView(XXX object,PETSC_VIEWER_DRAW_(comm));
7785c6c1daeSBarry Smith 
7795c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_WORLD, PETSC_VIEWER_DRAW_SELF, PetscViewerDrawOpen(),
7805c6c1daeSBarry Smith @*/
7815c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_DRAW_(MPI_Comm comm)
7825c6c1daeSBarry Smith {
7835c6c1daeSBarry Smith   PetscErrorCode ierr;
7845c6c1daeSBarry Smith   PetscMPIInt    flag;
7855c6c1daeSBarry Smith   PetscViewer    viewer;
7865c6c1daeSBarry Smith   MPI_Comm       ncomm;
7875c6c1daeSBarry Smith 
7885c6c1daeSBarry Smith   PetscFunctionBegin;
78902c9f0b5SLisandro 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);}
7905c6c1daeSBarry Smith   if (Petsc_Viewer_Draw_keyval == MPI_KEYVAL_INVALID) {
79102c9f0b5SLisandro Dalcin     ierr = MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Draw_keyval,NULL);
79202c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7935c6c1daeSBarry Smith   }
79447435625SJed Brown   ierr = MPI_Comm_get_attr(ncomm,Petsc_Viewer_Draw_keyval,(void**)&viewer,&flag);
79502c9f0b5SLisandro Dalcin   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7965c6c1daeSBarry Smith   if (!flag) { /* PetscViewer not yet created */
79702c9f0b5SLisandro Dalcin     ierr = PetscViewerDrawOpen(ncomm,NULL,NULL,PETSC_DECIDE,PETSC_DECIDE,300,300,&viewer);
79802c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
7995c6c1daeSBarry Smith     ierr = PetscObjectRegisterDestroy((PetscObject)viewer);
80002c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
80147435625SJed Brown     ierr = MPI_Comm_set_attr(ncomm,Petsc_Viewer_Draw_keyval,(void*)viewer);
80202c9f0b5SLisandro Dalcin     if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
8035c6c1daeSBarry Smith   }
8045c6c1daeSBarry Smith   ierr = PetscCommDestroy(&ncomm);
80502c9f0b5SLisandro Dalcin   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_DRAW_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," ");PetscFunctionReturn(NULL);}
8065c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
8075c6c1daeSBarry Smith }
8085c6c1daeSBarry Smith 
8095c6c1daeSBarry Smith /*@
8105c6c1daeSBarry Smith     PetscViewerDrawSetBounds - sets the upper and lower bounds to be used in plotting
8115c6c1daeSBarry Smith 
8125c6c1daeSBarry Smith     Collective on PetscViewer
8135c6c1daeSBarry Smith 
8145c6c1daeSBarry Smith     Input Parameters:
8155c6c1daeSBarry Smith +   viewer - the PetscViewer (created with PetscViewerDrawOpen())
8165c6c1daeSBarry Smith .   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
8175c6c1daeSBarry 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, .....
8185c6c1daeSBarry Smith 
819e9457bf7SBarry Smith 
820e9457bf7SBarry Smith     Options Database:
821e9457bf7SBarry Smith .   -draw_bounds  minF0,maxF0,minF1,maxF1
822e9457bf7SBarry Smith 
8235c6c1daeSBarry Smith     Level: intermediate
8245c6c1daeSBarry Smith 
82595452b02SPatrick Sanan     Notes:
82695452b02SPatrick 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
827f3f0eb19SBarry 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
828f3f0eb19SBarry Smith       this viewer. Otherwise the color to physical value meaning changes with each new image if this is not set.
829f3f0eb19SBarry Smith 
8305c6c1daeSBarry Smith 
8315c6c1daeSBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen()
8325c6c1daeSBarry Smith @*/
8335c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawSetBounds(PetscViewer viewer,PetscInt nbounds,const PetscReal *bounds)
8345c6c1daeSBarry Smith {
835e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
836e5ab1681SLisandro Dalcin   PetscBool        isdraw;
8375c6c1daeSBarry Smith   PetscErrorCode   ierr;
8385c6c1daeSBarry Smith 
8395c6c1daeSBarry Smith 
8405c6c1daeSBarry Smith   PetscFunctionBegin;
8415c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
842e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
843e5ab1681SLisandro Dalcin   if (!isdraw) PetscFunctionReturn(0);
844e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
845a297a907SKarl Rupp 
846e5ab1681SLisandro Dalcin   vdraw->nbounds = nbounds;
847e5ab1681SLisandro Dalcin   ierr = PetscFree(vdraw->bounds);CHKERRQ(ierr);
848785e854fSJed Brown   ierr = PetscMalloc1(2*nbounds,&vdraw->bounds);CHKERRQ(ierr);
849580bdb30SBarry Smith   ierr = PetscArraycpy(vdraw->bounds,bounds,2*nbounds);CHKERRQ(ierr);
8505c6c1daeSBarry Smith   PetscFunctionReturn(0);
8515c6c1daeSBarry Smith }
8525c6c1daeSBarry Smith 
8535c6c1daeSBarry Smith /*@C
8545c6c1daeSBarry Smith     PetscViewerDrawGetBounds - gets the upper and lower bounds to be used in plotting set with PetscViewerDrawSetBounds()
8555c6c1daeSBarry Smith 
8565c6c1daeSBarry Smith     Collective on PetscViewer
8575c6c1daeSBarry Smith 
8585c6c1daeSBarry Smith     Input Parameter:
8595c6c1daeSBarry Smith .   viewer - the PetscViewer (created with PetscViewerDrawOpen())
8605c6c1daeSBarry Smith 
861fd292e60Sprj-     Output Parameters:
8625c6c1daeSBarry Smith +   nbounds - number of plots that can be made with this viewer, for example the dof passed to DMDACreate()
8635c6c1daeSBarry 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, .....
8645c6c1daeSBarry Smith 
8655c6c1daeSBarry Smith     Level: intermediate
8665c6c1daeSBarry Smith 
8675c6c1daeSBarry Smith 
868f3f0eb19SBarry Smith .seealso: PetscViewerDrawGetLG(), PetscViewerDrawGetAxis(), PetscViewerDrawOpen(), PetscViewerDrawSetBounds()
8695c6c1daeSBarry Smith @*/
8705c6c1daeSBarry Smith PetscErrorCode  PetscViewerDrawGetBounds(PetscViewer viewer,PetscInt *nbounds,const PetscReal **bounds)
8715c6c1daeSBarry Smith {
872e5ab1681SLisandro Dalcin   PetscViewer_Draw *vdraw;
873e5ab1681SLisandro Dalcin   PetscBool        isdraw;
874e5ab1681SLisandro Dalcin   PetscErrorCode   ierr;
8755c6c1daeSBarry Smith 
8765c6c1daeSBarry Smith   PetscFunctionBegin;
8775c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
878e5ab1681SLisandro Dalcin   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr);
879e5ab1681SLisandro Dalcin   if (!isdraw) {if (nbounds) *nbounds = 0; if (bounds) *bounds = NULL; PetscFunctionReturn(0);}
880e5ab1681SLisandro Dalcin   vdraw = (PetscViewer_Draw*)viewer->data;
881e5ab1681SLisandro Dalcin 
882e5ab1681SLisandro Dalcin   if (nbounds) *nbounds = vdraw->nbounds;
883e5ab1681SLisandro Dalcin   if (bounds)  *bounds  = vdraw->bounds;
8845c6c1daeSBarry Smith   PetscFunctionReturn(0);
8855c6c1daeSBarry Smith }
886