snapshot_read_header Subroutine

public subroutine snapshot_read_header(fh, offset_tree, offset_block)

Uses

  • proc~~snapshot_read_header~~UsesGraph proc~snapshot_read_header snapshot_read_header mod_physics mod_physics proc~snapshot_read_header->mod_physics module~mod_forest mod_forest proc~snapshot_read_header->module~mod_forest module~mod_global_parameters mod_global_parameters proc~snapshot_read_header->module~mod_global_parameters module~mod_basic_types mod_basic_types module~mod_global_parameters->module~mod_basic_types module~mod_connectivity mod_connectivity module~mod_global_parameters->module~mod_connectivity module~mod_constants mod_constants module~mod_global_parameters->module~mod_constants module~mod_physicaldata mod_physicaldata module~mod_global_parameters->module~mod_physicaldata module~mod_variables mod_variables module~mod_global_parameters->module~mod_variables mpi mpi module~mod_global_parameters->mpi module~mod_variables->module~mod_basic_types

Read header for a snapshot

If you edit the header, don't forget to update: snapshot_write_header(), snapshot_read_header(), doc/fileformat.md, tools/python/dat_reader.py

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: fh

File handle

integer(kind=MPI_OFFSET_KIND), intent(out) :: offset_tree

Offset of tree info

integer(kind=MPI_OFFSET_KIND), intent(out) :: offset_block

Offset of block data


Calls

proc~~snapshot_read_header~~CallsGraph proc~snapshot_read_header snapshot_read_header proc~get_snapshot_index get_snapshot_index proc~snapshot_read_header->proc~get_snapshot_index proc~mpi_file_read_wrapper mpi_file_read_wrapper proc~snapshot_read_header->proc~mpi_file_read_wrapper proc~mpistop mpistop proc~snapshot_read_header->proc~mpistop mpi_file_read mpi_file_read proc~mpi_file_read_wrapper->mpi_file_read mpi_abort mpi_abort proc~mpistop->mpi_abort

Called by

proc~~snapshot_read_header~~CalledByGraph proc~snapshot_read_header snapshot_read_header proc~read_snapshot read_snapshot proc~read_snapshot->proc~snapshot_read_header proc~main main proc~main->proc~read_snapshot program~agile agile program~agile->proc~main

Source Code

  subroutine snapshot_read_header(fh, offset_tree, offset_block)
    use mod_forest
    use mod_global_parameters
    use mod_physics, only: physics_type
    integer, intent(in)                   :: fh
    !< File handle
    integer(MPI_OFFSET_KIND), intent(out) :: offset_tree
    !< Offset of tree info
    integer(MPI_OFFSET_KIND), intent(out) :: offset_block
    !< Offset of block data
    integer                               :: i, version
    integer                               :: ibuf(ndim), iw
    double precision                      :: rbuf(ndim)
    integer, dimension(MPI_STATUS_SIZE)   :: st
    character(len=name_len), allocatable  :: var_names(:), param_names(:)
    double precision, allocatable         :: params(:)
    character(len=name_len)               :: phys_name, geom_name
    integer                               :: er, n_par, tmp_int
    logical                               :: periodic(ndim)

    ! Version number
    call mpi_file_read_wrapper(fh, version, 1, MPI_INTEGER, st, er)
    if (all(compatible_versions /= version)) then
      call mpistop("Incompatible file version (maybe old format?)")
    end if

    ! offset_tree
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    offset_tree = ibuf(1)

    ! offset_block
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    offset_block = ibuf(1)

    ! nw
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    nw_found=ibuf(1)
    if (nw /= ibuf(1)) then
      write(*,*) "nw=",nw," and nw found in restart file=",ibuf(1)
      write(*,*) "Please be aware of changes in w at restart."
      !call mpistop("currently, changing nw at restart is not allowed")
    end if

    ! ndir
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    if (ibuf(1) /= ndir) then
      write(*,*) "ndir in restart file = ",ibuf(1)
      write(*,*) "ndir = ",ndir
      call mpistop("reset ndir to ndir in restart file")
    end if

    ! ndim
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    if (ibuf(1) /= ndim) then
      write(*,*) "ndim in restart file = ",ibuf(1)
      write(*,*) "ndim = ",ndim
      call mpistop("reset ndim to ndim in restart file")
    end if

    ! levmax
    call mpi_file_read_wrapper(fh, ibuf(1), 1, MPI_INTEGER, st, er)
    if (ibuf(1) > refine_max_level) then
      write(*,*) "number of levels in restart file = ",ibuf(1)
      write(*,*) "refine_max_level = ",refine_max_level
      call mpistop("refine_max_level < num. levels in restart file")
    end if

    ! nleafs
    call mpi_file_read_wrapper(fh, nleafs, 1, MPI_INTEGER, st, er)

    ! nparents
    call mpi_file_read_wrapper(fh, nparents, 1, MPI_INTEGER, st, er)

    ! it
    call mpi_file_read_wrapper(fh, it, 1, MPI_INTEGER, st, er)

    ! global time
    call mpi_file_read_wrapper(fh, global_time, 1, MPI_DOUBLE_PRECISION, st, er)

    ! xprobmin^D
    call mpi_file_read_wrapper(fh,rbuf(1:ndim),ndim,MPI_DOUBLE_PRECISION,st,er)
    if (maxval(abs(rbuf(1:ndim) - [ xprobmin1,xprobmin2,&
       xprobmin3 ])) > 0) then
      write(*,*) "Error: xprobmin differs from restart data: ", rbuf(1:ndim)
      call mpistop("change xprobmin^D in par file")
    end if

    ! xprobmax^D
    call mpi_file_read_wrapper(fh,rbuf(1:ndim),ndim,MPI_DOUBLE_PRECISION,st,er)
    if (maxval(abs(rbuf(1:ndim) - [ xprobmax1,xprobmax2,&
       xprobmax3 ])) > 0) then
      write(*,*) "Error: xprobmax differs from restart data: ", rbuf(1:ndim)
      call mpistop("change xprobmax^D in par file")
    end if

    ! domain_nx^D
    call mpi_file_read_wrapper(fh,ibuf(1:ndim), ndim, MPI_INTEGER,st,er)
    if (any(ibuf(1:ndim) /= [ domain_nx1,domain_nx2,domain_nx3 ])) then
      write(*,*) "Error: mesh size differs from restart data: ", ibuf(1:ndim)
      call mpistop("change domain_nx^D in par file")
    end if

    ! block_nx^D
    call mpi_file_read_wrapper(fh,ibuf(1:ndim), ndim, MPI_INTEGER,st,er)
    if (any(ibuf(1:ndim) /= [ block_nx1,block_nx2,block_nx3 ])) then
      write(*,*) "Error: block size differs from restart data:", ibuf(1:ndim)
      call mpistop("change block_nx^D in par file")
    end if

    ! From version 5, read more info about the grid
    if (version > 4) then
      call mpi_file_read_wrapper(fh, periodic, ndim, MPI_LOGICAL, st, er)
      if (periodic(1) .and. .not.periodB(1) .or. .not.periodic(1) .and. &
         periodB(1) .or. periodic(2) .and. .not.periodB(2) .or. &
         .not.periodic(2) .and. periodB(2) .or. periodic(3) .and. &
         .not.periodB(3) .or. .not.periodic(3) .and. periodB(3)) call &
         mpistop("change in periodicity in par file")

      call mpi_file_read_wrapper(fh, geom_name, name_len, MPI_CHARACTER, st, er)

      if (geom_name /= geometry_name(1:name_len)) then
        write(*,*) "type of coordinates in data is: ", geom_name
        call mpistop("select the correct coordinates in mod_usr.t file")
      end if

      call mpi_file_read_wrapper(fh, stagger_mark_dat, 1, MPI_LOGICAL, st, er)
      if (stagger_grid .and. .not. stagger_mark_dat .or. &
         .not.stagger_grid.and.stagger_mark_dat) then
        write(*,*) "Warning: stagger grid flag differs from restart data:",&
            stagger_mark_dat
        !call mpistop("change parameter to use stagger grid")
      end if
    end if

    ! From version 4 onwards, the later parts of the header must be present
    if (version > 3) then
      ! w_names (not used here)
      allocate(var_names(nw_found))
      do iw = 1, nw_found
        call mpi_file_read_wrapper(fh, var_names(iw), name_len, MPI_CHARACTER, st, er)
      end do

      ! Physics related information
      call mpi_file_read_wrapper(fh, phys_name, name_len, MPI_CHARACTER, st, er)

      if (phys_name /= physics_type) then
!        call mpistop("Cannot restart with a different physics type")
      end if

      call mpi_file_read_wrapper(fh, n_par, 1, MPI_INTEGER, st, er)
      allocate(params(n_par))
      allocate(param_names(n_par))
      call mpi_file_read_wrapper(fh, params, n_par, MPI_DOUBLE_PRECISION, st, er)
      call mpi_file_read_wrapper(fh, param_names, name_len * n_par, MPI_CHARACTER, st,&
          er)

      ! Read snapshotnext etc. for restarting
      call mpi_file_read_wrapper(fh, tmp_int, 1, MPI_INTEGER, st, er)

      ! Only set snapshotnext if the user hasn't specified it
      if (snapshotnext == -1) snapshotnext = tmp_int

      call mpi_file_read_wrapper(fh, tmp_int, 1, MPI_INTEGER, st, er)
      if (slicenext == -1) slicenext = tmp_int

      call mpi_file_read_wrapper(fh, tmp_int, 1, MPI_INTEGER, st, er)
      if (collapsenext == -1) collapsenext = tmp_int
    else
      ! Guess snapshotnext from file name if not set
      if (snapshotnext == -1) snapshotnext = &
         get_snapshot_index(trim(restart_from_file)) + 1
      ! Set slicenext and collapsenext if not set
      if (slicenext == -1) slicenext = 0
      if (collapsenext == -1) collapsenext = 0
    end if

    ! Still used in convert
    snapshotini = snapshotnext-1

  end subroutine snapshot_read_header