#NEWLINE# def run_model( exe_name , namefile , model_ws = './' , silent = False , pause = False , report = False , normal_msg = 'normal termination' ) : #NEWLINE# #INDENT# "\n    This function will run the model using subprocess.Popen.\n\n    Parameters\n    ----------\n    exe_name : str\n        Executable name (with path, if necessary) to run.\n    namefile : str\n        Namefile of model to run. The namefile must be the\n        filename of the namefile without the path.\n    model_ws : str\n        Path to the location of the namefile. (default is the\n        current working directory - './')\n    silent : boolean\n        Echo run information to screen (default is True).\n    pause : boolean, optional\n        Pause upon completion (default is False).\n    report : boolean, optional\n        Save stdout lines to a list (buff) which is returned\n        by the method . (default is False).\n    normal_msg : str\n        Normal termination message used to determine if the\n        run terminated normally. (default is 'normal termination')\n\n    Returns\n    -------\n    (success, buff)\n    success : boolean\n    buff : list of lines of stdout\n\n    " #NEWLINE# success = False #NEWLINE# buff = [ ] #NEWLINE# exe = which ( exe_name ) #NEWLINE# if ( exe is None ) : #NEWLINE# #INDENT# import platform #NEWLINE# if ( platform . system ( ) in 'Windows' ) : #NEWLINE# #INDENT# if ( not exe_name . lower ( ) . endswith ( '.exe' ) ) : #NEWLINE# #INDENT# exe = which ( ( exe_name + '.exe' ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( exe is None ) : #NEWLINE# #INDENT# s = 'The program {} does not exist or is not executable.' . format ( exe_name ) #NEWLINE# raise Exception ( s ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not silent ) : #NEWLINE# #INDENT# s = 'FloPy is using the following executable to run the model: {}' . format ( exe ) #NEWLINE# print ( s ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . path . isfile ( os . path . join ( model_ws , namefile ) ) ) : #NEWLINE# #INDENT# s = 'The namefile for this model does not exists: {}' . format ( namefile ) #NEWLINE# raise Exception ( s ) #NEWLINE# #UNINDENT# proc = sp . Popen ( [ exe_name , namefile ] , stdout = sp . PIPE , cwd = exe_name ) #NEWLINE# while True : #NEWLINE# #INDENT# line = proc . stdout . readline ( ) #NEWLINE# c = line . decode ( 'utf-8' ) #NEWLINE# if ( c != '' ) : #NEWLINE# #INDENT# if ( normal_msg in c . lower ( ) ) : #NEWLINE# #INDENT# success = True #NEWLINE# #UNINDENT# c = c . rstrip ( '\r\n' ) #NEWLINE# if ( not silent ) : #NEWLINE# #INDENT# print ( '{}' . format ( c ) ) #NEWLINE# #UNINDENT# if ( report == True ) : #NEWLINE# #INDENT# buff . append ( c ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# if pause : #NEWLINE# #INDENT# input ( 'Press Enter to continue...' ) #NEWLINE# #UNINDENT# return ( success , buff )