xref: /petsc/src/sys/objects/aoptions.c (revision 3a89f35bd826bccc16d67340a1af7dd022eb28af)
17d0a6c19SBarry Smith 
21a1499c8SBarry Smith 
353acd3b1SBarry Smith /*
43fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
53fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
653acd3b1SBarry Smith 
753acd3b1SBarry Smith */
853acd3b1SBarry Smith 
9af0996ceSBarry Smith #include <petsc/private/petscimpl.h>        /*I  "petscsys.h"   I*/
10665c2dedSJed Brown #include <petscviewer.h>
1153acd3b1SBarry Smith 
122aa6d131SJed Brown #define ManSection(str) ((str) ? (str) : "None")
132aa6d131SJed Brown 
1453acd3b1SBarry Smith /*
1553acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
163fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1753acd3b1SBarry Smith 
1853acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1953acd3b1SBarry Smith */
20e55864a3SBarry Smith 
2153acd3b1SBarry Smith 
2253acd3b1SBarry Smith /*
2353acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2453acd3b1SBarry Smith */
254416b707SBarry Smith PetscErrorCode PetscOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2653acd3b1SBarry Smith {
2753acd3b1SBarry Smith   PetscErrorCode ierr;
2853acd3b1SBarry Smith 
2953acd3b1SBarry Smith   PetscFunctionBegin;
3076280437SVaclav Hapla   if (prefix) PetscValidCharPointer(prefix,2);
3176280437SVaclav Hapla   PetscValidCharPointer(title,3);
3276280437SVaclav Hapla   if (mansec) PetscValidCharPointer(mansec,4);
330eb63584SBarry Smith   if (!PetscOptionsObject->alreadyprinted) {
349de0f6ecSBarry Smith     if (!PetscOptionsHelpPrintedSingleton) {
359de0f6ecSBarry Smith       ierr = PetscOptionsHelpPrintedCreate(&PetscOptionsHelpPrintedSingleton);CHKERRQ(ierr);
369de0f6ecSBarry Smith     }
379de0f6ecSBarry Smith     ierr = PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrintedSingleton,prefix,title,&PetscOptionsObject->alreadyprinted);CHKERRQ(ierr);
380eb63584SBarry Smith   }
3902c9f0b5SLisandro Dalcin   PetscOptionsObject->next          = NULL;
40e55864a3SBarry Smith   PetscOptionsObject->comm          = comm;
41e55864a3SBarry Smith   PetscOptionsObject->changedmethod = PETSC_FALSE;
42a297a907SKarl Rupp 
43e55864a3SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject->prefix);CHKERRQ(ierr);
44e55864a3SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject->title);CHKERRQ(ierr);
4553acd3b1SBarry Smith 
462d747510SLisandro Dalcin   ierr = PetscOptionsHasHelp(PetscOptionsObject->options,&PetscOptionsObject->printhelp);CHKERRQ(ierr);
47e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1) {
48e55864a3SBarry Smith     if (!PetscOptionsObject->alreadyprinted) {
49c0bb3764SVaclav Hapla       ierr = (*PetscHelpPrintf)(comm,"----------------------------------------\n%s:\n",title);CHKERRQ(ierr);
5053acd3b1SBarry Smith     }
5161b37b28SSatish Balay   }
5253acd3b1SBarry Smith   PetscFunctionReturn(0);
5353acd3b1SBarry Smith }
5453acd3b1SBarry Smith 
553194b578SJed Brown /*
563194b578SJed Brown     Handles setting up the data structure in a call to PetscObjectOptionsBegin()
573194b578SJed Brown */
584416b707SBarry Smith PetscErrorCode PetscObjectOptionsBegin_Private(PetscOptionItems *PetscOptionsObject,PetscObject obj)
593194b578SJed Brown {
603194b578SJed Brown   PetscErrorCode ierr;
613194b578SJed Brown   char           title[256];
623194b578SJed Brown   PetscBool      flg;
633194b578SJed Brown 
643194b578SJed Brown   PetscFunctionBegin;
653194b578SJed Brown   PetscValidHeader(obj,1);
66e55864a3SBarry Smith   PetscOptionsObject->object         = obj;
67e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = obj->optionsprinted;
68a297a907SKarl Rupp 
693194b578SJed Brown   ierr = PetscStrcmp(obj->description,obj->class_name,&flg);CHKERRQ(ierr);
703194b578SJed Brown   if (flg) {
718caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s options",obj->class_name);CHKERRQ(ierr);
723194b578SJed Brown   } else {
738caf3d72SBarry Smith     ierr = PetscSNPrintf(title,sizeof(title),"%s (%s) options",obj->description,obj->class_name);CHKERRQ(ierr);
743194b578SJed Brown   }
75e55864a3SBarry Smith   ierr = PetscOptionsBegin_Private(PetscOptionsObject,obj->comm,obj->prefix,title,obj->mansec);CHKERRQ(ierr);
763194b578SJed Brown   PetscFunctionReturn(0);
773194b578SJed Brown }
783194b578SJed Brown 
7953acd3b1SBarry Smith /*
8053acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
8153acd3b1SBarry Smith */
824416b707SBarry Smith static int PetscOptionItemCreate_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptionItem *amsopt)
8353acd3b1SBarry Smith {
8453acd3b1SBarry Smith   int             ierr;
854416b707SBarry Smith   PetscOptionItem next;
863be6e4c3SJed Brown   PetscBool       valid;
8753acd3b1SBarry Smith 
8853acd3b1SBarry Smith   PetscFunctionBegin;
893be6e4c3SJed Brown   ierr = PetscOptionsValidKey(opt,&valid);CHKERRQ(ierr);
903be6e4c3SJed Brown   if (!valid) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_INCOMP,"The option '%s' is not a valid key",opt);
913be6e4c3SJed Brown 
92b00a9115SJed Brown   ierr            = PetscNew(amsopt);CHKERRQ(ierr);
9302c9f0b5SLisandro Dalcin   (*amsopt)->next = NULL;
9453acd3b1SBarry Smith   (*amsopt)->set  = PETSC_FALSE;
956356e834SBarry Smith   (*amsopt)->type = t;
9602c9f0b5SLisandro Dalcin   (*amsopt)->data = NULL;
9761b37b28SSatish Balay 
9853acd3b1SBarry Smith   ierr = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
9953acd3b1SBarry Smith   ierr = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
1006356e834SBarry Smith   ierr = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
10153acd3b1SBarry Smith 
102e55864a3SBarry Smith   if (!PetscOptionsObject->next) PetscOptionsObject->next = *amsopt;
103a297a907SKarl Rupp   else {
104e55864a3SBarry Smith     next = PetscOptionsObject->next;
10553acd3b1SBarry Smith     while (next->next) next = next->next;
10653acd3b1SBarry Smith     next->next = *amsopt;
10753acd3b1SBarry Smith   }
10853acd3b1SBarry Smith   PetscFunctionReturn(0);
10953acd3b1SBarry Smith }
11053acd3b1SBarry Smith 
111aee2cecaSBarry Smith /*
1123fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
1133fc1eb6aSBarry Smith 
114d083f849SBarry Smith     Collective
1153fc1eb6aSBarry Smith 
1163fc1eb6aSBarry Smith    Input Parameters:
1173fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
1183fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
1193fc1eb6aSBarry Smith -     str - location to store input
120aee2cecaSBarry Smith 
121aee2cecaSBarry Smith     Bugs:
122aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
123aee2cecaSBarry Smith 
124aee2cecaSBarry Smith */
1253fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
126aee2cecaSBarry Smith {
127330cf3c9SBarry Smith   size_t         i;
128aee2cecaSBarry Smith   char           c;
1293fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
130aee2cecaSBarry Smith   PetscErrorCode ierr;
131aee2cecaSBarry Smith 
132aee2cecaSBarry Smith   PetscFunctionBegin;
133aee2cecaSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
134aee2cecaSBarry Smith   if (!rank) {
135aee2cecaSBarry Smith     c = (char) getchar();
136aee2cecaSBarry Smith     i = 0;
137aee2cecaSBarry Smith     while (c != '\n' && i < n-1) {
138aee2cecaSBarry Smith       str[i++] = c;
139aee2cecaSBarry Smith       c = (char)getchar();
140aee2cecaSBarry Smith     }
141aee2cecaSBarry Smith     str[i] = 0;
142aee2cecaSBarry Smith   }
1434dc2109aSBarry Smith   ierr = PetscMPIIntCast(n,&nm);CHKERRQ(ierr);
1443fc1eb6aSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
145aee2cecaSBarry Smith   PetscFunctionReturn(0);
146aee2cecaSBarry Smith }
147aee2cecaSBarry Smith 
1485b02f95dSBarry Smith /*
1495b02f95dSBarry Smith     This is needed because certain strings may be freed by SAWs, hence we cannot use PetscStrallocpy()
1505b02f95dSBarry Smith */
1515b02f95dSBarry Smith static PetscErrorCode  PetscStrdup(const char s[],char *t[])
1525b02f95dSBarry Smith {
1535b02f95dSBarry Smith   PetscErrorCode ierr;
1545b02f95dSBarry Smith   size_t         len;
15502c9f0b5SLisandro Dalcin   char           *tmp = NULL;
1565b02f95dSBarry Smith 
1575b02f95dSBarry Smith   PetscFunctionBegin;
1585b02f95dSBarry Smith   if (s) {
1595b02f95dSBarry Smith     ierr = PetscStrlen(s,&len);CHKERRQ(ierr);
160f416af30SBarry Smith     tmp = (char*) malloc((len+1)*sizeof(char));
1615b02f95dSBarry Smith     if (!tmp) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_MEM,"No memory to duplicate string");
1625b02f95dSBarry Smith     ierr = PetscStrcpy(tmp,s);CHKERRQ(ierr);
1635b02f95dSBarry Smith   }
1645b02f95dSBarry Smith   *t = tmp;
1655b02f95dSBarry Smith   PetscFunctionReturn(0);
1665b02f95dSBarry Smith }
1675b02f95dSBarry Smith 
1685b02f95dSBarry Smith 
169aee2cecaSBarry Smith /*
1703cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
171aee2cecaSBarry Smith 
17295452b02SPatrick Sanan     Notes:
17395452b02SPatrick Sanan     this isn't really practical, it is just to demonstrate the principle
174aee2cecaSBarry Smith 
1757781c08eSBarry Smith     A carriage return indicates no change from the default; but this like -ksp_monitor <stdout>  the default is actually not stdout the default
1767781c08eSBarry Smith     is to do nothing so to get it to use stdout you need to type stdout. This is kind of bug?
1777781c08eSBarry Smith 
178aee2cecaSBarry Smith     Bugs:
1797781c08eSBarry Smith +    All processes must traverse through the exact same set of option queries due to the call to PetscScanString()
1803cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
181aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
182aee2cecaSBarry Smith 
18395452b02SPatrick Sanan     Developer Notes:
18495452b02SPatrick Sanan     Normally the GUI that presents the options the user and retrieves the values would be running in a different
1853cc1e11dSBarry Smith      address space and communicating with the PETSc program
1863cc1e11dSBarry Smith 
187aee2cecaSBarry Smith */
1884416b707SBarry Smith PetscErrorCode PetscOptionsGetFromTextInput(PetscOptionItems *PetscOptionsObject)
1896356e834SBarry Smith {
1906356e834SBarry Smith   PetscErrorCode  ierr;
1914416b707SBarry Smith   PetscOptionItem next = PetscOptionsObject->next;
1926356e834SBarry Smith   char            str[512];
1937781c08eSBarry Smith   PetscBool       bid;
194a4404d99SBarry Smith   PetscReal       ir,*valr;
195330cf3c9SBarry Smith   PetscInt        *vald;
196330cf3c9SBarry Smith   size_t          i;
1976356e834SBarry Smith 
1982a409bb0SBarry Smith   PetscFunctionBegin;
199c0bb3764SVaclav Hapla   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s --------------------\n",PetscOptionsObject->title);CHKERRQ(ierr);
2006356e834SBarry Smith   while (next) {
2016356e834SBarry Smith     switch (next->type) {
2026356e834SBarry Smith     case OPTION_HEAD:
2036356e834SBarry Smith       break;
204e26ddf31SBarry Smith     case OPTION_INT_ARRAY:
205e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
206e26ddf31SBarry Smith       vald = (PetscInt*) next->data;
207e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
208e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
209e26ddf31SBarry Smith         if (i < next->arraylength-1) {
210e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
211e26ddf31SBarry Smith         }
212e26ddf31SBarry Smith       }
213e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
214e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
215e26ddf31SBarry Smith       if (str[0]) {
216e26ddf31SBarry Smith         PetscToken token;
217e26ddf31SBarry Smith         PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
218e26ddf31SBarry Smith         size_t     len;
219e26ddf31SBarry Smith         char       *value;
220ace3abfcSBarry Smith         PetscBool  foundrange;
221e26ddf31SBarry Smith 
222e26ddf31SBarry Smith         next->set = PETSC_TRUE;
223e26ddf31SBarry Smith         value     = str;
224e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
225e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
226e26ddf31SBarry Smith         while (n < nmax) {
227e26ddf31SBarry Smith           if (!value) break;
228e26ddf31SBarry Smith 
229e26ddf31SBarry Smith           /* look for form  d-D where d and D are integers */
230e26ddf31SBarry Smith           foundrange = PETSC_FALSE;
231e26ddf31SBarry Smith           ierr       = PetscStrlen(value,&len);CHKERRQ(ierr);
232e26ddf31SBarry Smith           if (value[0] == '-') i=2;
233e26ddf31SBarry Smith           else i=1;
234330cf3c9SBarry Smith           for (;i<len; i++) {
235e26ddf31SBarry Smith             if (value[i] == '-') {
236e32f2f54SBarry Smith               if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
237e26ddf31SBarry Smith               value[i] = 0;
238cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value,&start);CHKERRQ(ierr);
239cfbddea1SSatish Balay               ierr     = PetscOptionsStringToInt(value+i+1,&end);CHKERRQ(ierr);
240e32f2f54SBarry Smith               if (end <= start) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, %s-%s cannot have decreasing list",n,value,value+i+1);
241e32f2f54SBarry Smith               if (n + end - start - 1 >= nmax) SETERRQ4(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry, not enough space in left in array (%D) to contain entire range from %D to %D",n,nmax-n,start,end);
242e26ddf31SBarry Smith               for (; start<end; start++) {
243e26ddf31SBarry Smith                 *dvalue = start; dvalue++;n++;
244e26ddf31SBarry Smith               }
245e26ddf31SBarry Smith               foundrange = PETSC_TRUE;
246e26ddf31SBarry Smith               break;
247e26ddf31SBarry Smith             }
248e26ddf31SBarry Smith           }
249e26ddf31SBarry Smith           if (!foundrange) {
250cfbddea1SSatish Balay             ierr = PetscOptionsStringToInt(value,dvalue);CHKERRQ(ierr);
251e26ddf31SBarry Smith             dvalue++;
252e26ddf31SBarry Smith             n++;
253e26ddf31SBarry Smith           }
254e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
255e26ddf31SBarry Smith         }
2568c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
257e26ddf31SBarry Smith       }
258e26ddf31SBarry Smith       break;
259e26ddf31SBarry Smith     case OPTION_REAL_ARRAY:
260e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1);CHKERRQ(ierr);
261e26ddf31SBarry Smith       valr = (PetscReal*) next->data;
262e26ddf31SBarry Smith       for (i=0; i<next->arraylength; i++) {
263e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
264e26ddf31SBarry Smith         if (i < next->arraylength-1) {
265e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
266e26ddf31SBarry Smith         }
267e26ddf31SBarry Smith       }
268e26ddf31SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s) ",next->text,next->man);CHKERRQ(ierr);
269e26ddf31SBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
270e26ddf31SBarry Smith       if (str[0]) {
271e26ddf31SBarry Smith         PetscToken token;
272e26ddf31SBarry Smith         PetscInt   n = 0,nmax = next->arraylength;
273e26ddf31SBarry Smith         PetscReal  *dvalue = (PetscReal*)next->data;
274e26ddf31SBarry Smith         char       *value;
275e26ddf31SBarry Smith 
276e26ddf31SBarry Smith         next->set = PETSC_TRUE;
277e26ddf31SBarry Smith         value     = str;
278e26ddf31SBarry Smith         ierr      = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
279e26ddf31SBarry Smith         ierr      = PetscTokenFind(token,&value);CHKERRQ(ierr);
280e26ddf31SBarry Smith         while (n < nmax) {
281e26ddf31SBarry Smith           if (!value) break;
282cfbddea1SSatish Balay           ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
283e26ddf31SBarry Smith           dvalue++;
284e26ddf31SBarry Smith           n++;
285e26ddf31SBarry Smith           ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
286e26ddf31SBarry Smith         }
2878c74ee41SBarry Smith         ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
288e26ddf31SBarry Smith       }
289e26ddf31SBarry Smith       break;
2906356e834SBarry Smith     case OPTION_INT:
291e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%d>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,*(int*)next->data,next->text,next->man);CHKERRQ(ierr);
2923fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2933fc1eb6aSBarry Smith       if (str[0]) {
294d25d7f95SJed Brown #if defined(PETSC_SIZEOF_LONG_LONG)
295d25d7f95SJed Brown         long long lid;
296d25d7f95SJed Brown         sscanf(str,"%lld",&lid);
2971a1499c8SBarry Smith         if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %lld",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,lid);
298c272547aSJed Brown #else
299d25d7f95SJed Brown         long  lid;
300d25d7f95SJed Brown         sscanf(str,"%ld",&lid);
3011a1499c8SBarry Smith         if (lid > PETSC_MAX_INT || lid < PETSC_MIN_INT) SETERRQ3(PETSC_COMM_WORLD,PETSC_ERR_ARG_OUTOFRANGE,"Argument: -%s%s %ld",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,lid);
302c272547aSJed Brown #endif
303a297a907SKarl Rupp 
304d25d7f95SJed Brown         next->set = PETSC_TRUE;
305d25d7f95SJed Brown         *((PetscInt*)next->data) = (PetscInt)lid;
306aee2cecaSBarry Smith       }
307aee2cecaSBarry Smith       break;
308aee2cecaSBarry Smith     case OPTION_REAL:
309e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%g>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,*(double*)next->data,next->text,next->man);CHKERRQ(ierr);
3103fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3113fc1eb6aSBarry Smith       if (str[0]) {
312ce63c4c1SBarry Smith #if defined(PETSC_USE_REAL_SINGLE)
313a4404d99SBarry Smith         sscanf(str,"%e",&ir);
314570b7f6dSBarry Smith #elif defined(PETSC_USE_REAL___FP16)
315570b7f6dSBarry Smith         float irtemp;
316570b7f6dSBarry Smith         sscanf(str,"%e",&irtemp);
317570b7f6dSBarry Smith         ir = irtemp;
318ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL_DOUBLE)
319aee2cecaSBarry Smith         sscanf(str,"%le",&ir);
320ce63c4c1SBarry Smith #elif defined(PETSC_USE_REAL___FLOAT128)
321d9822059SBarry Smith         ir = strtoflt128(str,0);
322d9822059SBarry Smith #else
323513dbe71SLisandro Dalcin         SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unknown scalar type");
324a4404d99SBarry Smith #endif
325aee2cecaSBarry Smith         next->set                 = PETSC_TRUE;
326aee2cecaSBarry Smith         *((PetscReal*)next->data) = ir;
327aee2cecaSBarry Smith       }
328aee2cecaSBarry Smith       break;
3297781c08eSBarry Smith     case OPTION_BOOL:
33083355fc5SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,*(PetscBool*)next->data ? "true": "false",next->text,next->man);CHKERRQ(ierr);
3317781c08eSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3327781c08eSBarry Smith       if (str[0]) {
3337781c08eSBarry Smith         ierr = PetscOptionsStringToBool(str,&bid);CHKERRQ(ierr);
3347781c08eSBarry Smith         next->set = PETSC_TRUE;
3357781c08eSBarry Smith         *((PetscBool*)next->data) = bid;
3367781c08eSBarry Smith       }
3377781c08eSBarry Smith       break;
338aee2cecaSBarry Smith     case OPTION_STRING:
339e55864a3SBarry Smith       ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <%s>: %s (%s) ",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",next->option+1,(char*)next->data,next->text,next->man);CHKERRQ(ierr);
3403fc1eb6aSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3413fc1eb6aSBarry Smith       if (str[0]) {
342aee2cecaSBarry Smith         next->set = PETSC_TRUE;
34364facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3445b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3456356e834SBarry Smith       }
3466356e834SBarry Smith       break;
347a264d7a6SBarry Smith     case OPTION_FLIST:
34844ef3d73SBarry Smith       ierr = PetscFunctionListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject->prefix,next->option,next->text,next->man,next->flist,(char*)next->data,(char*)next->data);CHKERRQ(ierr);
3493cc1e11dSBarry Smith       ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
3503cc1e11dSBarry Smith       if (str[0]) {
351e55864a3SBarry Smith         PetscOptionsObject->changedmethod = PETSC_TRUE;
3523cc1e11dSBarry Smith         next->set = PETSC_TRUE;
35364facd6cSBarry Smith         /* must use system malloc since SAWs may free this */
3545b02f95dSBarry Smith         ierr = PetscStrdup(str,(char**)&next->data);CHKERRQ(ierr);
3553cc1e11dSBarry Smith       }
3563cc1e11dSBarry Smith       break;
357b432afdaSMatthew Knepley     default:
358b432afdaSMatthew Knepley       break;
3596356e834SBarry Smith     }
3606356e834SBarry Smith     next = next->next;
3616356e834SBarry Smith   }
3626356e834SBarry Smith   PetscFunctionReturn(0);
3636356e834SBarry Smith }
3646356e834SBarry Smith 
365e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
366e04113cfSBarry Smith #include <petscviewersaws.h>
367d5649816SBarry Smith 
368d5649816SBarry Smith static int count = 0;
369d5649816SBarry Smith 
370e04113cfSBarry Smith PetscErrorCode PetscOptionsSAWsDestroy(void)
371d5649816SBarry Smith {
3722657e9d9SBarry Smith   PetscFunctionBegin;
373d5649816SBarry Smith   PetscFunctionReturn(0);
374d5649816SBarry Smith }
375d5649816SBarry Smith 
3769c1e0ce8SBarry Smith static const char *OptionsHeader = "<head>\n"
377a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/jquery-1.9.1.js\"></script>\n"
378a8d69d7bSBarry Smith                                    "<script type=\"text/javascript\" src=\"https://www.mcs.anl.gov/research/projects/saws/js/SAWs.js\"></script>\n"
379d1fc0251SBarry Smith                                    "<script type=\"text/javascript\" src=\"js/PETSc.js\"></script>\n"
38064bbc9efSBarry Smith                                    "<script>\n"
38164bbc9efSBarry Smith                                       "jQuery(document).ready(function() {\n"
38264bbc9efSBarry Smith                                          "PETSc.getAndDisplayDirectory(null,\"#variablesInfo\")\n"
38364bbc9efSBarry Smith                                       "})\n"
38464bbc9efSBarry Smith                                   "</script>\n"
38564bbc9efSBarry Smith                                   "</head>\n";
3861423471aSBarry Smith 
3871423471aSBarry Smith /*  Determines the size and style of the scroll region where PETSc options selectable from users are displayed */
3881423471aSBarry Smith static const char *OptionsBodyBottom = "<div id=\"variablesInfo\" style=\"background-color:lightblue;height:auto;max-height:500px;overflow:scroll;\"></div>\n<br>\n</body>";
38964bbc9efSBarry Smith 
390b3506946SBarry Smith /*
3917781c08eSBarry Smith     PetscOptionsSAWsInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the SAWs
392b3506946SBarry Smith 
393b3506946SBarry Smith     Bugs:
394b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
395b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
396b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
397b3506946SBarry Smith 
398b3506946SBarry Smith 
399b3506946SBarry Smith */
4004416b707SBarry Smith PetscErrorCode PetscOptionsSAWsInput(PetscOptionItems *PetscOptionsObject)
401b3506946SBarry Smith {
402b3506946SBarry Smith   PetscErrorCode  ierr;
4034416b707SBarry Smith   PetscOptionItem next     = PetscOptionsObject->next;
404d5649816SBarry Smith   static int      mancount = 0;
405b3506946SBarry Smith   char            options[16];
4067aab2a10SBarry Smith   PetscBool       changedmethod = PETSC_FALSE;
407a23eb982SSurtai Han   PetscBool       stopasking    = PETSC_FALSE;
40888a9752cSBarry Smith   char            manname[16],textname[16];
4092657e9d9SBarry Smith   char            dir[1024];
410b3506946SBarry Smith 
4112a409bb0SBarry Smith   PetscFunctionBegin;
412b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
413b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
414a297a907SKarl Rupp 
4157325c4a4SBarry Smith   PetscOptionsObject->pprefix = PetscOptionsObject->prefix; /* SAWs will change this, so cannot pass prefix directly */
4161bc75a8dSBarry Smith 
417d50831c4SBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","_title");CHKERRQ(ierr);
41883355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->title,1,SAWs_READ,SAWs_STRING));
4197781c08eSBarry Smith   ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s","prefix");CHKERRQ(ierr);
42083355fc5SBarry Smith   PetscStackCallSAWs(SAWs_Register,(dir,&PetscOptionsObject->pprefix,1,SAWs_READ,SAWs_STRING));
4212657e9d9SBarry Smith   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/ChangedMethod",&changedmethod,1,SAWs_WRITE,SAWs_BOOLEAN));
422a23eb982SSurtai Han   PetscStackCallSAWs(SAWs_Register,("/PETSc/Options/StopAsking",&stopasking,1,SAWs_WRITE,SAWs_BOOLEAN));
423b3506946SBarry Smith 
424b3506946SBarry Smith   while (next) {
425d50831c4SBarry Smith     sprintf(manname,"_man_%d",mancount);
4262657e9d9SBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",manname);CHKERRQ(ierr);
4277781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->man,1,SAWs_READ,SAWs_STRING));
428d50831c4SBarry Smith     sprintf(textname,"_text_%d",mancount++);
4297781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",textname);CHKERRQ(ierr);
4307781c08eSBarry Smith     PetscStackCallSAWs(SAWs_Register,(dir,&next->text,1,SAWs_READ,SAWs_STRING));
4319f32e415SBarry Smith 
432b3506946SBarry Smith     switch (next->type) {
433b3506946SBarry Smith     case OPTION_HEAD:
434b3506946SBarry Smith       break;
435b3506946SBarry Smith     case OPTION_INT_ARRAY:
4367781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4372657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_INT));
438b3506946SBarry Smith       break;
439b3506946SBarry Smith     case OPTION_REAL_ARRAY:
4407781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4412657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_DOUBLE));
442b3506946SBarry Smith       break;
443b3506946SBarry Smith     case OPTION_INT:
4447781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4452657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_INT));
446b3506946SBarry Smith       break;
447b3506946SBarry Smith     case OPTION_REAL:
4487781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4492657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_DOUBLE));
450b3506946SBarry Smith       break;
4517781c08eSBarry Smith     case OPTION_BOOL:
4527781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4532657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,1,SAWs_WRITE,SAWs_BOOLEAN));
4541ae3d29cSBarry Smith       break;
4557781c08eSBarry Smith     case OPTION_BOOL_ARRAY:
4567781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4572657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_BOOLEAN));
45871f08665SBarry Smith       break;
459b3506946SBarry Smith     case OPTION_STRING:
4607781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4617781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
4621ae3d29cSBarry Smith       break;
4631ae3d29cSBarry Smith     case OPTION_STRING_ARRAY:
4647781c08eSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4652657e9d9SBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,next->data,next->arraylength,SAWs_WRITE,SAWs_STRING));
466b3506946SBarry Smith       break;
467a264d7a6SBarry Smith     case OPTION_FLIST:
468a264d7a6SBarry Smith       {
469a264d7a6SBarry Smith       PetscInt ntext;
4707781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4717781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
472a264d7a6SBarry Smith       ierr = PetscFunctionListGet(next->flist,(const char***)&next->edata,&ntext);CHKERRQ(ierr);
473a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
474a264d7a6SBarry Smith       }
475a264d7a6SBarry Smith       break;
4761ae3d29cSBarry Smith     case OPTION_ELIST:
477a264d7a6SBarry Smith       {
478a264d7a6SBarry Smith       PetscInt ntext = next->nlist;
4797781c08eSBarry Smith       ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
4807781c08eSBarry Smith       PetscStackCallSAWs(SAWs_Register,(dir,&next->data,1,SAWs_WRITE,SAWs_STRING));
481ead66b60SBarry Smith       ierr = PetscMalloc1((ntext+1),(char***)&next->edata);CHKERRQ(ierr);
4821ae3d29cSBarry Smith       ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
483a264d7a6SBarry Smith       PetscStackCallSAWs(SAWs_Set_Legal_Variable_Values,(dir,ntext,next->edata));
484a264d7a6SBarry Smith       }
485a264d7a6SBarry Smith       break;
486b3506946SBarry Smith     default:
487b3506946SBarry Smith       break;
488b3506946SBarry Smith     }
489b3506946SBarry Smith     next = next->next;
490b3506946SBarry Smith   }
491b3506946SBarry Smith 
492b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
49364bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Header,("index.html",OptionsHeader));
49464bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Push_Body,("index.html",2,OptionsBodyBottom));
4957aab2a10SBarry Smith   ierr = PetscSAWsBlock();CHKERRQ(ierr);
49664bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Header,("index.html"));
49764bbc9efSBarry Smith   PetscStackCallSAWs(SAWs_Pop_Body,("index.html",2));
498b3506946SBarry Smith 
49988a9752cSBarry Smith   /* determine if any values have been set in GUI */
50083355fc5SBarry Smith   next = PetscOptionsObject->next;
50188a9752cSBarry Smith   while (next) {
50288a9752cSBarry Smith     ierr = PetscSNPrintf(dir,1024,"/PETSc/Options/%s",next->option);CHKERRQ(ierr);
503f7b25cf6SBarry Smith     PetscStackCallSAWs(SAWs_Selected,(dir,(int*)&next->set));
50488a9752cSBarry Smith     next = next->next;
50588a9752cSBarry Smith   }
50688a9752cSBarry Smith 
507b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
508f7b25cf6SBarry Smith   if (changedmethod) PetscOptionsObject->count = -2;
509b3506946SBarry Smith 
510a23eb982SSurtai Han   if (stopasking) {
511a23eb982SSurtai Han     PetscOptionsPublish      = PETSC_FALSE;
51212655325SBarry Smith     PetscOptionsObject->count = 0;//do not ask for same thing again
513a23eb982SSurtai Han   }
514a23eb982SSurtai Han 
5159a492a5cSBarry Smith   PetscStackCallSAWs(SAWs_Delete,("/PETSc/Options"));
516b3506946SBarry Smith   PetscFunctionReturn(0);
517b3506946SBarry Smith }
518b3506946SBarry Smith #endif
519b3506946SBarry Smith 
5204416b707SBarry Smith PetscErrorCode PetscOptionsEnd_Private(PetscOptionItems *PetscOptionsObject)
52153acd3b1SBarry Smith {
52253acd3b1SBarry Smith   PetscErrorCode  ierr;
5234416b707SBarry Smith   PetscOptionItem last;
5246356e834SBarry Smith   char            option[256],value[1024],tmp[32];
525330cf3c9SBarry Smith   size_t          j;
52653acd3b1SBarry Smith 
52753acd3b1SBarry Smith   PetscFunctionBegin;
52883355fc5SBarry Smith   if (PetscOptionsObject->next) {
52983355fc5SBarry Smith     if (!PetscOptionsObject->count) {
530a264d7a6SBarry Smith #if defined(PETSC_HAVE_SAWS)
531f7b25cf6SBarry Smith       ierr = PetscOptionsSAWsInput(PetscOptionsObject);CHKERRQ(ierr);
532b3506946SBarry Smith #else
533e55864a3SBarry Smith       ierr = PetscOptionsGetFromTextInput(PetscOptionsObject);CHKERRQ(ierr);
534b3506946SBarry Smith #endif
535aee2cecaSBarry Smith     }
536aee2cecaSBarry Smith   }
5376356e834SBarry Smith 
538e55864a3SBarry Smith   ierr = PetscFree(PetscOptionsObject->title);CHKERRQ(ierr);
5396356e834SBarry Smith 
540e26ddf31SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
541e55864a3SBarry Smith   if (PetscOptionsObject->changedmethod) PetscOptionsObject->count = -2;
5427a72a596SBarry Smith   /* reset alreadyprinted flag */
543e55864a3SBarry Smith   PetscOptionsObject->alreadyprinted = PETSC_FALSE;
544e55864a3SBarry Smith   if (PetscOptionsObject->object) PetscOptionsObject->object->optionsprinted = PETSC_TRUE;
545e55864a3SBarry Smith   PetscOptionsObject->object = NULL;
54653acd3b1SBarry Smith 
547e55864a3SBarry Smith   while (PetscOptionsObject->next) {
548e55864a3SBarry Smith     if (PetscOptionsObject->next->set) {
549e55864a3SBarry Smith       if (PetscOptionsObject->prefix) {
55053acd3b1SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
551e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->prefix);CHKERRQ(ierr);
552e55864a3SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject->next->option+1);CHKERRQ(ierr);
5536356e834SBarry Smith       } else {
554e55864a3SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject->next->option);CHKERRQ(ierr);
5556356e834SBarry Smith       }
5566356e834SBarry Smith 
557e55864a3SBarry Smith       switch (PetscOptionsObject->next->type) {
5586356e834SBarry Smith       case OPTION_HEAD:
5596356e834SBarry Smith         break;
5606356e834SBarry Smith       case OPTION_INT_ARRAY:
561e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[0]);
562e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
563e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject->next->data)[j]);
5646356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5656356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5666356e834SBarry Smith         }
5676356e834SBarry Smith         break;
5686356e834SBarry Smith       case OPTION_INT:
569e55864a3SBarry Smith         sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject->next->data);
5706356e834SBarry Smith         break;
5716356e834SBarry Smith       case OPTION_REAL:
572e55864a3SBarry Smith         sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject->next->data);
5736356e834SBarry Smith         break;
5746356e834SBarry Smith       case OPTION_REAL_ARRAY:
575e55864a3SBarry Smith         sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[0]);
576e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
577e55864a3SBarry Smith           sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject->next->data)[j]);
5786356e834SBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5796356e834SBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5806356e834SBarry Smith         }
5816356e834SBarry Smith         break;
582050cccc3SHong Zhang       case OPTION_SCALAR_ARRAY:
58395f3a755SJose E. Roman         sprintf(value,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[0]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[0]));
584050cccc3SHong Zhang         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
58595f3a755SJose E. Roman           sprintf(tmp,"%g+%gi",(double)PetscRealPart(((PetscScalar*)PetscOptionsObject->next->data)[j]),(double)PetscImaginaryPart(((PetscScalar*)PetscOptionsObject->next->data)[j]));
586050cccc3SHong Zhang           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
587050cccc3SHong Zhang           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
588050cccc3SHong Zhang         }
589050cccc3SHong Zhang         break;
5907781c08eSBarry Smith       case OPTION_BOOL:
591e55864a3SBarry Smith         sprintf(value,"%d",*(int*)PetscOptionsObject->next->data);
5926356e834SBarry Smith         break;
5937781c08eSBarry Smith       case OPTION_BOOL_ARRAY:
594e55864a3SBarry Smith         sprintf(value,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[0]);
595e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
596e55864a3SBarry Smith           sprintf(tmp,"%d",(int)((PetscBool*)PetscOptionsObject->next->data)[j]);
5971ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
5981ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
5991ae3d29cSBarry Smith         }
6001ae3d29cSBarry Smith         break;
601a264d7a6SBarry Smith       case OPTION_FLIST:
6026991f827SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
6036991f827SBarry Smith         break;
6041ae3d29cSBarry Smith       case OPTION_ELIST:
605e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
6066356e834SBarry Smith         break;
6071ae3d29cSBarry Smith       case OPTION_STRING:
608e55864a3SBarry Smith         ierr = PetscStrcpy(value,(char*)PetscOptionsObject->next->data);CHKERRQ(ierr);
609d51da6bfSBarry Smith         break;
6101ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
611e55864a3SBarry Smith         sprintf(value,"%s",((char**)PetscOptionsObject->next->data)[0]);
612e55864a3SBarry Smith         for (j=1; j<PetscOptionsObject->next->arraylength; j++) {
613e55864a3SBarry Smith           sprintf(tmp,"%s",((char**)PetscOptionsObject->next->data)[j]);
6141ae3d29cSBarry Smith           ierr = PetscStrcat(value,",");CHKERRQ(ierr);
6151ae3d29cSBarry Smith           ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
6161ae3d29cSBarry Smith         }
6176356e834SBarry Smith         break;
6186356e834SBarry Smith       }
619c5929fdfSBarry Smith       ierr = PetscOptionsSetValue(PetscOptionsObject->options,option,value);CHKERRQ(ierr);
6206356e834SBarry Smith     }
6216991f827SBarry Smith     if (PetscOptionsObject->next->type == OPTION_ELIST) {
6226991f827SBarry Smith       ierr = PetscStrNArrayDestroy(PetscOptionsObject->next->nlist,(char ***)&PetscOptionsObject->next->list);CHKERRQ(ierr);
6236991f827SBarry Smith     }
624e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->text);CHKERRQ(ierr);
625e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->option);CHKERRQ(ierr);
626e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->man);CHKERRQ(ierr);
627e55864a3SBarry Smith     ierr   = PetscFree(PetscOptionsObject->next->edata);CHKERRQ(ierr);
628c979a496SBarry Smith 
62983355fc5SBarry Smith     if ((PetscOptionsObject->next->type == OPTION_STRING) || (PetscOptionsObject->next->type == OPTION_FLIST) || (PetscOptionsObject->next->type == OPTION_ELIST)){
63083355fc5SBarry Smith       free(PetscOptionsObject->next->data);
631c979a496SBarry Smith     } else {
63283355fc5SBarry Smith       ierr   = PetscFree(PetscOptionsObject->next->data);CHKERRQ(ierr);
633c979a496SBarry Smith     }
6347781c08eSBarry Smith 
63583355fc5SBarry Smith     last                    = PetscOptionsObject->next;
63683355fc5SBarry Smith     PetscOptionsObject->next = PetscOptionsObject->next->next;
6376356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
6386356e834SBarry Smith   }
639f59f755dSBarry Smith   ierr = PetscFree(PetscOptionsObject->prefix);CHKERRQ(ierr);
64002c9f0b5SLisandro Dalcin   PetscOptionsObject->next = NULL;
64153acd3b1SBarry Smith   PetscFunctionReturn(0);
64253acd3b1SBarry Smith }
64353acd3b1SBarry Smith 
64488aa4217SBarry Smith /*MC
64553acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
64653acd3b1SBarry Smith 
6473f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
64853acd3b1SBarry Smith 
64988aa4217SBarry Smith    Synopsis:
65088aa4217SBarry Smith    #include "petscsys.h"
651*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
65288aa4217SBarry Smith 
65353acd3b1SBarry Smith    Input Parameters:
65453acd3b1SBarry Smith +  opt - option name
65553acd3b1SBarry Smith .  text - short string that describes the option
65653acd3b1SBarry Smith .  man - manual page with additional information on option
65753acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
6580fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
6590fdccdaeSBarry Smith $                 PetscOptionsEnum(..., obj->value,&object->value,...) or
6600fdccdaeSBarry Smith $                 value = defaultvalue
6610fdccdaeSBarry Smith $                 PetscOptionsEnum(..., value,&value,&flg);
6620fdccdaeSBarry Smith $                 if (flg) {
66353acd3b1SBarry Smith 
66453acd3b1SBarry Smith    Output Parameter:
66553acd3b1SBarry Smith +  value - the  value to return
666b32e0204SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
66753acd3b1SBarry Smith 
66853acd3b1SBarry Smith    Level: beginner
66953acd3b1SBarry Smith 
67095452b02SPatrick Sanan    Notes:
67195452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
67253acd3b1SBarry Smith 
67353acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
67453acd3b1SBarry Smith 
6752efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
6762efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
6772efd9cb1SBarry Smith 
678989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
679989712b9SBarry Smith 
68053acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
681acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
682acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
68353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
68453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
685acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
686a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
68788aa4217SBarry Smith M*/
68888aa4217SBarry Smith 
6894416b707SBarry Smith PetscErrorCode  PetscOptionsEnum_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum currentvalue,PetscEnum *value,PetscBool  *set)
69053acd3b1SBarry Smith {
69153acd3b1SBarry Smith   PetscErrorCode ierr;
69253acd3b1SBarry Smith   PetscInt       ntext = 0;
693aa5bb8c0SSatish Balay   PetscInt       tval;
694ace3abfcSBarry Smith   PetscBool      tflg;
69553acd3b1SBarry Smith 
69653acd3b1SBarry Smith   PetscFunctionBegin;
69753acd3b1SBarry Smith   while (list[ntext++]) {
698e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
69953acd3b1SBarry Smith   }
700e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
70153acd3b1SBarry Smith   ntext -= 3;
702e55864a3SBarry Smith   ierr   = PetscOptionsEList_Private(PetscOptionsObject,opt,text,man,list,ntext,list[currentvalue],&tval,&tflg);CHKERRQ(ierr);
703aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
704aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
705aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
70653acd3b1SBarry Smith   PetscFunctionReturn(0);
70753acd3b1SBarry Smith }
70853acd3b1SBarry Smith 
70988aa4217SBarry Smith /*MC
710d3e47460SLisandro Dalcin    PetscOptionsEnumArray - Gets an array of enum values for a particular
711d3e47460SLisandro Dalcin    option in the database.
712d3e47460SLisandro Dalcin 
713d3e47460SLisandro Dalcin    Logically Collective on the communicator passed in PetscOptionsBegin()
714d3e47460SLisandro Dalcin 
71588aa4217SBarry Smith    Synopsis:
71688aa4217SBarry Smith    #include "petscsys.h"
717*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEnumArray(const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
71888aa4217SBarry Smith 
719d3e47460SLisandro Dalcin    Input Parameters:
720d3e47460SLisandro Dalcin +  opt - the option one is seeking
721d3e47460SLisandro Dalcin .  text - short string describing option
722d3e47460SLisandro Dalcin .  man - manual page for option
72322d58ec6SMatthew G. Knepley .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
724d3e47460SLisandro Dalcin -  n - maximum number of values
725d3e47460SLisandro Dalcin 
726d3e47460SLisandro Dalcin    Output Parameter:
727d3e47460SLisandro Dalcin +  value - location to copy values
728d3e47460SLisandro Dalcin .  n - actual number of values found
729d3e47460SLisandro Dalcin -  set - PETSC_TRUE if found, else PETSC_FALSE
730d3e47460SLisandro Dalcin 
731d3e47460SLisandro Dalcin    Level: beginner
732d3e47460SLisandro Dalcin 
733d3e47460SLisandro Dalcin    Notes:
734d3e47460SLisandro Dalcin    The array must be passed as a comma separated list.
735d3e47460SLisandro Dalcin 
736d3e47460SLisandro Dalcin    There must be no intervening spaces between the values.
737d3e47460SLisandro Dalcin 
738d3e47460SLisandro Dalcin    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
739d3e47460SLisandro Dalcin 
740d3e47460SLisandro Dalcin .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
741d3e47460SLisandro Dalcin           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
742d3e47460SLisandro Dalcin           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
743d3e47460SLisandro Dalcin           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
744d3e47460SLisandro Dalcin           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
745d3e47460SLisandro Dalcin           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
74688aa4217SBarry Smith M*/
74788aa4217SBarry Smith 
7484416b707SBarry Smith PetscErrorCode  PetscOptionsEnumArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char *const *list,PetscEnum value[],PetscInt *n,PetscBool  *set)
749d3e47460SLisandro Dalcin {
750d3e47460SLisandro Dalcin   PetscInt        i,nlist = 0;
7514416b707SBarry Smith   PetscOptionItem amsopt;
752d3e47460SLisandro Dalcin   PetscErrorCode  ierr;
753d3e47460SLisandro Dalcin 
754d3e47460SLisandro Dalcin   PetscFunctionBegin;
755d3e47460SLisandro Dalcin   while (list[nlist++]) if (nlist > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
756d3e47460SLisandro Dalcin   if (nlist < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
757d3e47460SLisandro Dalcin   nlist -= 3; /* drop enum name, prefix, and null termination */
758d3e47460SLisandro Dalcin   if (0 && !PetscOptionsObject->count) { /* XXX Requires additional support */
759d3e47460SLisandro Dalcin     PetscEnum *vals;
7604416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY/*XXX OPTION_ENUM_ARRAY*/,&amsopt);CHKERRQ(ierr);
761d3e47460SLisandro Dalcin     ierr = PetscStrNArrayallocpy(nlist,list,(char***)&amsopt->list);CHKERRQ(ierr);
762d3e47460SLisandro Dalcin     amsopt->nlist = nlist;
763d3e47460SLisandro Dalcin     ierr = PetscMalloc1(*n,(PetscEnum**)&amsopt->data);CHKERRQ(ierr);
764d3e47460SLisandro Dalcin     amsopt->arraylength = *n;
765d3e47460SLisandro Dalcin     vals = (PetscEnum*)amsopt->data;
766d3e47460SLisandro Dalcin     for (i=0; i<*n; i++) vals[i] = value[i];
767d3e47460SLisandro Dalcin   }
768c5929fdfSBarry Smith   ierr = PetscOptionsGetEnumArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,value,n,set);CHKERRQ(ierr);
769d3e47460SLisandro Dalcin   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
770d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,list[value[0]]);CHKERRQ(ierr);
771d3e47460SLisandro Dalcin     for (i=1; i<*n; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%s",list[value[i]]);CHKERRQ(ierr);}
772d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (choose from)",text);CHKERRQ(ierr);
773d3e47460SLisandro Dalcin     for (i=0; i<nlist; i++) {ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);}
774d3e47460SLisandro Dalcin     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
775d3e47460SLisandro Dalcin   }
776d3e47460SLisandro Dalcin   PetscFunctionReturn(0);
777d3e47460SLisandro Dalcin }
778d3e47460SLisandro Dalcin 
77988aa4217SBarry Smith /*MC
7805a856986SBarry Smith    PetscOptionsBoundedInt - Gets an integer value greater than or equal a given bound for a particular option in the database.
7815a856986SBarry Smith 
7825a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
7835a856986SBarry Smith 
78488aa4217SBarry Smith    Synopsis:
78588aa4217SBarry Smith    #include "petscsys.h"
786*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsBoundInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt bound)
78788aa4217SBarry Smith 
7885a856986SBarry Smith    Input Parameters:
7895a856986SBarry Smith +  opt - option name
7905a856986SBarry Smith .  text - short string that describes the option
7915a856986SBarry Smith .  man - manual page with additional information on option
7925a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
79388aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
7945a856986SBarry Smith $                 value = defaultvalue
7955a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
7965a856986SBarry Smith $                 if (flg) {
79788aa4217SBarry Smith -  bound - the requested value should be greater than or equal this bound or an error is generated
7985a856986SBarry Smith 
7995a856986SBarry Smith    Output Parameter:
8005a856986SBarry Smith +  value - the integer value to return
8015a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
8025a856986SBarry Smith 
8035a856986SBarry Smith    Notes:
8045a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8055a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8065a856986SBarry Smith 
8075a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8085a856986SBarry Smith 
8095a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8105a856986SBarry Smith 
8115a856986SBarry Smith    Level: beginner
8125a856986SBarry Smith 
8135a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
8145a856986SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), PetscOptionsRangeInt()
8155a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8165a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8175a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8185a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8195a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
82088aa4217SBarry Smith M*/
8215a856986SBarry Smith 
82288aa4217SBarry Smith /*MC
8235a856986SBarry Smith    PetscOptionsRangeInt - Gets an integer value within a range of values for a particular option in the database.
8245a856986SBarry Smith 
8255a856986SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
8265a856986SBarry Smith 
82788aa4217SBarry Smith    Synopsis:
82888aa4217SBarry Smith    #include "petscsys.h"
829*3a89f35bSSatish Balay PetscErrorCode  PetscOptionsRangeInt(const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg,PetscInt lb,PetscInt ub)
83088aa4217SBarry Smith 
8315a856986SBarry Smith    Input Parameters:
8325a856986SBarry Smith +  opt - option name
8335a856986SBarry Smith .  text - short string that describes the option
8345a856986SBarry Smith .  man - manual page with additional information on option
8355a856986SBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
83688aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8375a856986SBarry Smith $                 value = defaultvalue
8385a856986SBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8395a856986SBarry Smith $                 if (flg) {
84088aa4217SBarry Smith .  lb - the lower bound, provided value must be greater than or equal to this value or an error is generated
84188aa4217SBarry Smith -  ub - the upper bound, provided value must be less than or equal to this value or an error is generated
8425a856986SBarry Smith 
8435a856986SBarry Smith    Output Parameter:
8445a856986SBarry Smith +  value - the integer value to return
8455a856986SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
8465a856986SBarry Smith 
8475a856986SBarry Smith    Notes:
8485a856986SBarry Smith     If the user does not supply the option at all value is NOT changed. Thus
8495a856986SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8505a856986SBarry Smith 
8515a856986SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
8525a856986SBarry Smith 
8535a856986SBarry Smith     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
8545a856986SBarry Smith 
8555a856986SBarry Smith    Level: beginner
8565a856986SBarry Smith 
8575a856986SBarry Smith .seealso: PetscOptionsInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
8585a856986SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), PetscOptionsBoundedInt()
8595a856986SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
8605a856986SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
8615a856986SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
8625a856986SBarry Smith           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
8635a856986SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
86488aa4217SBarry Smith M*/
8655a856986SBarry Smith 
86688aa4217SBarry Smith /*MC
86753acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
86853acd3b1SBarry Smith 
8693f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
87053acd3b1SBarry Smith 
87188aa4217SBarry Smith    Synopsis:
87288aa4217SBarry Smith    #include "petscsys.h"
873*3a89f35bSSatish Balay PetscErrorCode  PetscOptionsInt(const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool *flg))
87488aa4217SBarry Smith 
87588aa4217SBarry Smith 
87653acd3b1SBarry Smith    Input Parameters:
87753acd3b1SBarry Smith +  opt - option name
87853acd3b1SBarry Smith .  text - short string that describes the option
87953acd3b1SBarry Smith .  man - manual page with additional information on option
8800fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
88188aa4217SBarry Smith $                 PetscOptionsInt(..., obj->value,&obj->value,...) or
8820fdccdaeSBarry Smith $                 value = defaultvalue
8830fdccdaeSBarry Smith $                 PetscOptionsInt(..., value,&value,&flg);
8840fdccdaeSBarry Smith $                 if (flg) {
88553acd3b1SBarry Smith 
88653acd3b1SBarry Smith    Output Parameter:
88753acd3b1SBarry Smith +  value - the integer value to return
88853acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
88953acd3b1SBarry Smith 
89095452b02SPatrick Sanan    Notes:
89195452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
8922efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
8932efd9cb1SBarry Smith 
894989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
895989712b9SBarry Smith 
89695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
89753acd3b1SBarry Smith 
8985a856986SBarry Smith    Level: beginner
8995a856986SBarry Smith 
9005a856986SBarry Smith .seealso: PetscOptionsBoundedInt(), PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
9015a856986SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(), PetscOptionsRangeInt()
902acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
90353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
90453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
905acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
906a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
90788aa4217SBarry Smith M*/
90888aa4217SBarry Smith 
9095a856986SBarry Smith PetscErrorCode  PetscOptionsInt_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt currentvalue,PetscInt *value,PetscBool  *set,PetscInt lb,PetscInt ub)
91053acd3b1SBarry Smith {
91153acd3b1SBarry Smith   PetscErrorCode  ierr;
9124416b707SBarry Smith   PetscOptionItem amsopt;
91312655325SBarry Smith   PetscBool       wasset;
91453acd3b1SBarry Smith 
91553acd3b1SBarry Smith   PetscFunctionBegin;
9165a856986SBarry Smith   if (currentvalue < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D less than allowed bound %D",currentvalue,lb);
917c5910190SPierre Jolivet   if (currentvalue > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Current value %D greater than allowed bound %D",currentvalue,ub);
918e55864a3SBarry Smith      if (!PetscOptionsObject->count) {
9194416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
9206356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
92112655325SBarry Smith     *(PetscInt*)amsopt->data = currentvalue;
9223e211508SBarry Smith 
923c5929fdfSBarry Smith     ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,&currentvalue,&wasset);CHKERRQ(ierr);
9243e211508SBarry Smith     if (wasset) {
92512655325SBarry Smith       *(PetscInt*)amsopt->data = currentvalue;
9263e211508SBarry Smith     }
927af6d86caSBarry Smith   }
92844ef3d73SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&wasset);CHKERRQ(ierr);
9295a856986SBarry Smith   if (wasset && *value < lb) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D less than allowed bound %D",*value,lb);
9305a856986SBarry Smith   if (wasset && *value > ub) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Newly set value %D greater than allowed bound %D",*value,ub);
93144ef3d73SBarry Smith   if (set) *set = wasset;
932e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9330e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %D : formerly %D>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,wasset && value ? *value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr);
93453acd3b1SBarry Smith   }
93553acd3b1SBarry Smith   PetscFunctionReturn(0);
93653acd3b1SBarry Smith }
93753acd3b1SBarry Smith 
93888aa4217SBarry Smith /*MC
93953acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
94053acd3b1SBarry Smith 
9413f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
94253acd3b1SBarry Smith 
94388aa4217SBarry Smith    Synopsis:
94488aa4217SBarry Smith    #include "petscsys.h"
945*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsString(const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
94688aa4217SBarry Smith 
94753acd3b1SBarry Smith    Input Parameters:
94853acd3b1SBarry Smith +  opt - option name
94953acd3b1SBarry Smith .  text - short string that describes the option
95053acd3b1SBarry Smith .  man - manual page with additional information on option
9510fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. This is not used to set value
952bcbf2dc5SJed Brown -  len - length of the result string including null terminator
95353acd3b1SBarry Smith 
95453acd3b1SBarry Smith    Output Parameter:
95553acd3b1SBarry Smith +  value - the value to return
95653acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
95753acd3b1SBarry Smith 
95853acd3b1SBarry Smith    Level: beginner
95953acd3b1SBarry Smith 
96095452b02SPatrick Sanan    Notes:
96195452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
96253acd3b1SBarry Smith 
9637fccdfe4SBarry Smith    Even if the user provided no string (for example -optionname -someotheroption) the flag is set to PETSC_TRUE (and the string is fulled with nulls).
9647fccdfe4SBarry Smith 
9652efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
9662efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
9672efd9cb1SBarry Smith 
968989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
969989712b9SBarry Smith 
9702efd9cb1SBarry Smith 
97189a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
972acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
973acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsBool(),
97453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
97553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
976acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
977a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
97888aa4217SBarry Smith M*/
97988aa4217SBarry Smith 
9804416b707SBarry Smith PetscErrorCode  PetscOptionsString_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],const char currentvalue[],char value[],size_t len,PetscBool  *set)
98153acd3b1SBarry Smith {
98253acd3b1SBarry Smith   PetscErrorCode  ierr;
9834416b707SBarry Smith   PetscOptionItem amsopt;
98444ef3d73SBarry Smith   PetscBool       lset;
98553acd3b1SBarry Smith 
98653acd3b1SBarry Smith   PetscFunctionBegin;
9871a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
9884416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
98964facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
9900fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
991af6d86caSBarry Smith   }
99244ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
99344ef3d73SBarry Smith   if (set) *set = lset;
994e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
9950e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %s : formerly %s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? value : currentvalue,currentvalue,text,ManSection(man));CHKERRQ(ierr);
99653acd3b1SBarry Smith   }
99753acd3b1SBarry Smith   PetscFunctionReturn(0);
99853acd3b1SBarry Smith }
99953acd3b1SBarry Smith 
100088aa4217SBarry Smith /*MC
100153acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
100253acd3b1SBarry Smith 
10033f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
100453acd3b1SBarry Smith 
100588aa4217SBarry Smith    Synopsis:
100688aa4217SBarry Smith    #include "petscsys.h"
1007*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
100888aa4217SBarry Smith 
100953acd3b1SBarry Smith    Input Parameters:
101053acd3b1SBarry Smith +  opt - option name
101153acd3b1SBarry Smith .  text - short string that describes the option
101253acd3b1SBarry Smith .  man - manual page with additional information on option
10130fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
101488aa4217SBarry Smith $                 PetscOptionsReal(..., obj->value,&obj->value,...) or
10150fdccdaeSBarry Smith $                 value = defaultvalue
10160fdccdaeSBarry Smith $                 PetscOptionsReal(..., value,&value,&flg);
10170fdccdaeSBarry Smith $                 if (flg) {
101853acd3b1SBarry Smith 
101953acd3b1SBarry Smith    Output Parameter:
102053acd3b1SBarry Smith +  value - the value to return
102153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
102253acd3b1SBarry Smith 
102395452b02SPatrick Sanan    Notes:
102495452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10252efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10262efd9cb1SBarry Smith 
1027989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1028989712b9SBarry Smith 
102995452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
103053acd3b1SBarry Smith 
10315a856986SBarry Smith    Level: beginner
10325a856986SBarry Smith 
103389a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1034acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1035acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
103653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
103753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1038acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1039a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
104088aa4217SBarry Smith M*/
104188aa4217SBarry Smith 
10424416b707SBarry Smith PetscErrorCode  PetscOptionsReal_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal currentvalue,PetscReal *value,PetscBool  *set)
104353acd3b1SBarry Smith {
104453acd3b1SBarry Smith   PetscErrorCode  ierr;
10454416b707SBarry Smith   PetscOptionItem amsopt;
104644ef3d73SBarry Smith   PetscBool       lset;
104753acd3b1SBarry Smith 
104853acd3b1SBarry Smith   PetscFunctionBegin;
1049e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
10504416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
1051538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1052a297a907SKarl Rupp 
10530fdccdaeSBarry Smith     *(PetscReal*)amsopt->data = currentvalue;
1054538aa990SBarry Smith   }
105544ef3d73SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,&lset);CHKERRQ(ierr);
105644ef3d73SBarry Smith   if (set) *set = lset;
10571a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
10580e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g : %g>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,lset && value ? (double)*value : (double) currentvalue,(double)currentvalue,text,ManSection(man));CHKERRQ(ierr);
105953acd3b1SBarry Smith   }
106053acd3b1SBarry Smith   PetscFunctionReturn(0);
106153acd3b1SBarry Smith }
106253acd3b1SBarry Smith 
106388aa4217SBarry Smith /*MC
106453acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
106553acd3b1SBarry Smith 
10663f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
106753acd3b1SBarry Smith 
106888aa4217SBarry Smith    Synopsis:
106988aa4217SBarry Smith    #include "petscsys.h"
1070*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
107188aa4217SBarry Smith 
107253acd3b1SBarry Smith    Input Parameters:
107353acd3b1SBarry Smith +  opt - option name
107453acd3b1SBarry Smith .  text - short string that describes the option
107553acd3b1SBarry Smith .  man - manual page with additional information on option
10760fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with either
107788aa4217SBarry Smith $                 PetscOptionsScalar(..., obj->value,&obj->value,...) or
10780fdccdaeSBarry Smith $                 value = defaultvalue
10790fdccdaeSBarry Smith $                 PetscOptionsScalar(..., value,&value,&flg);
10800fdccdaeSBarry Smith $                 if (flg) {
10810fdccdaeSBarry Smith 
108253acd3b1SBarry Smith 
108353acd3b1SBarry Smith    Output Parameter:
108453acd3b1SBarry Smith +  value - the value to return
108553acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
108653acd3b1SBarry Smith 
108795452b02SPatrick Sanan    Notes:
108895452b02SPatrick Sanan     If the user does not supply the option at all value is NOT changed. Thus
10892efd9cb1SBarry Smith     you should ALWAYS initialize value if you access it without first checking if the set flag is true.
10902efd9cb1SBarry Smith 
1091989712b9SBarry Smith     The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1092989712b9SBarry Smith 
109395452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
109453acd3b1SBarry Smith 
10955a856986SBarry Smith    Level: beginner
10965a856986SBarry Smith 
109789a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1098acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1099acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
110053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
110153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1102acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1103a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
110488aa4217SBarry Smith M*/
110588aa4217SBarry Smith 
11064416b707SBarry Smith PetscErrorCode  PetscOptionsScalar_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar currentvalue,PetscScalar *value,PetscBool  *set)
110753acd3b1SBarry Smith {
110853acd3b1SBarry Smith   PetscErrorCode ierr;
110953acd3b1SBarry Smith 
111053acd3b1SBarry Smith   PetscFunctionBegin;
111153acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
11120fdccdaeSBarry Smith   ierr = PetscOptionsReal(opt,text,man,currentvalue,value,set);CHKERRQ(ierr);
111353acd3b1SBarry Smith #else
1114c5929fdfSBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,set);CHKERRQ(ierr);
111553acd3b1SBarry Smith #endif
111653acd3b1SBarry Smith   PetscFunctionReturn(0);
111753acd3b1SBarry Smith }
111853acd3b1SBarry Smith 
111988aa4217SBarry Smith /*MC
112090d69ab7SBarry Smith    PetscOptionsName - Determines if a particular option has been set in the database. This returns true whether the option is a number, string or boolean, even
112190d69ab7SBarry Smith                       its value is set to false.
112253acd3b1SBarry Smith 
11233f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
112453acd3b1SBarry Smith 
112588aa4217SBarry Smith    Synopsis:
112688aa4217SBarry Smith    #include "petscsys.h"
1127*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsName(const char opt[],const char text[],const char man[],PetscBool  *flg)
112888aa4217SBarry Smith 
112953acd3b1SBarry Smith    Input Parameters:
113053acd3b1SBarry Smith +  opt - option name
113153acd3b1SBarry Smith .  text - short string that describes the option
113253acd3b1SBarry Smith -  man - manual page with additional information on option
113353acd3b1SBarry Smith 
113453acd3b1SBarry Smith    Output Parameter:
113553acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
113653acd3b1SBarry Smith 
113753acd3b1SBarry Smith    Level: beginner
113853acd3b1SBarry Smith 
113995452b02SPatrick Sanan    Notes:
114095452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
114153acd3b1SBarry Smith 
114289a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1143acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1144acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
114553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
114653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1147acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1148a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
114988aa4217SBarry Smith M*/
115088aa4217SBarry Smith 
11514416b707SBarry Smith PetscErrorCode  PetscOptionsName_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
115253acd3b1SBarry Smith {
115353acd3b1SBarry Smith   PetscErrorCode  ierr;
11544416b707SBarry Smith   PetscOptionItem amsopt;
115553acd3b1SBarry Smith 
115653acd3b1SBarry Smith   PetscFunctionBegin;
1157e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
11584416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1159ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1160a297a907SKarl Rupp 
1161ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
11621ae3d29cSBarry Smith   }
1163c5929fdfSBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg);CHKERRQ(ierr);
1164e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1165e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
116653acd3b1SBarry Smith   }
116753acd3b1SBarry Smith   PetscFunctionReturn(0);
116853acd3b1SBarry Smith }
116953acd3b1SBarry Smith 
117088aa4217SBarry Smith /*MC
1171a264d7a6SBarry Smith      PetscOptionsFList - Puts a list of option values that a single one may be selected from
117253acd3b1SBarry Smith 
11733f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
117453acd3b1SBarry Smith 
117588aa4217SBarry Smith    Synopsis:
117688aa4217SBarry Smith    #include "petscsys.h"
1177*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsFList(const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
117888aa4217SBarry Smith 
117953acd3b1SBarry Smith    Input Parameters:
118053acd3b1SBarry Smith +  opt - option name
118153acd3b1SBarry Smith .  text - short string that describes the option
118253acd3b1SBarry Smith .  man - manual page with additional information on option
118353acd3b1SBarry Smith .  list - the possible choices
11840fdccdaeSBarry Smith .  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
11850fdccdaeSBarry Smith $                 PetscOptionsFlist(..., obj->value,value,len,&flg);
11860fdccdaeSBarry Smith $                 if (flg) {
11873cc1e11dSBarry Smith -  len - the length of the character array value
118853acd3b1SBarry Smith 
118953acd3b1SBarry Smith    Output Parameter:
119053acd3b1SBarry Smith +  value - the value to return
119153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
119253acd3b1SBarry Smith 
119353acd3b1SBarry Smith    Level: intermediate
119453acd3b1SBarry Smith 
119595452b02SPatrick Sanan    Notes:
119695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
119753acd3b1SBarry Smith 
11982efd9cb1SBarry Smith           If the user does not supply the option at all value is NOT changed. Thus
11992efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
12002efd9cb1SBarry Smith 
1201989712b9SBarry Smith           The default/currentvalue passed into this routine does not get transferred to the output value variable automatically.
1202989712b9SBarry Smith 
120353acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
120453acd3b1SBarry Smith 
120553acd3b1SBarry Smith    To get a listing of all currently specified options,
120688c29154SBarry Smith     see PetscOptionsView() or PetscOptionsGetAll()
120753acd3b1SBarry Smith 
1208eabe10d7SBarry Smith    Developer Note: This cannot check for invalid selection because of things like MATAIJ that are not included in the list
1209eabe10d7SBarry Smith 
121089a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1211acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
121253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
121353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1214acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1215a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsEnum()
121688aa4217SBarry Smith M*/
121788aa4217SBarry Smith 
12184416b707SBarry Smith PetscErrorCode  PetscOptionsFList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],PetscFunctionList list,const char currentvalue[],char value[],size_t len,PetscBool  *set)
121953acd3b1SBarry Smith {
122053acd3b1SBarry Smith   PetscErrorCode  ierr;
12214416b707SBarry Smith   PetscOptionItem amsopt;
122244ef3d73SBarry Smith   PetscBool       lset;
122353acd3b1SBarry Smith 
122453acd3b1SBarry Smith   PetscFunctionBegin;
12251a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12264416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_FLIST,&amsopt);CHKERRQ(ierr);
122764facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12280fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12293cc1e11dSBarry Smith     amsopt->flist = list;
12303cc1e11dSBarry Smith   }
123144ef3d73SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,len,&lset);CHKERRQ(ierr);
123244ef3d73SBarry Smith   if (set) *set = lset;
12331a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1234c3b366b1Sprj-     ierr = PetscFunctionListPrintTypes(PetscOptionsObject->comm,stdout,PetscOptionsObject->prefix,opt,ltext,man,list,currentvalue,lset && value ? value : currentvalue);CHKERRQ(ierr);
123553acd3b1SBarry Smith   }
123653acd3b1SBarry Smith   PetscFunctionReturn(0);
123753acd3b1SBarry Smith }
123853acd3b1SBarry Smith 
123988aa4217SBarry Smith /*MC
124053acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
124153acd3b1SBarry Smith 
12423f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
124353acd3b1SBarry Smith 
124488aa4217SBarry Smith    Synopsis:
124588aa4217SBarry Smith    #include "petscsys.h"
1246*3a89f35bSSatish Balay    PetscErrorCode  PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool  *set)
124788aa4217SBarry Smith 
124853acd3b1SBarry Smith    Input Parameters:
124953acd3b1SBarry Smith +  opt - option name
125053acd3b1SBarry Smith .  ltext - short string that describes the option
125153acd3b1SBarry Smith .  man - manual page with additional information on option
1252a264d7a6SBarry Smith .  list - the possible choices (one of these must be selected, anything else is invalid)
125353acd3b1SBarry Smith .  ntext - number of choices
12540fdccdaeSBarry Smith -  currentvalue - the current value; caller is responsible for setting this value correctly. Normally this is done with
12550fdccdaeSBarry Smith $                 PetscOptionsElist(..., obj->value,&value,&flg);
12560fdccdaeSBarry Smith $                 if (flg) {
12570fdccdaeSBarry Smith 
125853acd3b1SBarry Smith 
125953acd3b1SBarry Smith    Output Parameter:
126053acd3b1SBarry Smith +  value - the index of the value to return
126153acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
126253acd3b1SBarry Smith 
126353acd3b1SBarry Smith    Level: intermediate
126453acd3b1SBarry Smith 
126595452b02SPatrick Sanan    Notes:
126695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
126753acd3b1SBarry Smith 
12682efd9cb1SBarry Smith          If the user does not supply the option at all value is NOT changed. Thus
12692efd9cb1SBarry Smith           you should ALWAYS initialize value if you access it without first checking if the set flag is true.
12702efd9cb1SBarry Smith 
1271a264d7a6SBarry Smith    See PetscOptionsFList() for when the choices are given in a PetscFunctionList()
127253acd3b1SBarry Smith 
127389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1274acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
127553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
127653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1277acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1278a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEnum()
127988aa4217SBarry Smith M*/
128088aa4217SBarry Smith 
12814416b707SBarry Smith PetscErrorCode  PetscOptionsEList_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char ltext[],const char man[],const char *const *list,PetscInt ntext,const char currentvalue[],PetscInt *value,PetscBool  *set)
128253acd3b1SBarry Smith {
128353acd3b1SBarry Smith   PetscErrorCode  ierr;
128453acd3b1SBarry Smith   PetscInt        i;
12854416b707SBarry Smith   PetscOptionItem amsopt;
128644ef3d73SBarry Smith   PetscBool       lset;
128753acd3b1SBarry Smith 
128853acd3b1SBarry Smith   PetscFunctionBegin;
12891a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
12904416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,ltext,man,OPTION_ELIST,&amsopt);CHKERRQ(ierr);
129164facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
12920fdccdaeSBarry Smith     ierr = PetscStrdup(currentvalue ? currentvalue : "",(char**)&amsopt->data);CHKERRQ(ierr);
12936991f827SBarry Smith     ierr = PetscStrNArrayallocpy(ntext,list,(char***)&amsopt->list);CHKERRQ(ierr);
12941ae3d29cSBarry Smith     amsopt->nlist = ntext;
12951ae3d29cSBarry Smith   }
129644ef3d73SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,list,ntext,value,&lset);CHKERRQ(ierr);
129744ef3d73SBarry Smith   if (set) *set = lset;
12981a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
12990e4c290aSBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <now %s : formerly %s> %s (choose one of)",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,lset && value ? list[*value] : currentvalue,currentvalue,ltext);CHKERRQ(ierr);
130053acd3b1SBarry Smith     for (i=0; i<ntext; i++) {
1301e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," %s",list[i]);CHKERRQ(ierr);
130253acd3b1SBarry Smith     }
1303e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm," (%s)\n",ManSection(man));CHKERRQ(ierr);
130453acd3b1SBarry Smith   }
130553acd3b1SBarry Smith   PetscFunctionReturn(0);
130653acd3b1SBarry Smith }
130753acd3b1SBarry Smith 
130888aa4217SBarry Smith /*MC
1309acfcf0e5SJed Brown      PetscOptionsBoolGroupBegin - First in a series of logical queries on the options database for
1310d5649816SBarry Smith        which at most a single value can be true.
131153acd3b1SBarry Smith 
13123f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
131353acd3b1SBarry Smith 
131488aa4217SBarry Smith    Synopsis:
131588aa4217SBarry Smith    #include "petscsys.h"
1316*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupBegin(const char opt[],const char text[],const char man[],PetscBool  *flg)
131788aa4217SBarry Smith 
131853acd3b1SBarry Smith    Input Parameters:
131953acd3b1SBarry Smith +  opt - option name
132053acd3b1SBarry Smith .  text - short string that describes the option
132153acd3b1SBarry Smith -  man - manual page with additional information on option
132253acd3b1SBarry Smith 
132353acd3b1SBarry Smith    Output Parameter:
132453acd3b1SBarry Smith .  flg - whether that option was set or not
132553acd3b1SBarry Smith 
132653acd3b1SBarry Smith    Level: intermediate
132753acd3b1SBarry Smith 
132895452b02SPatrick Sanan    Notes:
132995452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
133053acd3b1SBarry Smith 
1331acfcf0e5SJed Brown    Must be followed by 0 or more PetscOptionsBoolGroup()s and PetscOptionsBoolGroupEnd()
133253acd3b1SBarry Smith 
133389a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1334acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
133553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
133653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1337acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1338a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
133988aa4217SBarry Smith M*/
134088aa4217SBarry Smith 
13414416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupBegin_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
134253acd3b1SBarry Smith {
134353acd3b1SBarry Smith   PetscErrorCode  ierr;
13444416b707SBarry Smith   PetscOptionItem amsopt;
134553acd3b1SBarry Smith 
134653acd3b1SBarry Smith   PetscFunctionBegin;
1347e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
13484416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1349ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1350a297a907SKarl Rupp 
1351ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
13521ae3d29cSBarry Smith   }
135368b16fdaSBarry Smith   *flg = PETSC_FALSE;
1354c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1355e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1356e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
1357e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
135853acd3b1SBarry Smith   }
135953acd3b1SBarry Smith   PetscFunctionReturn(0);
136053acd3b1SBarry Smith }
136153acd3b1SBarry Smith 
136288aa4217SBarry Smith /*MC
1363acfcf0e5SJed Brown      PetscOptionsBoolGroup - One in a series of logical queries on the options database for
1364d5649816SBarry Smith        which at most a single value can be true.
136553acd3b1SBarry Smith 
13663f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
136753acd3b1SBarry Smith 
136888aa4217SBarry Smith    Synopsis:
136988aa4217SBarry Smith    #include "petscsys.h"
1370*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroup(const char opt[],const char text[],const char man[],PetscBool  *flg)
137188aa4217SBarry Smith 
137253acd3b1SBarry Smith    Input Parameters:
137353acd3b1SBarry Smith +  opt - option name
137453acd3b1SBarry Smith .  text - short string that describes the option
137553acd3b1SBarry Smith -  man - manual page with additional information on option
137653acd3b1SBarry Smith 
137753acd3b1SBarry Smith    Output Parameter:
137853acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
137953acd3b1SBarry Smith 
138053acd3b1SBarry Smith    Level: intermediate
138153acd3b1SBarry Smith 
138295452b02SPatrick Sanan    Notes:
138395452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
138453acd3b1SBarry Smith 
1385acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin() and preceded a PetscOptionsBoolGroupEnd()
138653acd3b1SBarry Smith 
138789a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1388acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
138953acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
139053acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1391acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1392a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
139388aa4217SBarry Smith M*/
139488aa4217SBarry Smith 
13954416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroup_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
139653acd3b1SBarry Smith {
139753acd3b1SBarry Smith   PetscErrorCode  ierr;
13984416b707SBarry Smith   PetscOptionItem amsopt;
139953acd3b1SBarry Smith 
140053acd3b1SBarry Smith   PetscFunctionBegin;
1401e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14024416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1403ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1404a297a907SKarl Rupp 
1405ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
14061ae3d29cSBarry Smith   }
140717326d04SJed Brown   *flg = PETSC_FALSE;
1408c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1409e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1410e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
141153acd3b1SBarry Smith   }
141253acd3b1SBarry Smith   PetscFunctionReturn(0);
141353acd3b1SBarry Smith }
141453acd3b1SBarry Smith 
141588aa4217SBarry Smith /*MC
1416acfcf0e5SJed Brown      PetscOptionsBoolGroupEnd - Last in a series of logical queries on the options database for
1417d5649816SBarry Smith        which at most a single value can be true.
141853acd3b1SBarry Smith 
14193f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
142053acd3b1SBarry Smith 
142188aa4217SBarry Smith    Synopsis:
142288aa4217SBarry Smith    #include "petscsys.h"
1423*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolGroupEnd(const char opt[],const char text[],const char man[],PetscBool  *flg)
142488aa4217SBarry Smith 
142553acd3b1SBarry Smith    Input Parameters:
142653acd3b1SBarry Smith +  opt - option name
142753acd3b1SBarry Smith .  text - short string that describes the option
142853acd3b1SBarry Smith -  man - manual page with additional information on option
142953acd3b1SBarry Smith 
143053acd3b1SBarry Smith    Output Parameter:
143153acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
143253acd3b1SBarry Smith 
143353acd3b1SBarry Smith    Level: intermediate
143453acd3b1SBarry Smith 
143595452b02SPatrick Sanan    Notes:
143695452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
143753acd3b1SBarry Smith 
1438acfcf0e5SJed Brown    Must follow a PetscOptionsBoolGroupBegin()
143953acd3b1SBarry Smith 
144089a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1441acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
144253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
144353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1444acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1445a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
144688aa4217SBarry Smith M*/
144788aa4217SBarry Smith 
14484416b707SBarry Smith PetscErrorCode  PetscOptionsBoolGroupEnd_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool  *flg)
144953acd3b1SBarry Smith {
145053acd3b1SBarry Smith   PetscErrorCode  ierr;
14514416b707SBarry Smith   PetscOptionItem amsopt;
145253acd3b1SBarry Smith 
145353acd3b1SBarry Smith   PetscFunctionBegin;
1454e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
14554416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1456ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1457a297a907SKarl Rupp 
1458ace3abfcSBarry Smith     *(PetscBool*)amsopt->data = PETSC_FALSE;
14591ae3d29cSBarry Smith   }
146017326d04SJed Brown   *flg = PETSC_FALSE;
1461c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,NULL);CHKERRQ(ierr);
1462e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1463e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"    -%s%s: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
146453acd3b1SBarry Smith   }
146553acd3b1SBarry Smith   PetscFunctionReturn(0);
146653acd3b1SBarry Smith }
146753acd3b1SBarry Smith 
146888aa4217SBarry Smith /*MC
1469acfcf0e5SJed Brown    PetscOptionsBool - Determines if a particular option is in the database with a true or false
147053acd3b1SBarry Smith 
14713f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
147253acd3b1SBarry Smith 
147388aa4217SBarry Smith    Synopsis:
147488aa4217SBarry Smith    #include "petscsys.h"
1475*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsBool(const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
147688aa4217SBarry Smith 
147753acd3b1SBarry Smith    Input Parameters:
147853acd3b1SBarry Smith +  opt - option name
147953acd3b1SBarry Smith .  text - short string that describes the option
1480868c398cSBarry Smith .  man - manual page with additional information on option
148194ae4db5SBarry Smith -  currentvalue - the current value
148253acd3b1SBarry Smith 
148353acd3b1SBarry Smith    Output Parameter:
1484a2b725a8SWilliam Gropp +  flg - PETSC_TRUE or PETSC_FALSE
1485a2b725a8SWilliam Gropp -  set - PETSC_TRUE if found, else PETSC_FALSE
148653acd3b1SBarry Smith 
14872efd9cb1SBarry Smith    Notes:
14882efd9cb1SBarry Smith        TRUE, true, YES, yes, nostring, and 1 all translate to PETSC_TRUE
14892efd9cb1SBarry Smith        FALSE, false, NO, no, and 0 all translate to PETSC_FALSE
14902efd9cb1SBarry Smith 
14912efd9cb1SBarry Smith       If the option is given, but no value is provided, then flg and set are both given the value PETSC_TRUE. That is -requested_bool
14922efd9cb1SBarry Smith      is equivalent to -requested_bool true
14932efd9cb1SBarry Smith 
14942efd9cb1SBarry Smith        If the user does not supply the option at all flg is NOT changed. Thus
14952efd9cb1SBarry Smith      you should ALWAYS initialize the flg if you access it without first checking if the set flag is true.
14962efd9cb1SBarry Smith 
149795452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
149853acd3b1SBarry Smith 
14995a856986SBarry Smith    Level: beginner
15005a856986SBarry Smith 
150189a13869SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
1502acfcf0e5SJed Brown           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
1503acfcf0e5SJed Brown           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
150453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
150553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1506acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1507a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
150888aa4217SBarry Smith M*/
150988aa4217SBarry Smith 
15104416b707SBarry Smith PetscErrorCode  PetscOptionsBool_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool currentvalue,PetscBool  *flg,PetscBool  *set)
151153acd3b1SBarry Smith {
151253acd3b1SBarry Smith   PetscErrorCode  ierr;
1513ace3abfcSBarry Smith   PetscBool       iset;
15144416b707SBarry Smith   PetscOptionItem amsopt;
151553acd3b1SBarry Smith 
151653acd3b1SBarry Smith   PetscFunctionBegin;
1517e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
15184416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL,&amsopt);CHKERRQ(ierr);
1519ace3abfcSBarry Smith     ierr = PetscMalloc(sizeof(PetscBool),&amsopt->data);CHKERRQ(ierr);
1520a297a907SKarl Rupp 
152194ae4db5SBarry Smith     *(PetscBool*)amsopt->data = currentvalue;
1522af6d86caSBarry Smith   }
1523c5929fdfSBarry Smith   ierr = PetscOptionsGetBool(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,flg,&iset);CHKERRQ(ierr);
152453acd3b1SBarry Smith   if (set) *set = iset;
15251a1499c8SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
152644ef3d73SBarry Smith     const char *v = PetscBools[currentvalue], *vn = PetscBools[iset && flg ? *flg : currentvalue];
152744ef3d73SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s: <%s : %s> %s (%s)\n",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,v,vn,text,ManSection(man));CHKERRQ(ierr);
152853acd3b1SBarry Smith   }
152953acd3b1SBarry Smith   PetscFunctionReturn(0);
153053acd3b1SBarry Smith }
153153acd3b1SBarry Smith 
153288aa4217SBarry Smith /*MC
153353acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
153453acd3b1SBarry Smith    option in the database. The values must be separated with commas with
153553acd3b1SBarry Smith    no intervening spaces.
153653acd3b1SBarry Smith 
15373f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
153853acd3b1SBarry Smith 
153988aa4217SBarry Smith    Synopsis:
154088aa4217SBarry Smith    #include "petscsys.h"
1541*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
154288aa4217SBarry Smith 
154353acd3b1SBarry Smith    Input Parameters:
154453acd3b1SBarry Smith +  opt - the option one is seeking
154553acd3b1SBarry Smith .  text - short string describing option
154653acd3b1SBarry Smith .  man - manual page for option
154753acd3b1SBarry Smith -  nmax - maximum number of values
154853acd3b1SBarry Smith 
154953acd3b1SBarry Smith    Output Parameter:
155053acd3b1SBarry Smith +  value - location to copy values
155153acd3b1SBarry Smith .  nmax - actual number of values found
155253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
155353acd3b1SBarry Smith 
155453acd3b1SBarry Smith    Level: beginner
155553acd3b1SBarry Smith 
155653acd3b1SBarry Smith    Notes:
155753acd3b1SBarry Smith    The user should pass in an array of doubles
155853acd3b1SBarry Smith 
155953acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
156053acd3b1SBarry Smith 
156189a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1562acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
156353acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
156453acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1565acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1566a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
156788aa4217SBarry Smith M*/
156888aa4217SBarry Smith 
15694416b707SBarry Smith PetscErrorCode PetscOptionsRealArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscBool  *set)
157053acd3b1SBarry Smith {
157153acd3b1SBarry Smith   PetscErrorCode  ierr;
157253acd3b1SBarry Smith   PetscInt        i;
15734416b707SBarry Smith   PetscOptionItem amsopt;
157453acd3b1SBarry Smith 
157553acd3b1SBarry Smith   PetscFunctionBegin;
1576e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1577e26ddf31SBarry Smith     PetscReal *vals;
1578e26ddf31SBarry Smith 
15794416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1580e55864a3SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1581e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1582e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1583e26ddf31SBarry Smith     amsopt->arraylength = *n;
1584e26ddf31SBarry Smith   }
1585c5929fdfSBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1586e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1587a519f713SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)value[0]);CHKERRQ(ierr);
158853acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1589e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g",(double)value[i]);CHKERRQ(ierr);
159053acd3b1SBarry Smith     }
1591e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
159253acd3b1SBarry Smith   }
159353acd3b1SBarry Smith   PetscFunctionReturn(0);
159453acd3b1SBarry Smith }
159553acd3b1SBarry Smith 
159688aa4217SBarry Smith /*MC
1597050cccc3SHong Zhang    PetscOptionsScalarArray - Gets an array of Scalar values for a particular
1598050cccc3SHong Zhang    option in the database. The values must be separated with commas with
1599050cccc3SHong Zhang    no intervening spaces.
1600050cccc3SHong Zhang 
1601050cccc3SHong Zhang    Logically Collective on the communicator passed in PetscOptionsBegin()
1602050cccc3SHong Zhang 
160388aa4217SBarry Smith    Synopsis:
160488aa4217SBarry Smith    #include "petscsys.h"
1605*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsScalarArray(const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
160688aa4217SBarry Smith 
1607050cccc3SHong Zhang    Input Parameters:
1608050cccc3SHong Zhang +  opt - the option one is seeking
1609050cccc3SHong Zhang .  text - short string describing option
1610050cccc3SHong Zhang .  man - manual page for option
1611050cccc3SHong Zhang -  nmax - maximum number of values
1612050cccc3SHong Zhang 
1613050cccc3SHong Zhang    Output Parameter:
1614050cccc3SHong Zhang +  value - location to copy values
1615050cccc3SHong Zhang .  nmax - actual number of values found
1616050cccc3SHong Zhang -  set - PETSC_TRUE if found, else PETSC_FALSE
1617050cccc3SHong Zhang 
1618050cccc3SHong Zhang    Level: beginner
1619050cccc3SHong Zhang 
1620050cccc3SHong Zhang    Notes:
1621050cccc3SHong Zhang    The user should pass in an array of doubles
1622050cccc3SHong Zhang 
1623050cccc3SHong Zhang    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1624050cccc3SHong Zhang 
162589a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1626050cccc3SHong Zhang           PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1627050cccc3SHong Zhang           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1628050cccc3SHong Zhang           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1629050cccc3SHong Zhang           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1630050cccc3SHong Zhang           PetscOptionsFList(), PetscOptionsEList()
163188aa4217SBarry Smith M*/
163288aa4217SBarry Smith 
16334416b707SBarry Smith PetscErrorCode PetscOptionsScalarArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscScalar value[],PetscInt *n,PetscBool  *set)
1634050cccc3SHong Zhang {
1635050cccc3SHong Zhang   PetscErrorCode  ierr;
1636050cccc3SHong Zhang   PetscInt        i;
16374416b707SBarry Smith   PetscOptionItem amsopt;
1638050cccc3SHong Zhang 
1639050cccc3SHong Zhang   PetscFunctionBegin;
1640050cccc3SHong Zhang   if (!PetscOptionsObject->count) {
1641050cccc3SHong Zhang     PetscScalar *vals;
1642050cccc3SHong Zhang 
16434416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_SCALAR_ARRAY,&amsopt);CHKERRQ(ierr);
1644050cccc3SHong Zhang     ierr = PetscMalloc((*n)*sizeof(PetscScalar),&amsopt->data);CHKERRQ(ierr);
1645050cccc3SHong Zhang     vals = (PetscScalar*)amsopt->data;
1646050cccc3SHong Zhang     for (i=0; i<*n; i++) vals[i] = value[i];
1647050cccc3SHong Zhang     amsopt->arraylength = *n;
1648050cccc3SHong Zhang   }
1649c5929fdfSBarry Smith   ierr = PetscOptionsGetScalarArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1650050cccc3SHong Zhang   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
165195f3a755SJose E. Roman     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%g+%gi",PetscOptionsObject->prefix?PetscOptionsObject->prefix:"",opt+1,(double)PetscRealPart(value[0]),(double)PetscImaginaryPart(value[0]));CHKERRQ(ierr);
1652050cccc3SHong Zhang     for (i=1; i<*n; i++) {
165395f3a755SJose E. Roman       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%g+%gi",(double)PetscRealPart(value[i]),(double)PetscImaginaryPart(value[i]));CHKERRQ(ierr);
1654050cccc3SHong Zhang     }
1655050cccc3SHong Zhang     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1656050cccc3SHong Zhang   }
1657050cccc3SHong Zhang   PetscFunctionReturn(0);
1658050cccc3SHong Zhang }
165953acd3b1SBarry Smith 
166088aa4217SBarry Smith /*MC
166153acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
1662b32a342fSShri Abhyankar    option in the database.
166353acd3b1SBarry Smith 
16643f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
166553acd3b1SBarry Smith 
166688aa4217SBarry Smith    Synopsis:
166788aa4217SBarry Smith    #include "petscsys.h"
1668*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
166988aa4217SBarry Smith 
167053acd3b1SBarry Smith    Input Parameters:
167153acd3b1SBarry Smith +  opt - the option one is seeking
167253acd3b1SBarry Smith .  text - short string describing option
167353acd3b1SBarry Smith .  man - manual page for option
1674f8a50e2bSBarry Smith -  n - maximum number of values
167553acd3b1SBarry Smith 
167653acd3b1SBarry Smith    Output Parameter:
167753acd3b1SBarry Smith +  value - location to copy values
1678f8a50e2bSBarry Smith .  n - actual number of values found
167953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
168053acd3b1SBarry Smith 
168153acd3b1SBarry Smith    Level: beginner
168253acd3b1SBarry Smith 
168353acd3b1SBarry Smith    Notes:
1684b32a342fSShri Abhyankar    The array can be passed as
1685bebe2cf6SSatish Balay    a comma separated list:                                 0,1,2,3,4,5,6,7
16860fd488f5SShri Abhyankar    a range (start-end+1):                                  0-8
16870fd488f5SShri Abhyankar    a range with given increment (start-end+1:inc):         0-7:2
1688bebe2cf6SSatish Balay    a combination of values and ranges separated by commas: 0,1-8,8-15:2
1689b32a342fSShri Abhyankar 
1690b32a342fSShri Abhyankar    There must be no intervening spaces between the values.
169153acd3b1SBarry Smith 
169253acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
169353acd3b1SBarry Smith 
169489a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1695acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
169653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
169753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1698acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1699a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList(), PetscOptionsRealArray()
170088aa4217SBarry Smith M*/
170188aa4217SBarry Smith 
17024416b707SBarry Smith PetscErrorCode  PetscOptionsIntArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscBool  *set)
170353acd3b1SBarry Smith {
170453acd3b1SBarry Smith   PetscErrorCode ierr;
170553acd3b1SBarry Smith   PetscInt        i;
17064416b707SBarry Smith   PetscOptionItem amsopt;
170753acd3b1SBarry Smith 
170853acd3b1SBarry Smith   PetscFunctionBegin;
1709e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1710e26ddf31SBarry Smith     PetscInt *vals;
1711e26ddf31SBarry Smith 
17124416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1713854ce69bSBarry Smith     ierr = PetscMalloc1(*n,(PetscInt**)&amsopt->data);CHKERRQ(ierr);
1714e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1715e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1716e26ddf31SBarry Smith     amsopt->arraylength = *n;
1717e26ddf31SBarry Smith   }
1718c5929fdfSBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1719e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1720e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
172153acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1722e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
172353acd3b1SBarry Smith     }
1724e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
172553acd3b1SBarry Smith   }
172653acd3b1SBarry Smith   PetscFunctionReturn(0);
172753acd3b1SBarry Smith }
172853acd3b1SBarry Smith 
172988aa4217SBarry Smith /*MC
173053acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
173153acd3b1SBarry Smith    option in the database. The values must be separated with commas with
173253acd3b1SBarry Smith    no intervening spaces.
173353acd3b1SBarry Smith 
17343f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
173553acd3b1SBarry Smith 
173688aa4217SBarry Smith    Synopsis:
173788aa4217SBarry Smith    #include "petscsys.h"
1738*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
173988aa4217SBarry Smith 
174053acd3b1SBarry Smith    Input Parameters:
174153acd3b1SBarry Smith +  opt - the option one is seeking
174253acd3b1SBarry Smith .  text - short string describing option
174353acd3b1SBarry Smith .  man - manual page for option
174453acd3b1SBarry Smith -  nmax - maximum number of strings
174553acd3b1SBarry Smith 
174653acd3b1SBarry Smith    Output Parameter:
174753acd3b1SBarry Smith +  value - location to copy strings
174853acd3b1SBarry Smith .  nmax - actual number of strings found
174953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
175053acd3b1SBarry Smith 
175153acd3b1SBarry Smith    Level: beginner
175253acd3b1SBarry Smith 
175353acd3b1SBarry Smith    Notes:
175453acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
175553acd3b1SBarry Smith    strings returned by this function.
175653acd3b1SBarry Smith 
175753acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
175853acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
175953acd3b1SBarry Smith 
176053acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
176153acd3b1SBarry Smith 
176289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1763acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
176453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
176553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1766acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1767a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
176888aa4217SBarry Smith M*/
176988aa4217SBarry Smith 
17704416b707SBarry Smith PetscErrorCode  PetscOptionsStringArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscBool  *set)
177153acd3b1SBarry Smith {
177253acd3b1SBarry Smith   PetscErrorCode  ierr;
17734416b707SBarry Smith   PetscOptionItem amsopt;
177453acd3b1SBarry Smith 
177553acd3b1SBarry Smith   PetscFunctionBegin;
1776e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
17774416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1778854ce69bSBarry Smith     ierr = PetscMalloc1(*nmax,(char**)&amsopt->data);CHKERRQ(ierr);
1779a297a907SKarl Rupp 
17801ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
17811ae3d29cSBarry Smith   }
1782c5929fdfSBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,nmax,set);CHKERRQ(ierr);
1783e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1784e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,text,ManSection(man));CHKERRQ(ierr);
178553acd3b1SBarry Smith   }
178653acd3b1SBarry Smith   PetscFunctionReturn(0);
178753acd3b1SBarry Smith }
178853acd3b1SBarry Smith 
178988aa4217SBarry Smith /*MC
1790acfcf0e5SJed Brown    PetscOptionsBoolArray - Gets an array of logical values (true or false) for a particular
1791e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1792e2446a98SMatthew Knepley    no intervening spaces.
1793e2446a98SMatthew Knepley 
17943f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
1795e2446a98SMatthew Knepley 
179688aa4217SBarry Smith    Synopsis:
179788aa4217SBarry Smith    #include "petscsys.h"
1798*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsBoolArray(const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
179988aa4217SBarry Smith 
1800e2446a98SMatthew Knepley    Input Parameters:
1801e2446a98SMatthew Knepley +  opt - the option one is seeking
1802e2446a98SMatthew Knepley .  text - short string describing option
1803e2446a98SMatthew Knepley .  man - manual page for option
1804e2446a98SMatthew Knepley -  nmax - maximum number of values
1805e2446a98SMatthew Knepley 
1806e2446a98SMatthew Knepley    Output Parameter:
1807e2446a98SMatthew Knepley +  value - location to copy values
1808e2446a98SMatthew Knepley .  nmax - actual number of values found
1809e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1810e2446a98SMatthew Knepley 
1811e2446a98SMatthew Knepley    Level: beginner
1812e2446a98SMatthew Knepley 
1813e2446a98SMatthew Knepley    Notes:
1814e2446a98SMatthew Knepley    The user should pass in an array of doubles
1815e2446a98SMatthew Knepley 
1816e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1817e2446a98SMatthew Knepley 
181889a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1819acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
1820e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1821e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1822acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1823a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
182488aa4217SBarry Smith M*/
182588aa4217SBarry Smith 
18264416b707SBarry Smith PetscErrorCode  PetscOptionsBoolArray_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscBool value[],PetscInt *n,PetscBool *set)
1827e2446a98SMatthew Knepley {
1828e2446a98SMatthew Knepley   PetscErrorCode   ierr;
1829e2446a98SMatthew Knepley   PetscInt         i;
18304416b707SBarry Smith   PetscOptionItem  amsopt;
1831e2446a98SMatthew Knepley 
1832e2446a98SMatthew Knepley   PetscFunctionBegin;
1833e55864a3SBarry Smith   if (!PetscOptionsObject->count) {
1834ace3abfcSBarry Smith     PetscBool *vals;
18351ae3d29cSBarry Smith 
18364416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_BOOL_ARRAY,&amsopt);CHKERRQ(ierr);
18371a1499c8SBarry Smith     ierr = PetscMalloc1(*n,(PetscBool**)&amsopt->data);CHKERRQ(ierr);
1838ace3abfcSBarry Smith     vals = (PetscBool*)amsopt->data;
18391ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
18401ae3d29cSBarry Smith     amsopt->arraylength = *n;
18411ae3d29cSBarry Smith   }
1842c5929fdfSBarry Smith   ierr = PetscOptionsGetBoolArray(PetscOptionsObject->options,PetscOptionsObject->prefix,opt,value,n,set);CHKERRQ(ierr);
1843e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1844e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%d",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,value[0]);CHKERRQ(ierr);
1845e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1846e55864a3SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,",%d",value[i]);CHKERRQ(ierr);
1847e2446a98SMatthew Knepley     }
1848e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,">: %s (%s)\n",text,ManSection(man));CHKERRQ(ierr);
1849e2446a98SMatthew Knepley   }
1850e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1851e2446a98SMatthew Knepley }
1852e2446a98SMatthew Knepley 
185388aa4217SBarry Smith /*MC
1854d1da0b69SBarry Smith    PetscOptionsViewer - Gets a viewer appropriate for the type indicated by the user
18558cc676e6SMatthew G Knepley 
18568cc676e6SMatthew G Knepley    Logically Collective on the communicator passed in PetscOptionsBegin()
18578cc676e6SMatthew G Knepley 
185888aa4217SBarry Smith    Synopsis:
185988aa4217SBarry Smith    #include "petscsys.h"
1860*3a89f35bSSatish Balay    PetscErrorCode PetscOptionsViewer(const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
186188aa4217SBarry Smith 
18628cc676e6SMatthew G Knepley    Input Parameters:
18638cc676e6SMatthew G Knepley +  opt - option name
18648cc676e6SMatthew G Knepley .  text - short string that describes the option
18658cc676e6SMatthew G Knepley -  man - manual page with additional information on option
18668cc676e6SMatthew G Knepley 
18678cc676e6SMatthew G Knepley    Output Parameter:
18688cc676e6SMatthew G Knepley +  viewer - the viewer
18698cc676e6SMatthew G Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
18708cc676e6SMatthew G Knepley 
18718cc676e6SMatthew G Knepley    Level: beginner
18728cc676e6SMatthew G Knepley 
187395452b02SPatrick Sanan    Notes:
187495452b02SPatrick Sanan     Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
18758cc676e6SMatthew G Knepley 
18765a7113b9SPatrick Sanan    See PetscOptionsGetViewer() for the format of the supplied viewer and its options
18778cc676e6SMatthew G Knepley 
187889a13869SBarry Smith .seealso: PetscOptionsGetViewer(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
18798cc676e6SMatthew G Knepley           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool()
18808cc676e6SMatthew G Knepley           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsBool(),
18818cc676e6SMatthew G Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
18828cc676e6SMatthew G Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
18838cc676e6SMatthew G Knepley           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1884a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
188588aa4217SBarry Smith M*/
188688aa4217SBarry Smith 
18874416b707SBarry Smith PetscErrorCode  PetscOptionsViewer_Private(PetscOptionItems *PetscOptionsObject,const char opt[],const char text[],const char man[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool  *set)
18888cc676e6SMatthew G Knepley {
18898cc676e6SMatthew G Knepley   PetscErrorCode  ierr;
18904416b707SBarry Smith   PetscOptionItem amsopt;
18918cc676e6SMatthew G Knepley 
18928cc676e6SMatthew G Knepley   PetscFunctionBegin;
18931a1499c8SBarry Smith   if (!PetscOptionsObject->count) {
18944416b707SBarry Smith     ierr = PetscOptionItemCreate_Private(PetscOptionsObject,opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
189564facd6cSBarry Smith     /* must use system malloc since SAWs may free this */
18965b02f95dSBarry Smith     ierr = PetscStrdup("",(char**)&amsopt->data);CHKERRQ(ierr);
18978cc676e6SMatthew G Knepley   }
189816413a6aSBarry Smith   ierr = PetscOptionsGetViewer(PetscOptionsObject->comm,PetscOptionsObject->options,PetscOptionsObject->prefix,opt,viewer,format,set);CHKERRQ(ierr);
1899e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1900e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject->prefix ? PetscOptionsObject->prefix : "",opt+1,"",text,ManSection(man));CHKERRQ(ierr);
19018cc676e6SMatthew G Knepley   }
19028cc676e6SMatthew G Knepley   PetscFunctionReturn(0);
19038cc676e6SMatthew G Knepley }
19048cc676e6SMatthew G Knepley 
190553acd3b1SBarry Smith /*@C
1906b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
190753acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
190853acd3b1SBarry Smith 
19093f9fe445SBarry Smith    Logically Collective on the communicator passed in PetscOptionsBegin()
191053acd3b1SBarry Smith 
191153acd3b1SBarry Smith    Input Parameter:
191253acd3b1SBarry Smith .   head - the heading text
191353acd3b1SBarry Smith 
191453acd3b1SBarry Smith 
191553acd3b1SBarry Smith    Level: intermediate
191653acd3b1SBarry Smith 
191795452b02SPatrick Sanan    Notes:
1918*3a89f35bSSatish Balay     Must be between a PetscOptionsBegin() and a PetscOptionsEnd(), and PetscOptionsObject created in PetscOptionsBegin() should be the first argument
191953acd3b1SBarry Smith 
1920b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
192153acd3b1SBarry Smith 
192289a13869SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1923acfcf0e5SJed Brown            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsBool(),
192453acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
192553acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1926acfcf0e5SJed Brown           PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
1927a264d7a6SBarry Smith           PetscOptionsFList(), PetscOptionsEList()
192853acd3b1SBarry Smith @*/
19294416b707SBarry Smith PetscErrorCode  PetscOptionsHead(PetscOptionItems *PetscOptionsObject,const char head[])
193053acd3b1SBarry Smith {
193153acd3b1SBarry Smith   PetscErrorCode ierr;
193253acd3b1SBarry Smith 
193353acd3b1SBarry Smith   PetscFunctionBegin;
1934e55864a3SBarry Smith   if (PetscOptionsObject->printhelp && PetscOptionsObject->count == 1 && !PetscOptionsObject->alreadyprinted) {
1935e55864a3SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject->comm,"  %s\n",head);CHKERRQ(ierr);
193653acd3b1SBarry Smith   }
193753acd3b1SBarry Smith   PetscFunctionReturn(0);
193853acd3b1SBarry Smith }
193953acd3b1SBarry Smith 
194053acd3b1SBarry Smith 
194153acd3b1SBarry Smith 
194253acd3b1SBarry Smith 
194353acd3b1SBarry Smith 
194453acd3b1SBarry Smith 
1945