LCOV - code coverage report
Current view: top level - chem/private - lodders_mod.f90 (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.9 % 38 30
Test Date: 2025-05-08 18:23:42 Functions: 100.0 % 2 2

            Line data    Source code
       1              : ! ***********************************************************************
       2              : !
       3              : !   Copyright (C) 2010  Ed Brown & The MESA Team
       4              : !
       5              : !   This program is free software: you can redistribute it and/or modify
       6              : !   it under the terms of the GNU Lesser General Public License
       7              : !   as published by the Free Software Foundation,
       8              : !   either version 3 of the License, or (at your option) any later version.
       9              : !
      10              : !   This program is distributed in the hope that it will be useful,
      11              : !   but WITHOUT ANY WARRANTY; without even the implied warranty of
      12              : !   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      13              : !   See the GNU Lesser General Public License for more details.
      14              : !
      15              : !   You should have received a copy of the GNU Lesser General Public License
      16              : !   along with this program. If not, see <https://www.gnu.org/licenses/>.
      17              : !
      18              : ! ***********************************************************************
      19              : 
      20              : module lodders_mod
      21              : 
      22              :    use const_def, only : dp, mesa_data_dir
      23              : 
      24              :    implicit none
      25              : 
      26              :    contains
      27              : 
      28          302 :    subroutine read_lodders03_data(datafile,ierr)
      29              :       use iso_fortran_env, only : iostat_end
      30              :       use chem_def
      31              :       use utils_lib, only : integer_dict_define
      32              : 
      33              :       character(len=*), intent(in) :: datafile
      34              :       integer, intent(out) :: ierr
      35              :       integer, parameter :: lodders_header_length = 5, max_number_isotopes = 500
      36              :       integer :: Z, A
      37         8016 :       real(dp), dimension(max_number_isotopes) :: percent
      38              :       integer :: nentries
      39           16 :       real(dp) :: NSi
      40              :       integer :: iounit, ios, i
      41              :       character(len=2) :: el
      42              :       character(len=iso_name_length), dimension(max_number_isotopes) :: lodders03_isotopes
      43              :       character(len=256) :: filename
      44              : 
      45           16 :       ierr = 0
      46           16 :       filename = trim(mesa_data_dir)//'/chem_data/'//trim(datafile)
      47           16 :       open(newunit=iounit, file=trim(filename), iostat=ierr, status="old", action="read")
      48           16 :       if ( ierr /= 0 ) then
      49            0 :          write(*,*) 'chem_init: Error opening file containing Lodders (2003) table'
      50            0 :          write(*,*) 'filename ' // trim(filename)
      51              :          return
      52              :       end if
      53              : 
      54              :       ! skip the header
      55           96 :       do i = 1, lodders_header_length
      56           96 :          read(iounit,*)
      57              :       end do
      58              : 
      59              :       ! read in the file, setting bookmarks as we go.
      60           16 :       nentries = 0   ! accumulates number of spaces to hold the percentages
      61         4592 :       do i = 1, max_number_isotopes
      62         4592 :          read(iounit,*,iostat=ios) Z, el, A, percent(i), NSi
      63         4592 :          if (ios == iostat_end) exit
      64         4576 :          nentries = nentries + 1
      65         4592 :          write(lodders03_isotopes(i), '(a,i0)') trim(el_name(Z)),A
      66              : 
      67              :       end do
      68              : 
      69           16 :       allocate(lodders03_tab6% isotopic_percent(nentries))
      70         4592 :       lodders03_tab6% isotopic_percent(1:nentries) = percent(1:nentries)
      71         4592 :       do i = 1, nentries
      72         4576 :          call integer_dict_define(lodders03_tab6% name_dict, lodders03_isotopes(i), i, ierr)
      73         4592 :          if (ierr /= 0) then
      74            0 :             write(*,*) 'FATAL ERROR: read_lodders03_data failed in integer_dict_define'
      75            0 :             call mesa_error(__FILE__,__LINE__)
      76              :          end if
      77              :       end do
      78              : 
      79           16 :       close(iounit)
      80           16 :    end subroutine read_lodders03_data
      81              : 
      82          286 :    function get_lodders03_isotopic_abundance(nuclei,ierr) result(percent)
      83           16 :       use chem_def
      84              :       use utils_lib, only : integer_dict_lookup
      85              :       character(len=*), intent(in) :: nuclei
      86              :       integer, intent(out) :: ierr
      87              :       real(dp) :: percent
      88              :       integer :: indx
      89              : 
      90          286 :       percent = 0.0d0
      91          286 :       if (.not.chem_has_been_initialized) then
      92            0 :          ierr = -9
      93            0 :          return
      94              :       end if
      95              : 
      96              :       ierr = 0
      97          286 :       call integer_dict_lookup(lodders03_tab6% name_dict, nuclei, indx, ierr)
      98          286 :       if (ierr /= 0) then
      99            0 :          ierr = 0
     100            0 :          return
     101              :       end if
     102          286 :       percent = lodders03_tab6% isotopic_percent(indx)
     103              : 
     104          286 :    end function get_lodders03_isotopic_abundance
     105              : 
     106              : end module lodders_mod
        

Generated by: LCOV version 2.0-1