xref: /petsc/src/mat/tests/ex173.c (revision 2f613bf53f46f9356e00a2ca2bd69453be72fc31)
1 static char help[] = "Test MatrixMarket outputting.\n\n";
2 
3 /*
4   Include "petscmat.h" so that we can use matrices.
5   automatically includes:
6      petscsys.h    - base PETSc routines   petscvec.h    - vectors
7      petscmat.h    - matrices
8      petscis.h     - index sets            petscviewer.h - viewers
9 */
10 
11 #include <petscmat.h>
12 
13 int main(int argc,char **args)
14 {
15   Mat            A;
16   PetscViewer    fd;                        /* viewer */
17   char           file[PETSC_MAX_PATH_LEN];  /* input file name */
18   PetscErrorCode ierr;
19   PetscBool      flg;
20 
21   ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr;
22   ierr = PetscOptionsGetString(NULL,NULL,"-f0",file,sizeof(file),&flg);CHKERRQ(ierr);
23   if (!flg) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_USER,"Must indicate binary file with the -f0 option");
24   ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);CHKERRQ(ierr);
25   ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
26   ierr = MatLoad(A,fd);CHKERRQ(ierr);
27   ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
28 
29   ierr = PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD,PETSC_VIEWER_ASCII_MATRIXMARKET);CHKERRQ(ierr);
30   ierr = MatView(A,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
31   ierr = PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
32   ierr = MatDestroy(&A);CHKERRQ(ierr);
33   ierr = PetscFinalize();
34   return ierr;
35 }
36 
37 /*TEST
38 
39    test:
40       args: -f0 ${wPETSC_DIR}/share/petsc/datafiles/matrices/ns-real-int32-float64
41       requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
42 
43 TEST*/
44