Actual source code: ex20.c

petsc-3.6.1 2015-08-06
Report Typos and Errors
  1: static const char help[] = "Tests PetscOptionsPrefix{Push,Pop}\n\n";

  3: #include <petscsys.h>

  7: int main(int argc, char *argv[])
  8: {
 10:   PetscInt       opts[6] = {0};
 11:   PetscBool      hascl   = PETSC_FALSE,hasstr = PETSC_FALSE;

 13:   PetscInitialize(&argc,&argv,0,help);
 14:   PetscOptionsSetValue("-zero","0");
 15:   PetscOptionsPrefixPush("a_");
 16:   PetscOptionsSetValue("-one","1");
 17:   PetscOptionsPrefixPush("bb_");
 18:   PetscOptionsSetValue("-two","2");
 19:   PetscOptionsPrefixPop();
 20:   PetscOptionsSetValue("-three","3");
 21:   PetscOptionsPrefixPush("cc_");
 22:   PetscOptionsPrefixPush("ddd_");
 23:   PetscOptionsSetValue("-four","4");
 24:   PetscOptionsPrefixPop();
 25:   PetscOptionsPrefixPop();
 26:   PetscOptionsPrefixPop();
 27:   PetscOptionsSetValue("-five","5");

 29:   PetscOptionsGetInt(0,"-zero",&opts[0],0);
 30:   PetscOptionsGetInt(0,"-a_one",&opts[1],0);
 31:   PetscOptionsGetInt(0,"-a_bb_two",&opts[2],0);
 32:   PetscOptionsGetInt(0,"-a_three",&opts[3],0);
 33:   PetscOptionsGetInt(0,"-a_cc_ddd_four",&opts[4],0);
 34:   PetscOptionsGetInt(0,"-five",&opts[5],0);
 35:   PetscPrintf(PETSC_COMM_WORLD,"opts = {%D %D %D %D %D %D}\n",opts[0],opts[1],opts[2],opts[3],opts[4],opts[5]);

 37:   PetscOptionsGetBool(0,"-cl",&hascl,0);
 38:   if (hascl) {
 39:     PetscMemzero(opts,sizeof(opts));
 40:     PetscOptionsGetInt(0,"-cl_zero",&opts[0],0);
 41:     PetscOptionsGetInt(0,"-cl_a_one",&opts[1],0);
 42:     PetscOptionsGetInt(0,"-cl_a_bb_two",&opts[2],0);
 43:     PetscOptionsGetInt(0,"-cl_a_three",&opts[3],0);
 44:     PetscOptionsGetInt(0,"-cl_a_cc_ddd_four",&opts[4],0);
 45:     PetscOptionsGetInt(0,"-cl_five",&opts[5],0);
 46:     PetscPrintf(PETSC_COMM_WORLD,"cl_opts = {%D %D %D %D %D %D}\n",opts[0],opts[1],opts[2],opts[3],opts[4],opts[5]);
 47:   }

 49:   PetscOptionsGetBool(0,"-str",&hasstr,0);
 50:   if (hasstr) {
 51:     PetscOptionsInsertString("-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");
 52:     PetscMemzero(opts,sizeof(opts));
 53:     PetscOptionsGetInt(0,"-str_zero",&opts[0],0);
 54:     PetscOptionsGetInt(0,"-str_a_one",&opts[1],0);
 55:     PetscOptionsGetInt(0,"-str_a_bb_two",&opts[2],0);
 56:     PetscOptionsGetInt(0,"-str_a_three",&opts[3],0);
 57:     PetscOptionsGetInt(0,"-str_a_cc_ddd_four",&opts[4],0);
 58:     PetscOptionsGetInt(0,"-str_five",&opts[5],0);
 59:     PetscPrintf(PETSC_COMM_WORLD,"str_opts = {%D %D %D %D %D %D}\n",opts[0],opts[1],opts[2],opts[3],opts[4],opts[5]);
 60:   }

 62:   PetscFinalize();
 63:   return 0;
 64: }