jimbraun / XCDF

XCDF: eXplicitly Compacted Data Format. See documentation at Read the Docs:
https://xcdf.readthedocs.io/en/latest/
Other
14 stars 8 forks source link

Allow for writing arrays to fields #101

Closed HealthyPear closed 1 year ago

HealthyPear commented 1 year ago

Context

In #99 I wanted to expose the minimum available API to write to file with Python3.

Though, I noticed that the Add method of XCDFField allowed only to add a single value at the time, so in Python one would have to perform for cycles for each array to write, e.g. what is currently in the writing example of the Python tutorial,

for i in np.arange(0, 1, 0.25):
        field_B.add(i)

which obviously not scalable.

Implementation

I added an overloaded method of XCDFField::Add which instead of eating a single value eats a std::vector and inside it just loops over it calling XCDFFieldData::Add on each value.

I added a dedicated unit test and updated the documentation accordingly.

With this we can do, e.g.

field_B.add(np.arange(0, 1, 0.25))