xref: /petsc/src/sys/tests/ex20.c (revision f97672e55eacc8688507b9471cd7ec2664d7f203)
1 static const char help[] = "Tests PetscOptionsPrefix{Push,Pop}\n\n";
2 
3 #include <petscsys.h>
4 
5 int main(int argc, char *argv[])
6 {
7   PetscInt       opts[6] = {0};
8   PetscBool      hascl   = PETSC_FALSE,hasstr = PETSC_FALSE;
9 
10   PetscCall(PetscInitialize(&argc,&argv,0,help));
11   PetscCall(PetscOptionsSetValue(NULL,"-zero","0"));
12   PetscCall(PetscOptionsPrefixPush(NULL,"a_"));
13   PetscCall(PetscOptionsSetValue(NULL,"-one","1"));
14   PetscCall(PetscOptionsPrefixPush(NULL,"bb_"));
15   PetscCall(PetscOptionsSetValue(NULL,"-two","2"));
16   PetscCall(PetscOptionsPrefixPop(NULL));
17   PetscCall(PetscOptionsSetValue(NULL,"-three","3"));
18   PetscCall(PetscOptionsPrefixPush(NULL,"cc_"));
19   PetscCall(PetscOptionsPrefixPush(NULL,"ddd_"));
20   PetscCall(PetscOptionsSetValue(NULL,"-four","4"));
21   PetscCall(PetscOptionsPrefixPop(NULL));
22   PetscCall(PetscOptionsPrefixPop(NULL));
23   PetscCall(PetscOptionsPrefixPop(NULL));
24   PetscCall(PetscOptionsSetValue(NULL,"-five","5"));
25 
26   PetscCall(PetscOptionsGetInt(NULL,0,"-zero",&opts[0],0));
27   PetscCall(PetscOptionsGetInt(NULL,0,"-a_one",&opts[1],0));
28   PetscCall(PetscOptionsGetInt(NULL,0,"-a_bb_two",&opts[2],0));
29   PetscCall(PetscOptionsGetInt(NULL,0,"-a_three",&opts[3],0));
30   PetscCall(PetscOptionsGetInt(NULL,0,"-a_cc_ddd_four",&opts[4],0));
31   PetscCall(PetscOptionsGetInt(NULL,0,"-five",&opts[5],0));
32   PetscCall(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]));
33 
34   PetscCall(PetscOptionsGetBool(NULL,0,"-cl",&hascl,0));
35   if (hascl) {
36     PetscCall(PetscMemzero(opts,sizeof(opts)));
37     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_zero",&opts[0],0));
38     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_a_one",&opts[1],0));
39     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_a_bb_two",&opts[2],0));
40     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_a_three",&opts[3],0));
41     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_a_cc_ddd_four",&opts[4],0));
42     PetscCall(PetscOptionsGetInt(NULL,0,"-cl_five",&opts[5],0));
43     PetscCall(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]));
44   }
45 
46   PetscCall(PetscOptionsGetBool(NULL,0,"-str",&hasstr,0));
47   if (hasstr) {
48     PetscCall(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"));
49     PetscCall(PetscMemzero(opts,sizeof(opts)));
50     PetscCall(PetscOptionsGetInt(NULL,0,"-str_zero",&opts[0],0));
51     PetscCall(PetscOptionsGetInt(NULL,0,"-str_a_one",&opts[1],0));
52     PetscCall(PetscOptionsGetInt(NULL,0,"-str_a_bb_two",&opts[2],0));
53     PetscCall(PetscOptionsGetInt(NULL,0,"-str_a_three",&opts[3],0));
54     PetscCall(PetscOptionsGetInt(NULL,0,"-str_a_cc_ddd_four",&opts[4],0));
55     PetscCall(PetscOptionsGetInt(NULL,0,"-str_five",&opts[5],0));
56     PetscCall(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]));
57   }
58 
59   PetscCall(PetscFinalize());
60   return 0;
61 }
62 
63 /*TEST
64 
65    test:
66       output_file: output/ex20_1.out
67 
68    test:
69       suffix: 2
70       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
71 
72    test:
73       suffix: 3
74       args: -str
75 
76 TEST*/
77