@@ -237,6 +237,25 @@ def get_write_subset(self, spec_type):
237237 return write_fields
238238
239239
240+ def preprocess_header (self , field ):
241+ """
242+ Get and process the fields as needed before writing
243+ """
244+ string_field = str (getattr (self , field ))
245+
246+ # Certain fields need extra processing
247+ if field == "fs" and isinstance (self .fs , float ):
248+ if round (self .fs , 8 ) == float (int (self .fs )):
249+ string_field = str (int (self .fs ))
250+ elif field == "base_time" and "." in string_field :
251+ string_field = string_field .rstrip ("0" )
252+ elif field == "base_date" :
253+ string_field = "/" .join (
254+ (string_field [8 :], string_field [5 :7 ], string_field [:4 ])
255+ )
256+
257+ return string_field
258+
240259class HeaderMixin (BaseHeaderMixin ):
241260 """
242261 Mixin class with single-segment header methods. Inherited by Record class.
@@ -534,19 +553,7 @@ def wr_header_file(self, rec_write_fields, sig_write_fields, write_dir):
534553 for field in RECORD_SPECS .index :
535554 # If the field is being used, add it with its delimiter
536555 if field in rec_write_fields :
537- string_field = str (getattr (self , field ))
538-
539- # Certain fields need extra processing
540- if field == "fs" and isinstance (self .fs , float ):
541- if round (self .fs , 8 ) == float (int (self .fs )):
542- string_field = str (int (self .fs ))
543- elif field == "base_time" and "." in string_field :
544- string_field = string_field .rstrip ("0" )
545- elif field == "base_date" :
546- string_field = "/" .join (
547- (string_field [8 :], string_field [5 :7 ], string_field [:4 ])
548- )
549-
556+ string_field = self .preprocess_header (field )
550557 record_line += (
551558 RECORD_SPECS .loc [field , "delimiter" ] + string_field
552559 )
@@ -756,25 +763,8 @@ def wr_header_file(self, write_fields, write_dir):
756763 for field in RECORD_SPECS .index :
757764 # If the field is being used, add it with its delimiter
758765 if field in write_fields :
759- string_field = str (getattr (self , field ))
760-
761- # Certain fields need extra processing
762- if field == "fs" and isinstance (self .fs , float ):
763- if round (self .fs , 8 ) == float (int (self .fs )):
764- string_field = str (int (self .fs ))
765- elif field == "base_time" and "." in string_field :
766- string_field = string_field .rstrip ("0" )
767- elif field == "base_date" :
768- string_field = "/" .join (
769- (string_field [8 :], string_field [5 :7 ], string_field [:4 ])
770- )
771-
772- record_line += (
773- RECORD_SPECS .loc [field , "delimiter" ] + string_field
774- )
775- # The 'base_counter' field needs to be closed with ')'
776- if field == "base_counter" :
777- record_line += ")"
766+ string_field = self .preprocess_header (field )
767+ record_line += (RECORD_SPECS .loc [field , "delimiter" ] + string_field )
778768
779769 header_lines = [record_line ]
780770
0 commit comments