write_data Subroutine

private subroutine write_data(this, outfile)

Writes the data describing the cryosphere to the disc as an HDF5 file. h5open_f must have been called once prior to using this method. After the method has been used, h5close_f must be called once before the end of the program.

Arguments

Type IntentOptional AttributesName
class(cryosphere), intent(in) :: this
character(len=*), intent(in) :: outfile

The file to which to write the data describing the state of the cryosphere


Calls

proc~~write_data~~CallsGraph proc~write_data write_data proc~current_time current_time proc~write_data->proc~current_time interface~version version proc~write_data->interface~version str str proc~write_data->str h5ltset_attribute_double_f h5ltset_attribute_double_f proc~write_data->h5ltset_attribute_double_f h5fcreate_f h5fcreate_f proc~write_data->h5fcreate_f h5fclose_f h5fclose_f proc~write_data->h5fclose_f interface~compile_time compile_time proc~write_data->interface~compile_time proc~version version interface~version->proc~version proc~compile_time compile_time interface~compile_time->proc~compile_time

Contents

Source Code


Source Code

  subroutine write_data(this,outfile)
    !* Author: Christopher MacMackin
    !  Date: April 2016
    !
    ! Writes the data describing the cryosphere to the disc as an HDF5
    ! file. `h5open_f` must have been called once prior to using this
    ! method. After the method has been used, `h5close_f` must be
    ! called once before the end of the program.
    !
    class(cryosphere), intent(in) :: this
    character(len=*), intent(in)  :: outfile
      !! The file to which to write the data describing the state of the 
      !! cryosphere
    integer(hid_t) :: file_id, error_code
    call h5fcreate_f(outfile, H5F_ACC_TRUNC_F, file_id, error_code)
    if (error_code /= 0) then
      call logger%error('cryosphere%write_data','Error code '//    &
                        trim(str(error_code))//' returned when '// &
                        'creating HDF5 file '//outfile)
      return
    end if

    ! Write any whole-system data...
    call h5ltset_attribute_string_f(file_id,'/',hdf_version,version(),error_code)
    call h5ltset_attribute_string_f(file_id,'/',hdf_comp_time,compile_time(), &
                                    error_code)
    call h5ltset_attribute_string_f(file_id,'/',hdf_write_time,current_time(), &
                                    error_code)
    call h5ltset_attribute_double_f(file_id,'/',hdf_simulation_time,[this%time], &
                                    1_size_t,error_code)
    if (error_code /= 0) then
      call logger%warning('cryosphere%write_data','Error code '//    &
                          trim(str(error_code))//' returned when '// &
                          'writing attributes to HDF5 file '//outfile)
    end if
    
    ! Call for subobjects
    call this%ice%write_data(file_id, hdf_glacier, error_code)
    call this%sub_ice%write_data(file_id, hdf_basal, error_code)

    call h5fclose_f(file_id, error_code)
    if (error_code /= 0) then
      call logger%warning('cryosphere%write_data','Error code '//    &
                          trim(str(error_code))//' returned when '// &
                          'closing HDF5 file '//outfile)
    end if

#ifdef DEBUG
    call logger%debug('cryosphere%write_data','Wrote cryosphere data to '// &
                      'HDF file '//outfile//' at simulation time '//        &
                      trim(str(this%time)))
#endif
  end subroutine write_data