# Makefile for "full" export version of DDSCAT.6.1

#--------- do NOT alter the following definitions: -------------------------
MPI_f   = mpi_subs.f \
	  mpi_bcast_char.f mpi_bcast_cplx.f mpi_bcast_int.f \
	  mpi_bcast_int2.f mpi_bcast_real.f
MPI_o	= mpi_subs.o \
	  mpi_bcast_char.o mpi_bcast_cplx.o mpi_bcast_int.o \
	  mpi_bcast_int2.o mpi_bcast_real.o
#---------------------------------------------------------------------------

#******************************************************************************
#
# 1. Compiler Definition
#    ===================
#    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
#
# 2. TIMEIT Definition
#    =================
#    TIMEIT defines the timeing routine, which depends on system calls
#    provided by the operating system.
#    use one of the following:
#	timeit_null (no timing results provided)
#	timeit_linux (if using Linux)
#	timeit_sun (if using Solaris)
#	timeit_hp
#	timeit_sgi
#	timeit_convex
#	timeit_ibm6000
#	timeit_osf
#	timeit_vms
#	timeit_cray
#	timeit_titan
#    
#----------------------Linux with g77, no MPI --------------------------------

FC		= g77 
FFLAGS		= -c -O
FFLAGSslamc1	= -c
TIMEIT		= timeit_linux
LDFLAGS 	=

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

#FC		= pgf77 -Msecond_underscore
#FFLAGS  	= -c -fast 
#FFLAGSslamc1	= -c
#LDFLAGS 	= -Bstatic 
#TIMEIT  	= timeit_linux

#----------------------- Linux ifc, no MPI ---------------------------------
# ifc = intel fortran compiler

#FC              = ifc
#FFLAGS          = -c -O3
#FFLAGSslamc1    = -c
#LDFLAGS         = -Vaxlib
#TIMEIT          = timeit_linux

#********************* Linux pgf77 with MPI support **************************
#                      (this may be site-dependent)

# 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		= mpif77
#FFLAGS  	= -c -fast 
#FFLAGSslamc1	= -c
#LDFLAGS 	= -Bstatic 
#TIMEIT          = timeit_linux

#********************* Linux ifc77 with MPI support **************************

# mpif77 = shell script to invoke pgf77 compiler with appropriate
#          options to support MPI
# 2004.04.09: this compiles and links on hydra, but
#             execution fails with strange error message
# 2004.04.10: source /usr/local/bin/switch-ifc.sh
# this set following enivronmental variables:
# LD_LIBRARY_PATH
# CC=icc
# F77=ifc
# F90=ifc
# IA32ROOT=/usr/peyton/intel/compiler70/ia32
# MPICH=/opt/mpich-1.2.4

# also replaced previous mpif.h with /opt/mpich-1.2.4/include/mpif.h

#LD_LIBRARY_PATH        =/usr/peyton/intel/compiler70/ia32/lib:/usr/peyton/intel/compiler70/ia32/lib
#FC             = mpif77 -fc=ifc
#MPICH_F                = ifc
#MPICH_F77LINKER        = ifc
#FFLAGS         =
#FFLAGSslamc1   =
#TIMEIT          = timeit_linux

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

#FC		= f77
#FFLAGS		= -c -fast
#FFLAGSslamc1	= -c
#LDFLAGS	=
#TIMEIT		= timeit_osf

#************************* Sun fortran, no MPI *********************************

#FC		= f77
#FFLAGS		= -fast 
#FFLAGSslamc1	= -c
#LDFLAGS	= -fast -O3
#TIMEIT		= timeit_sun

#********************** AIX fortran on RS6000, no MPI *************************

#FC		= xlf
#FFLAGS		= -O
#FFLAGSslamc1	= -c
#LDFLAGS 	= -O
#TIMEIT		= timeit_ibm6000

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

#FC		= f77
#FFLAGS		= -mips2 -O2
#FFLAGSslamc1	= -c
#LDFLAGS	= -mips2 -O2
#TIMEIT		= timeit_sgi

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

#FC		= f77
#FFLAGS		= -mips4 -O2
#FFLAGSslamc1	= -c
#LDFLAGS	= -mips4 -O2
#TIMEIT		= timeit_sgi

#********************** HP AUX, no MPI ****************************************

#FC		= f77
#FFLAGS		= -O3 -c
#FFLAGSslamc1	= -c
#LDFLAGS	=
#TIMEIT		= timeit_hp

#******************************************************************************
#
# 3. MPI support 
#
#    Module DDSCAT.f require very minor editing to prepare it for
#    either non-MPI use or use on a system with MPI support.
#    Consult either the UserGuide (section 24.1) or comments within DDSCAT.f
#    for instructions on which line needs to be enabled
#    and which line needs to be commented out.
#
#    If MPI support is desired and MPI library is installed, uncomment 
#    the following two definitions (and comment out the definitions in terms
#    of mpi_fake.f and mpi_fake.o below):

#MPI.f	= $(MPI_f)
#MPI.o	= $(MPI_o)

#    if MPI support is not required, comment out the above two definitions
#    and uncomment the following:

MPI.f	= mpi_fake.f
MPI.o	= mpi_fake.o

#******************************************************************************
#
# 4. FFTW support.
#
#
#    Note: DDSCAT can use the FFTW package of Frigo and Johnson.
#    If the FFTW package is not installed on system, then uncomment
#    following definitions:

CXFFTW		= cxfftw_fake
LIBFFTW 	=

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

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


#******************************************************************************
#
# 5. Convex native FFT support

#    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 	= cxc3dfft_fake

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

#CXC3DFFT 	= cxc3dfft

#******************************************************************************
#
# 6. netCDF library support

# 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      = writenet_fake
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

#******************************************************************************
#
#                  End of option specifications.
#      User should not need to edit the Makefile below this point
#
#******************************************************************************

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\
		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\
		taranirec.f\
		tarblocks.f\
		tarcel.f\
		tarcyl.f\
		tarcylcap.f\
		tarell.f\
		target.f\
		targspher_fake.f\
		tarhex.f\
		tarnsp.f\
		tarprsm.f\
		tarrec.f\
		tarslb.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\
		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\
		taranirec.o\
		tarblocks.o\
		tarcel.o\
		tarcyl.o\
		tarcylcap.o\
		tarell.o\
		target.o\
		targspher_fake.o\
		tarhex.o\
		tarnsp.o\
		tarprsm.o\
		tarrec.o\
		tarslb.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.
# Only exceptions are the following routines:

lapackslamc1.o: lapackslamc1.f
		$(FC) $(FFLAGSslamc1) lapackslamc1.f -o lapackslamc1.o

#-----------------------------------------------------------------------------
# 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\
		taranirec.f\
		tarblocks.f\
		tarcel.f\
		tarcyl.f\
		tarcylcap.f\
		tarell.f\
		target.f\
		targspher_fake.f\
		tarhex.f\
		tarnsp.f\
		tarprsm.f\
		tarrec.f\
		tarslb.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\
		taranirec.o\
		tarblocks.o\
		tarcel.o\
		tarcyl.o\
		tarcylcap.o\
		tarell.o\
		target.o\
		targspher_fake.o\
		tarhex.o\
		tarnsp.o\
		tarprsm.o\
		tarrec.o\
		tarslb.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

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

veryclean:	clean
		rm -f calltarget ddscat tstfft *~
