# HDF5-UDF 1.2 released, allowing translation of CSV to HDF5

**URL:** <https://forum.hdfgroup.org/t/hdf5-udf-1-2-released-allowing-translation-of-csv-to-hdf5/8080>\
**Category:** HDF5 Ancillary Tools\
**Created:** [January 29, 2021, 6:05pm UTC](https://forum.hdfgroup.org/t/hdf5-udf-1-2-released-allowing-translation-of-csv-to-hdf5/8080 "2021-01-29T18:05:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasvr](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/lucasvr/32/1136_2.png) [@lucasvr](https://forum.hdfgroup.org/u/lucasvr)\
**Post date:** [January 29, 2021, 6:05pm UTC](https://forum.hdfgroup.org/t/hdf5-udf-1-2-released-allowing-translation-of-csv-to-hdf5/8080/1 "2021-01-29T18:05:27Z")

</div>

Hello there, folks!

I’m happy to announce the availability of **HDF5-UDF 1.2**. You probably remember it, but it doesn’t hurt to state that the tool allows **embedding routines written in C/C++, Python or Lua on HDF5 files** in a way that such routines execute each time the dataset is read.

This new release comes with some exciting new features over the previous version:

- Support for **outputting string datatypes**
- Support for **outputting compound datatypes** , which may include string elements and native datatypes
- Using 1-based indexing on the Lua API to conform with the language recommendations

What’s really special about support for generating compounds and strings is that **it is possible to translate CSV to HDF5 on-the-fly** , and it’s **easy** to do so, as the examples below will show.

Please refer to the [project page at GitHub](https://github.com/lucasvr/hdf5-udf) for download instructions and more examples. Feedback is welcome as usual and pull requests even more!

### _CSV to HDF5 with HDF5-UDF_

##### Snippet of `albumlist.csv`

```auto
Number,Year,Album,Artist,Genre
1,1967,Sgt. Peppers Lonely Hearts Club Band,The Beatles,Rock
2,1966,Pet Sounds,The Beach Boys,Rock
3,1966,Revolver,The Beatles,Rock

```

##### User-Defined Function (yes, it’s this simple)

```auto
def dynamic_dataset():
    udf_data = lib.getData("GreatestAlbums")
    with open("albumlist.csv") as f:
        # Skip the header
        f.readline()

        for i, line in enumerate(f.readlines()):
            # Split the line using "," as separator
            elements = [col.strip("\n") for col in line.split(",")]

            # Generate compound members on-the-fly
            udf_data[i].id = int(elements[0])
            udf_data[i].year = int(elements[1])
            lib.setString(udf_data[i].album, elements[2])
            lib.setString(udf_data[i].artist, elements[3])
            lib.setString(udf_data[i].genre, elements[4])

```

##### Command to embed the User-Defined Function on HDF5

```auto
$ hdf5-udf file.h5 dynamic_dataset.py \
  'GreatestAlbums:{id:int32,year:int16,album:string(40),artist:string,genre:string}:500'

```

##### First few entries of the dynamically generated HDF5 dataset

```auto
$ h5dump -O -d /GreatestAlbums file.h5
   (0): {
         1,
         1967,
         "Sgt. Peppers Lonely Hearts Club Band",
         "The Beatles",
         "Rock"
      },
   (1): {
         2,
         1966,
         "Pet Sounds",
         "The Beach Boys",
         "Rock"
      },
   (2): {
         3,
         1966,
         "Revolver",
         "The Beatles",
         "Rock"
      },
    ...

```
