Actual source code: ex20.c

petsc-3.7.3 2016-08-01
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(NULL,"-zero","0");
 15:   PetscOptionsPrefixPush(NULL,"a_");
 16:   PetscOptionsSetValue(NULL,"-one","1");
 17:   PetscOptionsPrefixPush(NULL,"bb_");
 18:   PetscOptionsSetValue(NULL,"-two","2");
 19:   PetscOptionsPrefixPop(NULL);
 20:   PetscOptionsSetValue(NULL,"-three","3");
 21:   PetscOptionsPrefixPush(NULL,"cc_");
 22:   PetscOptionsPrefixPush(NULL,"ddd_");
 23:   PetscOptionsSetValue(NULL,"-four","4");
 24:   PetscOptionsPrefixPop(NULL);
 25:   PetscOptionsPrefixPop(NULL);
 26:   PetscOptionsPrefixPop(NULL);
 27:   PetscOptionsSetValue(NULL,"-five","5");

 29:   PetscOptionsGetInt(NULL,0,"-zero",&opts[0],0);
 30:   PetscOptionsGetInt(NULL,0,"-a_one",&opts[1],0);
 31:   PetscOptionsGetInt(NULL,0,"-a_bb_two",&opts[2],0);
 32:   PetscOptionsGetInt(NULL,0,"-a_three",&opts[3],0);
 33:   PetscOptionsGetInt(NULL,0,"-a_cc_ddd_four",&opts[4],0);
 34:   PetscOptionsGetInt(NULL,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(NULL,0,"-cl",&hascl,0);
 38:   if (hascl) {
 39:     PetscMemzero(opts,sizeof(opts));
 40:     PetscOptionsGetInt(NULL,0,"-cl_zero",&opts[0],0);
 41:     PetscOptionsGetInt(NULL,0,"-cl_a_one",&opts[1],0);
 42:     PetscOptionsGetInt(NULL,0,"-cl_a_bb_two",&opts[2],0);
 43:     PetscOptionsGetInt(NULL,0,"-cl_a_three",&opts[3],0);
 44:     PetscOptionsGetInt(NULL,0,"-cl_a_cc_ddd_four",&opts[4],0);
 45:     PetscOptionsGetInt(NULL,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(NULL,0,"-str",&hasstr,0);
 50:   if (hasstr) {
 51:     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");
 52:     PetscMemzero(opts,sizeof(opts));
 53:     PetscOptionsGetInt(NULL,0,"-str_zero",&opts[0],0);
 54:     PetscOptionsGetInt(NULL,0,"-str_a_one",&opts[1],0);
 55:     PetscOptionsGetInt(NULL,0,"-str_a_bb_two",&opts[2],0);
 56:     PetscOptionsGetInt(NULL,0,"-str_a_three",&opts[3],0);
 57:     PetscOptionsGetInt(NULL,0,"-str_a_cc_ddd_four",&opts[4],0);
 58:     PetscOptionsGetInt(NULL,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: }