xref: /petsc/src/sys/classes/viewer/interface/viewa.c (revision 6dd63270497ad23dcf16ae500a87ff2b2a0b7474)
1 #include <petsc/private/viewerimpl.h> /*I "petscsys.h" I*/
2 
3 const char *const PetscViewerFormats[] = {"DEFAULT", "ASCII_MATLAB", "ASCII_MATHEMATICA", "ASCII_IMPL", "ASCII_INFO", "ASCII_INFO_DETAIL", "ASCII_COMMON", "ASCII_SYMMODU", "ASCII_INDEX", "ASCII_DENSE", "ASCII_MATRIXMARKET", "ASCII_PCICE", "ASCII_PYTHON", "ASCII_FACTOR_INFO", "ASCII_LATEX", "ASCII_XML", "ASCII_FLAMEGRAPH", "ASCII_GLVIS", "ASCII_CSV", "DRAW_BASIC", "DRAW_LG", "DRAW_LG_XRANGE", "DRAW_CONTOUR", "DRAW_PORTS", "VTK_VTS", "VTK_VTR", "VTK_VTU", "BINARY_MATLAB", "NATIVE", "HDF5_PETSC", "HDF5_VIZ", "HDF5_XDMF", "HDF5_MAT", "NOFORMAT", "LOAD_BALANCE", "FAILED", "ALL", "PetscViewerFormat", "PETSC_VIEWER_", NULL};
4 
5 /*@C
6   PetscViewerSetFormat - Sets the format for a `PetscViewer`.
7 
8   Logically Collective, No Fortran Support
9 
10   This routine is deprecated, you should use `PetscViewerPushFormat()`/`PetscViewerPopFormat()`
11 
12   Input Parameters:
13 + viewer - the `PetscViewer`
14 - format - the format
15 
16   Level: deprecated
17 
18   Note:
19   See `PetscViewerFormat` for available values
20 
21 .seealso: [](sec_viewers), `PetscViewerGetFormat()`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
22           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
23 @*/
24 PetscErrorCode PetscViewerSetFormat(PetscViewer viewer, PetscViewerFormat format)
25 {
26   PetscFunctionBegin;
27   if (!viewer) viewer = PETSC_VIEWER_STDOUT_SELF;
28   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
29   PetscValidLogicalCollectiveEnum(viewer, format, 2);
30   viewer->format = format;
31   PetscFunctionReturn(PETSC_SUCCESS);
32 }
33 
34 /*@
35   PetscViewerPushFormat - Sets the format for a `PetscViewer`.
36 
37   Logically Collective
38 
39   Input Parameters:
40 + viewer - the `PetscViewer`
41 - format - the format
42 
43   Level: intermediate
44 
45   Note:
46   See `PetscViewerFormat` for available values
47 
48 .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerFormat`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
49           `PetscViewerSetFormat()`, `PetscViewerPopFormat()`
50 @*/
51 PetscErrorCode PetscViewerPushFormat(PetscViewer viewer, PetscViewerFormat format)
52 {
53   PetscFunctionBegin;
54   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
55   PetscValidLogicalCollectiveEnum(viewer, format, 2);
56   PetscCheck(viewer->iformat <= PETSCVIEWERFORMATPUSHESMAX - 1, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Too many PetscViewerPushFormat(), perhaps you forgot PetscViewerPopFormat()?");
57 
58   viewer->formats[viewer->iformat++] = viewer->format;
59   viewer->format                     = format;
60   PetscFunctionReturn(PETSC_SUCCESS);
61 }
62 
63 /*@
64   PetscViewerPopFormat - Resets the format for a `PetscViewer` to the value it had before the previous call to `PetscViewerPushFormat()`
65 
66   Logically Collective
67 
68   Input Parameter:
69 . viewer - the `PetscViewer`
70 
71   Level: intermediate
72 
73 .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerFormat`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`,
74           `PetscViewerSetFormat()`, `PetscViewerPushFormat()`
75 @*/
76 PetscErrorCode PetscViewerPopFormat(PetscViewer viewer)
77 {
78   PetscFunctionBegin;
79   PetscValidHeaderSpecific(viewer, PETSC_VIEWER_CLASSID, 1);
80   if (viewer->iformat <= 0) PetscFunctionReturn(PETSC_SUCCESS);
81 
82   viewer->format = viewer->formats[--viewer->iformat];
83   PetscFunctionReturn(PETSC_SUCCESS);
84 }
85 
86 /*@
87   PetscViewerGetFormat - Gets the current format for `PetscViewer`.
88 
89   Not Collective
90 
91   Input Parameter:
92 . viewer - the `PetscViewer`
93 
94   Output Parameter:
95 . format - the format
96 
97   Level: intermediate
98 
99   Note:
100   See `PetscViewerFormat` for available values
101 
102 .seealso: [](sec_viewers), `PetscViewer`, `PetscViewerASCIIOpen()`, `PetscViewerBinaryOpen()`, `MatView()`, `VecView()`, `PetscViewerType`,
103           `PetscViewerPushFormat()`, `PetscViewerPopFormat()`, `PetscViewerDrawOpen()`, `PetscViewerSocketOpen()`
104 @*/
105 PetscErrorCode PetscViewerGetFormat(PetscViewer viewer, PetscViewerFormat *format)
106 {
107   PetscFunctionBegin;
108   *format = viewer->format;
109   PetscFunctionReturn(PETSC_SUCCESS);
110 }
111