xref: /petsc/src/sys/classes/viewer/impls/ascii/ftn-custom/zfilevf.c (revision 1c29782424b0471dc8dc88c93721450c93069e6f)
1af0996ceSBarry Smith #include <petsc/private/fortranimpl.h>
2665c2dedSJed Brown #include <petscviewer.h>
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith #if defined(PETSC_HAVE_FORTRAN_CAPS)
55c6c1daeSBarry Smith #define petscviewerfilesetname_                PETSCVIEWERFILESETNAME
6df863907SAlex Fikl #define petscviewerfilegetname_                PETSCVIEWERFILEGETNAME
75c6c1daeSBarry Smith #define petscviewerasciiprintf_                PETSCVIEWERASCIIPRINTF
8*1c297824SMatthew G. Knepley #define petscviewerasciipushtab_               PETSCVIEWERASCIIPUSHTAB
9*1c297824SMatthew G. Knepley #define petscviewerasciipoptab_                PETSCVIEWERASCIIPOPTAB
105c6c1daeSBarry Smith #define petscviewerasciisynchronizedprintf_    PETSCVIEWERASCIISYNCHRONIZEDPRINTF
1160cf285bSSatish Balay #define petscviewerasciipushsynchronized_      PETSCVIEWERASCIIPUSHSYNCHRONIZED
1260cf285bSSatish Balay #define petscviewerasciipopsynchronized_       PETSCVIEWERASCIIPOPSYNCHRONIZED
135c6c1daeSBarry Smith #elif !defined(PETSC_HAVE_FORTRAN_UNDERSCORE)
145c6c1daeSBarry Smith #define petscviewerfilesetname_                petscviewerfilesetname
15df863907SAlex Fikl #define petscviewerfilegetname_                petscviewerfilegetname
165c6c1daeSBarry Smith #define petscviewerasciiprintf_                petscviewerasciiprintf
17*1c297824SMatthew G. Knepley #define petscviewerasciipushtab_               petscviewerasciipushtab
18*1c297824SMatthew G. Knepley #define petscviewerasciipoptab_                petscviewerasciipoptab
195c6c1daeSBarry Smith #define petscviewerasciisynchronizedprintf_    petscviewerasciisynchronizedprintf
201575c14dSBarry Smith #define petscviewerasciipushsynchronized_      petscviewerasciipushsynchronized
211575c14dSBarry Smith #define petscviewerasciipopsynchronized_       petscviewerasciipopsynchronized
225c6c1daeSBarry Smith #endif
235c6c1daeSBarry Smith 
24390e1bf2SBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerfilesetname_(PetscViewer *viewer,char* name PETSC_MIXED_LEN(len),PetscErrorCode *ierr PETSC_END_LEN(len))
255c6c1daeSBarry Smith {
265c6c1daeSBarry Smith   char        *c1;
275c6c1daeSBarry Smith   PetscViewer v;
285c6c1daeSBarry Smith   PetscPatchDefaultViewers_Fortran(viewer,v);
295c6c1daeSBarry Smith   FIXCHAR(name,len,c1);
305c6c1daeSBarry Smith   *ierr = PetscViewerFileSetName(v,c1);
315c6c1daeSBarry Smith   FREECHAR(name,c1);
325c6c1daeSBarry Smith }
335c6c1daeSBarry Smith 
34390e1bf2SBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerfilegetname_(PetscViewer *viewer, char* name PETSC_MIXED_LEN(len), PetscErrorCode *ierr PETSC_END_LEN(len))
35df863907SAlex Fikl {
36df863907SAlex Fikl    const char *c1;
37df863907SAlex Fikl 
38df863907SAlex Fikl    *ierr = PetscViewerGetType(*viewer, &c1);
39df863907SAlex Fikl    *ierr = PetscStrncpy(name, c1, len);
40df863907SAlex Fikl    FIXRETURNCHAR(PETSC_TRUE, name, len);
41df863907SAlex Fikl }
42df863907SAlex Fikl 
435c6c1daeSBarry Smith static PetscErrorCode PetscFixSlashN(const char *in, char **out)
445c6c1daeSBarry Smith {
455c6c1daeSBarry Smith   PetscErrorCode ierr;
465c6c1daeSBarry Smith   PetscInt       i;
475c6c1daeSBarry Smith   size_t         len;
485c6c1daeSBarry Smith 
495c6c1daeSBarry Smith   PetscFunctionBegin;
505c6c1daeSBarry Smith   ierr = PetscStrallocpy(in,out);CHKERRQ(ierr);
515c6c1daeSBarry Smith   ierr = PetscStrlen(*out,&len);CHKERRQ(ierr);
525c6c1daeSBarry Smith   for (i=0; i<(int)len-1; i++) {
535c6c1daeSBarry Smith     if ((*out)[i] == '\\' && (*out)[i+1] == 'n') {(*out)[i] = ' '; (*out)[i+1] = '\n';}
545c6c1daeSBarry Smith   }
555c6c1daeSBarry Smith   PetscFunctionReturn(0);
565c6c1daeSBarry Smith }
575c6c1daeSBarry Smith 
58390e1bf2SBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerasciiprintf_(PetscViewer *viewer,char* str PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
595c6c1daeSBarry Smith {
605c6c1daeSBarry Smith   char        *c1, *tmp;
615c6c1daeSBarry Smith   PetscViewer v;
625c6c1daeSBarry Smith 
635c6c1daeSBarry Smith   PetscPatchDefaultViewers_Fortran(viewer,v);
645c6c1daeSBarry Smith   FIXCHAR(str,len1,c1);
655c6c1daeSBarry Smith   *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
665c6c1daeSBarry Smith   FREECHAR(str,c1);
678bceffaeSBarry Smith   *ierr = PetscViewerASCIIPrintf(v,tmp);if (*ierr) return;
688bceffaeSBarry Smith   *ierr = PetscFree(tmp);
695c6c1daeSBarry Smith }
705c6c1daeSBarry Smith 
71*1c297824SMatthew G. Knepley PETSC_EXTERN void PETSC_STDCALL petscviewerasciipushtab_(PetscViewer *viewer,PetscErrorCode *ierr)
72*1c297824SMatthew G. Knepley {
73*1c297824SMatthew G. Knepley   PetscViewer v;
74*1c297824SMatthew G. Knepley   PetscPatchDefaultViewers_Fortran(viewer,v);
75*1c297824SMatthew G. Knepley   *ierr = PetscViewerASCIIPushTab(v);
76*1c297824SMatthew G. Knepley }
77*1c297824SMatthew G. Knepley 
78*1c297824SMatthew G. Knepley PETSC_EXTERN void PETSC_STDCALL petscviewerasciipoptab_(PetscViewer *viewer,PetscErrorCode *ierr)
79*1c297824SMatthew G. Knepley {
80*1c297824SMatthew G. Knepley   PetscViewer v;
81*1c297824SMatthew G. Knepley   PetscPatchDefaultViewers_Fortran(viewer,v);
82*1c297824SMatthew G. Knepley   *ierr = PetscViewerASCIIPopTab(v);
83*1c297824SMatthew G. Knepley }
84*1c297824SMatthew G. Knepley 
85390e1bf2SBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerasciisynchronizedprintf_(PetscViewer *viewer,char* str PETSC_MIXED_LEN(len1),PetscErrorCode *ierr PETSC_END_LEN(len1))
865c6c1daeSBarry Smith {
875c6c1daeSBarry Smith   char        *c1, *tmp;
885c6c1daeSBarry Smith   PetscViewer v;
895c6c1daeSBarry Smith 
905c6c1daeSBarry Smith   PetscPatchDefaultViewers_Fortran(viewer,v);
915c6c1daeSBarry Smith   FIXCHAR(str,len1,c1);
925c6c1daeSBarry Smith   *ierr = PetscFixSlashN(c1,&tmp);if (*ierr) return;
935c6c1daeSBarry Smith   FREECHAR(str,c1);
948bceffaeSBarry Smith   *ierr = PetscViewerASCIISynchronizedPrintf(v,tmp);if (*ierr) return;
958bceffaeSBarry Smith   *ierr = PetscFree(tmp);
965c6c1daeSBarry Smith }
975c6c1daeSBarry Smith 
981575c14dSBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerasciipushsynchronized_(PetscViewer *viewer,PetscErrorCode *ierr)
995c6c1daeSBarry Smith {
1005c6c1daeSBarry Smith   PetscViewer v;
1015c6c1daeSBarry Smith 
1025c6c1daeSBarry Smith   PetscPatchDefaultViewers_Fortran(viewer,v);
1031575c14dSBarry Smith   *ierr = PetscViewerASCIIPushSynchronized(v);
1041575c14dSBarry Smith }
1051575c14dSBarry Smith 
1061575c14dSBarry Smith PETSC_EXTERN void PETSC_STDCALL petscviewerasciipopsynchronized_(PetscViewer *viewer,PetscErrorCode *ierr)
1071575c14dSBarry Smith {
1081575c14dSBarry Smith   PetscViewer v;
1091575c14dSBarry Smith 
1101575c14dSBarry Smith   PetscPatchDefaultViewers_Fortran(viewer,v);
1111575c14dSBarry Smith   *ierr = PetscViewerASCIIPopSynchronized(v);
1125c6c1daeSBarry Smith }
113