Skip to content

Commit 7f2adad

Browse files
committed
wip
1 parent 8224d23 commit 7f2adad

File tree

144 files changed

+5314
-1061
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+5314
-1061
lines changed

flopy4/mf6/codec/reader/grammar/filters.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ def get_recarray_name(block_name: str) -> str:
7777
return f"{block_name}data"
7878

7979

80-
def get_recarray_columns(field_names: list[str], block_fields: Mapping[str, FieldV2]) -> list[str]:
80+
def get_recarray_columns(field_names: list[str], block_fields: Mapping[str, FieldV2]) -> list[tuple[str, bool]]:
8181
"""
82-
Get column names for a recarray, similar to V1 format.
82+
Get column names for a recarray with optionality info.
8383
84-
Returns column names in format like: ['cellid', 'q', 'aux', 'boundname']
84+
Returns list of (column_name, is_optional) tuples like:
85+
[('cellid', False), ('q', False), ('aux', True), ('boundname', True)]
8586
"""
8687
columns = []
8788

@@ -96,10 +97,13 @@ def get_recarray_columns(field_names: list[str], block_fields: Mapping[str, Fiel
9697
break
9798

9899
if has_spatial:
99-
columns.append("cellid")
100+
columns.append(("cellid", False)) # cellid is always required
100101

101-
# Add the field names as columns
102-
columns.extend(field_names)
102+
# Add the field names as columns with their optionality
103+
for name in field_names:
104+
field = block_fields[name]
105+
is_optional = getattr(field, 'optional', False)
106+
columns.append((name, is_optional))
103107

104108
return columns
105109

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-CDB
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -14,7 +9,8 @@ start: block*
149
block: options_block | dimensions_block | period_block
1510
options_block: "begin"i "options"i options_fields "end"i "options"i
1611
dimensions_block: "begin"i "dimensions"i dimensions_fields "end"i "dimensions"i
17-
period_block: "begin"i "period"i period_fields "end"i "period"i
12+
period_block: "begin"i "period"i block_index period_fields "end"i "period"i block_index
13+
block_index: integer
1814
options_fields: (auxiliary | boundnames | print_input | print_flows | save_flows | obs_filerecord)*
1915
dimensions_fields: (maxbound)*
2016
period_fields: (stress_period_data)*
@@ -25,9 +21,39 @@ print_flows: "print_flows"i
2521
save_flows: "save_flows"i
2622
obs_filerecord: "filein"i "obs6"i string
2723
maxbound: "maxbound"i integer
28-
stress_period_data: cellid idcxs width aux boundname
29-
cellid: integer+
30-
idcxs: integer
31-
width: double
32-
aux: double
33-
boundname: string
24+
stress_period_data: integer+ integer double double? string?
25+
// Inline typed grammar rules
26+
integer: _integer
27+
double.2: _number
28+
string: ESCAPED_STRING | record
29+
record.1: _token+ _NL
30+
list: record*
31+
array: (single_array | layered_array)
32+
single_array: [netcdf] readarray
33+
layered_array: layered [netcdf] readarray+
34+
layered: "layered"i
35+
netcdf: "netcdf"i
36+
readarray: control [data]
37+
control: constant | internal | external
38+
constant: "constant"i double
39+
internal: "internal"i [factor] [iprn]
40+
external: "open/close"i filename [factor] [binary] [iprn]
41+
factor: "factor"i double
42+
iprn: "iprn"i integer
43+
binary: "(binary)"i
44+
filename: ESCAPED_STRING | _word
45+
data: double+
46+
47+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
48+
_number: SIGNED_NUMBER | NUMBER
49+
_integer: SIGNED_INT | INT
50+
_token: _word | _number
51+
52+
%import common.NEWLINE -> _NL
53+
%import common.CNAME
54+
%import common.WORD
55+
%import common.NUMBER
56+
%import common.INT
57+
%import common.ESCAPED_STRING
58+
%import common.SIGNED_NUMBER
59+
%import common.SIGNED_INT
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-CHD
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -14,7 +9,8 @@ start: block*
149
block: options_block | dimensions_block | period_block
1510
options_block: "begin"i "options"i options_fields "end"i "options"i
1611
dimensions_block: "begin"i "dimensions"i dimensions_fields "end"i "dimensions"i
17-
period_block: "begin"i "period"i period_fields "end"i "period"i
12+
period_block: "begin"i "period"i block_index period_fields "end"i "period"i block_index
13+
block_index: integer
1814
options_fields: (auxiliary | auxmultname | boundnames | print_input | print_flows | save_flows | ts_filerecord | obs_filerecord)*
1915
dimensions_fields: (maxbound)*
2016
period_fields: (stress_period_data)*
@@ -27,8 +23,39 @@ save_flows: "save_flows"i
2723
ts_filerecord: "ts6"i "filein"i string
2824
obs_filerecord: "filein"i "obs6"i string
2925
maxbound: "maxbound"i integer
30-
stress_period_data: cellid head aux boundname
31-
cellid: integer+
32-
head: double
33-
aux: double
34-
boundname: string
26+
stress_period_data: integer+ double double? string?
27+
// Inline typed grammar rules
28+
integer: _integer
29+
double.2: _number
30+
string: ESCAPED_STRING | record
31+
record.1: _token+ _NL
32+
list: record*
33+
array: (single_array | layered_array)
34+
single_array: [netcdf] readarray
35+
layered_array: layered [netcdf] readarray+
36+
layered: "layered"i
37+
netcdf: "netcdf"i
38+
readarray: control [data]
39+
control: constant | internal | external
40+
constant: "constant"i double
41+
internal: "internal"i [factor] [iprn]
42+
external: "open/close"i filename [factor] [binary] [iprn]
43+
factor: "factor"i double
44+
iprn: "iprn"i integer
45+
binary: "(binary)"i
46+
filename: ESCAPED_STRING | _word
47+
data: double+
48+
49+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
50+
_number: SIGNED_NUMBER | NUMBER
51+
_integer: SIGNED_INT | INT
52+
_token: _word | _number
53+
54+
%import common.NEWLINE -> _NL
55+
%import common.CNAME
56+
%import common.WORD
57+
%import common.NUMBER
58+
%import common.INT
59+
%import common.ESCAPED_STRING
60+
%import common.SIGNED_NUMBER
61+
%import common.SIGNED_INT

flopy4/mf6/codec/reader/grammar/generated/chf-cxs.lark

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-CXS
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -25,3 +20,39 @@ nsections: "nsections"i integer
2520
npoints: "npoints"i integer
2621
packagedata: "packagedata"i recarray
2722
crosssectiondata: "crosssectiondata"i recarray
23+
24+
// Inline typed grammar rules
25+
integer: _integer
26+
double.2: _number
27+
string: ESCAPED_STRING | record
28+
record.1: _token+ _NL
29+
list: record*
30+
array: (single_array | layered_array)
31+
single_array: [netcdf] readarray
32+
layered_array: layered [netcdf] readarray+
33+
layered: "layered"i
34+
netcdf: "netcdf"i
35+
readarray: control [data]
36+
control: constant | internal | external
37+
constant: "constant"i double
38+
internal: "internal"i [factor] [iprn]
39+
external: "open/close"i filename [factor] [binary] [iprn]
40+
factor: "factor"i double
41+
iprn: "iprn"i integer
42+
binary: "(binary)"i
43+
filename: ESCAPED_STRING | _word
44+
data: double+
45+
46+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
47+
_number: SIGNED_NUMBER | NUMBER
48+
_integer: SIGNED_INT | INT
49+
_token: _word | _number
50+
51+
%import common.NEWLINE -> _NL
52+
%import common.CNAME
53+
%import common.WORD
54+
%import common.NUMBER
55+
%import common.INT
56+
%import common.ESCAPED_STRING
57+
%import common.SIGNED_NUMBER
58+
%import common.SIGNED_INT

flopy4/mf6/codec/reader/grammar/generated/chf-dfw.lark

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-DFW
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -27,3 +22,39 @@ export_array_ascii: "export_array_ascii"i
2722
dev_swr_conductance: "dev_swr_conductance"i
2823
manningsn: "manningsn"i array
2924
idcxs: "idcxs"i array
25+
26+
// Inline typed grammar rules
27+
integer: _integer
28+
double.2: _number
29+
string: ESCAPED_STRING | record
30+
record.1: _token+ _NL
31+
list: record*
32+
array: (single_array | layered_array)
33+
single_array: [netcdf] readarray
34+
layered_array: layered [netcdf] readarray+
35+
layered: "layered"i
36+
netcdf: "netcdf"i
37+
readarray: control [data]
38+
control: constant | internal | external
39+
constant: "constant"i double
40+
internal: "internal"i [factor] [iprn]
41+
external: "open/close"i filename [factor] [binary] [iprn]
42+
factor: "factor"i double
43+
iprn: "iprn"i integer
44+
binary: "(binary)"i
45+
filename: ESCAPED_STRING | _word
46+
data: double+
47+
48+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
49+
_number: SIGNED_NUMBER | NUMBER
50+
_integer: SIGNED_INT | INT
51+
_token: _word | _number
52+
53+
%import common.NEWLINE -> _NL
54+
%import common.CNAME
55+
%import common.WORD
56+
%import common.NUMBER
57+
%import common.INT
58+
%import common.ESCAPED_STRING
59+
%import common.SIGNED_NUMBER
60+
%import common.SIGNED_INT

flopy4/mf6/codec/reader/grammar/generated/chf-disv1d.lark

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-DISV1D
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -17,7 +12,7 @@ dimensions_block: "begin"i "dimensions"i dimensions_fields "end"i "dimensions"i
1712
griddata_block: "begin"i "griddata"i griddata_fields "end"i "griddata"i
1813
vertices_block: "begin"i "vertices"i vertices_fields "end"i "vertices"i
1914
cell1d_block: "begin"i "cell1d"i cell1d_fields "end"i "cell1d"i
20-
options_fields: (length_units | nogrb | grb_filerecord | xorigin | yorigin | angrot | export_array_ascii | crs)*
15+
options_fields: (length_units | nogrb | grb_filerecord | xorigin | yorigin | angrot | export_array_ascii)*
2116
dimensions_fields: (nodes | nvert)*
2217
griddata_fields: (width | bottom | idomain)*
2318
vertices_fields: (vertices)*
@@ -29,11 +24,46 @@ xorigin: "xorigin"i double
2924
yorigin: "yorigin"i double
3025
angrot: "angrot"i double
3126
export_array_ascii: "export_array_ascii"i
32-
crs: "crs"i array
3327
nodes: "nodes"i integer
3428
nvert: "nvert"i integer
3529
width: "width"i array
3630
bottom: "bottom"i array
3731
idomain: "idomain"i array
3832
vertices: "vertices"i recarray
3933
cell1d: "cell1d"i recarray
34+
35+
// Inline typed grammar rules
36+
integer: _integer
37+
double.2: _number
38+
string: ESCAPED_STRING | record
39+
record.1: _token+ _NL
40+
list: record*
41+
array: (single_array | layered_array)
42+
single_array: [netcdf] readarray
43+
layered_array: layered [netcdf] readarray+
44+
layered: "layered"i
45+
netcdf: "netcdf"i
46+
readarray: control [data]
47+
control: constant | internal | external
48+
constant: "constant"i double
49+
internal: "internal"i [factor] [iprn]
50+
external: "open/close"i filename [factor] [binary] [iprn]
51+
factor: "factor"i double
52+
iprn: "iprn"i integer
53+
binary: "(binary)"i
54+
filename: ESCAPED_STRING | _word
55+
data: double+
56+
57+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
58+
_number: SIGNED_NUMBER | NUMBER
59+
_integer: SIGNED_INT | INT
60+
_token: _word | _number
61+
62+
%import common.NEWLINE -> _NL
63+
%import common.CNAME
64+
%import common.WORD
65+
%import common.NUMBER
66+
%import common.INT
67+
%import common.ESCAPED_STRING
68+
%import common.SIGNED_NUMBER
69+
%import common.SIGNED_INT
Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// Auto-generated grammar for MF6 CHF-EVP
2-
%import typed.integer -> integer
3-
%import typed.double -> double
4-
%import typed.string -> string
5-
%import typed.list -> list
6-
%import typed.array -> array
72
%import common.WS
83
%import common.SH_COMMENT
94

@@ -14,7 +9,8 @@ start: block*
149
block: options_block | dimensions_block | period_block
1510
options_block: "begin"i "options"i options_fields "end"i "options"i
1611
dimensions_block: "begin"i "dimensions"i dimensions_fields "end"i "dimensions"i
17-
period_block: "begin"i "period"i period_fields "end"i "period"i
12+
period_block: "begin"i "period"i block_index period_fields "end"i "period"i block_index
13+
block_index: integer
1814
options_fields: (auxiliary | auxmultname | boundnames | print_input | print_flows | save_flows | ts_filerecord | obs_filerecord)*
1915
dimensions_fields: (maxbound)*
2016
period_fields: (stress_period_data)*
@@ -27,8 +23,39 @@ save_flows: "save_flows"i
2723
ts_filerecord: "ts6"i "filein"i string
2824
obs_filerecord: "filein"i "obs6"i string
2925
maxbound: "maxbound"i integer
30-
stress_period_data: cellid evaporation aux boundname
31-
cellid: integer+
32-
evaporation: double
33-
aux: double
34-
boundname: string
26+
stress_period_data: integer+ double double? string?
27+
// Inline typed grammar rules
28+
integer: _integer
29+
double.2: _number
30+
string: ESCAPED_STRING | record
31+
record.1: _token+ _NL
32+
list: record*
33+
array: (single_array | layered_array)
34+
single_array: [netcdf] readarray
35+
layered_array: layered [netcdf] readarray+
36+
layered: "layered"i
37+
netcdf: "netcdf"i
38+
readarray: control [data]
39+
control: constant | internal | external
40+
constant: "constant"i double
41+
internal: "internal"i [factor] [iprn]
42+
external: "open/close"i filename [factor] [binary] [iprn]
43+
factor: "factor"i double
44+
iprn: "iprn"i integer
45+
binary: "(binary)"i
46+
filename: ESCAPED_STRING | _word
47+
data: double+
48+
49+
_word: /[a-zA-Z0-9._'~,-\\(\\)]+/
50+
_number: SIGNED_NUMBER | NUMBER
51+
_integer: SIGNED_INT | INT
52+
_token: _word | _number
53+
54+
%import common.NEWLINE -> _NL
55+
%import common.CNAME
56+
%import common.WORD
57+
%import common.NUMBER
58+
%import common.INT
59+
%import common.ESCAPED_STRING
60+
%import common.SIGNED_NUMBER
61+
%import common.SIGNED_INT

0 commit comments

Comments
 (0)