shelf_write_data Subroutine

private subroutine shelf_write_data(this, file_id, group_name, error)

Writes the state of the ice shelf object to an HDF file in the specified group. This will consist of a thickness and a velocity dataset.

Arguments

Type IntentOptional AttributesName
class(ice_shelf), intent(in) :: this
integer(kind=hid_t), intent(in) :: file_id

The identifier for the HDF5 file/group in which this data is meant to be written.

character(len=*), intent(in) :: group_name

The name to give the group in the HDF5 file storing the ice shelf's data.

integer, intent(out) :: error

Flag indicating whether routine ran without error. If no error occurs then has value 0.


Calls

proc~~shelf_write_data~~CallsGraph proc~shelf_write_data shelf_write_data h5ltset_attribute_string_f h5ltset_attribute_string_f proc~shelf_write_data->h5ltset_attribute_string_f h5gcreate_f h5gcreate_f proc~shelf_write_data->h5gcreate_f h5ltset_attribute_int_f h5ltset_attribute_int_f proc~shelf_write_data->h5ltset_attribute_int_f str str proc~shelf_write_data->str h5ltset_attribute_double_f h5ltset_attribute_double_f proc~shelf_write_data->h5ltset_attribute_double_f h5gclose_f h5gclose_f proc~shelf_write_data->h5gclose_f

Contents

Source Code


Source Code

  subroutine shelf_write_data(this,file_id,group_name,error)
    !* Author: Chris MacMackin
    !  Date: November 2016
    !
    ! Writes the state of the ice shelf object to an HDF file in the
    ! specified group. This will consist of a thickness and a velocity
    ! dataset.
    !
    class(ice_shelf), intent(in) :: this
    integer(hid_t), intent(in)   :: file_id
      !! The identifier for the HDF5 file/group in which this data is
      !! meant to be written.
    character(len=*), intent(in) :: group_name
      !! The name to give the group in the HDF5 file storing the
      !! ice shelf's data.
    integer, intent(out)         :: error
      !! Flag indicating whether routine ran without error. If no
      !! error occurs then has value 0.
    integer(hid_t) :: group_id
    integer :: ret_err, i, nkap
    character(len=20) :: fieldname

    ret_err = 0
    call h5gcreate_f(file_id, group_name, group_id, error)
    if (error /= 0) then
      call logger%warning('ice_shelf%write_data','Error code '// &
                          trim(str(error))//' returned when '//  &
                          'creating HDF group "'//group_name//'"')
      call logger%error('ice_shelf%write_data','Data IO not performed for '// &
                        'ice shelf')
      return
    end if

    if (allocated(this%kappa)) then
      nkap = size(this%kappa)
    else
      nkap = 0
    end if

    call h5ltset_attribute_string_f(file_id, group_name, hdf_type_attr, &
                                    hdf_type_name, error)
    call h5ltset_attribute_double_f(file_id, group_name, hdf_lambda, &
                                    [this%lambda], 1_size_t, error)
    call h5ltset_attribute_double_f(file_id, group_name, hdf_chi, &
                                    [this%chi], 1_size_t, error)
    call h5ltset_attribute_double_f(file_id, group_name, hdf_zeta, &
                                    [this%zeta], 1_size_t, error)
    call h5ltset_attribute_int_f(file_id, group_name, hdf_n_kappa, &
                                 [nkap], 1_size_t, error)
    if (error /= 0) then
      call logger%warning('ice_shelf%write_data','Error code '// &
                          trim(str(error))//' returned when '//  &
                          'writing attribute to HDF group '//    &
                          group_name)
      ret_err = error
    end if

    call this%thickness%write_hdf(group_id, hdf_thickness, error)
    if (error /= 0) then
      call logger%warning('ice_shelf%write_data','Error code '//        &
                          trim(str(error))//' returned when writing '// &
                          'ice shelf thickness field to HDF file')
      if (ret_err == 0) ret_err = error
    end if

    call this%velocity%write_hdf(group_id, hdf_velocity, error)
    if (error /= 0) then
      call logger%warning('ice_shelf%write_data','Error code '// &
                          trim(str(error))//' returned when '//  &
                          'writing ice shelf velocity field '//  &
                          'to HDF file')
      if (ret_err == 0) ret_err = error
    end if

    do i = 1, nkap
      write(fieldname , hdf_kappa) i
      call this%kappa(i)%write_hdf(group_id, trim(fieldname), error)
      if (error /= 0) then
        call logger%warning('ice_shelf%write_data','Error code '// &
                            trim(str(error))//' returned when '//  &
                            'writing ice shelf kappa field '//  &
                            'to HDF file')
        if (ret_err == 0) ret_err = error
      end if
    end do

    call h5gclose_f(group_id, error)
    if (error /= 0) then
      call logger%warning('ice_shelf%write_data','Error code '// &
                          trim(str(error))//' returned when '//  &
                          'closing HDF group '//group_name)
      if (ret_err == 0) ret_err = error
    end if
    error = ret_err
    call logger%trivia('ice_shelf%write_data','Wrote ice shelf data to '// &
                       'HDF group '//group_name)
  end subroutine shelf_write_data