xref: /petsc/src/sys/classes/viewer/interface/viewreg.c (revision e04113cf637149666d9c83678a5abc4e1b351bcc)
15c6c1daeSBarry Smith 
2665c2dedSJed Brown #include <petsc-private/viewerimpl.h>  /*I "petscviewer.h" I*/
3*e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
4*e04113cfSBarry Smith #include <petscviewersaws.h>
5bfb97211SBarry Smith #endif
65c6c1daeSBarry Smith 
7140e18c1SBarry Smith PetscFunctionList PetscViewerList = 0;
85c6c1daeSBarry Smith 
92bf49c77SBarry Smith #undef __FUNCT__
102bf49c77SBarry Smith #define __FUNCT__ "PetscOptionsGetViewer"
112bf49c77SBarry Smith /*@C
122bf49c77SBarry Smith    PetscOptionsGetViewer - Gets a viewer appropriate for the type indicated by the user
132bf49c77SBarry Smith 
142bf49c77SBarry Smith    Collective on MPI_Comm
152bf49c77SBarry Smith 
162bf49c77SBarry Smith    Input Parameters:
172bf49c77SBarry Smith +  comm - the communicator to own the viewer
180298fd71SBarry Smith .  pre - the string to prepend to the name or NULL
192bf49c77SBarry Smith -  name - the option one is seeking
202bf49c77SBarry Smith 
212bf49c77SBarry Smith    Output Parameter:
222bf49c77SBarry Smith +  viewer - the viewer
23cffb1e40SBarry Smith .  format - the PetscViewerFormat requested by the user
242bf49c77SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
252bf49c77SBarry Smith 
262bf49c77SBarry Smith    Level: intermediate
272bf49c77SBarry Smith 
282bf49c77SBarry Smith    Notes: If no value is provided ascii:stdout is used
293550efbcSJed Brown $       ascii[:[filename][:[format][:append]]]   defaults to stdout - format can be one of ascii_info, ascii_info_detail, or ascii_matlab, for example ascii::ascii_info prints just the info
3005315717SToby Isaac $                                     about the object to standard out - unless :append is given filename opens in write mode
313550efbcSJed Brown $       binary[:[filename][:[format][:append]]]   defaults to binaryoutput
322bf49c77SBarry Smith $       draw
332bf49c77SBarry Smith $       socket[:port]                  defaults to the standard output port
34*e04113cfSBarry Smith $       ams[:communicatorname]         publishes object to the SAWs (Argonne Memory Snooper)
352bf49c77SBarry Smith 
36cffb1e40SBarry Smith    Use PetscViewerDestroy() after using the viewer, otherwise a memory leak will occur
372bf49c77SBarry Smith 
382bf49c77SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(),
392bf49c77SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
402bf49c77SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
412bf49c77SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
422bf49c77SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
432bf49c77SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
44cffb1e40SBarry Smith           PetscOptionsList(), PetscOptionsEList()
452bf49c77SBarry Smith @*/
46cffb1e40SBarry Smith PetscErrorCode  PetscOptionsGetViewer(MPI_Comm comm,const char pre[],const char name[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
472bf49c77SBarry Smith {
482bf49c77SBarry Smith   char           *value;
492bf49c77SBarry Smith   PetscErrorCode ierr;
502bf49c77SBarry Smith   PetscBool      flag;
512bf49c77SBarry Smith 
522bf49c77SBarry Smith   PetscFunctionBegin;
532bf49c77SBarry Smith   PetscValidCharPointer(name,3);
542bf49c77SBarry Smith 
55e3f3e4b6SBarry Smith   if (format) *format = PETSC_VIEWER_DEFAULT;
562bf49c77SBarry Smith   if (set) *set = PETSC_FALSE;
572bf49c77SBarry Smith   ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr);
582bf49c77SBarry Smith   if (flag) {
592bf49c77SBarry Smith     if (set) *set = PETSC_TRUE;
602bf49c77SBarry Smith     if (!value) {
612bf49c77SBarry Smith       ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
62706a11cbSBarry Smith       ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
632bf49c77SBarry Smith     } else {
6435d27ee3SJed Brown       char       *loc0_vtype,*loc1_fname,*loc2_fmt = NULL,*loc3_fmode = NULL;
652bf49c77SBarry Smith       PetscInt   cnt;
66*e04113cfSBarry Smith       const char *viewers[] = {PETSCVIEWERASCII,PETSCVIEWERBINARY,PETSCVIEWERDRAW,PETSCVIEWERSOCKET,PETSCVIEWERMATLAB,PETSCVIEWERSAWS,PETSCVIEWERVTK,0};
672bf49c77SBarry Smith 
6835d27ee3SJed Brown       ierr = PetscStrallocpy(value,&loc0_vtype);CHKERRQ(ierr);
6935d27ee3SJed Brown       ierr = PetscStrchr(loc0_vtype,':',&loc1_fname);CHKERRQ(ierr);
7035d27ee3SJed Brown       if (loc1_fname) {
7135d27ee3SJed Brown         *loc1_fname++ = 0;
7235d27ee3SJed Brown         ierr = PetscStrchr(loc1_fname,':',&loc2_fmt);CHKERRQ(ierr);
7335d27ee3SJed Brown       }
7435d27ee3SJed Brown       if (loc2_fmt) {
7535d27ee3SJed Brown         *loc2_fmt++ = 0;
7635d27ee3SJed Brown         ierr = PetscStrchr(loc2_fmt,':',&loc3_fmode);CHKERRQ(ierr);
7735d27ee3SJed Brown       }
7835d27ee3SJed Brown       if (loc3_fmode) *loc3_fmode++ = 0;
7935d27ee3SJed Brown       ierr = PetscStrendswithwhich(*loc0_vtype ? loc0_vtype : "ascii",viewers,&cnt);CHKERRQ(ierr);
8035d27ee3SJed Brown       if (cnt > (PetscInt) sizeof(viewers)-1) SETERRQ1(comm,PETSC_ERR_ARG_OUTOFRANGE,"Unknown viewer type: %s",loc0_vtype);
8135d27ee3SJed Brown       if (!loc1_fname) {
8243b63833SBarry Smith         switch (cnt) {
8343b63833SBarry Smith         case 0:
842bf49c77SBarry Smith           ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
8543b63833SBarry Smith           break;
8643b63833SBarry Smith         case 1:
87aa1c909bSJed Brown           if (!(*viewer = PETSC_VIEWER_BINARY_(comm))) CHKERRQ(PETSC_ERR_PLIB);
8843b63833SBarry Smith           break;
8943b63833SBarry Smith         case 2:
90aa1c909bSJed Brown           if (!(*viewer = PETSC_VIEWER_DRAW_(comm))) CHKERRQ(PETSC_ERR_PLIB);
9143b63833SBarry Smith           break;
92b58ca069SBarry Smith #if defined(PETSC_USE_SOCKET_VIEWER)
9343b63833SBarry Smith         case 3:
94aa1c909bSJed Brown           if (!(*viewer = PETSC_VIEWER_SOCKET_(comm))) CHKERRQ(PETSC_ERR_PLIB);
9543b63833SBarry Smith           break;
96b58ca069SBarry Smith #endif
9743b63833SBarry Smith #if defined(PETSC_HAVE_MATLAB_ENGINE)
9843b63833SBarry Smith         case 4:
99aa1c909bSJed Brown           if (!(*viewer = PETSC_VIEWER_MATLAB_(comm))) CHKERRQ(PETSC_ERR_PLIB);
10043b63833SBarry Smith           break;
10143b63833SBarry Smith #endif
102*e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
103bfb97211SBarry Smith         case 5:
104*e04113cfSBarry Smith           if (!(*viewer = PETSC_VIEWER_SAWS_(comm))) CHKERRQ(PETSC_ERR_PLIB);
105bfb97211SBarry Smith           break;
106bfb97211SBarry Smith #endif
107aa1c909bSJed Brown         default: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported viewer %s",loc0_vtype);
1087f677774SBarry Smith         }
109706a11cbSBarry Smith         ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
1107f677774SBarry Smith       } else {
11135d27ee3SJed Brown         if (loc2_fmt && !*loc1_fname && (cnt == 0)) { /* ASCII format without file name */
1127f677774SBarry Smith           ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
113706a11cbSBarry Smith           ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
1147f677774SBarry Smith         } else {
1153550efbcSJed Brown           PetscFileMode fmode;
1162bf49c77SBarry Smith           ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
11735d27ee3SJed Brown           ierr = PetscViewerSetType(*viewer,*loc0_vtype ? loc0_vtype : "ascii");CHKERRQ(ierr);
1183550efbcSJed Brown           fmode = FILE_MODE_WRITE;
1193550efbcSJed Brown           if (loc3_fmode && *loc3_fmode) { /* Has non-empty file mode ("write" or "append") */
12035d27ee3SJed Brown             ierr = PetscEnumFind(PetscFileModes,loc3_fmode,(PetscEnum*)&fmode,&flag);CHKERRQ(ierr);
1213550efbcSJed Brown             if (!flag) SETERRQ1(comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown file mode: %s",loc3_fmode);
1227f677774SBarry Smith           }
1233550efbcSJed Brown           ierr = PetscViewerFileSetMode(*viewer,flag?fmode:FILE_MODE_WRITE);CHKERRQ(ierr);
12435d27ee3SJed Brown           ierr = PetscViewerFileSetName(*viewer,loc1_fname);CHKERRQ(ierr);
12505315717SToby Isaac         }
12605315717SToby Isaac       }
12735d27ee3SJed Brown       if (loc2_fmt && *loc2_fmt) {
12835d27ee3SJed Brown         ierr = PetscEnumFind(PetscViewerFormats,loc2_fmt,(PetscEnum*)format,&flag);CHKERRQ(ierr);
12935d27ee3SJed Brown         if (!flag) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unknown viewer format %s",loc2_fmt);CHKERRQ(ierr);
1307f677774SBarry Smith       }
1312bf49c77SBarry Smith       ierr = PetscViewerSetUp(*viewer);CHKERRQ(ierr);
13235d27ee3SJed Brown       ierr = PetscFree(loc0_vtype);CHKERRQ(ierr);
1332bf49c77SBarry Smith     }
1342bf49c77SBarry Smith   }
1352bf49c77SBarry Smith   PetscFunctionReturn(0);
1362bf49c77SBarry Smith }
1372bf49c77SBarry Smith 
1382bf49c77SBarry Smith #undef __FUNCT__
1395c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerCreate"
1405c6c1daeSBarry Smith /*@
1415c6c1daeSBarry Smith    PetscViewerCreate - Creates a viewing context
1425c6c1daeSBarry Smith 
1435c6c1daeSBarry Smith    Collective on MPI_Comm
1445c6c1daeSBarry Smith 
1455c6c1daeSBarry Smith    Input Parameter:
1465c6c1daeSBarry Smith .  comm - MPI communicator
1475c6c1daeSBarry Smith 
1485c6c1daeSBarry Smith    Output Parameter:
1495c6c1daeSBarry Smith .  inviewer - location to put the PetscViewer context
1505c6c1daeSBarry Smith 
1515c6c1daeSBarry Smith    Level: advanced
1525c6c1daeSBarry Smith 
1535c6c1daeSBarry Smith    Concepts: graphics^creating PetscViewer
1545c6c1daeSBarry Smith    Concepts: file input/output^creating PetscViewer
1555c6c1daeSBarry Smith    Concepts: sockets^creating PetscViewer
1565c6c1daeSBarry Smith 
1575c6c1daeSBarry Smith .seealso: PetscViewerDestroy(), PetscViewerSetType(), PetscViewerType
1585c6c1daeSBarry Smith 
1595c6c1daeSBarry Smith @*/
1605c6c1daeSBarry Smith PetscErrorCode  PetscViewerCreate(MPI_Comm comm,PetscViewer *inviewer)
1615c6c1daeSBarry Smith {
1625c6c1daeSBarry Smith   PetscViewer    viewer;
1635c6c1daeSBarry Smith   PetscErrorCode ierr;
1645c6c1daeSBarry Smith 
1655c6c1daeSBarry Smith   PetscFunctionBegin;
1665c6c1daeSBarry Smith   *inviewer = 0;
1675c6c1daeSBarry Smith #if !defined(PETSC_USE_DYNAMIC_LIBRARIES)
168607a6623SBarry Smith   ierr = PetscViewerInitializePackage();CHKERRQ(ierr);
1695c6c1daeSBarry Smith #endif
17067c2884eSBarry Smith   ierr         = PetscHeaderCreate(viewer,_p_PetscViewer,struct _PetscViewerOps,PETSC_VIEWER_CLASSID,"PetscViewer","PetscViewer","Viewer",comm,PetscViewerDestroy,0);CHKERRQ(ierr);
1715c6c1daeSBarry Smith   *inviewer    = viewer;
1725c6c1daeSBarry Smith   viewer->data = 0;
1735c6c1daeSBarry Smith   PetscFunctionReturn(0);
1745c6c1daeSBarry Smith }
1755c6c1daeSBarry Smith 
1765c6c1daeSBarry Smith #undef __FUNCT__
1775c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetType"
1785c6c1daeSBarry Smith /*@C
1795c6c1daeSBarry Smith    PetscViewerSetType - Builds PetscViewer for a particular implementation.
1805c6c1daeSBarry Smith 
1815c6c1daeSBarry Smith    Collective on PetscViewer
1825c6c1daeSBarry Smith 
1835c6c1daeSBarry Smith    Input Parameter:
1845c6c1daeSBarry Smith +  viewer      - the PetscViewer context
1858f6c3df8SBarry Smith -  type        - for example, PETSCVIEWERASCII
1865c6c1daeSBarry Smith 
1875c6c1daeSBarry Smith    Options Database Command:
1885c6c1daeSBarry Smith .  -draw_type  <type> - Sets the type; use -help for a list
1895c6c1daeSBarry Smith     of available methods (for instance, ascii)
1905c6c1daeSBarry Smith 
1915c6c1daeSBarry Smith    Level: advanced
1925c6c1daeSBarry Smith 
1935c6c1daeSBarry Smith    Notes:
1945c6c1daeSBarry Smith    See "include/petscviewer.h" for available methods (for instance,
1958f6c3df8SBarry Smith    PETSCVIEWERSOCKET)
1965c6c1daeSBarry Smith 
1978f6c3df8SBarry Smith .seealso: PetscViewerCreate(), PetscViewerGetType(), PetscViewerType, PetscViewerSetFormat()
1985c6c1daeSBarry Smith @*/
1995c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetType(PetscViewer viewer,PetscViewerType type)
2005c6c1daeSBarry Smith {
2015c6c1daeSBarry Smith   PetscErrorCode ierr,(*r)(PetscViewer);
2025c6c1daeSBarry Smith   PetscBool      match;
2035c6c1daeSBarry Smith 
2045c6c1daeSBarry Smith   PetscFunctionBegin;
2055c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2065c6c1daeSBarry Smith   PetscValidCharPointer(type,2);
2075c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,type,&match);CHKERRQ(ierr);
2085c6c1daeSBarry Smith   if (match) PetscFunctionReturn(0);
2095c6c1daeSBarry Smith 
2105c6c1daeSBarry Smith   /* cleanup any old type that may be there */
2115c6c1daeSBarry Smith   if (viewer->data) {
2125c6c1daeSBarry Smith     ierr         = (*viewer->ops->destroy)(viewer);CHKERRQ(ierr);
213a297a907SKarl Rupp 
2140298fd71SBarry Smith     viewer->ops->destroy = NULL;
2155c6c1daeSBarry Smith     viewer->data         = 0;
2165c6c1daeSBarry Smith   }
2175c6c1daeSBarry Smith   ierr = PetscMemzero(viewer->ops,sizeof(struct _PetscViewerOps));CHKERRQ(ierr);
2185c6c1daeSBarry Smith 
2191c9cd337SJed Brown   ierr =  PetscFunctionListFind(PetscViewerList,type,&r);CHKERRQ(ierr);
2205c6c1daeSBarry Smith   if (!r) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown PetscViewer type given: %s",type);
2215c6c1daeSBarry Smith 
2225c6c1daeSBarry Smith   ierr = PetscObjectChangeTypeName((PetscObject)viewer,type);CHKERRQ(ierr);
2235c6c1daeSBarry Smith   ierr = (*r)(viewer);CHKERRQ(ierr);
2245c6c1daeSBarry Smith   PetscFunctionReturn(0);
2255c6c1daeSBarry Smith }
2265c6c1daeSBarry Smith 
2275c6c1daeSBarry Smith #undef __FUNCT__
2285c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerRegister"
2291c84c290SBarry Smith /*@C
2301c84c290SBarry Smith    PetscViewerRegister - Adds a viewer
2311c84c290SBarry Smith 
2321c84c290SBarry Smith    Not Collective
2331c84c290SBarry Smith 
2341c84c290SBarry Smith    Input Parameters:
2351c84c290SBarry Smith +  name_solver - name of a new user-defined viewer
2361c84c290SBarry Smith -  routine_create - routine to create method context
2371c84c290SBarry Smith 
2381c84c290SBarry Smith    Level: developer
2391c84c290SBarry Smith    Notes:
2401c84c290SBarry Smith    PetscViewerRegister() may be called multiple times to add several user-defined viewers.
2411c84c290SBarry Smith 
2421c84c290SBarry Smith    Sample usage:
2431c84c290SBarry Smith .vb
244bdf89e91SBarry Smith    PetscViewerRegister("my_viewer_type",MyViewerCreate);
2451c84c290SBarry Smith .ve
2461c84c290SBarry Smith 
2471c84c290SBarry Smith    Then, your solver can be chosen with the procedural interface via
2481c84c290SBarry Smith $     PetscViewerSetType(viewer,"my_viewer_type")
2491c84c290SBarry Smith    or at runtime via the option
2501c84c290SBarry Smith $     -viewer_type my_viewer_type
2511c84c290SBarry Smith 
2521c84c290SBarry Smith   Concepts: registering^Viewers
2531c84c290SBarry Smith 
2541c84c290SBarry Smith .seealso: PetscViewerRegisterAll(), PetscViewerRegisterDestroy()
2551c84c290SBarry Smith  @*/
256bdf89e91SBarry Smith PetscErrorCode  PetscViewerRegister(const char *sname,PetscErrorCode (*function)(PetscViewer))
2575c6c1daeSBarry Smith {
2585c6c1daeSBarry Smith   PetscErrorCode ierr;
2595c6c1daeSBarry Smith 
2605c6c1daeSBarry Smith   PetscFunctionBegin;
261a240a19fSJed Brown   ierr = PetscFunctionListAdd(&PetscViewerList,sname,function);CHKERRQ(ierr);
2625c6c1daeSBarry Smith   PetscFunctionReturn(0);
2635c6c1daeSBarry Smith }
2645c6c1daeSBarry Smith 
2655c6c1daeSBarry Smith #undef __FUNCT__
2665c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetFromOptions"
2675c6c1daeSBarry Smith /*@C
2685c6c1daeSBarry Smith    PetscViewerSetFromOptions - Sets the graphics type from the options database.
2695c6c1daeSBarry Smith       Defaults to a PETSc X windows graphics.
2705c6c1daeSBarry Smith 
2715c6c1daeSBarry Smith    Collective on PetscViewer
2725c6c1daeSBarry Smith 
2735c6c1daeSBarry Smith    Input Parameter:
2745c6c1daeSBarry Smith .     PetscViewer - the graphics context
2755c6c1daeSBarry Smith 
2765c6c1daeSBarry Smith    Level: intermediate
2775c6c1daeSBarry Smith 
2785c6c1daeSBarry Smith    Notes:
2795c6c1daeSBarry Smith     Must be called after PetscViewerCreate() before the PetscViewer is used.
2805c6c1daeSBarry Smith 
2815c6c1daeSBarry Smith   Concepts: PetscViewer^setting options
2825c6c1daeSBarry Smith 
2835c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType
2845c6c1daeSBarry Smith 
2855c6c1daeSBarry Smith @*/
2865c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetFromOptions(PetscViewer viewer)
2875c6c1daeSBarry Smith {
2885c6c1daeSBarry Smith   PetscErrorCode    ierr;
2895c6c1daeSBarry Smith   char              vtype[256];
2905c6c1daeSBarry Smith   PetscBool         flg;
2910076e027SBarry Smith   PetscViewer       v2;
2920076e027SBarry Smith   PetscViewerFormat format;
2935c6c1daeSBarry Smith 
2945c6c1daeSBarry Smith   PetscFunctionBegin;
2955c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2965c6c1daeSBarry Smith 
2975c6c1daeSBarry Smith   if (!PetscViewerList) {
298607a6623SBarry Smith     ierr = PetscViewerRegisterAll();CHKERRQ(ierr);
2995c6c1daeSBarry Smith   }
3005c6c1daeSBarry Smith   ierr = PetscObjectOptionsBegin((PetscObject)viewer);CHKERRQ(ierr);
3015c6c1daeSBarry Smith   ierr = PetscOptionsList("-viewer_type","Type of PetscViewer","None",PetscViewerList,(char*)(((PetscObject)viewer)->type_name ? ((PetscObject)viewer)->type_name : PETSCVIEWERASCII),vtype,256,&flg);CHKERRQ(ierr);
3025c6c1daeSBarry Smith   if (flg) {
3035c6c1daeSBarry Smith     ierr = PetscViewerSetType(viewer,vtype);CHKERRQ(ierr);
3045c6c1daeSBarry Smith   }
3055c6c1daeSBarry Smith   /* type has not been set? */
3065c6c1daeSBarry Smith   if (!((PetscObject)viewer)->type_name) {
3075c6c1daeSBarry Smith     ierr = PetscViewerSetType(viewer,PETSCVIEWERASCII);CHKERRQ(ierr);
3085c6c1daeSBarry Smith   }
3095c6c1daeSBarry Smith   if (viewer->ops->setfromoptions) {
3105c6c1daeSBarry Smith     ierr = (*viewer->ops->setfromoptions)(viewer);CHKERRQ(ierr);
3115c6c1daeSBarry Smith   }
3125c6c1daeSBarry Smith 
3135c6c1daeSBarry Smith   /* process any options handlers added with PetscObjectAddOptionsHandler() */
3145c6c1daeSBarry Smith   ierr = PetscObjectProcessOptionsHandlers((PetscObject)viewer);CHKERRQ(ierr);
3150076e027SBarry Smith   ierr = PetscOptionsViewer("-viewer_view","Display Viewer with the viewer","PetscViewerView",&v2,&format,&flg);CHKERRQ(ierr);
3160076e027SBarry Smith   if (flg) {
3170076e027SBarry Smith     ierr = PetscViewerPushFormat(v2,format);CHKERRQ(ierr);
3180076e027SBarry Smith     ierr = PetscViewerView(viewer,v2);CHKERRQ(ierr);
3190076e027SBarry Smith     ierr = PetscViewerPopFormat(v2);CHKERRQ(ierr);
3200076e027SBarry Smith   }
3215c6c1daeSBarry Smith   ierr = PetscOptionsEnd();CHKERRQ(ierr);
3225c6c1daeSBarry Smith   PetscFunctionReturn(0);
3235c6c1daeSBarry Smith }
324