3 Script to process ellipsometry data output by WVASE
4 and interface to gnuplot
12 keys = ["wavelength","angle", "psi", "delta", "uncertainty_psi", "uncertainty_delta"]
14 def getData(fileName):
15 dataFile = open(fileName, "r")
17 #wavelength angle psi delta uncertainty_psi uncertainty_delta
19 title = dataFile.readline().strip()
21 #Skip lines before data
27 line = dataFile.readline()
29 values = line.split(" ")
30 if len(values) != len(keys):
31 sys.stderr.write("Number of on line \""+line.strip() + "\" doesn't match number of keys ("+str(len(keys))+") " + str(keys) +"\n")
33 #sys.stdout.write("Debug: Read line \""+line.strip()+"\"\n")
35 for i in range(0, len(keys)):
36 point.update({keys[i]:values[i]})
38 #data.append({"wavelength":values[0], "angle":values[1], "psi":values[2], "delta":values[3], "uncertainty_psi":values[4], "uncertainty_delta":values[4]})
39 line = dataFile.readline()
41 return {"title":title, "data":data}
43 def extractData(line, x, y, conditions):
44 for condition in conditions:
45 [name, value] = condition.split("=")
46 if keys.count(name) <= 0:
47 sys.stderr.write("Unknown key \""+name+"\" for condition " + str(condition) + "\n")
49 values = value.split(",")
52 #sys.stdout.write(line[name] + " .vs. " + str(v) + "\n")
53 if float(line[name]) == float(v):
57 #sys.stdout.write("Condition \""+str(condition)+"\" not satisfied ("+str(line[name]) + " .vs. " + str(values[0])+ "\n")
59 #sys.stdout.write("Condition satisfied\n")
60 return [line[x], line[y]]
63 if __name__ == "__main__":
70 if arg[0] == '-' and arg[1] == '-':
73 #sys.stdout.write("State is " + state + "\n")
76 if len(sys.argv) - indexStart < 3:
77 sys.stderr.write("Usage: " +sys.argv[0] + " [options] datafile x y [conditions] outfile\n")
80 datafile = sys.argv[indexStart]
81 x = sys.argv[indexStart+1]
82 y = sys.argv[indexStart+2]
86 if keys.count(k) <= 0:
87 sys.stderr.write("Unknown key \""+k+"\"\n")
93 conditions = sys.argv[indexStart+3:len(sys.argv)-1]
94 #sys.stdout.write("Debug: Conditions are " + str(conditions) + "\n")
95 #for condition in conditions:
96 # sys.stdout.write(" Debug: Condition " + str(condition.split("=")) + "\n")
97 outfile = sys.argv[len(sys.argv)-1]
99 results = getData(datafile)
102 toPlot = map(lambda e : extractData(e, x,y,conditions) , results["data"])
103 toPlot = filter(lambda e : e != None and len(e) == 2, toPlot)
105 tmpFile = open(outfile+".tmp", "w")
107 tmpFile.write(point[0] + " " + point[1] + "\n")
110 if state == "--plot":
112 command += "set term png size 960,480\n"
113 command += "set output \"" + outfile + "\"\n"
114 command += "set xlabel \"" + x + "\"\n"
115 command += "set ylabel \"" + y + "\"\n"
116 command += "set title \"" + results["title"] + "\"\n"
117 command += "set key outside right\n"
118 command += "plot \"" + outfile + ".tmp\" using 1:2 with points title \""+str(conditions)+"\"\n"
121 tmpFile = open(outfile+".tmp.plt", "w")
122 tmpFile.write(command)
125 sys.stdout.write("Calling gnuplot now...\n")
126 #sys.stdout.write("------------------------------------\n")
127 os.system("gnuplot -p "+outfile+".tmp.plt") #2>/dev/null 1>/dev/null")
128 #sys.stdout.write("------------------------------------\n")
129 sys.stdout.write("gnuplot finished.\n")
131 os.remove(outfile+".tmp")
132 os.remove(outfile+".tmp.plt")
133 sys.stdout.write("Done!\n")
134 elif state == "--raw":
135 os.system("mv " + outfile+".tmp " + outfile)