# Makefile for Fortran 90/95 programs to manipulate SIR files
# written by D. Long Mar. 2017
#
# be sure to manually edit lib/SIR.nc to reflect machine/compiler type
# prior to running.  Also, check to compile statement below to include
# or not include the SIREZ routines
#

# uses code from the fortran 77 library for read/writing SIR files
# and doing geometric computations

#*****************************************************************************
# Uncomment next 2 lines if using SUN solaris machine.  Also edit lib/SIR.inc
#*****************************************************************************
#FF		=	f90
#FFLAGS		=	-e -Ilib -I../f/lib -libmil -native -O'	# (compiler issues)

#*****************************************************************************
# Uncomment next 2 lines if using SGI machine.  Also edit lib/SIR.inc
#*****************************************************************************
#FF		=	f90
#FFLAGS		=	-static -Ilib -I../f/lib

#*****************************************************************************
# Uncomment next 2 lines if using HP machine.  Also edit lib/SIR.inc
#*****************************************************************************
#FF		=	f90
#FFLAGS		=	-Ilib -I../f/lib -K +gformat77 +es +DAportable

#*****************************************************************************
# Uncomment next 2 lines if using Lahey f95 for linux. Also edit lib/SIR.inc
#*****************************************************************************
#FF		=	lf95
#FFLAGS		=	-Ilib -I../f/lib --wide --mldefault cdecl --sav

#*****************************************************************************
# Uncomment next 2 lines if using pathscale for linux. Also edit lib/SIR.inc
#*****************************************************************************
#FF		=	pathf95
#FFLAGS		=	-Ilib -I../f/lib -m64 -extend-source -static-data -O3

#*****************************************************************************
# Uncomment next 2 lines if using gfortran for linux. Also edit lib/SIR.inc
#*****************************************************************************
FF		=	gfortran
FFLAGS		=	-Ilib -I../f/lib -ff2c -m64 -O -ffixed-line-length-none

EXES = libfsirf_f90.a f90sirexample fsir_locmap
LDFLAGS = -L. -lfsirf_f90

all : $(EXES) libfsirf_f90.a

.PHONY: all clean 

f90sirexample : f90sirexample.f90 libfsirf_f90.a
	$(FF) $(FFLAGS) -o f90sirexample f90sirexample.f90 $(LDFLAGS)

fsir_locmap : fsir_locmap.f90 libfsirf_f90.a
	$(FF) $(FFLAGS) -o fsir_locmap fsir_locmap.f90 $(LDFLAGS)

# source includes .f files from f77 library plus .f90 files
LIBSRC = ../f/lib/arctand.f ../f/lib/easegrid.f ../f/lib/f2ipix.f  \
	../f/lib/ieasegrid.f ../f/lib/ease2grid.f ../f/lib/iease2grid.f \
	../f/lib/ease2_map_info.f ../f/lib/ease2sf.f \
	../f/lib/easeconv_normalize_degrees.f ../f/lib/ilambert1.f \
	../f/lib/ipolster.f ../f/lib/lambert1.f ../f/lib/latlon2pix.f \
	../f/lib/pix2latlon.f ../f/lib/polster.f ../f/lib/length.f \
	../f/lib/length1.f ../f/lib/printhead.f \
	../f/lib/printhead3.f ../f/lib/readsirf.f ../f/lib/readsirhead.f \
	../f/lib/readsirhead3.f ../f/lib/swapbuf.f ../f/lib/writesir.f \
	../f/lib/writesir3.f ../f/lib/sirupdate.f \
	../f/lib/readsirf_block.f \
	lib/SIREZ_f90.f90 lib/LENGTH1.f90 lib/YESNO1.f90

libfsirf_f90.a : $(LIBSRC)
	rm -f *.o libfsirf.a
	$(FF) $(FFLAGS) -c $(LIBSRC)
	ar cr libfsirf_f90.a *.o
	rm -f *.o *.B *.s

clean :
	rm -f $(EXES) *.o *.B *.s libfsirf_f90.a

