source: sasview/DataLoader/readers/TXT2_Reader.py @ bd30f4a5

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 bd30f4a5 was 11a0319, checked in by Gervaise Alina <gervyh@…>, 17 years ago

dataloader is added.need plugins…

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[11a0319]1# class Loader  to load any king of file
2import wx
3import string,numpy
4class 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   
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            input_f =  open(path,'r')
21            buff = input_f.read()
22            lines = buff.split('\n')
23            self.x=[]
24            self.y=[]
25            self.dx = [] 
26            self.dy=[]
27            value="can't read" 
28            for line in lines:
29                toks = line.split()
30                try:
31                    x = float(toks[0])
32                    self.x.append(x)
33                except:
34                    print "READ ERROR", line
35                try:
36                    y = float(toks[1])
37                    self.y.append(y)
38                except:
39                    print "READ ERROR", line
40                try:
41                    dy=float(toks[2])
42                    self.dy.append(dy)
43
44                except:
45                    print "READ ERROR", line
46
47            if(( self.x==[])or (self.y==[])) or (self.dy !=[]):
48                print "went here"
49                #return value
50                raise ValueError, "Reader1 can't read"
51            else:
52                #msg="R1 reading: \n"+"this x :"+ str(self.x) +"\n"+"this y:"+str(self.y)+"\n"+"this dy :"+str(self.dy)+"\n"
53                #return msg
54                print "TXT2_Reader reading: \n"
55                return self.x,self.y,self.dy
56               
57   
58       
59   
60if __name__ == "__main__": 
61    read= Reader()
62    read.load("testdata_line.txt")
63   
64           
Note: See TracBrowser for help on using the repository browser.