# sanity checks
    if not os.path.isdir(maindir):
        print(('ERROR: directory', maindir, 'does not exists.'))
        sys.exit(0)
    if os.path.isfile(output):
        print(('ERROR: file', output,
               'exists, delete or provide a new filename.'))
        sys.exit(0)

    # start time
    t1 = time.time()

    # get all h5 files
    allh5 = get_all_files(maindir, ext='.h5')
    print(('found', len(allh5), 'H5 files.'))

    # create summary file
    HDF5.create_aggregate_file(output,
                               expectedrows=len(allh5),
                               summaryfile=True)
    print('Summary file created, we start filling it.')

    # fill it
    h5 = HDF5.open_h5_file_append(output)
    HDF5.fill_hdf5_aggregate_file(h5, allh5, summaryfile=True)
    h5.close()

    # done!
    stimelength = str(datetime.timedelta(seconds=time.time() - t1))
    print(('Summarized', len(allh5), 'files in:', stimelength))
    # sanity checks
    if not os.path.isdir(maindir):
        print('ERROR: directory',maindir,'does not exists.')
        sys.exit(0)
    if os.path.isfile(output):
        print('ERROR: file',output,'exists, delete or provide a new filename.')
        sys.exit(0)

    # start time
    t1 = time.time()

    # get all h5 files
    allh5 = get_all_files(maindir,ext='.h5')
    print('found',len(allh5),'H5 files.')

    # create summary file
    HDF5.create_aggregate_file(output,expectedrows=len(allh5),
                               summaryfile=True)
    print('Summary file created, we start filling it.')

    # fill it
    h5 = HDF5.open_h5_file_append(output)
    HDF5.fill_hdf5_aggregate_file(h5,allh5,summaryfile=True)
    h5.close()

    # done!
    stimelength = str(datetime.timedelta(seconds=time.time()-t1))
    print('Summarized',len(allh5),'files in:',stimelength)