Actual source code: ex20.c


  2: static char help[] = "Demonstrates PetscOptionsPush()/PetscOptionsPop().\n\n";

  4: #include <petscsys.h>
  5: #include <petscoptions.h>
  6: int main(int argc, char **argv)
  7: {
  8:   PetscOptions opt1, opt2;
  9:   PetscInt     int1, int2;
 10:   PetscBool    flg1, flg2, flga, match;
 11:   char         str[16];

 13:   PetscFunctionBeginUser;
 14:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

 16:   PetscCall(PetscOptionsCreate(&opt1));
 17:   PetscCall(PetscOptionsInsertString(opt1, "-testa a"));
 18:   PetscCall(PetscOptionsPush(opt1));
 19:   PetscCall(PetscOptionsSetValue(NULL, "-test1", "1"));
 20:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-test1", &int1, &flg1));
 21:   PetscCheck(flg1 && int1 == 1, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option test1 or it has the wrong value");
 22:   PetscCall(PetscOptionsGetString(NULL, NULL, "-testa", str, sizeof(str), &flga));
 23:   PetscCall(PetscStrcmp(str, "a", &match));
 24:   PetscCheck(flga && match, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option testa or it has the wrong value");
 25:   PetscCall(PetscOptionsCreate(&opt2));
 26:   PetscCall(PetscOptionsPush(opt2));
 27:   PetscCall(PetscOptionsSetValue(NULL, "-test2", "2"));
 28:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-test2", &int2, &flg2));
 29:   PetscCheck(flg2 && int2 == 2, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Unable to locate option test2 or it has the wrong value");
 30:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-test1", &int1, &flg1));
 31:   PetscCheck(!flg1, PETSC_COMM_WORLD, PETSC_ERR_PLIB, "Able to access test1 from a different options database");

 33:   PetscCall(PetscOptionsPop());
 34:   PetscCall(PetscOptionsPop());
 35:   PetscCall(PetscOptionsDestroy(&opt2));
 36:   PetscCall(PetscOptionsDestroy(&opt1));
 37:   PetscCall(PetscFinalize());
 38:   return 0;
 39: }

 41: /*TEST

 43:    test:

 45: TEST*/