<s> """<STR_LIT>""" <EOL> import os <EOL> import numpy <EOL> class AbsFile ( object ) : <EOL> invalid_value = - <NUM_LIT> <EOL> def __init__ ( self , filename ) : <EOL> if not os . path . exists ( filename ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . data = { } <EOL> self . row_size = False <EOL> self . col_size = False <EOL> with open ( filename , '<STR_LIT:r>' ) as file_handle : <EOL> def read_dimension ( dimension ) : <EOL> line = file_handle . readline ( ) <EOL> data = line . strip ( ) . split ( "<STR_LIT:U+0020>" ) <EOL> if len ( data ) == <NUM_LIT:2> and data [ <NUM_LIT:1> ] == dimension : <EOL> return int ( data [ <NUM_LIT:0> ] ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" % dimension ) <EOL> def read_data_type ( ) : <EOL> line = file_handle . readline ( ) <EOL> data = line . strip ( ) . split ( "<STR_LIT:U+0020>" , <NUM_LIT:1> ) <EOL> if len ( data ) == <NUM_LIT:2> and data [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> return data [ <NUM_LIT:1> ] [ <NUM_LIT:1> : - <NUM_LIT:2> ] . split ( "<STR_LIT:U+0020>" ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def read_data ( data_type ) : <EOL> data_type = numpy . int if data_type == '<STR_LIT>' else numpy . float <EOL> result = numpy . zeros ( self . col_size * self . row_size , dtype = data_type ) <EOL> index = <NUM_LIT:0> <EOL> line = file_handle . readline ( ) <EOL> data = line . strip ( ) . split ( "<STR_LIT:U+0020>" ) <EOL> for value in data : <EOL> try : <EOL> result [ index ] = data_type ( value ) <EOL> index = index + <NUM_LIT:1> <EOL> except ValueError : <EOL> print "<STR_LIT>" % ( data_type , value ) <EOL> if data_type == numpy . float : <EOL> result [ result == AbsFile . invalid_value ] = numpy . nan <EOL> return result . reshape ( self . row_size , self . col_size ) <EOL> self . row_size = read_dimension ( '<STR_LIT>' ) <EOL> self . col_size = read_dimension ( '<STR_LIT>' ) <EOL> self . data_type = read_data_type ( ) <EOL> for current_data_type in self . data_type : <EOL> self . data [ current_data_type ] = read_data ( current_data_type ) <EOL> @ property <EOL> def width ( self ) : <EOL> return self . col_size <EOL> @ property <EOL> def height ( self ) : <EOL> return self . row_size </s>
