#! GNU Makefile for Pégase.3.0.1 (2019-02-21).

#!======================================================================
#! Fortran compiler:
COMPILER = gfortran
#COMPILER = ifort
#! (If you change the compiler, run first `make clean`, then `make`.)

#!======================================================================
#! Fortran version:
VERSION = 95

#!======================================================================
#! Executables produced by the compilation:
all:	license_message \
	changed_Makefile \
	final_message \
	SSPs \
	spectra \
	colors \
	calib \
	plot_spectra \
	plot_grain_temp \
	plot_grain_SED


#!======================================================================
#! Path to search for files:
vpath %.f90 ../source_dir:../util_dir

#!======================================================================
ifeq ($(COMPILER), ifort)
#! Compilation directives:
	OPTIONS = -fp-model precise \
		-check bounds \
		-check overflow \
		-warn declarations \
		-check uninit \
		-warn argument_checking \
		-warn uninitialized \
		-warn usage \
		-implicitnone \
		-warn uncalled \
		-warn unused \
		-vec-report0 \
		-warn all

#! Compilation directive specifying the Fortran version:
	STANDARD = -std$(VERSION) #! Not used for "plot*" executables because pgplot \
#! routines are not compliant with the standard.

#! Link with the PGPLOT graphic library:
	PGPLOT_LIB = -L /usr/local/pgplot_ifort -lpgplot -shared-intel -L /usr/lib -lX11

else ifeq ($(COMPILER), gfortran)
#! Note:
#! Altough the "delim" specifier is authorized in an "open" statement 
#! in Fortran 95, option "-std=f95" of gfortran leads to this error:
#!
#! 	Error: Fortran 2003: DELIM= at (1) not allowed in Fortran 95
#!
#! No error however in an "inquire" statement.

#! Compilation directives:
	OPTIONS = -fimplicit-none \
		-pedantic \
		-Wall \
		-Wextra \
		-finit-local-zero \
		-fbounds-check \
		-O2 

#! Compilation directive specifying the Fortran version:
	STANDARD = -std=f$(VERSION) #! Not used for "plot*" executables because pgplot \
#! routines are not compliant with the standard.

#! Link with the PGPLOT graphic library:
	PGPLOT_LIB = -lm -L /usr/local/pgplot_gf -lpgplot -L /usr/lib -lX11 -std=legacy

else #! For another compiler.

	OPTIONS = #! Compilation directives.

	STANDARD = #! Compilation directive imposing a strict interpretation of the Fortran standard $(VERSION).

	PGPLOT_LIB = #! Link with the PGPLOT graphic library.

endif

#!======================================================================
#! Objects files:

plot%.o: plot%.f90

	@ echo "\nCompiling \"$<\"."
#	@ $(COMPILER) $(OPTIONS) -std=legacy -o $@ -c $<
	@ $(COMPILER) $(OPTIONS) -o $@ -c $<

%.o: %.f90

	@ echo "\nCompiling \"$<\"."
	@ $(COMPILER) $(OPTIONS) $(STANDARD) -o $@ -c $<

mod_constants.o: mod_types.o

mod_spectra_constants.o: mod_types.o

mod_linked_list.o: mod_types.o

mod_SSPs_constants.o: mod_types.o

mod_file_access.o: mod_strings.o mod_types.o mod_dir_access.o

mod_directories.o: mod_dir_access.o

mod_convert_type.o: mod_types.o mod_strings.o

mod_random.o: mod_types.o

mod_read_file_list.o: mod_types.o mod_file_access.o mod_convert_type.o \
	mod_remove_duplicates.o mod_linked_list.o

mod_remove_duplicates.o: mod_heap_index.o

mod_select_file.o: mod_types.o mod_read_file_list.o mod_file_access.o \
	mod_convert_type.o mod_strings.o mod_linked_list.o

mod_interp.o: mod_types.o 

mod_IMF.o: mod_types.o mod_directories.o mod_file_access.o mod_interp.o \
	mod_select_file.o mod_SSPs_constants.o

mod_stel_lib.o: mod_types.o mod_directories.o mod_file_access.o \
	mod_SSPs_constants.o

mod_tracks.o: mod_types.o mod_directories.o mod_interp.o mod_file_access.o 

mod_read_abundances.o: mod_types.o mod_file_access.o mod_linked_list.o

mod_yields.o: mod_types.o mod_directories.o mod_file_access.o \
	mod_read_abundances.o mod_interp.o mod_IMF.o mod_constants.o \
	mod_loc.o mod_SSPs_constants.o

mod_isochrone.o: mod_interp.o mod_types.o mod_tracks.o

mod_remnants_ejecta_SN.o: mod_IMF.o mod_types.o mod_interp.o \
	mod_SSPs_constants.o

mod_SSP_emission.o: mod_IMF.o mod_stel_lib.o mod_types.o \
	mod_SSPs_constants.o mod_isochrone.o

mod_SSPs_ages.o: mod_types.o mod_file_access.o mod_directories.o \
	mod_linked_list.o

mod_spectra_ages.o: mod_types.o mod_directories.o mod_file_access.o \
	mod_linked_list.o

mod_nebular.o: mod_types.o mod_directories.o mod_constants.o \
	mod_file_access.o mod_interp.o mod_heap_index.o mod_scenario.o

mod_RT.o: mod_types.o mod_directories.o mod_file_access.o mod_interp.o 

mod_grain_properties.o: mod_types.o mod_directories.o mod_constants.o \
	mod_spectra_constants.o mod_file_access.o mod_interp.o \
	mod_strings.o mod_interm_grid.o

mod_read_SSPs.o: mod_types.o mod_directories.o mod_file_access.o \
	mod_constants.o mod_read_dust_evol_param.o mod_convert_type.o \
	mod_stel_lib.o mod_linked_list.o mod_constants.o

mod_analyze_statement.o: mod_strings.o mod_types.o mod_convert_type.o

mod_parse_file.o: mod_types.o mod_strings.o mod_file_access.o \
	mod_analyze_statement.o mod_convert_type.o

mod_read_columns.o: mod_types.o mod_file_access.o mod_linked_list.o

mod_spectra_default_param.o: mod_types.o

mod_read_SF_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_constants.o mod_strings.o mod_directories.o \
	mod_read_columns.o mod_convert_type.o mod_spectra_default_param.o

mod_read_reserv_infall_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_constants.o mod_strings.o mod_directories.o \
	mod_read_columns.o mod_convert_type.o mod_spectra_default_param.o

mod_read_outflow_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_constants.o mod_strings.o mod_directories.o \
	mod_read_columns.o mod_convert_type.o mod_spectra_default_param.o

mod_read_dust_evol_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_default_param.o

mod_read_dust_transfer_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_default_param.o

mod_read_cloud_neb_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_default_param.o

mod_read_other_param.o: mod_types.o mod_analyze_statement.o \
	mod_parse_file.o mod_random.o mod_spectra_default_param.o 

mod_read_output_param.o: mod_types.o mod_analyze_statement.o \
	mod_spectra_default_param.o mod_linked_list.o

mod_scenario.o: mod_types.o mod_constants.o mod_analyze_statement.o \
	mod_parse_file.o mod_read_SF_param.o \
	mod_read_reserv_infall_param.o mod_read_outflow_param.o \
	mod_read_dust_evol_param.o mod_read_dust_transfer_param.o \
	mod_read_cloud_neb_param.o mod_strings.o mod_read_other_param.o \
	mod_read_output_param.o mod_write_scenario_param.o mod_random.o \
	mod_read_cosmo_param.o

mod_initialization.o: mod_scenario.o mod_constants.o \
	mod_spectra_constants.o mod_loc.o

mod_evolution.o: mod_types.o mod_interp.o mod_scenario.o mod_loc.o \
	mod_constants.o mod_random.o

mod_SFC_DISM.o: mod_types.o mod_interp.o mod_extinction.o \
	mod_RT.o mod_constants.o mod_spectra_constants.o \
	mod_grain_properties.o mod_scenario.o

mod_extinction.o: mod_types.o mod_interp.o mod_constants.o \
	mod_spectra_constants.o mod_RT.o mod_black_body.o \
	mod_read_dust_transfer_param.o mod_grain_properties.o mod_scenario.o

mod_compute_various.o: mod_types.o mod_constants.o 

mod_loc.o: mod_types.o 

mod_black_body.o: mod_types.o mod_constants.o 

mod_dust_emission.o: mod_types.o mod_constants.o mod_spectra_constants.o \
	mod_interp.o mod_loc.o mod_black_body.o mod_file_access.o \
	mod_strings.o mod_interm_grid.o mod_directories.o \
	mod_read_output_param.o mod_grain_properties.o mod_linked_list.o \
	mod_convert_type.o

mod_intersperse.o: mod_types.o

mod_convert_type.o: mod_types.o

mod_write_scenario_param.o: mod_types.o mod_strings.o mod_convert_type.o \
	mod_read_SF_param.o mod_read_reserv_infall_param.o \
	mod_read_outflow_param.o mod_read_dust_evol_param.o \
	mod_read_dust_transfer_param.o mod_read_cloud_neb_param.o \
	mod_read_other_param.o mod_read_output_param.o \
	mod_read_cosmo_param.o mod_linked_list.o mod_parse_file.o

mod_write_spectra_output.o: mod_types.o mod_convert_type.o mod_strings.o \
	mod_constants.o mod_grain_properties.o mod_write_scenario_param.o \
	mod_code_version.o mod_compiler.o mod_linked_list.o

mod_read_abundances.o: mod_types.o mod_file_access.o 

mod_read_spectra_output.o: mod_types.o mod_file_access.o mod_directories.o

mod_interm_grid.o: mod_types.o

mod_process_file_name.o: mod_file_access.o mod_strings.o mod_convert_type.o

mod_spectra_alloc.o: mod_types.o mod_scenario.o

mod_read_grain_temp.o: mod_types.o mod_file_access.o mod_directories.o

mod_read_grain_SED.o: mod_types.o mod_file_access.o mod_directories.o

mod_filters_constants.o: mod_types.o

mod_filters.o: mod_types.o mod_directories.o mod_interp.o \
	mod_linked_list.o mod_filters_constants.o mod_file_access.o

mod_colors.o: mod_types.o mod_linked_list.o

mod_magnit.o: mod_types.o mod_hash.o mod_colors.o mod_filters_constants.o

mod_compiler.o: mod_types.o

mod_calib.o: mod_convert_type.o mod_types.o

mod_read_cosmo_param.o: mod_types.o mod_analyze_statement.o

mod_cosmo.o: mod_types.o mod_read_cosmo_param.o mod_constants.o

SSPs.o: mod_types.o \
	mod_strings.o \
	mod_convert_type.o \
	mod_directories.o \
	mod_select_file.o \
	mod_read_file_list.o \
	mod_constants.o \
	mod_SSPs_constants.o \
	mod_IMF.o \
	mod_stel_lib.o \
	mod_tracks.o \
	mod_yields.o \
	mod_isochrone.o \
	mod_remnants_ejecta_SN.o \
	mod_SSP_emission.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_interp.o \
	mod_SSPs_ages.o \
	mod_compiler.o \
	mod_ISO_8601.o 

spectra.o: mod_types.o \
	mod_directories.o \
	mod_constants.o \
	mod_spectra_constants.o \
	mod_stel_lib.o \
	mod_spectra_ages.o \
	mod_nebular.o \
	mod_RT.o \
	mod_grain_properties.o \
	mod_read_SSPs.o \
	mod_initialization.o \
	mod_evolution.o \
	mod_SFC_DISM.o \
	mod_extinction.o \
	mod_compute_various.o \
	mod_write_spectra_output.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_dust_emission.o \
	mod_write_scenario_param.o \
	mod_intersperse.o \
	mod_interp.o \
	mod_read_other_param.o \
	mod_read_output_param.o \
	mod_scenario.o \
	mod_parse_file.o \
	mod_strings.o \
	mod_convert_type.o \
	mod_read_abundances.o \
	mod_ISO_8601.o \
	mod_select_file.o \
	mod_read_file_list.o \
	mod_interm_grid.o \
	mod_process_file_name.o \
	mod_spectra_alloc.o \
	mod_compiler.o \
	mod_read_cosmo_param.o

calib.o: mod_types.o \
	mod_directories.o \
	mod_file_access.o \
	mod_constants.o \
	mod_filters_constants.o \
	mod_filters.o \
	mod_calib.o \
	mod_strings.o \
	mod_convert_type.o \
	mod_heap_index.o \
	mod_code_version.o \
	mod_compiler.o \
	mod_ISO_8601.o 

colors.o: mod_types.o \
	mod_directories.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_constants.o \
	mod_read_spectra_output.o \
	mod_select_file.o \
	mod_read_file_list.o \
	mod_interp.o \
	mod_filters_constants.o \
	mod_filters.o \
	mod_colors.o \
	mod_convert_type.o \
	mod_hash.o \
	mod_magnit.o \
	mod_strings.o \
	mod_code_version.o \
	mod_compiler.o \
	mod_ISO_8601.o \
	incl_colors.f90

plot_spectra.o: mod_read_spectra_output.o \
	mod_types.o mod_directories.o \
	mod_select_file.o \
	mod_constants.o \
	mod_convert_type.o \
	mod_interp.o

plot_grain_temp.o: mod_read_grain_temp.o \
	mod_strings.o \
	mod_types.o \
	mod_directories.o \
	mod_select_file.o \
	mod_constants.o

plot_grain_SED.o: mod_read_grain_SED.o \
	mod_strings.o \
	mod_types.o \
	mod_directories.o \
	mod_select_file.o \
	mod_constants.o

#!======================================================================
#! Executables:

SSPs: 	mod_types.o \
	mod_convert_type.o \
	mod_strings.o \
	mod_directories.o \
	mod_strings.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_read_file_list.o \
	mod_linked_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o \
	mod_select_file.o \
	mod_constants.o \
	mod_SSPs_constants.o \
	mod_interp.o \
	mod_IMF.o \
	mod_stel_lib.o \
	mod_tracks.o \
	mod_read_abundances.o \
	mod_loc.o \
	mod_yields.o \
	mod_isochrone.o \
	mod_remnants_ejecta_SN.o \
	mod_SSP_emission.o \
	mod_SSPs_ages.o \
	mod_compiler.o \
	mod_code_version.o \
	mod_ISO_8601.o \
	SSPs.o

	@ echo "\nCompiling \"SSPs\"."

	@ $(COMPILER) $(OPTIONS) $(STANDARD) -o $@ $^

	@ - echo "\"$(COMPILER)\" ! Compiler." > compil_SSPs.txt
	@ - echo "\"$(VERSION)\" ! Fortran version." >> compil_SSPs.txt
	@ - echo "\"$(OPTIONS) $(STANDARD)\" ! Compilation options." >> compil_SSPs.txt
	@ echo "\n======================================================================"

spectra: mod_types.o \
	mod_linked_list.o \
	mod_directories.o \
	mod_constants.o \
	mod_spectra_constants.o \
	mod_strings.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_stel_lib.o \
	mod_spectra_ages.o \
	mod_interp.o \
	mod_nebular.o \
	mod_RT.o \
	mod_grain_properties.o \
	mod_read_SSPs.o \
	mod_analyze_statement.o \
	mod_parse_file.o \
	mod_read_columns.o \
	mod_random.o \
	mod_spectra_default_param.o \
	mod_read_SF_param.o \
	mod_read_reserv_infall_param.o \
	mod_read_outflow_param.o \
	mod_read_dust_evol_param.o \
	mod_read_dust_transfer_param.o \
	mod_read_cloud_neb_param.o \
	mod_read_other_param.o \
	mod_read_output_param.o \
	mod_scenario.o \
	mod_initialization.o \
	mod_evolution.o \
	mod_SFC_DISM.o \
	mod_extinction.o \
	mod_compute_various.o \
	mod_loc.o \
	mod_black_body.o \
	mod_dust_emission.o \
	mod_convert_type.o \
	mod_write_scenario_param.o \
	mod_write_spectra_output.o \
	mod_intersperse.o \
	mod_read_abundances.o \
	mod_ISO_8601.o \
	mod_select_file.o \
	mod_read_file_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o \
	mod_interm_grid.o \
	mod_process_file_name.o \
	mod_spectra_alloc.o \
	mod_code_version.o \
	mod_compiler.o \
	mod_read_cosmo_param.o \
	mod_cosmo.o \
	spectra.o

	@ echo "\nCompiling \"spectra\"."

	@ $(COMPILER) $(OPTIONS) $(STANDARD) -o $@ $^

	@ - echo "\"$(COMPILER)\" ! Compiler." > compil_spectra.txt
	@ - echo "\"$(VERSION)\" ! Fortran version." >> compil_spectra.txt
	@ - echo "\"$(OPTIONS) $(STANDARD)\" ! Compilation options." >> compil_spectra.txt
	@ echo "\n======================================================================"

calib: 	mod_types.o \
	mod_linked_list.o \
	mod_directories.o \
	mod_strings.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_interp.o \
	mod_constants.o \
	mod_filters_constants.o \
	mod_filters.o \
	mod_convert_type.o \
	mod_heap_index.o \
	mod_calib.o \
	mod_strings.o \
	mod_code_version.o \
	mod_compiler.o \
	mod_ISO_8601.o \
	calib.o

	@ echo "\nCompiling \"calib\"."

	@ $(COMPILER) $(OPTIONS) $(STANDARD) -o $@ $^

	@ - echo "\"$(COMPILER)\" ! Compiler." > compil_calib.txt
	@ - echo "\"$(VERSION)\" ! Fortran version." >> compil_calib.txt
	@ - echo "\"$(OPTIONS) $(STANDARD)\" ! Compilation options." >> compil_calib.txt
	@ echo "\n======================================================================"

../calib_dir/calib.txt: ../calib_dir/list_filters.txt calib

	@ echo "\nRunning \"calib\"."

	@ ./calib

colors: mod_types.o \
	mod_linked_list.o \
	mod_directories.o \
	mod_strings.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_interp.o \
	mod_constants.o \
	mod_read_spectra_output.o \
	mod_select_file.o \
	mod_read_file_list.o \
	mod_linked_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o \
	mod_interp.o \
	mod_filters_constants.o \
	mod_filters.o \
	mod_colors.o \
	mod_convert_type.o \
	mod_hash.o \
	mod_magnit.o \
	mod_strings.o \
	mod_code_version.o \
	mod_compiler.o \
	mod_ISO_8601.o \
	../calib_dir/calib.txt \
	incl_colors.f90 \
	colors.o

	@ echo "\nCompiling \"colors\"."

	@ $(COMPILER) $(OPTIONS) $(STANDARD) -o $@ $(filter %.o, $^)

	@ - echo "\"$(COMPILER)\" ! Compiler." > compil_colors.txt
	@ - echo "\"$(VERSION)\" ! Fortran version." >> compil_colors.txt
	@ - echo "\"$(OPTIONS) $(STANDARD)\" ! Compilation options." >> compil_colors.txt
	@ echo "\n======================================================================"

plot_spectra: plot_spectra.o \
	mod_convert_type.o \
	mod_read_file_list.o \
	mod_linked_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o \
	mod_select_file.o \
	mod_strings.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_types.o \
	mod_constants.o \
	mod_directories.o \
	mod_interp.o \
	mod_read_spectra_output.o

	@ echo "\nCompiling \"plot_spectra\"."
	@ echo "Requires the PGPLOT graphic library."

	@ - $(COMPILER) $(OPTIONS) -o $@ $^ $(PGPLOT_LIB)
	@ echo "\n======================================================================"

plot_grain_temp: plot_grain_temp.o \
	mod_read_grain_temp.o \
	mod_types.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_strings.o \
	mod_directories.o \
	mod_select_file.o \
	mod_constants.o \
	mod_read_file_list.o \
	mod_linked_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o

	@ echo "\nCompiling \"plot_grain_temp\"."
	@ echo "Requires the PGPLOT graphic library."

	@ - $(COMPILER) $(OPTIONS) -o $@ $^ $(PGPLOT_LIB)
	@ echo "\n======================================================================"

plot_grain_SED: plot_grain_SED.o \
	mod_read_grain_SED.o \
	mod_types.o \
	mod_file_access.o \
	mod_dir_access.o \
	mod_strings.o \
	mod_directories.o \
	mod_select_file.o \
	mod_constants.o \
	mod_read_file_list.o \
	mod_linked_list.o \
	mod_remove_duplicates.o \
	mod_heap_index.o

	@ echo "\nCompiling \"plot_grain_SED\"."
	@ echo "Requires the PGPLOT graphic library."

	@ - $(COMPILER) $(OPTIONS) -o $@ $^ $(PGPLOT_LIB)

#!======================================================================
license_message:

	@ echo "\nCompiling code Pégase.3.0.1 (*), version dated 2019-02-21."
	@ echo "\nThis software is copyleft. See the header \
	of any of the Fortran source files \nand the text of the CeCILL \
	license in directory \"doc_dir/\" for details."
	@ echo "__________________"
	@ echo "(*) In UTF-8. If it looks garbled, \"Pégase\" = \"P\\'egase\" in TeX."
	@ echo "\n\n\t\t\t\t*       *\n\n\n"
	@ echo "\t\t\t\t*       *\n"
	@ echo "\nPress the <RETURN>/<ENTER> key to proceed."
	@ read whatever

#!======================================================================
final_message:

	@ echo "\n\t\t\t\t*       *\n\n\n"
	@ echo "\t\t\t\t*       *\n\n"

#!======================================================================
changed_Makefile: Makefile

	@ echo "\nFile \"Makefile\" seems to have changed since last compilation. \
	You may need \nto execute \`make clean\` first.\n"

#!======================================================================
#! Cleaning instructions:

clean: 
	rm -f *.o *.mod

	@ touch changed_Makefile
