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