Comments (11)
@14NGiestas I am quite busy this week, if you can provide a complete test example I can more easily test it :)
from fdict.
Thanks! Your zip file says it is incomplete?
Archive: ~/fdict-test.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
from fdict.
Ok, the problem is quite trivial. When you are using .first.
you are not retrieving the value of the first element in the dictionary. You are basically creating a new pointer to the dictionary starting from the first key. Then you can loop on this using:
type(Dict) :: main_dict
type(Dict) :: loop_dict
loop_dict = .first. main_dict
do while ( .not. .empty. loop_dict )
< do something with this key-val segment in the dictionary >
loop_dict = .next. loop_dict
end do
So your code should look like this:
module my_module
use dictionary
type MyType
type(Dict) :: main_dict
end type MyType
contains
function MyType_(array) result(self)
implicit none
type(MyType) :: self
type(Dict) :: sub_dict
character(*) :: array(:)
integer :: i
real(8) :: v
do i = 1 , size(array)
sub_dict = ('val1' .kv. 100.d0) // ('val2' .kv. 'A string')
self%main_dict = self%main_dict // (array(i) .kvp. sub_dict)
call nullify(sub_dict)
end do
end function MyType_
end module my_module
program main
use my_module
type(MyType) :: t
type(Dict) :: sub_dict, loop_dict
real(8) :: val
character(20) :: buffer
t = MyType_(['hello', 'world', 'then!'])
loop_dict = .first. (t%main_dict)
call associate(sub_dict, loop_dict)
call assign(buffer, sub_dict, 'val2')
call assign(val, sub_dict, 'val1')
print*, "Should print 100.0d0:", val
print*, "Should print 'A string':", buffer ! Should print "A string" ?
end program main
from fdict.
I am not really sure what you are trying to do.
Do you populate the main dict in multiple subroutines?
If yes, then the above code should concatenate the main dict
main_dict = main_dict // ('sub-dict1' .kvp. sub_dict)
In case you are dealing with allocatable
arrays or static arrays in subroutines and using kvp, then it won't work. I am not at my computer so I can't create a small example, but if you clarify a bit more I'll be able to help you.
from fdict.
Sorry I'll try to be more clear,
I have a derived type which holds the main dict then I try to populate using a array of strings as key in that manner, in fact this works however the sub-dict do not keep the default values I provided.
subroutine (...)
do i=(...)
new_dict = (
array(i) .kvp. (
('value1' .kv. 0.d0) //
('value2' .kv. 'string')
)
)
self % main_dict = self % main_dict // (new_dict)
end do
(...)
end subroutine
I also tried to do the following:
new_dict = ('value1' .kv. 0.d0)//('value2' .kv. 'string')
self % main_dict = self % main_dict // (array(i) .kvp. new_dict)
In main program I try to retrieve the defaults:
type(dict) :: d
type(myderived) :: my
real :: r
character(255) :: buffer
! here I can retrieve all keys (populated by array(i))
! but can't retrieve the values of the sub dict
d = .first. my % main_dict
call assign(r, d, 'value1') ! non sense
call assign(buffer, d, 'value2') ! blank
print*, .key. d ! ok returns the right key name
from fdict.
Here it is a complete example...
fdict-test.zip
from fdict.
Oops... I edited the previous comment adding the correct file
from fdict.
hmm, same error appears. Could you try and create a tar?
from fdict.
Using a online tool this time O_O
EDIT: Fixed the example...
fdict-test-3.zip
from fdict.
worked! ;) I'll have a look!
from fdict.
Thank you, Zerothi, it works! 😃
from fdict.
Related Issues (20)
- Overload the operator(=), to interface the assign and associate functions HOT 5
- Can't get it to work HOT 3
- How to implement in an example HOT 4
- Error linking the library to another project HOT 9
- Creating the dictionary from a read file HOT 5
- Add c_ptr, c_funptr to variable and dictionary HOT 1
- please provide a pkgconfig HOT 2
- Memory leak when overwriting entries from concat
- README.md clarification/enhancement HOT 4
- problem with install HOT 20
- Compilation error with CRAY compiler HOT 3
- interface which to query contained type field HOT 1
- document cmake building instructions HOT 1
- Fails to build with `ninja-build` HOT 2
- Make project compatible with `FetchContent` HOT 6
- Clarify the api HOT 2
- Using plain C preprocessor instead of fypp? HOT 7
- CI tools HOT 4
- Strongly typed dictionaries HOT 7
- having error in compiling siesta-master HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fdict.