File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 2323{% endmacro %}
2424
2525{% macro record (name , value ) %}
26- {% for itemitem in value .values () -%}
27- {% if item .tagged %} {{ item.name.upper() }} {% endif %} {{ field(item) }}
26+ {% if value is mapping %}
27+ {% for item in value .values () -%}
28+ {{ item.name.upper() }} {{ field(item) }}
2829{% - endfor %}
30+ {% else %}
31+ {{ value|join(" ") }}
32+ {% endif %}
2933{% endmacro %}
3034
3135{% macro recarray (name , value , how ="internal" ) %}
Original file line number Diff line number Diff line change 1+ from pathlib import Path
12from typing import Any
23
34import xattree
78from flopy4 .mf6 .spec import get_blocks
89
910
11+ def _transform_path_to_record (field_name : str , path_value : Path ) -> tuple :
12+ """Transform a Path field to its corresponding MF6 record format."""
13+ # Infer record structure from field name
14+ if field_name .endswith ("_file" ):
15+ base_name = field_name .replace ("_file" , "" ).upper ()
16+ return (base_name , "FILEOUT" , str (path_value ))
17+
18+ # Default fallback
19+ return (field_name .upper (), "FILEOUT" , str (path_value ))
20+
21+
1022def unstructure_component (value : Component ) -> dict [str , Any ]:
1123 data = xattree .asdict (value )
1224 blockspec = get_blocks (value .dfn )
1325 blocks = {}
1426 for block_name , block in blockspec .items ():
1527 blocks [block_name ] = {}
1628 for field_name in block .keys ():
17- blocks [block_name ][field_name ] = data [field_name ]
29+ field_value = data [field_name ]
30+
31+ # Transform Path fields to record format
32+ if isinstance (field_value , Path ) and field_value is not None :
33+ field_value = _transform_path_to_record (field_name , field_value )
34+
35+ blocks [block_name ][field_name ] = field_value
1836 return blocks
1937
2038
You can’t perform that action at this time.
0 commit comments