register_mesa_fields Subroutine

private subroutine register_mesa_fields(dirname, pnum, fld_col, nf)

Register curated colour fields present in a run.

Matches one profile's body header against MESA_FIELD_CAND, setting shared registry and each matched field's body column.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dirname

Path of MESA run directory.

integer(kind=int32), intent(in) :: pnum

Profile number whose body header is read.

integer(kind=int32), intent(out), allocatable :: fld_col(:)

Body column of each registered field.

integer(kind=int32), intent(out) :: nf

Number of registered fields.


Source Code

   subroutine register_mesa_fields(dirname, pnum, fld_col, nf)
      !! Register curated colour fields present in a run.
      !!
      !! Matches one profile's body header against `MESA_FIELD_CAND`, setting shared registry and
      !! each matched field's body column.
      ! Arguments
      character(len=*), intent(in) :: dirname
         !! Path of MESA run directory.
      integer(int32), intent(in) :: pnum
         !! Profile number whose body header is read.
      integer(int32), allocatable, intent(out) :: fld_col(:)
         !! Body column of each registered field.
      integer(int32), intent(out) :: nf
         !! Number of registered fields.
      integer(int32) :: iunit, iostat, c, ci
      integer(int32), allocatable :: tmpcol(:)
      integer(int32) :: tmpcand(MESA_NCAND)
      character(len=256) :: fname, bnames
      character(len=8192) :: scratch

      fname = trim(dirname)//'/profile'//trim(itoa(pnum))//'.data'
      open (NEWUNIT=iunit, FILE=trim(fname), STATUS='OLD', &
            ACTION='READ', IOSTAT=iostat)
      if (iostat /= 0) &
         error stop '[register_mesa_fields] cannot open '//trim(fname)
      read (iunit, '(a)') scratch      ! 1 header col indices
      read (iunit, '(a)') scratch      ! 2 header names
      read (iunit, '(a)') scratch      ! 3 header values
      read (iunit, '(a)') scratch      ! 4 blank
      read (iunit, '(a)') scratch      ! 5 body col indices
      read (iunit, '(a)') bnames       ! 6 body names
      close (iunit)

      allocate (tmpcol(MESA_NCAND))
      nf = 0
      do c = 1, MESA_NCAND
         ci = col_index(bnames, trim(MESA_FIELD_CAND(c)))
         if (ci < 1) cycle
         nf = nf + 1
         tmpcol(nf) = ci
         tmpcand(nf) = c
      end do

      call reset_field_registry(nf)
      allocate (fld_col(nf))
      do c = 1, nf
         fld_col(c) = tmpcol(c)
         field_names(c) = MESA_FIELD_CAND(tmpcand(c))
      end do
      deallocate (tmpcol)
   end subroutine register_mesa_fields