Actual source code: ex34.c
1: /*$Id: ex34.c,v 1.17 2001/04/10 19:35:44 bsmith Exp $*/
3: static char help[] = "Reads a matrix and vector from a file and writes to another. Input options:\n\
4: -fin <input_file> : file to load. For an example of a 5X5 5-pt. stencil,\n\
5: use the file matbinary.ex.\n\
6: -fout <output_file> : file for saving output matrix and vector\n\n";
8: #include petscmat.h
12: int main(int argc,char **args)
13: {
14: int ierr;
15: PetscTruth flg;
16: Vec x;
17: Mat A;
18: char file[256];
19: PetscViewer fd;
21: PetscInitialize(&argc,&args,(char *)0,help);
23: /* Read matrix and RHS */
24: PetscOptionsGetString(PETSC_NULL,"-fin",file,255,&flg);
25: if (!flg) SETERRQ(1,help);
26: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,PETSC_FILE_RDONLY,&fd);
27: MatLoad(fd,MATSEQAIJ,&A);
28: VecLoad(fd,PETSC_NULL,&x);
29: PetscViewerDestroy(fd);
31: /* Write matrix and vector */
32: PetscOptionsGetString(PETSC_NULL,"-fout",file,255,&flg);
33: if (!flg) SETERRQ(1,help);
34: PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,PETSC_FILE_CREATE,&fd);
35: MatView(A,fd);
36: VecView(x,fd);
38: /* Free data structures */
39: MatDestroy(A);
40: VecDestroy(x);
41: PetscViewerDestroy(fd);
43: PetscFinalize();
44: return 0;
45: }