# # auto2uvmat3spline.py # # # Created by Victor Brena on 06/05/2010. # # This script loads a given AUTO solution data file, interpolates it # homogeneously, and saves data on intercalated files or separately xppaut-like format. #libraries needed from numpy import * import sys from scipy import interpolate #homogeneous cubic spline function def distribute(input_file,sufix,sortof): print "Input file name:", input_file #loads input file s = loadtxt(input_file) #selects columns x = s[:,0] u = s[:,1] v = s[:,2] #interpolates linearly from 0 to shape(x)[0] N = shape(x) print "Number re-scaled points:", N[0] utck = interpolate.splrep(x,u) vtck = interpolate.splrep(x,v) xnew = linspace(0,1,N[0]) unew = interpolate.splev(xnew,utck,der=0) vnew = interpolate.splev(xnew,vtck,der=0) foutname = str('s%04d'%sufix) #choose if solutions will be saved on separate files or xpp format if sortof == 0: fout = open('U_'+foutname,'w') for m in range(0,N[0]): su = unew[m] fout.write(str(su)) fout.write('\n') fout.close() print "U file name:", 'U_'+foutname fout = open('V_'+foutname,'w') for m in range(0,N[0]): sv = vnew[m] fout.write(str(sv)) fout.write('\n') fout.close() print "V file name:", 'V_'+foutname else: fout = open('UV_'+foutname,'w') for m in range(0,N[0]): su = unew[m] sv = vnew[m] fout.write(str(su)) fout.write('\n') fout.write(str(sv)) fout.write('\n') fout.close() print "UV file name:", 'UV_'+foutname # This is the Python syntax for making a script runnable if __name__ == '__main__': # The first argument is the name of the input file. input_file = sys.argv[1] # The second argument is the prefix to use for the # output files. sufix = sys.argv[2] # The third argument sorts output data intercalary or separately. sortof = sys.argv[3] distribute(input_file,sufix,sortof)