write_datasets function

Write data sets