docs: def magic_read_dict(path, data=None, sort_by_this_name=None, return_keys=False):
      """
      Read a magic-formatted tab-delimited file and return a dictionary of
      dictionaries, with this format:
      {'Z35.5a': {'specimen_weight': '1.000e-03', 'er_citation_names': 'This study', 'specimen_volume': '', 'er_location_name': '', 'er_site_name': 'Z35.', 'er_sample_name': 'Z35.5', 'specimen_class': '', 'er_specimen_name': 'Z35.5a', 'specimen_lithology': '', 'specimen_type': ''}, ....}
      return data, file_type, and keys (if return_keys is true)
      """
      DATA = {}
      #fin = open(path, 'r')
      #first_line = fin.readline()
      lines = open_file(path)
      if not lines:
          if return_keys:
              return {}, 'empty_file', None
          else:
              return {}, 'empty_file'
      first_line = lines.pop(0)
      if first_line[0] == "s" or first_line[1] == "s":
          delim = ' '
      elif first_line[0] == "t" or first_line[1] == "t":
          delim = '\t'
      else:
          print('-W- error reading ', path)
          if return_keys:
              return {}, 'bad_file', None
          else:
              return {}, 'bad_file'
  
      file_type = first_line.strip('\n').strip('\r').split(delim)[1]
  
      item_type = file_type
      #item_type = file_type.split('_')[1][:-1]
      if sort_by_this_name:
          pass
      elif item_type == 'age':
          sort_by_this_name = "by_line_number"
      else:
          sort_by_this_name = item_type
      line = lines.pop(0)
      header = line.strip('\n').strip('\r').split(delim)
      counter = 0
      for line in lines:
          tmp_data = {}
          tmp_line = line.strip('\n').strip('\r').split(delim)
          for i in range(len(header)):
              if i < len(tmp_line):
                  tmp_data[header[i]] = tmp_line[i].strip()
              else:
                  tmp_data[header[i]] = ""
          if sort_by_this_name == "by_line_number":
              DATA[counter] = tmp_data
              counter += 1
          else:
              if tmp_data[sort_by_this_name] != "":
                  DATA[tmp_data[sort_by_this_name]] = tmp_data
      if return_keys:
          return DATA, file_type, header
      else:
          return DATA, file_type