63 character(len=27),
parameter,
public :: parser_varname_excluded_characters =
'|!''"#$%&/\()=?{}+-*^.,;:<> '
66 integer function oct_parse_init(file_out, mpiv_node)
bind(c)
69 character(kind=c_char),
intent(in) :: file_out(*)
70 integer,
intent(in) :: mpiv_node
71 end function oct_parse_init
75 integer function oct_parse_input(file_in, set_used)
bind(c)
78 character(kind=c_char),
intent(in) :: file_in(*)
79 integer,
intent(in) :: set_used
80 end function oct_parse_input
84 subroutine oct_parse_environment(prefix)
bind(c)
87 character(kind=c_char),
intent(in) :: prefix(*)
88 end subroutine oct_parse_environment
92 subroutine oct_parse_end()
94 end subroutine oct_parse_end
98 subroutine oct_sym_output_table(only_unused, mpiv_node)
100 integer,
intent(in) :: only_unused
101 integer,
intent(in) :: mpiv_node
102 end subroutine oct_sym_output_table
106 integer pure function oct_parse_isdef(name)
bind(c)
109 character(kind=c_char),
intent(in) :: name(*)
110 end function oct_parse_isdef
116 use,
intrinsic :: iso_fortran_env
118 character(kind=c_char),
intent(in) :: name(*)
119 integer(int64),
intent(in) :: def
120 integer(int64),
intent(out) :: res
125 use,
intrinsic :: iso_fortran_env
127 character(kind=c_char),
intent(in) :: name(*)
128 real(real64),
intent(in) :: def
129 real(real64),
intent(out) :: res
134 use,
intrinsic :: iso_fortran_env
136 character(kind=c_char),
intent(in) :: name(*)
137 complex(real64),
intent(in) :: def
138 complex(real64),
intent(out) :: res
144 character(kind=c_char),
intent(in) :: name(*), def(*)
145 character(kind=c_char),
intent(inout) :: res(*)
146 integer(kind=c_size_t),
intent(in) :: res_len
153 character(kind=c_char),
intent(in) :: name(*)
175 subroutine oct_parse_block_end(blk)
178 type(block_t),
intent(inout) :: blk
179 end subroutine oct_parse_block_end
183 integer function oct_parse_block_n(blk)
186 type(block_t),
intent(in) :: blk
187 end function oct_parse_block_n
191 integer function oct_parse_block_cols(blk, line)
194 type(
block_t),
intent(in) :: blk
195 integer,
intent(in) :: line
196 end function oct_parse_block_cols
200 subroutine oct_parse_block_int(blk, l, c, res)
203 type(
block_t),
intent(in) :: blk
204 integer,
intent(in) :: l, c
205 integer,
intent(out) :: res
206 end subroutine oct_parse_block_int
208 subroutine oct_parse_block_int8(blk, l, c, res)
209 use,
intrinsic :: iso_fortran_env
212 type(
block_t),
intent(in) :: blk
213 integer,
intent(in) :: l, c
214 integer(int64),
intent(out) :: res
215 end subroutine oct_parse_block_int8
219 subroutine oct_parse_block_double(blk, l, c, res)
220 use,
intrinsic :: iso_fortran_env
223 type(
block_t),
intent(in) :: blk
224 integer,
intent(in) :: l, c
225 real(real64),
intent(out) :: res
226 end subroutine oct_parse_block_double
232 subroutine oct_parse_block_complex(blk, l, c, res)
233 use,
intrinsic :: iso_fortran_env
237 integer,
intent(in) :: l, c
238 complex(real64),
intent(out) :: res
239 end subroutine oct_parse_block_complex
255 character(len=*),
optional,
intent(in) :: log_file
256 logical,
optional,
intent(in) :: dont_write
259 logical :: file_exists
260 character(len=:),
allocatable :: log_file_
261 character(len=MAX_PATH_LEN) :: variables
262 integer(c_int) :: dont_write_
264 if (
present(log_file))
then
265 log_file_ = trim(log_file)
267 log_file_ =
'exec/parser.log'
270 if (
present(dont_write))
then
271 dont_write_ = merge(1_c_int, 0_c_int, dont_write)
273 dont_write_ = mpi_world%rank
276 variables = trim(conf%share)//
'/variables'
277 file_exists = .false.
278 inquire(file=variables, exist=file_exists)
279 if (.not. file_exists)
then
280 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
281 write(stderr,
'(a)')
'Error initializing parser'
282 write(stderr,
'(a)')
'Cannot open variables file: '//trim(conf%share)//
'/variables'
287 if (.not.
present(log_file))
then
288 if (mpi_world%is_root())
call loct_mkdir(
'exec')
293 ierr =
parse_init(string_f_to_c(log_file_), dont_write_)
295 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
296 write(stderr,
'(a)')
'Error initializing parser: cannot write to ' // log_file_
297 write(stderr,
'(a)')
'Do you have write permissions in this directory?'
304 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
305 write(stderr,
'(a)')
'Error initializing parser'
306 write(stderr,
'(a)')
'Cannot open variables file: '//trim(conf%share)//
'/variables'
317 logical :: file_exists
321 file_exists = .false.
322 inquire(file=
'inp', exist=file_exists)
323 if (.not. file_exists)
then
324 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
325 write(stderr,
'(a)')
'Error initializing parser'
326 write(stderr,
'(a)')
'Cannot open input file!'
327 write(stderr,
'(a)')
'Please provide an input file with name inp in the current workdir'
333 write(stderr,
'(a)')
'*** Fatal Error (description follows)'
334 write(stderr,
'(a)')
'Error initializing parser'
335 write(stderr,
'(a)')
'Cannot open input file!'
336 write(stderr,
'(a)')
'Please provide an input file with name inp in the current workdir'
347 integer :: parser_log
356 if(mpi_world%is_root())
then
357 open(newunit=parser_log, file=
'exec/parser.log', status=
'old', action=
'write', position=
'append')
358 write(parser_log,
'(a)')
'# Octopus version: '//trim(conf%version)
359 write(parser_log,
'(a)')
'# Octopus git_commit: '//trim(conf%git_commit)
368 type(namespace_t),
intent(in) :: namespace
369 character(len=*),
intent(in) :: name
371 character(len=MAX_PATH_LEN) :: full_name
381 character(len=*),
intent(in) :: file_contents
382 integer,
intent(in) :: set_used
385 integer function oct_parse_input_string(file_contents, set_used)
bind(c)
388 character(kind=c_char),
intent(in) :: file_contents(*)
389 integer,
intent(in) :: set_used
390 end function oct_parse_input_string
399 type(namespace_t),
intent(in) :: namespace
400 character(len=*),
intent(in) :: name
401 integer,
intent(in) :: def
402 integer,
intent(out) :: res
404 integer(int64) :: res8
405 character(len=MAX_PATH_LEN) :: full_name
410 call oct_parse_int(string_f_to_c(full_name), int(def, int64), res8)
419 type(namespace_t),
intent(in) :: namespace
420 character(len=*),
intent(in) :: name
421 integer(int64),
intent(in) :: def
422 integer(int64),
intent(out) :: res
432 type(namespace_t),
intent(in) :: namespace
433 character(len=*),
intent(in) :: name
434 integer,
intent(in) :: def
435 integer(int64),
intent(out) :: res
437 character(len=MAX_PATH_LEN) :: full_name
443 call oct_parse_int(string_f_to_c(full_name), int(def, int64), res)
450 type(namespace_t),
intent(in) :: namespace
451 character(len=*),
intent(in) :: name
452 integer(int64),
intent(in) :: def
453 integer,
intent(out) :: res
455 integer(int64) :: res8
456 character(len=MAX_PATH_LEN) :: full_name
470 type(namespace_t),
intent(in) :: namespace
471 character(len=*),
intent(in) :: name
472 character(len=*),
intent(in) :: def
473 character(len=*),
intent(inout) :: res
475 integer(kind=c_size_t) :: res_len
476 character(len=MAX_PATH_LEN) :: full_name
477 character(kind=c_char) :: c_res(len(res)+1)
485 call oct_parse_string(string_f_to_c(full_name), string_f_to_c(def), c_res, res_len)
486 call string_c_to_f(c_res, res)
492 type(namespace_t),
intent(in) :: namespace
493 character(len=*),
intent(in) :: name
494 logical,
intent(in) :: def
495 logical,
intent(out) :: res
497 integer(int64) :: idef, ires
498 character(len=MAX_PATH_LEN) :: full_name
515 type(namespace_t),
intent(in) :: namespace
516 character(len=*),
intent(in) :: name
517 complex(real64),
intent(in) :: def
518 complex(real64),
intent(out) :: res
527 integer function parse_block(namespace, name, blk, check_varinfo_)
528 type(namespace_t),
intent(in) :: namespace
529 character(len=*),
intent(in) :: name
530 type(
block_t),
intent(out) :: blk
531 logical,
optional,
intent(in) :: check_varinfo_
533 logical :: check_varinfo
534 character(len=MAX_PATH_LEN) :: full_name
536 check_varinfo = .
true.
537 if (
present(check_varinfo_)) check_varinfo = check_varinfo_
539 if (check_varinfo)
then
552 type(
block_t),
intent(in) :: blk
553 integer,
intent(in) :: l, c
554 logical,
intent(out) :: res
558 call oct_parse_block_int(blk, l, c, ires)
566 type(namespace_t),
intent(in) :: namespace
567 character(len=*),
intent(in) :: name
568 real(real64),
intent(in) :: def
569 real(real64),
intent(out) :: res
570 type(unit_t),
optional,
intent(in) :: unit
572 character(len=MAX_PATH_LEN) :: full_name
578 if (
present(unit))
then
579 call oct_parse_double(string_f_to_c(full_name), units_from_atomic(unit, def), res)
580 res = units_to_atomic(unit, res)
590 type(
block_t),
intent(in) :: blk
591 integer,
intent(in) :: l, c
592 real(real64),
intent(out) :: res
593 type(unit_t),
intent(in) :: unit
595 call oct_parse_block_double(blk, l, c, res)
596 res = units_to_atomic(unit, res)
602 real(real64),
intent(out) :: re, im
603 integer,
intent(in) :: ndim
604 real(real64),
intent(in) :: x(:), r, t
605 character(len=*),
intent(in) :: pot
618 character(len=*),
intent(inout) :: inp_string
619 real(real64),
intent(in) :: x(:, :)
620 character(len=1),
intent(in) :: arraychar
622 integer :: i, m, n_atom, coord, string_length
623 character (LEN=100) :: v_string
625 string_length = len(inp_string)
626 do i = 1, string_length - 1
627 if (inp_string(i:i+1) == arraychar//
"[")
then
629 if (inp_string(i+3:i+3) ==
",") m = 1
630 if (inp_string(i+4:i+4) ==
",") m = 2
632 write(stderr,
'(a)')
"*** Fatal Error (description follows)"
633 write(stderr,
'(a)')
"Attempting to parse a string with array elements larger than 99"
636 read(inp_string(i+2:i+1+m),*) n_atom
637 read(inp_string(i+3+m:i+3+m),*) coord
638 write(v_string,*) x(n_atom, coord)
639 inp_string = inp_string(:i-1) //
"(" // trim(v_string) //
")" // inp_string(i+5+m:)
648 character(len=*),
intent(in) :: varname
650 if (.not. varinfo_exists(varname))
then
651 write(stderr,
'(a)')
"*** Fatal Internal Error (description follows)"
652 write(stderr,
'(a)')
'Attempting to parse undocumented variable '//trim(varname)//
'.'
686 type(namespace_t),
target,
intent(in) :: namespace
687 character(len=*),
intent(in) :: varname
688 character(len=:),
allocatable :: name
692 type(namespace_t),
pointer :: ancestor
693 character(len=MAX_NAMESPACE_LEN) :: ancestor_name, tmp
698 ancestor => namespace
699 do while (
associated(ancestor) .and. .not. found)
702 ancestor_name = ancestor%get()
704 do while (len_trim(ancestor_name) > 0 .and. is /= 0 .and. .not. found)
706 name = trim(ancestor_name) //
"." // trim(varname)
707 found =
parse_isdef(string_f_to_c(trim(name))) /= 0
710 is = index(ancestor_name,
".")
711 tmp = ancestor_name(is+1:)
714 ancestor => ancestor%parent
718 if (.not. found) name = varname
723 type(
block_t),
intent(in) :: blk
724 integer,
intent(in) :: l, c
725 character(len=*),
intent(inout) :: res
726 logical,
optional,
intent(in) :: convert_to_c
728 character(kind=c_char) :: c_res(len(res)+1)
730 interface oct_parse_block_string
731 subroutine oct_parse_block_string(blk, l, c, res)
735 type(
block_t),
intent(in) :: blk
736 integer,
intent(in) :: l, c
737 character(kind=c_char),
intent(out) :: res(*)
738 end subroutine oct_parse_block_string
739 end interface oct_parse_block_string
742 call oct_parse_block_string(blk, l, c, c_res)
743 call string_c_to_f(c_res, res)
745 if(optional_default(convert_to_c, .false.))
then
746 call conv_to_c_string(res)
765 real(real64),
intent(in) :: x, r, t
766 integer,
intent(in) :: ndim
767 real(real64),
intent(out) :: re, im
768 character(len=*),
intent(in) :: pot
770 interface oct_parse_expression_low
771 subroutine oct_parse_expression_low(re, im, ndim, x, r, t, pot) bind(c, name='oct_parse_expression')
773 use,
intrinsic :: iso_fortran_env
775 real(real64),
intent(in) :: x, r, t
776 integer,
intent(in) :: ndim
777 real(real64),
intent(out) :: re, im
778 character(kind=c_char),
intent(in) :: pot(*)
779 end subroutine oct_parse_expression_low
780 end interface oct_parse_expression_low
782 call oct_parse_expression_low(re, im, ndim, x, r, t, string_f_to_c(pot))
786 real(real64),
intent(out) :: re, im
787 character(len=*),
intent(in) :: c
788 real(real64),
intent(in) :: x
789 character(len=*),
intent(in) :: string
791 interface oct_parse_expression1
792 subroutine oct_parse_expression1(re, im, c, x, string)
bind(c)
794 use,
intrinsic :: iso_fortran_env
796 real(real64),
intent(out) :: re, im
797 character(kind=c_char),
intent(in) :: c(*)
798 real(real64),
intent(in) :: x
799 character(kind=c_char),
intent(in) :: string(*)
800 end subroutine oct_parse_expression1
801 end interface oct_parse_expression1
803 call oct_parse_expression1(re, im, string_f_to_c(c), x, string_f_to_c(string))
812 call mpi_world%abort()
System information (time, memory, sysname)
character(len=:) function, allocatable, public parse_get_full_name(namespace, varname)
Given a namespace and a variable name, this function will iterate over all namespace ancestors contai...
logical function, public parse_is_defined(namespace, name)
subroutine parse_logical(namespace, name, def, res)
subroutine, public parser_initialize_symbol_table(log_file, dont_write)
Initialise the Octopus parser symbol table from file of keys.
subroutine parse_integer(namespace, name, def, res)
subroutine, public parse_block_string(blk, l, c, res, convert_to_c)
subroutine parse_integer48(namespace, name, def, res)
subroutine, public parser_init()
Initialise the Octopus parser.
subroutine, public parse_block_logical(blk, l, c, res)
subroutine oct_parse_expression(re, im, ndim, x, r, t, pot)
The public subroutine parse_expression accepts two possible interfaces, one which assumes that the va...
subroutine, public parser_end()
End the Octopus parser.
subroutine oct_parse_block_double_unit(blk, l, c, res, unit)
subroutine parse_integer84(namespace, name, def, res)
subroutine, public parse_array(inp_string, x, arraychar)
A very primitive way to "preprocess" a string that contains reference to the elements of a two-dimens...
integer function, public parse_input_string(file_contents, set_used)
subroutine parse_integer8(namespace, name, def, res)
subroutine oct_parse_double_unit(namespace, name, def, res, unit)
subroutine oct_parse_expression_vec1(re, im, c, x, string)
subroutine oct_parse_expression_vec0(re, im, ndim, x, r, t, pot)
subroutine parse_string(namespace, name, def, res)
subroutine parse_check_varinfo(varname)
subroutine parse_cmplx(namespace, name, def, res)
integer function, public parse_block(namespace, name, blk, check_varinfo_)
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.