#NEWLINE# def run_model( pth ) : #NEWLINE# #INDENT# proc = sp . Popen ( [ exe_name , 'DG.nam' ] , stdout = sp . PIPE , cwd = pth ) #NEWLINE# sys . stdout . write ( '  running {} in {}\n' . format ( exe_name , pth ) ) #NEWLINE# success = False #NEWLINE# buff = [ ] #NEWLINE# elt = 'Normal model termination did not occur' #NEWLINE# while True : #NEWLINE# #INDENT# line = proc . stdout . readline ( ) #NEWLINE# c = line . decode ( 'utf-8' ) #NEWLINE# if ( c != '' ) : #NEWLINE# #INDENT# if ( 'normal termination of simulation' in c . lower ( ) ) : #NEWLINE# #INDENT# success = True #NEWLINE# #UNINDENT# c = c . rstrip ( '\r\n' ) #NEWLINE# buff . append ( c ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if success : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# elt = buff [ ( - 3 ) ] . strip ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# return [ success , elt ]