Index: wflow-py/Scripts/bmi2runner.py =================================================================== diff -u -r3e39e84af48f1bcb5ec0d243748147be223674f2 -rc3d4f45b39e8806a46597b1e2b1463487f053ce5 --- wflow-py/Scripts/bmi2runner.py (.../bmi2runner.py) (revision 3e39e84af48f1bcb5ec0d243748147be223674f2) +++ wflow-py/Scripts/bmi2runner.py (.../bmi2runner.py) (revision c3d4f45b39e8806a46597b1e2b1463487f053ce5) @@ -26,77 +26,81 @@ import wflow.pcrut as pcrut import os import time +import sys +import getopt +import logging +def usage(*args): + sys.stdout = sys.stderr + """Way""" + for msg in args: print msg + print __doc__ + sys.exit(0) -""" -Perform command line execution of the model. -""" -configfile = "bmi2runner.ini" +def main(argv=None): + """ + Perform command line execution of the model. + """ -loglevel = "INFO" -combilogger = pcrut.setlogger("bmi2runner.log", "bmi2runner_logging", thelevel=loglevel) + configfile = "bmirunner.ini" -# Construct object and initilize the models -combilogger.info("Starting combined bmi object") -bmiobj = wfbmi.wflowbmi_csdms() -# this line is needed when running from batch script -# os.sys.path.append(os.getcwd() +'\\rtc\\rtc_brantas\\bin\\') + if argv is None: + argv = sys.argv[1:] + if len(argv) == 0: + usage() + return + ######################################################################## + ## Process command-line options # + ######################################################################## + try: + opts, args = getopt.getopt(argv, 'c:l:') + except getopt.error, msg: + usage(msg) -bmiobj.initialize_config(configfile, loglevel=loglevel) -bmiobj.initialize_model() + loglevel=logging.WARN + for o, a in opts: + if o == '-c': configfile = a + if o == '-l': exec "loglevel = logging." + a -# Get and set start and end times -start = bmiobj.get_start_time() -end = bmiobj.get_end_time() -bmiobj.set_start_time(start) -bmiobj.set_end_time(end) -# Update models (if necessary) to start time -bmiobj.update_to_start_time(start) -# Number of steps to run models -ts = bmiobj.get_time_step() -steps = int((end - start) / ts + 1) - -print("start = ", start) # time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(start)) -print( - "start time rtc =", - time.strftime( - "%Y-%m-%d %H:%M:%S", time.gmtime(bmiobj.bmimodels["RTC-Tools"].get_start_time()) - ), -) -print( - "start time wflow =", - time.strftime( - "%Y-%m-%d %H:%M:%S", time.gmtime(bmiobj.bmimodels["wflow_sbm"].get_start_time()) - ), -) -print( - "start time lintul =", - time.strftime( - "%Y-%m-%d %H:%M:%S", - time.gmtime(bmiobj.bmimodels["wflow_lintul"].get_start_time()), - ), -) - - -cts = bmiobj.currenttimestep -# Loop over the time duration -while cts < steps: - - bmiobj.update() + combilogger = pcrut.setlogger("bmi2runner.log", "bmi2runner_logging", thelevel=loglevel) + + # Construct object and initilize the models + combilogger.info("Starting combined bmi object") + bmiobj = wfbmi.wflowbmi_csdms() + + bmiobj.initialize_config(configfile, loglevel=loglevel) + bmiobj.initialize_model() + + # Get and set start and end times + start = bmiobj.get_start_time() + end = bmiobj.get_end_time() + bmiobj.set_start_time(start) + bmiobj.set_end_time(end) + + # Update models (if necessary) to start time + bmiobj.update_to_start_time(start) + + # Number of steps to run models + ts = bmiobj.get_time_step() + steps = int((end - start) / ts + 1) + cts = bmiobj.currenttimestep + # Loop over the time duration + while cts < steps: + combilogger.info("time is: " + str(bmiobj.get_current_time())) + bmiobj.update() + cts = bmiobj.currenttimestep + + + bmiobj.finalize() + combilogger.info("Finishing run") -# else: -# bmiobj.bmimodels['RTC-Tools'].update() -# bmiobj.bmimodels['wflow_sbm'].update() -# bmiobj.bmimodels['wflow_lintul'].update() -# cts = bmiobj.currenttimestep +if __name__ == "__main__": + main() -bmiobj.bmimodels["RTC-Tools"].finalize() -bmiobj.bmimodels["wflow_sbm"].finalize() -bmiobj.bmimodels["wflow_lintul"].finalize() -combilogger.info("Finishing run") +