xref: /petsc/src/sys/classes/viewer/tests/ex5.c (revision 648c30bcb65f74c3cbd15d7a91a7ed7c1890e25b)
1c4762a1bSJed Brown static char help[] = "Tests PetscOptionsPushGetViewerOff() via checking output of PetscViewerASCIIPrintf().\n\n";
2c4762a1bSJed Brown 
3c4762a1bSJed Brown #include <petscviewer.h>
4c4762a1bSJed Brown 
5d71ae5a4SJacob Faibussowitsch int main(int argc, char **args)
6d71ae5a4SJacob Faibussowitsch {
7c4762a1bSJed Brown   PetscViewer       viewer;
8c4762a1bSJed Brown   PetscViewerFormat format;
9c4762a1bSJed Brown   PetscBool         iascii;
10c4762a1bSJed Brown 
11327415f7SBarry Smith   PetscFunctionBeginUser;
129566063dSJacob Faibussowitsch   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
13*648c30bcSBarry Smith   PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL));
149566063dSJacob Faibussowitsch   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii));
15c4762a1bSJed Brown   if (iascii) {
16c4762a1bSJed Brown     PetscBool flg;
179566063dSJacob Faibussowitsch     PetscCall(PetscViewerPushFormat(viewer, format));
189566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 0));
199566063dSJacob Faibussowitsch     PetscCall(PetscViewerPopFormat(viewer));
20*648c30bcSBarry Smith     PetscCall(PetscViewerDestroy(&viewer));
21*648c30bcSBarry Smith     PetscCall(PetscOptionsPushCreateViewerOff(PETSC_TRUE));
22*648c30bcSBarry Smith     PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg));
2328b400f6SJacob Faibussowitsch     PetscCheck(!flg, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Pushed viewer off, but viewer was set");
24c4762a1bSJed Brown     if (viewer) {
259566063dSJacob Faibussowitsch       PetscCall(PetscViewerPushFormat(viewer, format));
269566063dSJacob Faibussowitsch       PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 1));
279566063dSJacob Faibussowitsch       PetscCall(PetscViewerPopFormat(viewer));
28c4762a1bSJed Brown     }
29*648c30bcSBarry Smith     PetscCall(PetscOptionsPopCreateViewerOff());
30*648c30bcSBarry Smith     PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg));
319566063dSJacob Faibussowitsch     PetscCall(PetscViewerPushFormat(viewer, format));
329566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 2));
339566063dSJacob Faibussowitsch     PetscCall(PetscViewerPopFormat(viewer));
34c4762a1bSJed Brown   }
35*648c30bcSBarry Smith   PetscCall(PetscViewerDestroy(&viewer));
369566063dSJacob Faibussowitsch   PetscCall(PetscFinalize());
37b122ec5aSJacob Faibussowitsch   return 0;
38c4762a1bSJed Brown }
39c4762a1bSJed Brown 
40c4762a1bSJed Brown /*TEST
41c4762a1bSJed Brown 
42c4762a1bSJed Brown    test:
43c4762a1bSJed Brown       args: -myviewer
44c4762a1bSJed Brown 
45c4762a1bSJed Brown TEST*/
46