xref: /petsc/src/sys/objects/aoptions.c (revision 1ae3d29c0c4ff12b751c773c3532c58ab4c7ae04)
153acd3b1SBarry Smith #define PETSC_DLL
253acd3b1SBarry Smith /*
33fc1eb6aSBarry Smith    Implements the higher-level options database querying methods. These are self-documenting and can attach at runtime to
43fc1eb6aSBarry Smith    GUI code to display the options and get values from the users.
553acd3b1SBarry Smith 
653acd3b1SBarry Smith */
753acd3b1SBarry Smith 
8d382aafbSBarry Smith #include "petscsys.h"        /*I  "petscsys.h"   I*/
953acd3b1SBarry Smith #if defined(PETSC_HAVE_STDLIB_H)
1053acd3b1SBarry Smith #include <stdlib.h>
1153acd3b1SBarry Smith #endif
1253acd3b1SBarry Smith 
1353acd3b1SBarry Smith /*
1453acd3b1SBarry Smith     Keep a linked list of options that have been posted and we are waiting for
153fc1eb6aSBarry Smith    user selection. See the manual page for PetscOptionsBegin()
1653acd3b1SBarry Smith 
1753acd3b1SBarry Smith     Eventually we'll attach this beast to a MPI_Comm
1853acd3b1SBarry Smith */
19f8d0b74dSMatthew Knepley PetscOptionsObjectType PetscOptionsObject;
2053acd3b1SBarry Smith PetscInt               PetscOptionsPublishCount = 0;
2153acd3b1SBarry Smith 
2253acd3b1SBarry Smith #undef __FUNCT__
2353acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsBegin_Private"
2453acd3b1SBarry Smith /*
2553acd3b1SBarry Smith     Handles setting up the data structure in a call to PetscOptionsBegin()
2653acd3b1SBarry Smith */
2753acd3b1SBarry Smith PetscErrorCode PetscOptionsBegin_Private(MPI_Comm comm,const char prefix[],const char title[],const char mansec[])
2853acd3b1SBarry Smith {
2953acd3b1SBarry Smith   PetscErrorCode ierr;
3053acd3b1SBarry Smith 
3153acd3b1SBarry Smith   PetscFunctionBegin;
3253acd3b1SBarry Smith   PetscOptionsObject.next          = 0;
3353acd3b1SBarry Smith   PetscOptionsObject.comm          = comm;
346356e834SBarry Smith   PetscOptionsObject.changedmethod = PETSC_FALSE;
35f8d0b74dSMatthew Knepley   if (PetscOptionsObject.prefix) {
36503cfb0cSBarry Smith     ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
37f8d0b74dSMatthew Knepley   }
3853acd3b1SBarry Smith   ierr = PetscStrallocpy(prefix,&PetscOptionsObject.prefix);CHKERRQ(ierr);
39f8d0b74dSMatthew Knepley   if (PetscOptionsObject.title) {
40503cfb0cSBarry Smith     ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
41f8d0b74dSMatthew Knepley   }
4253acd3b1SBarry Smith   ierr = PetscStrallocpy(title,&PetscOptionsObject.title);CHKERRQ(ierr);
4353acd3b1SBarry Smith 
4453acd3b1SBarry Smith   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
4553acd3b1SBarry Smith   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
4661b37b28SSatish Balay     if (!PetscOptionsObject.alreadyprinted) {
4753acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
4853acd3b1SBarry Smith     }
4961b37b28SSatish Balay   }
5053acd3b1SBarry Smith   PetscFunctionReturn(0);
5153acd3b1SBarry Smith }
5253acd3b1SBarry Smith 
5353acd3b1SBarry Smith /*
5453acd3b1SBarry Smith      Handles adding another option to the list of options within this particular PetscOptionsBegin() PetscOptionsEnd()
5553acd3b1SBarry Smith */
5653acd3b1SBarry Smith #undef __FUNCT__
5753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsCreate_Private"
58e3ed6ec8SBarry Smith static int PetscOptionsCreate_Private(const char opt[],const char text[],const char man[],PetscOptionType t,PetscOptions *amsopt)
5953acd3b1SBarry Smith {
6053acd3b1SBarry Smith   int          ierr;
6153acd3b1SBarry Smith   PetscOptions next;
6253acd3b1SBarry Smith 
6353acd3b1SBarry Smith   PetscFunctionBegin;
64e3ed6ec8SBarry Smith   ierr             = PetscNew(struct _p_PetscOptions,amsopt);CHKERRQ(ierr);
6553acd3b1SBarry Smith   (*amsopt)->next  = 0;
6653acd3b1SBarry Smith   (*amsopt)->set   = PETSC_FALSE;
676356e834SBarry Smith   (*amsopt)->type  = t;
6853acd3b1SBarry Smith   (*amsopt)->data  = 0;
6961b37b28SSatish Balay 
7053acd3b1SBarry Smith   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
7153acd3b1SBarry Smith   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
726356e834SBarry Smith   ierr             = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
7353acd3b1SBarry Smith 
7453acd3b1SBarry Smith   if (!PetscOptionsObject.next) {
7553acd3b1SBarry Smith     PetscOptionsObject.next = *amsopt;
7653acd3b1SBarry Smith   } else {
7753acd3b1SBarry Smith     next = PetscOptionsObject.next;
7853acd3b1SBarry Smith     while (next->next) next = next->next;
7953acd3b1SBarry Smith     next->next = *amsopt;
8053acd3b1SBarry Smith   }
8153acd3b1SBarry Smith   PetscFunctionReturn(0);
8253acd3b1SBarry Smith }
8353acd3b1SBarry Smith 
8453acd3b1SBarry Smith #undef __FUNCT__
85aee2cecaSBarry Smith #define __FUNCT__ "PetscScanString"
86aee2cecaSBarry Smith /*
873fc1eb6aSBarry Smith     PetscScanString -  Gets user input via stdin from process and broadcasts to all processes
883fc1eb6aSBarry Smith 
893fc1eb6aSBarry Smith     Collective on MPI_Comm
903fc1eb6aSBarry Smith 
913fc1eb6aSBarry Smith    Input Parameters:
923fc1eb6aSBarry Smith +     commm - communicator for the broadcast, must be PETSC_COMM_WORLD
933fc1eb6aSBarry Smith .     n - length of the string, must be the same on all processes
943fc1eb6aSBarry Smith -     str - location to store input
95aee2cecaSBarry Smith 
96aee2cecaSBarry Smith     Bugs:
97aee2cecaSBarry Smith .   Assumes process 0 of the given communicator has access to stdin
98aee2cecaSBarry Smith 
99aee2cecaSBarry Smith */
1003fc1eb6aSBarry Smith static PetscErrorCode PetscScanString(MPI_Comm comm,size_t n,char str[])
101aee2cecaSBarry Smith {
102330cf3c9SBarry Smith   size_t         i;
103aee2cecaSBarry Smith   char           c;
1043fc1eb6aSBarry Smith   PetscMPIInt    rank,nm;
105aee2cecaSBarry Smith   PetscErrorCode ierr;
106aee2cecaSBarry Smith 
107aee2cecaSBarry Smith   PetscFunctionBegin;
108aee2cecaSBarry Smith   ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr);
109aee2cecaSBarry Smith   if (!rank) {
110aee2cecaSBarry Smith     c = (char) getchar();
111aee2cecaSBarry Smith     i = 0;
112aee2cecaSBarry Smith     while ( c != '\n' && i < n-1) {
113aee2cecaSBarry Smith       str[i++] = c;
114aee2cecaSBarry Smith       c = (char) getchar();
115aee2cecaSBarry Smith     }
116aee2cecaSBarry Smith     str[i] = 0;
117aee2cecaSBarry Smith   }
1183fc1eb6aSBarry Smith   nm   = PetscMPIIntCast(n);
1193fc1eb6aSBarry Smith   ierr = MPI_Bcast(str,nm,MPI_CHAR,0,comm);CHKERRQ(ierr);
120aee2cecaSBarry Smith   PetscFunctionReturn(0);
121aee2cecaSBarry Smith }
122aee2cecaSBarry Smith 
123aee2cecaSBarry Smith #undef __FUNCT__
124aee2cecaSBarry Smith #define __FUNCT__ "PetscOptionsGetFromTextInput"
125aee2cecaSBarry Smith /*
1263cc1e11dSBarry Smith     PetscOptionsGetFromTextInput - Presents all the PETSc Options processed by the program so the user may change them at runtime
127aee2cecaSBarry Smith 
128aee2cecaSBarry Smith     Notes: this isn't really practical, it is just to demonstrate the principle
129aee2cecaSBarry Smith 
130aee2cecaSBarry Smith     Bugs:
131aee2cecaSBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
1323cc1e11dSBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
133aee2cecaSBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
134aee2cecaSBarry Smith 
1353cc1e11dSBarry Smith     Developer Notes: Normally the GUI that presents the options the user and retrieves the values would be running in a different
1363cc1e11dSBarry Smith      address space and communicating with the PETSc program
1373cc1e11dSBarry Smith 
138aee2cecaSBarry Smith */
139aee2cecaSBarry Smith PetscErrorCode PetscOptionsGetFromTextInput()
1406356e834SBarry Smith {
1416356e834SBarry Smith   PetscErrorCode ierr;
1426356e834SBarry Smith   PetscOptions   next = PetscOptionsObject.next;
1436356e834SBarry Smith   char           str[512];
144a4404d99SBarry Smith   PetscInt       id;
145a4404d99SBarry Smith   PetscReal      ir,*valr;
146330cf3c9SBarry Smith   PetscInt       *vald;
147330cf3c9SBarry Smith   size_t         i;
1486356e834SBarry Smith 
149e26ddf31SBarry Smith   ierr = (*PetscPrintf)(PETSC_COMM_WORLD,"%s -------------------------------------------------\n",PetscOptionsObject.title);CHKERRQ(ierr);
1506356e834SBarry Smith   while (next) {
1516356e834SBarry Smith     switch (next->type) {
1526356e834SBarry Smith       case OPTION_HEAD:
1536356e834SBarry Smith         break;
154e26ddf31SBarry Smith       case OPTION_INT_ARRAY:
155e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
156e26ddf31SBarry Smith         vald = (PetscInt*) next->data;
157e26ddf31SBarry Smith         for (i=0; i<next->arraylength; i++) {
158e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,"%d",vald[i]);CHKERRQ(ierr);
159e26ddf31SBarry Smith           if (i < next->arraylength-1) {
160e26ddf31SBarry Smith             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
161e26ddf31SBarry Smith           }
162e26ddf31SBarry Smith         }
163e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
164e26ddf31SBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
165e26ddf31SBarry Smith         if (str[0]) {
166e26ddf31SBarry Smith           PetscToken token;
167e26ddf31SBarry Smith           PetscInt   n=0,nmax = next->arraylength,*dvalue = (PetscInt*)next->data,start,end;
168e26ddf31SBarry Smith           size_t     len;
169e26ddf31SBarry Smith           char*      value;
170e26ddf31SBarry Smith           PetscTruth foundrange;
171e26ddf31SBarry Smith 
172e26ddf31SBarry Smith           next->set = PETSC_TRUE;
173e26ddf31SBarry Smith           value = str;
174e26ddf31SBarry Smith 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
175e26ddf31SBarry Smith 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
176e26ddf31SBarry Smith 	  while (n < nmax) {
177e26ddf31SBarry Smith 	    if (!value) break;
178e26ddf31SBarry Smith 
179e26ddf31SBarry Smith 	    /* look for form  d-D where d and D are integers */
180e26ddf31SBarry Smith 	    foundrange = PETSC_FALSE;
181e26ddf31SBarry Smith 	    ierr      = PetscStrlen(value,&len);CHKERRQ(ierr);
182e26ddf31SBarry Smith 	    if (value[0] == '-') i=2;
183e26ddf31SBarry Smith 	    else i=1;
184330cf3c9SBarry Smith 	    for (;i<len; i++) {
185e26ddf31SBarry Smith 	      if (value[i] == '-') {
186e32f2f54SBarry Smith 		if (i == len-1) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_USER,"Error in %D-th array entry %s\n",n,value);
187e26ddf31SBarry Smith 		value[i] = 0;
188e26ddf31SBarry Smith 		ierr     = PetscOptionsAtoi(value,&start);CHKERRQ(ierr);
189e26ddf31SBarry Smith 		ierr     = PetscOptionsAtoi(value+i+1,&end);CHKERRQ(ierr);
190e32f2f54SBarry 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);
191e32f2f54SBarry 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);
192e26ddf31SBarry Smith 		for (;start<end; start++) {
193e26ddf31SBarry Smith 		  *dvalue = start; dvalue++;n++;
194e26ddf31SBarry Smith 		}
195e26ddf31SBarry Smith 		foundrange = PETSC_TRUE;
196e26ddf31SBarry Smith 		break;
197e26ddf31SBarry Smith 	      }
198e26ddf31SBarry Smith 	    }
199e26ddf31SBarry Smith 	    if (!foundrange) {
200e26ddf31SBarry Smith 	      ierr      = PetscOptionsAtoi(value,dvalue);CHKERRQ(ierr);
201e26ddf31SBarry Smith 	      dvalue++;
202e26ddf31SBarry Smith 	      n++;
203e26ddf31SBarry Smith 	    }
204e26ddf31SBarry Smith 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
205e26ddf31SBarry Smith 	  }
206e26ddf31SBarry Smith 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
207e26ddf31SBarry Smith         }
208e26ddf31SBarry Smith         break;
209e26ddf31SBarry Smith       case OPTION_REAL_ARRAY:
210e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,"-%s%s <",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",next->option+1);CHKERRQ(ierr);
211e26ddf31SBarry Smith         valr = (PetscReal*) next->data;
212e26ddf31SBarry Smith         for (i=0; i<next->arraylength; i++) {
213e26ddf31SBarry Smith           ierr = PetscPrintf(PETSC_COMM_WORLD,"%g",valr[i]);CHKERRQ(ierr);
214e26ddf31SBarry Smith           if (i < next->arraylength-1) {
215e26ddf31SBarry Smith             ierr = PetscPrintf(PETSC_COMM_WORLD,",");CHKERRQ(ierr);
216e26ddf31SBarry Smith           }
217e26ddf31SBarry Smith         }
218e26ddf31SBarry Smith         ierr = PetscPrintf(PETSC_COMM_WORLD,">: %s (%s)",next->text,next->man);CHKERRQ(ierr);
219e26ddf31SBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
220e26ddf31SBarry Smith         if (str[0]) {
221e26ddf31SBarry Smith           PetscToken token;
222e26ddf31SBarry Smith           PetscInt   n=0,nmax = next->arraylength;
223e26ddf31SBarry Smith           PetscReal   *dvalue = (PetscReal*)next->data;
224e26ddf31SBarry Smith           char*      value;
225e26ddf31SBarry Smith 
226e26ddf31SBarry Smith           next->set = PETSC_TRUE;
227e26ddf31SBarry Smith           value = str;
228e26ddf31SBarry Smith 	  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
229e26ddf31SBarry Smith 	  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
230e26ddf31SBarry Smith 	  while (n < nmax) {
231e26ddf31SBarry Smith 	    if (!value) break;
232e26ddf31SBarry Smith             ierr      = PetscOptionsAtod(value,dvalue);CHKERRQ(ierr);
233e26ddf31SBarry Smith 	    dvalue++;
234e26ddf31SBarry Smith 	    n++;
235e26ddf31SBarry Smith 	    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
236e26ddf31SBarry Smith 	  }
237e26ddf31SBarry Smith 	  ierr = PetscTokenDestroy(token);CHKERRQ(ierr);
238e26ddf31SBarry Smith         }
239e26ddf31SBarry Smith         break;
2406356e834SBarry Smith       case OPTION_INT:
241e26ddf31SBarry 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);
2423fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2433fc1eb6aSBarry Smith         if (str[0]) {
244c272547aSJed Brown #if defined(PETSC_USE_64BIT_INDICES)
245c272547aSJed Brown           sscanf(str,"%lld",&id);
246c272547aSJed Brown #else
247aee2cecaSBarry Smith           sscanf(str,"%d",&id);
248c272547aSJed Brown #endif
249aee2cecaSBarry Smith           next->set = PETSC_TRUE;
250aee2cecaSBarry Smith           *((PetscInt*)next->data) = id;
251aee2cecaSBarry Smith         }
252aee2cecaSBarry Smith         break;
253aee2cecaSBarry Smith       case OPTION_REAL:
254e26ddf31SBarry 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);
2553fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2563fc1eb6aSBarry Smith         if (str[0]) {
257a4404d99SBarry Smith #if defined(PETSC_USE_SCALAR_SINGLE)
258a4404d99SBarry Smith           sscanf(str,"%e",&ir);
259a4404d99SBarry Smith #else
260aee2cecaSBarry Smith           sscanf(str,"%le",&ir);
261a4404d99SBarry Smith #endif
262aee2cecaSBarry Smith           next->set = PETSC_TRUE;
263aee2cecaSBarry Smith           *((PetscReal*)next->data) = ir;
264aee2cecaSBarry Smith         }
265aee2cecaSBarry Smith         break;
266aee2cecaSBarry Smith       case OPTION_LOGICAL:
267aee2cecaSBarry Smith       case OPTION_STRING:
268e26ddf31SBarry 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);
2693fc1eb6aSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2703fc1eb6aSBarry Smith         if (str[0]) {
271aee2cecaSBarry Smith           next->set = PETSC_TRUE;
272330cf3c9SBarry Smith           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
2736356e834SBarry Smith         }
2746356e834SBarry Smith         break;
2753cc1e11dSBarry Smith       case OPTION_LIST:
2763cc1e11dSBarry Smith         ierr = PetscFListPrintTypes(PETSC_COMM_WORLD,stdout,PetscOptionsObject.prefix,next->option,next->text,next->man,next->flist,(char*)next->data);CHKERRQ(ierr);
2773cc1e11dSBarry Smith         ierr = PetscScanString(PETSC_COMM_WORLD,512,str);CHKERRQ(ierr);
2783cc1e11dSBarry Smith         if (str[0]) {
2793cc1e11dSBarry Smith 	  PetscOptionsObject.changedmethod = PETSC_TRUE;
2803cc1e11dSBarry Smith           next->set = PETSC_TRUE;
281330cf3c9SBarry Smith           ierr = PetscStrcpy((char*)next->data,str);CHKERRQ(ierr);
2823cc1e11dSBarry Smith         }
2833cc1e11dSBarry Smith         break;
284b432afdaSMatthew Knepley     default:
285b432afdaSMatthew Knepley       break;
2866356e834SBarry Smith     }
2876356e834SBarry Smith     next = next->next;
2886356e834SBarry Smith   }
2896356e834SBarry Smith   PetscFunctionReturn(0);
2906356e834SBarry Smith }
2916356e834SBarry Smith 
292b3506946SBarry Smith #if defined(PETSC_HAVE_AMS)
293*1ae3d29cSBarry Smith #define CHKERRAMS(err)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"AMS Error: %s",msg);}
294*1ae3d29cSBarry Smith #define CHKERRAMSFieldName(err,fn)  if (err) {char *msg; AMS_Explain_error((err), &(msg)); SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Fieldname %s, AMS Error: %s",fn,msg);}
295b3506946SBarry Smith #undef __FUNCT__
296b3506946SBarry Smith #define __FUNCT__ "PetscOptionsGetFromAMSInput"
297b3506946SBarry Smith /*
298b3506946SBarry Smith     PetscOptionsGetFromAMSInput - Presents all the PETSc Options processed by the program so the user may change them at runtime using the AMS
299b3506946SBarry Smith 
300b3506946SBarry Smith     Bugs:
301b3506946SBarry Smith +    All processes must traverse through the exact same set of option queries do to the call to PetscScanString()
302b3506946SBarry Smith .    Internal strings have arbitrary length and string copies are not checked that they fit into string space
303b3506946SBarry Smith -    Only works for PetscInt == int, PetscReal == double etc
304b3506946SBarry Smith 
305b3506946SBarry Smith 
306b3506946SBarry Smith */
307b3506946SBarry Smith PetscErrorCode PetscOptionsGetFromAMSInput()
308b3506946SBarry Smith {
309b3506946SBarry Smith   PetscErrorCode ierr;
310b3506946SBarry Smith   PetscOptions   next = PetscOptionsObject.next;
3119f32e415SBarry Smith   static int     count = 0,mancount = 0;
312b3506946SBarry Smith   char           options[16];
313b3506946SBarry Smith   AMS_Comm       acomm = -1;
314b3506946SBarry Smith   AMS_Memory     amem = -1;
315b3506946SBarry Smith   PetscTruth     changedmethod = PETSC_FALSE;
3169f32e415SBarry Smith   char           manname[16];
317b3506946SBarry Smith 
318b3506946SBarry Smith   /* the next line is a bug, this will only work if all processors are here, the comm passed in is ignored!!! */
319b3506946SBarry Smith   ierr = PetscViewerAMSGetAMSComm(PETSC_VIEWER_AMS_(PETSC_COMM_WORLD),&acomm);CHKERRQ(ierr);
320b3506946SBarry Smith   sprintf(options,"Options_%d",count++);
321*1ae3d29cSBarry Smith   ierr = AMS_Memory_create(acomm,options,&amem);CHKERRAMS(ierr);
322*1ae3d29cSBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
3231bc75a8dSBarry Smith   PetscOptionsObject.pprefix = PetscOptionsObject.prefix; /* AMS will change this, so cannot pass prefix directly */
3241bc75a8dSBarry Smith 
325*1ae3d29cSBarry Smith   ierr = AMS_Memory_add_field(amem,PetscOptionsObject.title,&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,PetscOptionsObject.title);
326*1ae3d29cSBarry Smith   //  ierr = AMS_Memory_add_field(amem,"mansec",&PetscOptionsObject.pprefix,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMS(ierr);
327*1ae3d29cSBarry Smith   ierr = AMS_Memory_add_field(amem,"ChangedMethod",&changedmethod,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,"ChangedMethod");
328b3506946SBarry Smith 
329b3506946SBarry Smith   while (next) {
330*1ae3d29cSBarry Smith     ierr = AMS_Memory_add_field(amem,next->option,&next->set,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->option);
3311bc75a8dSBarry Smith     ierr =  PetscMalloc(sizeof(char*),&next->pman);CHKERRQ(ierr);
3321bc75a8dSBarry Smith     *(char **)next->pman = next->man;
3339f32e415SBarry Smith     sprintf(manname,"man_%d",mancount++);
334*1ae3d29cSBarry Smith     ierr = AMS_Memory_add_field(amem,manname,next->pman,1,AMS_STRING,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,manname);
3359f32e415SBarry Smith 
336b3506946SBarry Smith     switch (next->type) {
337b3506946SBarry Smith       case OPTION_HEAD:
338b3506946SBarry Smith         break;
339b3506946SBarry Smith       case OPTION_INT_ARRAY:
340*1ae3d29cSBarry Smith         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
341b3506946SBarry Smith         break;
342b3506946SBarry Smith       case OPTION_REAL_ARRAY:
343*1ae3d29cSBarry Smith         ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
344b3506946SBarry Smith         break;
345b3506946SBarry Smith       case OPTION_INT:
346*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_INT,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
347b3506946SBarry Smith         break;
348b3506946SBarry Smith       case OPTION_REAL:
349*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_DOUBLE,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
350b3506946SBarry Smith         break;
351b3506946SBarry Smith       case OPTION_LOGICAL:
352*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
353*1ae3d29cSBarry Smith         break;
354*1ae3d29cSBarry Smith       case OPTION_LOGICAL_ARRAY:
355*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_BOOLEAN,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
35671f08665SBarry Smith         break;
357b3506946SBarry Smith       case OPTION_STRING:
358*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
359*1ae3d29cSBarry Smith         break;
360*1ae3d29cSBarry Smith       case OPTION_STRING_ARRAY:
361*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->data,next->arraylength,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
362b3506946SBarry Smith         break;
363b3506946SBarry Smith       case OPTION_LIST:
36471f08665SBarry Smith         {PetscInt  ntext;
36571f08665SBarry Smith         char       ldefault[128];
36671f08665SBarry Smith 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
36771f08665SBarry Smith 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
368*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
36971f08665SBarry Smith 	ierr = PetscFListGet(next->flist,(char***)&next->edata,&ntext);CHKERRQ(ierr);
370*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
371*1ae3d29cSBarry Smith         break;}
372*1ae3d29cSBarry Smith       case OPTION_ELIST:
373*1ae3d29cSBarry Smith         {PetscInt  ntext;
374*1ae3d29cSBarry Smith         char       ldefault[128];
375*1ae3d29cSBarry Smith 	ierr = PetscStrcpy(ldefault,"DEFAULT:");CHKERRQ(ierr);
376*1ae3d29cSBarry Smith 	ierr = PetscStrcat(ldefault,next->text);CHKERRQ(ierr);
377*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,ldefault,next->data,1,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,ldefault);
378*1ae3d29cSBarry Smith 	ierr = PetscMalloc((ntext+1)*sizeof(char**),&next->edata);CHKERRQ(ierr);
379*1ae3d29cSBarry Smith         ierr = PetscMemcpy(next->edata,next->list,ntext*sizeof(char*));CHKERRQ(ierr);
380*1ae3d29cSBarry Smith 	ierr = AMS_Memory_add_field(amem,next->text,next->edata,ntext,AMS_STRING,AMS_WRITE,AMS_COMMON,AMS_REDUCT_UNDEF);CHKERRAMSFieldName(ierr,next->text);
38171f08665SBarry Smith         break;}
382b3506946SBarry Smith     default:
383b3506946SBarry Smith       break;
384b3506946SBarry Smith     }
385b3506946SBarry Smith     next = next->next;
386b3506946SBarry Smith   }
387b3506946SBarry Smith 
388*1ae3d29cSBarry Smith   ierr = AMS_Memory_publish(amem);CHKERRAMS(ierr);
389*1ae3d29cSBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
390b3506946SBarry Smith   /* wait until accessor has unlocked the memory */
391*1ae3d29cSBarry Smith   ierr = AMS_Memory_lock(amem,0);CHKERRAMS(ierr);
392*1ae3d29cSBarry Smith   ierr = AMS_Memory_take_access(amem);CHKERRAMS(ierr);
393b3506946SBarry Smith 
394b3506946SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
395b3506946SBarry Smith   if (changedmethod) PetscOptionsPublishCount = -2;
396b3506946SBarry Smith 
397*1ae3d29cSBarry Smith   ierr = AMS_Memory_grant_access(amem);CHKERRAMS(ierr);
398*1ae3d29cSBarry Smith   ierr = AMS_Memory_destroy(amem);CHKERRAMS(ierr);
399b3506946SBarry Smith   PetscFunctionReturn(0);
400b3506946SBarry Smith }
401b3506946SBarry Smith #endif
402b3506946SBarry Smith 
4036356e834SBarry Smith #undef __FUNCT__
40453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnd_Private"
40553acd3b1SBarry Smith PetscErrorCode PetscOptionsEnd_Private(void)
40653acd3b1SBarry Smith {
40753acd3b1SBarry Smith   PetscErrorCode ierr;
4086356e834SBarry Smith   PetscOptions   last;
4096356e834SBarry Smith   char           option[256],value[1024],tmp[32];
410330cf3c9SBarry Smith   size_t         j;
41153acd3b1SBarry Smith 
41253acd3b1SBarry Smith   PetscFunctionBegin;
4136356e834SBarry Smith 
4141bc75a8dSBarry Smith   CHKMEMQ;
415aee2cecaSBarry Smith   if (PetscOptionsObject.next) {
416b3506946SBarry Smith     if (!PetscOptionsPublishCount) {
417b3506946SBarry Smith #if defined(PETSC_HAVE_AMS)
41871f08665SBarry Smith       ierr = PetscOptionsGetFromAMSInput();CHKERRQ(ierr);
419b3506946SBarry Smith #else
42071f08665SBarry Smith       ierr = PetscOptionsGetFromTextInput();CHKERRQ(ierr);
421b3506946SBarry Smith #endif
422aee2cecaSBarry Smith     }
423aee2cecaSBarry Smith   }
4246356e834SBarry Smith 
425503cfb0cSBarry Smith   ierr = PetscFree(PetscOptionsObject.title);CHKERRQ(ierr); PetscOptionsObject.title  = 0;
426503cfb0cSBarry Smith   ierr = PetscFree(PetscOptionsObject.prefix);CHKERRQ(ierr); PetscOptionsObject.prefix = 0;
4276356e834SBarry Smith 
4286356e834SBarry Smith   /* reset counter to -2; this updates the screen with the new options for the selected method */
4296356e834SBarry Smith   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2;
43061b37b28SSatish Balay   /* reset alreadyprinted flag */
43161b37b28SSatish Balay   PetscOptionsObject.alreadyprinted = PETSC_FALSE;
4326356e834SBarry Smith 
4336356e834SBarry Smith   while (PetscOptionsObject.next) {
4346356e834SBarry Smith     if (PetscOptionsObject.next->set) {
4356356e834SBarry Smith       if (PetscOptionsObject.prefix) {
4366356e834SBarry Smith         ierr = PetscStrcpy(option,"-");CHKERRQ(ierr);
4376356e834SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject.prefix);CHKERRQ(ierr);
4386356e834SBarry Smith         ierr = PetscStrcat(option,PetscOptionsObject.next->option+1);CHKERRQ(ierr);
4396356e834SBarry Smith       } else {
4406356e834SBarry Smith         ierr = PetscStrcpy(option,PetscOptionsObject.next->option);CHKERRQ(ierr);
4416356e834SBarry Smith       }
4426356e834SBarry Smith 
4436356e834SBarry Smith       switch (PetscOptionsObject.next->type) {
4446356e834SBarry Smith         case OPTION_HEAD:
4456356e834SBarry Smith           break;
446e26ddf31SBarry Smith         case OPTION_INT_ARRAY:
447e26ddf31SBarry Smith           sprintf(value,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[0]);
448e26ddf31SBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
449e26ddf31SBarry Smith             sprintf(tmp,"%d",(int)((PetscInt*)PetscOptionsObject.next->data)[j]);
450e26ddf31SBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
451e26ddf31SBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
452e26ddf31SBarry Smith           }
453e26ddf31SBarry Smith           break;
4546356e834SBarry Smith         case OPTION_INT:
4557a72a596SBarry Smith           sprintf(value,"%d",(int) *(PetscInt*)PetscOptionsObject.next->data);
4566356e834SBarry Smith           break;
4576356e834SBarry Smith         case OPTION_REAL:
4587a72a596SBarry Smith           sprintf(value,"%g",(double) *(PetscReal*)PetscOptionsObject.next->data);
4596356e834SBarry Smith           break;
4606356e834SBarry Smith         case OPTION_REAL_ARRAY:
4617a72a596SBarry Smith           sprintf(value,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[0]);
4626356e834SBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
4637a72a596SBarry Smith             sprintf(tmp,"%g",(double)((PetscReal*)PetscOptionsObject.next->data)[j]);
4646356e834SBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
4656356e834SBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
4666356e834SBarry Smith           }
4676356e834SBarry Smith           break;
4686356e834SBarry Smith         case OPTION_LOGICAL:
46971f08665SBarry Smith           sprintf(value,"%d",*(int*)PetscOptionsObject.next->data);
4706356e834SBarry Smith           break;
471*1ae3d29cSBarry Smith       case OPTION_LOGICAL_ARRAY:
472*1ae3d29cSBarry Smith           sprintf(value,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[0]);
473*1ae3d29cSBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
474*1ae3d29cSBarry Smith             sprintf(tmp,"%d",(int)((PetscTruth*)PetscOptionsObject.next->data)[j]);
475*1ae3d29cSBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
476*1ae3d29cSBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
477*1ae3d29cSBarry Smith           }
478*1ae3d29cSBarry Smith           break;
4796356e834SBarry Smith         case OPTION_LIST:
480*1ae3d29cSBarry Smith         case OPTION_ELIST:
48171f08665SBarry Smith           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
4826356e834SBarry Smith           break;
483*1ae3d29cSBarry Smith         case OPTION_STRING:
48471f08665SBarry Smith           ierr = PetscStrcpy(value,*(char**)PetscOptionsObject.next->data);CHKERRQ(ierr);
485*1ae3d29cSBarry Smith         case OPTION_STRING_ARRAY:
486*1ae3d29cSBarry Smith           sprintf(value,"%s",((char**)PetscOptionsObject.next->data)[0]);
487*1ae3d29cSBarry Smith           for (j=1; j<PetscOptionsObject.next->arraylength; j++) {
488*1ae3d29cSBarry Smith             sprintf(tmp,"%s",((char**)PetscOptionsObject.next->data)[j]);
489*1ae3d29cSBarry Smith             ierr = PetscStrcat(value,",");CHKERRQ(ierr);
490*1ae3d29cSBarry Smith             ierr = PetscStrcat(value,tmp);CHKERRQ(ierr);
491*1ae3d29cSBarry Smith           }
4926356e834SBarry Smith           break;
4936356e834SBarry Smith       }
4946356e834SBarry Smith       ierr = PetscOptionsSetValue(option,value);CHKERRQ(ierr);
4956356e834SBarry Smith     }
496503cfb0cSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->text);CHKERRQ(ierr);
497503cfb0cSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->option);CHKERRQ(ierr);
4986356e834SBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->man);CHKERRQ(ierr);
49905b42c5fSBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->data);CHKERRQ(ierr);
50071f08665SBarry Smith     ierr   = PetscFree(PetscOptionsObject.next->edata);CHKERRQ(ierr);
5016356e834SBarry Smith     last                    = PetscOptionsObject.next;
5026356e834SBarry Smith     PetscOptionsObject.next = PetscOptionsObject.next->next;
5036356e834SBarry Smith     ierr                    = PetscFree(last);CHKERRQ(ierr);
5041bc75a8dSBarry Smith     CHKMEMQ;
5056356e834SBarry Smith   }
5061bc75a8dSBarry Smith   CHKMEMQ;
5076356e834SBarry Smith   PetscOptionsObject.next = 0;
50853acd3b1SBarry Smith   PetscFunctionReturn(0);
50953acd3b1SBarry Smith }
51053acd3b1SBarry Smith 
51153acd3b1SBarry Smith #undef __FUNCT__
51253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEnum"
51353acd3b1SBarry Smith /*@C
51453acd3b1SBarry Smith    PetscOptionsEnum - Gets the enum value for a particular option in the database.
51553acd3b1SBarry Smith 
51653acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
51753acd3b1SBarry Smith 
51853acd3b1SBarry Smith    Input Parameters:
51953acd3b1SBarry Smith +  opt - option name
52053acd3b1SBarry Smith .  text - short string that describes the option
52153acd3b1SBarry Smith .  man - manual page with additional information on option
52253acd3b1SBarry Smith .  list - array containing the list of choices, followed by the enum name, followed by the enum prefix, followed by a null
52353acd3b1SBarry Smith -  defaultv - the default (current) value
52453acd3b1SBarry Smith 
52553acd3b1SBarry Smith    Output Parameter:
52653acd3b1SBarry Smith +  value - the  value to return
52753acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
52853acd3b1SBarry Smith 
52953acd3b1SBarry Smith    Level: beginner
53053acd3b1SBarry Smith 
53153acd3b1SBarry Smith    Concepts: options database
53253acd3b1SBarry Smith 
53353acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
53453acd3b1SBarry Smith 
53553acd3b1SBarry Smith           list is usually something like PCASMTypes or some other predefined list of enum names
53653acd3b1SBarry Smith 
53753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
53853acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
53953acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
54053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
54153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
54253acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
54353acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
54453acd3b1SBarry Smith @*/
5452ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEnum(const char opt[],const char text[],const char man[],const char *const*list,PetscEnum defaultv,PetscEnum *value,PetscTruth *set)
54653acd3b1SBarry Smith {
54753acd3b1SBarry Smith   PetscErrorCode ierr;
54853acd3b1SBarry Smith   PetscInt       ntext = 0;
549aa5bb8c0SSatish Balay   PetscInt       tval;
550aa5bb8c0SSatish Balay   PetscTruth     tflg;
55153acd3b1SBarry Smith 
55253acd3b1SBarry Smith   PetscFunctionBegin;
55353acd3b1SBarry Smith   while (list[ntext++]) {
554e32f2f54SBarry Smith     if (ntext > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
55553acd3b1SBarry Smith   }
556e32f2f54SBarry Smith   if (ntext < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
55753acd3b1SBarry Smith   ntext -= 3;
558aa5bb8c0SSatish Balay   ierr = PetscOptionsEList(opt,text,man,list,ntext,list[defaultv],&tval,&tflg);CHKERRQ(ierr);
559aa5bb8c0SSatish Balay   /* with PETSC_USE_64BIT_INDICES sizeof(PetscInt) != sizeof(PetscEnum) */
560aa5bb8c0SSatish Balay   if (tflg) *value = (PetscEnum)tval;
561aa5bb8c0SSatish Balay   if (set)  *set   = tflg;
56253acd3b1SBarry Smith   PetscFunctionReturn(0);
56353acd3b1SBarry Smith }
56453acd3b1SBarry Smith 
56553acd3b1SBarry Smith /* -------------------------------------------------------------------------------------------------------------*/
56653acd3b1SBarry Smith #undef __FUNCT__
56753acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsInt"
56853acd3b1SBarry Smith /*@C
56953acd3b1SBarry Smith    PetscOptionsInt - Gets the integer value for a particular option in the database.
57053acd3b1SBarry Smith 
57153acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
57253acd3b1SBarry Smith 
57353acd3b1SBarry Smith    Input Parameters:
57453acd3b1SBarry Smith +  opt - option name
57553acd3b1SBarry Smith .  text - short string that describes the option
57653acd3b1SBarry Smith .  man - manual page with additional information on option
57753acd3b1SBarry Smith -  defaultv - the default (current) value
57853acd3b1SBarry Smith 
57953acd3b1SBarry Smith    Output Parameter:
58053acd3b1SBarry Smith +  value - the integer value to return
58153acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
58253acd3b1SBarry Smith 
58353acd3b1SBarry Smith    Level: beginner
58453acd3b1SBarry Smith 
58553acd3b1SBarry Smith    Concepts: options database^has int
58653acd3b1SBarry Smith 
58753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
58853acd3b1SBarry Smith 
58953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
59053acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
59153acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
59253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
59353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
59453acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
59553acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
59653acd3b1SBarry Smith @*/
59753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsInt(const char opt[],const char text[],const char man[],PetscInt defaultv,PetscInt *value,PetscTruth *set)
59853acd3b1SBarry Smith {
59953acd3b1SBarry Smith   PetscErrorCode ierr;
6006356e834SBarry Smith   PetscOptions   amsopt;
60153acd3b1SBarry Smith 
60253acd3b1SBarry Smith   PetscFunctionBegin;
603b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
6046356e834SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT,&amsopt);CHKERRQ(ierr);
6056356e834SBarry Smith     ierr = PetscMalloc(sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
6066356e834SBarry Smith     *(PetscInt*)amsopt->data = defaultv;
607af6d86caSBarry Smith   }
60853acd3b1SBarry Smith   ierr = PetscOptionsGetInt(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
60961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
61053acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
61153acd3b1SBarry Smith   }
61253acd3b1SBarry Smith   PetscFunctionReturn(0);
61353acd3b1SBarry Smith }
61453acd3b1SBarry Smith 
61553acd3b1SBarry Smith #undef __FUNCT__
61653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsString"
61753acd3b1SBarry Smith /*@C
61853acd3b1SBarry Smith    PetscOptionsString - Gets the string value for a particular option in the database.
61953acd3b1SBarry Smith 
62053acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
62153acd3b1SBarry Smith 
62253acd3b1SBarry Smith    Input Parameters:
62353acd3b1SBarry Smith +  opt - option name
62453acd3b1SBarry Smith .  text - short string that describes the option
62553acd3b1SBarry Smith .  man - manual page with additional information on option
62653acd3b1SBarry Smith -  defaultv - the default (current) value
62753acd3b1SBarry Smith 
62853acd3b1SBarry Smith    Output Parameter:
62953acd3b1SBarry Smith +  value - the value to return
63053acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
63153acd3b1SBarry Smith 
63253acd3b1SBarry Smith    Level: beginner
63353acd3b1SBarry Smith 
63453acd3b1SBarry Smith    Concepts: options database^has int
63553acd3b1SBarry Smith 
63653acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
63753acd3b1SBarry Smith 
63853acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
63953acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
64071f08665SBarry Smith           PetscOptionsInt(), PetscOptionsReal(), PetscOptionsTruth(),
64153acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
64253acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
64353acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
64453acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
64553acd3b1SBarry Smith @*/
64653acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsString(const char opt[],const char text[],const char man[],const char defaultv[],char value[],size_t len,PetscTruth *set)
64753acd3b1SBarry Smith {
64853acd3b1SBarry Smith   PetscErrorCode ierr;
649aee2cecaSBarry Smith   PetscOptions   amsopt;
65053acd3b1SBarry Smith 
65153acd3b1SBarry Smith   PetscFunctionBegin;
652b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
653aee2cecaSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING,&amsopt);CHKERRQ(ierr);
65471f08665SBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
65571f08665SBarry Smith     *(const char**)amsopt->data = defaultv;
656af6d86caSBarry Smith   }
65753acd3b1SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
65861b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
65953acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
66053acd3b1SBarry Smith   }
66153acd3b1SBarry Smith   PetscFunctionReturn(0);
66253acd3b1SBarry Smith }
66353acd3b1SBarry Smith 
66453acd3b1SBarry Smith #undef __FUNCT__
66553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsReal"
66653acd3b1SBarry Smith /*@C
66753acd3b1SBarry Smith    PetscOptionsReal - Gets the PetscReal value for a particular option in the database.
66853acd3b1SBarry Smith 
66953acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
67053acd3b1SBarry Smith 
67153acd3b1SBarry Smith    Input Parameters:
67253acd3b1SBarry Smith +  opt - option name
67353acd3b1SBarry Smith .  text - short string that describes the option
67453acd3b1SBarry Smith .  man - manual page with additional information on option
67553acd3b1SBarry Smith -  defaultv - the default (current) value
67653acd3b1SBarry Smith 
67753acd3b1SBarry Smith    Output Parameter:
67853acd3b1SBarry Smith +  value - the value to return
67953acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
68053acd3b1SBarry Smith 
68153acd3b1SBarry Smith    Level: beginner
68253acd3b1SBarry Smith 
68353acd3b1SBarry Smith    Concepts: options database^has int
68453acd3b1SBarry Smith 
68553acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
68653acd3b1SBarry Smith 
68753acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
68853acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
68953acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
69053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
69153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
69253acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
69353acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
69453acd3b1SBarry Smith @*/
69553acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsReal(const char opt[],const char text[],const char man[],PetscReal defaultv,PetscReal *value,PetscTruth *set)
69653acd3b1SBarry Smith {
69753acd3b1SBarry Smith   PetscErrorCode ierr;
698538aa990SBarry Smith   PetscOptions   amsopt;
69953acd3b1SBarry Smith 
70053acd3b1SBarry Smith   PetscFunctionBegin;
701b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
702538aa990SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL,&amsopt);CHKERRQ(ierr);
703538aa990SBarry Smith     ierr = PetscMalloc(sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
704538aa990SBarry Smith     *(PetscReal*)amsopt->data = defaultv;
705538aa990SBarry Smith   }
70653acd3b1SBarry Smith   ierr = PetscOptionsGetReal(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
70761b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
708a83599f4SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv,text,man);CHKERRQ(ierr);
70953acd3b1SBarry Smith   }
71053acd3b1SBarry Smith   PetscFunctionReturn(0);
71153acd3b1SBarry Smith }
71253acd3b1SBarry Smith 
71353acd3b1SBarry Smith #undef __FUNCT__
71453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsScalar"
71553acd3b1SBarry Smith /*@C
71653acd3b1SBarry Smith    PetscOptionsScalar - Gets the scalar value for a particular option in the database.
71753acd3b1SBarry Smith 
71853acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
71953acd3b1SBarry Smith 
72053acd3b1SBarry Smith    Input Parameters:
72153acd3b1SBarry Smith +  opt - option name
72253acd3b1SBarry Smith .  text - short string that describes the option
72353acd3b1SBarry Smith .  man - manual page with additional information on option
72453acd3b1SBarry Smith -  defaultv - the default (current) value
72553acd3b1SBarry Smith 
72653acd3b1SBarry Smith    Output Parameter:
72753acd3b1SBarry Smith +  value - the value to return
72853acd3b1SBarry Smith -  flg - PETSC_TRUE if found, else PETSC_FALSE
72953acd3b1SBarry Smith 
73053acd3b1SBarry Smith    Level: beginner
73153acd3b1SBarry Smith 
73253acd3b1SBarry Smith    Concepts: options database^has int
73353acd3b1SBarry Smith 
73453acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
73553acd3b1SBarry Smith 
73653acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
73753acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
73853acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
73953acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
74053acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
74153acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
74253acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
74353acd3b1SBarry Smith @*/
74453acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsScalar(const char opt[],const char text[],const char man[],PetscScalar defaultv,PetscScalar *value,PetscTruth *set)
74553acd3b1SBarry Smith {
74653acd3b1SBarry Smith   PetscErrorCode ierr;
74753acd3b1SBarry Smith 
74853acd3b1SBarry Smith   PetscFunctionBegin;
74953acd3b1SBarry Smith #if !defined(PETSC_USE_COMPLEX)
75053acd3b1SBarry Smith   ierr = PetscOptionsReal(opt,text,man,defaultv,value,set);CHKERRQ(ierr);
75153acd3b1SBarry Smith #else
75253acd3b1SBarry Smith   ierr = PetscOptionsGetScalar(PetscOptionsObject.prefix,opt,value,set);CHKERRQ(ierr);
75353acd3b1SBarry Smith #endif
75453acd3b1SBarry Smith   PetscFunctionReturn(0);
75553acd3b1SBarry Smith }
75653acd3b1SBarry Smith 
75753acd3b1SBarry Smith #undef __FUNCT__
75853acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsName"
75953acd3b1SBarry Smith /*@C
76090d69ab7SBarry 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
76190d69ab7SBarry Smith                       its value is set to false.
76253acd3b1SBarry Smith 
76353acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
76453acd3b1SBarry Smith 
76553acd3b1SBarry Smith    Input Parameters:
76653acd3b1SBarry Smith +  opt - option name
76753acd3b1SBarry Smith .  text - short string that describes the option
76853acd3b1SBarry Smith -  man - manual page with additional information on option
76953acd3b1SBarry Smith 
77053acd3b1SBarry Smith    Output Parameter:
77153acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
77253acd3b1SBarry Smith 
77353acd3b1SBarry Smith    Level: beginner
77453acd3b1SBarry Smith 
77553acd3b1SBarry Smith    Concepts: options database^has int
77653acd3b1SBarry Smith 
77753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
77853acd3b1SBarry Smith 
77953acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
78053acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
78153acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
78253acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
78353acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
78453acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
78553acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
78653acd3b1SBarry Smith @*/
78753acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsName(const char opt[],const char text[],const char man[],PetscTruth *flg)
78853acd3b1SBarry Smith {
78953acd3b1SBarry Smith   PetscErrorCode ierr;
790*1ae3d29cSBarry Smith   PetscOptions   amsopt;
79153acd3b1SBarry Smith 
79253acd3b1SBarry Smith   PetscFunctionBegin;
793*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
794*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
795*1ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
796*1ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
797*1ae3d29cSBarry Smith   }
79853acd3b1SBarry Smith   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
79961b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
80053acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
80153acd3b1SBarry Smith   }
80253acd3b1SBarry Smith   PetscFunctionReturn(0);
80353acd3b1SBarry Smith }
80453acd3b1SBarry Smith 
80553acd3b1SBarry Smith #undef __FUNCT__
80653acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsList"
80753acd3b1SBarry Smith /*@C
80853acd3b1SBarry Smith      PetscOptionsList - Puts a list of option values that a single one may be selected from
80953acd3b1SBarry Smith 
81053acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
81153acd3b1SBarry Smith 
81253acd3b1SBarry Smith    Input Parameters:
81353acd3b1SBarry Smith +  opt - option name
81453acd3b1SBarry Smith .  text - short string that describes the option
81553acd3b1SBarry Smith .  man - manual page with additional information on option
81653acd3b1SBarry Smith .  list - the possible choices
8173cc1e11dSBarry Smith .  defaultv - the default (current) value
8183cc1e11dSBarry Smith -  len - the length of the character array value
81953acd3b1SBarry Smith 
82053acd3b1SBarry Smith    Output Parameter:
82153acd3b1SBarry Smith +  value - the value to return
82253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
82353acd3b1SBarry Smith 
82453acd3b1SBarry Smith    Level: intermediate
82553acd3b1SBarry Smith 
82653acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
82753acd3b1SBarry Smith 
82853acd3b1SBarry Smith    See PetscOptionsEList() for when the choices are given in a string array
82953acd3b1SBarry Smith 
83053acd3b1SBarry Smith    To get a listing of all currently specified options,
83153acd3b1SBarry Smith     see PetscOptionsPrint() or PetscOptionsGetAll()
83253acd3b1SBarry Smith 
83353acd3b1SBarry Smith    Concepts: options database^list
83453acd3b1SBarry Smith 
83553acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
83653acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
83753acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
83853acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
83953acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
84053acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
84153acd3b1SBarry Smith @*/
8423cc1e11dSBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsList(const char opt[],const char ltext[],const char man[],PetscFList list,const char defaultv[],char value[],size_t len,PetscTruth *set)
84353acd3b1SBarry Smith {
84453acd3b1SBarry Smith   PetscErrorCode ierr;
8453cc1e11dSBarry Smith   PetscOptions   amsopt;
84653acd3b1SBarry Smith 
84753acd3b1SBarry Smith   PetscFunctionBegin;
848b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
8493cc1e11dSBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
85071f08665SBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
85171f08665SBarry Smith     *(const char**)amsopt->data = defaultv;
8523cc1e11dSBarry Smith     amsopt->flist = list;
8533cc1e11dSBarry Smith   }
85453acd3b1SBarry Smith   ierr = PetscOptionsGetString(PetscOptionsObject.prefix,opt,value,len,set);CHKERRQ(ierr);
85561b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
8563cc1e11dSBarry Smith     ierr = PetscFListPrintTypes(PetscOptionsObject.comm,stdout,PetscOptionsObject.prefix,opt,ltext,man,list,defaultv);CHKERRQ(ierr);CHKERRQ(ierr);
85753acd3b1SBarry Smith   }
85853acd3b1SBarry Smith   PetscFunctionReturn(0);
85953acd3b1SBarry Smith }
86053acd3b1SBarry Smith 
86153acd3b1SBarry Smith #undef __FUNCT__
86253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsEList"
86353acd3b1SBarry Smith /*@C
86453acd3b1SBarry Smith      PetscOptionsEList - Puts a list of option values that a single one may be selected from
86553acd3b1SBarry Smith 
86653acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
86753acd3b1SBarry Smith 
86853acd3b1SBarry Smith    Input Parameters:
86953acd3b1SBarry Smith +  opt - option name
87053acd3b1SBarry Smith .  ltext - short string that describes the option
87153acd3b1SBarry Smith .  man - manual page with additional information on option
87253acd3b1SBarry Smith .  list - the possible choices
87353acd3b1SBarry Smith .  ntext - number of choices
87453acd3b1SBarry Smith -  defaultv - the default (current) value
87553acd3b1SBarry Smith 
87653acd3b1SBarry Smith    Output Parameter:
87753acd3b1SBarry Smith +  value - the index of the value to return
87853acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
87953acd3b1SBarry Smith 
88053acd3b1SBarry Smith    Level: intermediate
88153acd3b1SBarry Smith 
88253acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
88353acd3b1SBarry Smith 
88453acd3b1SBarry Smith    See PetscOptionsList() for when the choices are given in a PetscFList()
88553acd3b1SBarry Smith 
88653acd3b1SBarry Smith    Concepts: options database^list
88753acd3b1SBarry Smith 
88853acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
88953acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
89053acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
89153acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
89253acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
89353acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
89453acd3b1SBarry Smith @*/
8952ae9f97cSJed Brown PetscErrorCode PETSC_DLLEXPORT PetscOptionsEList(const char opt[],const char ltext[],const char man[],const char *const*list,PetscInt ntext,const char defaultv[],PetscInt *value,PetscTruth *set)
89653acd3b1SBarry Smith {
89753acd3b1SBarry Smith   PetscErrorCode ierr;
89853acd3b1SBarry Smith   PetscInt       i;
899*1ae3d29cSBarry Smith   PetscOptions   amsopt;
90053acd3b1SBarry Smith 
90153acd3b1SBarry Smith   PetscFunctionBegin;
902*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
903*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,ltext,man,OPTION_LIST,&amsopt);CHKERRQ(ierr);
904*1ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(char*),&amsopt->data);CHKERRQ(ierr);
905*1ae3d29cSBarry Smith     *(const char**)amsopt->data = defaultv;
906*1ae3d29cSBarry Smith     amsopt->list  = list;
907*1ae3d29cSBarry Smith     amsopt->nlist = ntext;
908*1ae3d29cSBarry Smith   }
90953acd3b1SBarry Smith   ierr = PetscOptionsGetEList(PetscOptionsObject.prefix,opt,list,ntext,value,set);CHKERRQ(ierr);
91061b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
91153acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%s> (choose one of)",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,defaultv);CHKERRQ(ierr);
91253acd3b1SBarry Smith     for (i=0; i<ntext; i++){
91353acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm," %s",list[i]);CHKERRQ(ierr);
91453acd3b1SBarry Smith     }
91553acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"\n");CHKERRQ(ierr);
91653acd3b1SBarry Smith   }
91753acd3b1SBarry Smith   PetscFunctionReturn(0);
91853acd3b1SBarry Smith }
91953acd3b1SBarry Smith 
92053acd3b1SBarry Smith #undef __FUNCT__
92153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupBegin"
92253acd3b1SBarry Smith /*@C
92353acd3b1SBarry Smith      PetscOptionsTruthGroupBegin - First in a series of logical queries on the options database for
92453acd3b1SBarry Smith        which only a single value can be true.
92553acd3b1SBarry Smith 
92653acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
92753acd3b1SBarry Smith 
92853acd3b1SBarry Smith    Input Parameters:
92953acd3b1SBarry Smith +  opt - option name
93053acd3b1SBarry Smith .  text - short string that describes the option
93153acd3b1SBarry Smith -  man - manual page with additional information on option
93253acd3b1SBarry Smith 
93353acd3b1SBarry Smith    Output Parameter:
93453acd3b1SBarry Smith .  flg - whether that option was set or not
93553acd3b1SBarry Smith 
93653acd3b1SBarry Smith    Level: intermediate
93753acd3b1SBarry Smith 
93853acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
93953acd3b1SBarry Smith 
94053acd3b1SBarry Smith    Must be followed by 0 or more PetscOptionsTruthGroup()s and PetscOptionsTruthGroupEnd()
94153acd3b1SBarry Smith 
94253acd3b1SBarry Smith     Concepts: options database^logical group
94353acd3b1SBarry Smith 
94453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
94553acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
94653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
94753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
94853acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
94953acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
95053acd3b1SBarry Smith @*/
95153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupBegin(const char opt[],const char text[],const char man[],PetscTruth *flg)
95253acd3b1SBarry Smith {
95353acd3b1SBarry Smith   PetscErrorCode ierr;
954*1ae3d29cSBarry Smith   PetscOptions   amsopt;
95553acd3b1SBarry Smith 
95653acd3b1SBarry Smith   PetscFunctionBegin;
957*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
958*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
959*1ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
960*1ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_TRUE;
961*1ae3d29cSBarry Smith   }
96217326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
96361b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
96453acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  Pick at most one of -------------\n");CHKERRQ(ierr);
96553acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
96653acd3b1SBarry Smith   }
96753acd3b1SBarry Smith   PetscFunctionReturn(0);
96853acd3b1SBarry Smith }
96953acd3b1SBarry Smith 
97053acd3b1SBarry Smith #undef __FUNCT__
97153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroup"
97253acd3b1SBarry Smith /*@C
97353acd3b1SBarry Smith      PetscOptionsTruthGroup - One in a series of logical queries on the options database for
97453acd3b1SBarry Smith        which only a single value can be true.
97553acd3b1SBarry Smith 
97653acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
97753acd3b1SBarry Smith 
97853acd3b1SBarry Smith    Input Parameters:
97953acd3b1SBarry Smith +  opt - option name
98053acd3b1SBarry Smith .  text - short string that describes the option
98153acd3b1SBarry Smith -  man - manual page with additional information on option
98253acd3b1SBarry Smith 
98353acd3b1SBarry Smith    Output Parameter:
98453acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
98553acd3b1SBarry Smith 
98653acd3b1SBarry Smith    Level: intermediate
98753acd3b1SBarry Smith 
98853acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
98953acd3b1SBarry Smith 
99053acd3b1SBarry Smith    Must follow a PetscOptionsTruthGroupBegin() and preceded a PetscOptionsTruthGroupEnd()
99153acd3b1SBarry Smith 
99253acd3b1SBarry Smith     Concepts: options database^logical group
99353acd3b1SBarry Smith 
99453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
99553acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
99653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
99753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
99853acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
99953acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
100053acd3b1SBarry Smith @*/
100153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroup(const char opt[],const char text[],const char man[],PetscTruth *flg)
100253acd3b1SBarry Smith {
100353acd3b1SBarry Smith   PetscErrorCode ierr;
1004*1ae3d29cSBarry Smith   PetscOptions   amsopt;
100553acd3b1SBarry Smith 
100653acd3b1SBarry Smith   PetscFunctionBegin;
1007*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
1008*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1009*1ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
1010*1ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
1011*1ae3d29cSBarry Smith   }
101217326d04SJed Brown   *flg = PETSC_FALSE;
101317326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
101461b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
101553acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
101653acd3b1SBarry Smith   }
101753acd3b1SBarry Smith   PetscFunctionReturn(0);
101853acd3b1SBarry Smith }
101953acd3b1SBarry Smith 
102053acd3b1SBarry Smith #undef __FUNCT__
102153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruthGroupEnd"
102253acd3b1SBarry Smith /*@C
102353acd3b1SBarry Smith      PetscOptionsTruthGroupEnd - Last in a series of logical queries on the options database for
102453acd3b1SBarry Smith        which only a single value can be true.
102553acd3b1SBarry Smith 
102653acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
102753acd3b1SBarry Smith 
102853acd3b1SBarry Smith    Input Parameters:
102953acd3b1SBarry Smith +  opt - option name
103053acd3b1SBarry Smith .  text - short string that describes the option
103153acd3b1SBarry Smith -  man - manual page with additional information on option
103253acd3b1SBarry Smith 
103353acd3b1SBarry Smith    Output Parameter:
103453acd3b1SBarry Smith .  flg - PETSC_TRUE if found, else PETSC_FALSE
103553acd3b1SBarry Smith 
103653acd3b1SBarry Smith    Level: intermediate
103753acd3b1SBarry Smith 
103853acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
103953acd3b1SBarry Smith 
104053acd3b1SBarry Smith    Must follow a PetscOptionsTruthGroupBegin()
104153acd3b1SBarry Smith 
104253acd3b1SBarry Smith     Concepts: options database^logical group
104353acd3b1SBarry Smith 
104453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
104553acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
104653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
104753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
104853acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
104953acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
105053acd3b1SBarry Smith @*/
105153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthGroupEnd(const char opt[],const char text[],const char man[],PetscTruth *flg)
105253acd3b1SBarry Smith {
105353acd3b1SBarry Smith   PetscErrorCode ierr;
1054*1ae3d29cSBarry Smith   PetscOptions   amsopt;
105553acd3b1SBarry Smith 
105653acd3b1SBarry Smith   PetscFunctionBegin;
1057*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
1058*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
1059*1ae3d29cSBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
1060*1ae3d29cSBarry Smith     *(PetscTruth*)amsopt->data = PETSC_FALSE;
1061*1ae3d29cSBarry Smith   }
106217326d04SJed Brown   *flg = PETSC_FALSE;
106317326d04SJed Brown   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,PETSC_NULL);CHKERRQ(ierr);
106461b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
106553acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"    -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
106653acd3b1SBarry Smith   }
106753acd3b1SBarry Smith   PetscFunctionReturn(0);
106853acd3b1SBarry Smith }
106953acd3b1SBarry Smith 
107053acd3b1SBarry Smith #undef __FUNCT__
107153acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsTruth"
107253acd3b1SBarry Smith /*@C
107353acd3b1SBarry Smith    PetscOptionsTruth - Determines if a particular option is in the database with a true or false
107453acd3b1SBarry Smith 
107553acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
107653acd3b1SBarry Smith 
107753acd3b1SBarry Smith    Input Parameters:
107853acd3b1SBarry Smith +  opt - option name
107953acd3b1SBarry Smith .  text - short string that describes the option
108053acd3b1SBarry Smith -  man - manual page with additional information on option
108153acd3b1SBarry Smith 
108253acd3b1SBarry Smith    Output Parameter:
108353acd3b1SBarry Smith .  flg - PETSC_TRUE or PETSC_FALSE
108453acd3b1SBarry Smith .  set - PETSC_TRUE if found, else PETSC_FALSE
108553acd3b1SBarry Smith 
108653acd3b1SBarry Smith    Level: beginner
108753acd3b1SBarry Smith 
108853acd3b1SBarry Smith    Concepts: options database^logical
108953acd3b1SBarry Smith 
109053acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
109153acd3b1SBarry Smith 
109253acd3b1SBarry Smith .seealso: PetscOptionsGetReal(), PetscOptionsHasName(), PetscOptionsGetString(), PetscOptionsGetInt(),
109353acd3b1SBarry Smith           PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth()
109453acd3b1SBarry Smith           PetscOptionsInt(), PetscOptionsString(), PetscOptionsReal(), PetscOptionsTruth(),
109553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
109653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
109753acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
109853acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
109953acd3b1SBarry Smith @*/
110053acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruth(const char opt[],const char text[],const char man[],PetscTruth deflt,PetscTruth *flg,PetscTruth *set)
110153acd3b1SBarry Smith {
110253acd3b1SBarry Smith   PetscErrorCode ierr;
110353acd3b1SBarry Smith   PetscTruth     iset;
1104aee2cecaSBarry Smith   PetscOptions   amsopt;
110553acd3b1SBarry Smith 
110653acd3b1SBarry Smith   PetscFunctionBegin;
1107b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1108aee2cecaSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL,&amsopt);CHKERRQ(ierr);
110971f08665SBarry Smith     ierr = PetscMalloc(sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
111071f08665SBarry Smith     *(PetscTruth*)amsopt->data = deflt;
1111af6d86caSBarry Smith   }
111253acd3b1SBarry Smith   ierr = PetscOptionsGetTruth(PetscOptionsObject.prefix,opt,flg,&iset);CHKERRQ(ierr);
111353acd3b1SBarry Smith   if (!iset) {
111453acd3b1SBarry Smith     if (flg) *flg = deflt;
111553acd3b1SBarry Smith   }
111653acd3b1SBarry Smith   if (set) *set = iset;
111761b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
111853acd3b1SBarry Smith     const char *v = PetscTruths[deflt];
111953acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: <%s> %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,v,text,man);CHKERRQ(ierr);
112053acd3b1SBarry Smith   }
112153acd3b1SBarry Smith   PetscFunctionReturn(0);
112253acd3b1SBarry Smith }
112353acd3b1SBarry Smith 
112453acd3b1SBarry Smith #undef __FUNCT__
112553acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsRealArray"
112653acd3b1SBarry Smith /*@C
112753acd3b1SBarry Smith    PetscOptionsRealArray - Gets an array of double values for a particular
112853acd3b1SBarry Smith    option in the database. The values must be separated with commas with
112953acd3b1SBarry Smith    no intervening spaces.
113053acd3b1SBarry Smith 
113153acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
113253acd3b1SBarry Smith 
113353acd3b1SBarry Smith    Input Parameters:
113453acd3b1SBarry Smith +  opt - the option one is seeking
113553acd3b1SBarry Smith .  text - short string describing option
113653acd3b1SBarry Smith .  man - manual page for option
113753acd3b1SBarry Smith -  nmax - maximum number of values
113853acd3b1SBarry Smith 
113953acd3b1SBarry Smith    Output Parameter:
114053acd3b1SBarry Smith +  value - location to copy values
114153acd3b1SBarry Smith .  nmax - actual number of values found
114253acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
114353acd3b1SBarry Smith 
114453acd3b1SBarry Smith    Level: beginner
114553acd3b1SBarry Smith 
114653acd3b1SBarry Smith    Notes:
114753acd3b1SBarry Smith    The user should pass in an array of doubles
114853acd3b1SBarry Smith 
114953acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
115053acd3b1SBarry Smith 
115153acd3b1SBarry Smith    Concepts: options database^array of strings
115253acd3b1SBarry Smith 
115353acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
115453acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
115553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
115653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
115753acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
115853acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
115953acd3b1SBarry Smith @*/
116053acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsRealArray(const char opt[],const char text[],const char man[],PetscReal value[],PetscInt *n,PetscTruth *set)
116153acd3b1SBarry Smith {
116253acd3b1SBarry Smith   PetscErrorCode ierr;
116353acd3b1SBarry Smith   PetscInt       i;
1164e26ddf31SBarry Smith   PetscOptions   amsopt;
116553acd3b1SBarry Smith 
116653acd3b1SBarry Smith   PetscFunctionBegin;
1167b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1168e26ddf31SBarry Smith     PetscReal *vals;
1169e26ddf31SBarry Smith 
1170e26ddf31SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_REAL_ARRAY,&amsopt);CHKERRQ(ierr);
1171e26ddf31SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscReal),&amsopt->data);CHKERRQ(ierr);
1172e26ddf31SBarry Smith     vals = (PetscReal*)amsopt->data;
1173e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1174e26ddf31SBarry Smith     amsopt->arraylength = *n;
1175e26ddf31SBarry Smith   }
117653acd3b1SBarry Smith   ierr = PetscOptionsGetRealArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
117761b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1178a83599f4SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%G",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
117953acd3b1SBarry Smith     for (i=1; i<*n; i++) {
1180a83599f4SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%G",value[i]);CHKERRQ(ierr);
118153acd3b1SBarry Smith     }
118253acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
118353acd3b1SBarry Smith   }
118453acd3b1SBarry Smith   PetscFunctionReturn(0);
118553acd3b1SBarry Smith }
118653acd3b1SBarry Smith 
118753acd3b1SBarry Smith 
118853acd3b1SBarry Smith #undef __FUNCT__
118953acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsIntArray"
119053acd3b1SBarry Smith /*@C
119153acd3b1SBarry Smith    PetscOptionsIntArray - Gets an array of integers for a particular
119253acd3b1SBarry Smith    option in the database. The values must be separated with commas with
119353acd3b1SBarry Smith    no intervening spaces.
119453acd3b1SBarry Smith 
119553acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
119653acd3b1SBarry Smith 
119753acd3b1SBarry Smith    Input Parameters:
119853acd3b1SBarry Smith +  opt - the option one is seeking
119953acd3b1SBarry Smith .  text - short string describing option
120053acd3b1SBarry Smith .  man - manual page for option
1201f8a50e2bSBarry Smith -  n - maximum number of values
120253acd3b1SBarry Smith 
120353acd3b1SBarry Smith    Output Parameter:
120453acd3b1SBarry Smith +  value - location to copy values
1205f8a50e2bSBarry Smith .  n - actual number of values found
120653acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
120753acd3b1SBarry Smith 
120853acd3b1SBarry Smith    Level: beginner
120953acd3b1SBarry Smith 
121053acd3b1SBarry Smith    Notes:
121153acd3b1SBarry Smith    The user should pass in an array of integers
121253acd3b1SBarry Smith 
121353acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
121453acd3b1SBarry Smith 
121553acd3b1SBarry Smith    Concepts: options database^array of strings
121653acd3b1SBarry Smith 
121753acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
121853acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
121953acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
122053acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
122153acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
122253acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList(), PetscOptionsRealArray()
122353acd3b1SBarry Smith @*/
122453acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsIntArray(const char opt[],const char text[],const char man[],PetscInt value[],PetscInt *n,PetscTruth *set)
122553acd3b1SBarry Smith {
122653acd3b1SBarry Smith   PetscErrorCode ierr;
122753acd3b1SBarry Smith   PetscInt       i;
1228e26ddf31SBarry Smith   PetscOptions   amsopt;
122953acd3b1SBarry Smith 
123053acd3b1SBarry Smith   PetscFunctionBegin;
1231b3506946SBarry Smith   if (!PetscOptionsPublishCount) {
1232e26ddf31SBarry Smith     PetscInt *vals;
1233e26ddf31SBarry Smith 
1234e26ddf31SBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_INT_ARRAY,&amsopt);CHKERRQ(ierr);
1235e26ddf31SBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscInt),&amsopt->data);CHKERRQ(ierr);
1236e26ddf31SBarry Smith     vals = (PetscInt*)amsopt->data;
1237e26ddf31SBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1238e26ddf31SBarry Smith     amsopt->arraylength = *n;
1239e26ddf31SBarry Smith   }
124053acd3b1SBarry Smith   ierr = PetscOptionsGetIntArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
124161b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
124253acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
124353acd3b1SBarry Smith     for (i=1; i<*n; i++) {
124453acd3b1SBarry Smith       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
124553acd3b1SBarry Smith     }
124653acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
124753acd3b1SBarry Smith   }
124853acd3b1SBarry Smith   PetscFunctionReturn(0);
124953acd3b1SBarry Smith }
125053acd3b1SBarry Smith 
125153acd3b1SBarry Smith #undef __FUNCT__
125253acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsStringArray"
125353acd3b1SBarry Smith /*@C
125453acd3b1SBarry Smith    PetscOptionsStringArray - Gets an array of string values for a particular
125553acd3b1SBarry Smith    option in the database. The values must be separated with commas with
125653acd3b1SBarry Smith    no intervening spaces.
125753acd3b1SBarry Smith 
125853acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
125953acd3b1SBarry Smith 
126053acd3b1SBarry Smith    Input Parameters:
126153acd3b1SBarry Smith +  opt - the option one is seeking
126253acd3b1SBarry Smith .  text - short string describing option
126353acd3b1SBarry Smith .  man - manual page for option
126453acd3b1SBarry Smith -  nmax - maximum number of strings
126553acd3b1SBarry Smith 
126653acd3b1SBarry Smith    Output Parameter:
126753acd3b1SBarry Smith +  value - location to copy strings
126853acd3b1SBarry Smith .  nmax - actual number of strings found
126953acd3b1SBarry Smith -  set - PETSC_TRUE if found, else PETSC_FALSE
127053acd3b1SBarry Smith 
127153acd3b1SBarry Smith    Level: beginner
127253acd3b1SBarry Smith 
127353acd3b1SBarry Smith    Notes:
127453acd3b1SBarry Smith    The user should pass in an array of pointers to char, to hold all the
127553acd3b1SBarry Smith    strings returned by this function.
127653acd3b1SBarry Smith 
127753acd3b1SBarry Smith    The user is responsible for deallocating the strings that are
127853acd3b1SBarry Smith    returned. The Fortran interface for this routine is not supported.
127953acd3b1SBarry Smith 
128053acd3b1SBarry Smith    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
128153acd3b1SBarry Smith 
128253acd3b1SBarry Smith    Concepts: options database^array of strings
128353acd3b1SBarry Smith 
128453acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
128553acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
128653acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
128753acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
128853acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
128953acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
129053acd3b1SBarry Smith @*/
129153acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsStringArray(const char opt[],const char text[],const char man[],char *value[],PetscInt *nmax,PetscTruth *set)
129253acd3b1SBarry Smith {
129353acd3b1SBarry Smith   PetscErrorCode ierr;
1294*1ae3d29cSBarry Smith   PetscOptions   amsopt;
129553acd3b1SBarry Smith 
129653acd3b1SBarry Smith   PetscFunctionBegin;
1297*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
1298*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_STRING_ARRAY,&amsopt);CHKERRQ(ierr);
1299*1ae3d29cSBarry Smith     ierr = PetscMalloc((*nmax)*sizeof(char*),&amsopt->data);CHKERRQ(ierr);
1300*1ae3d29cSBarry Smith     amsopt->arraylength = *nmax;
1301*1ae3d29cSBarry Smith   }
130253acd3b1SBarry Smith   ierr = PetscOptionsGetStringArray(PetscOptionsObject.prefix,opt,value,nmax,set);CHKERRQ(ierr);
130361b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
130453acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <string1,string2,...>: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
130553acd3b1SBarry Smith   }
130653acd3b1SBarry Smith   PetscFunctionReturn(0);
130753acd3b1SBarry Smith }
130853acd3b1SBarry Smith 
1309e2446a98SMatthew Knepley #undef __FUNCT__
1310e2446a98SMatthew Knepley #define __FUNCT__ "PetscOptionsTruthArray"
1311e2446a98SMatthew Knepley /*@C
1312e2446a98SMatthew Knepley    PetscOptionsTruthArray - Gets an array of logical values (true or false) for a particular
1313e2446a98SMatthew Knepley    option in the database. The values must be separated with commas with
1314e2446a98SMatthew Knepley    no intervening spaces.
1315e2446a98SMatthew Knepley 
1316e2446a98SMatthew Knepley    Collective on the communicator passed in PetscOptionsBegin()
1317e2446a98SMatthew Knepley 
1318e2446a98SMatthew Knepley    Input Parameters:
1319e2446a98SMatthew Knepley +  opt - the option one is seeking
1320e2446a98SMatthew Knepley .  text - short string describing option
1321e2446a98SMatthew Knepley .  man - manual page for option
1322e2446a98SMatthew Knepley -  nmax - maximum number of values
1323e2446a98SMatthew Knepley 
1324e2446a98SMatthew Knepley    Output Parameter:
1325e2446a98SMatthew Knepley +  value - location to copy values
1326e2446a98SMatthew Knepley .  nmax - actual number of values found
1327e2446a98SMatthew Knepley -  set - PETSC_TRUE if found, else PETSC_FALSE
1328e2446a98SMatthew Knepley 
1329e2446a98SMatthew Knepley    Level: beginner
1330e2446a98SMatthew Knepley 
1331e2446a98SMatthew Knepley    Notes:
1332e2446a98SMatthew Knepley    The user should pass in an array of doubles
1333e2446a98SMatthew Knepley 
1334e2446a98SMatthew Knepley    Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
1335e2446a98SMatthew Knepley 
1336e2446a98SMatthew Knepley    Concepts: options database^array of strings
1337e2446a98SMatthew Knepley 
1338e2446a98SMatthew Knepley .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
1339e2446a98SMatthew Knepley            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
1340e2446a98SMatthew Knepley           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
1341e2446a98SMatthew Knepley           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
1342e2446a98SMatthew Knepley           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
1343e2446a98SMatthew Knepley           PetscOptionsList(), PetscOptionsEList()
1344e2446a98SMatthew Knepley @*/
1345e2446a98SMatthew Knepley PetscErrorCode PETSC_DLLEXPORT PetscOptionsTruthArray(const char opt[],const char text[],const char man[],PetscTruth value[],PetscInt *n,PetscTruth *set)
1346e2446a98SMatthew Knepley {
1347e2446a98SMatthew Knepley   PetscErrorCode ierr;
1348e2446a98SMatthew Knepley   PetscInt       i;
1349*1ae3d29cSBarry Smith   PetscOptions   amsopt;
1350e2446a98SMatthew Knepley 
1351e2446a98SMatthew Knepley   PetscFunctionBegin;
1352*1ae3d29cSBarry Smith   if (!PetscOptionsPublishCount) {
1353*1ae3d29cSBarry Smith     PetscTruth *vals;
1354*1ae3d29cSBarry Smith 
1355*1ae3d29cSBarry Smith     ierr = PetscOptionsCreate_Private(opt,text,man,OPTION_LOGICAL_ARRAY,&amsopt);CHKERRQ(ierr);
1356*1ae3d29cSBarry Smith     ierr = PetscMalloc((*n)*sizeof(PetscTruth),&amsopt->data);CHKERRQ(ierr);
1357*1ae3d29cSBarry Smith     vals = (PetscTruth*)amsopt->data;
1358*1ae3d29cSBarry Smith     for (i=0; i<*n; i++) vals[i] = value[i];
1359*1ae3d29cSBarry Smith     amsopt->arraylength = *n;
1360*1ae3d29cSBarry Smith   }
1361e2446a98SMatthew Knepley   ierr = PetscOptionsGetTruthArray(PetscOptionsObject.prefix,opt,value,n,set);CHKERRQ(ierr);
1362e2446a98SMatthew Knepley   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
1363e2446a98SMatthew Knepley     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s <%d",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,value[0]);CHKERRQ(ierr);
1364e2446a98SMatthew Knepley     for (i=1; i<*n; i++) {
1365e2446a98SMatthew Knepley       ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,",%d",value[i]);CHKERRQ(ierr);
1366e2446a98SMatthew Knepley     }
1367e2446a98SMatthew Knepley     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,">: %s (%s)\n",text,man);CHKERRQ(ierr);
1368e2446a98SMatthew Knepley   }
1369e2446a98SMatthew Knepley   PetscFunctionReturn(0);
1370e2446a98SMatthew Knepley }
1371e2446a98SMatthew Knepley 
137253acd3b1SBarry Smith 
137353acd3b1SBarry Smith #undef __FUNCT__
137453acd3b1SBarry Smith #define __FUNCT__ "PetscOptionsHead"
137553acd3b1SBarry Smith /*@C
1376b52f573bSBarry Smith      PetscOptionsHead - Puts a heading before listing any more published options. Used, for example,
137753acd3b1SBarry Smith             in KSPSetFromOptions_GMRES().
137853acd3b1SBarry Smith 
137953acd3b1SBarry Smith    Collective on the communicator passed in PetscOptionsBegin()
138053acd3b1SBarry Smith 
138153acd3b1SBarry Smith    Input Parameter:
138253acd3b1SBarry Smith .   head - the heading text
138353acd3b1SBarry Smith 
138453acd3b1SBarry Smith 
138553acd3b1SBarry Smith    Level: intermediate
138653acd3b1SBarry Smith 
138753acd3b1SBarry Smith    Notes: Must be between a PetscOptionsBegin() and a PetscOptionsEnd()
138853acd3b1SBarry Smith 
1389b52f573bSBarry Smith           Can be followed by a call to PetscOptionsTail() in the same function.
139053acd3b1SBarry Smith 
139153acd3b1SBarry Smith    Concepts: options database^subheading
139253acd3b1SBarry Smith 
139353acd3b1SBarry Smith .seealso: PetscOptionsGetInt(), PetscOptionsGetReal(),
139453acd3b1SBarry Smith            PetscOptionsHasName(), PetscOptionsGetIntArray(), PetscOptionsGetRealArray(), PetscOptionsTruth(),
139553acd3b1SBarry Smith           PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
139653acd3b1SBarry Smith           PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
139753acd3b1SBarry Smith           PetscOptionsTruthGroupBegin(), PetscOptionsTruthGroup(), PetscOptionsTruthGroupEnd(),
139853acd3b1SBarry Smith           PetscOptionsList(), PetscOptionsEList()
139953acd3b1SBarry Smith @*/
140053acd3b1SBarry Smith PetscErrorCode PETSC_DLLEXPORT PetscOptionsHead(const char head[])
140153acd3b1SBarry Smith {
140253acd3b1SBarry Smith   PetscErrorCode ierr;
140353acd3b1SBarry Smith 
140453acd3b1SBarry Smith   PetscFunctionBegin;
140561b37b28SSatish Balay   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
140653acd3b1SBarry Smith     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  %s\n",head);CHKERRQ(ierr);
140753acd3b1SBarry Smith   }
140853acd3b1SBarry Smith   PetscFunctionReturn(0);
140953acd3b1SBarry Smith }
141053acd3b1SBarry Smith 
141153acd3b1SBarry Smith 
141253acd3b1SBarry Smith 
141353acd3b1SBarry Smith 
141453acd3b1SBarry Smith 
141553acd3b1SBarry Smith 
1416