@@ -21,22 +21,40 @@ def make_var(lap,id=None,shape=None):
2121 lap .id = id
2222 return lap
2323
24+
25+ # TODO: need an actual 'vars.txt' file for the doctests
2426def readAscii ( text_file ,header = 0 , ids = None , shape = None , next = '------' ,separators = [';' ,',' ,':' ]):
25- """Reads data from an ascii file
26- Usage :::
27- vars = genutil.ASCII.readAscii( text_file ,header=0, ids=None, shape=None, next='------',separators=[';',',',':'])
28- :::
29-
30- Options :::
31- text_file :: ASCII File to read from.
32- header :: (0) Number of header lines, these lines will be skipped.
33- ids :: (None) use the values in this list as variable ids (1 per variable returned)
34- shape :: (None) use the tuple/list in this list as the final shape of the variable read.
35- next :: ('------') character string marking separation between variables
36- separators :: ([';',',', ':']) List of character recognized as column separator
37- Output :::
38- vars :: List containing transient(s) variable(s) possibly named after ids and reshaped from the 'shape' option.
39-
27+ """
28+ Reads data from an ascii file to generate a list of transient(s)/varable(s)
29+
30+ :Example:
31+
32+ .. doctest:: genutil_ASCII_readascii
33+
34+ >>> vars=genutil.ASCII.readAscii("vars.txt") # use default params
35+
36+ :param text_file: A string, containing the path to an ASCII File to read from.
37+ :type text_file: str
38+
39+ :param header: Number of header lines, these lines will be skipped.
40+ :type header: int
41+
42+ :param ids: List of values to use as variable ids (1 per variable returned)
43+ :type ids: list
44+
45+ :param shape: use the tuple/list in this list as the final shape of the variable read.
46+ :type shape: tuple or list
47+
48+ :param next: character string marking separation between variables (i.e. '------')
49+ :type next: str
50+
51+ :param separators: ([';',',', ':']) List of characters recognized as column
52+ separators. Can be represented as a list or a string.
53+ If it is a string, separator characters must be space-delimited.
54+ :type separators: list or str
55+
56+ :returns: List containing transient(s) variable(s) possibly named after ids and reshaped from the 'shape' option.
57+ :rtype: list
4058 """
4159 sep = []
4260 if isinstance (separators ,str ):
@@ -82,24 +100,49 @@ def readAscii( text_file ,header=0, ids=None, shape=None, next='------',separato
82100 return vars [0 ]
83101
84102
85- def read_col ( text_file ,header = 0 , cskip = 0 , cskip_type = 'columns' , axis = False , ids = None , idrow = 0 , separators = [';' ,',' , ':' ]):
86- """ Reads column-stored data from ASCII files
87- Usage:::
88- vars = genutil.ASCII.read_col( text_file ,header=0, cskip=0, cskip_type='columns', axis=False, ids=None, idrow=False, separators=[';',',', ':'])
89-
90- Options :::
91- text_file :: ASCII File to read from.
92- header :: (0) Number of header lines, these lines will be skipped.
93- cskip :: (0) Number of 'column'/'character' to skip (dummy column)
94- cskip_type :: ('column') is 'cskip' a number of 'column' or 'character' to skip?
95- axis :: (False) Use as the values for the first column as variable axis (x values in y(x))
96- idrow :: (False) Is the first row representing the ids of var generated ?
97- ids :: (None) use the values in this list as variable ids (1 per column returned)
98- separators :: ([';',',', ':']) List of character recognized as column separator
99- Output :::
100- vars :: List containing 1 transient varialbe per column in the files.
101- Variable ids are optionaly determined by first row.
102- Variable axis may be the first column
103+ def read_col ( text_file ,header = 0 , cskip = 0 , cskip_type = 'columns' , axis = False , ids = None , idrow = 0 ,
104+ separators = [';' ,',' , ':' ]):
105+ """
106+ Reads column-stored data from ASCII files
107+
108+ :Example:
109+
110+ .. doctest:: genutil_ASCII_read_col
111+
112+ >>> vars = genutil.ASCII.read_col("vars.txt") # use default params
113+
114+
115+ :param text_file: ASCII File to read from.
116+ :type text_file:
117+
118+ :param header: Number of header lines, these lines will be skipped.
119+ :type header: int
120+
121+ :param cskip: Number of 'column'/'character' to skip (dummy column)
122+ :type cskip: int
123+
124+ :param cskip_type: One of 'columns' or 'characters'. Specifies which should be skipped.
125+ :type cskip_type: str
126+
127+ :param axis: Boolean flag indicating whether to use as the values for the first column as
128+ variable axis (x values in y(x)).
129+ :type axis: bool
130+
131+ :param idrow: Is the first row representing the ids of var generated.
132+ :type idrow:
133+
134+ :param ids: (None) use the values in this list as variable ids (1 per column returned)
135+ :type ids:
136+
137+ :param separators: ([';',',', ':']) List of characters recognized as column
138+ separator. Can be represented as a list or a string.
139+ If it is a string, separator characters must be space-delimited.
140+ :type separators: list or str
141+
142+ :returns: List containing 1 transient variable per column in the files.
143+ Variable ids are optionally determined by first row.
144+ Variable axis may be the first column.
145+ :rtype: list
103146 """
104147
105148 sep = []
@@ -108,9 +151,9 @@ def read_col( text_file ,header=0, cskip=0, cskip_type='columns', axis=False, id
108151 for s in separators :
109152 sep .append (s )
110153
111- f = open ( text_file )
112- lst = f .readlines ( )
113- f .close ( )
154+ f = open (text_file )
155+ lst = f .readlines ()
156+ f .close ()
114157 lst = lst [header :]
115158 if not isinstance (ids ,(tuple ,list )):
116159 ids = [ids ]
0 commit comments