Actual source code: ex4.c

  1: static char help[] = "Tests PetscOptionsGetViewer() via checking output of PetscViewerASCIIPrintf().\n\n";

  3: #include <petscviewer.h>

  5: int main(int argc, char **args)
  6: {
  7:   PetscViewer       viewer;
  8:   PetscViewerFormat format;
  9:   PetscBool         iascii;

 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(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: }

 30: /*TEST

 32:    test:
 33:       args: -myviewer ascii:ex4w1.tmp
 34:       filter: cat ex4w1.tmp
 35:       output_file: output/ex4w.out

 37:    test:
 38:       suffix: 2
 39:       args: -myviewer ascii:ex4w2.tmp::
 40:       filter: cat ex4w2.tmp
 41:       output_file: output/ex4w.out

 43:    test:
 44:       suffix: 3
 45:       args: -myviewer ascii:ex4w3.tmp::write
 46:       filter: cat ex4w3.tmp
 47:       output_file: output/ex4w.out

 49:    test:
 50:       suffix: 4
 51:       args: -myviewer ascii:ex4a1.tmp::append
 52:       filter: cat ex4a1.tmp
 53:       output_file: output/ex4a.out

 55: TEST*/