@@ -23,10 +23,7 @@ def __init__(self,outfile,headers):
23
23
24
24
25
25
def write_row (self ,row ):
26
- # remove any keys not in 'fieldnames' to avoid ValueError
27
- for key in list (row .keys ()):
28
- if key not in self .csvwriter .fieldnames :
29
- del row [key ]
26
+
30
27
self .csvwriter .writerow (row )
31
28
32
29
@@ -70,29 +67,8 @@ def close(self):
70
67
71
68
xmlfile .write (xml )
72
69
73
-
74
- def parse_octet_length (octet_str ):
75
- # attempt to compute the length for simple cases
76
- # fallback if expression is more complex
77
- if any (sym in octet_str for sym in ['(' , ')' , '+' , '*' , 'ND' , 'NF' , 'n' ]):
78
- return ""
70
+
79
71
80
- total_length = 0
81
- parts = [p .strip () for p in octet_str .split (',' )]
82
- for p in parts :
83
- range_match = re .match (r'^(\d+)-(\d+)$' , p )
84
- single_match = re .match (r'^(\d+)$' , p )
85
- if range_match :
86
- start = int (range_match .group (1 ))
87
- end = int (range_match .group (2 ))
88
- total_length += (end - start + 1 )
89
- elif single_match :
90
- total_length += 1
91
- else :
92
- return ""
93
- return str (total_length )
94
-
95
-
96
72
def process_files (files ,pattern ,writers ,title_prefix ):
97
73
98
74
rows = []
@@ -165,13 +141,6 @@ def process_files(files,pattern,writers,title_prefix):
165
141
rows = [row for * _ ,row in decorated ]
166
142
167
143
168
-
169
- # For Template rows, add computed OctetNumer
170
- if pattern == 'GRIB2_Template' :
171
- for row in rows :
172
- octet_str = row .get ("OctetNo" , "" )
173
- row ["OctetCount" ] = parse_octet_length (octet_str )
174
-
175
144
for row in rows :
176
145
for writer in writers :
177
146
writer .write_row (row )
@@ -207,12 +176,13 @@ def process_files(files,pattern,writers,title_prefix):
207
176
# Template tables
208
177
template_files = load_files ("GRIB2_Template" ,basedir = "." )
209
178
210
- # Added "OctetCount" to both fieldnames
211
- fieldnames = ["Title_en" ,"OctetNo" ,"Contents_en" ,"Note_en" ,"noteIDs" ,"codeTable" ,"flagTable" ,"OctetCount" ,"Status" ]
179
+ fieldnames = ["Title_en" ,"OctetNo" ,"Contents_en" ,"Note_en" ,"noteIDs" ,"codeTable" ,"flagTable" ,"Status" ]
212
180
csv_writer = CSVWriter ("txt/Template.txt" ,fieldnames )
213
181
214
182
xml_elements = ["Title_en" ,"OctetNo" ,"Contents_en" ,"Note_en" ,"noteIDs" ,"codeTable" ,"flagTable" ,"Status" ]
215
183
xml_writer = XMLWriter ("xml/Template.xml" ,xml_elements ,"GRIB2_Template_en" )
216
184
217
185
writers = [csv_writer ,xml_writer ]
218
186
process_files (template_files ,"GRIB2_Template" ,writers ,"Identification template" )
187
+
188
+
0 commit comments