Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2015 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/48ec78d8c5d957ce8a05 to your computer and use it in GitHub Desktop.
Save anonymous/48ec78d8c5d957ce8a05 to your computer and use it in GitHub Desktop.
nx=128
ny=128
nz=128
program dataread
implicit none
integer nx, ny, nz, i, n
character(100) line
type::params
character(32)::name
character(32)::val
end type params
type(params),dimension(:),allocatable::test
open(17, file='data.txt', status='old')
allocate(test(100))
do
read(17, '(A)', end=100) line
i = i + 1
call splitTextByEqual(line, test(i)%name, test(i)%val)
end do
100 print*, 'Data inputted.'
n = i !record number
do i=1, n
if(test(i)%name == 'nx') read (test(i)%val, *) nx
if(test(i)%name == 'ny') read (test(i)%val, *) ny
if(test(i)%name == 'nz') read (test(i)%val, *) nz
enddo
print '(" nx, ny, nz = ", 3(i0, ", "))', nx, ny, nz
contains
subroutine splitTextByEqual(txt, name, val)
implicit none
character(32) txt,name,val
name = txt(:(index(txt, '=') - 1))
val = txt((index(txt, '=') + 1):)
end subroutine splitTextByEqual
end program
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment