Actual source code: ex14.c
petsc-3.6.1 2015-08-06
2: static char help[] = "Tests PetscOptionsGetScalar(), PetscOptionsScalarArray() for complex numbers\n";
4: #include <petscsys.h>
8: int main(int argc,char **argv)
9: {
10: PetscInt ierr,n,i;
11: PetscScalar a,array[10];
12: PetscReal rarray[10];
14: PetscInitialize(&argc,&argv,(char*)0,help);
15: PetscOptionsGetScalar(NULL,"-a",&a,NULL);
16: PetscPrintf(PETSC_COMM_SELF,"Scalar a = %g + %gi\n",(double)PetscRealPart(a),(double)PetscImaginaryPart(a));
18: PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"test options",NULL);
19: n = 10; /* max num of input values */
20: PetscOptionsRealArray("-rarray", "Input a real array", "ex14.c", rarray, &n, NULL);
21: if (n) {
22: PetscPrintf(PETSC_COMM_SELF,"Real rarray of length %d\n",n);
23: for (i=0; i<n; i++){
24: PetscPrintf(PETSC_COMM_SELF," %g,\n",rarray[i]);
25: }
26: }
28: n = 10; /* max num of input values */
29: PetscOptionsScalarArray("-array", "Input a scalar array", "ex14.c", array, &n, NULL);
30: if (n) {
31: PetscPrintf(PETSC_COMM_SELF,"Scalar rarray of length %d\n",n);
32: for (i=0; i<n; i++){
33: if (PetscImaginaryPart(array[i]) < 0.0) {
34: PetscPrintf(PETSC_COMM_SELF," %g - %gi\n",(double)PetscRealPart(array[i]),(double)PetscAbsReal(PetscImaginaryPart(array[i])));
35: } else {
36: PetscPrintf(PETSC_COMM_SELF," %g + %gi\n",(double)PetscRealPart(array[i]),(double)PetscImaginaryPart(array[i]));
37: }
38: }
39: }
40: PetscOptionsEnd();
41: PetscFinalize();
42: return 0;
43: }