Actual source code: ex4.c


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

  4: #include <petscviewer.h>

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

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

 31: /*TEST

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

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

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

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

 56: TEST*/