Data Conversions of Arithmetic Data Types HDFEOS Workshop

  • Slides: 16
Download presentation
Data Conversions of Arithmetic Data Types HDF-EOS Workshop IX Quincey Koziol and Ray Lu

Data Conversions of Arithmetic Data Types HDF-EOS Workshop IX Quincey Koziol and Ray Lu 30 Nov 2005 1

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data conversions Compiler vs. library conversions Exception handling 2

Arithmetic Data Types I. Integers – Predefined: H 5 T_arch_base • • • –

Arithmetic Data Types I. Integers – Predefined: H 5 T_arch_base • • • – II. User-defined Floating-point numbers – Predefined: H 5 T_arch_base • • • – III. Standard: H 5 T_STD_U 8 LE, H 5 T_STD_I 32 BE Native: H 5 T_NATIVE_SHORT, H 5 T_NATIVE_LLONG System-specific: H 5 T_MIPS_U 64 IEEE standard: H 5 T_IEEE_F 32 BE, H 5 T_IEEE_F 64 LE Native: H 5 T_NATIVE_FLOAT, H 5 T_NATIVE_LDOUBLE System-specific: H 5 T_INTEL_F 64 User-defined Full list of predefined data types: Predefined Datatypes in HDF 5 Reference Manual. 3

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data conversions Compiler vs. library conversions Exception handling 4

Data Conversions • Memory disk: through H 5 Dwrite() and H 5 Dread(). •

Data Conversions • Memory disk: through H 5 Dwrite() and H 5 Dread(). • Memory memory: through H 5 Tconvert(). • Examples 5

Data Conversion Examples • Memory disk • Memory memory int buf[]={0, 1, 2, 3,

Data Conversion Examples • Memory disk • Memory memory int buf[]={0, 1, 2, 3, …}; float fbuf[NELMTS]={0, 1. 0, …}; void *conv_buf; hid_t dset = H 5 Dcreate(fid, “dset”, H 5 T_STD_U 64 LE, sid, H 5 P_DEFAULT); H 5 Dwrite(dset, H 5 T_NATIVE_INT, H 5 S_ALL, H 5 P_DEFAULT, buf); conv_buf = (void*)malloc(NELMTS*8); memcpy(conv_buf, fbuf, NELMTS*sizeof(float)); H 5 Tconvert( H 5 T_NATIVE_FLOAT, H 5 T_IEEE_F 64 BE, NELMTS, conv_buf, NULL, /*background buffer*/ H 5 P_DEFAULT); 6

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data conversions Compiler vs. library conversions Exception handling 7

Compiler vs. Library Conversions Compiler conversions: Library Conversions: • Conversion is done by compiler.

Compiler vs. Library Conversions Compiler conversions: Library Conversions: • Conversion is done by compiler. Equivalent to casting like this • The HDF 5 library’s own conversion routine. Bit sequence of source is converted to that of destination. float a = 3. 14; int b = (int)a; Example: H 5 T_conv_f_i() • Can only be applied to native data types. Example: H 5 T_NATIVE_FLOAT H 5 T_NATIVE_INT • Conversion function is between certain pair of data types. • Handle any data type in a data type class, including predefined and user-defined data types. Example: H 5 T_NATIVE_INT H 5 T_IEEE_F 64 BE Example: H 5 T_conv_float_int() Compiler vs. Library Conversions 8

Compiler vs. Library Conversions (continued) Compiler conversions: Library Conversions: • Library’s default conversion. •

Compiler vs. Library Conversions (continued) Compiler conversions: Library Conversions: • Library’s default conversion. • More rigid and slower. • Also called soft or software conversions. • Faster. • Also called hard or hard- ware conversions. Compiler vs. Library Conversions 9

Register Conversion Functions • Register a soft function will replace all conversions between data

Register Conversion Functions • Register a soft function will replace all conversions between data type classes: Example: H 5 Tregister(H 5 T_PERS_SOFT, “fp_integer”, H 5 T_NATIVE_FLOAT, H 5 T_NATIVE_LONG, conv_fp_integer). • Register a hard function will only replace the conversion between certain pair of data types: Example: H 5 Tregister(H 5 T_PERS_HARD, “float_long”, H 5 T_NATIVE_FLOAT, H 5 T_NATIVE_LONG, conv_float_long). Compiler vs. Library Conversions 10

Un-register conversion functions If you only want to use library’s conversion, use H 5

Un-register conversion functions If you only want to use library’s conversion, use H 5 Tunregister() to un-register all compiler conversions. Example: H 5 Tunregister(H 5 T_PERS_HARD, NULL, -1, NULL); Compiler vs. Library Conversions 11

Handling Incorrect Compiler Conversion • Some compilers don’t handle conversion correctly. • The library

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 H 5 Tcompiler_conv(hid_t source, hid_t destination) Compiler vs. Library Conversions 12

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data conversions Compiler vs. library conversions Handling Exception 13

Handling Exception • To handle exceptions during conversions yourselves: register user’s handling function through

Handling Exception • To handle exceptions during conversions yourselves: register user’s handling function through H 5 Pset_type_conv_cb(). • Cases of exception: – – – – H 5 T_CONV_EXCEPT_RANGE_HI H 5 T_CONV_EXCEPT_RANGE_LOW H 5 T_CONV_EXCEPT_TRUNCATE H 5 T_CONV_EXCEPT_PRECISION H 5 T_CONV_EXCEPT_PINF H 5 T_CONV_EXCEPT_NAN • Return values: H 5 T_CONV_ABORT, H 5 T_CONV_HANDLED H 5 T_CONV_UNHANDLED, 14

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data

Outline 1. 2. 3. 4. Arithmetic data types in the HDF 5 library Data conversions Compiler vs. library conversions Exception handling 15

Documents User’s Guide: http: //hdf. ncsa. uiuc. edu/HDF 5/doc_dev_snapshot/HE 9 Error. API, Data. Conversion/Data.

Documents User’s Guide: http: //hdf. ncsa. uiuc. edu/HDF 5/doc_dev_snapshot/HE 9 Error. API, Data. Conversion/Data. Conversion-Aug 05. pdf Reference Manual: http: //hdf. ncsa. uiuc. edu/HDF 5/doc_dev_snapshot/H 5_dev/RM/RM_H 5 T. 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 NNG 05 GC 60 A. 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) 16