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 81c297824SMatthew G. Knepley #define petscviewerasciipushtab_ PETSCVIEWERASCIIPUSHTAB 91c297824SMatthew 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 171c297824SMatthew G. Knepley #define petscviewerasciipushtab_ petscviewerasciipushtab 181c297824SMatthew 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 2419caf8f3SSatish Balay PETSC_EXTERN void petscviewerfilesetname_(PetscViewer *viewer, char *name, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len) 255c6c1daeSBarry Smith { 265c6c1daeSBarry Smith char *c1; 275c6c1daeSBarry Smith PetscViewer v; 285c6c1daeSBarry Smith PetscPatchDefaultViewers_Fortran(viewer, v); 295c6c1daeSBarry Smith FIXCHAR(name, len, c1); 30*5975b3b6SBarry Smith *ierr = PetscViewerFileSetName(v, c1); 31*5975b3b6SBarry Smith if (*ierr) return; 325c6c1daeSBarry Smith FREECHAR(name, c1); 335c6c1daeSBarry Smith } 345c6c1daeSBarry Smith 3519caf8f3SSatish Balay PETSC_EXTERN void petscviewerfilegetname_(PetscViewer *viewer, char *name, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len) 36df863907SAlex Fikl { 37df863907SAlex Fikl const char *c1; 38df863907SAlex Fikl 39*5975b3b6SBarry Smith *ierr = PetscViewerGetType(*viewer, &c1); 40*5975b3b6SBarry Smith if (*ierr) return; 41*5975b3b6SBarry Smith *ierr = PetscStrncpy(name, c1, len); 42*5975b3b6SBarry Smith if (*ierr) return; 43df863907SAlex Fikl FIXRETURNCHAR(PETSC_TRUE, name, len); 44df863907SAlex Fikl } 45df863907SAlex Fikl 465c6c1daeSBarry Smith static PetscErrorCode PetscFixSlashN(const char *in, char **out) 475c6c1daeSBarry Smith { 485c6c1daeSBarry Smith PetscInt i; 495c6c1daeSBarry Smith size_t len; 505c6c1daeSBarry Smith 515c6c1daeSBarry Smith PetscFunctionBegin; 529566063dSJacob Faibussowitsch PetscCall(PetscStrallocpy(in, out)); 539566063dSJacob Faibussowitsch PetscCall(PetscStrlen(*out, &len)); 545c6c1daeSBarry Smith for (i = 0; i < (int)len - 1; i++) { 55*5975b3b6SBarry Smith if ((*out)[i] == '\\' && (*out)[i + 1] == 'n') { 56*5975b3b6SBarry Smith (*out)[i] = ' '; 57*5975b3b6SBarry Smith (*out)[i + 1] = '\n'; 58*5975b3b6SBarry Smith } 595c6c1daeSBarry Smith } 603ba16761SJacob Faibussowitsch PetscFunctionReturn(PETSC_SUCCESS); 615c6c1daeSBarry Smith } 625c6c1daeSBarry Smith 6319caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciiprintf_(PetscViewer *viewer, char *str, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len1) 645c6c1daeSBarry Smith { 655c6c1daeSBarry Smith char *c1, *tmp; 665c6c1daeSBarry Smith PetscViewer v; 675c6c1daeSBarry Smith 685c6c1daeSBarry Smith PetscPatchDefaultViewers_Fortran(viewer, v); 695c6c1daeSBarry Smith FIXCHAR(str, len1, c1); 70*5975b3b6SBarry Smith *ierr = PetscFixSlashN(c1, &tmp); 71*5975b3b6SBarry Smith if (*ierr) return; 725c6c1daeSBarry Smith FREECHAR(str, c1); 73*5975b3b6SBarry Smith *ierr = PetscViewerASCIIPrintf(v, "%s", tmp); 74*5975b3b6SBarry Smith if (*ierr) return; 758bceffaeSBarry Smith *ierr = PetscFree(tmp); 765c6c1daeSBarry Smith } 775c6c1daeSBarry Smith 7819caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciipushtab_(PetscViewer *viewer, PetscErrorCode *ierr) 791c297824SMatthew G. Knepley { 801c297824SMatthew G. Knepley PetscViewer v; 811c297824SMatthew G. Knepley PetscPatchDefaultViewers_Fortran(viewer, v); 821c297824SMatthew G. Knepley *ierr = PetscViewerASCIIPushTab(v); 831c297824SMatthew G. Knepley } 841c297824SMatthew G. Knepley 8519caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciipoptab_(PetscViewer *viewer, PetscErrorCode *ierr) 861c297824SMatthew G. Knepley { 871c297824SMatthew G. Knepley PetscViewer v; 881c297824SMatthew G. Knepley PetscPatchDefaultViewers_Fortran(viewer, v); 891c297824SMatthew G. Knepley *ierr = PetscViewerASCIIPopTab(v); 901c297824SMatthew G. Knepley } 911c297824SMatthew G. Knepley 9219caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciisynchronizedprintf_(PetscViewer *viewer, char *str, PetscErrorCode *ierr, PETSC_FORTRAN_CHARLEN_T len1) 935c6c1daeSBarry Smith { 945c6c1daeSBarry Smith char *c1, *tmp; 955c6c1daeSBarry Smith PetscViewer v; 965c6c1daeSBarry Smith 975c6c1daeSBarry Smith PetscPatchDefaultViewers_Fortran(viewer, v); 985c6c1daeSBarry Smith FIXCHAR(str, len1, c1); 99*5975b3b6SBarry Smith *ierr = PetscFixSlashN(c1, &tmp); 100*5975b3b6SBarry Smith if (*ierr) return; 1015c6c1daeSBarry Smith FREECHAR(str, c1); 102*5975b3b6SBarry Smith *ierr = PetscViewerASCIISynchronizedPrintf(v, "%s", tmp); 103*5975b3b6SBarry Smith if (*ierr) return; 1048bceffaeSBarry Smith *ierr = PetscFree(tmp); 1055c6c1daeSBarry Smith } 1065c6c1daeSBarry Smith 10719caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciipushsynchronized_(PetscViewer *viewer, PetscErrorCode *ierr) 1085c6c1daeSBarry Smith { 1095c6c1daeSBarry Smith PetscViewer v; 1105c6c1daeSBarry Smith 1115c6c1daeSBarry Smith PetscPatchDefaultViewers_Fortran(viewer, v); 1121575c14dSBarry Smith *ierr = PetscViewerASCIIPushSynchronized(v); 1131575c14dSBarry Smith } 1141575c14dSBarry Smith 11519caf8f3SSatish Balay PETSC_EXTERN void petscviewerasciipopsynchronized_(PetscViewer *viewer, PetscErrorCode *ierr) 1161575c14dSBarry Smith { 1171575c14dSBarry Smith PetscViewer v; 1181575c14dSBarry Smith 1191575c14dSBarry Smith PetscPatchDefaultViewers_Fortran(viewer, v); 1201575c14dSBarry Smith *ierr = PetscViewerASCIIPopSynchronized(v); 1215c6c1daeSBarry Smith } 122