Skip to content

decode 8 byte real according to Calma official GDSII format documenta… #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion gds2ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ def appendName(record):
}
return name_list[record[1][0]]

def unpack_8byte_real(data):
e = (data[0] & 0x7F) - 64
s = (data[0] & 0x80) >> 7

m = 0
for i in range(7):
m |= (data[i + 1] & 0xFF) << ((6 - i) * 8)

d = m
d = d * (16.0 ** (e - 14))
d = -d if s == 1 else d
return d

# Extracting Hex Data to readable ASCii
#
# input : (list) [ record length, [record type, data type], [data1, data2, ...] ]
Expand Down Expand Up @@ -117,7 +130,12 @@ def extractData(record):

elif record[1][1] == 0x05:
for i in list(range(0, (record[0]-4)//8)):
data.append( struct.unpack('>d', record[2][i])[0] )
# note that we cant just pack into a 8 byte python double
# because gdsii 8-byte real number has the form of
# SEEEEEEE MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM
# that's different than the IEEE 754 binary64 double format that python "struct" uses
# data.append( struct.unpack('>d', record[2][i])[0] )
data.append(unpack_8byte_real(record[2][i]))
return data

else:
Expand Down