# ===============================================================
#  RTSOS – Radiative Transfer model based on Successive Orders of Scattering
#  Copyright (C) 2025  Pengwang Zhai
#
#  Licensed under the Creative Commons Attribution–NonCommercial 4.0
#  International License (CC BY-NC 4.0).
#  You may use, modify, and share this code for research and
#  educational purposes with proper attribution.
#  Commercial use requires written permission from the author.
#
#  Full license: https://creativecommons.org/licenses/by-nc/4.0/
#  Contact: Pengwang Zhai  |  [pwzhai@gmail.com]
# ===============================================================

OBJ=mathlib.o rttype_sos_rao_dg.o emis_sea.o SnowBRDF.o RossLiBRDF.o surface_glint.o Atmosphere_Profile.o Save_Ocean_Rad.o rtsos_rao_dg.o bessel.o rtspecfunc.o spher.o bfit.o deltafit.o aerosol_microphysical_model.o main_GSFC_AC_LUT.o

F90=gfortran
#F90=ifort
FCFLAG= -O3 -llapack -lblas
#FCFLAG=-real-size 64 -O3 -llapack -lblas
#FCFLAG= -g -fbounds-check -ffpe-trap=invalid,zero,overflow -finit-real=snan -llapack -lblas

HDF5DIR = /opt/homebrew/Cellar/hdf5/1.14.6/
HDF5LIB=-I$(HDF5DIR)/include
H5FC=$(HDF5DIR)/bin/h5fc
LIBSHDF= $(HDF5LIB) -L$(HDF5DIR)/lib/ -lhdf5 -lhdf5_fortran -lhdf5_hl_fortran

# cocco options
#HDF5INCLUDE=-I/usr/include/hdf5/serial/
#HDF5LIB=/usr/lib/x86_64-linux-gnu/
#LIBSHDF= $(HDF5INCLUDE) -L$(HDF5LIB) -lhdf5_serial -lhdf5_serial_fortran
#H5FC=h5fc

# Taki options
#HDF5DIR =
#HDF5LIB=
#H5FC=ifort
#LIBSHDF= -lhdf5 -lhdf5_fortran

DIRCore=../src/core/
DIRMain=../src/AC_Aerosols_LUT/

rtsos_GSFC_AC_LUT.exe: $(OBJ)
	$(F90) -o rtsos_GSFC_AC_LUT.exe $(FCFLAG) $(OBJ) $(LIBSHDF)
mathlib.o: $(DIRCore)/mathlib.f90
	 $(F90) -c $(FCFLAG) $(DIRCore)/mathlib.f90
rttype_sos_rao_dg.o: $(DIRCore)/rttype_sos_rao_dg.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/rttype_sos_rao_dg.f90
emis_sea.o:$(DIRCore)/emis_sea.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/emis_sea.f90
SnowBRDF.o:$(DIRCore)/SnowBRDF.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/SnowBRDF.f90
RossLiBRDF.o:$(DIRCore)/RossLiBRDF.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/RossLiBRDF.f90
surface_glint.o: $(DIRCore)/surface_glint.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/surface_glint.f90
Atmosphere_Profile.o: $(DIRCore)/Atmosphere_Profile.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/Atmosphere_Profile.f90
Save_Ocean_Rad.o: $(DIRCore)/Save_Ocean_Rad.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/Save_Ocean_Rad.f90
bessel.o:$(DIRCore)/bessel.f
	$(F90) -c $(FCFLAG) $(DIRCore)/bessel.f
rtspecfunc.o:$(DIRCore)/rtspecfunc.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/rtspecfunc.f90
rtsos_rao_dg.o: $(DIRCore)/rtsos_rao_dg.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/rtsos_rao_dg.f90
spher.o: $(DIRCore)/spher.f
	$(F90) -c $(FCFLAG) $(DIRCore)/spher.f
bfit.o: $(DIRCore)/bfit.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/bfit.f90
deltafit.o: $(DIRCore)/deltafit.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/deltafit.f90
aerosol_microphysical_model.o: $(DIRCore)/aerosol_microphysical_model.f90
	$(F90) -c $(FCFLAG) $(DIRCore)/aerosol_microphysical_model.f90

main_GSFC_AC_LUT.o: $(DIRMain)main_GSFC_AC_LUT.f90
	$(F90) -c $(FCFLAG) $(LIBSHDF) $(DIRMain)main_GSFC_AC_LUT.f90

clean:;       rm -f *.o *.exe
