

#include "finclude/petscdef.h"
      Program PetscF2003
      use petsc
      implicit none
   
      PetscErrorCode                            :: ierr
      Character(len=99) list1(6)
      PetscEnum                                 :: opt=-1
      PetscBool                                 :: set=PETSC_FALSE
      
      Call PetscInitialize(PETSC_NULL_CHARACTER,ierr)
      list1(1) = 'a123'
      list1(2) = 'b456'
      list1(3) = 'c789'
      list1(4) = 'list1'
      list1(5) = 'prefix_'
      list1(6) = ''
      
      print*, list1(1)  
      call PetscOptionsGetEnum('joe_','-jeff',list1,opt,set,ierr)
      write(*,*) 'opt is ', opt
      write(*,*) 'set is ', set

      Call PetscFinalize(ierr)
      end


      Subroutine PetscOptionsGetEnum(pre,name,FArray,opt,set,ierr)
      use,intrinsic :: iso_c_binding
      implicit none
      character(*) FArray(*)
      Type(C_Ptr),Dimension(:),Pointer         :: CArray
      PetscBool                                :: set
      PetscEnum                                :: opt
      PetscErrorCode,intent(out)               :: ierr
      character(kind=c_char),pointer           :: nullc => null()      
      PetscInt                                 :: i,Len
      character(*) pre,name
      Character(kind=C_char,len=99),Dimension(:),Pointer::list1

      do i=1,100
        if (len_trim(Farray(i)) .eq. 0) then
          Len = i-1
          goto 100
        endif
      enddo
 100  continue

      Allocate(list1(Len),stat=ierr);
      Allocate(CArray(Len+1),stat=ierr)
      
      do i=1,Len
         list1(i) = trim(FArray(i))//C_NULL_CHAR
      enddo

      CArray = (/(c_loc(list1(i)),i=1,Len),c_loc(nullc)/)
      call PetscOptionsGetEnumPrivate(pre,name,CArray,opt,set,ierr)
      DeAllocate(CArray)
      DeAllocate(list1)
      End Subroutine 

