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 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(PetscViewerDestroy(&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(PetscViewerDestroy(&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