ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since 792db7d5 was
1b0b3ca,
checked in by Gervaise Alina <gervyh@…>, 16 years ago
|
not cleaned yet but working using guiframe
|
-
Property mode set to
100644
|
File size:
2.5 KB
|
Line | |
---|
1 | # class Loader to load any king of file |
---|
2 | import wx |
---|
3 | import string,numpy |
---|
4 | class Reader: |
---|
5 | """ |
---|
6 | This class is loading values from given file or value giving by the user |
---|
7 | should be able to read only 2 columns of data |
---|
8 | """ |
---|
9 | ext=['.txt','.dat'] |
---|
10 | def _init_(self,x=None,y=None,dx=None,dy=None): |
---|
11 | # variable to store loaded values |
---|
12 | self.x = x |
---|
13 | self.y = y |
---|
14 | self.dx = dx |
---|
15 | self.dy = dy |
---|
16 | |
---|
17 | def read(self,path, format=None): |
---|
18 | """ Store the values loaded from file in local variables """ |
---|
19 | if not path == None: |
---|
20 | read_it = False |
---|
21 | |
---|
22 | for item in self.ext: |
---|
23 | if path.lower().find(item)>=0: |
---|
24 | read_it = True |
---|
25 | #print "this is the flag",read_it, path.lower() |
---|
26 | if read_it==False: |
---|
27 | return None |
---|
28 | else: |
---|
29 | input_f = open(path,'r') |
---|
30 | buff = input_f.read() |
---|
31 | lines = buff.split('\n') |
---|
32 | self.x=[] |
---|
33 | self.y=[] |
---|
34 | self.dx = [] |
---|
35 | self.dy=[] |
---|
36 | for line in lines: |
---|
37 | toks = line.split() |
---|
38 | try: |
---|
39 | x = float(toks[0]) |
---|
40 | self.x.append(x) |
---|
41 | except: |
---|
42 | pass |
---|
43 | #print "READ ERROR", line |
---|
44 | try: |
---|
45 | y = float(toks[1]) |
---|
46 | self.y.append(y) |
---|
47 | except: |
---|
48 | pass |
---|
49 | #print "READ ERROR", line |
---|
50 | try: |
---|
51 | dy=float(toks[2]) |
---|
52 | self.dy.append(dy) |
---|
53 | |
---|
54 | except: |
---|
55 | pass |
---|
56 | #print "READ ERROR", line |
---|
57 | |
---|
58 | if(( self.x==[])or (self.y==[])) or (self.dy !=[]): |
---|
59 | #print "went here" |
---|
60 | #return value |
---|
61 | raise ValueError, "TXT2_Reader can't read %s"%path |
---|
62 | else: |
---|
63 | #msg="R1 reading: \n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n" |
---|
64 | #return msg |
---|
65 | print "TXT2_Reader reading %s\n" %path |
---|
66 | return self.x,self.y,self.dy |
---|
67 | return None |
---|
68 | |
---|
69 | |
---|
70 | |
---|
71 | if __name__ == "__main__": |
---|
72 | read= Reader() |
---|
73 | read.load("testdata_line.txt") |
---|
74 | |
---|
75 | |
---|
Note: See
TracBrowser
for help on using the repository browser.