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