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. There is more info 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.
//#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.
|
Thanks to Edward Banta for the following instructions.
|
Thanks to Christian D Langevin and David Ahlfeld for the following instructions.
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.)
|
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.
Thanks to Jaime Carrera for the following additional suggestions regarding compiling with gfortran.
F77FLAGS = -fno-second-underscore F77= gfortran
make install
Jaime Carrera says he tested it on Linux - Fedora Core 4. |