How to compile MT3DMS with gfortran GNU compiler (I did it on the Mac OS X 10.6
T.N.Olsthorn 091009
tolsthoorn@gmail.com t.n.olsthoorn@tudelft.nl


Use the makefile that that was borrowed from mf2k.1_18 and adapated

The old fashioned rules ‘.f.o:  has been changed into modern pattern rules

%o : % for

=================== gfortran reports error in mt3dms5.for=================== 
gfortran  -c mt3dms5.for
mt3dms5.for:79.61:

      INTEGER   iNameFile,iFLen,IC,iFTLfmt,iUnitTRNOP,MXTRNOP,          
                                                            1
Error: Symbol 'mxtrnop' at (1) already has basic type of INTEGER
mt3dms5.for:148.11:

=================== Action Olsthoorn=======================================
MXTRNOP, removed because already declared in line 58:


      INTEGER,PARAMETER :: MXTRNOP=50,MXCOMP=100,
     &                     MXPRS=1000,MXSTP=1000,MXOBS=200     
     
=================== compilation continues    ============================== 
=================== gfortran reports error in ============================= 
mt_dsp5.for:75.63:

      INTEGER   IN,IOUT,NCOL,NROW,NLAY,K,MCOMP,ICOMP,IMSD,J,I,K,        
                                                              1
Error: Symbol 'k' at (1) already has basic type of INTEGER
mt_dsp5.for:66.26:

=================== Action Olsthoorn=======================================

K, removed because delared twice in this line

=========================== compiling and linking continues ================
gfortran  -c mt_dsp5.for
gfortran  -c mt_fmi5.for
gfortran  -c mt_gcg5.for
gfortran  -c mt_rct5.for
gfortran  -c mt_ssm5.for
gfortran  -c mt_tob5.for
gfortran  -o mt3dms5 mt3dms5.o mt_utl5.o mt_adv5.o mt_btn5.o mt_dsp5.o mt_fmi5.o mt_gcg5.o mt_rct5.o mt_ssm5.o mt_tob5.o   -lc
Undefined symbols:
  "_getcl_", referenced from:
      _MAIN__ in mt3dms5.o
ld: symbol(s) not found

================ problem is due to GETCL not known at line 53 ==============

C
C--The following statement should be uncommented in order to use
C--GETCL to retrieve a command line argument.  The call to GETCL may
C--be commented out for compilers that do not support it.
      CALL GETCL(FLNAME)
C
C--Get Name of NAME File from Screen
      IF(FLNAME.EQ.' ') THEN

=================== Action Olsthoorn=======================================
===== change into a call to getarg (as indicated in mf2k) =================

      CALL GETARG(1,FLNAME)
C
C--Get Name of NAME File from Screen
      IF(FLNAME.EQ.' ') THEN

====== after which linking contiues and a succesful executable is obtained

$>make
gfortran  -c mt3dms5.for
gfortran  -o mt3dms5 mt3dms5.o mt_utl5.o mt_adv5.o mt_btn5.o mt_dsp5.o mt_fmi5.o mt_gcg5.o mt_rct5.o mt_ssm5.o mt_tob5.o   -lc
$>

======= by the way =======================================================

The gfortran compiler warned bout constructs like
      do ....
      statements
      goto 100
100   enddo

Where the compiler issued a warning I changed that into

      do ....
      statements
      goto 100
      enddo
100   continue

======= Theo Olsthoorn, tolsthoorn@gmail.com date: 091009




======= Below is the full content of the makefile used to build the executable =============

# Makefile for non-USGS distribution
#
# @ (#) Makefile for Modtools 27June1997
# Borrowed from mf2k and adapated by Olsthoorn 091010
#
SOURCELOC = 
UTILITYLOC = 
NEWMOD = 
PROGRAM = mt3dms5
INCDIR= .

# Define the Fortran compile rand its flags
F77= gfortran
F90= gfortran
F77FLAGS=
F90FLAGS=

# Define the C compiler and its flags
CC= gfortran

# -D_UF defines UNIX naming conventions for mixed language compilation.
CFLAGS= -D_UF -O3

# Define the libraries
SYSLIBS=  -lc
USRLIB = 

# Define all object files which make up Modtools
OBJECTS= \
		mt3dms5.o \
		mt_utl5.o \
		mt_adv5.o \
		mt_btn5.o \
		mt_dsp5.o \
		mt_fmi5.o \
		mt_gcg5.o \
		mt_rct5.o \
		mt_ssm5.o \
		mt_tob5.o

SRCS= $(OBJECTS:.o=.f)

install: $(PROGRAM)

# Define Task Function Program Modtools
all: $(PROGRAM)

# Define what Modtools is
$(PROGRAM): $(OBJECTS)
	-$(F77) $(F77FLAGS) -o $(PROGRAM) $(OBJECTS) $(GMG) $(USRLIB) $(SYSLIBS)

# Pth_Object codes of Modtools
%.o: %.for
	$(F77) $(F77FLAGS) -c $<

#  end
