Online Guide to MODFLOW-2005

Suggestions on Compiling MODFLOW-2000

Hide Navigation Pane

Suggestions on Compiling MODFLOW-2000

Previous topic Next topic No directory for this topic Expand/collapse all hidden text  

Suggestions on Compiling MODFLOW-2000

Previous topic Next topic Topic directory requires JavaScript JavaScript is required for expanding text JavaScript is required for the print function  

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.

hmtoggle_plus1Lahey-Fujitsu Fortran 95 (LF95)
1.Make sure that you have installed the Fujitsu C compiler that comes with LF95.  The compiler is named fcc.exe.  It should be in the "bin" directory under the directory in which LF95 is installed.  If you have not installed the Fujitsu C compiler, install it from the same CD (or other media) on which you received LF95.  After installing it, be sure to also install the most recent patch file for your version of LF95 from the Lahey web site.
2.Download MODFLOW-2000.
3.Extract all the source code being sure to retain the directory structure inside the compressed download file.
4.Download automake.fig and place it in the same directory as the source code (for example C:\Wrdapp\mf2k.1_17\src\mf2k).
5.In the directory with the MODFLOW-2000 source code, create a subdirectory named "objLF95" (for example C:\Wrdapp\mf2k.1_17\src\mf2k\objLF95).
6.In the mf2k src directory create a subdirectory named "bin" (for example C:\Wrdapp\mf2k.1_17\src\bin).
7.Edit the line in Automake.fig that specifies the location of the include files of the Fujitsu C compiler to use the correct path for your system.  That line is

 

     COMPILE=@fcc /c /D _UF /I C:\Compilers\Lahey\LF9557\Include /o .\objLF95\%sf%oe %fi

 

8.You can run AutoMake to compile MODFLOW-2000 either by running the file AM.bat (which is distributed with LF95) from the command prompt or by doing the following.
9.Start the Lahey ED Developer.
10.Open any of the source code files for MODFLOW-2000.
11.Click on the Automake button.

Automake Button

hmtoggle_plus1Compaq Digital Visual Fortran
1.Download MODFLOW-2000.
2.Extract all the source code being sure to retain the directory structure inside the compressed download file.
3.Copy parallel.inc from the mf2k.1_17\src\mf2k directory to the mf2k.1_17\src\mf2k\serial directory.
4.Open Solvers.C in a text editor, and change all copies of "resprint" to "RESPRINT". (lines 52, 173, 201, and 234)
5.Make sure you have Visual Studio installed. It comes with Compaq Digital Visual Fortran.
6.Make sure you have Microsoft Visual C++ installed.  You might need to purchase Microsoft Visual C++ separately.
7.Start Visual Studio.
8.Select File|New and create a new Project that is a Fortran Console Application.  A good location for the project would be in C:\MF2K.1_17\SRC which Visual studio will change to C:\MF2K.1_17\SRC\mf2k.  After you click the OK button, choose "An empty project" (the default) and click on the Finish button.  Then click OK to close the "New Project Information" dialog box.

Compaq New Project dialog box

9.Change to "File View" and right click on "mf2k files". Select Add Files to Project.

Compaq "File View" mode with pop-up menu

10.Select all the files with the extensions .c and .h in the \src\mf2k directory.
11.Right click on "mf2k files" again and select Add Files to Project.  This time, change the file type to Fortran Source files and add all the Fortran source files in the \src\mf2k directory.
12.Right click on "mf2k files" again and select Add Files to Project.  Change the file type to Fortran Source files and add para-non.f  in the \src\mf2k\serial directory.
13.On line 398 of gmg1.f, add a “c” in column one in order to comment out the “_resprint” reference:

c      !DEC$ ATTRIBUTES ALIAS:'_resprint' :: RESPRINT

14.Select "Project|Settings" and on the C/C++ tab change the "Category" to "Code Generation" and then change the "Calling Convention" to "__stdcall".

Compaq Project Settings dialog box with __stdcall selected

14.Change to the Link tab and add "DFOR.LIB" to the end of the list of  Object/libray modules.

Compaq Project Settings dialog box with DFOR.LIB showing

15.Click the OK button to close the Project Settings dialog box.  Then select Build|Build mf2k.exe
hmtoggle_plus1Microsoft Visual Studio .NET 2003 and the Intel Fortran Compiler 8.1.

Thanks to Ingo Berg for the following instructions. Thanks to Edward Banta and Eileen Poeter for additional suggestions.

1.First, extract the source code being sure to retain the directory structure inside the compressed download file.
2.Copy par-non.f from the mf2k.1_17\src\mf2k\serial directory to the mf2k.1_17\src\mf2k directory.
3.Open Solvers.h in a text editor. At the beginning of the file, comment out the following three lines (6,7,8) by placing a "//" in front of them like:

 

     //#ifdef _UF

     //#define resprint resprint_

     //#endif

 

     Behind this block write the following line:

 

     #define resprint RESPRINT

 

4.Open Microsoft Visual Studio .NET and create a new project using the "File | New | Project menu". Select Intel(R) Fortran Projects on the left side of the window and choose "Console Application" on the right side. Name the project mf2k_net and select ...\mf2k.1_17\src\mf2k as the project location. The IDE will create a new directory with that name to store the project.

 

Creating a new Fortran project

 

Press OK. A Window with the application wizard will open. Go to the application settings and select "Empty Project". Press finish afterwards.

 

Empty project

 

5.You should now see the Microsoft .NET IDE with the project explorer treeview on the right side. In the File menu select "File | Add existing element". A File dialog box will appear. This dialog box shows the content of the newly created "mf2k_net" directory, which does not contain any Fortran files yet. Go to the parent directory. (Press the small yellow symbol with the buckled arrow pointing upwards on top of the window). You should now see the content of the "mf2k" directory which consists of the Fortran files. Select all of them. In order to select all of the files, hold the shift key down and select the first and the last file. After doing this press "open". Now you should see the files added to the project explorer treeview.

 

Fortran project with source files.

 

 

6.Now we have a project with the fortran source code files. The part that is missing are the C-source code files. These will be added next. Since It is not possible to mix Fortran and c code within the same project, we have to create another project containing the c files. From the main menu, select "File | New | Project". From the "Visual C++ Projects" node on the left side, select "Win32". From the right side, select "Win32-Project". Assign "mf2k_gmg" as the project name and assign ...\mf2k.1_17\src\mf2k as the project path. Make sure you have the "Add to project" radiobutton active; otherwise, the IDE would close the previousely created Fortran project.

 

Add to Project

 

7.Press OK. The Project C++ project wizard will open. Go to the application settings and select "Static library". Uncheck the "Precompiled headers" option.

 

C++ Project Wizard

 

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.

8.The next step is telling the IDE to link the gmg library file to the main program. For this reason first compile the "mf2k_gmg" project in order to create a library file. Select the project; press the right mouse button; and select the "build" menu entry. You should see the library compile. If successful, a file named "mf2k_gmg.lib" should be created in either the "mf2k\mf2k_gmg\Debug" or the "mf2k\mf2k_gmg\Release" directory. The location depends on whether "debug" or "release" is selected as the build option in your IDE. For this test, the file is assumed to be located in the "Debug" directory.
9.In the "Project Explorer" treeview, select the "Ressource Files" node from "mf2k_net" project. This is the place where we are going to add the gmg lib file. Press the right mouse button and select "Add | Existing Element". A file selector will open. Go to the "mf2k_gmg/Debug directory". In the File types selector at the bottom of the window, change the filter to *.*. Select the file "mf2k_gmg.lib" and press open. The gmg lib has now been added to the main program.

 

mf2k_gmg lib

 

10.Finally select the "mf2k_net" Project and build it. The output file will be created either as "mf2k.1_17\src\mf2k\mf2k_net\Debug}mf2k_net" or as "mf2k.1_17\src\mf2k\mf2k_net\Debug}mf2k_net". If you wish, change the name of the output file in the Project settings or rename it manually to mf2k.
11.

 

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.

 

illustration showing how to ignore the MSVCRT library.

 

hmtoggle_plus1Microsoft Visual Studio C++ .NET 2003 and the Intel Fortran Compiler 9.0.

Thanks to Edward Banta for the following instructions. Thanks to Edward Banta and Eileen Poeter for additional suggestions.

1.First, extract the MODFLOW-2000 source code, being sure to retain the directory structure inside the compressed download file.
2.Copy para-non.f from the src\mf2k\serial folder to the src\mf2k folder.
3.Open Microsoft Visual Studio .NET 2003 and create a new solution using File … New … Blank Solution. Name the solution “MF2K_Solution” and for Location, browse to an existing folder; it would be convenient to use the folder that is the parent of the src folder of the MODFLOW-2000 distribution, but the location can be anywhere.  The new solution will be in a subfolder that will be created under the selected folder.  Click OK.New Console Application - MF2K

New Project

4.Create a project in the “MF2K_Solution” solution you just made. To do this, in the Solution Explorer panel right click Solution ‘MF2K_Solution’ and select Add…New Project.  In the Add New Project dialog, click on “Intel Fortran Projects” in the left panel and ensure that “Console Application” is selected in the right panel.  Change the name to “mf2k” and click OK.
5.The Fortran Console Application wizard will open. Click on Application Settings and select "Empty Project".  Click Finish.Empty Project.

Empty Project

6.The next step is to add Fortran source code files to the mf2k project.  In the Solution Explorer panel under the “mf2k” project, right click “Source Files” and select Add…Add Existing Item.  Navigate to the src\mf2k folder of the MODFLOW-2000 distribution.  Ensure that the “Files of type” filter is “Common Intel Fortran files”.  Select all the *.f and *.f90 files (click on the first one and <Shift>-click on the last one).  Click Open.  Add more files to the “Source Files” list, but this time set the “Files of type” filter to “All Files”.  Select ground.com then use <Ctrl>-click to add hydmod.inc, lmt6.inc, openspec.inc, param.inc, params.inc, and startdaf.com to the selection.  Click Open.
7.Now we have a project with the Fortran source code files. The C source code will be added next. Since it is not possible to mix Fortran and C code within the same project, we have to create another project containing the C files.  In the Solution Explorer panel, right click Solution ‘MF2K_Solution’ and select Add…New Project.  In the Add New Project dialog, expand “Visual C++ Projects” in the left panel and select Win32.  In the right panel, select “Win32 Project” and enter “mf2k_gmg” as the name.  Click OK.  In the Win32 Application Wizard dialog, click “Application Settings” and then under Application type, select “static library” and clear the “Precompiled header” check box.  Click Finish.
8.You will see a second project appear in the Solution Explorer panel. This project will be used to create a static library for the GMG components that are written in C. Next we have to add the C source files. In the Solution Explorer panel, under the “mf2k_gmg” project, right click “Source Files” and select Add…Add Existing Item.  Navigate to the src\mf2k folder of the MODFLOW-2000 distribution and select all the *.c files (four of them).  In a similar manner, add the four *.h files in the src\mf2k folder under “Header Files” in the Solution Explorer panel.
9.The next step to tell the IDE to link the GMG library file to the mf2k project, but first the GMG static library needs to be compiled. In the drop-down list near the top of the Visual Studio window, change the configuration (which is not labeled as such) from “Debug” to “Release”. The next step is to compile the "mf2k_gmg" project in order to create a library file. Select the project; press the right mouse button; and select the "build" menu entry. You should see the library compile. If successful, a file named "mf2k_gmg.lib" should be created in the "MF2K_Solution\mf2k_gmg\Release" directory.
10.In the Solution Explorer panel, select "Resource Files" under the "mf2k" project. This is the place where we are going to add the GMG library file. Press the right mouse button and select Add … Add Existing Item". A file selector will open. Go to the "MF2K_Solution\mf2k_gmg\Release directory". In the File types selector at the bottom of the window, change the filter to All Files. Select the file "mf2k_gmg.lib" and press open. The GMG library has now been added to the solution.
11.Finally, select the "mf2k" project and build it. The output file will be created as mf2k.exe in the MF2K_Solution\mf2k\Release folder.  To save the solution, on the File menu click “Save All”.
12.

 

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.

 

illustration showing how to ignore the MSVCRT library.

 

13.The steps above generate a mixed precision executable file, like the one posted on the MODFLOW-2000 web page.  In some cases, it is advantageous to use a fully double precision version of MODFLOW-2000 to generate satisfactory results.  A fully double precision executable can be generated as follows.  Select the mf2k project in the Solution Explorer panel.  On the main menu bar select Project…Properties. In the mf2k Property Page dialog, select Fortran and under Fortran select Data.  Change the Default Real KIND from 4 to 8.  Click OK.  Again, build the mf2k project.  The resulting mf2k.exe program is now fully double-precision. You might want to rename it as “mf2k-dp.exe”.  Be aware that programs that read binary files produced by MODFLOW-2000 (e.g. Modpath, Zonebudget, ModelViewer) expect to read single-precision data, and they will be unable to read data from binary files produced by a double-precision version of MODFLOW-2000.  Those programs, however, could be similarly recompiled as fully double precision, which would enable them to read double precision binary files.
hmtoggle_plus1Microsoft Visual Studio 2005 with Intel Fortran Compiler 11.1

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.

1.First, extract the source code being sure to retain the directory structure inside the compressed download file.
2.Copy par-non.f from the mf2k.1_17\src\mf2k\serial directory to the mf2k.1_17\src\mf2k directory.
3.Open Microsoft Visual Studio
4.File>New>Project: Make sure to select the settings according to the following window.  You can give the project a name, such as mf2k, and set the location to the location of the MODFLOW Fortran source files.  Then click OK.

Dialog box with the Console Application selected for an Intel Fortran project

Click Next to the "Welcome to the Fortran Console Application Wizard".

5.Click "Empty Project" under the "Application Settings" window, and then click Finish.

Fortran Consol Application Wizard. Empty project selected.

6.Now you need to add all of the Fortran files to the mf2k project that you just created.  You can do this by selecting Project>Add Existing Item...  Select all of the Fortran source files in the mf2k subdirectory and click Add.

Add Fortran files.

7.Confirm that the following line is present gmg1.f after the line containing "SUBROUTINE RESPRINT":

 

           !DEC$ ATTRIBUTES ALIAS:'_resprint' :: RESPRINT

 

8.Next, you need to create a new project for the GMG solver because a project can contain only a single programming language.  Click File>New>Project.  Then select the settings as follows making sure to "Add to Solution".

Empty C++ project for GMG solver.

9.Now you should see that the gmg project has been added to the solution.  This will be shown in the Solution Explorer Window, which may be on the right-side of the screen.  To add the gmg C files to the gmg project, select Project>Add Existing Item... (make sure that the gmg project is selected in the solution window).  Add only the .c and .h files as follows and click Add:

Add .c and .h files for GMG solver.

10.Now select Project>Project Dependencies.  Then select the mf2k project and check the underlying box that says gmg as follows:

Make Fortran project depend on gmg project.

11.Now select the project properties for the gmg project and change the configuration type from .exe to a static library (.lib) as follows:

Make GMG project a static library

12.Now, open the solvers.h file, which is a Header File under the gmg project.  As Ingo Berg mentioned in his description of compiling MODFLOW-2000 with Microsoft Visual Studio .NET 2003, you need make the following changes.  Comment out the following three lines by placing a // in front of them

 

//#ifdef_UF

//#define resprint resprint_

//#endif

 

(According the David Ahlfeld, MODFLOW will still compile if this instruction is omitted.)

 

13.After these commented lines add the following line:

 

#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.)

14.In the Fortran code project property (shown after click on the 'property' in the popped list when you right-click on the title of the Fortran project in the solution explorer), 'Configuration properties>Fortran>Diagnostics>Check Routine Interfaces' should be "NO", otherwise the program generates error messages.
15.In the Fortran code project property, 'Configuration properties>Linker>General>Enable Incremental Linking" should be "YES", to avoid an error.
16.The same option for both of 'Configuration properties>Fortran>Libraries>Runtime Library' in the Fortran code project property and 'Configuration properties>C/C++>Code Generation>Runtime Library' in the C code project, i.e., gmg, property is recommended. E.g., if "Multi-threaded Debug (/MTd)" is chosen for the C code part, the same one is recommended to choose for the counterpart in the Fortran project.
17.If "DLL" is chosen, it will cause an error. E.g., "Multi-threaded DLL (/MD)" is chosen for 'Configuration properties>C/C++>Code Generation>Runtime Library' in the C code project property will not work.
18.Also include the path to the default Intel Fortan header file and library directories in the project property dialog box.
19.You are now ready to compile MODFLOW-2000, including the GMG solver.  Click Build>Build Solution.  Keep in mind that "debug" is the default configuration.  You may want to change to the "release" configuration and make adjustments to the optimization settings to improve efficiency.  If you have a problem with the "release" configuration, make sure that the GMG project is set to a "Static Library (.lib)".
20.

 

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.

 

illustration showing how to ignore the MSVCRT library.

 

hmtoggle_plus1Visual Studio 2008 with Intel C++ compiler 11.0 and Intel Visual Fortran compiler 11.0

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.

1.First, extract the source code being sure to retain the directory structure inside the compressed download file.
2.Copy par-non.f from the mf2k.1_19\src\mf2k\serial directory to the mf2k.1_19\src\mf2k directory.
3.Rename the mf2k.1_19\src\mf2k directory to mf2k.1_19\src\temp directory
4.Open Microsoft Visual Studio 2008
5.Select File>New>Project: Make sure to select the settings according to the following window.  You can give the project a name, such as mf2k, and set the location to the location of the MODFLOW Fortran source files.  Then click OK.

Dialog box showing how to create a new Intel Fortran Empty Project

6.Copy all the files from the mf2k.1_19\src\temp to the mf2k.1_19\src\mf2k directory created by Visual Studio
7.Now you need to add all of the Fortran files to the mf2k project that you just created.  You can do this by selecting Project>Add Existing Item...  Select all of the Fortran source files in the mf2k subdirectory and click Add.

Add Existing Item dialog box showing all Fortran files being selected

8.Next, you need to create a new project for the GMG solver because a project can contain only a single programming language.  Click File>New>Project.  Then select the settings as follows making sure to "Add to Solution".

New Project dialog box with new Visual C++ Console application selected

9.In the Win32 Application Wizard, click the Finish button

Final dialog box in the Win32 Appliation Wizard

10.Remove all the header and source files from the gmg project by right-clicking on them and selecting Remove from the pop-up menu.
11.Now you should see that the gmg project has been added to the solution.  This will be shown in the Solution Explorer Window.  To add the gmg C files to the gmg project, select Project>Add Existing Item... (make sure that the gmg project is selected in the solution window).  Add only the .c and .h files as follows and click Add:

Add Existing Item dialog box with all .c and .h files selected. 

12.Right click on the gmg project and select Intel C++ compiler pro>Use Intel C++
13.Now select Project>Project Dependencies.  Then select the mf2k project and check the underlying box that says gmg as follows:

Project Dependiencies dialog box with gmg selected.

14.Now select Project>Properties for the gmg project and change the configuration type from .exe to a static library (.lib) as follows:

Property Pages fo the gms project with the Configuration type changed to Static Library.

15.Turn off the use of precompiled headers.

Project Pages for gmg project with Create/Use Precompiled Header selected.

16.In the Fortran code project property (shown after click on the 'property' in the popped list when you right-click on the title of the Fortran project in the solution explorer), 'Configuration properties>Fortran>Diagnostics>Check Routine Interfaces' should be "NO", otherwise the program generates error messages.

Property Pages for mf2k project with Check Routine Interfaces turned off.

17.In the Fortran code project property, 'Configuration properties>Linker>General>Enable Incremental Linking" should be "YES", to avoid an error.

Property Pages for mf2k project Incremental linking turned on.

18.The same option for both of 'Configuration properties>Fortran>Libraries>Runtime Library' in the Fortran code project property and 'Configuration properties>C/C++>Code Generation>Runtime Library' in the C code project, i.e., gmg, property is recommended. E.g., if "Multi-threaded Debug (/MTd)" is chosen for the C code part, the same one is recommended to choose for the counterpart in the Fortran project.

Property Pages for gmg project with multithreaded debug selected

Property Pages for mf2k project with multithreaded debug selected

19.If "DLL" is chosen, it will cause an error. E.g., "Multi-threaded DLL (/MD)" is chosen for 'Configuration properties>C/C++>Code Generation>Runtime Library' in the C code project property will not work.
20.Also include the path to the default Intel Fortan header file and library directories in the GMG project property dialog box.

Property Pages for gmg project with an additional include directory specified.

21.You are now ready to compile MODFLOW-2000, including the GMG solver.  Click Build>Build Solution.  Keep in mind that "debug" is the default configuration.  You may want to change to the "release" configuration and make adjustments to the optimization settings to improve efficiency.  If you have a problem with the "release" configuration, make sure that the GMG project is set to a "Static Library (.lib)".
hmtoggle_plus1GNU gfortran on Mac OS X (UNIX)

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.

hmtoggle_plus1GNU Fortran (gfortran)

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.

 

1.Modify the makefile file:

     F77FLAGS = -fno-second-underscore

     F77= gfortran

2.On the command line just type (under src/mf2k/)

     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.

1.Comment out lines 5, 6 and 7 of solvers.h

 

     /* Append underscore to fortran modual name */

     //#ifdef _UF/

     /#define resprint resprint

     //#endif

 

2.   2. Change lines 11..17 of mf2kgmg.h into

 

     /* 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.

 

3.To compile the .f files use:

 

     gfortran -c -fno-underscoring file.f

 

4.To compile the .c files use:

 

     gfortran -c -D_UF -Ilocation file.c

 

     where 'location' points to the drive and directory where the include files for gfortran are located.

 

5.To link the object files into an executable use:

 

     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.

hmtoggle_plus1GNU Fortran and the GNU C compiler on the Mac OSX

Laurent Delphin has provided a makefile for compiling MODFLOW-2005 on the Mac.

makefile

hmtoggle_plus1Suggestions for compiling the Conduit Flow Process for MODFLOW-2005

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)

hmtoggle_plus1FTN95 and Watcom Compilers for Compiling MODFLOW-2005

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

echo start

del *.obj

del mf2005.exe

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   de47.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gmg7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2bas7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2bcf7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2chd7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2drn7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2drt7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2ets7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2evt7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2fhb7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2gag7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2ghb7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2hfb7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2huf7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2hydmod7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2ibs7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2lak7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2lpf7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2mnw17.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2mnw27.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2mnw2i7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2rch7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2res7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2riv7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2sfr7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2str7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2sub7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2swt7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2uzf1.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwf2wel7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwfsfrmodule.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   gwfuzfmodule.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   hufutl7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   lmt7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   mhc7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2bas7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2chd7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2drn7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2ghb7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2riv7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   obs2str7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   parutl7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   pcg7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   sip7.f

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   utl7.f /ALT_kinds

c:\watcom\binnt\wcc386.exe  r_vector.c

c:\watcom\binnt\wcc386.exe  solvers.c

c:\watcom\binnt\wcc386.exe  ccfd.c

c:\watcom\binnt\wcc386.exe  mf2kgmg.c

"C:\Program Files\Silverfrost\FTN95\FTN95.exe"   mf2005.f /link

hmtoggle_plus1Code::Blocks and Gfortran

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.
CodeBlock Compiler auto-detection with GNU Fortran Compiler selected

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.
File associations left unchanged.

Next you may need to configure Code::Blocks to use gfortran.

1.Select “Settings|Compiler.”
2.Select the GNU Fortran Compiler, make sure the debugger is set to GDB/CDB debugger, and click OK.

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.

1.In Code::Blocks, select “File|New|Project” or click the “Create new project” link.
2.Select “Fortran Application” and click the Go button.
New Fortran application selected
3.A new “wizard” dialog box will appear. If you have never used Code::Blocks before, the first page of the dialog box does nothing so just click the “Next” button.
4.On the next page, specify a project title and a folder for MODFLOW-2005 and click the “Next” button. In this example, we will use “MF2005” as the name of the project. Code::Blocks will create a subfolder in that directory to contain the source code for the project. In this case, the folder is “C:\MF2005.”
Specifying the project title in Codeblocks
5.On the next page, be sure to set the compiler to the gfortran compiler and click the “Finish” button.
Specifying the GNU GFortran Compiler
6.At this point, the workspace will contain one file named “main.f95” under “Fortran Sources” that was automatically generated by Code::Blocks. That file isn’t needed because we already have all of the source code for MODFLOW. Click on it to select it. Then right-click and select “Remove file from project” from the pop-up menu. You may also delete the file from your computer using Windows Explorer.
Codeblocks with main.f95 visible
7.Copy all the source code files into the folder for the project (C:\MF2005).
8.Right-click on “MF2005” and select “Add files…” from the pop-up menu.
9.Select all the files in the folder for the project except MF2005.cbp, nogmg.txt, and openspec.inc. That should be all the files with the extension “.f”, “.f90”, “.c”, or “.h”.  (MF2005.cbp is the Code::Blocks project file. Nogmg.txt is used to replace gmg.f if MODFLOW is being compiled without the GMG package. Openspec.inc is part of the source code that will be “included” in several different source code files.)
10.Code::Blocks will display a dialog box asking to which targets the files should belong. The default is that the files should belong to both the debug and release targets which is what we want so just click OK.
Specifying targets
11.Select Project|Build Options, select MF2005, and select the “Compiler Settings” tab. Under that select the “Other options” tab. Enter "-D _UF" on that tab. This step defines "_UF" when compiling some of the C code in MODFLOW.
Build option for MF2005 in Codeblocks
12.Switch to the Linker settings tab and click the “Add” button under “Link libraries”. Select the file libgfortran.a which you may find at C:\Program Files (x86)\CodeBlocks\MinGW\lib\gcc\mingw32\4.7.1\. When it asks if you want to “Keep this as a relative path?”, click the Yes button. Click the Add button two more times and select libgcc.a and libquadmath.a too. (If you choose to skip this step, you can still compile MODFLOW but you will need to have some dlls available for MODFLOW when you run it. Look for the dlls in C:\Program Files (x86)\CodeBlocks\MinGW\bin or C:\Program Files\CodeBlocks\MinGW\bin .)
specifying additional required libraries
13.(Note: This step may no longer be necessary with the current version of CodeBlocks (version 16.01).) Because of dependencies among the various source code files in MODFLOW, the order in which they are compiled is important with gfortran. (With other compilers, it may not be necessary to specify a compile order.) The order in which the files are compiled can be controlled using the “priority weight” for each file. The default priority weight is 50. We will need to specify smaller priority weights for some files in order to control the order in which the files are compiled. The table below gives the priority weights that will be assigned. To assign a priority weight, expand “Fortran Sources” and right click on one of the files. From the pop-up menu, select “Properties”. In the dialog box, select the “Build” tab and use the slider to set the priority weight.
Specifying the priority of of a file.

File name

Priority Weight

gwf2bas7.f

20

gwf2bcf7.f

25

gwf2huf7.f

22

gwf2ibs7.f

25

gwf2lak7.f

27

gwf2lpf7.f

22

gwf2str7.f

27

gwf2sub7.f

30

gwfsfrmodule.f

21

gwfuzfmodule.f

22

pcg7.f

30

pcgn2.f90

33

pcgn_solve2.f90

30

sip7.f

27

14.Open Openspec.inc in a text editor such as Notepad. Openspec.inc has some Fortran code that used in opening binary files. What we want to do is to compile MODFLOW in such a way that a binary file is a “unstructured non-formatted” file so that programs that aren’t compiled with gfortran will be able to read them. With gfortran we need to change Openspec.inc slightly so that the binary files are unstructured non-formatted files.
15.In FORTRAN, if the first character of a line is a “C”, that line is considered a comment and is ignored by the compiler. Note that most of the lines in openspec.inc are comments. There are only four lines that are not comments. The first one declares three variables named ACCESS,FORM, and ACTION. The other three lines each set one of those variables. If you look at the comments, for FORM, and ACTION, there are two versions of the lines that set those variables. For each of them, one version of the line is marked with a C as the first character and so is ignored by the compiler. The other one isn’t marked with a C as the first character and so is used by the compiler. In the version of MODFLOW with which I am working, the version of the line for ACTION is the “Standard FORTRAN” version. Leave it alone. The active version of the line for FORM is “Non-standard Fortran”. We will need to change that to the “Standard FORTRAN” version. Delete the “C” at the beginning of the line

C      DATA FORM/'UNFORMATTED'/

16.and insert a “C” at the beginning of the line

      DATA FORM/'BINARY'/

17.Now both FORM and ACCESS are using Standard FORTRAN. We need to make two more changes. Locate the line where ACCESS is specified. It reads

      DATA ACCESS/'SEQUENTIAL'/

18.Insert a “C” at the beginning of that line so that it is ignored by the compiler. Then insert the following lines. Do not use tab characters instead of spaces.

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'/

19.Save Openspec.inc
20.Right-click on gwf2lpf7.f and select "Build". (This step is required in CodeBlocks version 16.01 but not in some earlier versions.)
21.Select “Build|Build.” If you get error messages, check to see if the following steps help.
22.If you get an error message like the ones below, go to the appropriate lines and fix the error and then try to build MODFLOW again. In this case, you just have to change a line like
         IF ( LVAL.EQ. .FALSE. ) THEN
to
         IF ( LVAL.EQV. .FALSE. ) THEN
Illustration of error message "Error: Logicals must be compared with .eqv. instead of .eq."
Then select Build|Rebuild workspace.