xref: /petsc/src/sys/classes/draw/interface/dviewp.c (revision 57622a8ec272e2944ba90348a8875f087fbb2bc6)
15c6c1daeSBarry Smith 
25c6c1daeSBarry Smith /*
35c6c1daeSBarry Smith        Provides the calling sequences for all the basic PetscDraw routines.
45c6c1daeSBarry Smith */
55c6c1daeSBarry Smith #include <petsc-private/drawimpl.h>  /*I "petscdraw.h" I*/
65c6c1daeSBarry Smith 
75c6c1daeSBarry Smith #undef __FUNCT__
85c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSetViewPort"
95c6c1daeSBarry Smith /*@
105c6c1daeSBarry Smith    PetscDrawSetViewPort - Sets the portion of the window (page) to which draw
115c6c1daeSBarry Smith    routines will write.
125c6c1daeSBarry Smith 
135c6c1daeSBarry Smith    Collective on PetscDraw
145c6c1daeSBarry Smith 
155c6c1daeSBarry Smith    Input Parameters:
165c6c1daeSBarry Smith +  xl,yl,xr,yr - upper right and lower left corners of subwindow
175c6c1daeSBarry Smith                  These numbers must always be between 0.0 and 1.0.
185c6c1daeSBarry Smith                  Lower left corner is (0,0).
195c6c1daeSBarry Smith -  draw - the drawing context
205c6c1daeSBarry Smith 
215c6c1daeSBarry Smith    Level: advanced
225c6c1daeSBarry Smith 
235c6c1daeSBarry Smith    Concepts: drawing^in subset of window
245c6c1daeSBarry Smith    Concepts: graphics^in subset of window
255c6c1daeSBarry Smith 
265c6c1daeSBarry Smith @*/
275c6c1daeSBarry Smith PetscErrorCode  PetscDrawSetViewPort(PetscDraw draw,PetscReal xl,PetscReal yl,PetscReal xr,PetscReal yr)
285c6c1daeSBarry Smith {
295c6c1daeSBarry Smith   PetscErrorCode ierr;
305c6c1daeSBarry Smith 
315c6c1daeSBarry Smith   PetscFunctionBegin;
325c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
33*57622a8eSBarry Smith   if (xl < 0.0 || xr > 1.0 || yl < 0.0 || yr > 1.0 || xr <= xl || yr <= yl) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"ViewPort values must be >= 0 and <= 1: Instead %g %g %g %g",(double)xl,(double)yl,(double)xr,(double)yr);
345c6c1daeSBarry Smith   draw->port_xl = xl; draw->port_yl = yl;
355c6c1daeSBarry Smith   draw->port_xr = xr; draw->port_yr = yr;
365c6c1daeSBarry Smith   if (draw->ops->setviewport) {
375c6c1daeSBarry Smith     ierr = (*draw->ops->setviewport)(draw,xl,yl,xr,yr);CHKERRQ(ierr);
385c6c1daeSBarry Smith   }
395c6c1daeSBarry Smith   PetscFunctionReturn(0);
405c6c1daeSBarry Smith }
415c6c1daeSBarry Smith 
425c6c1daeSBarry Smith #undef __FUNCT__
435c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawGetViewPort"
445c6c1daeSBarry Smith /*@
455c6c1daeSBarry Smith    PetscDrawGetViewPort - Gets the portion of the window (page) to which draw
465c6c1daeSBarry Smith    routines will write.
475c6c1daeSBarry Smith 
485c6c1daeSBarry Smith    Collective on PetscDraw
495c6c1daeSBarry Smith 
505c6c1daeSBarry Smith    Input Parameter:
515c6c1daeSBarry Smith .  draw - the drawing context
525c6c1daeSBarry Smith 
535c6c1daeSBarry Smith    Output Parameter:
545c6c1daeSBarry Smith .  xl,yl,xr,yr - upper right and lower left corners of subwindow
555c6c1daeSBarry Smith                  These numbers must always be between 0.0 and 1.0.
565c6c1daeSBarry Smith                  Lower left corner is (0,0).
575c6c1daeSBarry Smith 
585c6c1daeSBarry Smith    Level: advanced
595c6c1daeSBarry Smith 
605c6c1daeSBarry Smith    Concepts: drawing^in subset of window
615c6c1daeSBarry Smith    Concepts: graphics^in subset of window
625c6c1daeSBarry Smith 
635c6c1daeSBarry Smith @*/
645c6c1daeSBarry Smith PetscErrorCode  PetscDrawGetViewPort(PetscDraw draw,PetscReal *xl,PetscReal *yl,PetscReal *xr,PetscReal *yr)
655c6c1daeSBarry Smith {
665c6c1daeSBarry Smith   PetscFunctionBegin;
675c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
685c6c1daeSBarry Smith   *xl = draw->port_xl;
695c6c1daeSBarry Smith   *yl = draw->port_yl;
705c6c1daeSBarry Smith   *xr = draw->port_xr;
715c6c1daeSBarry Smith   *yr = draw->port_yr;
725c6c1daeSBarry Smith   PetscFunctionReturn(0);
735c6c1daeSBarry Smith }
745c6c1daeSBarry Smith 
755c6c1daeSBarry Smith #undef __FUNCT__
765c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawSplitViewPort"
775c6c1daeSBarry Smith /*@
785c6c1daeSBarry Smith    PetscDrawSplitViewPort - Splits a window shared by several processes into smaller
795c6c1daeSBarry Smith    view ports. One for each process.
805c6c1daeSBarry Smith 
815c6c1daeSBarry Smith    Collective on PetscDraw
825c6c1daeSBarry Smith 
835c6c1daeSBarry Smith    Input Parameter:
845c6c1daeSBarry Smith .  draw - the drawing context
855c6c1daeSBarry Smith 
865c6c1daeSBarry Smith    Level: advanced
875c6c1daeSBarry Smith 
885c6c1daeSBarry Smith    Concepts: drawing^in subset of window
895c6c1daeSBarry Smith 
905c6c1daeSBarry Smith .seealso: PetscDrawDivideViewPort(), PetscDrawSetViewPort()
915c6c1daeSBarry Smith 
925c6c1daeSBarry Smith @*/
935c6c1daeSBarry Smith PetscErrorCode  PetscDrawSplitViewPort(PetscDraw draw)
945c6c1daeSBarry Smith {
955c6c1daeSBarry Smith   PetscErrorCode ierr;
965c6c1daeSBarry Smith   PetscMPIInt    rank,size;
97369cc0aeSBarry Smith   PetscInt       n;
985c6c1daeSBarry Smith   PetscBool      isnull;
995c6c1daeSBarry Smith   PetscReal      xl,xr,yl,yr,h;
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith   PetscFunctionBegin;
1025c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
1035c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr);
1045c6c1daeSBarry Smith   if (isnull) PetscFunctionReturn(0);
1055c6c1daeSBarry Smith 
106ce94432eSBarry Smith   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr);
107ce94432eSBarry Smith   ierr = MPI_Comm_size(PetscObjectComm((PetscObject)draw),&size);CHKERRQ(ierr);
1085c6c1daeSBarry Smith 
109369cc0aeSBarry Smith   n = (PetscInt)(.1 + PetscSqrtReal((PetscReal)size));
110a297a907SKarl Rupp   while (n*n < size) n++;
1115c6c1daeSBarry Smith 
1125c6c1daeSBarry Smith   h  = 1.0/n;
1135c6c1daeSBarry Smith   xl = (rank % n)*h;
1145c6c1daeSBarry Smith   xr = xl + h;
1155c6c1daeSBarry Smith   yl = (rank/n)*h;
1165c6c1daeSBarry Smith   yr = yl + h;
1175c6c1daeSBarry Smith 
1185c6c1daeSBarry Smith   ierr = PetscDrawLine(draw,xl,yl,xl,yr,PETSC_DRAW_BLACK);CHKERRQ(ierr);
1195c6c1daeSBarry Smith   ierr = PetscDrawLine(draw,xl,yr,xr,yr,PETSC_DRAW_BLACK);CHKERRQ(ierr);
1205c6c1daeSBarry Smith   ierr = PetscDrawLine(draw,xr,yr,xr,yl,PETSC_DRAW_BLACK);CHKERRQ(ierr);
1215c6c1daeSBarry Smith   ierr = PetscDrawLine(draw,xr,yl,xl,yl,PETSC_DRAW_BLACK);CHKERRQ(ierr);
1225c6c1daeSBarry Smith   ierr = PetscDrawSynchronizedFlush(draw);CHKERRQ(ierr);
1235c6c1daeSBarry Smith 
1245c6c1daeSBarry Smith   draw->port_xl = xl + .1*h;
1255c6c1daeSBarry Smith   draw->port_xr = xr - .1*h;
1265c6c1daeSBarry Smith   draw->port_yl = yl + .1*h;
1275c6c1daeSBarry Smith   draw->port_yr = yr - .1*h;
1285c6c1daeSBarry Smith 
1295c6c1daeSBarry Smith   if (draw->ops->setviewport) {
1305c6c1daeSBarry Smith     ierr =  (*draw->ops->setviewport)(draw,xl,yl,xr,yr);CHKERRQ(ierr);
1315c6c1daeSBarry Smith   }
1325c6c1daeSBarry Smith   PetscFunctionReturn(0);
1335c6c1daeSBarry Smith }
1345c6c1daeSBarry Smith 
1355c6c1daeSBarry Smith #undef __FUNCT__
1365c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawViewPortsCreate"
1375c6c1daeSBarry Smith /*@C
1385c6c1daeSBarry Smith    PetscDrawViewPortsCreate - Splits a window into smaller
1395c6c1daeSBarry Smith        view ports. Each processor shares all the viewports.
1405c6c1daeSBarry Smith 
1415c6c1daeSBarry Smith    Collective on PetscDraw
1425c6c1daeSBarry Smith 
1435c6c1daeSBarry Smith    Input Parameters:
1445c6c1daeSBarry Smith +  draw - the drawing context
1455c6c1daeSBarry Smith -  nports - the number of ports
1465c6c1daeSBarry Smith 
1475c6c1daeSBarry Smith    Output Parameter:
1485c6c1daeSBarry Smith .  ports - a PetscDrawViewPorts context (C structure)
1495c6c1daeSBarry Smith 
1505c6c1daeSBarry Smith    Level: advanced
1515c6c1daeSBarry Smith 
1525c6c1daeSBarry Smith    Concepts: drawing^in subset of window
1535c6c1daeSBarry Smith 
1545c6c1daeSBarry Smith .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsDestroy()
1555c6c1daeSBarry Smith 
1565c6c1daeSBarry Smith @*/
1575c6c1daeSBarry Smith PetscErrorCode  PetscDrawViewPortsCreate(PetscDraw draw,PetscInt nports,PetscDrawViewPorts **ports)
1585c6c1daeSBarry Smith {
1595c6c1daeSBarry Smith   PetscInt       i,n;
1605c6c1daeSBarry Smith   PetscErrorCode ierr;
1615c6c1daeSBarry Smith   PetscBool      isnull;
1625c6c1daeSBarry Smith   PetscReal      *xl,*xr,*yl,*yr,h;
1635c6c1daeSBarry Smith 
1645c6c1daeSBarry Smith   PetscFunctionBegin;
1655c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
1665c6c1daeSBarry Smith   PetscValidPointer(ports,3);
1675c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)draw,PETSC_DRAW_NULL,&isnull);CHKERRQ(ierr);
1685c6c1daeSBarry Smith   if (isnull) {
1690298fd71SBarry Smith     *ports = NULL;
1705c6c1daeSBarry Smith     PetscFunctionReturn(0);
1715c6c1daeSBarry Smith   }
1725c6c1daeSBarry Smith 
173b00a9115SJed Brown   ierr             = PetscNew(ports);CHKERRQ(ierr);
1745c6c1daeSBarry Smith   (*ports)->draw   = draw;
1755c6c1daeSBarry Smith   (*ports)->nports = nports;
1765c6c1daeSBarry Smith 
1775c6c1daeSBarry Smith   ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr);
1785c6c1daeSBarry Smith 
179369cc0aeSBarry Smith   n = (PetscInt)(.1 + PetscSqrtReal((PetscReal)nports));
180a297a907SKarl Rupp   while (n*n < nports) n++;
1815c6c1daeSBarry Smith 
182785e854fSJed Brown   ierr = PetscMalloc1(n*n,&xl);CHKERRQ(ierr);(*ports)->xl = xl;
183785e854fSJed Brown   ierr = PetscMalloc1(n*n,&xr);CHKERRQ(ierr);(*ports)->xr = xr;
184785e854fSJed Brown   ierr = PetscMalloc1(n*n,&yl);CHKERRQ(ierr);(*ports)->yl = yl;
185785e854fSJed Brown   ierr = PetscMalloc1(n*n,&yr);CHKERRQ(ierr);(*ports)->yr = yr;
1865c6c1daeSBarry Smith 
1875c6c1daeSBarry Smith   h = 1.0/n;
1885c6c1daeSBarry Smith 
1895c6c1daeSBarry Smith   for (i=0; i<n*n; i++) {
1905c6c1daeSBarry Smith     xl[i] = (i % n)*h;
1915c6c1daeSBarry Smith     xr[i] = xl[i] + h;
1925c6c1daeSBarry Smith     yl[i] = (i/n)*h;
1935c6c1daeSBarry Smith     yr[i] = yl[i] + h;
1945c6c1daeSBarry Smith 
1955c6c1daeSBarry Smith     ierr = PetscDrawLine(draw,xl[i],yl[i],xl[i],yr[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
1965c6c1daeSBarry Smith     ierr = PetscDrawLine(draw,xl[i],yr[i],xr[i],yr[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
1975c6c1daeSBarry Smith     ierr = PetscDrawLine(draw,xr[i],yr[i],xr[i],yl[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
1985c6c1daeSBarry Smith     ierr = PetscDrawLine(draw,xr[i],yl[i],xl[i],yl[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
1995c6c1daeSBarry Smith 
2005c6c1daeSBarry Smith     xl[i] += .1*h;
2015c6c1daeSBarry Smith     xr[i] -= .1*h;
2025c6c1daeSBarry Smith     yl[i] += .1*h;
2035c6c1daeSBarry Smith     yr[i] -= .1*h;
2045c6c1daeSBarry Smith   }
2055c6c1daeSBarry Smith   /* save previous drawport of window */
2065c6c1daeSBarry Smith   ierr = PetscDrawGetViewPort(draw,&(*ports)->port_xl,&(*ports)->port_yl,&(*ports)->port_xr,&(*ports)->port_yr);CHKERRQ(ierr);
2075c6c1daeSBarry Smith   /* ierr = PetscDrawSynchronizedFlush(draw);CHKERRQ(ierr);*/  /* this causes flicker */
2085c6c1daeSBarry Smith   PetscFunctionReturn(0);
2095c6c1daeSBarry Smith }
2105c6c1daeSBarry Smith 
2115c6c1daeSBarry Smith #undef __FUNCT__
2125c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawViewPortsCreateRect"
2135c6c1daeSBarry Smith /*@C
2145c6c1daeSBarry Smith    PetscDrawViewPortsCreateRect - Splits a window into smaller
2155c6c1daeSBarry Smith        view ports. Each processor shares all the viewports. The number
2165c6c1daeSBarry Smith        of views in the x- and y-directions is specified.
2175c6c1daeSBarry Smith 
2185c6c1daeSBarry Smith    Collective on PetscDraw
2195c6c1daeSBarry Smith 
2205c6c1daeSBarry Smith    Input Parameters:
2215c6c1daeSBarry Smith +  draw - the drawing context
2225c6c1daeSBarry Smith .  nx - the number of x divisions
2235c6c1daeSBarry Smith -  ny - the number of y divisions
2245c6c1daeSBarry Smith 
2255c6c1daeSBarry Smith    Output Parameter:
2265c6c1daeSBarry Smith .  ports - a PetscDrawViewPorts context (C structure)
2275c6c1daeSBarry Smith 
2285c6c1daeSBarry Smith    Level: advanced
2295c6c1daeSBarry Smith 
2305c6c1daeSBarry Smith    Concepts: drawing^in subset of window
2315c6c1daeSBarry Smith 
2325c6c1daeSBarry Smith .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsDestroy()
2335c6c1daeSBarry Smith 
2345c6c1daeSBarry Smith @*/
2355c6c1daeSBarry Smith PetscErrorCode  PetscDrawViewPortsCreateRect(PetscDraw draw,PetscInt nx,PetscInt ny,PetscDrawViewPorts **ports)
2365c6c1daeSBarry Smith {
2375c6c1daeSBarry Smith   PetscReal      *xl, *xr, *yl, *yr, hx, hy;
2385c6c1daeSBarry Smith   PetscBool      isnull;
2395c6c1daeSBarry Smith   PetscInt       i, j, n;
2405c6c1daeSBarry Smith   PetscErrorCode ierr;
2415c6c1daeSBarry Smith 
2425c6c1daeSBarry Smith   PetscFunctionBegin;
2435c6c1daeSBarry Smith   PetscValidHeaderSpecific(draw,PETSC_DRAW_CLASSID,1);
2445c6c1daeSBarry Smith   if ((nx < 1) || (ny < 1)) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE, "Number of divisions must be positive: %d x %d", nx, ny);
2455c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject) draw, PETSC_DRAW_NULL, &isnull);CHKERRQ(ierr);
2465c6c1daeSBarry Smith   if (isnull) {
2470298fd71SBarry Smith     *ports = NULL;
2485c6c1daeSBarry Smith     PetscFunctionReturn(0);
2495c6c1daeSBarry Smith   }
2505c6c1daeSBarry Smith   n    = nx*ny;
2515c6c1daeSBarry Smith   hx   = 1.0/nx;
2525c6c1daeSBarry Smith   hy   = 1.0/ny;
253b00a9115SJed Brown   ierr = PetscNew(ports);CHKERRQ(ierr);
254a297a907SKarl Rupp 
2555c6c1daeSBarry Smith   (*ports)->draw   = draw;
2565c6c1daeSBarry Smith   (*ports)->nports = n;
257a297a907SKarl Rupp 
2585c6c1daeSBarry Smith   ierr = PetscObjectReference((PetscObject) draw);CHKERRQ(ierr);
259785e854fSJed Brown   ierr = PetscMalloc1(n, &xl);CHKERRQ(ierr);(*ports)->xl = xl;
260785e854fSJed Brown   ierr = PetscMalloc1(n, &xr);CHKERRQ(ierr);(*ports)->xr = xr;
261785e854fSJed Brown   ierr = PetscMalloc1(n, &yl);CHKERRQ(ierr);(*ports)->yl = yl;
262785e854fSJed Brown   ierr = PetscMalloc1(n, &yr);CHKERRQ(ierr);(*ports)->yr = yr;
2635c6c1daeSBarry Smith   for (i = 0; i < nx; i++) {
2645c6c1daeSBarry Smith     for (j = 0; j < ny; j++) {
2655c6c1daeSBarry Smith       PetscInt k = j*nx+i;
2665c6c1daeSBarry Smith 
2675c6c1daeSBarry Smith       xl[k] = i*hx;
2685c6c1daeSBarry Smith       xr[k] = xl[k] + hx;
2695c6c1daeSBarry Smith       yl[k] = j*hy;
2705c6c1daeSBarry Smith       yr[k] = yl[k] + hy;
2715c6c1daeSBarry Smith 
2725c6c1daeSBarry Smith       ierr = PetscDrawLine(draw,xl[k],yl[k],xl[k],yr[k],PETSC_DRAW_BLACK);CHKERRQ(ierr);
2735c6c1daeSBarry Smith       ierr = PetscDrawLine(draw,xl[k],yr[k],xr[k],yr[k],PETSC_DRAW_BLACK);CHKERRQ(ierr);
2745c6c1daeSBarry Smith       ierr = PetscDrawLine(draw,xr[k],yr[k],xr[k],yl[k],PETSC_DRAW_BLACK);CHKERRQ(ierr);
2755c6c1daeSBarry Smith       ierr = PetscDrawLine(draw,xr[k],yl[k],xl[k],yl[k],PETSC_DRAW_BLACK);CHKERRQ(ierr);
2765c6c1daeSBarry Smith 
2775c6c1daeSBarry Smith       xl[k] += .01*hx;
2785c6c1daeSBarry Smith       xr[k] -= .01*hx;
2795c6c1daeSBarry Smith       yl[k] += .01*hy;
2805c6c1daeSBarry Smith       yr[k] -= .01*hy;
2815c6c1daeSBarry Smith     }
2825c6c1daeSBarry Smith   }
2835c6c1daeSBarry Smith   ierr = PetscDrawGetViewPort(draw,&(*ports)->port_xl,&(*ports)->port_yl,&(*ports)->port_xr,&(*ports)->port_yr);CHKERRQ(ierr);
2845c6c1daeSBarry Smith   /* ierr = PetscDrawSynchronizedFlush(draw);CHKERRQ(ierr); */  /* this causes flicker */
2855c6c1daeSBarry Smith   PetscFunctionReturn(0);
2865c6c1daeSBarry Smith }
2875c6c1daeSBarry Smith 
2885c6c1daeSBarry Smith #undef __FUNCT__
2895c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawViewPortsDestroy"
2905c6c1daeSBarry Smith /*@C
2915c6c1daeSBarry Smith    PetscDrawViewPortsDestroy - frees a PetscDrawViewPorts object
2925c6c1daeSBarry Smith 
2935c6c1daeSBarry Smith    Collective on PetscDraw inside PetscDrawViewPorts
2945c6c1daeSBarry Smith 
2955c6c1daeSBarry Smith    Input Parameter:
2965c6c1daeSBarry Smith .  ports - the PetscDrawViewPorts object
2975c6c1daeSBarry Smith 
2985c6c1daeSBarry Smith    Level: advanced
2995c6c1daeSBarry Smith 
3005c6c1daeSBarry Smith .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsSet(), PetscDrawViewPortsCreate()
3015c6c1daeSBarry Smith 
3025c6c1daeSBarry Smith @*/
3035c6c1daeSBarry Smith PetscErrorCode  PetscDrawViewPortsDestroy(PetscDrawViewPorts *ports)
3045c6c1daeSBarry Smith {
3055c6c1daeSBarry Smith   PetscErrorCode ierr;
3065c6c1daeSBarry Smith 
3075c6c1daeSBarry Smith   PetscFunctionBegin;
3085c6c1daeSBarry Smith   if (!ports) PetscFunctionReturn(0);
3095c6c1daeSBarry Smith   /* reset Drawport of Window back to previous value */
3105c6c1daeSBarry Smith   ierr = PetscDrawSetViewPort(ports->draw,ports->port_xl,ports->port_yl,ports->port_xr,ports->port_yr);CHKERRQ(ierr);
3115c6c1daeSBarry Smith   ierr = PetscDrawDestroy(&ports->draw);CHKERRQ(ierr);
3125c6c1daeSBarry Smith   ierr = PetscFree(ports->xl);CHKERRQ(ierr);
3135c6c1daeSBarry Smith   ierr = PetscFree(ports->xr);CHKERRQ(ierr);
3145c6c1daeSBarry Smith   ierr = PetscFree(ports->yl);CHKERRQ(ierr);
3155c6c1daeSBarry Smith   ierr = PetscFree(ports->yr);CHKERRQ(ierr);
3165c6c1daeSBarry Smith   ierr = PetscFree(ports);CHKERRQ(ierr);
3175c6c1daeSBarry Smith   PetscFunctionReturn(0);
3185c6c1daeSBarry Smith }
3195c6c1daeSBarry Smith 
3205c6c1daeSBarry Smith #undef __FUNCT__
3215c6c1daeSBarry Smith #define __FUNCT__ "PetscDrawViewPortsSet"
3225c6c1daeSBarry Smith /*@C
3235c6c1daeSBarry Smith    PetscDrawViewPortsSet - sets a draw object to use a particular subport
3245c6c1daeSBarry Smith 
3255c6c1daeSBarry Smith    Logically Collective on PetscDraw inside PetscDrawViewPorts
3265c6c1daeSBarry Smith 
3275c6c1daeSBarry Smith    Input Parameter:
3285c6c1daeSBarry Smith +  ports - the PetscDrawViewPorts object
3295c6c1daeSBarry Smith -  port - the port number, from 0 to nports-1
3305c6c1daeSBarry Smith 
3315c6c1daeSBarry Smith    Level: advanced
3325c6c1daeSBarry Smith 
3335c6c1daeSBarry Smith    Concepts: drawing^in subset of window
3345c6c1daeSBarry Smith 
3355c6c1daeSBarry Smith .seealso: PetscDrawSplitViewPort(), PetscDrawSetViewPort(), PetscDrawViewPortsDestroy(), PetscDrawViewPortsCreate()
3365c6c1daeSBarry Smith 
3375c6c1daeSBarry Smith @*/
3385c6c1daeSBarry Smith PetscErrorCode  PetscDrawViewPortsSet(PetscDrawViewPorts *ports,PetscInt port)
3395c6c1daeSBarry Smith {
3405c6c1daeSBarry Smith   PetscErrorCode ierr;
3415c6c1daeSBarry Smith 
3425c6c1daeSBarry Smith   PetscFunctionBegin;
3435c6c1daeSBarry Smith   if (ports) {
3445c6c1daeSBarry Smith     if (port < 0 || port > ports->nports-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Port is out of range requested %d from 0 to %d\n",port,ports->nports);
3455c6c1daeSBarry Smith     ierr = PetscDrawSetViewPort(ports->draw,ports->xl[port],ports->yl[port],ports->xr[port],ports->yr[port]);CHKERRQ(ierr);
3465c6c1daeSBarry Smith   }
3475c6c1daeSBarry Smith   PetscFunctionReturn(0);
3485c6c1daeSBarry Smith }
349