2020module colors_utils
2121 use const_def, only: dp, strlen, mesa_dir
2222 use colors_def, only: Colors_General_Info
23+ use utils_lib, only: mesa_error
2324
2425 implicit none
2526
@@ -39,7 +40,7 @@ subroutine dilute_flux(surface_flux, R, d, calibrated_flux)
3940 ! Check that the output array has the same size as the input
4041 if (size (calibrated_flux) /= size (surface_flux)) then
4142 print * , " Error in dilute_flux: Output array must have the same size as input array."
42- stop 1
43+ call mesa_error(__FILE__, __LINE__)
4344 end if
4445
4546 ! Apply the dilution factor (R/d)^2 to each element
@@ -59,25 +60,25 @@ subroutine trapezoidal_integration(x, y, result)
5960 real (dp), intent (out ) :: result
6061
6162 integer :: i, n
62- REAL :: sum
63+ real (dp) :: sum
6364
6465 n = size (x)
65- sum = 0.0
66+ sum = 0.0_dp
6667
6768 ! Validate input sizes
6869 if (size (x) /= size (y)) then
6970 print * , " Error: x and y arrays must have the same size."
70- stop
71+ call mesa_error(__FILE__, __LINE__)
7172 end if
7273
7374 if (size (x) < 2 ) then
7475 print * , " Error: x and y arrays must have at least 2 elements."
75- stop
76+ call mesa_error(__FILE__, __LINE__)
7677 end if
7778
7879 ! Perform trapezoidal integration
7980 do i = 1 , n - 1
80- sum = sum + 0.5 * (x(i + 1 ) - x(i))* (y(i + 1 ) + y(i))
81+ sum = sum + 0.5_dp * (x(i + 1 ) - x(i))* (y(i + 1 ) + y(i))
8182 end do
8283
8384 result = sum
@@ -96,15 +97,15 @@ subroutine simpson_integration(x, y, result)
9697 ! Validate input sizes
9798 if (size (x) /= size (y)) then
9899 print * , " Error: x and y arrays must have the same size."
99- stop
100+ call mesa_error(__FILE__, __LINE__)
100101 end if
101102
102103 if (size (x) < 2 ) then
103104 print * , " Error: x and y arrays must have at least 2 elements."
104- stop
105+ call mesa_error(__FILE__, __LINE__)
105106 end if
106107
107- ! Perform adaptive Simpson’ s rule
108+ ! Perform adaptive Simpson' s rule
108109 do i = 1 , n - 2 , 2
109110 h1 = x(i + 1 ) - x(i) ! Step size for first interval
110111 h2 = x(i + 2 ) - x(i + 1 ) ! Step size for second interval
@@ -139,12 +140,12 @@ subroutine romberg_integration(x, y, result)
139140 ! Validate input sizes
140141 if (size (x) /= size (y)) then
141142 print * , " Error: x and y arrays must have the same size."
142- stop
143+ call mesa_error(__FILE__, __LINE__)
143144 end if
144145
145146 if (n < 2 ) then
146147 print * , " Error: x and y arrays must have at least 2 elements."
147- stop
148+ call mesa_error(__FILE__, __LINE__)
148149 end if
149150
150151 allocate (R(m))
@@ -192,14 +193,14 @@ subroutine load_vega_sed(filepath, wavelengths, flux)
192193 open (unit, file= trim (filepath), status= ' OLD' , action= ' READ' , iostat= status)
193194 if (status /= 0 ) then
194195 print * , " Error: Could not open Vega SED file " , trim (filepath)
195- stop
196+ call mesa_error(__FILE__, __LINE__)
196197 end if
197198
198199 ! Skip header line
199200 read (unit, ' (A)' , iostat= status) line
200201 if (status /= 0 ) then
201202 print * , " Error: Could not read header from Vega SED file " , trim (filepath)
202- stop
203+ call mesa_error(__FILE__, __LINE__)
203204 end if
204205
205206 ! Count the number of data lines
@@ -237,21 +238,21 @@ subroutine load_filter(directory, filter_wavelengths, filter_trans)
237238
238239 character (len= 512 ) :: line
239240 integer :: unit, n_rows, status, i
240- REAL :: temp_wavelength, temp_trans
241+ real (dp) :: temp_wavelength, temp_trans
241242
242243 ! Open the file
243244 unit = 20
244245 open (unit, file= trim (directory), status= ' OLD' , action= ' READ' , iostat= status)
245246 if (status /= 0 ) then
246247 print * , " Error: Could not open file " , trim (directory)
247- stop
248+ call mesa_error(__FILE__, __LINE__)
248249 end if
249250
250251 ! Skip header line
251252 read (unit, ' (A)' , iostat= status) line
252253 if (status /= 0 ) then
253254 print * , " Error: Could not read the file" , trim (directory)
254- stop
255+ call mesa_error(__FILE__, __LINE__)
255256 end if
256257
257258 ! Count rows in the file
@@ -272,7 +273,7 @@ subroutine load_filter(directory, filter_wavelengths, filter_trans)
272273 read (unit, ' (A)' , iostat= status) line
273274 if (status /= 0 ) then
274275 print * , " Error: Could not rewind file" , trim (directory)
275- stop
276+ call mesa_error(__FILE__, __LINE__)
276277 end if
277278 if (line(1 :1 ) /= " #" ) exit
278279 end do
@@ -313,14 +314,14 @@ subroutine load_lookup_table(lookup_file, lookup_table, out_file_names, &
313314 open (unit, file= lookup_file, status= ' old' , action= ' read' , iostat= status)
314315 if (status /= 0 ) then
315316 print * , " Error: Could not open file" , lookup_file
316- stop
317+ call mesa_error(__FILE__, __LINE__)
317318 end if
318319
319320 ! Read header line
320321 read (unit, ' (A)' , iostat= status) line
321322 if (status /= 0 ) then
322323 print * , " Error: Could not read header line"
323- stop
324+ call mesa_error(__FILE__, __LINE__)
324325 end if
325326
326327 call split_line(line, delimiter, headers)
@@ -474,15 +475,15 @@ subroutine load_sed(directory, index, wavelengths, flux)
474475 open (unit, file= trim (directory), status= ' OLD' , action= ' READ' , iostat= status)
475476 if (status /= 0 ) then
476477 print * , " Error: Could not open file " , trim (directory)
477- stop
478+ call mesa_error(__FILE__, __LINE__)
478479 end if
479480
480481 ! Skip header lines
481482 do
482483 read (unit, ' (A)' , iostat= status) line
483484 if (status /= 0 ) then
484485 print * , " Error: Could not read the file" , trim (directory)
485- stop
486+ call mesa_error(__FILE__, __LINE__)
486487 end if
487488 if (line(1 :1 ) /= " #" ) exit
488489 end do
@@ -505,7 +506,7 @@ subroutine load_sed(directory, index, wavelengths, flux)
505506 read (unit, ' (A)' , iostat= status) line
506507 if (status /= 0 ) then
507508 print * , " Error: Could not rewind file" , trim (directory)
508- stop
509+ call mesa_error(__FILE__, __LINE__)
509510 end if
510511 if (line(1 :1 ) /= " #" ) exit
511512 end do
@@ -584,7 +585,7 @@ subroutine read_strings_from_file(colors_settings, strings, n, ierr)
584585 if (status /= 0 ) then
585586 ierr = - 1
586587 print * , " Error: Could not open file" , filename
587- stop
588+ call mesa_error(__FILE__, __LINE__)
588589 end if
589590
590591 do
0 commit comments