xref: /petsc/src/sys/tests/ex49.c (revision ea13f565a9e7eeb46a1941ff623f2af24053d663)
1 
2 static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";
3 
4 /*T
5    Concepts: introduction to PETSc;
6    Concepts: printing^in parallel
7    Processors: n
8 T*/
9 
10 #include <petscsys.h>
11 int main(int argc,char **argv)
12 {
13   PetscErrorCode ierr;
14   PetscDataType  dtype;
15   PetscBool      found;
16 
17   /*
18     Every PETSc routine should begin with the PetscInitialize() routine.
19     argc, argv - These command line arguments are taken to extract the options
20                  supplied to PETSc and options supplied to MPI.
21     help       - When PETSc executable is invoked with the option -help,
22                  it prints the various options that can be applied at
23                  runtime.  The user can use the "help" variable place
24                  additional help messages in this printout.
25   */
26   ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
27 
28   ierr = PetscDataTypeFromString("Scalar",&dtype,&found);CHKERRQ(ierr);
29   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find scalar datatype");
30   if (dtype != PETSC_SCALAR) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for scalar");
31 
32   ierr = PetscDataTypeFromString("INT",&dtype,&found);CHKERRQ(ierr);
33   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find int datatype");
34   if (dtype != PETSC_INT) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for int");
35 
36   ierr = PetscDataTypeFromString("real",&dtype,&found);CHKERRQ(ierr);
37   if (!found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Did not find real datatype");
38   if (dtype != PETSC_REAL) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found wrong datatype for real");
39 
40   ierr = PetscDataTypeFromString("abogusdatatype",&dtype,&found);CHKERRQ(ierr);
41   if (found) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Found a bogus datatype");
42 
43   ierr = PetscFinalize();
44   return ierr;
45 }
46 
47 
48 /*TEST
49 
50    test:
51 
52 TEST*/
53