modflowpy / flopy

A Python package to create, run, and post-process MODFLOW-based models.
https://flopy.readthedocs.io
Other
517 stars 313 forks source link

Writing a text file with flopy.utils.util_array.util_2d #29

Closed wchristensen closed 9 years ago

wchristensen commented 9 years ago

uzfbnd=fu.util_array.util_2d(mymodel,(nrow,ncol),np.int,iuzfbndT,ext_filename=uzfname)

From the available information, I expect the array (iuzfbndT) to be written to uzfname ('D:\MODFLOW\my_model-uzf-1505011656.txt'). But I don't an array file, or any errors. All other modflow files (bas, lpf,dis, etc) are written without a problem.

uzfbnd.write_txt((nrow,ncol),uzfname,iuzfbndT)

I get: TypeError: unsupported operand type(s) for %: 'int' and 'str' on line 873 of util_array.py. I am assuming the arg shape should be a tuple of integers. I cannot decipher how column_length in calculated in util_array.py, but for some reason ncol%column_length is producing errors.

Any suggestions on a better way to get this array file written?

jtwhite79 commented 9 years ago

If you just want to write a util_2d instance to a text file, then you can just use numpy.savetxt(uzbnd.array,fmt='%6d',delimiter='').

Looks like the problem arose from the need to support old-style "touching number" formats (yuck!). The default fortran_format arg in the call to write_txt() is "(FREE)" and python_format is None, which results in a column_length value of "free" instead of a numeric value, which then can't be used in the modulo operator. Fixed this by intercepting fortran_format=='(FREE)' and doing a simple np.savetxt(). Needs to be tested out further - only on develop branch for now