forked from cihologramas/pyoptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gls2rtgd.py
executable file
·80 lines (61 loc) · 2.33 KB
/
gls2rtgd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from enthought.traits.api import Float, String
from os import access, F_OK
"""
Utility to convert the Oslo Glass Data Files to the RayTrace Glass Data Format.
"""
from optparse import OptionParser
parser=OptionParser(usage="usage: %prog -i inputfile -o outputfile",
description=\
"Utility to convert de Oslo Glass Data Files, to the RayTrace"\
"material library file")
parser.add_option("-i", dest="inputfile", help="GLS file to convert")
parser.add_option("-o", dest="outputfile", help="RTGL file to create")
(options, args) = parser.parse_args()
if options.inputfile==None:
parser.error("\n\nError: Input filename must be given.\n\n")
print "\n\n\nProcessing file", options.inputfile, "\n\n\n"
try:
f=open(options.inputfile, 'r')
except:
print "File ", options.inputfile, "not found"
lines=f.readlines()
f.close()
try:
version, size, library=lines[0].split(None, 2)
s=float(size)
except:
exit("The input file seems not to be an OSLO glass description file")
if version not in ("5.00","5.11","5.31","5.32","5.41","6.02" , "6.03"):
print "Library version migth not be supported. Please verify the output file"
# Check if the output file exists
if access(options.outputfile, F_OK):
exit("The outputfile already exists. Use a diferent one.\n\n")
fo=open(options.outputfile, "w")
# Write the header of the library
# Library type RayTraceGlassLibrary Version 0
fo.write("RTGL-0\n")
# Description line allways tab separated
# ref - Glass reference as given by the manufacturer
# nd - Refraction index for the d line
# vd - Abbe's number for the d line
# B1,B2,B3,C1,C2,C3 - Dispersion constants for the glass
fo.write("ref\tnd\tvd\tB1\tB2\tB3\tC1\tC2\tC3\n")
for line in lines[1:]:
line_data=line.split()
# Skip blank lines
if len(line_data)!=0:
ndisp_coef=int(line_data[13])
if ndisp_coef ==6:
ref=line_data[0]
nd=line_data[1]
vd=line_data[2]
B1=line_data[14]
B2=line_data[15]
B3=line_data[16]
C1=line_data[17]
C2=line_data[18]
C3=line_data[19]
fo.write("\"%s\"\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n"%\
(ref, nd, vd, B1, B2, B3, C1, C2, C3))