Date: 2013-07-02T14:38:28+00:00

Actual source code: ex5f.F
petsc-3.4.2 2013-07-02

      1: !
      2: !
      3:       program main
      4: #include <finclude/petscsys.h>
      5: #include <finclude/petscdraw.h>
      6: !
      7: !  This example demonstrates basic use of the Fortran interface for
      8: !  PetscDraw routines.
      9: !
     10:       PetscDraw         draw
     11:       PetscDrawLG       lg
     12:       PetscDrawAxis     axis
     13:       PetscErrorCode    ierr
     14:       PetscBool         flg
     15:       integer           x,y,width,height
     16:       PetscScalar       xd,yd
     17:       PetscInt          i,n,w,h

     19:       n      = 20
     20:       x      = 0
     21:       y      = 0
     22:       w      = 300
     23:       h      = 300

     25:       call PetscInitialize(PETSC_NULL_CHARACTER,ierr)

     27: !  GetInt requires a PetscInt so have to do this ugly setting
     28:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-width',w,          &
     29:      &     flg,ierr)
     30:       width = w
     31:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-height',h,         &
     32:      &     flg,ierr)
     33:       height = h
     34:       call PetscOptionsGetInt(PETSC_NULL_CHARACTER,'-n',n,flg,ierr)

     36:       call PetscDrawCreate(PETSC_COMM_SELF,PETSC_NULL_CHARACTER,        &
     37:      &               PETSC_NULL_CHARACTER,x,y,width,height,draw,ierr)
     38:       call PetscDrawSetFromOptions(draw,ierr)

     40:       call PetscDrawLGCreate(draw,1,lg,ierr)
     41:       call PetscDrawLGGetAxis(lg,axis,ierr)
     42:       call PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED, &
     43:      &     PETSC_DRAW_BLUE,ierr)
     44:       call PetscDrawAxisSetLabels(axis,'toplabel','xlabel','ylabel',    &
     45:      &     ierr)

     47:       do 10, i=0,n-1
     48:         xd = i - 5.0
     49:         yd = xd*xd
     50:         call PetscDrawLGAddPoint(lg,xd,yd,ierr)
     51:  10   continue

     53:       call PetscDrawLGIndicateDataPoints(lg,ierr)
     54:       call PetscDrawLGDraw(lg,ierr)
     55:       call PetscDrawFlush(draw,ierr)

     57:       call PetscSleep(10,ierr)

     59:       call PetscDrawLGDestroy(lg,ierr)
     60:       call PetscDrawDestroy(draw,ierr)
     61:       call PetscFinalize(ierr)
     62:       end