Actual source code: ex20.c
1: static const char help[] = "Tests PetscOptionsPrefix{Push,Pop}\n\n";
3: #include <petscsys.h>
5: int main(int argc, char *argv[])
6: {
7: PetscInt opts[6] = {0};
8: PetscBool hascl = PETSC_FALSE, hasstr = PETSC_FALSE;
11: PetscInitialize(&argc, &argv, 0, help);
12: PetscOptionsSetValue(NULL, "-zero", "0");
13: PetscOptionsPrefixPush(NULL, "a_");
14: PetscOptionsSetValue(NULL, "-one", "1");
15: PetscOptionsPrefixPush(NULL, "bb_");
16: PetscOptionsSetValue(NULL, "-two", "2");
17: PetscOptionsPrefixPop(NULL);
18: PetscOptionsSetValue(NULL, "-three", "3");
19: PetscOptionsPrefixPush(NULL, "cc_");
20: PetscOptionsPrefixPush(NULL, "ddd_");
21: PetscOptionsSetValue(NULL, "-four", "4");
22: PetscOptionsPrefixPop(NULL);
23: PetscOptionsPrefixPop(NULL);
24: PetscOptionsPrefixPop(NULL);
25: PetscOptionsSetValue(NULL, "-five", "5");
27: PetscOptionsGetInt(NULL, 0, "-zero", &opts[0], 0);
28: PetscOptionsGetInt(NULL, 0, "-a_one", &opts[1], 0);
29: PetscOptionsGetInt(NULL, 0, "-a_bb_two", &opts[2], 0);
30: PetscOptionsGetInt(NULL, 0, "-a_three", &opts[3], 0);
31: PetscOptionsGetInt(NULL, 0, "-a_cc_ddd_four", &opts[4], 0);
32: PetscOptionsGetInt(NULL, 0, "-five", &opts[5], 0);
33: PetscPrintf(PETSC_COMM_WORLD, "opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]);
35: PetscOptionsGetBool(NULL, 0, "-cl", &hascl, 0);
36: if (hascl) {
37: PetscMemzero(opts, sizeof(opts));
38: PetscOptionsGetInt(NULL, 0, "-cl_zero", &opts[0], 0);
39: PetscOptionsGetInt(NULL, 0, "-cl_a_one", &opts[1], 0);
40: PetscOptionsGetInt(NULL, 0, "-cl_a_bb_two", &opts[2], 0);
41: PetscOptionsGetInt(NULL, 0, "-cl_a_three", &opts[3], 0);
42: PetscOptionsGetInt(NULL, 0, "-cl_a_cc_ddd_four", &opts[4], 0);
43: PetscOptionsGetInt(NULL, 0, "-cl_five", &opts[5], 0);
44: PetscPrintf(PETSC_COMM_WORLD, "cl_opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]);
45: }
47: PetscOptionsGetBool(NULL, 0, "-str", &hasstr, 0);
48: if (hasstr) {
49: PetscCall(
50: PetscOptionsInsertString(NULL, "-prefix_push str_ -zero 100 -prefix_push a_ -one 101 -prefix_push bb_ -two 102 -prefix_pop -three 103 -prefix_push cc_ -prefix_push ddd_ -four 104 -prefix_pop -prefix_pop -prefix_pop -five 105 -prefix_pop"));
51: PetscMemzero(opts, sizeof(opts));
52: PetscOptionsGetInt(NULL, 0, "-str_zero", &opts[0], 0);
53: PetscOptionsGetInt(NULL, 0, "-str_a_one", &opts[1], 0);
54: PetscOptionsGetInt(NULL, 0, "-str_a_bb_two", &opts[2], 0);
55: PetscOptionsGetInt(NULL, 0, "-str_a_three", &opts[3], 0);
56: PetscOptionsGetInt(NULL, 0, "-str_a_cc_ddd_four", &opts[4], 0);
57: PetscOptionsGetInt(NULL, 0, "-str_five", &opts[5], 0);
58: PetscPrintf(PETSC_COMM_WORLD, "str_opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]);
59: }
61: PetscFinalize();
62: return 0;
63: }
65: /*TEST
67: test:
68: output_file: output/ex20_1.out
70: test:
71: suffix: 2
72: args: -cl -prefix_push cl_ -zero 10 -prefix_push a_ -one 11 -prefix_push bb_ -two 12 -prefix_pop -three 13 -prefix_push cc_ -prefix_push ddd_ -four 14 -prefix_pop -prefix_pop -prefix_pop -five 15 -prefix_pop
74: test:
75: suffix: 3
76: args: -str
78: TEST*/