program package_lst implicit none integer :: ios integer :: m, n integer :: pos integer :: spos, epos character(len=2048) :: inline character(len=2048) :: wrkline character(len=64) :: filenm character(len=32) :: option character(len=32) :: key logical :: Done, found, lexist write(*,*) ' ' write(*,*) 'Enter filename' read(*,'(a)') filenm inquire( file=trim(filenm),exist=lexist ) if( .not. lexist ) then write(*,*) 'File ',trim(filenm),' does not exist' Stop 'File error' endif open(unit=10,file=trim(filenm),iostat=ios ) if( ios /= 0 ) then write(*,*) 'Can not open ',trim(filenm),'; error = ',ios Stop 'File error' endif write(*,*) ' ' write(*,*) 'Enter package' read(*,'(a)') option found = .false. do read(10,'(a)',iostat=ios) inline if( ios /= 0 ) then exit endif pos = index( trim(inline),'package' ) if( pos == 0 ) then cycle else pos = index( trim(inline),trim(option) ) if( pos == 0 ) then cycle endif found = .true. exit endif enddo got_package: & if( found ) then write(*,*) ' ' write(*,*) 'Enter key' read(*,'(a)') key spos = index( trim(inline),trim(key) ) if( spos == 0 ) then write(*,*) 'Can not find ',trim(key),' delimeter' Stop 'Syntax error' endif spos = spos + len_trim(key) epos = index( trim(inline(spos:)),';' ) if( epos /= 0 ) then epos = epos - 2 + spos else epos = len_trim(inline) + 1 endif wrkline = inline(spos:epos) epos = len_trim( wrkline ) write(*,*) ' ' m = 0 spos = 1 Done = .false. do pos = index( trim(wrkline),',' ) if( pos == 0 ) then Done = .true. pos = epos + 1 endif m = m + 1 write(*,'(''('',i3.3,'')'',5x,a)') m,wrkline(spos:pos-1) if( Done ) then exit endif wrkline(pos:pos) = ' ' spos = pos + 1 enddo else got_package write(*,*) 'Package ',trim(option),' not found in ',trim(filenm) endif got_package close( unit=10 ) end program package_lst