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