Actual source code: ex1.c

  1: static char help[] = "Appends to an ASCII file.\n\n";

  3: #include <petscviewer.h>

  5: int main(int argc, char **args)
  6: {
  7:   PetscViewer viewer;

  9:   PetscFunctionBeginUser;
 10:   PetscCall(PetscInitialize(&argc, &args, NULL, help));
 11:   PetscCall(PetscViewerCreate(PETSC_COMM_WORLD, &viewer));
 12:   PetscCall(PetscViewerSetType(viewer, PETSCVIEWERASCII));
 13:   PetscCall(PetscViewerFileSetMode(viewer, FILE_MODE_APPEND));
 14:   PetscCall(PetscViewerFileSetName(viewer, "test.txt"));
 15:   for (PetscInt i = 0; i < 10; ++i) PetscCall(PetscViewerASCIIPrintf(viewer, "test line %" PetscInt_FMT "\n", i));
 16:   PetscCall(PetscViewerDestroy(&viewer));
 17:   PetscCall(PetscFinalize());
 18:   return 0;
 19: }

 21: /*TEST

 23:    test:
 24:      output_file: output/empty.out

 26: TEST*/