xref: /petsc/src/sys/classes/viewer/interface/view.c (revision f8e4bde84cdee892096ab78baf4256ae384d8e42)
15c6c1daeSBarry Smith 
2665c2dedSJed Brown #include <petsc-private/viewerimpl.h>  /*I "petscviewer.h" I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith PetscClassId PETSC_VIEWER_CLASSID;
55c6c1daeSBarry Smith 
65c6c1daeSBarry Smith static PetscBool PetscViewerPackageInitialized = PETSC_FALSE;
75c6c1daeSBarry Smith #undef __FUNCT__
85c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFinalizePackage"
95c6c1daeSBarry Smith /*@C
105c6c1daeSBarry Smith   PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is
115c6c1daeSBarry Smith   called from PetscFinalize().
125c6c1daeSBarry Smith 
135c6c1daeSBarry Smith   Level: developer
145c6c1daeSBarry Smith 
155c6c1daeSBarry Smith .keywords: Petsc, destroy, package, mathematica
165c6c1daeSBarry Smith .seealso: PetscFinalize()
175c6c1daeSBarry Smith @*/
185c6c1daeSBarry Smith PetscErrorCode  PetscViewerFinalizePackage(void)
195c6c1daeSBarry Smith {
2037e93019SBarry Smith   PetscErrorCode ierr;
2137e93019SBarry Smith 
225c6c1daeSBarry Smith   PetscFunctionBegin;
2337e93019SBarry Smith   ierr = PetscFunctionListDestroy(&PetscViewerList);CHKERRQ(ierr);
245c6c1daeSBarry Smith   PetscViewerPackageInitialized = PETSC_FALSE;
250f51fdf8SToby Isaac   PetscViewerRegisterAllCalled  = PETSC_FALSE;
265c6c1daeSBarry Smith   PetscFunctionReturn(0);
275c6c1daeSBarry Smith }
285c6c1daeSBarry Smith 
295c6c1daeSBarry Smith #undef __FUNCT__
305c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerInitializePackage"
315c6c1daeSBarry Smith /*@C
325c6c1daeSBarry Smith   PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package.
335c6c1daeSBarry Smith 
345c6c1daeSBarry Smith   Level: developer
355c6c1daeSBarry Smith 
365c6c1daeSBarry Smith .keywords: Petsc, initialize, package
375c6c1daeSBarry Smith .seealso: PetscInitialize()
385c6c1daeSBarry Smith @*/
39607a6623SBarry Smith PetscErrorCode  PetscViewerInitializePackage(void)
405c6c1daeSBarry Smith {
415c6c1daeSBarry Smith   char           logList[256];
425c6c1daeSBarry Smith   char           *className;
435c6c1daeSBarry Smith   PetscBool      opt;
445c6c1daeSBarry Smith   PetscErrorCode ierr;
455c6c1daeSBarry Smith 
465c6c1daeSBarry Smith   PetscFunctionBegin;
475c6c1daeSBarry Smith   if (PetscViewerPackageInitialized) PetscFunctionReturn(0);
485c6c1daeSBarry Smith   PetscViewerPackageInitialized = PETSC_TRUE;
495c6c1daeSBarry Smith   /* Register Classes */
505c6c1daeSBarry Smith   ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr);
515c6c1daeSBarry Smith 
525c6c1daeSBarry Smith   /* Register Constructors */
53607a6623SBarry Smith   ierr = PetscViewerRegisterAll();CHKERRQ(ierr);
545c6c1daeSBarry Smith 
555c6c1daeSBarry Smith   /* Process info exclusions */
560298fd71SBarry Smith   ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr);
575c6c1daeSBarry Smith   if (opt) {
585c6c1daeSBarry Smith     ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr);
595c6c1daeSBarry Smith     if (className) {
605c6c1daeSBarry Smith       ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr);
615c6c1daeSBarry Smith     }
625c6c1daeSBarry Smith   }
635c6c1daeSBarry Smith   /* Process summary exclusions */
640298fd71SBarry Smith   ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr);
655c6c1daeSBarry Smith   if (opt) {
665c6c1daeSBarry Smith     ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr);
675c6c1daeSBarry Smith     if (className) {
685c6c1daeSBarry Smith       ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr);
695c6c1daeSBarry Smith     }
705c6c1daeSBarry Smith   }
715c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA)
72607a6623SBarry Smith   ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr);
735c6c1daeSBarry Smith #endif
745c6c1daeSBarry Smith   ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr);
755c6c1daeSBarry Smith   PetscFunctionReturn(0);
765c6c1daeSBarry Smith }
775c6c1daeSBarry Smith 
785c6c1daeSBarry Smith #undef __FUNCT__
795c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy"
805c6c1daeSBarry Smith /*@
815c6c1daeSBarry Smith    PetscViewerDestroy - Destroys a PetscViewer.
825c6c1daeSBarry Smith 
835c6c1daeSBarry Smith    Collective on PetscViewer
845c6c1daeSBarry Smith 
855c6c1daeSBarry Smith    Input Parameters:
865c6c1daeSBarry Smith .  viewer - the PetscViewer to be destroyed.
875c6c1daeSBarry Smith 
885c6c1daeSBarry Smith    Level: beginner
895c6c1daeSBarry Smith 
905c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen()
915c6c1daeSBarry Smith 
925c6c1daeSBarry Smith @*/
935c6c1daeSBarry Smith PetscErrorCode  PetscViewerDestroy(PetscViewer *viewer)
945c6c1daeSBarry Smith {
955c6c1daeSBarry Smith   PetscErrorCode ierr;
965c6c1daeSBarry Smith 
975c6c1daeSBarry Smith   PetscFunctionBegin;
985c6c1daeSBarry Smith   if (!*viewer) PetscFunctionReturn(0);
995c6c1daeSBarry Smith   PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1);
1005c6c1daeSBarry Smith 
1015c6c1daeSBarry Smith   ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr);
1025c6c1daeSBarry Smith   if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; PetscFunctionReturn(0);}
1035c6c1daeSBarry Smith 
104e04113cfSBarry Smith   ierr = PetscObjectSAWsViewOff((PetscObject)*viewer);CHKERRQ(ierr);
1055c6c1daeSBarry Smith   if ((*viewer)->ops->destroy) {
1065c6c1daeSBarry Smith     ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr);
1075c6c1daeSBarry Smith   }
1085c6c1daeSBarry Smith   ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr);
1095c6c1daeSBarry Smith   PetscFunctionReturn(0);
1105c6c1daeSBarry Smith }
1115c6c1daeSBarry Smith 
1125c6c1daeSBarry Smith #undef __FUNCT__
1135c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetType"
1145c6c1daeSBarry Smith /*@C
1155c6c1daeSBarry Smith    PetscViewerGetType - Returns the type of a PetscViewer.
1165c6c1daeSBarry Smith 
1175c6c1daeSBarry Smith    Not Collective
1185c6c1daeSBarry Smith 
1195c6c1daeSBarry Smith    Input Parameter:
1205c6c1daeSBarry Smith .   viewer - the PetscViewer
1215c6c1daeSBarry Smith 
1225c6c1daeSBarry Smith    Output Parameter:
1235c6c1daeSBarry Smith .  type - PetscViewer type (see below)
1245c6c1daeSBarry Smith 
1255c6c1daeSBarry Smith    Available Types Include:
1265c6c1daeSBarry Smith .  PETSCVIEWERSOCKET - Socket PetscViewer
1275c6c1daeSBarry Smith .  PETSCVIEWERASCII - ASCII PetscViewer
1285c6c1daeSBarry Smith .  PETSCVIEWERBINARY - binary file PetscViewer
1295c6c1daeSBarry Smith .  PETSCVIEWERSTRING - string PetscViewer
1305c6c1daeSBarry Smith .  PETSCVIEWERDRAW - drawing PetscViewer
1315c6c1daeSBarry Smith 
1325c6c1daeSBarry Smith    Level: intermediate
1335c6c1daeSBarry Smith 
1345c6c1daeSBarry Smith    Note:
1355c6c1daeSBarry Smith    See include/petscviewer.h for a complete list of PetscViewers.
1365c6c1daeSBarry Smith 
1375c6c1daeSBarry Smith    PetscViewerType is actually a string
1385c6c1daeSBarry Smith 
1395c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType
1405c6c1daeSBarry Smith 
1415c6c1daeSBarry Smith @*/
1425c6c1daeSBarry Smith PetscErrorCode  PetscViewerGetType(PetscViewer viewer,PetscViewerType *type)
1435c6c1daeSBarry Smith {
1445c6c1daeSBarry Smith   PetscFunctionBegin;
1455c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1465c6c1daeSBarry Smith   PetscValidPointer(type,2);
1475c6c1daeSBarry Smith   *type = ((PetscObject)viewer)->type_name;
1485c6c1daeSBarry Smith   PetscFunctionReturn(0);
1495c6c1daeSBarry Smith }
1505c6c1daeSBarry Smith 
1515c6c1daeSBarry Smith #undef __FUNCT__
1525c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetOptionsPrefix"
1535c6c1daeSBarry Smith /*@C
1545c6c1daeSBarry Smith    PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all
1555c6c1daeSBarry Smith    PetscViewer options in the database.
1565c6c1daeSBarry Smith 
1575c6c1daeSBarry Smith    Logically Collective on PetscViewer
1585c6c1daeSBarry Smith 
1595c6c1daeSBarry Smith    Input Parameter:
1605c6c1daeSBarry Smith +  viewer - the PetscViewer context
1615c6c1daeSBarry Smith -  prefix - the prefix to prepend to all option names
1625c6c1daeSBarry Smith 
1635c6c1daeSBarry Smith    Notes:
1645c6c1daeSBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
1655c6c1daeSBarry Smith    The first character of all runtime options is AUTOMATICALLY the hyphen.
1665c6c1daeSBarry Smith 
1675c6c1daeSBarry Smith    Level: advanced
1685c6c1daeSBarry Smith 
1695c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database
1705c6c1daeSBarry Smith 
1715c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions()
1725c6c1daeSBarry Smith @*/
1735c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
1745c6c1daeSBarry Smith {
1755c6c1daeSBarry Smith   PetscErrorCode ierr;
1765c6c1daeSBarry Smith 
1775c6c1daeSBarry Smith   PetscFunctionBegin;
1785c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
1795c6c1daeSBarry Smith   ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
1805c6c1daeSBarry Smith   PetscFunctionReturn(0);
1815c6c1daeSBarry Smith }
1825c6c1daeSBarry Smith 
1835c6c1daeSBarry Smith #undef __FUNCT__
1845c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerAppendOptionsPrefix"
1855c6c1daeSBarry Smith /*@C
1865c6c1daeSBarry Smith    PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all
1875c6c1daeSBarry Smith    PetscViewer options in the database.
1885c6c1daeSBarry Smith 
1895c6c1daeSBarry Smith    Logically Collective on PetscViewer
1905c6c1daeSBarry Smith 
1915c6c1daeSBarry Smith    Input Parameters:
1925c6c1daeSBarry Smith +  viewer - the PetscViewer context
1935c6c1daeSBarry Smith -  prefix - the prefix to prepend to all option names
1945c6c1daeSBarry Smith 
1955c6c1daeSBarry Smith    Notes:
1965c6c1daeSBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
1975c6c1daeSBarry Smith    The first character of all runtime options is AUTOMATICALLY the hyphen.
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith    Level: advanced
2005c6c1daeSBarry Smith 
2015c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database
2025c6c1daeSBarry Smith 
2035c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix()
2045c6c1daeSBarry Smith @*/
2055c6c1daeSBarry Smith PetscErrorCode  PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
2065c6c1daeSBarry Smith {
2075c6c1daeSBarry Smith   PetscErrorCode ierr;
2085c6c1daeSBarry Smith 
2095c6c1daeSBarry Smith   PetscFunctionBegin;
2105c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2115c6c1daeSBarry Smith   ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
2125c6c1daeSBarry Smith   PetscFunctionReturn(0);
2135c6c1daeSBarry Smith }
2145c6c1daeSBarry Smith 
2155c6c1daeSBarry Smith #undef __FUNCT__
2165c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetOptionsPrefix"
2175c6c1daeSBarry Smith /*@C
2185c6c1daeSBarry Smith    PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all
2195c6c1daeSBarry Smith    PetscViewer options in the database.
2205c6c1daeSBarry Smith 
2215c6c1daeSBarry Smith    Not Collective
2225c6c1daeSBarry Smith 
2235c6c1daeSBarry Smith    Input Parameter:
2245c6c1daeSBarry Smith .  viewer - the PetscViewer context
2255c6c1daeSBarry Smith 
2265c6c1daeSBarry Smith    Output Parameter:
2275c6c1daeSBarry Smith .  prefix - pointer to the prefix string used
2285c6c1daeSBarry Smith 
2295c6c1daeSBarry Smith    Notes: On the fortran side, the user should pass in a string 'prefix' of
2305c6c1daeSBarry Smith    sufficient length to hold the prefix.
2315c6c1daeSBarry Smith 
2325c6c1daeSBarry Smith    Level: advanced
2335c6c1daeSBarry Smith 
2345c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database
2355c6c1daeSBarry Smith 
2365c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix()
2375c6c1daeSBarry Smith @*/
2385c6c1daeSBarry Smith PetscErrorCode  PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
2395c6c1daeSBarry Smith {
2405c6c1daeSBarry Smith   PetscErrorCode ierr;
2415c6c1daeSBarry Smith 
2425c6c1daeSBarry Smith   PetscFunctionBegin;
2435c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2445c6c1daeSBarry Smith   ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
2455c6c1daeSBarry Smith   PetscFunctionReturn(0);
2465c6c1daeSBarry Smith }
2475c6c1daeSBarry Smith 
2485c6c1daeSBarry Smith #undef __FUNCT__
2495c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetUp"
2505c6c1daeSBarry Smith /*@
2515c6c1daeSBarry Smith    PetscViewerSetUp - Sets up the internal viewer data structures for the later use.
2525c6c1daeSBarry Smith 
2535c6c1daeSBarry Smith    Collective on PetscViewer
2545c6c1daeSBarry Smith 
2555c6c1daeSBarry Smith    Input Parameters:
2565c6c1daeSBarry Smith .  viewer - the PetscViewer context
2575c6c1daeSBarry Smith 
2585c6c1daeSBarry Smith    Notes:
2595c6c1daeSBarry Smith    For basic use of the PetscViewer classes the user need not explicitly call
2605c6c1daeSBarry Smith    PetscViewerSetUp(), since these actions will happen automatically.
2615c6c1daeSBarry Smith 
2625c6c1daeSBarry Smith    Level: advanced
2635c6c1daeSBarry Smith 
2645c6c1daeSBarry Smith .keywords: PetscViewer, setup
2655c6c1daeSBarry Smith 
2665c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy()
2675c6c1daeSBarry Smith @*/
2685c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetUp(PetscViewer viewer)
2695c6c1daeSBarry Smith {
270c98fd787SBarry Smith   PetscErrorCode ierr;
271c98fd787SBarry Smith 
2725c6c1daeSBarry Smith   PetscFunctionBegin;
2735c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
274c98fd787SBarry Smith   if (viewer->setupcalled) PetscFunctionReturn(0);
275c98fd787SBarry Smith   if (viewer->ops->setup) {
276c98fd787SBarry Smith     ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr);
277c98fd787SBarry Smith   }
278c98fd787SBarry Smith   viewer->setupcalled = PETSC_TRUE;
2795c6c1daeSBarry Smith   PetscFunctionReturn(0);
2805c6c1daeSBarry Smith }
2815c6c1daeSBarry Smith 
2825c6c1daeSBarry Smith #undef __FUNCT__
2835c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerView"
2845c6c1daeSBarry Smith /*@C
2855c6c1daeSBarry Smith    PetscViewerView - Visualizes a viewer object.
2865c6c1daeSBarry Smith 
2875c6c1daeSBarry Smith    Collective on PetscViewer
2885c6c1daeSBarry Smith 
2895c6c1daeSBarry Smith    Input Parameters:
2905c6c1daeSBarry Smith +  v - the viewer
2915c6c1daeSBarry Smith -  viewer - visualization context
2925c6c1daeSBarry Smith 
2935c6c1daeSBarry Smith   Notes:
2945c6c1daeSBarry Smith   The available visualization contexts include
2955c6c1daeSBarry Smith +    PETSC_VIEWER_STDOUT_SELF - standard output (default)
2965c6c1daeSBarry Smith .    PETSC_VIEWER_STDOUT_WORLD - synchronized standard
2975c6c1daeSBarry Smith         output where only the first processor opens
2985c6c1daeSBarry Smith         the file.  All other processors send their
2995c6c1daeSBarry Smith         data to the first processor to print.
3005c6c1daeSBarry Smith -     PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure
3015c6c1daeSBarry Smith 
3025c6c1daeSBarry Smith    Level: beginner
3035c6c1daeSBarry Smith 
3045c6c1daeSBarry Smith .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(),
3055c6c1daeSBarry Smith           PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
3065c6c1daeSBarry Smith @*/
3075c6c1daeSBarry Smith PetscErrorCode  PetscViewerView(PetscViewer v,PetscViewer viewer)
3085c6c1daeSBarry Smith {
3095c6c1daeSBarry Smith   PetscErrorCode    ierr;
3105c6c1daeSBarry Smith   PetscBool         iascii;
3115c6c1daeSBarry Smith   PetscViewerFormat format;
312e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
313536b137fSBarry Smith   PetscBool         issaws;
3140076e027SBarry Smith #endif
3155c6c1daeSBarry Smith 
3165c6c1daeSBarry Smith   PetscFunctionBegin;
3175c6c1daeSBarry Smith   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
3185c6c1daeSBarry Smith   PetscValidType(v,1);
3195c6c1daeSBarry Smith   if (!viewer) {
320ce94432eSBarry Smith     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr);
3215c6c1daeSBarry Smith   }
3225c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
3235c6c1daeSBarry Smith   PetscCheckSameComm(v,1,viewer,2);
3245c6c1daeSBarry Smith 
3255c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
326e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
327536b137fSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr);
3280076e027SBarry Smith #endif
3295c6c1daeSBarry Smith   if (iascii) {
3305c6c1daeSBarry Smith     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
331dae58748SBarry Smith     ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr);
33298c3331eSBarry Smith     if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
3332f234a98SBarry Smith       if (v->format) {
3342f234a98SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"  Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr);
3352f234a98SBarry Smith       }
3365c6c1daeSBarry Smith       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
3372bf49c77SBarry Smith       if (v->ops->view) {
3382bf49c77SBarry Smith         ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr);
3395c6c1daeSBarry Smith       }
3405c6c1daeSBarry Smith       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
3415c6c1daeSBarry Smith     }
342e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
343536b137fSBarry Smith   } else if (issaws) {
3440076e027SBarry Smith     if (!((PetscObject)v)->amsmem) {
345e04113cfSBarry Smith       ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr);
3460076e027SBarry Smith       if (v->ops->view) {
3470076e027SBarry Smith         ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr);
3480076e027SBarry Smith       }
3490076e027SBarry Smith     }
3500076e027SBarry Smith #endif
3515c6c1daeSBarry Smith   }
3525c6c1daeSBarry Smith   PetscFunctionReturn(0);
3535c6c1daeSBarry Smith }
3541d641e7bSMichael Lange 
3551d641e7bSMichael Lange #undef __FUNCT__
3561d641e7bSMichael Lange #define __FUNCT__ "PetscViewerRead"
3571d641e7bSMichael Lange /*@C
3581d641e7bSMichael Lange    PetscViewerRead - Reads data from a PetscViewer
3591d641e7bSMichael Lange 
3601d641e7bSMichael Lange    Collective on MPI_Comm
3611d641e7bSMichael Lange 
3621d641e7bSMichael Lange    Input Parameters:
3631d641e7bSMichael Lange +  viewer   - The viewer
3641d641e7bSMichael Lange .  data     - Location to write the data
3651d641e7bSMichael Lange .  count    - Number of items of data to read
3661d641e7bSMichael Lange -  datatype - Type of data to read
3671d641e7bSMichael Lange 
368*f8e4bde8SMatthew G. Knepley    Output Parameters:
369*f8e4bde8SMatthew G. Knepley .  count - number of items of data actually read
370*f8e4bde8SMatthew G. Knepley 
3711d641e7bSMichael Lange    Level: beginner
3721d641e7bSMichael Lange 
3731d641e7bSMichael Lange    Concepts: binary files, ascii files
3741d641e7bSMichael Lange 
3751d641e7bSMichael Lange .seealso: PetscViewerASCIIOpen(), PetscViewerSetFormat(), PetscViewerDestroy(),
3761d641e7bSMichael Lange           VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(),
3771d641e7bSMichael Lange           PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer
3781d641e7bSMichael Lange @*/
379*f8e4bde8SMatthew G. Knepley PetscErrorCode  PetscViewerRead(PetscViewer viewer, void *data, PetscInt *count, PetscDataType dtype)
3801d641e7bSMichael Lange {
381*f8e4bde8SMatthew G. Knepley   PetscInt       cnt = *count;
3821d641e7bSMichael Lange   PetscErrorCode ierr;
3831d641e7bSMichael Lange 
3841d641e7bSMichael Lange   PetscFunctionBegin;
3851d641e7bSMichael Lange   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
3861d641e7bSMichael Lange   if (dtype == PETSC_STRING) {
387*f8e4bde8SMatthew G. Knepley     PetscInt c, i = 0, num = 1;
3881d641e7bSMichael Lange     char *s = (char *)data;
389*f8e4bde8SMatthew G. Knepley     for (c = 0; c < cnt; c++) {
3901d641e7bSMichael Lange       /* Skip leading whitespaces */
391*f8e4bde8SMatthew G. Knepley       do {ierr = (*viewer->ops->read)(viewer, &(s[i]), &num, PETSC_CHAR);CHKERRQ(ierr); if (!num) break;}
3921d641e7bSMichael Lange       while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0');
3931d641e7bSMichael Lange       i++;
3941d641e7bSMichael Lange       /* Read strings one char at a time */
395*f8e4bde8SMatthew G. Knepley       do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), &num, PETSC_CHAR);CHKERRQ(ierr); if (!num) break;}
3961d641e7bSMichael Lange       while (s[i-1]!='\n' && s[i-1]!='\t' && s[i-1]!=' ' && s[i-1]!='\0');
3971d641e7bSMichael Lange       /* Terminate final string */
398*f8e4bde8SMatthew G. Knepley       if (c == cnt-1) s[i-1] = '\0';
3991d641e7bSMichael Lange     }
4001d641e7bSMichael Lange   } else {
4011d641e7bSMichael Lange     ierr = (*viewer->ops->read)(viewer, data, count, dtype);CHKERRQ(ierr);
4021d641e7bSMichael Lange   }
4031d641e7bSMichael Lange   PetscFunctionReturn(0);
4041d641e7bSMichael Lange }
405