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