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 vectornn";

 8:  #include petscmat.h

 10: int main(int argc,char **args)
 11: {
 12:   int         ierr;
 13:   PetscTruth  flg;
 14:   Vec         x;
 15:   Mat         A;
 16:   char        file[256];
 17:   PetscViewer fd;

 19:   PetscInitialize(&argc,&args,(char *)0,help);

 21:   /* Read matrix and RHS */
 22:   PetscOptionsGetString(PETSC_NULL,"-fin",file,255,&flg);
 23:   if (!flg) SETERRQ(1,help);
 24:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,PETSC_BINARY_RDONLY,&fd);
 25:   MatLoad(fd,MATSEQAIJ,&A);
 26:   VecLoad(fd,&x);
 27:   PetscViewerDestroy(fd);

 29:   /* Write matrix and vector */
 30:   PetscOptionsGetString(PETSC_NULL,"-fout",file,255,&flg);
 31:   if (!flg) SETERRQ(1,help);
 32:   PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,PETSC_BINARY_CREATE,&fd);
 33:   MatView(A,fd);
 34:   VecView(x,fd);

 36:   /* Free data structures */
 37:   MatDestroy(A);
 38:   VecDestroy(x);
 39:   PetscViewerDestroy(fd);

 41:   PetscFinalize();
 42:   return 0;
 43: }