Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions colors/defaults/colors.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
colors_results_directory = 'SED'
mag_system = 'Vega'
sed_per_model = .false.
photo_precompute = .false.

color_num_files = 2
color_file_names(1) = 'lcb98cor.dat'
color_num_colors(1) = 11
color_file_names(2) = 'blackbody_johnson.dat'
color_num_colors(2) = 5



! ``z_over_x_ref``
Expand Down
4 changes: 2 additions & 2 deletions colors/make/makefile_base
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ include $(MESA_DIR)/utils/makefile_header

SRCS = \
colors_def.f90 \
mod_colors.f90 \
colors_ctrls_io.f90 \
colors_history.f90 \
colors_def.f90 \
hermite_interp.f90 \
knn_interp.f90 \
linear_interp.f90 \
colors_utils.f90 \
bolometric.f90 \
synthetic.f90 \
colors_lib.f90

#################################################################
#
# LIBRARIES
Expand Down
21 changes: 20 additions & 1 deletion colors/private/colors_ctrls_io.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module colors_ctrls_io

use const_def, only: dp, strlen, max_extra_inlists
use colors_def, only: Colors_General_Info, get_colors_ptr
use colors_def, only: Colors_General_Info, get_colors_ptr, max_num_color_files

implicit none

Expand All @@ -43,6 +43,13 @@ module colors_ctrls_io
logical :: sed_per_model
logical :: use_colors

!photometric pre compute
logical :: photo_precompute
integer :: color_num_files
integer, dimension(max_num_color_files) :: color_num_colors
character(len=256), dimension(max_num_color_files) :: color_file_names


namelist /colors/ &
instrument, &
vega_sed, &
Expand All @@ -53,6 +60,10 @@ module colors_ctrls_io
sed_per_model, &
mag_system, &
colors_results_directory, &
photo_precompute, &
color_num_files, &
color_num_colors, &
color_file_names, &
use_colors, &
read_extra_colors_inlist, &
extra_colors_inlist_name
Expand Down Expand Up @@ -161,6 +172,10 @@ subroutine store_controls(rq, ierr)
rq%make_csv = make_csv
rq%sed_per_model = sed_per_model
rq%colors_results_directory = colors_results_directory
rq%photo_precompute = photo_precompute
rq%color_num_files = color_num_files
rq%color_num_colors = color_num_colors
rq%color_file_names = color_file_names
rq%use_colors = use_colors
rq%mag_system = mag_system

Expand Down Expand Up @@ -199,6 +214,10 @@ subroutine set_controls_for_writing(rq)
make_csv = rq%make_csv
sed_per_model = rq%sed_per_model
colors_results_directory = rq%colors_results_directory
photo_precompute = rq%photo_precompute
color_num_files = rq%color_num_files
color_num_colors = rq%color_num_colors
color_file_names = rq%color_file_names
use_colors = rq%use_colors
mag_system = rq%mag_system

Expand Down
188 changes: 115 additions & 73 deletions colors/private/colors_history.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

module colors_history

use const_def, only: dp
use const_def, only: dp, mbolsun, Teffsun, rsun
use utils_lib, only: mesa_error
use colors_def, only: Colors_General_Info, get_colors_ptr, num_color_filters, color_filter_names
use colors_utils, only: remove_dat, resolve_path
use bolometric, only: calculate_bolometric
use synthetic, only: calculate_synthetic
use mod_colors, only: Eval_Colors, thead_all, num_thead, lgt_list, max_num_bcs_per_file

implicit none

Expand Down Expand Up @@ -55,20 +56,24 @@ end function how_many_colors_history_columns
subroutine data_for_colors_history_columns( &
t_eff, log_g, R, metallicity, model_number, &
colors_handle, n, names, vals, ierr)
use const_def, only: mbolsun, Teffsun, rsun
use mod_colors, only: Eval_Colors, thead_all, num_thead, lgt_list, max_num_bcs_per_file
real(dp), intent(in) :: t_eff, log_g, R, metallicity
integer, intent(in) :: colors_handle, n
character(len=80) :: names(n)
real(dp) :: vals(n)
integer, intent(out) :: ierr
integer, intent(in) :: model_number

type(Colors_General_Info), pointer :: cs ! colors_settings
integer :: i, filter_offset
type(Colors_General_Info), pointer :: cs
integer :: i, j, k, filter_offset
real(dp) :: d, bolometric_magnitude, bolometric_flux, interpolation_radius
real(dp) :: zero_point
real(dp) :: zero_point, lum
character(len=256) :: sed_filepath
character(len=80) :: filter_name
logical :: make_sed
real(dp), dimension(max_num_bcs_per_file) :: bcs
type(lgt_list), pointer :: thead

real(dp), dimension(:), allocatable :: wavelengths, fluxes

Expand All @@ -79,78 +84,115 @@ subroutine data_for_colors_history_columns( &
return
end if

! verify data was loaded at initialization
if (.not. cs%lookup_loaded) then
write (*, *) 'colors error: lookup table not loaded'
ierr = -1
return
end if
if (.not. cs%filters_loaded) then
write (*, *) 'colors error: filter data not loaded'
ierr = -1
return
end if

d = cs%distance
sed_filepath = trim(resolve_path(cs%stellar_atm))
make_sed = cs%make_csv

call calculate_bolometric(cs, t_eff, log_g, metallicity, R, d, &
bolometric_magnitude, bolometric_flux, wavelengths, fluxes, &
sed_filepath, interpolation_radius)

names(1) = "Mag_bol"
vals(1) = bolometric_magnitude
names(2) = "Flux_bol"
vals(2) = bolometric_flux
names(3) = "Interp_rad"
vals(3) = interpolation_radius
filter_offset = 3

if (n == num_color_filters + filter_offset) then
do i = 1, num_color_filters
filter_name = trim(remove_dat(color_filter_names(i)))
names(i + filter_offset) = filter_name

! Negative [M/H] values are valid for metal-poor atmosphere grids.
! so we do not apply a limit on the "metallicity" parameter.
if (t_eff >= 0) then
! Select precomputed zero-point based on magnitude system
select case (trim(cs%mag_system))
case ('VEGA', 'Vega', 'vega')
zero_point = cs%filters(i)%vega_zero_point
case ('AB', 'ab')
zero_point = cs%filters(i)%ab_zero_point
case ('ST', 'st')
zero_point = cs%filters(i)%st_zero_point
case default
write (*, *) 'colors error: unknown magnitude system: ', trim(cs%mag_system)
zero_point = -1.0_dp
end select

vals(i + filter_offset) = calculate_synthetic(t_eff, log_g, metallicity, ierr, &
wavelengths, fluxes, &
cs%filters(i)%wavelengths, &
cs%filters(i)%transmission, &
zero_point, &
color_filter_names(i), &
make_sed, cs%sed_per_model, &
cs%colors_results_directory, model_number)

if (ierr /= 0) vals(i + filter_offset) = -1.0_dp
else
vals(i + filter_offset) = -1.0_dp
ierr = 1
end if
!write(0,*) 'DEBUG colors_history: n=', n, 'num_color_filters=', num_color_filters, &
! 'photo_precompute=', cs%photo_precompute
!flush(0)

if (cs%photo_precompute) then

lum = (R / rsun)**2 * (t_eff / Teffsun)**4
bolometric_magnitude = mbolsun - 2.5_dp * log10(lum)

names(1) = 'Mag_bol'
vals(1) = bolometric_magnitude
names(2) = 'Flux_bol'
vals(2) = -1.0_dp
names(3) = 'Interp_rad'
vals(3) = -1.0_dp
filter_offset = 3

k = 0
do j = 1, num_thead
thead => thead_all(j)%thead
call Eval_Colors(log10(t_eff), log_g, metallicity, bcs, thead, thead_all(j)%n_colors, ierr)
do i = 1, thead_all(j)%n_colors
k = k + 1
filter_name = trim(remove_dat(color_filter_names(k)))
names(k + filter_offset) = filter_name
if (ierr /= 0) then
vals(k + filter_offset) = -1.0_dp
else
vals(k + filter_offset) = bolometric_magnitude - bcs(i)
end if
end do
end do

else
ierr = 1
call mesa_error(__FILE__, __LINE__, 'colors: data_for_colors_history_columns array size mismatch')
end if

! clean up
if (allocated(wavelengths)) deallocate (wavelengths)
if (allocated(fluxes)) deallocate (fluxes)
! verify data was loaded at initialization
if (.not. cs%lookup_loaded) then
write (*, *) 'colors error: lookup table not loaded'
ierr = -1
return
end if
if (.not. cs%filters_loaded) then
write (*, *) 'colors error: filter data not loaded'
ierr = -1
return
end if

d = cs%distance
sed_filepath = trim(resolve_path(cs%stellar_atm))
make_sed = cs%make_csv

call calculate_bolometric(cs, t_eff, log_g, metallicity, R, d, &
bolometric_magnitude, bolometric_flux, wavelengths, fluxes, &
sed_filepath, interpolation_radius)

names(1) = "Mag_bol"
vals(1) = bolometric_magnitude
names(2) = "Flux_bol"
vals(2) = bolometric_flux
names(3) = "Interp_rad"
vals(3) = interpolation_radius
filter_offset = 3

if (n == num_color_filters + filter_offset) then
do i = 1, num_color_filters
filter_name = trim(remove_dat(color_filter_names(i)))
names(i + filter_offset) = filter_name

! Negative [M/H] values are valid for metal-poor atmosphere grids.
! so we do not apply a limit on the "metallicity" parameter.
if (t_eff >= 0) then
! Select precomputed zero-point based on magnitude system
select case (trim(cs%mag_system))
case ('VEGA', 'Vega', 'vega')
zero_point = cs%filters(i)%vega_zero_point
case ('AB', 'ab')
zero_point = cs%filters(i)%ab_zero_point
case ('ST', 'st')
zero_point = cs%filters(i)%st_zero_point
case default
write (*, *) 'colors error: unknown magnitude system: ', trim(cs%mag_system)
zero_point = -1.0_dp
end select

vals(i + filter_offset) = calculate_synthetic(t_eff, log_g, metallicity, ierr, &
wavelengths, fluxes, &
cs%filters(i)%wavelengths, &
cs%filters(i)%transmission, &
zero_point, &
color_filter_names(i), &
make_sed, cs%sed_per_model, &
cs%colors_results_directory, model_number)

if (ierr /= 0) vals(i + filter_offset) = -1.0_dp
else
vals(i + filter_offset) = -1.0_dp
ierr = 1
end if
end do
else
ierr = 1
call mesa_error(__FILE__, __LINE__, 'colors: data_for_colors_history_columns array size mismatch')
end if

! clean up
if (allocated(wavelengths)) deallocate (wavelengths)
if (allocated(fluxes)) deallocate (fluxes)

end if

end subroutine data_for_colors_history_columns

Expand Down
Loading
Loading