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:   PetscErrorCode    ierr;
 10:   PetscViewerFormat format;
 11:   PetscBool         iascii;

 13:   PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
 14:   PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-myviewer",&viewer,&format,NULL);
 15:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
 16:   if (iascii) {
 17:     PetscViewerPushFormat(viewer,format);
 18:     PetscViewerASCIIPrintf(viewer,"Testing PetscViewerASCIIPrintf %d\n", 0);
 19:     PetscViewerPopFormat(viewer);
 20:     PetscViewerDestroy(&viewer);
 21:     PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-myviewer",&viewer,&format,NULL);
 22:     PetscViewerPushFormat(viewer,format);
 23:     PetscViewerASCIIPrintf(viewer,"Testing PetscViewerASCIIPrintf %d\n", 1);
 24:     PetscViewerPopFormat(viewer);
 25:   }
 26:   PetscViewerDestroy(&viewer);
 27:   PetscFinalize();
 28:   return ierr;
 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*/