#NEWLINE# def read_ascii( self , fname = None ) : #NEWLINE# #INDENT# 'read ascii data file' #NEWLINE# lines = self . _open_ascii ( fname = fname ) #NEWLINE# if ( lines is None ) : #NEWLINE# #INDENT# return ( - 1 ) #NEWLINE# #UNINDENT# maxlines = len ( lines ) #NEWLINE# iline = 1 #NEWLINE# ndata_points = None #NEWLINE# tmp_dat = [ ] #NEWLINE# tmp_y = [ ] #NEWLINE# col_details = [ ] #NEWLINE# col_legend = None #NEWLINE# ntotal_at_2d = [ ] #NEWLINE# ny_counter = 0 #NEWLINE# mode = None #NEWLINE# while lines : #NEWLINE# #INDENT# ( key , raw ) = self . _getline ( lines ) #NEWLINE# iline = ( iline + 1 ) #NEWLINE# if ( ( key is not None ) and ( key != mode ) ) : #NEWLINE# #INDENT# mode = key #NEWLINE# #UNINDENT# if ( len ( raw ) < 3 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# self . ShowProgress ( ( ( iline * 100.0 ) / ( maxlines + 1 ) ) ) #NEWLINE# if ( mode == '2d' ) : #NEWLINE# #INDENT# self . dimension = 2 #NEWLINE# sx = raw . split ( ) #NEWLINE# yval = float ( sx [ 2 ] ) #NEWLINE# tmp_y . append ( yval ) #NEWLINE# self . yaddr = sx [ 1 ] . strip ( ) #NEWLINE# if self . yaddr . endswith ( ':' ) : #NEWLINE# #INDENT# self . yaddr = self . yaddr [ : ( - 1 ) ] #NEWLINE# #UNINDENT# mode = None #NEWLINE# if ( len ( tmp_dat ) > 0 ) : #NEWLINE# #INDENT# ntotal_at_2d . append ( len ( tmp_dat ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'epics scan' ) : #NEWLINE# #INDENT# print ( 'Warning: file appears to have a second scan appended!' ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'data' ) : #NEWLINE# #INDENT# tmp_dat . append ( numpy . array ( [ float ( i ) for i in raw . split ( ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == '-----' ) : #NEWLINE# #INDENT# if ( col_legend is None ) : #NEWLINE# #INDENT# col_legend = lines . pop ( ) [ 1 : ] . strip ( ) . split ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode in ( '=====' , 'n_points' ) ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'user titles' ) : #NEWLINE# #INDENT# self . user_titles . append ( raw [ 1 : ] . strip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'pv list' ) : #NEWLINE# #INDENT# str = raw [ 1 : ] . strip ( ) . replace ( 'not connected' , ' = not connected' ) #NEWLINE# if str . lower ( ) . startswith ( mode ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# desc = str #NEWLINE# addr = '' #NEWLINE# val = 'unknown' #NEWLINE# try : #NEWLINE# #INDENT# x = str . split ( '=' ) #NEWLINE# desc = x [ 0 ] . replace ( '\t' , '' ) . strip ( ) #NEWLINE# val = x [ 1 ] . strip ( ) #NEWLINE# if ( ( '(' in desc ) and desc . endswith ( ')' ) ) : #NEWLINE# #INDENT# n = desc . rfind ( '(' ) #NEWLINE# addr = desc [ ( n + 1 ) : ( - 1 ) ] #NEWLINE# desc = desc [ : n ] . rstrip ( ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# self . env_addr . append ( addr ) #NEWLINE# self . env_desc . append ( desc ) #NEWLINE# self . env_val . append ( val ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'scan regions' ) : #NEWLINE# #INDENT# self . scan_regions . append ( raw [ 1 : ] . strip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'scan ended at' ) : #NEWLINE# #INDENT# self . stop_time = raw [ 20 : ] . strip ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'scan began at' ) : #NEWLINE# #INDENT# self . start_time = raw [ 20 : ] . strip ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'column labels' ) : #NEWLINE# #INDENT# col_details . append ( raw [ 1 : ] . strip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode is None ) : #NEWLINE# #INDENT# sx = [ i . strip ( ) for i in raw [ 1 : ] . split ( '=' ) ] #NEWLINE# if ( len ( sx ) > 1 ) : #NEWLINE# #INDENT# if ( sx [ 0 ] == 'scan prefix' ) : #NEWLINE# #INDENT# self . scan_prefix = sx [ 1 ] #NEWLINE# #UNINDENT# if ( sx [ 0 ] == 'scan dimension' ) : #NEWLINE# #INDENT# self . dimension = int ( float ( sx [ 1 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( 'UNKOWN MODE = ' , mode , raw [ : 20 ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# del lines #NEWLINE# try : #NEWLINE# #INDENT# col_details . pop ( 0 ) #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# print ( 'Empty Scan File' ) #NEWLINE# return ( - 2 ) #NEWLINE# #UNINDENT# if ( len ( self . user_titles ) > 1 ) : #NEWLINE# #INDENT# self . user_titles . pop ( 0 ) #NEWLINE# #UNINDENT# if ( len ( self . scan_regions ) > 1 ) : #NEWLINE# #INDENT# self . scan_regions . pop ( 0 ) #NEWLINE# #UNINDENT# if ( self . dimension == 2 ) : #NEWLINE# #INDENT# ntotal_at_2d . append ( len ( tmp_dat ) ) #NEWLINE# np_row0 = ntotal_at_2d [ 0 ] #NEWLINE# nrows = len ( ntotal_at_2d ) #NEWLINE# npts = len ( tmp_dat ) #NEWLINE# if ( npts != ( np_row0 * nrows ) ) : #NEWLINE# #INDENT# for ( i , n ) in enumerate ( ntotal_at_2d ) : #NEWLINE# #INDENT# if ( n == ( np_row0 * ( i + 1 ) ) ) : #NEWLINE# #INDENT# ( nrows , npts_total ) = ( ( i + 1 ) , n ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( len ( tmp_y ) > nrows ) or ( len ( tmp_dat ) > npts_total ) ) : #NEWLINE# #INDENT# print ( 'Warning: Some trailing data may be lost!' ) #NEWLINE# tmp_y = tmp_y [ : nrows ] #NEWLINE# tmp_dat = tmp_dat [ : npts_total ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . y = numpy . array ( tmp_y ) #NEWLINE# self . _make_arrays ( tmp_dat , col_legend , col_details ) #NEWLINE# tmp_dat = None #NEWLINE# self . xaddr = self . pos_addr [ 0 ] . strip ( ) #NEWLINE# for ( addr , desc ) in zip ( self . env_addr , self . env_desc ) : #NEWLINE# #INDENT# if ( self . xaddr == addr ) : #NEWLINE# #INDENT# self . xdesc = desc #NEWLINE# #UNINDENT# if ( self . yaddr == addr ) : #NEWLINE# #INDENT# self . ydesc = desc #NEWLINE# #UNINDENT# #UNINDENT# self . has_fullxrf = False #NEWLINE# if os . path . exists ( ( '%s.fullxrf' % fname ) ) : #NEWLINE# #INDENT# self . read_fullxrf ( ( '%s.fullxrf' % fname ) , len ( self . x ) , len ( self . y ) )