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