xref: /petsc/src/sys/ftn-custom/zsys.c (revision a2fddd78f770fa4fc19a8af67e65be331f27d92b)
1 
2 #include <petsc/private/fortranimpl.h>
3 
4 #if defined(PETSC_HAVE_FORTRAN_CAPS)
5 #define chkmemfortran_              CHKMEMFORTRAN
6 #define petscoffsetfortran_         PETSCOFFSETFORTRAN
7 #define petscobjectstateincrease_   PETSCOBJECTSTATEINCREASE
8 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
9 #define petscoffsetfortran_         petscoffsetfortran
10 #define chkmemfortran_              chkmemfortran
11 #define flush__                     flush_
12 #define petscobjectstateincrease_   petscobjectstateincrease
13 #endif
14 
15 PETSC_EXTERN void petscobjectstateincrease_(PetscObject *obj, PetscErrorCode *ierr)
16 {
17   *ierr = PetscObjectStateIncrease(*obj);
18 }
19 
20 #if defined(PETSC_MISSING_FORTRAN_FLUSH_)
21 void flush__(int unit)
22 {
23 }
24 #endif
25 
26 PETSC_EXTERN void petscoffsetfortran_(PetscScalar *x,PetscScalar *y,size_t *shift,PetscErrorCode *ierr)
27 {
28   *ierr  = 0;
29   *shift = y - x;
30 }
31 
32 /* ---------------------------------------------------------------------------------*/
33 /*
34         This version does not do a malloc
35 */
36 static char FIXCHARSTRING[1024];
37 
38 #define FIXCHARNOMALLOC(a,n,b) \
39 {\
40   if (a == PETSC_NULL_CHARACTER_Fortran) { \
41     b = a = 0; \
42   } else { \
43     while ((n > 0) && (a[n-1] == ' ')) n--; \
44     if (a[n] != 0) { \
45       b = FIXCHARSTRING; \
46       *ierr = PetscStrncpy(b,a,n+1); \
47       if (*ierr) return; \
48     } else b = a;\
49   } \
50 }
51 
52 PETSC_EXTERN void chkmemfortran_(int *line,char* file,PetscErrorCode *ierr,PETSC_FORTRAN_CHARLEN_T len)
53 {
54   char *c1;
55 
56   FIXCHARNOMALLOC(file,len,c1);
57   *ierr = PetscMallocValidate(*line,"Userfunction",c1);
58 }
59 
60