parse_kipp_header Subroutine

private subroutine parse_kipp_header(hdrfile, ncols, c_model, c_age, c_dt, c_mass, c_radius, c_mix, c_eps)

Read ncols and required-role columns from .kipp sidecar header.

First word of each line decides its use ("Header file", docs/kippfiles.md): ncols N gives row width, <index> <name> names a column, dtype and columns ignored. Missing ncols or required column stops load w/ error.

Arguments

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

Path of sidecar header.

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

Number of values per cell.

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

Column of model number.

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

Column of age.

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

Column of time step, 0 if absent.

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

Column of mass coordinate.

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

Column of radius coordinate.

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

Column of mixing type.

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

Column of energy rate.


Source Code

   subroutine parse_kipp_header(hdrfile, ncols, c_model, c_age, c_dt, &
                                c_mass, c_radius, c_mix, c_eps)
      !! Read `ncols` and required-role columns from `.kipp` sidecar header.
      !!
      !! First word of each line decides its use ("Header file", docs/kippfiles.md): `ncols N` gives
      !! row width, `<index> <name>` names a column, `dtype` and `columns` ignored. Missing `ncols`
      !! or required column stops load w/ error.
      ! Arguments
      character(len=*), intent(in) :: hdrfile
         !! Path of sidecar header.
      integer(int32), intent(out) :: ncols
         !! Number of values per cell.
      integer(int32), intent(out) :: c_model
         !! Column of model number.
      integer(int32), intent(out) :: c_age
         !! Column of age.
      integer(int32), intent(out) :: c_dt
         !! Column of time step, 0 if absent.
      integer(int32), intent(out) :: c_mass
         !! Column of mass coordinate.
      integer(int32), intent(out) :: c_radius
         !! Column of radius coordinate.
      integer(int32), intent(out) :: c_mix
         !! Column of mixing type.
      integer(int32), intent(out) :: c_eps
         !! Column of energy rate.
      integer(int32) :: iunit, iostat, idx
      character(len=256) :: line, key, name

      c_model = 0; c_age = 0; c_dt = 0
      c_mass = 0; c_radius = 0; c_mix = 0; c_eps = 0
      ncols = 0

      open (NEWUNIT=iunit, FILE=trim(hdrfile), STATUS='OLD', ACTION='READ', &
            IOSTAT=iostat)
      if (iostat /= 0) &
         error stop '[loadkipp] cannot open '//trim(hdrfile)

      do
         read (iunit, '(a)', IOSTAT=iostat) line
         if (iostat /= 0) exit
         line = adjustl(line)
         if (len_trim(line) == 0) cycle

         read (line, *, IOSTAT=iostat) key
         if (iostat /= 0) cycle

         if (key == 'ncols') then
            read (line, *, IOSTAT=iostat) key, ncols
         else if (key == 'dtype' .or. key == 'columns' .or. key == 'columns:') then
            cycle
         else
            ! "<index> <name>" column line; key holds the index token
            read (line, *, IOSTAT=iostat) idx, name
            if (iostat /= 0) cycle
            call assign_kipp_col(name, idx, c_model, c_age, c_dt, &
                                 c_mass, c_radius, c_mix, c_eps)
         end if
      end do
      close (iunit)

      if (ncols < 1) &
         error stop '[loadkipp] header missing ncols'
      if (min(c_model, c_age, c_mass, c_radius, c_mix, c_eps) < 1) &
         error stop '[loadkipp] header missing a required column'
   end subroutine parse_kipp_header