@@ -75,7 +75,7 @@ def checkfield(self, field):
75
75
fielditem = getattr (self , field )
76
76
77
77
# Ensure the field item is a list
78
- if type (fielditem ) != list
78
+ if type (fielditem ) != list :
79
79
print ('The ' , field , ' field must be a list' )
80
80
sys .exit ()
81
81
@@ -131,7 +131,6 @@ def checkfieldcohesion(self):
131
131
132
132
def wrannfile (self ):
133
133
134
-
135
134
# If there is an fs, write it
136
135
if self .fs is not None :
137
136
databytes = insert_fs (self .fs )
@@ -182,9 +181,6 @@ def allfieldbytes(self):
182
181
fieldbytes [field ] = self .fieldbytes (field )
183
182
184
183
185
-
186
-
187
-
188
184
# Only need to write annsamp and anntype
189
185
#if extrawritefields == []:
190
186
# for i in range(0, len(self.annsamp)):
@@ -202,10 +198,6 @@ def fieldbytes(self, field):
202
198
203
199
databytes = []
204
200
205
-
206
- 'num' , 'subtype' , 'chan' , 'aux'
207
-
208
-
209
201
# annsamp and anntype bytes come together
210
202
if field == 'annsamp_anntype' :
211
203
# Difference values for annotation samples
@@ -230,18 +222,45 @@ def fieldbytes(self, field):
230
222
231
223
databytes .append (indexbytes )
232
224
225
+ # All other fields are optional
233
226
elif field == 'num' :
234
227
for i in range (0 , len (self .num )):
235
- # First byte gives
236
- databytes .append ([ , + 240 ])
237
-
238
-
228
+ if self .num [i ] is None :
229
+ databytes .append (None )
230
+ else :
231
+ # First byte stores num
232
+ # second byte stores 60*4 indicator
233
+ databytes .append ([self .num [i ], + 240 ])
239
234
elif field == 'subtype' :
240
- print ('on it' )
235
+ for i in range (0 , len (self .subtype )):
236
+ if self .subtype [i ] is None :
237
+ databytes .append (None )
238
+ else :
239
+ # First byte stores subtype
240
+ # second byte stores 61*4 indicator
241
+ databytes .append ([self .subtype [i ], + 244 ])
241
242
elif field == 'chan' :
242
- print ('on it' )
243
+ for i in range (0 , len (self .chan )):
244
+ if self .chan [i ] is None :
245
+ databytes .append (None )
246
+ else :
247
+ # First byte stores num
248
+ # second byte stores 62*4 indicator
249
+ databytes .append ([self .chan [i ], + 248 ])
243
250
elif field == 'aux' :
244
- print ('on it' )
251
+ for i in range (0 , len (self .aux )):
252
+ if self .aux [i ] is None :
253
+ databytes .append (None )
254
+ else :
255
+ aux = self .aux [i ]
256
+ # - First byte stores length of aux field
257
+ # - Second byte stores 63*4 indicator
258
+ # - Then store the aux string characters
259
+ auxbytes = [len (aux ), + 252 ] + [ord (i ) for i in x ]
260
+ # Zero pad odd length aux strings
261
+ if len (aux ) % 2 :
262
+ auxbytes .append ([0 ])
263
+ databytes .append (auxbytes )
245
264
246
265
return databytes
247
266
0 commit comments