def get_plot_file_info(output,file_name): found,lines=zip_get_data_file(file_name) print(file_name) if found==False: print("can't file file") return False for i in range(0, len(lines)): lines[i]=lines[i].rstrip() if len(lines)>1: if lines[0]=="#gpvdm": for i in range(0, len(lines)): if (len(lines[i])>0): if (lines[i][0]!="#"): break else: command=lines[i].split(" ",1) if len(command)<2: command.append("") if (command[0]=="#x_mul"): output.x_mul=float(command[1]) if (command[0]=="#y_mul"): output.y_mul=float(command[1]) if (command[0]=="#x_label"): output.x_label=command[1] if (command[0]=="#y_label"): output.y_label=command[1] if (command[0]=="#x_units"): output.x_units=command[1] if (command[0]=="#y_units"): output.y_units=command[1] if (command[0]=="#logscale_x"): output.logx=bool(int(command[1])) if (command[0]=="#logscale_y"): output.logy=bool(int(command[1])) if (command[0]=="#type"): output.type=command[1] if (command[0]=="#title"): output.title=command[1] if (command[0]=="#section_one"): output.section_one=command[1] if (command[0]=="#section_two"): output.section_two=command[1] if (command[0]=="#time"): output.time=float(command[1]) if (command[0]=="#Vexternal"): output.Vexternal=float(command[1]) if (command[0]=="#x"): output.x_len=int(command[1]) if (command[0]=="#y"): output.y_len=int(command[1]) if (command[0]=="#z"): output.z_len=int(command[1]) return True return False
def read_xyz_data(x,y,z,file_name): found,lines=zip_get_data_file(file_name) if found==True: lines_to_xyz(x,y,z,lines) #print "here z=,",z,x,file_name return True else: return False
def read_data_2d(x_scale, y_scale, z, file_name): if file_name == None: return False found, lines = zip_get_data_file(file_name) if found == True: x_max = 0 y_max = 0 y_pos = 0 z_store = [] for i in range(0, len(lines)): if len(lines[i]) > 0: if lines[i][0] != "#" and lines[i] != "\n": temp = lines[i] temp = re.sub(" +", " ", temp) temp = re.sub("\t", " ", temp) temp = temp.rstrip() sline = temp.split(" ") if len(sline) == 3: if x_max == 0: y_scale.append(float(lines[i].split(" ")[1])) if y_pos == 0: x_scale.append(float(lines[i].split(" ")[0])) z_store.append(float(lines[i].split(" ")[2])) y_pos = y_pos + 1 if x_max == 0: y_max = y_max + 1 if lines[i] == "": x_max = x_max + 1 y_pos = 0 if lines[len(lines) - 1] != "\n": x_max = x_max + 1 x_max = len(x_scale) y_max = len(y_scale) pos = 0 for x in range(0, x_max): z.append([]) for y in range(0, y_max): z[x].append(z_store[pos]) pos = pos + 1 return True else: return False
def lines_read(out,file_name): found,lines=zip_get_data_file(file_name) if found==False: return False for i in range(1,len(lines)): if lines[i]!="": #out.append(vec()) text=lines[i].split(" ") out.append(vec()) out[-1].x=float(text[0]) out[-1].y=float(text[1]) return True
def read_data_2d(x_scale,y_scale,z,file_name): found,lines=zip_get_data_file(file_name) if found==True: x_max=0 y_max=0 y_pos=0 z_store=[] for i in range(0, len(lines)): if (lines[i][0]!="#"): if lines[i]!="\n": temp=lines[i] temp=re.sub(' +',' ',temp) temp=re.sub('\t',' ',temp) temp=temp.rstrip() sline=temp.split(" ") if len(sline)==3: if x_max==0: y_scale.append(float(lines[i].split(" ")[1])) if y_pos==0: x_scale.append(float(lines[i].split(" ")[0])) z_store.append(float(lines[i].split(" ")[2])) y_pos=y_pos+1 if x_max==0: y_max=y_max+1 if lines[i]=="\n": x_max=x_max+1 y_pos=0 if lines[len(lines)-1]!="\n": x_max=x_max+1 #print "load 3d data",x_scale,y_scale pos=0 for x in range(0, x_max): z.append([]) for y in range(0, y_max): z[x].append(z_store[pos]) pos=pos+1 return True else: return False
def dat_file_read(out, file_name): if file_name == None: return False found, lines = zip_get_data_file(file_name) if found == False: return False out.x_scale = [] out.y_scale = [] out.z_scale = [] out.data = [] out.x_len, out.y_len, out.z_len = find_dim(lines) if out.x_len == False: out.x_len, out.y_len, out.z_len = guess_dim(lines) if out.x_len == False: print(file_name) return False out.data = [[[0.0 for k in range(out.y_len)] for j in range(out.x_len)] for i in range(out.z_len)] out.x_scale = [0.0] * out.x_len out.y_scale = [0.0] * out.y_len out.z_scale = [0.0] * out.z_len data_started = False x = 0 y = 0 z = 0 dim = 0 for i in range(0, len(lines)): temp = lines[i] temp = re.sub(" +", " ", temp) temp = re.sub("\t", " ", temp) s = temp.split(" ") if len(s) > 0: # if if data_started == False: if is_number(s[0]) == True: data_started = True if s[0] == "#end": break if data_started == True: line_found = False if len(s) == 4: line_found = True out.data[z][x][y] = float(s[3]) a0 = s[0] a1 = s[1] a2 = s[2] if len(s) == 3: line_found = True out.data[z][x][y] = float(s[2]) a0 = s[0] a1 = s[1] a2 = 0.0 elif len(s) == 2: line_found = True out.data[z][x][y] = float(s[1]) a0 = s[0] a1 = 0.0 a2 = 0.0 else: print("skip") if line_found == True: if len(s) == 2: if x == 0 and z == 0: out.y_scale[y] = float(a0) if len(s) == 3: if x == 0 and z == 0: out.y_scale[y] = float(a1) if z == 0 and y == 0: out.x_scale[x] = float(a0) # if z==y: # out.z_scale[y]=float(a0) y = y + 1 if y == out.y_len: y = 0 x = x + 1 if x == out.x_len: x = 0 z = z + 1 if s[0] == "#data": data_started = True if data_started == False: return False return True
def get_plot_file_info(output,file_name): found,lines=zip_get_data_file(file_name) #print(file_name) if found==False: print("can't find file",file_name) return False for i in range(0, len(lines)): lines[i]=lines[i].rstrip() if len(lines)>1: if lines[0]=="#gpvdm": for i in range(0, len(lines)): if (len(lines[i])>0): if (lines[i][0]!="#"): break else: command=lines[i].split(" ",1) if len(command)<2: command.append("") if (command[0]=="#x_mul"): output.x_mul=float(command[1]) if (command[0]=="#y_mul"): output.y_mul=float(command[1]) if (command[0]=="#z_mul"): output.z_mul=float(command[1]) if (command[0]=="#x_label"): output.x_label=command[1] if (command[0]=="#y_label"): output.y_label=command[1] if (command[0]=="#z_label"): output.z_label=command[1] if (command[0]=="#data_label"): output.data_label=command[1] if (command[0]=="#x_units"): output.x_units=command[1] if (command[0]=="#y_units"): output.y_units=command[1] if (command[0]=="#z_units"): output.z_units=command[1] if (command[0]=="#data_units"): output.data_units=command[1] if (command[0]=="#logscale_x"): output.logx=bool(int(command[1])) if (command[0]=="#logscale_y"): output.logy=bool(int(command[1])) if (command[0]=="#logscale_z"): output.logz=bool(int(command[1])) if (command[0]=="#type"): output.type=command[1] if (command[0]=="#title"): output.title=command[1] if (command[0]=="#section_one"): output.section_one=command[1] if (command[0]=="#section_two"): output.section_two=command[1] if (command[0]=="#time"): output.time=float(command[1]) if (command[0]=="#Vexternal"): output.Vexternal=float(command[1]) if (command[0]=="#x"): output.x_len=int(command[1]) if (command[0]=="#y"): output.y_len=int(command[1]) if (command[0]=="#z"): output.z_len=int(command[1]) return True return False