xref: /petsc/src/sys/tests/ex47.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
1 static char help[] = "Example for PetscOptionsInsertFileYAML\n";
2 
3 #include <petscsys.h>
4 #include <petscviewer.h>
5 
6 int main(int argc, char **argv) {
7   char      filename[PETSC_MAX_PATH_LEN];
8   PetscBool flg;
9 
10   PetscFunctionBeginUser;
11   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
12 
13   PetscCall(PetscOptionsGetString(NULL, NULL, "-f", filename, sizeof(filename), &flg));
14   if (flg) PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));
15 
16   PetscCall(PetscOptionsGetString(NULL, NULL, "-yaml", filename, sizeof(filename), &flg));
17   if (flg) {
18     PetscBool monitor = PETSC_FALSE;
19 
20     PetscCall(PetscOptionsGetBool(NULL, NULL, "-monitor", &monitor, NULL));
21     if (monitor) PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorDefault, NULL, NULL));
22     PetscCall(PetscOptionsClear(NULL));
23     PetscCall(PetscOptionsInsertFileYAML(PETSC_COMM_WORLD, NULL, filename, PETSC_TRUE));
24   }
25 
26   PetscCall(PetscOptionsView(NULL, PETSC_VIEWER_STDOUT_WORLD));
27   PetscCall(PetscOptionsClear(NULL));
28   PetscCall(PetscFinalize());
29   return 0;
30 }
31 
32 /*TEST
33 
34    testset:
35      args: -options_left false
36      filter:  egrep -v "(options_left|options_monitor)"
37      localrunfiles: petsc.yml
38 
39      test:
40         suffix: 1
41         args: -f petsc.yml
42 
43      test:
44         suffix: 2_file
45         output_file: output/ex47_2.out
46         args: -options_file_yaml petsc.yml
47 
48      test:
49         suffix: 2_string
50         output_file: output/ex47_2.out
51         args: -options_string_yaml "`cat petsc.yml`"
52 
53      test:
54         suffix: 2_auto
55         args: -options_monitor
56         args: -options_file ex47-yaml_tag
57         args: -options_file ex47-yaml_doc
58         localrunfiles: ex47-yaml_tag ex47-yaml_doc
59 
60      test:
61         suffix: 2_prefix
62         args: -options_monitor
63         args: -options_file ex47-opt.txt
64         args: -prefix_push p5_ -options_file ex47-opt.yml -prefix_pop
65         args: -prefix_push p5_ -options_file ex47-opt.yml:yaml -prefix_pop
66         args: -prefix_push p6_ -options_file_yaml ex47-opt.yml -prefix_pop
67         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
68         args: -prefix_push p7_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
69         args: -prefix_push p8_ -options_string_yaml "`cat ex47-opt.yml`" -prefix_pop
70         args: -prefix_push p9_ -options_file ex47-opt.json -prefix_pop
71         localrunfiles: ex47-opt.txt ex47-opt.yml ex47-opt.json
72 
73    testset:
74      nsize: {{1 2}}
75 
76      test:
77         suffix: 3_empty
78         args: -yaml ex47-empty.yaml
79         localrunfiles: ex47-empty.yaml
80 
81      test:
82         suffix: 3_merge
83         args: -yaml ex47-merge.yaml -monitor
84         localrunfiles: ex47-merge.yaml
85 
86      test:
87         suffix: 3_options
88         args: -yaml ex47-options.yaml
89         localrunfiles: ex47-options.yaml
90 
91      test:
92         suffix: 3_include
93         args: -yaml ex47-include.yaml
94         localrunfiles: ex47-include.yaml ex47-empty.yaml ex47-options.yaml
95 
96      test:
97         suffix: 3_prefix
98         args: -yaml ex47-prefix.yaml
99         localrunfiles: ex47-prefix.yaml
100 
101      test:
102         suffix: 3_multidoc
103         args: -yaml ex47-multidoc.yaml
104         localrunfiles: ex47-multidoc.yaml
105 
106 TEST*/
107