xref: /petsc/src/sys/classes/viewer/impls/ascii/vcreatea.c (revision 1baa6e3354bfe224b33a0c158f482508792a8a6e)
15c6c1daeSBarry Smith 
2f5860696SSatish Balay #include <../src/sys/classes/viewer/impls/ascii/asciiimpl.h>  /*I     "petscviewer.h"   I*/
35c6c1daeSBarry Smith 
45c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
55c6c1daeSBarry Smith 
6e2dcd6d3SBarry Smith /*
7e2dcd6d3SBarry Smith     The variable Petsc_Viewer_Stdout_keyval is used to indicate an MPI attribute that
8e2dcd6d3SBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
9e2dcd6d3SBarry Smith */
10d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Stdout_keyval = MPI_KEYVAL_INVALID;
11e2dcd6d3SBarry Smith 
129c5ded49SBarry Smith /*@
135c6c1daeSBarry Smith    PetscViewerASCIIGetStdout - Creates a ASCII PetscViewer shared by all processors
145c6c1daeSBarry Smith                     in a communicator. Error returning version of PETSC_VIEWER_STDOUT_()
155c6c1daeSBarry Smith 
16d083f849SBarry Smith    Collective
175c6c1daeSBarry Smith 
185c6c1daeSBarry Smith    Input Parameter:
195c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
205c6c1daeSBarry Smith 
215c6c1daeSBarry Smith    Level: beginner
225c6c1daeSBarry Smith 
235c6c1daeSBarry Smith    Notes:
245c6c1daeSBarry Smith      This should be used in all PETSc source code instead of PETSC_VIEWER_STDOUT_()
255c6c1daeSBarry Smith 
26db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDOUT_WORLD`,
27db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`
285c6c1daeSBarry Smith 
295c6c1daeSBarry Smith @*/
305c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIIGetStdout(MPI_Comm comm,PetscViewer *viewer)
315c6c1daeSBarry Smith {
32e2dcd6d3SBarry Smith   PetscBool      flg;
33e2dcd6d3SBarry Smith   MPI_Comm       ncomm;
345c6c1daeSBarry Smith 
355c6c1daeSBarry Smith   PetscFunctionBegin;
369566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStdout));
379566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&ncomm,NULL));
38e2dcd6d3SBarry Smith   if (Petsc_Viewer_Stdout_keyval == MPI_KEYVAL_INVALID) {
399566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Stdout_keyval,NULL));
40e2dcd6d3SBarry Smith   }
419566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm,Petsc_Viewer_Stdout_keyval,(void**)viewer,(PetscMPIInt*)&flg));
42e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
439566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm,"stdout",viewer));
449566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
459566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm,Petsc_Viewer_Stdout_keyval,(void*)*viewer));
46e2dcd6d3SBarry Smith   }
479566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
489566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockStdout));
495c6c1daeSBarry Smith   PetscFunctionReturn(0);
505c6c1daeSBarry Smith }
515c6c1daeSBarry Smith 
525c6c1daeSBarry Smith /*@C
535c6c1daeSBarry Smith    PETSC_VIEWER_STDOUT_ - Creates a ASCII PetscViewer shared by all processors
545c6c1daeSBarry Smith                     in a communicator.
555c6c1daeSBarry Smith 
56d083f849SBarry Smith    Collective
575c6c1daeSBarry Smith 
585c6c1daeSBarry Smith    Input Parameter:
595c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
605c6c1daeSBarry Smith 
615c6c1daeSBarry Smith    Level: beginner
625c6c1daeSBarry Smith 
635c6c1daeSBarry Smith    Notes:
645c6c1daeSBarry Smith    Unlike almost all other PETSc routines, this does not return
655c6c1daeSBarry Smith    an error code. Usually used in the form
665c6c1daeSBarry Smith $      XXXView(XXX object,PETSC_VIEWER_STDOUT_(comm));
675c6c1daeSBarry Smith 
68db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDOUT_WORLD`,
69db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`
705c6c1daeSBarry Smith 
715c6c1daeSBarry Smith @*/
725c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_STDOUT_(MPI_Comm comm)
735c6c1daeSBarry Smith {
745c6c1daeSBarry Smith   PetscErrorCode ierr;
755c6c1daeSBarry Smith   PetscViewer    viewer;
765c6c1daeSBarry Smith 
775c6c1daeSBarry Smith   PetscFunctionBegin;
785c6c1daeSBarry Smith   ierr = PetscViewerASCIIGetStdout(comm,&viewer);
7902c9f0b5SLisandro Dalcin   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_STDOUT_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," "); PetscFunctionReturn(NULL);}
805c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
815c6c1daeSBarry Smith }
825c6c1daeSBarry Smith 
835c6c1daeSBarry Smith /* ---------------------------------------------------------------------*/
845c6c1daeSBarry Smith 
85e2dcd6d3SBarry Smith /*
86e2dcd6d3SBarry Smith     The variable Petsc_Viewer_Stderr_keyval is used to indicate an MPI attribute that
87e2dcd6d3SBarry Smith   is attached to a communicator, in this case the attribute is a PetscViewer.
88e2dcd6d3SBarry Smith */
89d4c7638eSBarry Smith PetscMPIInt Petsc_Viewer_Stderr_keyval = MPI_KEYVAL_INVALID;
90e2dcd6d3SBarry Smith 
919c5ded49SBarry Smith /*@
925c6c1daeSBarry Smith    PetscViewerASCIIGetStderr - Creates a ASCII PetscViewer shared by all processors
935c6c1daeSBarry Smith                     in a communicator. Error returning version of PETSC_VIEWER_STDERR_()
945c6c1daeSBarry Smith 
95d083f849SBarry Smith    Collective
965c6c1daeSBarry Smith 
975c6c1daeSBarry Smith    Input Parameter:
985c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
995c6c1daeSBarry Smith 
1005c6c1daeSBarry Smith    Level: beginner
1015c6c1daeSBarry Smith 
1025c6c1daeSBarry Smith    Notes:
1035c6c1daeSBarry Smith      This should be used in all PETSc source code instead of PETSC_VIEWER_STDERR_()
1045c6c1daeSBarry Smith 
105db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_()`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDERR_`, `PETSC_VIEWER_STDERR_WORLD`,
106db781477SPatrick Sanan           `PETSC_VIEWER_STDERR_SELF`
1075c6c1daeSBarry Smith 
1085c6c1daeSBarry Smith @*/
1095c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIIGetStderr(MPI_Comm comm,PetscViewer *viewer)
1105c6c1daeSBarry Smith {
111e2dcd6d3SBarry Smith   PetscBool      flg;
112e2dcd6d3SBarry Smith   MPI_Comm       ncomm;
113e2dcd6d3SBarry Smith 
114e2dcd6d3SBarry Smith   PetscFunctionBegin;
1159566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStderr));
1169566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&ncomm,NULL));
117e2dcd6d3SBarry Smith   if (Petsc_Viewer_Stderr_keyval == MPI_KEYVAL_INVALID) {
1189566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Stderr_keyval,NULL));
119e2dcd6d3SBarry Smith   }
1209566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm,Petsc_Viewer_Stderr_keyval,(void**)viewer,(PetscMPIInt*)&flg));
121e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
1229566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm,"stderr",viewer));
1239566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
1249566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm,Petsc_Viewer_Stderr_keyval,(void*)*viewer));
125e2dcd6d3SBarry Smith   }
1269566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
1279566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockStderr));
1285c6c1daeSBarry Smith   PetscFunctionReturn(0);
1295c6c1daeSBarry Smith }
1305c6c1daeSBarry Smith 
1315c6c1daeSBarry Smith /*@C
1325c6c1daeSBarry Smith    PETSC_VIEWER_STDERR_ - Creates a ASCII PetscViewer shared by all processors
1335c6c1daeSBarry Smith                     in a communicator.
1345c6c1daeSBarry Smith 
135d083f849SBarry Smith    Collective
1365c6c1daeSBarry Smith 
1375c6c1daeSBarry Smith    Input Parameter:
1385c6c1daeSBarry Smith .  comm - the MPI communicator to share the PetscViewer
1395c6c1daeSBarry Smith 
1405c6c1daeSBarry Smith    Level: beginner
1415c6c1daeSBarry Smith 
1425c6c1daeSBarry Smith    Note:
1435c6c1daeSBarry Smith    Unlike almost all other PETSc routines, this does not return
1445c6c1daeSBarry Smith    an error code. Usually used in the form
1455c6c1daeSBarry Smith $      XXXView(XXX object,PETSC_VIEWER_STDERR_(comm));
1465c6c1daeSBarry Smith 
147db781477SPatrick Sanan .seealso: `PETSC_VIEWER_DRAW_`, `PetscViewerASCIIOpen()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDOUT_WORLD`,
148db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_SELF`, `PETSC_VIEWER_STDERR_WORLD`, `PETSC_VIEWER_STDERR_SELF`
1495c6c1daeSBarry Smith @*/
1505c6c1daeSBarry Smith PetscViewer  PETSC_VIEWER_STDERR_(MPI_Comm comm)
1515c6c1daeSBarry Smith {
1525c6c1daeSBarry Smith   PetscErrorCode ierr;
1535c6c1daeSBarry Smith   PetscViewer    viewer;
1545c6c1daeSBarry Smith 
1555c6c1daeSBarry Smith   PetscFunctionBegin;
1565c6c1daeSBarry Smith   ierr = PetscViewerASCIIGetStderr(comm,&viewer);
15702c9f0b5SLisandro Dalcin   if (ierr) {PetscError(PETSC_COMM_SELF,__LINE__,"PETSC_VIEWER_STDERR_",__FILE__,PETSC_ERR_PLIB,PETSC_ERROR_INITIAL," "); PetscFunctionReturn(NULL);}
1585c6c1daeSBarry Smith   PetscFunctionReturn(viewer);
1595c6c1daeSBarry Smith }
1605c6c1daeSBarry Smith 
1615c6c1daeSBarry Smith PetscMPIInt Petsc_Viewer_keyval = MPI_KEYVAL_INVALID;
1625c6c1daeSBarry Smith /*
1635c6c1daeSBarry Smith    Called with MPI_Comm_free() is called on a communicator that has a viewer as an attribute. The viewer is not actually destroyed because that is managed by
1645c6c1daeSBarry Smith    PetscObjectDestroyRegisterAll(). PetscViewerASCIIGetStdout() registers the viewer with PetscObjectDestroyRegister() to be destroyed when PetscFinalize() is called.
1655c6c1daeSBarry Smith 
1665c6c1daeSBarry Smith   This is called by MPI, not by users.
1675c6c1daeSBarry Smith 
1685c6c1daeSBarry Smith */
1698cc058d9SJed Brown PETSC_EXTERN PetscMPIInt MPIAPI Petsc_DelViewer(MPI_Comm comm,PetscMPIInt keyval,void *attr_val,void *extra_state)
1705c6c1daeSBarry Smith {
1715c6c1daeSBarry Smith   PetscFunctionBegin;
1729566063dSJacob Faibussowitsch   PetscCallMPI(PetscInfo(NULL,"Removing viewer data attribute in an MPI_Comm %ld\n",(long)comm));
1735c6c1daeSBarry Smith   PetscFunctionReturn(MPI_SUCCESS);
1745c6c1daeSBarry Smith }
1755c6c1daeSBarry Smith 
1765c6c1daeSBarry Smith /*@C
177f8859db6SBarry Smith    PetscViewerASCIIOpen - Opens an ASCII file for writing as a PetscViewer.
1785c6c1daeSBarry Smith 
179d083f849SBarry Smith    Collective
1805c6c1daeSBarry Smith 
1815c6c1daeSBarry Smith    Input Parameters:
1825c6c1daeSBarry Smith +  comm - the communicator
1835c6c1daeSBarry Smith -  name - the file name
1845c6c1daeSBarry Smith 
1855c6c1daeSBarry Smith    Output Parameter:
1865c6c1daeSBarry Smith .  lab - the PetscViewer to use with the specified file
1875c6c1daeSBarry Smith 
1885c6c1daeSBarry Smith    Level: beginner
1895c6c1daeSBarry Smith 
1905c6c1daeSBarry Smith    Notes:
191f8859db6SBarry Smith    To open a ASCII file as a viewer for reading one must use the sequence
192f8859db6SBarry Smith $     PetscViewerCreate(comm,&lab);
193f8859db6SBarry Smith $     PetscViewerSetType(lab,PETSCVIEWERASCII);
194f8859db6SBarry Smith $     PetscViewerFileSetMode(lab,FILE_MODE_READ);
195f8859db6SBarry Smith $     PetscViewerFileSetName(lab,name);
196f8859db6SBarry Smith 
1975c6c1daeSBarry Smith    This PetscViewer can be destroyed with PetscViewerDestroy().
1985c6c1daeSBarry Smith 
1992ea3bc1cSBarry Smith    The MPI communicator used here must match that used by the object one is viewing. For example if the
2002ea3bc1cSBarry Smith    Mat was created with a PETSC_COMM_WORLD, then the Viewer must be created with PETSC_COMM_WORLD
2015c6c1daeSBarry Smith 
2025c6c1daeSBarry Smith    As shown below, PetscViewerASCIIOpen() is useful in conjunction with
2035c6c1daeSBarry Smith    MatView() and VecView()
2045c6c1daeSBarry Smith .vb
2055c6c1daeSBarry Smith      PetscViewerASCIIOpen(PETSC_COMM_WORLD,"mat.output",&viewer);
2065c6c1daeSBarry Smith      MatView(matrix,viewer);
2075c6c1daeSBarry Smith .ve
2085c6c1daeSBarry Smith 
209db781477SPatrick Sanan .seealso: `MatView()`, `VecView()`, `PetscViewerDestroy()`, `PetscViewerBinaryOpen()`, `PetscViewerASCIIRead()`
210db781477SPatrick Sanan           `PetscViewerASCIIGetPointer()`, `PetscViewerPushFormat()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDERR_`,
211db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_WORLD`, `PETSC_VIEWER_STDOUT_SELF`,
2125c6c1daeSBarry Smith @*/
2135c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIIOpen(MPI_Comm comm,const char name[],PetscViewer *lab)
2145c6c1daeSBarry Smith {
2155c6c1daeSBarry Smith   PetscViewerLink *vlink,*nv;
2165c6c1daeSBarry Smith   PetscBool       flg,eq;
2175c6c1daeSBarry Smith   size_t          len;
2185c6c1daeSBarry Smith 
2195c6c1daeSBarry Smith   PetscFunctionBegin;
2209566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(name,&len));
2215c6c1daeSBarry Smith   if (!len) {
2229566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIGetStdout(comm,lab));
2239566063dSJacob Faibussowitsch     PetscCall(PetscObjectReference((PetscObject)*lab));
2245c6c1daeSBarry Smith     PetscFunctionReturn(0);
2255c6c1daeSBarry Smith   }
2269566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockOpen));
2275c6c1daeSBarry Smith   if (Petsc_Viewer_keyval == MPI_KEYVAL_INVALID) {
2289566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,Petsc_DelViewer,&Petsc_Viewer_keyval,(void*)0));
2295c6c1daeSBarry Smith   }
2302bf49c77SBarry Smith   /*
2312bf49c77SBarry Smith        It would be better to move this code to PetscFileSetName() but since it must return a preexiting communicator
2322bf49c77SBarry Smith      we cannot do that, since PetscFileSetName() takes a communicator that already exists.
2332bf49c77SBarry Smith 
2342bf49c77SBarry Smith       Plus if the original communicator that created the file has since been close this will not detect the old
2352bf49c77SBarry Smith       communictor and hence will overwrite the old data. It may be better to simply remove all this code
2362bf49c77SBarry Smith   */
2375c6c1daeSBarry Smith   /* make sure communicator is a PETSc communicator */
2389566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&comm,NULL));
2395c6c1daeSBarry Smith   /* has file already been opened into a viewer */
2409566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg));
2415c6c1daeSBarry Smith   if (flg) {
2425c6c1daeSBarry Smith     while (vlink) {
2439566063dSJacob Faibussowitsch       PetscCall(PetscStrcmp(name,((PetscViewer_ASCII*)(vlink->viewer->data))->filename,&eq));
2445c6c1daeSBarry Smith       if (eq) {
2459566063dSJacob Faibussowitsch         PetscCall(PetscObjectReference((PetscObject)vlink->viewer));
2465c6c1daeSBarry Smith         *lab = vlink->viewer;
2479566063dSJacob Faibussowitsch         PetscCall(PetscCommDestroy(&comm));
2489566063dSJacob Faibussowitsch         PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2495c6c1daeSBarry Smith         PetscFunctionReturn(0);
2505c6c1daeSBarry Smith       }
2515c6c1daeSBarry Smith       vlink = vlink->next;
2525c6c1daeSBarry Smith     }
2535c6c1daeSBarry Smith   }
2549566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm,lab));
2559566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab,PETSCVIEWERASCII));
256*1baa6e33SBarry Smith   if (name) PetscCall(PetscViewerFileSetName(*lab,name));
2575c6c1daeSBarry Smith   /* save viewer into communicator if needed later */
2589566063dSJacob Faibussowitsch   PetscCall(PetscNew(&nv));
2595c6c1daeSBarry Smith   nv->viewer = *lab;
2605c6c1daeSBarry Smith   if (!flg) {
2619566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(comm,Petsc_Viewer_keyval,nv));
2625c6c1daeSBarry Smith   } else {
2639566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_get_attr(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg));
2645c6c1daeSBarry Smith     if (vlink) {
2655c6c1daeSBarry Smith       while (vlink->next) vlink = vlink->next;
2665c6c1daeSBarry Smith       vlink->next = nv;
2675c6c1daeSBarry Smith     } else {
2689566063dSJacob Faibussowitsch       PetscCallMPI(MPI_Comm_set_attr(comm,Petsc_Viewer_keyval,nv));
2695c6c1daeSBarry Smith     }
2705c6c1daeSBarry Smith   }
2719566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&comm));
2729566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2735c6c1daeSBarry Smith   PetscFunctionReturn(0);
2745c6c1daeSBarry Smith }
2755c6c1daeSBarry Smith 
2765c6c1daeSBarry Smith /*@C
2775c6c1daeSBarry Smith    PetscViewerASCIIOpenWithFILE - Given an open file creates an ASCII viewer that prints to it.
2785c6c1daeSBarry Smith 
279d083f849SBarry Smith    Collective
2805c6c1daeSBarry Smith 
2815c6c1daeSBarry Smith    Input Parameters:
2825c6c1daeSBarry Smith +  comm - the communicator
2835c6c1daeSBarry Smith -  fd - the FILE pointer
2845c6c1daeSBarry Smith 
2855c6c1daeSBarry Smith    Output Parameter:
2865c6c1daeSBarry Smith .  lab - the PetscViewer to use with the specified file
2875c6c1daeSBarry Smith 
2885c6c1daeSBarry Smith    Level: beginner
2895c6c1daeSBarry Smith 
2905c6c1daeSBarry Smith    Notes:
2915c6c1daeSBarry Smith    This PetscViewer can be destroyed with PetscViewerDestroy(), but the fd will NOT be closed.
2925c6c1daeSBarry Smith 
2935c6c1daeSBarry Smith    If a multiprocessor communicator is used (such as PETSC_COMM_WORLD),
2945c6c1daeSBarry Smith    then only the first processor in the group uses the file.  All other
2955c6c1daeSBarry Smith    processors send their data to the first processor to print.
2965c6c1daeSBarry Smith 
297db781477SPatrick Sanan .seealso: `MatView()`, `VecView()`, `PetscViewerDestroy()`, `PetscViewerBinaryOpen()`,
298db781477SPatrick Sanan           `PetscViewerASCIIGetPointer()`, `PetscViewerPushFormat()`, `PETSC_VIEWER_STDOUT_`, `PETSC_VIEWER_STDERR_`,
299db781477SPatrick Sanan           `PETSC_VIEWER_STDOUT_WORLD`, `PETSC_VIEWER_STDOUT_SELF`, `PetscViewerASCIIOpen()`
3005c6c1daeSBarry Smith @*/
3015c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIIOpenWithFILE(MPI_Comm comm,FILE *fd,PetscViewer *lab)
3025c6c1daeSBarry Smith {
3035c6c1daeSBarry Smith   PetscFunctionBegin;
3049566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm,lab));
3059566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab,PETSCVIEWERASCII));
3069566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIISetFILE(*lab,fd));
3075c6c1daeSBarry Smith   PetscFunctionReturn(0);
3085c6c1daeSBarry Smith }
3095c6c1daeSBarry Smith 
3105c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIISetFILE(PetscViewer viewer,FILE *fd)
3115c6c1daeSBarry Smith {
3125c6c1daeSBarry Smith   PetscViewer_ASCII *vascii = (PetscViewer_ASCII*)viewer->data;
3135c6c1daeSBarry Smith 
3145c6c1daeSBarry Smith   PetscFunctionBegin;
3155c6c1daeSBarry Smith   vascii->fd        = fd;
3165c6c1daeSBarry Smith   vascii->closefile = PETSC_FALSE;
3175c6c1daeSBarry Smith   PetscFunctionReturn(0);
3185c6c1daeSBarry Smith }
319