########################################################################
# This Makefile can be used to build programs test_mcd_c and           #
# test_mcd_cpp, examples of C and C++ interfaces that use the fortran  #
# routines of the Mars Climate Database.                               #
# Before using it, you might have to change some of                    #
# the default definitions given below, namely:                         #
# - The path to your NetCDF installation directory (NETCDF_DIR)        #
# - The path to the fortran routines (call_mcd.F, julian.F and         #
#   heights.F) the interfaces will use (FROUTINES_DIR)                 #
# - The compiler names and options (FC, CC, CPP, FCOPT, CCOPT, CPPCOPT)#
# - The extra libraries (unfortunately extremely compiler dependent)   #
#   required to build the C end C++ interfaces (EXTRALIBS)             #
# See the user's guide for more information                            #
########################################################################
# Usage: (" > " is the Unix prompt in the examples given below)        #
# To build the C interface "test_mcd_c":                               #
# > make test_mcd_c                                                    #
# To build the C++ interface "test_mcd_cpp":                           #
# > make test_mcd_cpp                                                  #
# To build both:                                                       #
# > make                                                               #
########################################################################

# Path to (top directory of) NetCDF distribution 
NETCDF_DIR = /d2/emlmd/netcdf64-4.0.1_gfortran
#NETCDF_DIR = /d2/emlmd/netcdf64-4.0.1_pgi
# Path to the Fortan routines (call_mcd.F, julian.F and heights.F)
FROUTINES_DIR = .
# Fortran compiler 
FC = gfortran
#FC = pgf90
# Fortran compiler options
FCOPT = -O2
# C compiler
CC = gcc
#CC = pgcc
# C compiler options
CCOPT = -O2
# C++ compiler
CPPC = g++
#CPPC = pgCC
# C++ compiler options
CPPCOPT = -O2
# Extra libraries the C and C++ interfaces need
EXTRALIBS = -lgfortran # if FC = gfortran
#EXTRALIBS = -lpgf90 -lpgf90_rpm1 -lpgf902 -lpgf90rtl -lpgftnrtl -lrt # if FC = pgf90 and CC = pgcc
all:	test_mcd_c test_mcd_cpp

call_mcd.o:	$(FROUTINES_DIR)/call_mcd.F $(FROUTINES_DIR)/constants_mcd.inc heights.o
	$(FC) -c $(FROUTINES_DIR)/call_mcd.F -I$(NETCDF_DIR)/include -I$(FROUTINES_DIR) $(FCOPT)

julian.o:	$(FROUTINES_DIR)/julian.F
	$(FC) -c $(FROUTINES_DIR)/julian.F  $(FCOPT)

heights.o:	$(FROUTINES_DIR)/heights.F
	$(FC) -c $(FROUTINES_DIR)/heights.F -I$(NETCDF_DIR)/include $(FCOPT)
	
test_mcd_c: call_mcd.o julian.o test_mcd.c mcd.h
	$(CC) -o test_mcd_c call_mcd.o julian.o heights.o test_mcd.c -L$(NETCDF_DIR)/lib -lnetcdf $(EXTRALIBS) $(CCOPT)

test_mcd_cpp:	call_mcd.o julian.o test_mcd.cpp mcd.h
	$(CPPC) -o test_mcd_cpp call_mcd.o julian.o heights.o test_mcd.cpp -L$(NETCDF_DIR)/lib -lnetcdf $(EXTRALIBS) $(CPPCOPT)

clean:
	\rm -f call_mcd.o julian.o heights.o test_mcd.o test_mcd_c test_mcd_cpp
