program ftest use string_m use getkw_m implicit none external getarg, iargc integer(4) :: ival, iargc, argc, err, i, n, fgetc integer(4), dimension(100) :: itup real(8), dimension(100) :: dtup character(80), dimension(100) :: stup real(8) :: dval character(80) :: str, arg character, dimension(:), allocatable :: buf type(string_t) :: strt type(string_t), dimension(:), pointer :: starr ! figure out command line... argc=iargc() select case(argc) case(0) ! open default file arg='test.inp' case(1) call getarg(1, arg) case default print *, "usage: ftest [file]" call exit(1) end select call set_parser_verbose(1) call set_parser_strict(1) ! call set_parser_case_insensitive(1) !! !! uncomment to parse from a buffer instead of a file !! ! open(99, file=trim(arg)) ! n=getfsize(99) ! allocate(buf(n)) ! do i=1,n ! err=fgetc(99, buf(i)) ! end do ! close(99) ! ! call init_parse_buf(buf, err) call init_parse(trim(arg), err) if (err == 1) then print *, 'Invalid filename: "', trim(arg),'"' call end_parse() stop '' else if (err == 2) then call end_parse() stop 'stop.' end if call set_active_section('FOOBAR') call getkw('string', str) call getkw('double', dval) call getkw('integer', ival) call getkw('tuple_i', itup) call getkw('tuple_d', dtup) print *, '========= FOOBAR ===========' print *, 'string:', str ! call del_str_t(strt) print *, 'double:', dval print *, 'integer:', ival call get_kw_size('tuple_i', i) print *, 'ituple:', itup(1:i) call get_kw_size('tuple_d', i) print *, 'dtuple:', dtup(1:i) print *, '--------- BUZZ -----------' call getkw('BUZZ', ival) print *, 'BUZZ=', ival call getkw('BUZZ.buzz', ival) print *, 'buzz=', ival call getkw('BUZZ.string',str, 80) print *, 'string=', trim(str) ! ! The grunt section is optional, so we set defaults ! ival=42 str='foo' print *, '--------- grunt -----------' call getkw('grunt.grunt', ival) call getkw('grunt.foo', str) ! skip the lenght arg to preserve cont. print *, 'grunt.grunt=', ival print *, 'grunt.foo=', trim(str) call reset_active_section() dval=69.0 ival=69 call init_kw_string('RABOOF', starr) call getkw('RABOOF', starr) call getkw('RABOOF.string', str) call getkw('RABOOF.double', dval) call getkw('RABOOF.integer', ival) print *, '========= RABOOF ===========' print *, size(starr) do i=1,size(starr) print *, size(starr(i)%str) print *, 'RABOOF ', i, starr(i)%str end do call del_kw_string(starr) print *, 'string=', str print *, 'double=', dval print *, 'integer=', ival call end_parse() print * print *, 'Goodbye World...' print * contains function getfsize(fd) result(fs) integer(4) :: fd, fs integer(4) :: i, fseek, ftell i=fseek(99,0,2) fs=ftell(99) rewind(99) end function end program