! $Id$ ! ! module cr_file_mdl use hdf5 implicit none type cr_file_type character ( len = 200) :: name character ( len = 300) :: path character ( len = 300) :: full_file integer (HID_T) :: file_id character ( len = 128) :: machine character ( len =128) :: sensor character ( len =128 ) :: l1b_filename contains procedure :: create procedure :: add_attribute_char procedure :: add_attribute_int procedure :: add_attribute_real end type cr_file_type contains subroutine create ( self ) class ( cr_file_type ) :: self ! - h5 stuff integer :: hdferr integer :: arank integer (hsize_t) , dimension(1) :: adims = 1 integer ( hid_t) :: aspace_id integer ( HID_T) :: atype_id integer ( hid_t) :: attr_id integer ( size_t) :: attrlen character ( len =10) :: aname INTEGER, DIMENSION(7) :: data_dims CHARACTER(LEN=7), PARAMETER :: groupname = "./dfe" ! Group name INTEGER(HID_T) :: group_id ! Group identifier character(len=80) :: created TYPE(C_PTR) :: f_ptr character ( len=128) :: avalue integer :: l =8 real :: w=33.3 ! ------ attrlen = 10 created ='A.Walther' aname ='Created' call h5open_f ( hdferr ) call h5fcreate_f(self % full_file , H5F_ACC_TRUNC_F, self % file_id , hdferr) ! ! Create a group named "/MyGroup" in the file. ! self % machine = 'LUNA' self % sensor = 'VIIRS' self % l1b_filename = 'GSVDB_2012013014.h5' aname = 'Machine' call self % add_attribute_char ( self % file_id , aname, self % machine ) aname ='Sensor' call self % add_attribute_char ( self % file_id , aname, self % sensor ) aname ='l1b_filename' call self % add_attribute_char ( self % file_id , aname, self % l1b_filename ) ! ! Close the attribute. ! call h5fclose_f ( self % file_id , hdferr) end subroutine create subroutine add_attribute_char ( self , grp_id , aname , avalue ) USE ISO_C_BINDING class ( cr_file_type ) :: self INTEGER(HID_T) :: grp_id ! Group identifier integer :: arank integer (hsize_t) , dimension(1) :: adims = 1 integer ( hid_t) :: aspace_id integer :: hdferr integer ( HID_T) :: atype_id integer ( size_t) :: attrlen character ( len =10) :: aname character ( len=128) :: avalue TYPE(C_PTR) :: f_ptr integer ( hid_t) :: attr_id INTEGER, DIMENSION(7) :: data_dims attrlen = len_trim(avalue) arank = 1 CALL h5screate_simple_f(arank, adims, aspace_id, hdferr) CALL h5tcopy_f(H5T_NATIVE_CHARACTER, atype_id, hdferr) CALL h5tset_size_f(atype_id, attrlen, hdferr) CALL h5acreate_f( grp_id , aname, atype_id, aspace_id, & attr_id, hdferr) data_dims(1) = 2 f_ptr = C_LOC(avalue) CALL h5awrite_f(attr_id, atype_id, f_ptr, hdferr) CALL h5aclose_f(attr_id, hdferr) end subroutine add_attribute_char subroutine add_attribute_int ( self , grp_id , aname , avalue ) USE ISO_C_BINDING class ( cr_file_type ) :: self INTEGER(HID_T) :: grp_id ! Group identifier integer :: arank integer (hsize_t) , dimension(1) :: adims = 1 integer ( hid_t) :: aspace_id integer :: hdferr integer ( HID_T) :: atype_id integer ( size_t) :: attrlen character ( len =10) :: aname integer :: avalue TYPE(C_PTR) :: f_ptr integer ( hid_t) :: attr_id INTEGER, DIMENSION(7) :: data_dims attrlen =10 arank = 1 CALL h5screate_simple_f(arank, adims, aspace_id, hdferr) CALL h5tcopy_f(H5T_NATIVE_INTEGER, atype_id, hdferr) CALL h5tset_size_f(atype_id, attrlen, hdferr) CALL h5acreate_f( grp_id , aname, atype_id, aspace_id, & attr_id, hdferr) data_dims(1) = 2 f_ptr = C_LOC(avalue) CALL h5awrite_f(attr_id, atype_id, f_ptr, hdferr) CALL h5aclose_f(attr_id, hdferr) end subroutine add_attribute_int subroutine add_attribute_real ( self , grp_id , aname , avalue ) USE ISO_C_BINDING class ( cr_file_type ) :: self INTEGER(HID_T) :: grp_id ! Group identifier integer :: arank integer (hsize_t) , dimension(1) :: adims = 1 integer ( hid_t) :: aspace_id integer :: hdferr integer ( HID_T) :: atype_id integer ( size_t) :: attrlen character ( len =10) :: aname real :: avalue TYPE(C_PTR) :: f_ptr integer ( hid_t) :: attr_id INTEGER, DIMENSION(7) :: data_dims attrlen =10 arank = 1 CALL h5screate_simple_f(arank, adims, aspace_id, hdferr) CALL h5tcopy_f(H5T_NATIVE_REAL, atype_id, hdferr) CALL h5tset_size_f(atype_id, attrlen, hdferr) CALL h5acreate_f( grp_id , aname, atype_id, aspace_id, & attr_id, hdferr) data_dims(1) = 2 f_ptr = C_LOC(avalue) CALL h5awrite_f(attr_id, atype_id, f_ptr, hdferr) CALL h5aclose_f(attr_id, hdferr) end subroutine add_attribute_real end module cr_file_mdl