Commit 477be823 authored by Nick R. Papior's avatar Nick R. Papior
Browse files

Added fdf_bphysical and change { to [ in list creations

The sample.f90 has been checked and works correctly and
thus all lists may now be used as [. This is to accommodate
future { for dictionaries etc.

Added a fdf_bphysical routine for reading physical quantities
in blocks.

Added a copy statement to the dictionary.
parent c42999ca
......@@ -157,7 +157,7 @@ MODULE fdf
public :: fdf_block, fdf_bline, fdf_bbackspace, fdf_brewind
public :: fdf_bnintegers, fdf_bnreals, fdf_bnvalues, fdf_bnnames, fdf_bntokens
public :: fdf_bintegers, fdf_breals, fdf_bvalues, fdf_bnames, fdf_btokens
public :: fdf_bboolean
public :: fdf_bboolean, fdf_bphysical
public :: fdf_bnlists, fdf_blists
! Match, search over blocks, and destroy block structure
......@@ -2348,6 +2348,66 @@ MODULE fdf
!--------------------------------------------------------------------------- END
END FUNCTION fdf_physical
!
! Returns a double precision value from a block-line after a certain input value
! or the default value if label is not found in the fdf file.
! Converts the units to defunit.
!
FUNCTION fdf_bphysical(pline, default, defunit, after)
implicit none
!--------------------------------------------------------------- Input Variables
type(parsed_line), pointer :: pline
real(dp) :: default
character(*) :: defunit
integer(ip), intent(in), optional :: after
!-------------------------------------------------------------- Output Variables
real(dp) :: fdf_bphysical
!--------------------------------------------------------------- Local Variables
character(10) :: unitstr
character(80) :: msg
real(dp) :: value
type(line_dlist), pointer :: mark
!------------------------------------------------------------------------- BEGIN
! Prevents using FDF routines without initialize
if (.not. fdf_started) then
call die('FDF module: fdf_bphysical', 'FDF subsystem not initialized', &
THIS_FILE, __LINE__, fdf_err)
endif
if (.not. match(pline, 'vn', after)) then
write(msg,*) 'no real value for line: '//pline%line
call die('FDF module: fdf_bphysical', msg, THIS_FILE, &
__LINE__, fdf_err)
endif
! get value in block-line
value = values(pline, 1, after)
! get unit in block-line
unitstr = names(pline, 1, after)
if ( leqi(unitstr, defunit) ) then
fdf_bphysical = value
else
fdf_bphysical = value * fdf_convfac(unitstr, defunit)
end if
if ( fdf_output ) then
if ( present(after) ) then
write(fdf_out,'(5x,g20.10,1x,a10,1x,i0)') fdf_bphysical, &
defunit, after
else
write(fdf_out,'(5x,g20.10,1x,a10)') fdf_bphysical, defunit
end if
write(fdf_out,'(a,a,5x,g20.10,1x,a10)') &
'# above item on line: ', pline%line
end if
!--------------------------------------------------------------------------- END
END FUNCTION fdf_bphysical
!
! Returns conversion factor between a subset of physical units
! Written by j.m.soler. dec'96.
......@@ -2640,6 +2700,8 @@ MODULE fdf
!--------------------------------------------------------------------------- END
END FUNCTION fdf_bline
!
! Backspace to the previous physical line in the block
! returning .TRUE. while more lines exist in the block bfdf.
......
......@@ -1129,8 +1129,11 @@ MODULE parse
! String delimiters: " ' `
is_delstr(i) = (i .eq. 34) .or. (i .eq. 39) .or. (i .eq. 96)
! List delimiters: { }
is_dellist(i) = (i .eq. 123) .or. (i .eq. 125)
! List delimiters: [ ]
is_dellist(i) = (i .eq. 91) .or. (i .eq. 93)
! Dictionary delimiters: { }
! is_deldict(i) = (i .eq. 123) .or. (i .eq. 125)
! Special characters which are tokens by themselves: <
is_special(i) = (i .eq. 60)
......@@ -1258,10 +1261,14 @@ MODULE parse
do i= 1, ntokens
token = line(first(i):last(i))
j = last(i) - first(i) + 1
if ( ichar(token(1:1)) .eq. 123 .and. &
ichar(token(j:j)) .eq. 125 ) then
! if the token starts with { and ends with }, it will be a list
if ( ichar(token(1:1)) .eq. 91 .and. &
ichar(token(j:j)) .eq. 93 ) then
! if the token starts with [ and ends with ], it will be a list
token_id(i) = 'a'
! else if ( ichar(token(1:1)) .eq. 123 .and. &
! ichar(token(j:j)) .eq. 125 ) then
! if the token starts with { and ends with }, it will be a dictionary
! token_id(i) = 'd'
elseif (is_value(token)) then
! This read also serves to double check the token for
......
......@@ -20,12 +20,12 @@ AtomicCoordinatesAndAtomicSpecies < coords.fdf # Search in file
%endblock Other-Block
%block ListBlock
List1 {1,2,3 ,5 , 6 } {-1,-3} {100 -- 10 step 7}
List2 { 1 to 5 , 4 } {10 -- 20 step 4 , 3 }
List2 { 1 to 5 , 4 , 2 to 10 , -2 to -20}
List1 [1,2,3 ,5 , 6 ] [-1,-3] [100 -- 10 step 7]
List2 [ 1 to 5 , 4 ] [10 -- 20 step 4 , 3 ]
List2 [ 1 to 5 , 4 , 2 to 10 , -2 to -20]
%endblock ListBlock
MyList { 2 -- 10 , 11 , 20 }
MyList [ 2 -- 10 , 11 , 20 ]
debug faLSE # Case insensitive!!
......
......@@ -171,6 +171,11 @@ module dictionary
end interface pop
public :: pop
interface copy
module procedure copy_
end interface
public :: copy
interface nullify
module procedure nullify_
end interface nullify
......@@ -724,6 +729,35 @@ contains
end subroutine delete_
!> Generate the copy routine
subroutine copy_(from, to)
type(dict), intent(in) :: from
type(dict), intent(inout) :: to
type(d_entry), pointer :: d
type(var) :: v
! Delete the dictionary
call delete(to)
d => from%first
do while ( associated(d) )
! Associate data...
call associate(v, d%value)
! Copy data, hence .kv.
to = to // (trim(d%key).kv.v)
d => d%next
end do
! Clean up pointers...
call nullify(v)
nullify(d)
end subroutine copy_
subroutine pop_(val,this,key,dealloc)
type(var), intent(inout) :: val
type(dict), intent(inout) :: this
......
trunk-536--transiesta-2
trunk-536--transiesta-3
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment