/* This file contains info for the use of PETSc Fortran interface stubs */ #include "petsc.h" #include "petscfix.h" EXTERN PetscErrorCode PetscScalarAddressToFortran(PetscObject,PetscInt,PetscScalar*,PetscScalar*,PetscInt,size_t*); EXTERN PetscErrorCode PetscScalarAddressFromFortran(PetscObject,PetscScalar*,size_t,PetscInt,PetscScalar **); EXTERN size_t PetscIntAddressToFortran(PetscInt*,PetscInt*); EXTERN PetscInt *PetscIntAddressFromFortran(PetscInt*,size_t); extern char *PETSC_NULL_CHARACTER_Fortran; extern void *PETSC_NULL_INTEGER_Fortran; extern void *PETSC_NULL_Fortran; extern void *PETSC_NULL_SCALAR_Fortran; extern void *PETSC_NULL_DOUBLE_Fortran; extern void *PETSC_NULL_REAL_Fortran; extern void *PETSC_NULL_OBJECT_Fortran; EXTERN_C_BEGIN extern void (*PETSC_NULL_FUNCTION_Fortran)(void); EXTERN_C_END /* ----------------------------------------------------------------------*/ /* We store each PETSc object C pointer directly as a Fortran integer*4 or *8 depending on the size of pointers. */ #define PetscFInt long #define PetscToPointer(a) (*(long *)(a)) #define PetscFromPointer(a) (long)(a) /* ----------------------------------------------------------------------*/ #define PetscToPointerComm(a) MPI_Comm_f2c(*(MPI_Fint *)(&a)) #define PetscFromPointerComm(a) MPI_Comm_c2f(a) /* --------------------------------------------------------------------*/ /* This lets us map the str-len argument either, immediately following the char argument (DVF on Win32) or at the end of the argument list (general unix compilers) */ #if defined(PETSC_HAVE_FORTRAN_MIXED_STR_ARG) #define PETSC_MIXED_LEN(len) ,int len #define PETSC_END_LEN(len) #else #define PETSC_MIXED_LEN(len) #define PETSC_END_LEN(len) ,int len #endif /* --------------------------------------------------------------------*/ /* This defines the mappings from Fortran character strings to C character strings on the Cray T3D. */ #if defined(PETSC_USES_CPTOFCD) #include #define CHAR _fcd #define FIXCHAR(a,n,b) \ { \ b = _fcdtocp(a); \ n = _fcdlen (a); \ if (b == PETSC_NULL_CHARACTER_Fortran) { \ b = 0; \ } else { \ while((n > 0) && (b[n-1] == ' ')) n--; \ *ierr = PetscMalloc((n+1)*sizeof(char),&b); \ if(*ierr) return; \ *ierr = PetscStrncpy(b,_fcdtocp(a),n); \ if(*ierr) return; \ b[n] = 0; \ } \ } #define FREECHAR(a,b) if (b) PetscFreeVoid(b); #define FIXRETURNCHAR(a,n) #else #define CHAR char* #define FIXCHAR(a,n,b) \ {\ if (a == PETSC_NULL_CHARACTER_Fortran) { \ b = a = 0; \ } else { \ while((n > 0) && (a[n-1] == ' ')) n--; \ *ierr = PetscMalloc((n+1)*sizeof(char),&b); \ if(*ierr) return; \ *ierr = PetscStrncpy(b,a,n); \ if(*ierr) return; \ b[n] = 0; \ } \ } #define FREECHAR(a,b) if (a != b) PetscFreeVoid(b); #define FIXRETURNCHAR(a,n) \ { \ int __i; \ for (__i=0; __i