Actual source code: ex47.c

  1: static char help[] = "Example for PetscOptionsInsertFileYAML\n";

  3: #include <petscsys.h>
  4: #include <petscviewer.h>

  6: int main(int argc, char **argv)
  7: {
  8:   char      filename[PETSC_MAX_PATH_LEN];
  9:   PetscBool flg;

 12:   PetscInitialize(&argc, &argv, NULL, help);

 14:   PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg);
 15:   if (flg) PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE);

 17:   PetscOptionsGetString(NULL, NULL, "-yaml", filename, sizeof(filename), &flg);
 18:   if (flg) {
 19:     PetscBool monitor = PETSC_FALSE;

 21:     PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL);
 22:     if (monitor) PetscOptionsMonitorSet(PetscOptionsMonitorDefault, NULL, NULL);
 23:     PetscOptionsClear(NULL);
 24:     PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE);
 25:   }

 27:   PetscOptionsView(NULL, PETSC_VIEWER_STDOUT_WORLD);
 28:   PetscOptionsClear(NULL);
 29:   PetscFinalize();
 30:   return 0;
 31: }

 33: /*TEST

 35:    testset:
 36:      args: -options_left false
 37:      filter:  grep -E -v "(options_left|options_monitor)"
 38:      localrunfiles: petsc.yml

 40:      test:
 41:         suffix: 1
 42:         args: -f petsc.yml

 44:      test:
 45:         suffix: 2_file
 46:         output_file: output/ex47_2.out
 47:         args: -options_file_yaml petsc.yml

 49:      test:
 50:         suffix: 2_string
 51:         output_file: output/ex47_2.out
 52:         args: -options_string_yaml "`cat petsc.yml`"

 54:      test:
 55:         suffix: 2_auto
 56:         args: -options_monitor
 57:         args: -options_file ex47-yaml_tag
 58:         args: -options_file ex47-yaml_doc
 59:         localrunfiles: ex47-yaml_tag ex47-yaml_doc

 61:      test:
 62:         suffix: 2_prefix
 63:         args: -options_monitor
 64:         args: -options_file ex47-opt.txt
 65:         args: -prefix_push p5_ -options_file ex47-opt.yml -prefix_pop
 66:         args: -prefix_push p5_ -options_file ex47-opt.yml:yaml -prefix_pop
 67:         args: -prefix_push p6_ -options_file_yaml ex47-opt.yml -prefix_pop
 68:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 69:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 70:         args: -prefix_push p8_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 71:         args: -prefix_push p9_ -options_file ex47-opt.json -prefix_pop
 72:         localrunfiles: ex47-opt.txt ex47-opt.yml ex47-opt.json

 74:    testset:
 75:      nsize: {{1 2}}

 77:      test:
 78:         suffix: 3_empty
 79:         args: -yaml ex47-empty.yaml
 80:         localrunfiles: ex47-empty.yaml

 82:      test:
 83:         suffix: 3_merge
 84:         args: -yaml ex47-merge.yaml -monitor
 85:         localrunfiles: ex47-merge.yaml

 87:      test:
 88:         suffix: 3_options
 89:         args: -yaml ex47-options.yaml
 90:         localrunfiles: ex47-options.yaml

 92:      test:
 93:         suffix: 3_include
 94:         args: -yaml ex47-include.yaml
 95:         localrunfiles: ex47-include.yaml ex47-empty.yaml ex47-options.yaml

 97:      test:
 98:         suffix: 3_prefix
 99:         args: -yaml ex47-prefix.yaml
100:         localrunfiles: ex47-prefix.yaml

102:      test:
103:         suffix: 3_multidoc
104:         args: -yaml ex47-multidoc.yaml
105:         localrunfiles: ex47-multidoc.yaml

107: TEST*/