Suggestions on Compiling MODFLOW-2000
|
||
Most users will not need to compile MODFLOW-2000 because you can download a compiled version of MODFLOW-2000 from the USGS web site. However, if you wish to make changes to the source code, you will need to compile it yourself.
Nearly all the Fortran code in MODFLOW is standard Fortran that will compile the same way with any compiler. However, a small portion of the code uses compiler-dependent code. This compiler dependent code is included in the file "openspec.inc". Be sure to modify this file to the correct form for your compiler. There are extensive comments in openspec.inc that can help you.
Prior to version 1.15.00, MODFLOW-2000 was written entirely in Fortran. However, the GMG package added in version 1.15.00 is written primarily in C (with a small amount of Fortran code to link to the C code). This makes compiling MODFLOW-2000 a bit more challenging than previously. Now, instead of just a Fortran compiler, a C compiler is also required. If one is not aware that the C language is case-sensitive and the Fortran language is case insensitive, some error messages returned by compilers may be difficult to understand. Often the C compiler will "decorate" the name of the C function and the linker can't figure out how to link Fortran object code with an undecorated name with C object code with a decorated name. Users should try to find the switches in the compilers and linkers that control how names are decorated so that the object code generated by the C and Fortran compilers use consistent names.
This web page gives advice on compiling MODFLOW-2000 with some compilers. However, no attempt has been made to test all Fortran compilers. If you have information on how to compile it with another compiler, please send to rbwinst@usgs.gov so it can be included on this web page.
If you wish to compile a parallel version of MODFLOW-2000, you will need to get a copy of mpif.h.
To enable the parallel-processing capabilities of MODFLOW-2000, an implementation of MPI must first be installed on your computer(s). MPI software is not distributed by the USGS and must be obtained and installed separately. The mpif.h file and MPI subroutines referenced in the para-mpi.f file and other locations in the MODFLOW source code will be provided as part of the MPI installation. After MPI has been installed, use mpif.h and other source-code files provided with the MPI implementation that is installed on your computer(s) when MODFLOW-2000 is compiled with para-mpi.f. Some implementations of MPI support only certain compilers, so ensure that the MPI implementation you install supports the compiler you will be using to compile MODFLOW-2000. Please refer to page 203 of USGS Open-File Report 00-184 for additional information.
There is more info in the FAQ about compiling a parallel version of MODFLOW-2000.
You should check that the variables specified in openspec.inc are specified correctly for your compiler. There is more information about this in the FAQ.
References to commercial vendors of software products or services are provided solely for the convenience of users when obtaining or using USGS software. Such references do not imply any endorsement by the U.S. Government.
The information on this web page was provided with the assistance of Edward Banta, Steffan Mehl, Henk den Adel, William R. Hutchison, and Richard Winston. The instructions may be outdated or incorrect. If you find that the instructions are in error, please send corrections to rbwinst@usgs.gov.
COMPILE=@fcc /c /D _UF /I C:\Compilers\Lahey\LF9557\Include /o .\objLF95\%sf%oe %fi
|
c !DEC$ ATTRIBUTES ALIAS:'_resprint' :: RESPRINT
|
Thanks to Ingo Berg for the following instructions. Thanks to Edward Banta and Eileen Poeter for additional suggestions.
//#ifdef _UF //#define resprint resprint_ //#endif
Behind this block write the following line:
#define resprint RESPRINT
Press OK. A Window with the application wizard will open. Go to the application settings and select "Empty Project". Press finish afterwards.
Press the "Create" Button. You will see a second project appear in the Project explorer treeview. This project is the static library for the GMG components which are written in C. Next we have to add the source files. In the Project explorer select the "mf2k_gmg" project. From the main menu, select "File | Add existing element". In the file input dialog box, go to the parent directory. (Press the small yellow symbol with the buckled arrow pointing upwards on top of the window.) Select all files with the extension *.c and *.h. (Do not include the *.inc files!). Again, multiple files can be selected by holding the shift key down. Press open; the new files will appear in the Project explorer.
If the compiler reports errors of the form:
Error 16 error LNK2005: _calloc already defined in LIBCMT.lib(calloc.obj) MSVCRT.lib(MSVCR80.dll)
then set Ignore Specific Library to "MSVCRT" as shown.
|
Thanks to Edward Banta for the following instructions. Thanks to Edward Banta and Eileen Poeter for additional suggestions.
If the compiler reports errors of the form:
Error 16 error LNK2005: _calloc already defined in LIBCMT.lib(calloc.obj) MSVCRT.lib(MSVCR80.dll)
then set Ignore Specific Library to "MSVCRT" as shown.
|
Thanks to Christian D Langevin and David Ahlfeld for the following instructions. Thanks to Edward Banta, Eileen Poeter and Seung Jae Lee for additional suggestions.
Click Next to the "Welcome to the Fortran Console Application Wizard".
!DEC$ ATTRIBUTES ALIAS:'_resprint' :: RESPRINT
//#ifdef_UF //#define resprint resprint_ //#endif
(According the David Ahlfeld, MODFLOW will still compile if this instruction is omitted.)
#define resprint RESPRINT
(The original instructions from Christian D Langevin included the instruction above but according to David Ahlfeld they are not required and they cause a linker error.)
If the compiler reports errors of the form:
Error 16 error LNK2005: _calloc already defined in LIBCMT.lib(calloc.obj) MSVCRT.lib(MSVCR80.dll)
then set Ignore Specific Library to "MSVCRT" as shown.
|
These instructions are by Richard B. Winston. They are adapted from the Microsoft Visual Studio 2005 with Intel Fortran Compiler 11.1 above. To compile MODFLOW-2005, the following instructions can be used except that step 2 should be skipped and the directory names for the source code would be slightly different.
|
Thanks to Theo Olsthoorn for the following suggestions regarding compiling with gfortran on the Mac. -- Jaime Carrera’s suggestion to use the fno-second-underscore does is not necessary, at least on the Mac.
-- I have compiled on the unix version underlying the Mac OS X system. The only changes to the makefile were
F77= gfortran F90= gfortran CC= gfortran
After which mf2k.1_18 compiles and links perfectly after typing make on the command line. |
The methods described for gfortran on the Mac might work on other operating systems too. Thanks to Jaime Carrera for the following suggestions regarding compiling with gfortran.
F77FLAGS = -fno-second-underscore F77= gfortran
make install
Jaime Carrera says he tested it on Linux - Fedora Core 4. Miles McCammon says these instructions worked for MODFLOW 2005 on Linux Ubuntu 9.04 using gfortran.
Thanks to Henk den Adel for the following instructions. The GNU version of the Fortran 95 compiler (gfortran, i.e. not the G95 project) allows one to compile the .f files and the .c files.
/* Append underscore to fortran modual name */ //#ifdef _UF/ /#define resprint resprint //#endif
/* Append underscore to functions called from FORTRAN GMG interface */ #ifdef _UF #define MF2KGMG_ALLOCATE mf2kgmg_allocate #define MF2KGMG_FREE mf2kgmg_free #define MF2KGMG_ASSEMBLE mf2kgmg_assemble #define MF2KGMG_EVAL mf2kgmg_eval #define MF2KGMG_UPDATE mf2kgmg_update #define MF2KGMG_BIGR mf2kgmg_bigr #define MF2KGMG_BIGH mf2kgmg_bigh #endif
Do not append the tailing underscore. The -fno-underscoring makes it unnecessary. However, functions are case sensitive for this compiler.
gfortran -c -fno-underscoring file.f
gfortran -c -D_UF -Ilocation file.c
where 'location' points to the drive and directory where the include files for gfortran are located.
gfortran *.o -o mf2k
Final remark: Henk den Adel says he did not check whether the program runs; however all errors due to 'undefined references' were gone. |
Laurent Delphin has provided a makefile for compiling MODFLOW-2005 on the Mac. |
The Conduit Flow Process (CFP) was complied using double precision for real variables and arrays (Compiler setting was Default, Real, Kind=8). CFP relies on several FORTRAN routines from Numerical Recipes in Fortran (1992). Due to copyright restrictions the source code for these routines cannot be publicly released by the U.S. Geological Survey. Users interested in compiling CFP will need to obtain copies of the LUDCMP, LUBKSP, and MPROVE routines (or equivalent routines) prior to compiling the program.
Numerical Recipes in Fortran 1992 W. H. Press, S. A. Teukolsky, W. T. Vetterling adnd B. P. Flannery
SUBROUTINE LUDCMP(A, N, Np, Indx, D) SUBROUTINE LUBKSB(A, N, Np, Indx, B) SUBROUTINE MPROVE(A, Alud, N, Np, Indx, B, X) |
From Matt Gloe Install ftn95_personal http://www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx Install C from watcom http://www.openwatcom.org/index.php/Download Keep the default installation directory Copy the file compMF.bat (shown below) into the working directory (compMF = compile ModFlow). The locations of the compiler exe files are hardcoded to avoid path errors. Open a “CMD” window and change to the working directory. At the prompt type compMF and press enter. If you have errors, the best way to find them is to redirect output from the compMF batch file to a log file. compMF >> comp.log To check comp.log type notepad comp.log Note that the new executable will be created in the source code directory Also note that in older Fortran compilers, the code should be up to (and including) col 72. Fortran 95 is more flexible, but for compatibility, please keep each line under 72 cols
|
These instructions are by Richard B. Winston. The first step is to install Code::Blocks and gfortran. Gfortran is included in “MinGW” which is included with the Windows installer for Code::Blocks. For other operating systems, you may need to install Gfortran separately. First go to http://www.codeblocks.org/downloads and click on the link for “Download the binary release.” Then choose the installer for your operating system. There are several different ones available. If you are on Windows, you will need MinGW so choose one of the installers that includes MinGW unless you already have MinGW installed. At the time this was written, the installer that you are most likely to be appropriate is “codeblocks-12.11mingw-setup.exe.” However, by the time you read this, there may be a more recent version. Once the installer has downloaded, use the installer to install Code::Blocks. Note: in CodeBlocks version 17.12, you should not use the included gfortran compiler. Instead download a newer version of MinGW and use its compiler and debugger. Start Code::Blocks. It will ask you to select a default compiler. You can select the GNU Fortran compiler. It will display a dialog box asking whether you want associate C++ files with Code::Blocks. It is up to you how you wish to respond. Next you may need to configure Code::Blocks to use gfortran.
If you have not already done so, download MODFLOW-2005 from the USGS web site (https://water.usgs.gov/ogw/modflow/MODFLOW.html). MODFLOW-2005 comes in a zip file that you will need to unzip. The directory to which it is normally unzipped is “C:\WRDAPP.” (WRDAPP stands for Water Resources Division Application.) On of the subdirectories include in the zip file is named “src.” It contains the source code for MODFLOW-2005. There are two subdirectories of the src directory that contain the source code for two other programs that are distributed with MODFLOW-2005. We won’t deal with those other programs. Here are step-by-step instructions on compiling MODFLOW-2005.
C DATA FORM/'UNFORMATTED'/
DATA FORM/'BINARY'/
DATA ACCESS/'SEQUENTIAL'/
C c Non-standard Fortran that causes code compiled by gfortran C on personal computers to use unstructured non-formatted C files. This may make it possible for the non-formatted files used C by MODFLOW to be used with programs that are compiled by other C compilers. C DATA ACCESS/'STREAM'/
|