diff --git a/lib/fieldio.py b/lib/fieldio.py index 4fa4688..1fbd2da 100644 --- a/lib/fieldio.py +++ b/lib/fieldio.py @@ -37,6 +37,13 @@ def xmlFind(s,r): raise ValueError(f'finding record {r} in unsupported xml: {s}') return m[0] +def trimNull(d): + n = d.find(b'\0') + if n>=0: + return d[:n] + else: + return d + def printLimeHeaders(file): f = open(file,'rb') while True: @@ -51,7 +58,7 @@ def printLimeHeaders(file): mend = 1 & mbeg_end_res>>14 mres = ~(3<<14) & mbeg_end_res print(f'mbeg mend res: {mbeg} , {mend} , {mres}') - type = type[:type.find(b'\0')] + type = trimNull(type) print(f'size: {size}') print(f'type: {type}') loca = f.tell() @@ -60,9 +67,7 @@ def printLimeHeaders(file): next = (size+7)//8*8 else: data = f.read(size) - s = data.find(b'\0') - if s>0: - data = data[:s] + data = trimNull(data) print(f'* DATA: {data}') next = 7-(size+7)%8 # print(f'next: {next}') @@ -98,7 +103,7 @@ def logput(*args,**kwargs): # mend = 1 & mbeg_end_res>>14 # mres = ~(3<<14) & mbeg_end_res # logput(f'mbeg mend res: {mbeg} , {mend} , {mres}') - type = type[:type.find(b'\0')] + type = trimNull(type) # logput(f'size: {size}') # logput(f'type: {type}') loca = f.tell() @@ -110,7 +115,7 @@ def logput(*args,**kwargs): next = 7-(size+7)%8 else: data = f.read(size) - data = data[:data.find(b'\0')] + data = trimNull(data) if type==b'scidac-private-file-xml': # logput('version: ',xmlFind(data,'version')) spacetime = int(xmlFind(data,'spacetime')) @@ -240,16 +245,16 @@ def writeLattice(gauge, file): binary = numpy.ascontiguousarray(gauge, dtype=f'>c{latprec}').tobytes() suma,sumb = scidacChecksum(binary, vol, latdatacount*lattypesize) - scidac_private_file = f'1.1{latdatacount}{dims}0'.encode() - scidac_private_record = f'1.1{datetime.datetime.now(datetime.timezone.utc).ctime()} UTC0numpy.ndarray{precision}{latnc}1{lattypesize}{latdatacount}'.encode() - scidac_checksum = f'1.0{suma:x}{sumb:x}'.encode() + scidac_private_file = f'1.1{latdatacount}{dims}0\0'.encode() + scidac_private_record = f'1.1{datetime.datetime.now(datetime.timezone.utc).ctime()} UTC0numpy.ndarray{precision}{latnc}1{lattypesize}{latdatacount}\0'.encode() + scidac_checksum = f'1.0{suma:x}{sumb:x}\0'.encode() f = open(file,'wb') limeItemWrite(f, True, False, scidac_private_file, b'scidac-private-file-xml') - limeItemWrite(f, False, True, b'generated by NTHMC', b'scidac-file-xml') + limeItemWrite(f, False, True, b'generated by NTHMC\0', b'scidac-file-xml') limeItemWrite(f, True, False, scidac_private_record, b'scidac-private-record-xml') - limeItemWrite(f, False, False, b'gauge configuration', b'scidac-record-xml') + limeItemWrite(f, False, False, b'gauge configuration\0', b'scidac-record-xml') limeItemWrite(f, False, False, binary, b'scidac-binary-data') limeItemWrite(f, False, True, scidac_checksum, b'scidac-checksum')