xref: /petsc/src/sys/error/ftn-custom/zerrf.c (revision fa2bb9fe3cba50bac3b093e83d6f95e65b517df9)
1 #include <petsc/private/fortranimpl.h>
2 #include <petscsys.h>
3 #include <petscviewer.h>
4 
5 #if defined(PETSC_HAVE_FORTRAN_CAPS)
6 #define petscpusherrorhandler_        PETSCPUSHERRORHANDLER
7 #define petsctracebackerrorhandler_   PETSCTRACEBACKERRORHANDLER
8 #define petscaborterrorhandler_       PETSCABORTERRORHANDLER
9 #define petscignoreerrorhandler_      PETSCIGNOREERRORHANDLER
10 #define petscemacsclienterrorhandler_ PETSCEMACSCLIENTERRORHANDLER
11 #define petscattachdebuggererrorhandler_   PETSCATTACHDEBUGGERERRORHANDLER
12 #define petscerror_                PETSCERROR
13 #define petscerrorf_                PETSCERRORF
14 #define petscrealview_             PETSCREALVIEW
15 #define petscintview_              PETSCINTVIEW
16 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
17 #define petscpusherrorhandler_   petscpusherrorhandler
18 #define petsctracebackerrorhandler_   petsctracebackerrorhandler
19 #define petscaborterrorhandler_       petscaborterrorhandler
20 #define petscignoreerrorhandler_      petscignoreerrorhandler
21 #define petscemacsclienterrorhandler_ petscemacsclienterrorhandler
22 #define petscattachdebuggererrorhandler_   petscattachdebuggererrorhandler
23 #define petscerror_                petscerror
24 #define petscerrorf_                petscerrorf
25 #define petscrealview_             petscrealview
26 #define petscintview_              petscintview
27 #endif
28 
29 static void (PETSC_STDCALL *f2)(MPI_Comm *comm,int*,const char* PETSC_MIXED_LEN(len1),const char* PETSC_MIXED_LEN(len2),PetscErrorCode*,PetscErrorType*,const char* PETSC_MIXED_LEN(len3),void*,PetscErrorCode* PETSC_END_LEN(len1) PETSC_END_LEN(len2) PETSC_END_LEN(len3));
30 
31 /* These are not extern C because they are passed into non-extern C user level functions */
32 static PetscErrorCode ourerrorhandler(MPI_Comm comm,int line,const char *fun,const char *file,PetscErrorCode n,PetscErrorType p,const char *mess,void *ctx)
33 {
34   PetscErrorCode ierr = 0;
35   size_t         len1,len2,len3;
36 
37   PetscStrlen(fun,&len1);
38   PetscStrlen(file,&len2);
39   PetscStrlen(mess,&len3);
40 
41   (*f2)(&comm,&line,fun PETSC_MIXED_LEN_CALL(len1),file PETSC_MIXED_LEN_CALL(len2),&n,&p,mess PETSC_MIXED_LEN_CALL(len3),ctx,&ierr PETSC_END_LEN_CALL(len1) PETSC_END_LEN_CALL(len2) PETSC_END_LEN_CALL(len3));
42   return ierr;
43 }
44 
45 /*
46         These are not usually called from Fortran but allow Fortran users
47    to transparently set these monitors from .F code
48 
49    functions, hence no STDCALL
50 */
51 PETSC_EXTERN void petsctracebackerrorhandler_(MPI_Comm *comm,int *line,const char *fun,const char *file,PetscErrorCode *n,PetscErrorType *p,const char *mess,void *ctx,PetscErrorCode *ierr)
52 {
53   *ierr = PetscTraceBackErrorHandler(*comm,*line,fun,file,*n,*p,mess,ctx);
54 }
55 
56 PETSC_EXTERN void petscaborterrorhandler_(MPI_Comm *comm,int *line,const char *fun,const char *file,PetscErrorCode *n,PetscErrorType *p,const char *mess,void *ctx,PetscErrorCode *ierr)
57 {
58   *ierr = PetscAbortErrorHandler(*comm,*line,fun,file,*n,*p,mess,ctx);
59 }
60 
61 PETSC_EXTERN void petscattachdebuggererrorhandler_(MPI_Comm *comm,int *line,const char *fun,const char *file,PetscErrorCode *n,PetscErrorType *p,const char *mess,void *ctx,PetscErrorCode *ierr)
62 {
63   *ierr = PetscAttachDebuggerErrorHandler(*comm,*line,fun,file,*n,*p,mess,ctx);
64 }
65 
66 PETSC_EXTERN void petscemacsclienterrorhandler_(MPI_Comm *comm,int *line,const char *fun,const char *file,PetscErrorCode *n,PetscErrorType *p,const char *mess,void *ctx,PetscErrorCode *ierr)
67 {
68   *ierr = PetscEmacsClientErrorHandler(*comm,*line,fun,file,*n,*p,mess,ctx);
69 }
70 
71 PETSC_EXTERN void petscignoreerrorhandler_(MPI_Comm *comm,int *line,const char *fun,const char *file,PetscErrorCode *n,PetscErrorType *p,const char *mess,void *ctx,PetscErrorCode *ierr)
72 {
73   *ierr = PetscIgnoreErrorHandler(*comm,*line,fun,file,*n,*p,mess,ctx);
74 }
75 
76 PETSC_EXTERN void PETSC_STDCALL petscpusherrorhandler_(void (PETSC_STDCALL *handler)(MPI_Comm *comm,int*,const char* PETSC_MIXED_LEN(len1),const char* PETSC_MIXED_LEN(len2),PetscErrorCode*,PetscErrorType*,const char* PETSC_MIXED_LEN(len3),void*,PetscErrorCode* PETSC_END_LEN(len1) PETSC_END_LEN(len2) PETSC_END_LEN(len3)),void *ctx,PetscErrorCode *ierr)
77 {
78   if ((void(*)(void))handler == (void(*)(void))petsctracebackerrorhandler_) *ierr = PetscPushErrorHandler(PetscTraceBackErrorHandler,0);
79   else {
80     f2    = handler;
81     *ierr = PetscPushErrorHandler(ourerrorhandler,ctx);
82   }
83 }
84 
85 PETSC_EXTERN void PETSC_STDCALL petscerror_(MPI_Fint *comm,PetscErrorCode *number,PetscErrorType *p,char* message PETSC_MIXED_LEN(len) PETSC_END_LEN(len))
86 {
87   PetscErrorCode nierr,*ierr = &nierr;
88   char *t1;
89   FIXCHAR(message,len,t1);
90   nierr = PetscError(MPI_Comm_f2c(*(comm)),0,NULL,NULL,*number,*p,t1);
91   FREECHAR(message,t1);
92 }
93 
94 /* helper routine for CHKERRQ and CHKERRABORT macros on the fortran side */
95 PETSC_EXTERN void PETSC_STDCALL petscerrorf_(PetscErrorCode *number)
96 {
97   PetscError(PETSC_COMM_SELF,0,NULL,NULL,*number,PETSC_ERROR_REPEAT,NULL);
98 }
99 
100 PETSC_EXTERN void PETSC_STDCALL petscrealview_(PetscInt *n,PetscReal *d,PetscViewer *viwer,PetscErrorCode *ierr)
101 {
102   PetscViewer v;
103   PetscPatchDefaultViewers_Fortran(viwer,v);
104   *ierr = PetscRealView(*n,d,v);
105 }
106 
107 PETSC_EXTERN void PETSC_STDCALL petscintview_(PetscInt *n,PetscInt *d,PetscViewer *viwer,PetscErrorCode *ierr)
108 {
109   PetscViewer v;
110   PetscPatchDefaultViewers_Fortran(viwer,v);
111   *ierr = PetscIntView(*n,d,v);
112 }
113 
114 #if defined(PETSC_HAVE_FORTRAN_CAPS)
115 #define petscscalarview_             PETSCSCALARVIEW
116 #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
117 #define petscscalarview_             petscscalarview
118 #endif
119 
120 PETSC_EXTERN void PETSC_STDCALL petscscalarview_(PetscInt *n,PetscScalar *d,PetscViewer *viwer,PetscErrorCode *ierr)
121 {
122   PetscViewer v;
123   PetscPatchDefaultViewers_Fortran(viwer,v);
124   *ierr = PetscScalarView(*n,d,v);
125 }
126