1 static char help[] = "Demonstrates PetscOptionsPush()/PetscOptionsPop().\n\n";
2
3 #include <petscsys.h>
4 #include <petscoptions.h>
main(int argc,char ** argv)5 int main(int argc, char **argv)
6 {
7 PetscOptions opt1, opt2;
8 PetscInt int1, int2;
9 PetscBool flg1, flg2, flga, match;
10 char str[16];
11
12 PetscFunctionBeginUser;
13 PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14
15 PetscCall(PetscOptionsCreate(&opt1));
16 PetscCall(PetscOptionsInsertString(opt1, "-testa a"));
17 PetscCall(PetscOptionsPush(opt1));
18 PetscCall(PetscOptionsSetValue(NULL, "-test1", "1"));
19 PetscCall(PetscOptionsGetInt(NULL, NULL, "-test1", &int1, &flg1));
20 PetscCheck(flg1 && int1 == 1, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option test1 or it has the wrong value");
21 PetscCall(PetscOptionsGetString(NULL, NULL, "-testa", str, sizeof(str), &flga));
22 PetscCall(PetscStrcmp(str, "a", &match));
23 PetscCheck(flga && match, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option testa or it has the wrong value");
24 PetscCall(PetscOptionsCreate(&opt2));
25 PetscCall(PetscOptionsPush(opt2));
26 PetscCall(PetscOptionsSetValue(NULL, "-test2", "2"));
27 PetscCall(PetscOptionsGetInt(NULL, NULL, "-test2", &int2, &flg2));
28 PetscCheck(flg2 && int2 == 2, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option test2 or it has the wrong value");
29 PetscCall(PetscOptionsGetInt(NULL, NULL, "-test1", &int1, &flg1));
30 PetscCheck(!flg1, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Able to access test1 from a different options database");
31
32 PetscCall(PetscOptionsPop());
33 PetscCall(PetscOptionsPop());
34 PetscCall(PetscOptionsDestroy(&opt2));
35 PetscCall(PetscOptionsDestroy(&opt1));
36 PetscCall(PetscFinalize());
37 return 0;
38 }
39
40 /*TEST
41
42 test:
43 output_file: output/empty.out
44
45 TEST*/
46