%
%
fname="testhdf.h5";

if ~isfile(fname)
  fprintf("Creating new HDF5 file with a spiral in %s\n",fname);
  h5create(fname,'/spiral/st',[500]);
  h5create(fname,'/spiral/ct',[500]);
  h5create(fname,'/spiral/t',[500]);

  t = 0:pi/50:10*pi;
  st = sin(t);
  ct = cos(t);
  h5write(fname,'/spiral/st',st(1:500))
  h5write(fname,'/spiral/ct',ct(1:500))
  h5write(fname,'/spiral/t',t(1:500))

  % annotate dataset group with Dublin Core MD
  h5writeatt(fname,'/spiral','DC.title','500 point 3D spiral')
  h5writeatt(fname,'/spiral','DC.description','A 3D spiral')
  h5writeatt(fname,'/spiral','DC.creator','David Groep <davidg@nikhef.nl>')
  h5writeatt(fname,'/spiral','DC.date',datestr(date))
  h5writeatt(fname,'/spiral','DC.type','http://purl.org/dc/dcmitype/Dataset');
  h5writeatt(fname,'/spiral','DC.format','500x500')
  h5writeatt(fname,'/spiral','DC.format','HDF5 500x500')
  h5writeatt(fname,'/spiral','DC.publisher','nikhef.nl')
  h5writeatt(fname,'/spiral','DC.rights','CC-0')
else
  disp("reading existing file");
  hinfo = h5info(fname);
  for key = [ "st" "ct" "t" ]
    if ( ~ismember(key,{hinfo.Groups.Datasets.Name}) )
      error("""/spiral/%s"" is not a member of the dataset in %s",key,fname);
    end
  end
  ct=h5read(fname,"/spiral/ct");
  st=h5read(fname,"/spiral/st");
  t=h5read(fname,"/spiral/t");
end

plot3(st,ct,t)

h5disp(fname)
