160 likes | 309 Views
Data Conversions of Arithmetic Data Types. HDF-EOS Workshop IX Quincey Koziol and Ray Lu 30 Nov 2005. Outline. Arithmetic data types in the HDF5 library Data conversions Compiler vs. library conversions Exception handling. Arithmetic Data Types. Integers Predefined: H5T_arch_base
E N D
Data Conversions of Arithmetic Data Types HDF-EOS Workshop IX Quincey Koziol and Ray Lu 30 Nov 2005
Outline • Arithmetic data types in the HDF5 library • Data conversions • Compiler vs. library conversions • Exception handling
Arithmetic Data Types • Integers • Predefined: H5T_arch_base • Standard: H5T_STD_U8LE, H5T_STD_I32BE • Native: H5T_NATIVE_SHORT, H5T_NATIVE_LLONG • System-specific: H5T_MIPS_U64 • User-defined • Floating-point numbers • Predefined: H5T_arch_base • IEEE standard: H5T_IEEE_F32BE, H5T_IEEE_F64LE • Native: H5T_NATIVE_FLOAT, H5T_NATIVE_LDOUBLE • System-specific: H5T_INTEL_F64 • User-defined • Full list of predefined data types:Predefined Datatypes in HDF5 Reference Manual.
Outline • Arithmetic data types in the HDF5 library • Data conversions • Compiler vs. library conversions • Exception handling
Data Conversions • Memory disk:through H5Dwrite() and H5Dread(). • Memory memory:through H5Tconvert(). • Examples
Memory disk int buf[]={0,1,2,3,…}; hid_t dset = H5Dcreate(fid, “dset”, H5T_STD_U64LE, sid, H5P_DEFAULT); H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf); Memory memory float fbuf[NELMTS]={0,1.0,…}; void *conv_buf; conv_buf = (void*)malloc(NELMTS*8); memcpy(conv_buf, fbuf, NELMTS*sizeof(float)); H5Tconvert( H5T_NATIVE_FLOAT, H5T_IEEE_F64BE, NELMTS, conv_buf, NULL, /*background buffer*/ H5P_DEFAULT); Data Conversion Examples
Outline • Arithmetic data types in the HDF5 library • Data conversions • Compiler vs. library conversions • Exception handling
Compiler conversions: Conversion is done by compiler. Equivalent to casting like this float a = 3.14; int b = (int)a; Can only be applied to native data types. Example: H5T_NATIVE_FLOAT H5T_NATIVE_INT Conversion function is between certain pair of data types. Example: H5T_conv_float_int() Library Conversions: The HDF5 library’s own conversion routine. Bit sequence of source is converted to that of destination. Example: H5T_conv_f_i() Handle any data type in a data type class, including predefined and user-defined data types. Example: H5T_NATIVE_INT H5T_IEEE_F64BE Compiler vs. Library Conversions Compiler vs. Library Conversions
Compiler conversions: Library’s default conversion. Faster. Also called hard or hard- ware conversions. Library Conversions: More rigid and slower. Also called soft or software conversions. Compiler vs. Library Conversions(continued) Compiler vs. Library Conversions
Register Conversion Functions • Register a soft function will replace all conversions between data type classes: Example:H5Tregister(H5T_PERS_SOFT, “fp_integer”, H5T_NATIVE_FLOAT, H5T_NATIVE_LONG, conv_fp_integer). • Register a hard function will only replace the conversion between certain pair of data types: Example:H5Tregister(H5T_PERS_HARD, “float_long”, H5T_NATIVE_FLOAT, H5T_NATIVE_LONG, conv_float_long). Compiler vs. Library Conversions
Un-register conversion functions If you only want to use library’s conversion, use H5Tunregister() to un-register all compiler conversions. Example: H5Tunregister(H5T_PERS_HARD, NULL, -1, -1, NULL); Compiler vs. Library Conversions
Handling Incorrect Compiler Conversion • Some compilers don’t handle conversion correctly. • The library replaces these conversion with its own routine. • To find out, use htri_t H5Tcompiler_conv(hid_t source, hid_t destination) Compiler vs. Library Conversions
Outline • Arithmetic data types in the HDF5 library • Data conversions • Compiler vs. library conversions • Handling Exception
Handling Exception • To handle exceptions during conversions yourselves: register user’s handling function through H5Pset_type_conv_cb(). • Cases of exception: • H5T_CONV_EXCEPT_RANGE_HI • H5T_CONV_EXCEPT_RANGE_LOW • H5T_CONV_EXCEPT_TRUNCATE • H5T_CONV_EXCEPT_PRECISION • H5T_CONV_EXCEPT_PINF • H5T_CONV_EXCEPT_NINF • H5T_CONV_EXCEPT_NAN • Return values: H5T_CONV_ABORT, H5T_CONV_UNHANDLED, H5T_CONV_HANDLED
Outline • Arithmetic data types in the HDF5 library • Data conversions • Compiler vs. library conversions • Exception handling
Documents User’s Guide: http://hdf.ncsa.uiuc.edu/HDF5/doc_dev_snapshot/HE9-ErrorAPI,DataConversion/DataConversion-Aug05.pdf Reference Manual: http://hdf.ncsa.uiuc.edu/HDF5/doc_dev_snapshot/H5_dev/RM/RM_H5T.html Acknowledgement: 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 (http://hdf.ncsa.uiuc.edu/acknowledge.html)