Actual source code: zstartf.c

     2:  #include src/fortran/custom/zpetsc.h
     3:  #include petscsys.h

      6: #ifdef PETSC_HAVE_FORTRAN_CAPS
      7: #define petscinitializefortran_       PETSCINITIALIZEFORTRAN
      8: #define petscsetcommonblock_          PETSCSETCOMMONBLOCK
      9: #define petscsetfortranbasepointers_  PETSCSETFORTRANBASEPOINTERS
     10: #define petsc_null_function_          PETSC_NULL_FUNCTION
     11: #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
     12: #define petscinitializefortran_       petscinitializefortran
     13: #define petscsetcommonblock_          petscsetcommonblock
     14: #define petscsetfortranbasepointers_  petscsetfortranbasepointers
     15: #define petsc_null_function_          petsc_null_function
     16: #endif

     18: #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE)
     19: #define petsc_null_function_  petsc_null_function__
     20: #endif

     26: /*@C
     27:    PetscInitializeFortran - Routine that should be called from C AFTER
     28:    the call to PetscInitialize() if one is using a C main program
     29:    that calls Fortran routines that in turn call PETSc routines.

     31:    Collective on PETSC_COMM_WORLD

     33:    Level: beginner

     35:    Notes:
     36:    PetscInitializeFortran() initializes some of the default viewers,
     37:    communicators, etc. for use in the Fortran if a user's main program is
     38:    written in C.  PetscInitializeFortran() is NOT needed if a user's main
     39:    program is written in Fortran; in this case, just calling
     40:    PetscInitialize() in the main (Fortran) program is sufficient.

     42: .seealso:  PetscInitialize()

     44: .keywords: Mixing C and Fortran, passing PETSc objects to Fortran
     45: @*/

     47: PetscErrorCode PetscInitializeFortran(void)
     48: {
     49:   PetscMPIInt c1=0,c2=0;

     51:   if (PETSC_COMM_WORLD) {
     52:     c1 = PetscFromPointerComm(PETSC_COMM_WORLD);
     53:   }
     54:   if (PETSC_COMM_SELF) {
     55:     c2 = PetscFromPointerComm(PETSC_COMM_SELF);
     56:   }
     57:   petscsetcommonblock_(&c1,&c2);
     58:   return 0;
     59: }
     60:

     63: void PETSC_STDCALL petscinitializefortran_(int *ierr)
     64: {
     65:   *PetscInitializeFortran();
     66: }

     68: #if defined(PETSC_USES_CPTOFCD)
     69: void PETSC_STDCALL petscsetfortranbasepointers_(_fcd fnull_character,void *fnull_integer,
     70:                                   void* fnull,void *fnull_scalar,void * fnull_double, void *fnull_real,void* fnull_object,
     71:                                   void (*fnull_function)(void))
     72: {
     73:   PETSC_NULL_CHARACTER_Fortran  = _fcdtocp(fnull_character);
     74:   PETSC_NULL_INTEGER_Fortran    = fnull_integer;
     75:   PETSC_NULL_Fortran            = fnull;
     76:   PETSC_NULL_SCALAR_Fortran     = fnull_scalar;
     77:   PETSC_NULL_DOUBLE_Fortran     = fnull_double;
     78:   PETSC_NULL_REAL_Fortran       = fnull_real;
     79:   PETSC_NULL_OBJECT_Fortran     = fnull_object;
     80:   PETSC_NULL_FUNCTION_Fortran   = fnull_function;
     81: }
     82: #else
     83: void PETSC_STDCALL petscsetfortranbasepointers_(char *fnull_character PETSC_MIXED_LEN(len),
     84:                                   void *fnull_integer,void* fnull,void *fnull_scalar,void * fnull_double,
     85:                                     void *fnull_real,void *fnull_object,
     86:                                   void (*fnull_function)(void) PETSC_END_LEN(len))
     87: {
     88:   PETSC_NULL_CHARACTER_Fortran  = fnull_character;
     89:   PETSC_NULL_INTEGER_Fortran    = fnull_integer;
     90:   PETSC_NULL_SCALAR_Fortran     = fnull_scalar;
     91:   PETSC_NULL_DOUBLE_Fortran     = fnull_double;
     92:   PETSC_NULL_REAL_Fortran       = fnull_real;
     93:   PETSC_NULL_OBJECT_Fortran     = fnull_object;
     94:   PETSC_NULL_FUNCTION_Fortran   = fnull_function;
     95: }
     96: #endif

     98: /*
     99:   A valid address for the fortran variable PETSC_NULL_FUNCTION
    100: */
    101: void petsc_null_function_(void)
    102: {
    103:   return;
    104: }