xref: /petsc/src/sys/objects/ftn-custom/zstartf.c (revision 8cc058d9cd56c1ccb3be12a47760ddfc446aaffc)
1 
2 #include <petsc-private/fortranimpl.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5 #define petscinitializefortran_       PETSCINITIALIZEFORTRAN
6 #define petscsetcommonblock_          PETSCSETCOMMONBLOCK
7 #define petscsetfortranbasepointers_  PETSCSETFORTRANBASEPOINTERS
8 #define petsc_null_function_          PETSC_NULL_FUNCTION
9 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
10 #define petscinitializefortran_       petscinitializefortran
11 #define petscsetcommonblock_          petscsetcommonblock
12 #define petscsetfortranbasepointers_  petscsetfortranbasepointers
13 #define petsc_null_function_          petsc_null_function
14 #endif
15 
16 #if defined(PETSC_HAVE_FORTRAN_UNDERSCORE_UNDERSCORE)
17 #define petsc_null_function_  petsc_null_function__
18 #endif
19 
20 PETSC_EXTERN void PETSC_STDCALL petscsetcommonblock_(int*,int*);
21 
22 /*@C
23    PetscInitializeFortran - Routine that should be called soon AFTER
24    the call to PetscInitialize() if one is using a C main program
25    that calls Fortran routines that in turn call PETSc routines.
26 
27    Collective on PETSC_COMM_WORLD
28 
29    Level: beginner
30 
31    Notes:
32    PetscInitializeFortran() initializes some of the default viewers,
33    communicators, etc. for use in the Fortran if a user's main program is
34    written in C.  PetscInitializeFortran() is NOT needed if a user's main
35    program is written in Fortran; in this case, just calling
36    PetscInitialize() in the main (Fortran) program is sufficient.
37 
38 .seealso:  PetscInitialize()
39 
40 .keywords: Mixing C and Fortran, passing PETSc objects to Fortran
41 @*/
42 PetscErrorCode PetscInitializeFortran(void)
43 {
44   PetscMPIInt c1=0,c2=0;
45 
46   if (PETSC_COMM_WORLD) c1 =  MPI_Comm_c2f(PETSC_COMM_WORLD);
47   /* PETSC_COMM_SELF is defined as MPI_COMM_SELF */
48   c2 =  MPI_Comm_c2f(PETSC_COMM_SELF);
49   petscsetcommonblock_(&c1,&c2);
50   return 0;
51 }
52 
53 PETSC_EXTERN void PETSC_STDCALL petscinitializefortran_(int *ierr)
54 {
55   *ierr = PetscInitializeFortran();
56 }
57 
58 PETSC_EXTERN void PETSC_STDCALL petscsetfortranbasepointers_(char *fnull_character PETSC_MIXED_LEN(len),
59                                   void *fnull_integer,void *fnull_scalar,void * fnull_double,
60                                   void *fnull_real,void *fnull_object,
61                                   void* fnull_truth,void (*fnull_function)(void) PETSC_END_LEN(len))
62 {
63   PETSC_NULL_CHARACTER_Fortran = fnull_character;
64   PETSC_NULL_INTEGER_Fortran   = fnull_integer;
65   PETSC_NULL_SCALAR_Fortran    = fnull_scalar;
66   PETSC_NULL_DOUBLE_Fortran    = fnull_double;
67   PETSC_NULL_REAL_Fortran      = fnull_real;
68   PETSC_NULL_OBJECT_Fortran    = fnull_object;
69   PETSC_NULL_BOOL_Fortran      = fnull_truth;
70   PETSC_NULL_FUNCTION_Fortran  = fnull_function;
71 }
72 
73 /*
74   A valid address for the fortran variable PETSC_NULL_FUNCTION
75 */
76 PETSC_EXTERN void petsc_null_function_(void)
77 {
78   return;
79 }
80 
81 
82