1 Introduction to HDF5 Programming and Tools Boeing September 19, 2006.

Slides:



Advertisements
Similar presentations
MPI Message Passing Interface
Advertisements

A PLFS Plugin for HDF5 for Improved I/O Performance and Analysis Kshitij Mehta 1, John Bent 2, Aaron Torres 3, Gary Grider 3, Edgar Gabriel 1 1 University.
The HDF Group November 3-5, 2009HDF/HDF-EOS Workshop XIII1 HDF-Java Products Peter Cao The HDF Group The 13 th HDF and HDF-EOS Workshop.
The HDF Group November 3-5, 2009HDF/HDF-EOS Workshop XIII1 HDF5 Advanced Topics Elena Pourmal The HDF Group The 13 th HDF and HDF-EOS.
11/6/07HDF and HDF-EOS Workshop XI, Landover, MD1 Introduction to HDF5 HDF and HDF-EOS Workshop XI November 6-8, 2007.
10/15/08HDF & HDF-EOS Workshop XII11 Introduction to HDF5 HDF & HDF-EOS Workshop XII October 15, 2008.
NetCDF An Effective Way to Store and Retrieve Scientific Datasets Jianwei Li 02/11/2002.
HDF4 and HDF5 Performance Preliminary Results Elena Pourmal IV HDF-EOS Workshop September
The HDF Group Introduction to HDF5 Barbara Jones The HDF Group The 13 th HDF & HDF-EOS Workshop November 3-5, HDF/HDF-EOS Workshop.
University of Illinois at Urbana-ChampaignHDF Mike Folk HDF-EOS Workshop IV Sept , 2000 HDF Update HDF.
Status of netCDF-3, netCDF-4, and CF Conventions Russ Rew Community Standards for Unstructured Grids Workshop, Boulder
© 2008The MathWorks, Inc. ® ® The MATLAB Low-Level HDF5 Interface John Evans.
March 9, th International LCI Conference - HDF5 Tutorial1 Tutorial II: HDF5 and NetCDF-4 10 th International LCI Conference Albert Cheng, Neil Fortner.
Ensuring Long Term Access to Remotely Sensed HDF4 Data with Layout Maps Mike Folks, The HDF Group Ruth Duerr, NSIDC 1.
Euratom – ENEA Association Commonalities and differences between MDSplus and HDF5 data systems G. Manduchi Consorzio RFX, Euratom-ENEA Association, corso.
1 of 14 Substituting HDF5 tools with Python/H5py scripts Daniel Kahn Science Systems and Applications Inc. HDF HDF-EOS Workshop XIV, 28 Sep
HDF5 Tools Update Peter Cao - The HDF Group November 6, 2007 This report is based upon work supported in part by a Cooperative Agreement.
Parallel HDF5 Introductory Tutorial May 19, 2008 Kent Yang The HDF Group 5/19/20081SCICOMP 14 Tutorial.
HDF 1 HDF5 Advanced Topics Object’s Properties Storage Methods and Filters Datatypes HDF and HDF-EOS Workshop VIII October 26, 2004.
The HDF Group April 17-19, 2012HDF/HDF-EOS Workshop XV1 Introduction to HDF5 Barbara Jones The HDF Group The 15 th HDF and HDF-EOS Workshop.
1 High level view of HDF5 Data structures and library HDF Summit Boeing Seattle September 19, 2006.
HDF5 A new file format & software for high performance scientific data management.
Sep , 2010HDF/HDF-EOS Workshop XIV1 HDF5 Advanced Topics Neil Fortner The HDF Group The 14 th HDF and HDF-EOS Workshop September 28-30, 2010.
The HDF Group Parallel HDF5 Design and Programming Model May 30-31, 2012HDF5 Workshop at PSI 1.
A Metadata Based Approach For Supporting Subsetting Queries Over Parallel HDF5 Datasets Vignesh Santhanagopalan Graduate Student Department Of CSE.
February 2-3, 2006SRB Workshop, San Diego P eter Cao, NCSA Mike Wan, SDSC Sponsored by NLADR, NFS PACI Project in Support of NCSA-SDSC Collaboration Object-level.
1 Introduction to HDF5 Data Model, Programming Model and Library APIs HDF and HDF-EOS Workshop VIII October 26, 2004.
April 28, 2008LCI Tutorial1 HDF5 Tutorial LCI April 28, 2008.
May 30-31, 2012HDF5 Workshop at PSI1 HDF5 at Glance Quick overview of known topics.
The HDF Group HDF5 Datasets and I/O Dataset storage and its effect on performance May 30-31, 2012HDF5 Workshop at PSI 1.
The netCDF-4 data model and format Russ Rew, UCAR Unidata NetCDF Workshop 25 October 2012.
The HDF Group HDF5 Tools Updates Peter Cao, The HDF Group September 28-30, 20101HDF and HDF-EOS Workshop XIV.
HDF Dimension Scales in HDF5 HDF-EOS Workshop IX San Francisco, CA November 30 - December 2, 2005 Pedro Vicente Nunes THG/NCSA Champaign-Urbana, IL HDF.
The HDF Group October 28, 2010NetcDF Workshop1 Introduction to HDF5 Quincey Koziol The HDF Group Unidata netCDF Workshop October 28-29,
Support for NPP/NPOESS by The HDF Group Mike Folk The HDF Group HDF and HDF-EOS Workshop XII October 17, 2008 Oct HDF and HDF-EOS Workshop XII1.
October 15, 2008HDF and HDF-EOS Workshop XII1 What will be new in HDF5?
1 N-bit and ScaleOffset filters MuQun Yang National Center for Supercomputing Applications University of Illinois at Urbana-Champaign Urbana, IL
1 HDF5 Life cycle of data Boeing September 19, 2006.
1 Introduction to HDF5 Data Model, Programming Model and Library APIs HDF and HDF-EOS Workshop IX November 30, 2005.
- 1 - HDF5, HDF-EOS and Geospatial Data Archives HDF and HDF-EOS Workshop VII September 24, 2003.
HDF Hierarchical Data Format Nancy Yeager Mike Folk NCSA University of Illinois at Urbana-Champaign, USA
The HDF Group November 3-5, 2009HDF/HDF-EOS Workshop XIII1 HDF5 Advanced Topics Elena Pourmal The HDF Group The 13 th HDF and HDF-EOS.
1 Error Handling Interface HDF-EOS Workshop IX Quincey Koziol and Ray Lu 30 Nov 2005.
September 9, 2008SPEEDUP Workshop - HDF5 Tutorial1 Introduction to HDF5 Command-line Tools.
The HDF Group Introduction to netCDF-4 Elena Pourmal The HDF Group 110/17/2015.
HDF5 Q4 Demo. Architecture Friday, May 10, 2013 Friday Seminar2.
The HDF Group Single Writer/Multiple Reader (SWMR) 110/17/15.
March 9, th International LCI Conference - HDF5 Tutorial1 HDF5 Advanced Topics.
The HDF Group 10/17/15 1 HDF5 vs. Other Binary File Formats Introduction to the HDF5’s most powerful features ICALEPCS 2015.
Intro to Parallel HDF5 10/17/151ICALEPCS /17/152 Outline Overview of Parallel HDF5 design Parallel Environment Requirements Performance Analysis.
October 15-17, 2008HDF and HDF-EOS Workshop XII1 HDF-Java Products Peter Cao The HDF Group HDF and HDF-EOS Workshop XII October 15, 2008.
April 28, 2008LCI Tutorial1 Parallel HDF5 Tutorial Tutorial Part IV.
September 9, 2008SPEEDUP Workshop - HDF5 Tutorial1 HDF5 Tutorial 37 th SPEEDUP Workshop on HPC Albert Cheng, Elena Pourmal The HDF Group.
Support for NPP/NPOESS by The HDF Group Mike Folk, Elena Pourmal The HDF Group Annual HDF Briefing to ESDIS March 31, 2009 March Annual HDF Briefing.
The HDF Group 10/17/151 Introduction to HDF5 ICALEPCS 2015.
The HDF Group Introduction to HDF5 Session Two Data Model Comparison HDF5 File Format 1 Copyright © 2010 The HDF Group. All Rights Reserved.
The HDF Group Introduction to HDF5 Session 7 Datatypes 1 Copyright © 2010 The HDF Group. All Rights Reserved.
Copyright © 2010 The HDF Group. All Rights Reserved1 Data Storage and I/O in HDF5.
- 1 - Overview of Parallel HDF Overview of Parallel HDF5 and Performance Tuning in HDF5 Library NCSA/University of Illinois at Urbana- Champaign.
The HDF Group Introduction to HDF5 Session Three HDF5 Software Overview 1 Copyright © 2010 The HDF Group. All Rights Reserved.
1 January 11-13, 2010ESRF Workshop – Introduction to HDF5 Introduction to HDF5 Francesc Alted Consultant and PyTables creator.
HDF and HDF-EOS Workshop XII
Adding CF Attributes to an HDF5 File
Parallel HDF5 Introductory Tutorial
Introduction to HDF5 Session Five Reading & Writing Raw Data Values
Introduction to HDF5 Tutorial.
Introduction to HDF5 for HDF4 users
HDF5 Virtual Dataset Elena Pourmal Copyright 2017, The HDF Group.
Introduction to HDF5 Mike McGreevy The HDF Group
Moving applications to HDF
Presentation transcript:

1 Introduction to HDF5 Programming and Tools Boeing September 19, 2006

2 Topics Creating an HDF5 file with HDFView Introduction to HDF5 API Getting to know the documentation Introduction to HDF5 Tools

3 Creating an HDF5 file with HDFView

4 curley 3-D array of floats larry “/” (root) Example: create this HDF5 file 4x6 array of floats

5 Introduction to HDF5 API Programming model for sequential access

6 HDF5 Software stack Tools & Applications HDF File HDF I/O Library

7 Virtual file I/O (C only)  Perform byte-stream I/O operations (open/close, read/write, seek)  User-implementable I/O (stdio, network, memory, etc.) Virtual file I/O (C only)  Perform byte-stream I/O operations (open/close, read/write, seek)  User-implementable I/O (stdio, network, memory, etc.) Library internals Performs data transformations and other prep for I/O Configurable transformations (compression, etc.) Library internals Performs data transformations and other prep for I/O Configurable transformations (compression, etc.) Structure of HDF5 Library Object API (C, Fortran 90, Java, C++)  Specify objects and transformation properties  Invoke data movement operations and data transformations Object API (C, Fortran 90, Java, C++)  Specify objects and transformation properties  Invoke data movement operations and data transformations

8 Goals of HDF5 Library Flexible API to support a wide range of operations on data High performance access in serial and parallel computing environments Compatibility with common data models and programming languages Because of these goals, the HDF5 API is rich and large

9 Operations supported by the API Create groups, datasets, attributes, linkages Create complex data types Assign storage and I/O properties to objects Complex subsetting during read/write Flexible I/O^tparallel, remote, etc. Ability to transform data during I/O Query about file and structure and properties Query about object structure, content, properties

10 Characteristics of the HDF5 API For flexibility, the API is extensive – 300+ functions This can be daunting, at first But there is hope You can do a lot with a just few functions So start simple, and build up your knowledge The library functions are categorized by object type Once you learn the system, it’s much less daunting And there is an “H5Lite” API if all you want to do are simple things.

11 The General HDF5 API Currently has C, Fortran 90, Java and C++ bindings. C routines begin with prefix H5*, where * is a single letter indicating the object on which the operation is to be performed. Full functionality Example APIs: H5D :Dataset interface e.g.. H5Dread H5F : File interface e.g.. H5Fopen H5S : dataSpace interfacee.g.. H5Sclose

12 The General Paradigm Properties (called creation and access property lists) of objects are defined (optional) Objects are opened or created Objects then accessed Objects finally closed

13 Order of Operations The library imposes an order on the operations by argument dependencies Example: A file must be opened before a dataset because the dataset open call requires a file handle as an argument Objects can be closed in any order, and reusing a closed object will result in an error

14 HDF5 C Programming Issues For portability, HDF5 library has its own defined types: hid_t: object identifiers (native integer) hsize_t: size used for dimensions (unsigned long or unsigned long long) hsize_t: for specifying coordinates and sometimes for dimensions (signed long or signed long long) herr_t: function return value hvl_t: variable length datatype For C, include #include hdf5.h at the top of your HDF5 application.

15 curley 3-D array of floats larry “/” (root) Example: create this HDF5 file 4x6 array of floats

16 curley 4x6 array of floats 3-D array of floats larry “/” (root) Steps:

17 3-D array of floats “/” (root) Create an HDF5 file

18 Steps to Create a File Decide any special properties the file should have Creation properties, like size of user block Access properties, such as metadata cache size Create property lists, if necessary Create the file Close the file and the property lists, as needed

19 Ex. 1 – Create new file with default properties 1 hid_t file_id; 2 herr_t status; 3 file_id = H5Fcreate ("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 4 status = H5Fclose (file_id);

20 4x6 array of floats curley 3-D array of floats “/” (root) Add a dataset

21 Dataset Components DataMetadata Dataspace 3 Rank Dim_2 = 5 Dim_1 = 4 Dimensions Time = 32.4 Pressure = 987 Temp = 56 Attributes Chunked Compressed Dim_3 = 7 Storage info IEEE 32-bit float Datatype

22 Dataset Creation Property List Dataset creation property list: information on how to organize data in storage. Chunked Chunked & compressed

23 3-D array of floats Steps to create a dataset in a file 1.Define dataset characteristics Dataspace – 4x6 Datatype – float Properties (if needed) 2.Decide where to put it – “root group” Obtain location ID 3.Decide link or path – “curley” 4.Create link and dataset in file 5.Close everything curley “/” (root)

24 1 hid_t file_id, dataset_id, dataspace_id; 2 hsize_t dims[2]; 3 herr_t status; 4 file_id = H5Fcreate ("dset.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 5 dims[0] = 4; 6 dims[1] = 6; 7 dataspace_id = H5Screate_simple (2, dims, NULL); 8 dataset_id = H5Dcreate(file_id,"dset",H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); 9 status = H5Dclose (dataset_id); 10 status = H5Sclose (dataspace_id); 11 status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset Terminate access to dataset, dataspace, & file Create a dataspace rank current dims Create a dataset Dataspace Datatype Property list (default) Pathname

25 curley 3-D array of floats larry “/” (root) Example: create this HDF5 file 4x6 array of floats

26 Creating a group To create a group, the calling program must: Obtain location identifier where group is to be created Create the group Close the group

27 Creating a group hid_t file_id, group_id; /* identifiers */... /* Open “file.h5” */ file_id = H5Fopen(“file.h5”, H5F_ACC_RDWR, H5P_DEFAULT); /* Create a group "/larry" in file. */ group_id = H5Gcreate(file_id,"/larry",0); /* Close the group and file. */ status = H5Gclose(group_id); Status = H5Fclose(file_id);

28 Getting to know the documentation

29

30

31

32

33

34

35

36 Introduction to HDF5 Tools

37 HDF5 Tools Examine or manage HDF5 files Convert data between HDF5 and other special- purpose formats Measure HDF5 library performance Manage HDF5 library and application compilation, installation and configuration

38 User utilities h5dump Examine HDF5 file, dump to ASCII file h5lsList specified features of HDF5 file contents h5diffCompare two HDF5 files and report the differences H5repackCopy HDF5 file to a new file with or without compression/chunking. H5perfMeasure HDF5 performance H5repartRepartition a file, creating a family of files H5jamAdd a user block to the front of an HDF5 file H5unjamSplit an existing user block from an HDF5 file, placing it in a separate file

39 Configuration and library management H5redeployUpdate HDF5 compiler tools after an HDF5 software installation in a new location H5cc/h5pccSimplify compiling HDF5 C programs H5fc/h5pfcSimplify compiling HDF5 Fortran90 programs h5c++Simplify compiling HDF5 C++ programs

40 H5dump – Command-line utility for Viewing HDF5 Files h5dump [--header] [-a ] [-d ] [-g ] [-l ] [-t ] --header Display header only; no data is displayed. -a Display the specified attribute(s). -d Display the specified dataset(s). -g Display the specified group(s) and all the members. -l Displays the value(s) of the specified soft link(s). -t Display the specified named datatype(s). is one or more appropriate object names.

41 HDF5 "dset.h5" { GROUP "/" { DATASET "dset" { DATATYPE { H5T_STD_I32BE } DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) } DATA { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 } “/” ‘dset’ Example of h5dump Output

42 End up with a live demo of HDFView

43 For more information… HDF website HDF5 Information Center HDF Helpdesk 5

44 Thank you This presentation is based upon work supported in part by a Cooperative Agreement with the National Aeronautics and Space Administration (NASA) under NASA grant NNG05GC60A. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of NASA. Other support provided by NCSA and other sponsors and agencies (

45 Extra slides

46 Writing and Reading Datasets

47 Dataset I/O = moving and transforming data between a file and memory

48 Dataset I/O Dataset I/O involves reading or writing all or part of a dataset Compressed/uncompressed During I/O operations data is translated between the source & destination (file-memory, memory-file) Datatype conversion data types (e.g. 16-bit integer => 32-bit float) Other data transformation (checksum, compression) Dataspace conversion dataspace (e.g. 10x20 2d array => 200 1d array)

49 Partial I/O Selected elements (called selections) from source are mapped (read/written) to the selected elements in destination Selection Selections in memory can differ from selection in file Number of selected elements is always the same in source and destination Selection can be Hyperslabs (contiguous blocks, regularly spaced blocks) Points Results of set operations (union, difference, etc.) on hyperslabs or points

50 2D array of 16-bit ints3D array of 32-bit ints FileMemory Reading Dataset into Memory from File 2-d array Regularly spaced series of cubes The only restriction is that the number of selected elements on the left be the same as on the right.

51 2D array of 16-bit ints3D array of 32-bit ints FileMemory Reading Dataset into Memory from File Read

52 1hid_t file_id; 2hsize_t dims[2]; 3int data[6]={1,2,3,4,5,6}; 4herr_t status; 5file_id = H5Fcreate ("ex_lite1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 6dims[0] = 2; 7dims[1] = 3; 8status = H5LTmake_dataset(file_id,"/dset",2,dims, H5T_NATIVE_INT,data); 9status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset

53 Example HDF5 Application #include #include "H5IM.h" #define WIDTH 57 /* dataset dimensions and rank */ #define HEIGHT 57 #define RANK 2 int main (void) { hid_t file; /* file handle */ herr_t status; unsigned char data[WIDTH][HEIGHT]; /* data to write */ int i, j, num, val; FILE *fp;

54 Example HDF5 Application /* Open ASCII file */ fp = fopen ("storm110.txt", "r"); /* Read Values into ‘data’ buffer */ for (i=0; i<WIDTH; i++) for (j=0; j<HEIGHT; j++) { num = fscanf (fp, "%d ", &val); data[i][j] = val; } /* Create File */ file = H5Fcreate ("storm.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* Create Image */ status = H5IMmake_image_8bit (file, "Storm_Image", WIDTH, HEIGHT, (const unsigned char *)data); /* Close File */ status = H5Fclose(file); }

55 Groups & members of groups can be shared /tom/P /dick/R /harry/P “/” tom dick harry P R P

56 Goals Describe the HDF5 programming model Give a feel for what it’s like to use the general HDF5 API Review some of the key concepts of HDF5

57 General API Topics General info about HDF5 programming Creating an HDF5 file Creating a dataset Writing and reading a dataset

58 Creating an HDF5 File

59 Steps to Create a File Specify File Creation and Access Property Lists, if necessary Create a file Close the file and the property lists, if necessary

60 Property Lists A property list is a collection of values that can be passed to HDF5 functions at lower layers of the library File Creation Property List Controls file metadata Size of the user-block, sizes of file data structures, etc. Specifying H5P_DEFAULT uses the default values Access Property List Controls different methods of performing I/O on files Unbuffered I/O, parallel I/O, etc. Specifying H5P_DEFAULT uses the default values.

61 hid_t H5Fcreate (const char *name, unsigned flags, hid_t create_id, hid_t access_id) name IN: Name of the file to access flags IN: File access flags create_id IN:File creation property list identifier access_id IN:File access property list identifier

62 file_id IN:Identifier of the file to terminate access to herr_t H5Fclose (hid_t file_id)

63 Example 1 1 hid_t file_id; 2 herr_t status; 3 file_id = H5Fcreate ("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 4 status = H5Fclose (file_id); Create a new file using default properties

64 Example 1 1 hid_t file_id; 2 herr_t status; 3 file_id = H5Fcreate ("file.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 4 status = H5Fclose (file_id); Terminate access to the File

65 h5_crtfile.c 1 #include 2 #define FILE "file.h5" 3 4 main() { 5 6 hid_t file_id; /* file identifier */ 7 herr_t status; 8 9 /* Create a new file using default properties. */ 10 file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); /* Terminate access to the file. */ 13 status = H5Fclose (file_id); 14 }

66 Example 1: h5dump Output HDF5 "file.h5" { GROUP "/" { } ‘/’

67 Create a Dataset

68 Dataset Components DataMetadata Dataspace 3 Rank Dim_2 = 5 Dim_1 = 4 Dimensions Time = 32.4 Pressure = 987 Temp = 56 Attributes Chunked Compressed Dim_3 = 7 Storage info IEEE 32-bit float Datatype

69 Steps to Create a Dataset Obtain location ID where dataset is to be created Define dataset characteristics (datatype, dataspace, dataset creation property list, if necessary) Create the dataset Close the datatype, dataspace, and property list, if necessary Close the dataset

70 Step 1 Step 1. Obtain the location identifier where the dataset is to be created Location Identifier: the file or group identifier in which to create a dataset

71 Step 2 Step 2. Define the dataset characteristics datatype (e.g. integer) dataspace (2 dimensions: 100x200) dataset creation properties (e.g. chunked and compressed)

72 Standard Predefined Datatypes Examples: H5T_IEEE_F64LE Eight-byte, little-endian, IEEE floating-point H5T_IEEE_F32BE Four-byte, big-endian, IEEE floating point H5T_STD_I32LE Four-byte, little-endian, signed two's complement integer H5T_STD_U16BE Two-byte, big-endian, unsigned integer NOTE: These datatypes (DT) are the same on all platforms These are DT handles generated at run-time

73 Standard Predefined Datatypes Examples: H5T_IEEE_F64LE Eight-byte, little-endian, IEEE floating-point H5T_IEEE_F32BE Four-byte, big-endian, IEEE floating point H5T_STD_I32LE Four-byte, little-endian, signed two's complement integer H5T_STD_U16BE Two-byte, big-endian, unsigned integer Architecture Programming Type

74 Native Predefined Datatypes Examples of predefined native types in C: H5T_NATIVE_INT (int) H5T_NATIVE_FLOAT (float ) H5T_NATIVE_UINT (unsigned int) H5T_NATIVE_LONG (long ) H5T_NATIVE_CHAR (char ) NOTE: These datatypes are NOT the same on all platforms These are DT handles generated at run-time

75 Dataspaces Dataspace: size and shape of dataset and subset Dataset Rank: number of dimension Dimensions: sizes of all dimensions Permanent – part of dataset definition Subset Size, shape and position of selected elements Needed primarily during I/O operations Not permanent (Subsetting not covered in this tutorial) Applies to arrays in memory or in the file

76 rank IN: Number of dimensions of dataspace dims IN: An array of the size of each dimension maxdims IN: An array of the maximum size of each dimension A value of H5S_UNLIMITED specifies the unlimited dimension. A value of NULL specifies that dims and maxdims are the same. Creating a Simple Dataspace hid_t H5Screate_simple (int rank, const hsize_t * dims, const hsize_t *maxdims)

77 Dataset Creation Property List The dataset creation property list contains information on how to organize data in storage. Chunked Chunked & compressed

78 Property List Example Creating a dataset with ``deflate'' compression create_plist_id = H5Pcreate(H5P_DATASET_CREATE); H5Pset_chunk(create_plist_id, ndims, chunk_dims); H5Pset_deflate(create_plist_id, 9);

79 Remaining Steps to Create a Dataset Create the dataset Close the datatype, dataspace, and property list, if necessary Close the dataset

80 loc_id IN: Identifier of file or group to create the dataset within name IN: The name of (the link to) the dataset to create type_id IN: Identifier of datatype to use when creating the dataset space_id IN: Identifier of dataspace to use when creating the dataset create_plist_id IN: Identifier of the dataset creation property list (or H5P_DEFAULT ) hid_t H5Dcreate (hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t create_plist_id)

81 1 hid_t file_id, dataset_id, dataspace_id; 2 hsize_t dims[2]; 3 herr_t status; 4 file_id = H5Fcreate ("dset.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 5 dims[0] = 4; 6 dims[1] = 6; 7 dataspace_id = H5Screate_simple (2, dims, NULL); 8 dataset_id = H5Dcreate(file_id,"dset",H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); 9 status = H5Dclose (dataset_id); 10 status = H5Sclose (dataspace_id); 11 status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset Create a new file

82 1 hid_t file_id, dataset_id, dataspace_id; 2 hsize_t dims[2]; 3 herr_t status; 4 file_id = H5Fcreate ("dset.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 5 dims[0] = 4; 6 dims[1] = 6; 7 dataspace_id = H5Screate_simple (2, dims, NULL); 8 dataset_id = H5Dcreate(file_id,"dset",H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); 9 status = H5Dclose (dataset_id); 10 status = H5Sclose (dataspace_id); 11 status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset Create a dataspace rank Set maxdims to current dims current dims

83 1 hid_t file_id, dataset_id, dataspace_id; 2 hsize_t dims[2]; 3 herr_t status; 4 file_id = H5Fcreate ("dset.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 5 dims[0] = 4; 6 dims[1] = 6; 7 dataspace_id = H5Screate_simple (2, dims, NULL); 8 dataset_id = H5Dcreate(file_id,"dset",H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); 9 status = H5Dclose (dataset_id); 10 status = H5Sclose (dataspace_id); 11 status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset Create a dataset Dataspace Datatype Property list (default) Pathname

84 1 hid_t file_id, dataset_id, dataspace_id; 2 hsize_t dims[2]; 3 herr_t status; 4 file_id = H5Fcreate ("dset.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 5 dims[0] = 4; 6 dims[1] = 6; 7 dataspace_id = H5Screate_simple (2, dims, NULL); 8 dataset_id = H5Dcreate(file_id,"dset",H5T_STD_I32BE, dataspace_id, H5P_DEFAULT); 9 status = H5Dclose (dataset_id); 10 status = H5Sclose (dataspace_id); 11 status = H5Fclose (file_id); Example 2 – Create an empty 4x6 dataset Terminate access to dataset, dataspace, & file

85 Example2: h5dump Output An empty 4x6 dataset HDF5 "dset.h5" { GROUP "/" { DATASET "dset" { DATATYPE { H5T_STD_I32BE } DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) } DATA { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } “/” ‘dset’

86 Attributes Attribute – data of the form “name = value”, attached to an object Operations are scaled­down versions of the dataset operations Not extendible No compression No partial I/O Optional for the dataset definition Can be overwritten, deleted, added during the “life” of a dataset

87 Special Storage Options Better subsetting access time; extendible chunked Improves storage efficiency, transmission speed compressed Arrays can be extended in any direction extendible Metadata for Fred Dataset “Fred” File A File B Data for Fred Metadata in one file, raw data in another. External file

88 Groups Group – a mechanism for describing collections of related objects Every file starts with a root group Can have attributes Similar to UNIX directories, but cycles are allowed “/”

89 “/” x temp / (root) /x /foo /foo/temp /foo/bar/temp HDF5 objects are identified and located by their pathnames foo bar

90 Sample Mappings between File Dataspaces and Memory Dataspaces (c) A sequence of points from a 2D array to a sequence of points in a 3D array. (d) Union of hyperslabs in file to union of hyperslabs in memory. (b) Regular series of blocks from a 2D array to a contiguous sequence at a certain offset in a 1D array (a) Hyperslab from a 2D array to the corner of a smaller 2D array

91 2D array of 16-bit ints3D array of 32-bit ints FileMemory Reading Dataset into Memory from File 2-d array Regularly spaced series of cubes The only restriction is that the number of selected elements on the left be the same as on the right.

92 2D array of 16-bit ints3D array of 32-bit ints FileMemory Reading Dataset into Memory from File Read

93 Steps for Dataset Writing/Reading If necessary, open the file to obtain the file ID Open the dataset to obtain the dataset ID Specify Memory datatype Library “knows” file datatype – do not need to specify Memory dataspace File dataspace Transfer properties (optional) Perform the desired operation on the dataset Close dataspace, datatype and property lists

94 Data Transfer Property List The data transfer property list is used to control various aspects of the I/O, such as caching hints or collective I/O information.

95 loc_id IN:Identifier of the file or group in which to open a dataset name IN:The name of the dataset to access hid_t H5Dopen (hid_t loc_id, const char *name) NOTE: File datatype and dataspace are known when a dataset is opened

96 dataset_id IN: Identifier of the dataset to write to mem_type_id IN: Identifier of memory datatype of the dataset mem_space_id IN: Identifier of the memory dataspace (or H5S_ALL ) file_space_id IN: Identifier of the file dataspace (or H5S_ALL ) xfer_plist_id IN: Identifier of the data transfer properties to use (or H5P_DEFAULT ) buf IN: Buffer with data to be written to the file herr_t H5Dwrite (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, const void * buf )

97 Example 3 – Writing to an existing dataset 1 hid_t file_id, dataset_id; 2 herr_t status; 3 int i, j, dset_data[4][6]; 4 for (i = 0; i < 4; i++) 5 for (j = 0; j < 6; j++) 6 dset_data[i][j] = i * 6 + j + 1; 7 file_id = H5Fopen ("dset.h5", H5F_ACC_RDWR, H5P_DEFAULT); 8 dataset_id = H5Dopen (file_id, "dset"); 9 status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); Initialize buffer

98 Example 3 – Writing to an existing dataset 1 hid_t file_id, dataset_id; 2 herr_t status; 3 int i, j, dset_data[4][6]; 4 for (i = 0; i < 4; i++) 5 for (j = 0; j < 6; j++) 6 dset_data[i][j] = i * 6 + j + 1; 7 file_id = H5Fopen ("dset.h5", H5F_ACC_RDWR, H5P_DEFAULT); 8 dataset_id = H5Dopen (file_id, "dset"); 9 status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); Open existing file and dataset

99 Example 3 – Writing to an existing dataset 1 hid_t file_id, dataset_id; 2 herr_t status; 3 int i, j, dset_data[4][6]; 4 for (i = 0; i < 4; i++) 5 for (j = 0; j < 6; j++) 6 dset_data[i][j] = i * 6 + j + 1; 7 file_id = H5Fopen ("dset.h5", H5F_ACC_RDWR, H5P_DEFAULT); 8 dataset_id = H5Dopen (file_id, "dset"); 9 status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data); Write to dataset

100 Example 3: h5dump Output HDF5 "dset.h5" { GROUP "/" { DATASET "dset" { DATATYPE { H5T_STD_I32BE } DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) } DATA { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 }

101 HDF5 High Level APIs

102 High Level APIs Make HDF5 easier to use Encourage standard ways to store objects Included with HDF5 library However: Currently available in C and Fortran90 (HDF ) Still need HDF5 calls (H5Fopen/H5Fclose…)

103 High Level APIs HDF5 Lite (H5LT): Functions that simply the steps need to create/read datasets and attributes HDF5 Image (H5IM): Functions for creating images in HDF5. HDF5 Table (H5TB): Functions for creating tables (collections of records) in HDF5. Others … (dimension scales, packet)

104 file_id = H5Fcreate( "test.h5", ……. ); /* Call some High Level function */ H5LTsome_function( file_id,...extra parameters ); status = H5Fclose( file_id ); HDF5 LT Programming model

105 Creating a dataset with HDF5 Lite Specific type functions for each numeric type: C language type FunctionHDF5 type charH5LTmake_dataset_charH5T_NATIVE_CHAR shortH5LTmake_dataset_shortH5T_NATIVE_SHORT intH5LTmake_dataset_intH5T_NATIVE_INT longH5LTmake_dataset_longH5T_NATIVE_LONG floatH5LTmake_dataset_floatH5T_NATIVE_FLOAT doubleH5LTmake_dataset_doubleH5T_NATIVE_DOUBLE

106 Reading a dataset with HDF5 Lite Specific type functions also for reading: C language type FunctionHDF5 type charH5LTread_dataset_charH5T_NATIVE_CHAR shortH5LTread_dataset_shortH5T_NATIVE_SHORT intH5LTread_dataset_intH5T_NATIVE_INT longH5LTread_dataset_longH5T_NATIVE_LONG floatH5LTread_dataset_floatH5T_NATIVE_FLOAT doubleH5LTread_dataset_doubleH5T_NATIVE_DOUBLE

107 HDF5 Image (H5IM) Purpose: to defines a standard storage for HDF5 datasets that are intended to be interpreted as images 2 types of images (8bit indexed to a palette, and 24bit with 3 color planes (RGB)) Also palette functions

108 HDF5 Image Image functions H5IMmake_image_8bit H5IMmake_image_24bit H5IMget_image_info H5IMread_image H5IMis_image

109 HDF5 Image Palette functions H5IMmake_palette H5IMlink_palette H5IMunlink_palette H5IMget_npalettes H5IMget_palette_info H5IMget_palette H5IMis_palette

110 HDF5 Image (H5IM) Programming example file_id = H5Fcreate ( "ex_image1.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); /* Write image */ status = H5IMmake_image_8bit ( file_id, "Image1", WIDTH, HEIGHT, data ); /* Make a palette */ status = H5IMmake_palette ( file_id, "Palette", pal_dims, pal ); /* Attach a palette to the image dataset */ status = H5IMlink_palette ( file_id, "Image1", "Palette" ); /* Close the file. */ status = H5Fclose ( file_id );