! Main for OpenFile
Program OpenFile
use dfwin
implicit none

! Define types for structure "ofn"
!character*(*),parameter :: filter_spec ='*.*'C
character(max_path) :: file_spec = ""C
character(max_path) lpstrInitialDir ,lpstrFilter, lpstrTitle, &
					lpstrDefExt, lpstrFile
integer nFilterIndex
character(max_path) CurrentDirectory; integer istat
integer SelectFile, status
integer lenCurr

lpstrInitialDir =""C	!NULL
lpstrFilter = &
  "Data Files (*.dat)"C//"*.dat"C// &
  "Text Files (*.txt)"C//"*.txt"C//&
  "Fortran Files"C//"*.f90;*.f"C//&
  "All files (*.*)"C//"*.*"C//""C
lpstrTitle ='Select File'C
nFilterIndex =1
lpstrDefExt ='dat'C
lpstrFile ="*.dat"C	!""C

istat =GetCurrentDirectory(max_path, CurrentDirectory)
if(istat >0) then
lpstrInitialDir =CurrentDirectory
endif

status =SelectFile(lpstrInitialDir ,lpstrFilter, lpstrTitle, nFilterIndex, &
					lpstrDefExt, lpstrFile)

if(status >0) then
print*, 'Selected File: ', trim(lpstrFile)

! get current directory
istat =GetCurrentDirectory(max_path, CurrentDirectory)
lenCurr =index(CurrentDirectory, char(0))
print '(/, a, a)', 'Current Directory is: ', CurrentDirectory(:lenCurr-1)
else
print*, 'Error / Canceled'
end if

END
