Created
January 24, 2015 05:32
-
-
Save anonymous/48ec78d8c5d957ce8a05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nx=128 | |
ny=128 | |
nz=128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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