&nameList_1
! comments allow
name1='11111111111'
name2='22222222222'
size=4 !! To define size of dynamic array in namelist block 2
/
&nameList_2
! initialize array in namelist
strArr='asfd' 'fdsf' '23232' 'sfss'
/
test.f90
character(len=10) :: name1
character(len=10) :: name2
integer :: size
!! Use size from nameList_1 to allocate space for strArr
!! This is to make code more robostic
character(len=10) , dimension(:), allocatable ::strArr
NAMELIST /nameList_1/name2, name1, size ! order of keywords is NOT important
NAMELIST /nameList_2/strArr
READ(*,NML=nameList_1) ! read name list block 1 from command line via "<"
print *, name1
print *, name2
print *, size
allocate(strArr(size))
! open(8,file="nameList_1.conf", status='OLD', recl=80, delim='APOSTROPHE')
! read(8,NML=nameList_2) ! read name list from a file
! close(8) !!! also can read namelist block 2 via file
READ(*,NML=nameList_2) ! read name list from a file
print *, strArr
deallocate(strArr)
Run
$ .a.out < nameList_1.conf
No comments:
Post a Comment