# Makefile for DDSCAT.6.0

# The following variables need to be defined for this Makefile to work
# properly:

# FC specifies the fortran compiler

# FFLAGS is used to compile the modules in "OBJS"
# FFLAGSslamc1 is used to compile the module lapackslamc1.f
# FFLAGSundecl is used to compile the modules with variables that have not
#              been explicitly declared.

# LDFLAGS are flags for linking

# LIBFFTW is flag for linking to FFTW library (see notes below)

# MPI.f is one of
#       mpi_fake.f mpi_subs.f
#       mpi_subs.f

# MPI.o is one of
#       mpi_fake.o mpi_subs.o
#       mpi_fake.o

# cxfftw is one of
#	cxfftw (if FFTW library is installed)
# 	dummycxfftw (if FFTW library is not installed)

# cxc3dfft is one of
#	cxc3dfft (if on a Convex system with Convex vector library available)
#	dummycxc3dfft (otherwise)

# LIBNETCDF is flag for linking to netCDF library (see notes below)

# writenet is one of
#	writenet (if linking to the netCDF library)
#	dummywritenet (otherwise)

# timeit specifies system-dependent code for timing, select from:
#	timeit_sun
#	timeit_hp
#	timeit_sgi
#	timeit_convex
#	timeit_ibm6000
#	timeit_osf
#	timeit_vms
#	timeit_cray
#	timeit_titan

#******************************************************************************
#****************************** MPI support ***********************************

# Modules DDSCAT.f and mpi_subs.f require minor editing to prepare them for
# either non-MPI use or use on a system with MPI support
# Consult either the UserGuide (section 24.1) or comments within these
# modules themselves for instructions on which lines need to be enabled
# and which lines need to be commented out.

#*****************************************************************************
#*********************** Linux with g77, no MPI ******************************

FC		= g77 
FFLAGS		= -c -u -O
FFLAGSundecl  	= -c -O
FFLAGSslamc1	= -c
timeit		= timeit_sun
LDFLAGS 	=
MPI.f		= mpi_fake.f mpi_subs.f
MPI.o		= mpi_fake.o mpi_subs.o

#************************* Linux pgf77, no MPI ******************************
# pgf77 = Portland Group compiler (http://www.pgroup.com)

#FC		= pgf77 -Msecond_underscore
#FFLAGS  	= -c -fast 
#FFLAGSundecl 	= -c -fast 
#FFLAGSslamc1	= -c
#LDFLAGS 	= -Bstatic 
#timeit  	= timeit_sun
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#*****************************************************************************
#********************* Linux pgf77 with MPI support **************************

# mpif77 = shell script to invoke pgf77 compiler with appropriate
#          options to support MPI
# note: it may be necessary to append flag -Msecond_underscore
# (this is not needed on rfd, but is needed on hydra
# 

#FC		= /opt/mpich-1.2.4/bin/mpif77 -Msecond_underscore
#FFLAGS  	= -c -fast 
#FFLAGSundecl 	= -c -fast 
#FFLAGSslamc1	= -c
#LDFLAGS 	= -Bstatic 
#timeit          = timeit_sun
#MPI.f		= mpi_subs.f
#MPI.o		= mpi_subs.o

#********************** OSF on Compaq alpha, no MPI **************************

#FC		= f77
#FFLAGS		= -c -fast
#FFLAGSundecl	= -c -fast
#FFLAGSslamc1	= -c
#LDFLAGS	=
#timeit		= timeit_osf
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#******************************** Sun fortran *********************************

#FC		= f77
#FFLAGS		= -fast -u 
#FFLAGSundecl 	= -fast -O3 -c
#FFLAGSslamc1	= -c
#LDFLAGS	= -fast -O3
#timeit		= timeit_sun
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o


#****************************** AIX fortran on RS6000 *************************

#FC		= xlf
#FFLAGS		= -O
#FFLAGSundecl 	= -O -c
#FFLAGSslamc1	= -c
#LDFLAGS 	= -O
#timeit		= timeit_ibm6000
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#****************************** SGI IRIX on R4000  ****************************
# -mips2 option generates code using the MIPS 2 instruction set [R4000 cpu]

#FC		= f77
#FFLAGS		= -u -mips2 -O2
#FFLAGSundecl	= -mips2 -O2 -c
#FFLAGSslamc1	= -c
#LDFLAGS	= -mips2 -O2
#timeit		= timeit_sgi
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#************* SGI IRIX on R5000, R8000, or R10000 systems ********************
# -mips4 option generates code using the MIPS IV instruction set [supported on
# R5000, R8000, and R10000 cpus]

#FC		= f77
#FFLAGS		= -u -mips4 -O2
#FFLAGSundecl	= -mips4 -O2 -c
#FFLAGSslamc1	= -c
#LDFLAGS	= -mips4 -O2
#timeit		= timeit_sgi
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#****************************** HP AUX ****************************************

#FC		= f77
#FFLAGS		= -O3 -c
#FFLAGSundecl	= -O3
#FFLAGSslamc1	= -c
#LDFLAGS	=
#timeit		= timeit_hp
#MPI.f		= mpi_fake.f mpi_subs.f
#MPI.o		= mpi_fake.o mpi_subs.o

#******************************************************************************

# --------------------------- FFTW package ------------------------------------

# Note: DDSCAT is set up to use FFTW package of Frigo and Johnson.
# If libraries libsfftw.a and libsfftw.la are installed on your system in 
# directory /usr/local/lib then 
# uncomment following definitions (amend path as appropriate):

#LIBFFTW		= -L/usr/local/lib -lsfftw
#cxfftw		= cxfftw

# If FFTW package is not installed on system, then uncomment following
# definitions:

LIBFFTW 	=
cxfftw		= dummycxfftw

#-------------------------- Convex native FFT ---------------------------------

# Note: DDSCAT is set up to use C3DFFT = native 3d FFT routine in
# Convex vector library, if available.

# When NOT running on Convex with vector library, uncomment next definition:

cxc3dfft 	= dummycxc3dfft

# When running on Convex with vector library, uncomment next definition:

#cxc3dfft 	= cxc3dfft

#------------------------------- netCDF library -------------------------------

# Note: DDSCAT is set up to permit use of the netCDF library to produce
# binary output files compliant with netCDF protocols (see the User Guide).
# To NOT link to the netCDF library, uncomment next 3 definitions:

writenet      = dummywritenet
LIBNETCDF     = 
LINKNETCDF    =

# To link to the netCDF library, 
# (1) Edit the file "writenet.f" and modify the INCLUDE statement
#     to give the correct location for the file "netcdf.inc"
# (2) uncomment next 3 definitions ("writenet", "LIBNETCDF", LINKNETCDF"
#     and modify
#     LIBNETCDF to include the correct path to the netCDF libraries
#		("-L/u/flatau/netcdf-2.4.3/lib" works for astro)
#		("-L/usr/peyton/lib" should work for astro, but doesn't)
#     LINKNETCDF to include the names (x) of the libx.a libaries which are
#               needed for linking
#		("-lnetcdf -lnsl" works for astro)
#     You may wish to consult with your sysadmin to find out if these
#     libraries are installed on your system, and if so, where.

#writenet      = writenet
#LIBNETCDF     = -L/usr/local/lib
#LINKNETCDF    = -lnetcdf -lnsl

#---------------------------------------------------------------------------
SRCS	      = DDSCAT.f\
		alpha.f\
		blas.f\
		ccgpack.f\
		cgcommon.f\
		copyit.f\
		cprod.f\
		$(cxc3dfft).f\
		cxfft3n.f\
		$(cxfftw).f\
		dielec.f\
		divide.f\
		errmsg.f\
		eself.f\
		evala.f\
		evale.f\
		evalq.f\
		extend.f\
		farg.f\
		getfml.f\
		getmueller.f\
		gpfa.f\
		interp.f\
		lapackslamc1.f\
		lapacksubs.f\
		namer.f\
		namid.f\
		$(MPI.f)\
		nuller.f\
		orient.f\
		pim.f\
		prinaxis.f\
		reapar.f\
		reashp.f\
		reduce.f\
		refice.f\
		refwat.f\
		restore.f\
		rot2.f\
		rotate.f\
		scat.f\
		scavec.f\
		tar2el.f\
		tar2sp.f\
		tar3el.f\
		tarblocks.f\
		tarcel.f\
		tarcyl.f\
		tarell.f\
		target.f\
		tarhex.f\
		tarnsp.f\
		tarprsm.f\
		tarrec.f\
		tarslb.f\
		tarspharm.f\
		tartet.f\
		$(timeit).f\
		version.f\
		wrimsg.f\
		writebin.f\
		$(writenet).f\
		writesca.f

OBJS	      = DDSCAT.o\
		alpha.o\
		blas.o\
		ccgpack.o\
		cgcommon.o\
		copyit.o\
		cprod.o\
		$(cxc3dfft).o\
		cxfft3n.o\
		$(cxfftw).o\
		dielec.o\
		divide.o\
		errmsg.o\
		eself.o\
		evala.o\
		evale.o\
		evalq.o\
		extend.o\
		farg.o\
		getfml.o\
		getmueller.o\
		gpfa.o\
		interp.o\
		lapackslamc1.o\
		lapacksubs.o\
		$(MPI.o)\
		namer.o\
		namid.o\
		nuller.o\
		orient.o\
		pim.o\
		prinaxis.o\
		reapar.o\
		reashp.o\
		reduce.o\
		refice.o\
		refwat.o\
		restore.o\
		rot2.o\
		rotate.o\
		scat.o\
		scavec.o\
		tar2el.o\
		tar2sp.o\
		tar3el.o\
		tarblocks.o\
		tarcel.o\
		tarcyl.o\
		tarell.o\
		target.o\
		tarhex.o\
		tarnsp.o\
		tarprsm.o\
		tarrec.o\
		tarslb.o\
		tarspharm.o\
		tartet.o\
		$(timeit).o\
		version.o\
		wrimsg.o\
		writebin.o\
		$(writenet).o\
		writesca.o

CALLTARGET.o:	CALLTARGET.f
		$(FC) $(FFLAGS) CALLTARGET.f -o CALLTARGET.o

#-----------------------------------------------------------------------------
# Most of the $(OBJS) modules can be compiled with the -u option on Sun.
# (The -u option requires that every variable type be declared explicitly).
# Only exceptions are the following routines:

cfft99f.o:	cfft99f.f
		$(FC) $(FFLAGSundecl) cfft99f.f
gpfa.o:		gpfa.f
		$(FC) $(FFLAGSundecl) gpfa.f -o gpfa.o
lapackslamc1.o: lapackslamc1.f
		$(FC) $(FFLAGSslamc1) lapackslamc1.f -o lapackslamc1.o
refwat.o:	refwat.f
		$(FC) $(FFLAGSundecl) refwat.f

#-----------------------------------------------------------------------------
# dependencies for calltarget:

SRCS2	      =	CALLTARGET.f \
		blas.f\
		errmsg.f\
		lapackslamc1.f\
		lapacksubs.f\
		prinaxis.f\
		reashp.f\
		sizer.f\
		tar2el.f\
		tar2sp.f\
		tar3el.f\
		tarblocks.f\
		tarcel.f\
		tarcyl.f\
		tarell.f\
		target.f\
		tarhex.f\
		tarnsp.f\
		tarprsm.f\
		tarrec.f\
		tarslb.f\
		tarspharm.f\
		tartet.f\
		wrimsg.f

OBJS2	      =	CALLTARGET.o \
		blas.o\
		errmsg.o\
		lapackslamc1.o\
		lapacksubs.o\
		prinaxis.o\
		reashp.o\
		sizer.o\
		tar2el.o\
		tar2sp.o\
		tar3el.o\
		tarblocks.o\
		tarcel.o\
		tarcyl.o\
		tarell.o\
		target.o\
		tarhex.o\
		tarnsp.o\
		tarprsm.o\
		tarrec.o\
		tarslb.o\
		tarspharm.o\
		tartet.o\
		wrimsg.o

all:		ddscat calltarget tstfft

ddscat:		$(OBJS) Makefile
		$(FC) $(OBJS) $(LDFLAGS) $(LIBFFTW) $(LIBNETCDF) \
		$(LINKNETCDF) -o ddscat


calltarget:	$(OBJS2) Makefile
		$(FC) $(OBJS2) $(LDFLAGS) -o calltarget

tstfft:		TSTFFT.o cfft99f.o cxfft3n.o cxfftw.o errmsg.o \
		fourx.o gpfa.o $(timeit).o wrimsg.o
		$(FC) \
		TSTFFT.o cfft99f.o cxfft3n.o cxfftw.o errmsg.o \
		fourx.o gpfa.o $(timeit).o wrimsg.o \
		$(LDFLAGS) $(LIBFFTW) -o tstfft


clean:;		rm -f *.o *.FOR make.out* *.lnt *.xrf *.tre

veryclean:	clean
		rm -f calltarget ddscat tstfft *~





