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