[Mesa-users] using an index I found in another array

aldanag at campus.technion.ac.il aldanag at campus.technion.ac.il
Fri Feb 23 09:25:02 EST 2018


I am trying to inject energy to a star using  the following subroutine I added to the run.star.extras:

subroutine energy_routine(id, ierr)

         use const_def, only: Rsun
         integer, intent(in) :: id
         integer, intent(out) :: ierr
         type (star_info), pointer :: s
         integer :: k
         integer :: j
         real(dp),allocatable,dimension(:) :: avg_charge_H
         real(dp), pointer :: m_old(:)
         real(dp) :: A
         integer :: loc
         real(dp) :: m_50_new
         real(dp) :: m_50_old
         real(dp) :: delta_m
         real(dp) :: E_recomb
         call star_ptr(id, s, ierr)
    if (ierr /= 0) return
    if (s% star_age > 1.2275500000700004d9 .and. s% star_age < 1.2275500017700004d9) then
         do j=1, s% nz
         if(avg_charge_H(j) .eq. 0.5d0) then
          end if
      end do
      do k = 1, s% nz
        if (avg_charge_H(k) > 0.1d0 .and. avg_charge_H(k) < 0.9d0) then
               m_old(k) = s% M_center_old + s% q_old(k)*s% xmstar_old !gr
               m_50_new= s% m(k .eq. loc) !s% m(loc)
               !m_50_old= m_old(loc)
               delta_m= m_50_old - m_50_new
               A= 1.3d13 !13.6 ev/hydrogen mass where the energy in erg/gr
               E_recomb= s% X(loc)*delta_m*A !erg
               s% extra_heat(k) = E_recomb/ s% nz !erg/g/s
        end if
      end do
    end if
      end subroutine energy_routine

 yet the run won't compile.  The error displayed on the screen is:
                m_50_new= s% m(k .eq. loc) !s% m(loc)
Error: Array index at (1) must be of INTEGER type, found LOGICAL

I also tried adding the line in bold instead of what I wrote for m_50_new, in this case the run compiles yet I get the run time error:

Fortran runtime error: Index '-861944544' of dimension 1 of array 's%m' below lower bound of 1

So I suppose m_50_new is filled with junk instead of the value of m in the index of loc.

Is there any way to convert the logical type into integer, so I could use the mass in which avg_charge_H = 0.5 (the mass in the index loc)?

if not, is there an alternative way (maybe a built in function) in order to find the index where avg_charge_H = 0.5 and use the mass of that index in the subroutine?

Thank in advance,


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20180223/c8e4fde2/attachment.html>

More information about the Mesa-users mailing list