xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 252ecd3142ba3ca0b326827f24f26bd5c1233270)
1 
2 #include <petsc/private/viewerimpl.h>  /*I "petscsys.h" I*/
3 
4 const char *const PetscViewerFormats[] = {
5   "DEFAULT",
6   "ASCII_MATLAB",
7   "ASCII_MATHEMATICA",
8   "ASCII_IMPL",
9   "ASCII_INFO",
10   "ASCII_INFO_DETAIL",
11   "ASCII_COMMON",
12   "ASCII_SYMMODU",
13   "ASCII_INDEX",
14   "ASCII_DENSE",
15   "ASCII_MATRIXMARKET",
16   "ASCII_VTK",
17   "ASCII_VTK_CELL",
18   "ASCII_VTK_COORDS",
19   "ASCII_PCICE",
20   "ASCII_PYTHON",
21   "ASCII_FACTOR_INFO",
22   "ASCII_LATEX",
23   "ASCII_XML",
24   "ASCII_GLVIS",
25   "DRAW_BASIC",
26   "DRAW_LG",
27   "DRAW_CONTOUR",
28   "DRAW_PORTS",
29   "VTK_VTS",
30   "VTK_VTR",
31   "VTK_VTU",
32   "BINARY_MATLAB",
33   "NATIVE",
34   "HDF5_VIZ",
35   "NOFORMAT",
36   "PetscViewerFormat",
37   "PETSC_VIEWER_",
38   0
39 };
40 
41 /*@C
42    PetscViewerSetFormat - Sets the format for PetscViewers.
43 
44    Logically Collective on PetscViewer
45 
46    This routine is deprecated, you should use PetscViewerPushFormat()/PetscViewerPopFormat()
47 
48    Input Parameters:
49 +  viewer - the PetscViewer
50 -  format - the format
51 
52    Level: intermediate
53 
54    Notes:
55    Available formats include
56 +    PETSC_VIEWER_DEFAULT - default format
57 .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
58 .    PETSC_VIEWER_ASCII_DENSE - print matrix as dense
59 .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
60       (which is in many cases the same as the default)
61 .    PETSC_VIEWER_ASCII_INFO - basic information about object
62 .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
63        about object
64 .    PETSC_VIEWER_ASCII_COMMON - identical output format for
65        all objects of a particular type
66 .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
67        element number next to each vector entry
68 .    PETSC_VIEWER_ASCII_SYMMODU - print parallel vectors without
69        indicating the processor ranges
70 .    PETSC_VIEWER_ASCII_VTK - outputs the object to a VTK file
71 .    PETSC_VIEWER_NATIVE - store the object to the binary
72        file in its native format (for example, dense
73        matrices are stored as dense), DMDA vectors are dumped directly to the
74        file instead of being first put in the natural ordering
75 .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
76 .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
77 -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
78 
79    These formats are most often used for viewing matrices and vectors.
80 
81    If a format (for example PETSC_VIEWER_DRAW_CONTOUR) was applied to a viewer
82   where it didn't apply (PETSC_VIEWER_STDOUT_WORLD) it cause the default behavior
83   for that viewer to be used.
84 
85     Note: This supports passing in a NULL for the viewer for use in the debugger, but it should never be called in the code with a NULL viewer
86 
87    Concepts: PetscViewer^setting format
88 
89 .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(), PetscViewerType,
90           PetscViewerPushFormat(), PetscViewerPopFormat(), PetscViewerDrawOpen(),PetscViewerSocketOpen()
91 @*/
92 PetscErrorCode  PetscViewerSetFormat(PetscViewer viewer,PetscViewerFormat format)
93 {
94   PetscFunctionBegin;
95   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
96   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
97   PetscValidLogicalCollectiveEnum(viewer,format,2);
98   viewer->format = format;
99   PetscFunctionReturn(0);
100 }
101 
102 /*@C
103    PetscViewerPushFormat - Sets the format for file PetscViewers.
104 
105    Logically Collective on PetscViewer
106 
107    Input Parameters:
108 +  viewer - the PetscViewer
109 -  format - the format
110 
111    Level: intermediate
112 
113    Notes:
114    Available formats include
115 +    PETSC_VIEWER_DEFAULT - default format
116 .    PETSC_VIEWER_ASCII_MATLAB - MATLAB format
117 .    PETSC_VIEWER_ASCII_IMPL - implementation-specific format
118       (which is in many cases the same as the default)
119 .    PETSC_VIEWER_ASCII_INFO - basic information about object
120 .    PETSC_VIEWER_ASCII_INFO_DETAIL - more detailed info
121        about object
122 .    PETSC_VIEWER_ASCII_COMMON - identical output format for
123        all objects of a particular type
124 .    PETSC_VIEWER_ASCII_INDEX - (for vectors) prints the vector
125        element number next to each vector entry
126 .    PETSC_VIEWER_NATIVE - store the object to the binary
127        file in its native format (for example, dense
128        matrices are stored as dense), for DMDA vectors displays vectors in DMDA ordering, not natural
129 .    PETSC_VIEWER_DRAW_BASIC - views the vector with a simple 1d plot
130 .    PETSC_VIEWER_DRAW_LG - views the vector with a line graph
131 -    PETSC_VIEWER_DRAW_CONTOUR - views the vector with a contour plot
132 
133    These formats are most often used for viewing matrices and vectors.
134    Currently, the object name is used only in the MATLAB format.
135 
136    Concepts: PetscViewer^setting format
137 
138 .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(),
139           PetscViewerSetFormat(), PetscViewerPopFormat()
140 @*/
141 PetscErrorCode  PetscViewerPushFormat(PetscViewer viewer,PetscViewerFormat format)
142 {
143   PetscFunctionBegin;
144   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
145   PetscValidLogicalCollectiveEnum(viewer,format,2);
146   if (viewer->iformat > PETSCVIEWERFORMATPUSHESMAX-1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
147 
148   viewer->formats[viewer->iformat++] = viewer->format;
149   viewer->format                     = format;
150   PetscFunctionReturn(0);
151 }
152 
153 /*@C
154    PetscViewerPopFormat - Resets the format for file PetscViewers.
155 
156    Logically Collective on PetscViewer
157 
158    Input Parameters:
159 .  viewer - the PetscViewer
160 
161    Level: intermediate
162 
163    Concepts: PetscViewer^setting format
164 
165 .seealso: PetscViewerASCIIOpen(), PetscViewerBinaryOpen(), MatView(), VecView(),
166           PetscViewerSetFormat(), PetscViewerPushFormat()
167 @*/
168 PetscErrorCode  PetscViewerPopFormat(PetscViewer viewer)
169 {
170   PetscFunctionBegin;
171   PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1);
172   if (viewer->iformat <= 0) PetscFunctionReturn(0);
173 
174   viewer->format = viewer->formats[--viewer->iformat];
175   PetscFunctionReturn(0);
176 }
177 
178 PetscErrorCode  PetscViewerGetFormat(PetscViewer viewer,PetscViewerFormat *format)
179 {
180   PetscFunctionBegin;
181   *format =  viewer->format;
182   PetscFunctionReturn(0);
183 }
184 
185 
186 
187