xref: /petsc/src/sys/classes/viewer/interface/view.c (revision d7cbc13ea6be0157d079f2146f7336d278589a5b)
15c6c1daeSBarry Smith 
2af0996ceSBarry Smith #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 */
56c5929fdfSBarry Smith   ierr = PetscOptionsGetString(NULL,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 */
64c5929fdfSBarry Smith   ierr = PetscOptionsGetString(NULL,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__
113*d7cbc13eSBarry Smith #define __FUNCT__ "PetscViewerAndFormatCreate"
114*d7cbc13eSBarry Smith /*@C
115*d7cbc13eSBarry Smith    PetscViewerAndFormatCreate - Creates a PetscViewerAndFormat struct.
116*d7cbc13eSBarry Smith 
117*d7cbc13eSBarry Smith    Collective on PetscViewer
118*d7cbc13eSBarry Smith 
119*d7cbc13eSBarry Smith    Input Parameters:
120*d7cbc13eSBarry Smith +  viewer - the viewer
121*d7cbc13eSBarry Smith -  format - the format
122*d7cbc13eSBarry Smith 
123*d7cbc13eSBarry Smith    Output Parameter:
124*d7cbc13eSBarry Smith .   vf - viewer and format object
125*d7cbc13eSBarry Smith 
126*d7cbc13eSBarry Smith    Notes: This increases the reference count of the viewer so you can destroy the viewer object after this call
127*d7cbc13eSBarry Smith    Level: developer
128*d7cbc13eSBarry Smith 
129*d7cbc13eSBarry Smith    This is used as the context variable for many of the TS, SNES, and KSP monitor functions
130*d7cbc13eSBarry Smith 
131*d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatDestroy()
132*d7cbc13eSBarry Smith 
133*d7cbc13eSBarry Smith @*/
134*d7cbc13eSBarry Smith PetscErrorCode  PetscViewerAndFormatCreate(PetscViewer viewer, PetscViewerFormat format,PetscViewerAndFormat **vf)
135*d7cbc13eSBarry Smith {
136*d7cbc13eSBarry Smith   PetscErrorCode ierr;
137*d7cbc13eSBarry Smith 
138*d7cbc13eSBarry Smith   PetscFunctionBegin;
139*d7cbc13eSBarry Smith   ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr);
140*d7cbc13eSBarry Smith   ierr = PetscNew(vf);CHKERRQ(ierr);
141*d7cbc13eSBarry Smith   (*vf)->viewer = viewer;
142*d7cbc13eSBarry Smith   (*vf)->format = format;
143*d7cbc13eSBarry Smith   PetscFunctionReturn(0);
144*d7cbc13eSBarry Smith }
145*d7cbc13eSBarry Smith 
146*d7cbc13eSBarry Smith 
147*d7cbc13eSBarry Smith #undef __FUNCT__
148fe01d993SBarry Smith #define __FUNCT__ "PetscViewerAndFormatDestroy"
149fe01d993SBarry Smith /*@C
150fe01d993SBarry Smith    PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct.
151fe01d993SBarry Smith 
152fe01d993SBarry Smith    Collective on PetscViewer
153fe01d993SBarry Smith 
154fe01d993SBarry Smith    Input Parameters:
155fe01d993SBarry Smith .  viewer - the PetscViewerAndFormat to be destroyed.
156fe01d993SBarry Smith 
157*d7cbc13eSBarry Smith    Level: developer
158fe01d993SBarry Smith 
159*d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatCreate()
160fe01d993SBarry Smith 
161fe01d993SBarry Smith @*/
162fe01d993SBarry Smith PetscErrorCode  PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf)
163fe01d993SBarry Smith {
164fe01d993SBarry Smith   PetscErrorCode ierr;
165fe01d993SBarry Smith 
166fe01d993SBarry Smith   PetscFunctionBegin;
167fe01d993SBarry Smith   ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr);
168fe01d993SBarry Smith   ierr = PetscFree(*vf);CHKERRQ(ierr);
169fe01d993SBarry Smith   PetscFunctionReturn(0);
170fe01d993SBarry Smith }
171fe01d993SBarry Smith 
172fe01d993SBarry Smith #undef __FUNCT__
1735c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetType"
1745c6c1daeSBarry Smith /*@C
1755c6c1daeSBarry Smith    PetscViewerGetType - Returns the type of a PetscViewer.
1765c6c1daeSBarry Smith 
1775c6c1daeSBarry Smith    Not Collective
1785c6c1daeSBarry Smith 
1795c6c1daeSBarry Smith    Input Parameter:
1805c6c1daeSBarry Smith .   viewer - the PetscViewer
1815c6c1daeSBarry Smith 
1825c6c1daeSBarry Smith    Output Parameter:
1835c6c1daeSBarry Smith .  type - PetscViewer type (see below)
1845c6c1daeSBarry Smith 
1855c6c1daeSBarry Smith    Available Types Include:
1865c6c1daeSBarry Smith .  PETSCVIEWERSOCKET - Socket PetscViewer
1875c6c1daeSBarry Smith .  PETSCVIEWERASCII - ASCII PetscViewer
1885c6c1daeSBarry Smith .  PETSCVIEWERBINARY - binary file PetscViewer
1895c6c1daeSBarry Smith .  PETSCVIEWERSTRING - string PetscViewer
1905c6c1daeSBarry Smith .  PETSCVIEWERDRAW - drawing PetscViewer
1915c6c1daeSBarry Smith 
1925c6c1daeSBarry Smith    Level: intermediate
1935c6c1daeSBarry Smith 
1945c6c1daeSBarry Smith    Note:
1955c6c1daeSBarry Smith    See include/petscviewer.h for a complete list of PetscViewers.
1965c6c1daeSBarry Smith 
1975c6c1daeSBarry Smith    PetscViewerType is actually a string
1985c6c1daeSBarry Smith 
1995c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType
2005c6c1daeSBarry Smith 
2015c6c1daeSBarry Smith @*/
2025c6c1daeSBarry Smith PetscErrorCode  PetscViewerGetType(PetscViewer viewer,PetscViewerType *type)
2035c6c1daeSBarry Smith {
2045c6c1daeSBarry Smith   PetscFunctionBegin;
2055c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2065c6c1daeSBarry Smith   PetscValidPointer(type,2);
2075c6c1daeSBarry Smith   *type = ((PetscObject)viewer)->type_name;
2085c6c1daeSBarry Smith   PetscFunctionReturn(0);
2095c6c1daeSBarry Smith }
2105c6c1daeSBarry Smith 
2115c6c1daeSBarry Smith #undef __FUNCT__
2125c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetOptionsPrefix"
2135c6c1daeSBarry Smith /*@C
2145c6c1daeSBarry Smith    PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all
2155c6c1daeSBarry Smith    PetscViewer options in the database.
2165c6c1daeSBarry Smith 
2175c6c1daeSBarry Smith    Logically Collective on PetscViewer
2185c6c1daeSBarry Smith 
2195c6c1daeSBarry Smith    Input Parameter:
2205c6c1daeSBarry Smith +  viewer - the PetscViewer context
2215c6c1daeSBarry Smith -  prefix - the prefix to prepend to all option names
2225c6c1daeSBarry Smith 
2235c6c1daeSBarry Smith    Notes:
2245c6c1daeSBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
2255c6c1daeSBarry Smith    The first character of all runtime options is AUTOMATICALLY the hyphen.
2265c6c1daeSBarry Smith 
2275c6c1daeSBarry Smith    Level: advanced
2285c6c1daeSBarry Smith 
2295c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database
2305c6c1daeSBarry Smith 
2315c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions()
2325c6c1daeSBarry Smith @*/
2335c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
2345c6c1daeSBarry Smith {
2355c6c1daeSBarry Smith   PetscErrorCode ierr;
2365c6c1daeSBarry Smith 
2375c6c1daeSBarry Smith   PetscFunctionBegin;
2385c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2395c6c1daeSBarry Smith   ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
2405c6c1daeSBarry Smith   PetscFunctionReturn(0);
2415c6c1daeSBarry Smith }
2425c6c1daeSBarry Smith 
2435c6c1daeSBarry Smith #undef __FUNCT__
2445c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerAppendOptionsPrefix"
2455c6c1daeSBarry Smith /*@C
2465c6c1daeSBarry Smith    PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all
2475c6c1daeSBarry Smith    PetscViewer options in the database.
2485c6c1daeSBarry Smith 
2495c6c1daeSBarry Smith    Logically Collective on PetscViewer
2505c6c1daeSBarry Smith 
2515c6c1daeSBarry Smith    Input Parameters:
2525c6c1daeSBarry Smith +  viewer - the PetscViewer context
2535c6c1daeSBarry Smith -  prefix - the prefix to prepend to all option names
2545c6c1daeSBarry Smith 
2555c6c1daeSBarry Smith    Notes:
2565c6c1daeSBarry Smith    A hyphen (-) must NOT be given at the beginning of the prefix name.
2575c6c1daeSBarry Smith    The first character of all runtime options is AUTOMATICALLY the hyphen.
2585c6c1daeSBarry Smith 
2595c6c1daeSBarry Smith    Level: advanced
2605c6c1daeSBarry Smith 
2615c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database
2625c6c1daeSBarry Smith 
2635c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix()
2645c6c1daeSBarry Smith @*/
2655c6c1daeSBarry Smith PetscErrorCode  PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
2665c6c1daeSBarry Smith {
2675c6c1daeSBarry Smith   PetscErrorCode ierr;
2685c6c1daeSBarry Smith 
2695c6c1daeSBarry Smith   PetscFunctionBegin;
2705c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
2715c6c1daeSBarry Smith   ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
2725c6c1daeSBarry Smith   PetscFunctionReturn(0);
2735c6c1daeSBarry Smith }
2745c6c1daeSBarry Smith 
2755c6c1daeSBarry Smith #undef __FUNCT__
2765c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetOptionsPrefix"
2775c6c1daeSBarry Smith /*@C
2785c6c1daeSBarry Smith    PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all
2795c6c1daeSBarry Smith    PetscViewer options in the database.
2805c6c1daeSBarry Smith 
2815c6c1daeSBarry Smith    Not Collective
2825c6c1daeSBarry Smith 
2835c6c1daeSBarry Smith    Input Parameter:
2845c6c1daeSBarry Smith .  viewer - the PetscViewer context
2855c6c1daeSBarry Smith 
2865c6c1daeSBarry Smith    Output Parameter:
2875c6c1daeSBarry Smith .  prefix - pointer to the prefix string used
2885c6c1daeSBarry Smith 
2895c6c1daeSBarry Smith    Notes: On the fortran side, the user should pass in a string 'prefix' of
2905c6c1daeSBarry Smith    sufficient length to hold the prefix.
2915c6c1daeSBarry Smith 
2925c6c1daeSBarry Smith    Level: advanced
2935c6c1daeSBarry Smith 
2945c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database
2955c6c1daeSBarry Smith 
2965c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix()
2975c6c1daeSBarry Smith @*/
2985c6c1daeSBarry Smith PetscErrorCode  PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
2995c6c1daeSBarry Smith {
3005c6c1daeSBarry Smith   PetscErrorCode ierr;
3015c6c1daeSBarry Smith 
3025c6c1daeSBarry Smith   PetscFunctionBegin;
3035c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
3045c6c1daeSBarry Smith   ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr);
3055c6c1daeSBarry Smith   PetscFunctionReturn(0);
3065c6c1daeSBarry Smith }
3075c6c1daeSBarry Smith 
3085c6c1daeSBarry Smith #undef __FUNCT__
3095c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetUp"
3105c6c1daeSBarry Smith /*@
3115c6c1daeSBarry Smith    PetscViewerSetUp - Sets up the internal viewer data structures for the later use.
3125c6c1daeSBarry Smith 
3135c6c1daeSBarry Smith    Collective on PetscViewer
3145c6c1daeSBarry Smith 
3155c6c1daeSBarry Smith    Input Parameters:
3165c6c1daeSBarry Smith .  viewer - the PetscViewer context
3175c6c1daeSBarry Smith 
3185c6c1daeSBarry Smith    Notes:
3195c6c1daeSBarry Smith    For basic use of the PetscViewer classes the user need not explicitly call
3205c6c1daeSBarry Smith    PetscViewerSetUp(), since these actions will happen automatically.
3215c6c1daeSBarry Smith 
3225c6c1daeSBarry Smith    Level: advanced
3235c6c1daeSBarry Smith 
3245c6c1daeSBarry Smith .keywords: PetscViewer, setup
3255c6c1daeSBarry Smith 
3265c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy()
3275c6c1daeSBarry Smith @*/
3285c6c1daeSBarry Smith PetscErrorCode  PetscViewerSetUp(PetscViewer viewer)
3295c6c1daeSBarry Smith {
330c98fd787SBarry Smith   PetscErrorCode ierr;
331c98fd787SBarry Smith 
3325c6c1daeSBarry Smith   PetscFunctionBegin;
3335c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
334c98fd787SBarry Smith   if (viewer->setupcalled) PetscFunctionReturn(0);
335c98fd787SBarry Smith   if (viewer->ops->setup) {
336c98fd787SBarry Smith     ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr);
337c98fd787SBarry Smith   }
338c98fd787SBarry Smith   viewer->setupcalled = PETSC_TRUE;
3395c6c1daeSBarry Smith   PetscFunctionReturn(0);
3405c6c1daeSBarry Smith }
3415c6c1daeSBarry Smith 
3425c6c1daeSBarry Smith #undef __FUNCT__
3435c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerView"
3445c6c1daeSBarry Smith /*@C
3455c6c1daeSBarry Smith    PetscViewerView - Visualizes a viewer object.
3465c6c1daeSBarry Smith 
3475c6c1daeSBarry Smith    Collective on PetscViewer
3485c6c1daeSBarry Smith 
3495c6c1daeSBarry Smith    Input Parameters:
3505c6c1daeSBarry Smith +  v - the viewer
3515c6c1daeSBarry Smith -  viewer - visualization context
3525c6c1daeSBarry Smith 
3535c6c1daeSBarry Smith   Notes:
3545c6c1daeSBarry Smith   The available visualization contexts include
3555c6c1daeSBarry Smith +    PETSC_VIEWER_STDOUT_SELF - standard output (default)
3565c6c1daeSBarry Smith .    PETSC_VIEWER_STDOUT_WORLD - synchronized standard
3575c6c1daeSBarry Smith         output where only the first processor opens
3585c6c1daeSBarry Smith         the file.  All other processors send their
3595c6c1daeSBarry Smith         data to the first processor to print.
3605c6c1daeSBarry Smith -     PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure
3615c6c1daeSBarry Smith 
3625c6c1daeSBarry Smith    Level: beginner
3635c6c1daeSBarry Smith 
3646a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(),
3655c6c1daeSBarry Smith           PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
3665c6c1daeSBarry Smith @*/
3675c6c1daeSBarry Smith PetscErrorCode  PetscViewerView(PetscViewer v,PetscViewer viewer)
3685c6c1daeSBarry Smith {
3695c6c1daeSBarry Smith   PetscErrorCode    ierr;
3705c6c1daeSBarry Smith   PetscBool         iascii;
3715c6c1daeSBarry Smith   PetscViewerFormat format;
372e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
373536b137fSBarry Smith   PetscBool         issaws;
3740076e027SBarry Smith #endif
3755c6c1daeSBarry Smith 
3765c6c1daeSBarry Smith   PetscFunctionBegin;
3775c6c1daeSBarry Smith   PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1);
3785c6c1daeSBarry Smith   PetscValidType(v,1);
3795c6c1daeSBarry Smith   if (!viewer) {
380ce94432eSBarry Smith     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr);
3815c6c1daeSBarry Smith   }
3825c6c1daeSBarry Smith   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2);
3835c6c1daeSBarry Smith   PetscCheckSameComm(v,1,viewer,2);
3845c6c1daeSBarry Smith 
3855c6c1daeSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
386e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
387536b137fSBarry Smith   ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr);
3880076e027SBarry Smith #endif
3895c6c1daeSBarry Smith   if (iascii) {
3905c6c1daeSBarry Smith     ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr);
391dae58748SBarry Smith     ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr);
39298c3331eSBarry Smith     if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
3932f234a98SBarry Smith       if (v->format) {
3942f234a98SBarry Smith         ierr = PetscViewerASCIIPrintf(viewer,"  Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr);
3952f234a98SBarry Smith       }
3965c6c1daeSBarry Smith       ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
3972bf49c77SBarry Smith       if (v->ops->view) {
3982bf49c77SBarry Smith         ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr);
3995c6c1daeSBarry Smith       }
4005c6c1daeSBarry Smith       ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
4015c6c1daeSBarry Smith     }
402e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
403536b137fSBarry Smith   } else if (issaws) {
4040076e027SBarry Smith     if (!((PetscObject)v)->amsmem) {
405e04113cfSBarry Smith       ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr);
4060076e027SBarry Smith       if (v->ops->view) {
4070076e027SBarry Smith         ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr);
4080076e027SBarry Smith       }
4090076e027SBarry Smith     }
4100076e027SBarry Smith #endif
4115c6c1daeSBarry Smith   }
4125c6c1daeSBarry Smith   PetscFunctionReturn(0);
4135c6c1daeSBarry Smith }
4141d641e7bSMichael Lange 
4151d641e7bSMichael Lange #undef __FUNCT__
4161d641e7bSMichael Lange #define __FUNCT__ "PetscViewerRead"
4171d641e7bSMichael Lange /*@C
4181d641e7bSMichael Lange    PetscViewerRead - Reads data from a PetscViewer
4191d641e7bSMichael Lange 
4201d641e7bSMichael Lange    Collective on MPI_Comm
4211d641e7bSMichael Lange 
4221d641e7bSMichael Lange    Input Parameters:
4231d641e7bSMichael Lange +  viewer   - The viewer
4241d641e7bSMichael Lange .  data     - Location to write the data
425060da220SMatthew G. Knepley .  num      - Number of items of data to read
4261d641e7bSMichael Lange -  datatype - Type of data to read
4271d641e7bSMichael Lange 
428f8e4bde8SMatthew G. Knepley    Output Parameters:
429060da220SMatthew G. Knepley .  count - number of items of data actually read, or NULL
430f8e4bde8SMatthew G. Knepley 
4311d641e7bSMichael Lange    Level: beginner
4321d641e7bSMichael Lange 
4331d641e7bSMichael Lange    Concepts: binary files, ascii files
4341d641e7bSMichael Lange 
4356a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(),
4361d641e7bSMichael Lange           VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(),
4371d641e7bSMichael Lange           PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer
4381d641e7bSMichael Lange @*/
439060da220SMatthew G. Knepley PetscErrorCode  PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype)
4401d641e7bSMichael Lange {
4411d641e7bSMichael Lange   PetscErrorCode ierr;
4421d641e7bSMichael Lange 
4431d641e7bSMichael Lange   PetscFunctionBegin;
4441d641e7bSMichael Lange   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
4451d641e7bSMichael Lange   if (dtype == PETSC_STRING) {
446060da220SMatthew G. Knepley     PetscInt c, i = 0, cnt;
4471d641e7bSMichael Lange     char *s = (char *)data;
448060da220SMatthew G. Knepley     for (c = 0; c < num; c++) {
4491d641e7bSMichael Lange       /* Skip leading whitespaces */
450060da220SMatthew G. Knepley       do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;}
451eb2700f0SMichael Lange       while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r');
4521d641e7bSMichael Lange       i++;
4531d641e7bSMichael Lange       /* Read strings one char at a time */
454060da220SMatthew G. Knepley       do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;}
455eb2700f0SMichael Lange       while (s[i-1]!='\n' && s[i-1]!='\t' && s[i-1]!=' ' && s[i-1]!='\0' && s[i-1]!='\v' && s[i-1]!='\f' && s[i-1]!='\r');
4561d641e7bSMichael Lange       /* Terminate final string */
457060da220SMatthew G. Knepley       if (c == num-1) s[i-1] = '\0';
4581d641e7bSMichael Lange     }
459060da220SMatthew G. Knepley     if (count) *count = c;
460060da220SMatthew G. Knepley     else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num);
4611d641e7bSMichael Lange   } else {
462060da220SMatthew G. Knepley     ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr);
4631d641e7bSMichael Lange   }
4641d641e7bSMichael Lange   PetscFunctionReturn(0);
4651d641e7bSMichael Lange }
466