gfortran on Mac

Facts, news, and guidance about ROMS software

Moderators: arango, robertson

Post Reply
Message
Author
jsorense

gfortran on Mac

#1 Unread post by jsorense »

I am trying to get started on using ROMS. Has anybody compiled ROMS using gfortran (f95 compiler) on a mac?

jsorense

gfortran on mac

#2 Unread post by jsorense »

I successfully compiled ROMS on a mac using gfortran. The key for me was to use FFLAGS = -ff2c (courtesy of M. Hadfield). Also, I had to rewrite the declarations in mod_strings.f to read

character (len=80) :: my_os = "Darwin"
character (len=80) :: my_cpu = "macosx"
character (len=80) :: my_fort = "gfortran"
character (len=80) :: my_fc = "gfortran"
character (len=160) :: my_fflags = "-ff2c"

This was necessary because the assignments weren't working properly for my system.

I haven't had a chance yet to see if the compiled program actually works.

amaxwell
Posts: 6
Joined: Tue Dec 14, 2004 11:37 pm
Location: PNNL, Sequim WA

#3 Unread post by amaxwell »

It works for me; I build gfortran from the gcc CVS repository. The problem with mod_strings.f90 is annoying enough that I use this nasty hack.

In makefile:

Code: Select all

%.f90: %.F
	$(CPP) $(CPPFLAGS) $< > $*.f90
	sh fixStrings.sh $*.f90
	$(CLEAN) $*.f90
Where fixString.sh contains this:

Code: Select all

#!/bin/sh
if [ $1 = "mod_strings.f90" ]; then
sed -E -e 's/(my_[a-z]+ = )(.*$)/\1'"'\2'"'/g' $1 >$1.bak
mv $1.bak $1
fi
Someone who really understands GNU make will probably laugh, but it beats fixing the strings manually every time you recompile. Cleaner solutions welcome!

choboter
Posts: 4
Joined: Wed Dec 22, 2004 5:50 pm
Location: California Polytechnic State University

mod_strings on Mac

#4 Unread post by choboter »

amaxwell wrote:It works for me; I build gfortran from the gcc CVS repository. The problem with mod_strings.f90 is annoying enough that I use this nasty hack.

In makefile:

Code: Select all

%.f90: %.F
	$(CPP) $(CPPFLAGS) $< > $*.f90
	sh fixStrings.sh $*.f90
	$(CLEAN) $*.f90
Where fixString.sh contains this:

Code: Select all

#!/bin/sh
if [ $1 = "mod_strings.f90" ]; then
sed -E -e 's/(my_[a-z]+ = )(.*$)/\1'"'\2'"'/g' $1 >$1.bak
mv $1.bak $1
fi
Someone who really understands GNU make will probably laugh, but it beats fixing the strings manually every time you recompile. Cleaner solutions welcome!
I'm compiling on a Mac, and also had problems with mod_strings.F. Here is my hack. I don't know if this is really cleaner or not, but it is a simple one-time fix that doesn't need an external shell script.

In makefile:

Code: Select all

#--------------------------------------------------------------------------
#  Special CPP macros for mod_strings.F
#--------------------------------------------------------------------------
# Default special macro:  
#mod_strings.f90: CPPFLAGS += -DMY_OS="'$(OS)'" -DMY_CPU="'$(CPU)'" \
#                             -DMY_FORT="'$(FORT)'" -DMY_FC="'$(FC)'" \
#                             -DMY_FFLAGS="'$(FFLAGS)'"
# New and improved macro: 
mod_strings.f90: CPPFLAGS += -DMY_OS='"$(OS)"' -DMY_CPU='"$(CPU)"' \
                             -DMY_FORT='"$(FORT)"' -DMY_FC='"$(FC)"' \
                             -DMY_FFLAGS='"$(FFLAGS)"'
where the default special macro was already present in the makefile, and the new macro is identical, except that the double and single quotation marks have been reversed.

Hope this is helpful to someone.

User avatar
kate
Posts: 4091
Joined: Wed Jul 02, 2003 5:29 pm
Location: CFOS/UAF, USA

Re: mod_strings on Mac

#5 Unread post by kate »

choboter wrote:
I'm compiling on a Mac, and also had problems with mod_strings.F. Here is my hack. I don't know if this is really cleaner or not, but it is a simple one-time fix that doesn't need an external shell script.

In makefile:

Code: Select all

#--------------------------------------------------------------------------
#  Special CPP macros for mod_strings.F
#--------------------------------------------------------------------------
# Default special macro:  
#mod_strings.f90: CPPFLAGS += -DMY_OS="'$(OS)'" -DMY_CPU="'$(CPU)'" \
#                             -DMY_FORT="'$(FORT)'" -DMY_FC="'$(FC)'" \
#                             -DMY_FFLAGS="'$(FFLAGS)'"
# New and improved macro: 
mod_strings.f90: CPPFLAGS += -DMY_OS='"$(OS)"' -DMY_CPU='"$(CPU)"' \
                             -DMY_FORT='"$(FORT)"' -DMY_FC='"$(FC)"' \
                             -DMY_FFLAGS='"$(FFLAGS)"'
where the default special macro was already present in the makefile, and the new macro is identical, except that the double and single quotation marks have been reversed.

Hope this is helpful to someone.
It's wonderful as long as it doesn't mess up on any other system. I was having Mac troubles too and couldn't find the right quote combination.

amaxwell
Posts: 6
Joined: Tue Dec 14, 2004 11:37 pm
Location: PNNL, Sequim WA

Re: mod_strings on Mac

#6 Unread post by amaxwell »

kate wrote: It's wonderful as long as it doesn't mess up on any other system. I was having Mac troubles too and couldn't find the right quote combination.
Hear hear! Better than my solution. I thought I tried just about every combination of quotes before giving up in disgust, but I must have missed at least one.

Post Reply