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