Skip to content

Commit fc4981e

Browse files
committed
Added deletion feature of datasets/groups/attributes.
1 parent a00b1e8 commit fc4981e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ program attributes
195195
end program
196196
```
197197

198+
## Deletion
199+
200+
| hdf5 command | description |
201+
| ---------------------------------------------------- | ------------------------------------ |
202+
| `hdf5_delete(ifile, location)` | delete group/dataset |
203+
| `hdf5_delete_attribute(ifile, location, attr_name)` | delete attribute |
204+
205+
Deletion of datasets and groups is internally done simply by unlinking the objects.
206+
198207
## Summary of commands
199208

200209
| hdf5 command | description |
@@ -217,6 +226,8 @@ end program
217226
| `hdf5_read_attribute(ifile, location, attr_name, variable)` | read attribute |
218227
| `hdf5_get_number_attributes(ifile, location)` | get number of attributes |
219228
| `hdf5_list_attributes(ifile, location, list)` | get list of attributes |
229+
| `hdf5_delete(ifile, location)` | delete group/dataset |
230+
| `hdf5_delete_attribute(ifile, location, attr_name)` | delete attribute |
220231

221232
## Future Features
222233

hdf5_wrapper.f90

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,23 @@ subroutine hdf5_list_attributes(ifile, location, attrs)
28962896
enddo
28972897
end subroutine
28982898

2899+
subroutine hdf5_delete_attribute(ifile, location, attr)
2900+
integer(hid_t), intent(in) :: ifile
2901+
character(len=*), intent(in) :: location
2902+
character(len=*), intent(in) :: attr
2903+
2904+
integer(hid_t) :: obj_id
2905+
call h5oopen_f(ifile, trim(adjustl(location)), obj_id, hdf_err)
2906+
call h5adelete_f(obj_id, attr, hdf_err)
2907+
call h5oclose_f(obj_id, hdf_err)
2908+
end subroutine hdf5_delete_attribute
2909+
2910+
subroutine hdf5_delete(ifile, location)
2911+
integer(hid_t), intent(in) :: ifile
2912+
character(len=*), intent(in) :: location
2913+
call h5ldelete_f(ifile, location, hdf_err)
2914+
end subroutine hdf5_delete
2915+
28992916
! help function with separates /group1/group2/dset -> /group1/group2 and dset
29002917
subroutine hdf5_help_separate_dsetname(dsetfull, gname, dset)
29012918
character(len=*), intent(in) :: dsetfull

test_examples.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ program bla
4747
call hdf5_write_attribute(ifile, 'group1/group2', 'att2', 123)
4848
call hdf5_write_attribute(ifile, 'dataset1', 'att3', 1.22d-2)
4949

50+
call hdf5_delete_attribute(ifile, 'dataset1', 'att3')
51+
5052
! close the file again
5153
call hdf5_close_file(ifile)
5254

5355

5456

57+
5558
! open the file again in readonly mode
5659
call hdf5_open_file('test.hdf5', ifile, rdonly=.true.)
5760

0 commit comments

Comments
 (0)