xref: /petsc/src/sys/tests/ex20.c (revision 0d821f603638cf319655b464fce8824689c6444b)
1*5669f5d8SStefano Zampini static const char help[] = "Tests PetscOptionsPrefix{Push,Pop} and PetscOptionsDeprecated\n\n";
2c4762a1bSJed Brown 
3c4762a1bSJed Brown #include <petscsys.h>
4c4762a1bSJed Brown 
main(int argc,char * argv[])5d71ae5a4SJacob Faibussowitsch int main(int argc, char *argv[])
6d71ae5a4SJacob Faibussowitsch {
7c4762a1bSJed Brown   PetscInt  opts[6] = {0};
8c4762a1bSJed Brown   PetscBool hascl = PETSC_FALSE, hasstr = PETSC_FALSE;
9*5669f5d8SStefano Zampini   char      deprecated_prefix[PETSC_MAX_OPTION_NAME] = {0};
10*5669f5d8SStefano Zampini   PetscBool oldopt = PETSC_FALSE, newopt = PETSC_FALSE, useprefix;
11c4762a1bSJed Brown 
12327415f7SBarry Smith   PetscFunctionBeginUser;
139566063dSJacob Faibussowitsch   PetscCall(PetscInitialize(&argc, &argv, 0, help));
149566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-zero", "0"));
159566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPush(NULL, "a_"));
169566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-one", "1"));
179566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPush(NULL, "bb_"));
189566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-two", "2"));
199566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPop(NULL));
209566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-three", "3"));
219566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPush(NULL, "cc_"));
229566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPush(NULL, "ddd_"));
239566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-four", "4"));
249566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPop(NULL));
259566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPop(NULL));
269566063dSJacob Faibussowitsch   PetscCall(PetscOptionsPrefixPop(NULL));
279566063dSJacob Faibussowitsch   PetscCall(PetscOptionsSetValue(NULL, "-five", "5"));
28c4762a1bSJed Brown 
299566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-zero", &opts[0], 0));
309566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-a_one", &opts[1], 0));
319566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-a_bb_two", &opts[2], 0));
329566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-a_three", &opts[3], 0));
339566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-a_cc_ddd_four", &opts[4], 0));
349566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetInt(NULL, 0, "-five", &opts[5], 0));
359566063dSJacob Faibussowitsch   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]));
36c4762a1bSJed Brown 
379566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(NULL, 0, "-cl", &hascl, 0));
38c4762a1bSJed Brown   if (hascl) {
399566063dSJacob Faibussowitsch     PetscCall(PetscMemzero(opts, sizeof(opts)));
409566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_zero", &opts[0], 0));
419566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_one", &opts[1], 0));
429566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_bb_two", &opts[2], 0));
439566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_three", &opts[3], 0));
449566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_cc_ddd_four", &opts[4], 0));
459566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_five", &opts[5], 0));
469566063dSJacob Faibussowitsch     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]));
47c4762a1bSJed Brown   }
48c4762a1bSJed Brown 
499566063dSJacob Faibussowitsch   PetscCall(PetscOptionsGetBool(NULL, 0, "-str", &hasstr, 0));
50c4762a1bSJed Brown   if (hasstr) {
519371c9d4SSatish Balay     PetscCall(
529371c9d4SSatish Balay       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"));
539566063dSJacob Faibussowitsch     PetscCall(PetscMemzero(opts, sizeof(opts)));
549566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_zero", &opts[0], 0));
559566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_one", &opts[1], 0));
569566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_bb_two", &opts[2], 0));
579566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_three", &opts[3], 0));
589566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_cc_ddd_four", &opts[4], 0));
599566063dSJacob Faibussowitsch     PetscCall(PetscOptionsGetInt(NULL, 0, "-str_five", &opts[5], 0));
609566063dSJacob Faibussowitsch     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]));
61c4762a1bSJed Brown   }
62c4762a1bSJed Brown 
63*5669f5d8SStefano Zampini   PetscCall(PetscOptionsGetString(NULL, 0, "-deprecated_prefix", deprecated_prefix, sizeof(deprecated_prefix), &useprefix));
64*5669f5d8SStefano Zampini   PetscOptionsBegin(PETSC_COMM_WORLD, useprefix ? deprecated_prefix : NULL, "test deprecated options", NULL);
65*5669f5d8SStefano Zampini   PetscCall(PetscOptionsBool("-old_option", NULL, NULL, oldopt, &oldopt, NULL));
66*5669f5d8SStefano Zampini   PetscCall(PetscOptionsDeprecated("-old_option", "-new_option", "0.0", NULL));
67*5669f5d8SStefano Zampini   PetscCall(PetscOptionsBool("-new_option", NULL, NULL, newopt, &newopt, NULL));
68*5669f5d8SStefano Zampini   PetscOptionsEnd();
69*5669f5d8SStefano Zampini   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "opts = {old %d new %d}\n", oldopt, newopt));
70*5669f5d8SStefano Zampini 
719566063dSJacob Faibussowitsch   PetscCall(PetscFinalize());
72b122ec5aSJacob Faibussowitsch   return 0;
73c4762a1bSJed Brown }
74c4762a1bSJed Brown 
75c4762a1bSJed Brown /*TEST
76c4762a1bSJed Brown 
77c4762a1bSJed Brown    test:
78*5669f5d8SStefano Zampini       suffix: 1
79*5669f5d8SStefano Zampini       args: -old_option 1 -new_option 0
80c4762a1bSJed Brown 
81c4762a1bSJed Brown    test:
82c4762a1bSJed Brown       suffix: 2
83c4762a1bSJed Brown       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
84c4762a1bSJed Brown 
85c4762a1bSJed Brown    test:
86c4762a1bSJed Brown       suffix: 3
87*5669f5d8SStefano Zampini       args: -str -deprecated_prefix zz_ -zz_old_option 0 -zz_new_option 1
88*5669f5d8SStefano Zampini 
89*5669f5d8SStefano Zampini    test:
90*5669f5d8SStefano Zampini       suffix: 4
91*5669f5d8SStefano Zampini       args: -deprecated_prefix yy_ -yy_old_option 1
92c4762a1bSJed Brown 
93c4762a1bSJed Brown TEST*/
94