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

tutorial1.hds fails to load, nrow not read in properly, nrow=1145128264 instead of 10 #191

Closed Olsthoorn closed 7 years ago

Olsthoorn commented 7 years ago

Happens on mac compiled version of mf2005. mf2005 (mac compiled version runs fine as it has always done, but flopy fails reading the hds file because it gets back a wrong value for nrow when reading the header of the hds file in binaryfile.py on line 134. Shortly afterwards reading fails because of this wrong value of nrow.

ipdb> n

/Users/Theo/anaconda/lib/python3.5/site-packages/flopy/utils/binaryfile.py(135)binaryread() 133 nval = np.core.fromnumeric.prod(shape) 134 result = np.fromfile(file,vartype,nval) --> 135 if nval == 1: 136 result = result # [0] 137 else:

ipdb> result array([ (44, 1, 1.401298464324817e-45, 1.0, b'\x00\x00\x80? ', 1145128264, 10, 10)], dtype=[('kstp', '<i4'), ('kper', '<i4'), ('pertim', '<f4'), ('totim', '<f4'), ('text', 'S16'), ('ncol', '<i4'), ('nrow', '<i4'), ('ilay', '<i4')])

ArchiveTutorial1WithHdsFIle.zip

jtwhite79 commented 7 years ago

I also have trouble loading the hds file in that zip file. But, if I rerun the problem using the mac version of mf2005 that I have (compiled with ifort), I can load the hds. Is your mf2005 double or single precision?

Is this another one of those terrible fortran things? @jdhughes-usgs or @langevin-usgs ?

langevin-usgs commented 7 years ago

Hi @Olsthoorn ,

I think your issue is due to how you've compiled MODFLOW on your Mac. In Flopy, we do not have different binary readers for the different types of compilers. Instead, we have found a way to compile all MODFLOW variants so that the binary output files (budget, head, drawdown, etc.) have the same byte structure regardless of the compiler. This makes it possible read binary files created on Mac or Windows, compiled using gfortran or Intel. The way we do this now is to use the following settings in openspec.inc:

CHARACTER*20 ACCESS,FORM,ACTION(2)
DATA ACCESS/'STREAM'/
DATA FORM/'UNFORMATTED'/
DATA (ACTION(I),I=1,2)/'READ','READWRITE'/

With the STREAM ACCESS, no additional bytes are written between numbers (which is compiler specific if it is not used).

You might also be interested in the pymake package that we have developed. It has scripts for automatically downloading and compiling various MODFLOW versions from the USGS. It builds a dependency tree so that it knows the order to compile the individual source files (and it can handle the gmg C solver without any complications). The scripts will automatically change the ACCESS to STREAM and make other changes to the source code before compiling in order to work with gfortran or Intel.

Let me know if this doesn't fix the problem for you, and we'll reopen the issue.

Best, -C