Actual source code: ex49.c

  1: static char help[] = "Demonstrates PetscDataTypeFromString().\n\n";

  3: #include <petscsys.h>
  4: int main(int argc, char **argv)
  5: {
  6:   PetscDataType dtype;
  7:   PetscBool     found;

  9:   /*
 10:     Every PETSc routine should begin with the PetscInitialize() routine.
 11:     argc, argv - These command line arguments are taken to extract the options
 12:                  supplied to PETSc and options supplied to MPI.
 13:     help       - When PETSc executable is invoked with the option -help,
 14:                  it prints the various options that can be applied at
 15:                  runtime.  The user can use the "help" variable place
 16:                  additional help messages in this printout.
 17:   */
 18:   PetscFunctionBeginUser;
 19:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));

 21:   PetscCall(PetscDataTypeFromString("Scalar", &dtype, &found));
 22:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find scalar datatype");
 23:   PetscCheck(dtype == PETSC_SCALAR, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for scalar");

 25:   PetscCall(PetscDataTypeFromString("INT", &dtype, &found));
 26:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find int datatype");
 27:   PetscCheck(dtype == PETSC_INT, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for int");

 29:   PetscCall(PetscDataTypeFromString("real", &dtype, &found));
 30:   PetscCheck(found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Did not find real datatype");
 31:   PetscCheck(dtype == PETSC_REAL, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found wrong datatype for real");

 33:   PetscCall(PetscDataTypeFromString("abogusdatatype", &dtype, &found));
 34:   PetscCheck(!found, PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG, "Found a bogus datatype");

 36:   PetscCall(PetscFinalize());
 37:   return 0;
 38: }

 40: /*TEST

 42:    test:

 44: TEST*/