<commit_before>module mod_s_curve
  use mod_constants
  use mod_read_parameters
  use mod_variables
  implicit none

  real(kind = x_precision), dimension(nb_it) :: temperature ! Temperatures for which we need to solve the dichotomy
  real(kind = x_precision), dimension(nb_it) :: temp_real   ! Dimensioned version
  real(kind = x_precision)                   :: eps         ! Precision required for the dichotomy
  real(kind = x_precision)                   :: S_min       ! Minimum surface density limit
  real(kind = x_precision)                   :: S_max       ! Maximum surface density limit

contains
  !-------------------------------------------------------------------------
  ! SUBROUTINES :
  !               make_temperature      : : Create the temperature array needed for everyone else
  !                                     <-- input : Lower and upper bound for the temperature coordinate of the S curve 
  !                                         --> output :

  !               set_conditions        : : Set conditions for the resolution
  !                                     <-- input : Resolution treshold, lower and upper bound for the Sigma coordinate of the S curve
  !                                         --> output :

  !               curve                 : : fake main
  !                                         --> output : 2 arrays for the coordinates (Temperature, Sigma) of the first critical point

  !               first_critical_point  : :
  !                                     <-- input : T and Sigma for the optically thick medium + number of points
  !                                         --> output : (Temperature, Sigma) of the first critical point + index of the point

  !               second_critical_point : :
  !                                     <-- input : T and Sigma for the optically thin medium + T for the thick one + number of points + index of the thick critical point + precision
  !                                         --> output : (Temperature, Sigma) of the second critical point + index of the point

  !               build_s_curve         : : combining both thin and thick media
  !                                     <-- input : T and Sigma for both media + index of the thin critical point
  !                                         --> output : array for (Temperature, Sigma)

  !               quadratic             : : For a positive real solution of a quadratic equation ax^2 + bx + c =0
  !                                     <-- input : factors a, b, c
  !                                         --> output : positive solution

  !               variables             : : Computing all the variables for Q+ and Q-
  !                                     <-- input : Temperature, Sigma, Omega + optical depth indicator (0 or 1) + more
  !                                         --> output : f = Q+ - Q-

  !               dichotomy             : : In order to find the result of the equation Q+ - Q- = 0
  !                                     <-- input : Temperature, Sigma, Omega + optical depth indicator (0 or 1) + precision
  !                                         --> output : Sigma between a computed range of surface density [Smin, Smax] for a given temperature

  !-------------------------------------------------------------------------

  subroutine make_temperature(Tmin, Tmax)
    implicit none

    real(kind = x_precision), intent(in) :: Tmin
    real(kind = x_precision), intent(in) :: Tmax
    !------------------------------------------------------------------------

    real(kind = x_precision) :: dt
    integer                  :: i

    dt = (Tmax - Tmin) / (nb_it - 1)

    do i = 1, nb_it
      temperature(i) = dt * (i-1) + Tmin
    enddo

    temp_real  = temperature * state_0%T_0

  end subroutine make_temperature


  subroutine set_conditions(eps_in, Smin, Smax)
    implicit none

    real(kind = x_precision), intent(in) :: eps_in
    real(kind = x_precision), intent(in) :: Smin
    real(kind = x_precision), intent(in) :: Smax
    !------------------------------------------------------------------------

    eps   = eps_in
    S_min = Smin
    S_max = Smax

  end subroutine set_conditions


  subroutine curve(temperature_c, sigma_c)
    implicit none

    real(kind = x_precision), dimension(n_cell), intent(out) :: temperature_c  ! Temperature for the critical point
    real(kind = x_precision), dimension(n_cell), intent(out) :: sigma_c        ! Surface density for the critical point
    !------------------------------------------------------------------------
    integer                                     :: i,k            ! Iteration counters

    ! For variables
    real(kind = x_precision)                    :: f              ! Q+ - Q-
    real(kind = x_precision)                    :: tau_eff        ! Effective optical depth
    integer                                     :: optical_depth  ! Indicator for the optical thickness

    ! For the separate curves given the thickness
    real(kind = x_precision), dimension(nb_it)  :: sigma_t_thick
    real(kind = x_precision), dimension(nb_it)  :: sigma_t_thin
    real(kind = x_precision), dimension(nb_it)  :: sigma          ! Surface density for the S curve

    ! For the critical points
    integer                                     :: index_fcp
    real(kind = x_precision)                    :: sigma_c_thick
    real(kind = x_precision)                    :: temp_c_thick
    real(kind = x_precision), dimension(n_cell) :: sigma_thick
    real(kind = x_precision), dimension(n_cell) :: temp_thick
    real(kind = x_precision), dimension(nb_it)  :: tau_thick      ! Optical thickness for the first critical point
    integer                                     :: index_scp
    real(kind = x_precision)                    :: sigma_c_thin
    real(kind = x_precision)                    :: temp_c_thin
    real(kind = x_precision), dimension(n_cell) :: sigma_thin
    real(kind = x_precision), dimension(n_cell) :: temp_thin
    real(kind = x_precision), dimension(nb_it)  :: tau_thin       ! Optical thickness for the second critical point

    !------------------------------------------------------------------------
    ! Loop over values of r/x (radius)
    !------------------------------------------------------------------------
    do k = 1, n_cell
      ! For each point of the S curve
      do i = 1, nb_it
        ! Optical thick case (tau >= 1)
        optical_depth = 1

        ! S found with the dichotomy approach
        sigma_t_thick(i) = dichotomy(k, i, optical_depth)

        ! Optical thin case (tau < 1)
        optical_depth = 0

        ! S found with the dichotomy approach
        sigma_t_thin(i)  = dichotomy(k, i, optical_depth)
      enddo

      ! For the first critical point (the one at the right of the S shape)
      call first_critical_point(sigma_t_thick, index_fcp, sigma_c_thick, temp_c_thick)

      ! For the second critical point (the one at the left of the S shape)
      call second_critical_point(sigma_t_thick, sigma_t_thin, index_fcp, index_scp, sigma_c_thin, temp_c_thin)

      ! Combining the two separate curves into one that forms the S shape
      call build_s_curve(sigma_t_thick, sigma_t_thin, index_scp, sigma)

      ! Display the two critical points
      call display_critical_points(sigma_c_thin, temp_c_thin, sigma_c_thick, temp_c_thick, k)<commit_msg>mod_s_curve: Tiny fix<commit_after>module mod_s_curve
  use mod_constants
  use mod_read_parameters
  use mod_variables
  implicit none

  real(kind = x_precision), dimension(nb_it) :: temperature ! Temperatures for which we need to solve the dichotomy
  real(kind = x_precision), dimension(nb_it) :: temp_real   ! Dimensioned version
  real(kind = x_precision)                   :: eps         ! Precision required for the dichotomy
  real(kind = x_precision)                   :: S_min       ! Minimum surface density limit
  real(kind = x_precision)                   :: S_max       ! Maximum surface density limit

contains
  !-------------------------------------------------------------------------
  ! SUBROUTINES :
  !               make_temperature      : : Create the temperature array needed for everyone else
  !                                     <-- input : Lower and upper bound for the temperature coordinate of the S curve 
  !                                         --> output :

  !               set_conditions        : : Set conditions for the resolution
  !                                     <-- input : Resolution treshold, lower and upper bound for the Sigma coordinate of the S curve
  !                                         --> output :

  !               curve                 : : fake main
  !                                         --> output : 2 arrays for the coordinates (Temperature, Sigma) of the first critical point

  !               first_critical_point  : :
  !                                     <-- input : T and Sigma for the optically thick medium + number of points
  !                                         --> output : (Temperature, Sigma) of the first critical point + index of the point

  !               second_critical_point : :
  !                                     <-- input : T and Sigma for the optically thin medium + T for the thick one + number of points + index of the thick critical point + precision
  !                                         --> output : (Temperature, Sigma) of the second critical point + index of the point

  !               build_s_curve         : : combining both thin and thick media
  !                                     <-- input : T and Sigma for both media + index of the thin critical point
  !                                         --> output : array for (Temperature, Sigma)

  !               quadratic             : : For a positive real solution of a quadratic equation ax^2 + bx + c =0
  !                                     <-- input : factors a, b, c
  !                                         --> output : positive solution

  !               variables             : : Computing all the variables for Q+ and Q-
  !                                     <-- input : Temperature, Sigma, Omega + optical depth indicator (0 or 1) + more
  !                                         --> output : f = Q+ - Q-

  !               dichotomy             : : In order to find the result of the equation Q+ - Q- = 0
  !                                     <-- input : Temperature, Sigma, Omega + optical depth indicator (0 or 1) + precision
  !                                         --> output : Sigma between a computed range of surface density [Smin, Smax] for a given temperature

  !-------------------------------------------------------------------------

  subroutine make_temperature(Tmin, Tmax)
    implicit none

    real(kind = x_precision), intent(in) :: Tmin
    real(kind = x_precision), intent(in) :: Tmax
    !------------------------------------------------------------------------

    real(kind = x_precision) :: dt
    integer                  :: i

    dt = (Tmax - Tmin) / (nb_it - 1)

    do i = 1, nb_it
      temperature(i) = dt * (i-1) + Tmin
    enddo

    temp_real  = temperature * state_0%T_0

  end subroutine make_temperature


  subroutine set_conditions(eps_in, Smin, Smax)
    implicit none

    real(kind = x_precision), intent(in) :: eps_in
    real(kind = x_precision), intent(in) :: Smin
    real(kind = x_precision), intent(in) :: Smax
    !------------------------------------------------------------------------

    eps   = eps_in
    S_min = Smin
    S_max = Smax

  end subroutine set_conditions


  subroutine curve(temperature_c, sigma_c)
    implicit none

    real(kind = x_precision), dimension(n_cell), intent(out) :: temperature_c  ! Temperature for the critical point
    real(kind = x_precision), dimension(n_cell), intent(out) :: sigma_c        ! Surface density for the critical point
    !------------------------------------------------------------------------
    integer                                     :: i,k            ! Iteration counters

    ! For variables
    real(kind = x_precision)                    :: f              ! Q+ - Q-
    real(kind = x_precision)                    :: tau_eff        ! Effective optical depth
    integer                                     :: optical_depth  ! Indicator for the optical thickness

    ! For the separate curves given the thickness
    real(kind = x_precision), dimension(nb_it)  :: sigma_t_thick
    real(kind = x_precision), dimension(nb_it)  :: sigma_t_thin
    real(kind = x_precision), dimension(nb_it)  :: sigma          ! Surface density for the S curve

    ! For the critical points
    integer                                     :: index_fcp
    real(kind = x_precision)                    :: sigma_c_thick
    real(kind = x_precision)                    :: temp_c_thick
    real(kind = x_precision), dimension(n_cell) :: sigma_thick
    real(kind = x_precision), dimension(n_cell) :: temp_thick
    real(kind = x_precision), dimension(n_cell) :: tau_thick      ! Optical thickness for the first critical point
    integer                                     :: index_scp
    real(kind = x_precision)                    :: sigma_c_thin
    real(kind = x_precision)                    :: temp_c_thin
    real(kind = x_precision), dimension(n_cell) :: sigma_thin
    real(kind = x_precision), dimension(n_cell) :: temp_thin
    real(kind = x_precision), dimension(n_cell) :: tau_thin       ! Optical thickness for the second critical point

    !------------------------------------------------------------------------
    ! Loop over values of r/x (radius)
    !------------------------------------------------------------------------
    do k = 1, n_cell
      ! For each point of the S curve
      do i = 1, nb_it
        ! Optical thick case (tau >= 1)
        optical_depth = 1

        ! S found with the dichotomy approach
        sigma_t_thick(i) = dichotomy(k, i, optical_depth)

        ! Optical thin case (tau < 1)
        optical_depth = 0

        ! S found with the dichotomy approach
        sigma_t_thin(i)  = dichotomy(k, i, optical_depth)
      enddo

      ! For the first critical point (the one at the right of the S shape)
      call first_critical_point(sigma_t_thick, index_fcp, sigma_c_thick, temp_c_thick)

      ! For the second critical point (the one at the left of the S shape)
      call second_critical_point(sigma_t_thick, sigma_t_thin, index_fcp, index_scp, sigma_c_thin, temp_c_thin)

      ! Combining the two separate curves into one that forms the S shape
      call build_s_curve(sigma_t_thick, sigma_t_thin, index_scp, sigma)

      ! Display the two critical points
      call display_critical_points(sigma_c_thin, temp_c_thin, sigma_c_thick, temp_c_thick, k)
{'fraction_non_alphanumeric': 0.13654104979811574, 'fraction_numerical': 0.0025572005383580083, 'mean_word_length': 1.401971876515274, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 84, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '456520', 'n_tokens_mistral': 3940, 'n_tokens_neox': 3546, 'n_words': 1217}