#Leathem's thesis, Appendix A, Program for Creating Elliptical Stream Files # Line 364 = main() > On .exe traceback < Commenting t kills p shell prompts. Not option. # Line 320 = Output destination prompt > On .exe tb < # The program overwites files without notification or warning . # #!/usr/bin/python import math, array def square(x): result = x * x return result def Parse(): ## read in the command line options from optparse import OptionParser usage="%prog [OPTIONS] FILE" parser = OptionParser(usage) parser.add_option("-x", "--x-axis", type="int", dest="xa", default=10, #p.57 help="The length of the x-axis of the ellipse. Default=10") parser.add_option("-y", "--y-axis", type="int", dest="ya", default=10, help="The length of the x-axis of the ellipse. Default=10") parser.add_option("-s", "--spacing", type="int", dest="s", default=75, help="The spacing of the ellipses. Default=75") parser.add_option("-q", "--spacing2", type="int", dest="q", default=75, help="The spacing of the 2nd array of ellipses. Default=75") parser.add_option("-d", "--dwelltime", type="int", dest="d", default=100, help="Dwell time of the ion beam. Default=100") parser.add_option("-p", "--shape", type="int", dest="p", default=0, help="The basis shape; 0 : ellipse, 1 : rectangle Default=0") parser.add_option("-a", "--angle", type="float", dest="a", default=0, help="Angle of rotation of the ellipse(degrees). Default=0") #p.58 parser.add_option("-r", "--sparse", type="int", dest="r", default=0, help="Sparse Pattern; 0 : no, 1 : yes Default=0") parser.add_option("-l", "--loops", type="int", dest="l", default=1, help="The number of times to repeat the pattern. Default=1") parser.add_option("-n", "--num", type="int", dest="n", default=1, help="The number of shapes in the basis, 1 or 2. Default=1") parser.add_option("-u", "--xoffset", type="int", dest="xo", default=15, help="The x-offset of the second shape in the basis. Default=15") parser.add_option("-v", "--yoffset", type="int", dest="yo", default=15, help="The y-offset of the second shape in the basis. Default=15") (options, args) = parser.parse_args() try: args[0] except IndexError: parser.print_help() #p.59 return (1,None,options) else: return (0,args[0],options) def Max(xa,ya): """ The maximum of two values """ if xa > ya: max=int(xa) else: max=int(ya) return(max) def Min(xa,ya): """ The maximum of two values """ if xa < ya: max=int(xa) else: max=int(ya) return(max) class Shape: def Define(self): """ Initialise some values for the while loop """ shape=[] count=0 i=-self.max_dim j=-self.max_dim while j < self.max_dim: while i 10**6-1): # print "Warning, number of lines is ", count1_prediction+count2_prediction, "1,000,000" # print "There are currently ", count_max1, "elements in array1" # print "There are currently ", count_max2, "elements in array2" # print "Reducing the number of lattice points..." # print "" # gridmax=gridmax-Min(spacing1,spacing2) # count_max1=(gridmax-gridmin+1)//spacing1 # count_max2=(gridmax-Max(stream.xo,stream.yo)-gridmin+1)//spacing2 # count_max=Max(count_max1,count_max2) # count1_prediction=count_max1**2*shape.count # count2_prediction=count_max2**2*shape.count print "Calculating the grid... " xi,yi=0,0 count1, count2 = 0,0 x, y = gridmin, gridmin while yi < count_max: while xi < count_max: for point in shape.shape: if xi < count_max1 and yi < count_max1: xp = gridmin + int(xi*spacing1) + point[0] yp = gridmin + int(yi*spacing1) + point[1] stream.grid.AddPoint(xp,yp) #p.66 count1 = count1 + 1 for point in shape.shape: if xi < count_max2 and yi < count_max2: xp = gridmin + int(xi*spacing2) + point[0] + stream.xo yp = gridmin + int(yi*spacing2) + point[1] + stream.yo stream.grid.AddPoint(xp,yp) count2 = count2 + 1 # print xi,yi xi=xi+1 yi=yi+1 xi=0 count = count1 + count2 print "writing the file..." stream.Write(filename) print "Lines in Array 1:" print " expected:", count1_prediction print " actual:", count1 print "Lines in Array 2:" print " expected:", count2_prediction print " actual:", count2 print "Lines in Total:" print " expected:", count1_prediction+count2_prediction print " actual:", stream.grid.Count() def Main(): #p.67 filename=raw_input("Enter destination and filename as > C:\Name.STR <: ") # 320 on traceback log. n = int (raw_input ("Enter 1 for a single array or 2 for a double array: ")) if n==1: ### A single array print ("Brian's defaults were x=10,y=10,s=75,d=100,p=0,a=0,r=0,l=1.") t = raw_input("Enter x,y,s,d,p,a,r,l (separate values with commas, no spaces): ") t = t.split(',') xa = int(t[0]) ya = int(t[1]) s = int(t[2]) d = int(t[3]) p = int(t[4]) a = int(t[5]) r = int(t[6]) l = int(t[7]) stream=Stream(s,d,l) basis=Shape(xa,ya,a,p,r) CreateArray(filename,basis,stream) elif n==2: ### A double array print ("Brian's defaults were x=10,y=10,s=75,q=75,d=100,p=0,a=0,r=0,l=1,u=15,v=15.") t = raw_input("Enter x,y,s,q,d,p,a,r,l,u,v (separate values with commas, no spaces): ") t = t.split(',') xa = int(t[0]) ya = int(t[1]) s = int(t[2]) q = int(t[3]) d = int(t[4]) p = int(t[5]) a = int(t[6]) r = int(t[7]) l = int(t[8]) xo = int(t[9]) yo = int(t[10]) stream=Stream2(s,q,xo,yo,d,l) basis=Shape(xa,ya,a,p,r) CreateArray2(filename,basis,stream) Main() # line 364. shows in .EXE execution time traceback log.