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