<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 FloPy
A quick demo of how to control the ASCII format of numeric arrays written by FloPy
load and run the Freyberg model
Step1:  Each Util2d instance now has a .format attribute, which is an ArrayFormat instance
Step2:  The ArrayFormat class exposes each of the attributes seen in the ArrayFormat.___str___() call. ArrayFormat also exposes .fortran, .py and .numpy atrributes, which are the respective format descriptors
Step3:  (re)-setting .format
We can reset the format using a standard fortran type format descriptor
Step4:  Let's load the model we just wrote and check that the desired botm[0].format was used
Step5:  We can also reset individual format components (we can also generate some warnings)
Step6:  We can also select free format.  Note that setting to free format resets the format attributes to the default, max precision
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import sys
import os
import platform
import numpy as np
import matplotlib.pyplot as plt
import flopy
#Set name of MODFLOW exe
#  assumes executable is in users path statement
version = 'mf2005'
exe_name = 'mf2005'
if platform.system() == 'Windows':
    exe_name = 'mf2005.exe'
mfexe = exe_name
#Set the paths
loadpth = os.path.join('..', 'data', 'freyberg')
modelpth = os.path.join('data')
#make sure modelpth directory exists
if not os.path.exists(modelpth):
    os.makedirs(modelpth)
ml = flopy.modflow.Modflow.load('freyberg.nam', model_ws=loadpth, 
                                exe_name=exe_name, version=version)
ml.model_ws = modelpth
ml.write_input()
success, buff = ml.run_model()
if not success:
    print ('Something bad happened.')
files = ['freyberg.hds', 'freyberg.cbc']
for f in files:
    if os.path.isfile(os.path.join(modelpth, f)):
        msg = 'Output file located: {}'.format(f)
        print (msg)
    else:
        errmsg = 'Error. Output file cannot be found: {}'.format(f)
        print (errmsg)
Explanation: FloPy
A quick demo of how to control the ASCII format of numeric arrays written by FloPy
load and run the Freyberg model
End of explanation
print(ml.lpf.hk[0].format)
Explanation: Each Util2d instance now has a .format attribute, which is an ArrayFormat instance:
End of explanation
print(ml.dis.botm[0].format.fortran)
print(ml.dis.botm[0].format.py)
print(ml.dis.botm[0].format.numpy)
Explanation: The ArrayFormat class exposes each of the attributes seen in the ArrayFormat.___str___() call. ArrayFormat also exposes .fortran, .py and .numpy atrributes, which are the respective format descriptors:
End of explanation
ml.dis.botm[0].format.fortran = "(6f10.4)"
print(ml.dis.botm[0].format.fortran)
print(ml.dis.botm[0].format.py)
print(ml.dis.botm[0].format.numpy)
ml.write_input()
success, buff = ml.run_model()
Explanation: (re)-setting .format
We can reset the format using a standard fortran type format descriptor
End of explanation
ml1 = flopy.modflow.Modflow.load("freyberg.nam",model_ws=modelpth)
print(ml1.dis.botm[0].format)
Explanation: Let's load the model we just wrote and check that the desired botm[0].format was used:
End of explanation
ml.dis.botm[0].format.width = 9
ml.dis.botm[0].format.decimal = 1
print(ml1.dis.botm[0].format)
Explanation: We can also reset individual format components (we can also generate some warnings):
End of explanation
ml.dis.botm[0].format.free = True
print(ml1.dis.botm[0].format)
ml.write_input()
success, buff = ml.run_model()
ml1 = flopy.modflow.Modflow.load("freyberg.nam",model_ws=modelpth)
print(ml1.dis.botm[0].format)
Explanation: We can also select free format.  Note that setting to free format resets the format attributes to the default, max precision:
End of explanation
<END_TASK>