xref: /petsc/src/sys/classes/viewer/tests/ex4.c (revision 1b37a2a7cc4a4fb30c3e967db1c694c0a1013f51)
1 static char help[] = "Tests PetscOptionsGetViewer() via checking output of PetscViewerASCIIPrintf().\n\n";
2 
3 #include <petscviewer.h>
4 
5 int main(int argc, char **args)
6 {
7   PetscViewer       viewer;
8   PetscViewerFormat format;
9   PetscBool         iascii;
10 
11   PetscFunctionBeginUser;
12   PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
13   PetscCall(PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL));
14   PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii));
15   if (iascii) {
16     PetscCall(PetscViewerPushFormat(viewer, format));
17     PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 0));
18     PetscCall(PetscViewerPopFormat(viewer));
19     PetscCall(PetscOptionsRestoreViewer(&viewer));
20     PetscCall(PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL));
21     PetscCall(PetscViewerPushFormat(viewer, format));
22     PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 1));
23     PetscCall(PetscViewerPopFormat(viewer));
24   }
25   PetscCall(PetscOptionsRestoreViewer(&viewer));
26   PetscCall(PetscFinalize());
27   return 0;
28 }
29 
30 /*TEST
31 
32    test:
33       args: -myviewer ascii:ex4w1.tmp
34       filter: cat ex4w1.tmp
35       output_file: output/ex4w.out
36 
37    test:
38       suffix: 2
39       args: -myviewer ascii:ex4w2.tmp::
40       filter: cat ex4w2.tmp
41       output_file: output/ex4w.out
42 
43    test:
44       suffix: 3
45       args: -myviewer ascii:ex4w3.tmp::write
46       filter: cat ex4w3.tmp
47       output_file: output/ex4w.out
48 
49    test:
50       suffix: 4
51       args: -myviewer ascii:ex4a1.tmp::append
52       filter: cat ex4a1.tmp
53       output_file: output/ex4a.out
54 
55 TEST*/
56