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;
 11:   PetscFunctionBeginUser;
 12:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 14:   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg));
 15:   if (flg) PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));
 17:   PetscCall(PetscOptionsGetString(NULL, NULL, "-yaml", filename, sizeof(filename), &flg));
 18:   if (flg) {
 19:     PetscBool monitor = PETSC_FALSE;
 21:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL));
 22:     if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, PETSC_VIEWER_STDOUT_WORLD, NULL));
 23:     PetscCall(PetscOptionsClear(NULL));
 24:     PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));
 25:   }
 27:   PetscCall(PetscOptionsGetString(NULL, NULL, "-yamlstr", filename, sizeof(filename), &flg));
 28:   if (flg) {
 29:     PetscBool monitor = PETSC_FALSE;
 31:     PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL));
 32:     if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, NULL, NULL));
 33:     PetscCall(PetscOptionsClear(NULL));
 34:     PetscCall(PetscOptionsInsertStringYAML(NULL, filename));
 35:   }
 37:   PetscCall(PetscOptionsView(NULL, PETSC_VIEWER_STDOUT_WORLD));
 38:   PetscCall(PetscOptionsClear(NULL));
 39:   PetscCall(PetscFinalize());
 40:   return 0;
 41: }
 43: /*TEST
 45:    testset:
 46:      args: -options_left false
 47:      filter:  grep -E -v "(options_monitor)"
 48:      localrunfiles: petsc.yml
 50:      test:
 51:         suffix: 1
 52:         args: -f petsc.yml
 54:      test:
 55:         suffix: 2_file
 56:         output_file: output/ex47_2.out
 57:         args: -options_file_yaml petsc.yml
 59:      test:
 60:         suffix: 2_string
 61:         args: -options_string_yaml "`cat petsc.yml`"
 63:      test:
 64:         suffix: 2_auto
 65:         args: -options_monitor
 66:         args: -options_file ex47-yaml_tag
 67:         args: -options_file ex47-yaml_doc
 68:         localrunfiles: ex47-yaml_tag ex47-yaml_doc
 70:      test:
 71:         suffix: 2_prefix
 72:         args: -options_monitor
 73:         args: -options_file ex47-opt.txt
 74:         args: -prefix_push p5_ -options_file ex47-opt.yml -prefix_pop
 75:         args: -prefix_push p5_ -options_file ex47-opt.yml:yaml -prefix_pop
 76:         args: -prefix_push p6_ -options_file_yaml ex47-opt.yml -prefix_pop
 77:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 78:         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 79:         args: -prefix_push p8_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
 80:         args: -prefix_push p9_ -options_file ex47-opt.json -prefix_pop
 81:         localrunfiles: ex47-opt.txt ex47-opt.yml ex47-opt.json
 83:    testset:
 84:      nsize: {{1 2}}
 86:      test:
 87:         suffix: 3_empty
 88:         args: -yaml ex47-empty.yaml
 89:         localrunfiles: ex47-empty.yaml
 91:      test:
 92:         suffix: 3_merge
 93:         args: -yaml ex47-merge.yaml -monitor
 94:         localrunfiles: ex47-merge.yaml
 96:      test:
 97:         suffix: 3_env
 98:         env: PETSC_OPTIONS_YAML='"name: value"'
 99:         args: -monitor
101:      test:
102:         suffix: 3_str
103:         args: -yamlstr "name: value" -monitor
105:      test:
106:         suffix: 3_options
107:         args: -yaml ex47-options.yaml
108:         localrunfiles: ex47-options.yaml
110:      test:
111:         suffix: 3_include
112:         args: -yaml ex47-include.yaml
113:         localrunfiles: ex47-include.yaml ex47-empty.yaml ex47-options.yaml
115:      test:
116:         suffix: 3_prefix
117:         args: -yaml ex47-prefix.yaml
118:         localrunfiles: ex47-prefix.yaml
120:      test:
121:         suffix: 3_multidoc
122:         args: -yaml ex47-multidoc.yaml
123:         localrunfiles: ex47-multidoc.yaml
125: TEST*/