xref: /petsc/src/sys/classes/viewer/impls/ascii/vcreatea.c (revision 9566063d113dddea24716c546802770db7481bc0)
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 
265c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDOUT_WORLD,
275c6c1daeSBarry Smith           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;
36*9566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStdout));
37*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&ncomm,NULL));
38e2dcd6d3SBarry Smith   if (Petsc_Viewer_Stdout_keyval == MPI_KEYVAL_INVALID) {
39*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Stdout_keyval,NULL));
40e2dcd6d3SBarry Smith   }
41*9566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm,Petsc_Viewer_Stdout_keyval,(void**)viewer,(PetscMPIInt*)&flg));
42e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
43*9566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm,"stdout",viewer));
44*9566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
45*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm,Petsc_Viewer_Stdout_keyval,(void*)*viewer));
46e2dcd6d3SBarry Smith   }
47*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
48*9566063dSJacob 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 
685c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDOUT_WORLD,
695c6c1daeSBarry Smith           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 
1055c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_(), PetscViewerASCIIOpen(), PETSC_VIEWER_STDERR_, PETSC_VIEWER_STDERR_WORLD,
1065c6c1daeSBarry Smith           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;
115*9566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockStderr));
116*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&ncomm,NULL));
117e2dcd6d3SBarry Smith   if (Petsc_Viewer_Stderr_keyval == MPI_KEYVAL_INVALID) {
118*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_create_keyval(MPI_COMM_NULL_COPY_FN,MPI_COMM_NULL_DELETE_FN,&Petsc_Viewer_Stderr_keyval,NULL));
119e2dcd6d3SBarry Smith   }
120*9566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(ncomm,Petsc_Viewer_Stderr_keyval,(void**)viewer,(PetscMPIInt*)&flg));
121e2dcd6d3SBarry Smith   if (!flg) { /* PetscViewer not yet created */
122*9566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIOpen(ncomm,"stderr",viewer));
123*9566063dSJacob Faibussowitsch     PetscCall(PetscObjectRegisterDestroy((PetscObject)*viewer));
124*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(ncomm,Petsc_Viewer_Stderr_keyval,(void*)*viewer));
125e2dcd6d3SBarry Smith   }
126*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&ncomm));
127*9566063dSJacob 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 
1475c6c1daeSBarry Smith .seealso: PETSC_VIEWER_DRAW_, PetscViewerASCIIOpen(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDOUT_WORLD,
1485c6c1daeSBarry Smith           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;
172*9566063dSJacob 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 
209f8859db6SBarry Smith .seealso: MatView(), VecView(), PetscViewerDestroy(), PetscViewerBinaryOpen(), PetscViewerASCIIRead()
2106a9046bcSBarry Smith           PetscViewerASCIIGetPointer(), PetscViewerPushFormat(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDERR_,
2115c6c1daeSBarry Smith           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;
220*9566063dSJacob Faibussowitsch   PetscCall(PetscStrlen(name,&len));
2215c6c1daeSBarry Smith   if (!len) {
222*9566063dSJacob Faibussowitsch     PetscCall(PetscViewerASCIIGetStdout(comm,lab));
223*9566063dSJacob Faibussowitsch     PetscCall(PetscObjectReference((PetscObject)*lab));
2245c6c1daeSBarry Smith     PetscFunctionReturn(0);
2255c6c1daeSBarry Smith   }
226*9566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockLock(&PetscViewerASCIISpinLockOpen));
2275c6c1daeSBarry Smith   if (Petsc_Viewer_keyval == MPI_KEYVAL_INVALID) {
228*9566063dSJacob 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 */
238*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDuplicate(comm,&comm,NULL));
2395c6c1daeSBarry Smith   /* has file already been opened into a viewer */
240*9566063dSJacob Faibussowitsch   PetscCallMPI(MPI_Comm_get_attr(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg));
2415c6c1daeSBarry Smith   if (flg) {
2425c6c1daeSBarry Smith     while (vlink) {
243*9566063dSJacob Faibussowitsch       PetscCall(PetscStrcmp(name,((PetscViewer_ASCII*)(vlink->viewer->data))->filename,&eq));
2445c6c1daeSBarry Smith       if (eq) {
245*9566063dSJacob Faibussowitsch         PetscCall(PetscObjectReference((PetscObject)vlink->viewer));
2465c6c1daeSBarry Smith         *lab = vlink->viewer;
247*9566063dSJacob Faibussowitsch         PetscCall(PetscCommDestroy(&comm));
248*9566063dSJacob Faibussowitsch         PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2495c6c1daeSBarry Smith         PetscFunctionReturn(0);
2505c6c1daeSBarry Smith       }
2515c6c1daeSBarry Smith       vlink = vlink->next;
2525c6c1daeSBarry Smith     }
2535c6c1daeSBarry Smith   }
254*9566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm,lab));
255*9566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab,PETSCVIEWERASCII));
2565c6c1daeSBarry Smith   if (name) {
257*9566063dSJacob Faibussowitsch     PetscCall(PetscViewerFileSetName(*lab,name));
2585c6c1daeSBarry Smith   }
2595c6c1daeSBarry Smith   /* save viewer into communicator if needed later */
260*9566063dSJacob Faibussowitsch   PetscCall(PetscNew(&nv));
2615c6c1daeSBarry Smith   nv->viewer = *lab;
2625c6c1daeSBarry Smith   if (!flg) {
263*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_set_attr(comm,Petsc_Viewer_keyval,nv));
2645c6c1daeSBarry Smith   } else {
265*9566063dSJacob Faibussowitsch     PetscCallMPI(MPI_Comm_get_attr(comm,Petsc_Viewer_keyval,(void**)&vlink,(PetscMPIInt*)&flg));
2665c6c1daeSBarry Smith     if (vlink) {
2675c6c1daeSBarry Smith       while (vlink->next) vlink = vlink->next;
2685c6c1daeSBarry Smith       vlink->next = nv;
2695c6c1daeSBarry Smith     } else {
270*9566063dSJacob Faibussowitsch       PetscCallMPI(MPI_Comm_set_attr(comm,Petsc_Viewer_keyval,nv));
2715c6c1daeSBarry Smith     }
2725c6c1daeSBarry Smith   }
273*9566063dSJacob Faibussowitsch   PetscCall(PetscCommDestroy(&comm));
274*9566063dSJacob Faibussowitsch   PetscCall(PetscSpinlockUnlock(&PetscViewerASCIISpinLockOpen));
2755c6c1daeSBarry Smith   PetscFunctionReturn(0);
2765c6c1daeSBarry Smith }
2775c6c1daeSBarry Smith 
2785c6c1daeSBarry Smith /*@C
2795c6c1daeSBarry Smith    PetscViewerASCIIOpenWithFILE - Given an open file creates an ASCII viewer that prints to it.
2805c6c1daeSBarry Smith 
281d083f849SBarry Smith    Collective
2825c6c1daeSBarry Smith 
2835c6c1daeSBarry Smith    Input Parameters:
2845c6c1daeSBarry Smith +  comm - the communicator
2855c6c1daeSBarry Smith -  fd - the FILE pointer
2865c6c1daeSBarry Smith 
2875c6c1daeSBarry Smith    Output Parameter:
2885c6c1daeSBarry Smith .  lab - the PetscViewer to use with the specified file
2895c6c1daeSBarry Smith 
2905c6c1daeSBarry Smith    Level: beginner
2915c6c1daeSBarry Smith 
2925c6c1daeSBarry Smith    Notes:
2935c6c1daeSBarry Smith    This PetscViewer can be destroyed with PetscViewerDestroy(), but the fd will NOT be closed.
2945c6c1daeSBarry Smith 
2955c6c1daeSBarry Smith    If a multiprocessor communicator is used (such as PETSC_COMM_WORLD),
2965c6c1daeSBarry Smith    then only the first processor in the group uses the file.  All other
2975c6c1daeSBarry Smith    processors send their data to the first processor to print.
2985c6c1daeSBarry Smith 
2995c6c1daeSBarry Smith .seealso: MatView(), VecView(), PetscViewerDestroy(), PetscViewerBinaryOpen(),
3006a9046bcSBarry Smith           PetscViewerASCIIGetPointer(), PetscViewerPushFormat(), PETSC_VIEWER_STDOUT_, PETSC_VIEWER_STDERR_,
3015c6c1daeSBarry Smith           PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_STDOUT_SELF, PetscViewerASCIIOpen()
3025c6c1daeSBarry Smith @*/
3035c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIIOpenWithFILE(MPI_Comm comm,FILE *fd,PetscViewer *lab)
3045c6c1daeSBarry Smith {
3055c6c1daeSBarry Smith   PetscFunctionBegin;
306*9566063dSJacob Faibussowitsch   PetscCall(PetscViewerCreate(comm,lab));
307*9566063dSJacob Faibussowitsch   PetscCall(PetscViewerSetType(*lab,PETSCVIEWERASCII));
308*9566063dSJacob Faibussowitsch   PetscCall(PetscViewerASCIISetFILE(*lab,fd));
3095c6c1daeSBarry Smith   PetscFunctionReturn(0);
3105c6c1daeSBarry Smith }
3115c6c1daeSBarry Smith 
3125c6c1daeSBarry Smith PetscErrorCode  PetscViewerASCIISetFILE(PetscViewer viewer,FILE *fd)
3135c6c1daeSBarry Smith {
3145c6c1daeSBarry Smith   PetscViewer_ASCII *vascii = (PetscViewer_ASCII*)viewer->data;
3155c6c1daeSBarry Smith 
3165c6c1daeSBarry Smith   PetscFunctionBegin;
3175c6c1daeSBarry Smith   vascii->fd        = fd;
3185c6c1daeSBarry Smith   vascii->closefile = PETSC_FALSE;
3195c6c1daeSBarry Smith   PetscFunctionReturn(0);
3205c6c1daeSBarry Smith }
321