docs: def write_modes_to_file(
          self,
          filename="mode.dat",
          plot=True,
          fields_to_write=("Ex", "Ey", "Ez", "Hx", "Hy", "Hz"),
      ):
          """
          Writes the mode fields to a file and optionally plots them.
  
          Args:
              filename (str): The nominal filename to use for the saved
                  data.  The suffix will be automatically be changed to
                  identifiy each field and mode number.  Default is
                  'mode.dat'
              plot (bool): `True` if plots should be generates,
                  otherwise `False`.  Default is `True`.
              fields_to_write (tuple): A tuple of strings where the
                  strings can be 'Ex', 'Ey', 'Ez', 'Hx', 'Hy' and 'Hz'
                  defining what part of the mode should be saved and
                  plotted.  By default, all six components are written
                  and plotted.
  
          Returns:
              dict: A dictionary containing the effective indices
              and mode field profiles (if solved for).
          """
          modes_directory = self._modes_directory
  
          # Mode info file.
          with open(modes_directory + "mode_info", "w") as fs:
              fs.write("# Mode idx, Mode type, % in major direction, n_eff\n")
              for i, (n_eff, (mode_type, percentage)) in enumerate(
                  zip(self.n_effs, self.mode_types)
              ):
                  mode_idx = str(i)
                  line = "%s,%s,%.2f,%.3f" % (
                      mode_idx,
                      mode_type,
                      percentage,
                      n_eff.real,
                  )
                  fs.write(line + "\n")
  
          # Mode field plots.
          for i, (mode, areas) in enumerate(zip(self._ms.modes, self.overlaps)):
              mode_directory = "%smode_%i/" % (modes_directory, i)
              if not os.path.isdir(mode_directory):
                  os.mkdir(mode_directory)
              filename_full = mode_directory + filename
  
              for (field_name, field_profile), area in zip(
                  mode.fields.items(), areas
              ):
                  if field_name in fields_to_write:
                      filename_mode = self._get_mode_filename(
                          field_name, i, filename_full
                      )
                      self._write_mode_to_file(
                          np.real(field_profile), filename_mode
                      )
                      if plot:
                          self._plot_mode(
                              field_name,
                              i,
                              filename_mode,
                              self.n_effs[i],
                              area=area,
                              wavelength=self._structure._wl,
                          )
  
          return self.modes