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