APSIMInitiative / APSIM710

APSIM
https://www.apsim.info
30 stars 47 forks source link

Get values from XML file using manager2. #2184

Closed HongtaoXing closed 1 year ago

HongtaoXing commented 1 year ago

Hi

I am wondering if we could get values from xml files using Manager2.

If so, could you please let me know how to do it?

Thanks

Hongtao

peter-devoil commented 1 year ago

You're thinking about an ancillary xml file? If so, you can use System.Xml.* like any other; the only trick is to add a reference assembly if needed - Toolbox/Management/Reference - System.Xml.ReaderWriter.dll

Reading the .apsim file currently running would be a lot harder. I can't think of any easy options there, apart from the above.

HongtaoXing commented 1 year ago

Thanks for your response with advice, Peter

I am not really clear what I should do following your comments.

What I want to is to read/get the values in soil.xml using manager2.

The action I did following your suggestion is add one line of code "using System.Xml.Soil;" into my script. Did I do it right?

I did not get your point for the trick. Do you mean "Drag reference from Management to ManagerFolder" and "fill the value as System.Xml.ReaderWriter.dll to "Path to assembly"? But, I did not find the "System.Xml.ReaderWriter.dll" in APSIM/Model folder.

Thanks for your help in advance.

Hongtao

peter-devoil commented 1 year ago

My apologies, I wasnt clear.

Manager2 is a C# plugin, which means one uses C# libraries to extend the language beyond its core abilities. The C# people distribute a standard library to manipulate XML, and there are many examples and how-to pages that describe it.

But I suspect your question is not so much about XML, but how a manager2 component can find/read parameters from other modules. That's not always straight forward, as there are wrappers around every apsim module that only expose what the module's author thought was reasonable, and hide or discard the rest. So the answer is that you can only get values from the soil that are explicity exposed to the system (ie appear in the output variables).

There is nothing stopping you from adding a parameter to the manager2 component that is a duplicate of the soil parameter, and ensuring that the two are always kept "in sync".

HongtaoXing commented 1 year ago

Thank you very much for your detailed explanations and clarifications. Peter In this case, I will keep create "duplicate" parameters in Manager2 and conduct the parameter optimisations. Thanks again for your explanations. Hongtao