def hdf5_open(fid, mode='w'):
    """Open an hdf5 file.
  
  **Parameters:**
  
  fid : str
    Contains the filename of the hdf5 file.
  mode : str, optional
    Specifies the mode used to open the file. ('r', 'w', 'a')
  
  **Usage:**
  
  for hdf5_file in hdf5_open(fid,mode='w'):
    # Do something with hdf5_file...
  """
    import h5py
    if isinstance(fid, h5py.File):
        yield fid
    if not (fid.endswith('h5') or fid.endswith('hdf5')):
        fid += '.h5'
    hdf5_file = h5py.File(fid, mode)
    try:
        yield hdf5_file
    finally:
        hdf5_file.close()
