Actual source code: ex5.c


  2: static char help[] = "Tests PetscOptionsPushGetViewerOff() 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;

 13:   PetscInitialize(&argc, &args, (char *)0, help);
 14:   PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL);
 15:   PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &iascii);
 16:   if (iascii) {
 17:     PetscBool flg;
 18:     PetscViewerPushFormat(viewer, format);
 19:     PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 0);
 20:     PetscViewerPopFormat(viewer);
 21:     PetscViewerDestroy(&viewer);
 22:     PetscOptionsPushGetViewerOff(PETSC_TRUE);
 23:     PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg);
 25:     if (viewer) {
 26:       PetscViewerPushFormat(viewer, format);
 27:       PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 1);
 28:       PetscViewerPopFormat(viewer);
 29:     }
 30:     PetscOptionsPopGetViewerOff();
 31:     PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg);
 32:     PetscViewerPushFormat(viewer, format);
 33:     PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 2);
 34:     PetscViewerPopFormat(viewer);
 35:   }
 36:   PetscViewerDestroy(&viewer);
 37:   PetscFinalize();
 38:   return 0;
 39: }

 41: /*TEST

 43:    test:
 44:       args: -myviewer

 46: TEST*/