Actual source code: ex20.F

  1: !
  2: !    "$Id: ex20.F,v 1.13 2001/08/07 03:02:26 balay Exp $";
  3: !
  4:       program main
  5:       implicit none
 6:  #include include/finclude/petsc.h
 7:  #include include/finclude/petscsys.h
 8:  #include include/finclude/petscvec.h
 9:  #include include/finclude/petscviewer.h
 10: !
 11: !  This example demonstrates writing an array to a file in binary format
 12: !  that may be read in by PETSc's VecLoad() routine.
 13: !
 14:        integer          n,ierr,i,fd,veccookie(1)
 15:        PetscScalar      array(5)
 16:        Vec              x
 17:        PetscViewer           v

 19:        n            = 5
 20:        veccookie(1) = 1211211 + 3

 22:        call PetscInitialize(PETSC_NULL_CHARACTER,ierr)

 24:        do 10, i=1,5
 25:          array(i) = i
 26:  10    continue

 28: !   Open binary file for writing
 29:        call PetscBinaryOpen('testfile',PETSC_BINARY_CREATE,fd,ierr)
 30: !   Write the Vec header
 31:        call PetscBinaryWrite(fd,veccookie,1,PETSC_INT,0,ierr)
 32: !   Write the array length
 33:        call PetscBinaryWrite(fd,n,1,PETSC_INT,0,ierr)
 34: !   Write the array
 35:        call PetscBinaryWrite(fd,array,n,PETSC_DOUBLE,0,ierr)
 36: !   Close the file
 37:        call PetscBinaryClose(fd,ierr)

 39: !
 40: !  Open the file for reading by PETSc
 41: !
 42:        call PetscViewerBinaryOpen(PETSC_COMM_SELF,'testfile',                &
 43:      &                       PETSC_BINARY_RDONLY,v,ierr)
 44: !
 45: !  Load the vector
 46: !
 47:        Call VecLoad(v,x,ierr)
 48:        call PetscViewerDestroy(v,ierr)
 49: !
 50: !  Print the vector
 51: !
 52:        call VecView(x,PETSC_VIEWER_STDOUT_SELF,ierr)
 53: !

 55:        call VecDestroy(x,ierr)
 56:        call PetscFinalize(ierr)
 57:        end

 59: