subroutine hdf5_data_create(tbl, group_id, time_id, name, vars, comps)
type(growing_h5_tbl_t), intent(inout) :: tbl
integer(hid_t), intent(in) :: group_id, time_id
character(*), intent(in) :: name,vars(:)
type(hdf_desc_p_t), intent(inout) :: comps(:)
type(hdf_desc_t), allocatable :: components(:)
integer(hid_t) :: x_id, var_id, name_id, cmp_id
integer(hsize_t) :: dims(8)
real(dp), allocatable :: x(:)
integer(hsize_t), allocatable :: size_attr(:), size_cmp(:), size_name(:), size_var(:)
integer, allocatable :: int_attr(:)
character(:), allocatable :: str_attr(:), str_cmp(:), str_name(:), tmp_str
character(9) :: num_str
integer :: i,j,cell,cell_tot,err,str_trim
cell_tot = 0
allocate(components(size(comps)))
do i = 1, size(comps)
components(i) = comps(i)%p
cell_tot = cell_tot + size(components(i)%node_x)
enddo
if (cell_tot == 0) return
j = 0 ! finding longest component name and allocate required arrays
do i = 1, size(components)
j = max(j,len(components(i)%name))
enddo
allocate(character(j) :: str_attr(size(components)))
allocate( size_attr(size(components)))
allocate( int_attr(size(components)))
allocate( x(cell_tot))
allocate(character(j) :: str_cmp(cell_tot))
allocate( size_cmp(cell_tot))
allocate(character(j+9) :: str_name(cell_tot))
allocate( size_name(cell_tot))
size_var = len_trim(vars)
cell = 0 ! fill arrays: loop over component and later on node
do i = 1, size(components)
j = size(components(i)%node_x)
int_attr(i) = j
x(cell+1:cell+j) = components(i)%node_x
str_attr(i) = components(i)%name
size_attr(i) = len(components(i)%name)
write(num_str,'(i0)'),j
str_trim = len_trim(num_str)
str_cmp(cell+1:cell+j) = components(i)%name
size_cmp(cell+1:cell+j) = len(components(i)%name)
size_name(cell+1:cell+j) = len(components(i)%name) + str_trim + 1
tmp_str = '(i'//to_str(str_trim+1)//'.'//to_str(str_trim)//')'
do j = 1, size(components(i)%node_x)
write(num_str,tmp_str),j
str_name(cell+j) = components(i)%name//num_str
enddo
cell = cell + j - 1
enddo
call tbl_h5_create_dbl(tbl,group_id,name,tbl%data)
call write_vstr1d(group_id,name//'_cmp',str_cmp,size_cmp,cmp_id)
call write_vstr1d(group_id,name//'_name',str_name,size_name,name_id)
dims = 0
dims(1) = cell
call h5ltmake_dataset_f(group_id,name//'_x',1,dims,H5T_NATIVE_DOUBLE,x,err)
call h5dopen_f(group_id,name//'_x',x_id,err)
call write_vstr1d(group_id,name//'_var',vars,size_var,var_id)
call attach_scale(time_id, tbl%dset, 3, 't', 't')
call attach_scale(var_id, tbl%dset, 1, 'var','var')
call attach_scale(x_id, tbl%dset, 2, 'x')
call attach_scale(cmp_id, tbl%dset, 2, 'cmp')
call attach_scale(name_id, tbl%dset, 2, 'name','name')
! Writing attributes
call write_atribute_int(tbl%dset,'nodes',int_attr)
call write_attribute_vstr1d(tbl%dset,'names',str_attr,size_attr)
call h5dclose_f(var_id,err)
call h5dclose_f(name_id,err)
call h5dclose_f(x_id,err)
call h5dclose_f(cmp_id,err)
end subroutine hdf5_data_create