plot_main Subroutine

public subroutine plot_main(atom_data, band_plot, dis_manifold, fermi_energy_list, fermi_surface_plot, ham_logical, kmesh_info, kpt_latt, output_file, wvfn_read, real_space_ham, kpoint_path, print_output, wannier_data, wannier_plot, ws_region, w90_calculation, ham_k, ham_r, m_matrix, u_matrix, u_matrix_opt, eigval, real_lattice, wannier_centres_translated, bohr, irvec, mp_grid, ndegen, shift_vec, nrpts, num_bands, num_kpts, num_wann, rpt_origin, transport_mode, have_disentangled, lsitesymmetry, w90_system, seedname, stdout, timer, dist_k, error, comm)

Uses

  • proc~~plot_main~~UsesGraph proc~plot_main plot_main module~w90_constants w90_constants proc~plot_main->module~w90_constants module~w90_error w90_error proc~plot_main->module~w90_error module~w90_hamiltonian w90_hamiltonian proc~plot_main->module~w90_hamiltonian module~w90_io w90_io proc~plot_main->module~w90_io module~w90_types w90_types proc~plot_main->module~w90_types module~w90_utility w90_utility proc~plot_main->module~w90_utility module~w90_wannier90_types w90_wannier90_types proc~plot_main->module~w90_wannier90_types module~w90_ws_distance w90_ws_distance proc~plot_main->module~w90_ws_distance module~w90_comms w90_comms module~w90_error->module~w90_comms module~w90_error_base w90_error_base module~w90_error->module~w90_error_base module~w90_hamiltonian->module~w90_constants module~w90_hamiltonian->module~w90_error module~w90_hamiltonian->module~w90_types module~w90_io->module~w90_constants module~w90_types->module~w90_constants module~w90_utility->module~w90_constants module~w90_utility->module~w90_comms module~w90_wannier90_types->module~w90_constants module~w90_ws_distance->module~w90_constants module~w90_ws_distance->module~w90_error module~w90_comms->module~w90_constants module~w90_comms->module~w90_error_base

Main plotting routine

Arguments

Type IntentOptional Attributes Name
type(atom_data_type), intent(in) :: atom_data
type(band_plot_type), intent(in) :: band_plot
type(dis_manifold_type), intent(in) :: dis_manifold
real(kind=dp), intent(in), allocatable :: fermi_energy_list(:)
type(fermi_surface_plot_type), intent(in) :: fermi_surface_plot
type(ham_logical_type), intent(inout) :: ham_logical
type(kmesh_info_type), intent(in) :: kmesh_info
real(kind=dp), intent(in) :: kpt_latt(:,:)
type(output_file_type), intent(in) :: output_file
type(wvfn_read_type), intent(in) :: wvfn_read
type(real_space_ham_type), intent(inout) :: real_space_ham
type(kpoint_path_type), intent(in) :: kpoint_path
type(print_output_type), intent(in) :: print_output
type(wannier_data_type), intent(in) :: wannier_data
type(wannier_plot_type), intent(in) :: wannier_plot
type(ws_region_type), intent(in) :: ws_region
type(w90_calculation_type), intent(in) :: w90_calculation
complex(kind=dp), intent(inout), allocatable :: ham_k(:,:,:)
complex(kind=dp), intent(inout), allocatable :: ham_r(:,:,:)
complex(kind=dp), intent(in) :: m_matrix(:,:,:,:)
complex(kind=dp), intent(in) :: u_matrix(:,:,:)
complex(kind=dp), intent(in) :: u_matrix_opt(:,:,:)
real(kind=dp), intent(in) :: eigval(:,:)
real(kind=dp), intent(in) :: real_lattice(3,3)
real(kind=dp), intent(inout), allocatable :: wannier_centres_translated(:,:)
real(kind=dp), intent(in) :: bohr
integer, intent(inout), allocatable :: irvec(:,:)
integer, intent(in) :: mp_grid(3)
integer, intent(inout), allocatable :: ndegen(:)
integer, intent(inout), allocatable :: shift_vec(:,:)
integer, intent(inout) :: nrpts
integer, intent(in) :: num_bands
integer, intent(in) :: num_kpts
integer, intent(in) :: num_wann
integer, intent(inout) :: rpt_origin
character(len=20), intent(in) :: transport_mode
logical, intent(in) :: have_disentangled
logical, intent(in) :: lsitesymmetry
type(w90_system_type), intent(in) :: w90_system
character(len=50), intent(in) :: seedname
integer, intent(in) :: stdout
type(timer_list_type), intent(inout) :: timer
integer, intent(in) :: dist_k(:)
type(w90_error_type), intent(out), allocatable :: error
type(w90_comm_type), intent(in) :: comm

Calls

proc~~plot_main~~CallsGraph proc~plot_main plot_main proc~hamiltonian_get_hr hamiltonian_get_hr proc~plot_main->proc~hamiltonian_get_hr proc~hamiltonian_setup hamiltonian_setup proc~plot_main->proc~hamiltonian_setup proc~hamiltonian_write_hr hamiltonian_write_hr proc~plot_main->proc~hamiltonian_write_hr proc~hamiltonian_write_tb hamiltonian_write_tb proc~plot_main->proc~hamiltonian_write_tb proc~io_stopwatch_start io_stopwatch_start proc~plot_main->proc~io_stopwatch_start proc~io_stopwatch_stop io_stopwatch_stop proc~plot_main->proc~io_stopwatch_stop proc~mpirank mpirank proc~plot_main->proc~mpirank proc~plot_bvec plot_bvec proc~plot_main->proc~plot_bvec proc~plot_calc_projection plot_calc_projection proc~plot_main->proc~plot_calc_projection proc~plot_fermi_surface plot_fermi_surface proc~plot_main->proc~plot_fermi_surface proc~plot_interpolate_bands plot_interpolate_bands proc~plot_main->proc~plot_interpolate_bands proc~plot_svd_omega_i plot_svd_omega_i proc~plot_main->proc~plot_svd_omega_i proc~plot_u_matrices plot_u_matrices proc~plot_main->proc~plot_u_matrices proc~plot_wannier plot_wannier proc~plot_main->proc~plot_wannier proc~plot_write_r2mn plot_write_r2mn proc~plot_main->proc~plot_write_r2mn proc~plot_write_rmn plot_write_rmn proc~plot_main->proc~plot_write_rmn proc~plot_write_vdw_data plot_write_vdw_data proc~plot_main->proc~plot_write_vdw_data proc~plot_write_xyz plot_write_xyz proc~plot_main->proc~plot_write_xyz proc~utility_recip_lattice_base utility_recip_lattice_base proc~plot_main->proc~utility_recip_lattice_base proc~ws_translate_dist ws_translate_dist proc~plot_main->proc~ws_translate_dist proc~ws_write_vec ws_write_vec proc~plot_main->proc~ws_write_vec proc~hamiltonian_get_hr->proc~io_stopwatch_start proc~hamiltonian_get_hr->proc~io_stopwatch_stop proc~set_error_alloc set_error_alloc proc~hamiltonian_get_hr->proc~set_error_alloc proc~set_error_dealloc set_error_dealloc proc~hamiltonian_get_hr->proc~set_error_dealloc proc~utility_cart_to_frac utility_cart_to_frac proc~hamiltonian_get_hr->proc~utility_cart_to_frac proc~utility_frac_to_cart utility_frac_to_cart proc~hamiltonian_get_hr->proc~utility_frac_to_cart proc~utility_inverse_mat utility_inverse_mat proc~hamiltonian_get_hr->proc~utility_inverse_mat proc~hamiltonian_wigner_seitz hamiltonian_wigner_seitz proc~hamiltonian_setup->proc~hamiltonian_wigner_seitz proc~hamiltonian_setup->proc~set_error_alloc proc~hamiltonian_write_hr->proc~io_stopwatch_start proc~hamiltonian_write_hr->proc~io_stopwatch_stop proc~io_date io_date proc~hamiltonian_write_hr->proc~io_date proc~set_error_file set_error_file proc~hamiltonian_write_hr->proc~set_error_file proc~hamiltonian_write_tb->proc~io_stopwatch_start proc~hamiltonian_write_tb->proc~io_stopwatch_stop proc~hamiltonian_write_tb->proc~mpirank interface~comms_reduce comms_reduce proc~hamiltonian_write_tb->interface~comms_reduce proc~hamiltonian_write_tb->proc~io_date proc~hamiltonian_write_tb->proc~set_error_file proc~plot_bvec->proc~io_date proc~plot_bvec->proc~set_error_file proc~plot_calc_projection->proc~io_stopwatch_start proc~plot_calc_projection->proc~io_stopwatch_stop proc~plot_fermi_surface->proc~io_stopwatch_start proc~plot_fermi_surface->proc~io_stopwatch_stop proc~plot_fermi_surface->proc~io_date proc~io_time io_time proc~plot_fermi_surface->proc~io_time proc~plot_fermi_surface->proc~set_error_alloc proc~set_error_fatal set_error_fatal proc~plot_fermi_surface->proc~set_error_fatal proc~set_error_warn set_error_warn proc~plot_fermi_surface->proc~set_error_warn zhpevx zhpevx proc~plot_fermi_surface->zhpevx proc~plot_interpolate_bands->proc~io_stopwatch_start proc~plot_interpolate_bands->proc~io_stopwatch_stop proc~plot_interpolate_bands->proc~mpirank proc~plot_interpolate_bands->proc~ws_translate_dist 20 20 proc~plot_interpolate_bands->20 proc~plot_interpolate_bands->interface~comms_reduce proc~comms_array_split comms_array_split proc~plot_interpolate_bands->proc~comms_array_split proc~plot_interpolate_bands->proc~io_date proc~plot_interpolate_bands->proc~io_time proc~mpisize mpisize proc~plot_interpolate_bands->proc~mpisize proc~plot_interpolate_bands->proc~set_error_alloc proc~plot_interpolate_bands->proc~set_error_dealloc proc~plot_interpolate_bands->proc~set_error_fatal proc~plot_interpolate_bands->proc~set_error_warn proc~utility_metric utility_metric proc~plot_interpolate_bands->proc~utility_metric proc~plot_interpolate_bands->zhpevx proc~plot_svd_omega_i->proc~io_stopwatch_start proc~plot_svd_omega_i->proc~io_stopwatch_stop proc~plot_svd_omega_i->proc~mpirank interface~comms_allreduce comms_allreduce proc~plot_svd_omega_i->interface~comms_allreduce proc~plot_svd_omega_i->proc~set_error_alloc proc~plot_svd_omega_i->proc~set_error_dealloc proc~plot_svd_omega_i->proc~set_error_fatal zgesvd zgesvd proc~plot_svd_omega_i->zgesvd proc~plot_u_matrices->proc~io_date proc~plot_u_matrices->proc~set_error_alloc proc~plot_u_matrices->proc~set_error_dealloc zgemm zgemm proc~plot_u_matrices->zgemm proc~plot_wannier->proc~io_stopwatch_start proc~plot_wannier->proc~io_stopwatch_stop proc~plot_wannier->proc~mpirank proc~plot_wannier->proc~utility_recip_lattice_base proc~plot_wannier->interface~comms_reduce proc~plot_wannier->proc~io_date proc~plot_wannier->proc~mpisize proc~plot_read_unk plot_read_unk proc~plot_wannier->proc~plot_read_unk proc~plot_wannier->proc~set_error_alloc proc~plot_wannier->proc~set_error_dealloc proc~plot_wannier->proc~set_error_file proc~plot_wannier->proc~set_error_warn proc~plot_wannier->proc~utility_cart_to_frac proc~plot_wannier->proc~utility_frac_to_cart proc~plot_wannier->proc~utility_inverse_mat zaxpy zaxpy proc~plot_wannier->zaxpy proc~plot_write_r2mn->proc~mpirank proc~plot_write_r2mn->interface~comms_reduce proc~plot_write_r2mn->proc~set_error_file proc~plot_write_rmn->proc~mpirank proc~plot_write_rmn->interface~comms_reduce proc~plot_write_rmn->proc~io_date proc~plot_write_rmn->proc~set_error_file proc~plot_write_vdw_data->proc~set_error_alloc proc~plot_write_vdw_data->proc~set_error_dealloc proc~set_error_input set_error_input proc~plot_write_vdw_data->proc~set_error_input proc~utility_translate_home utility_translate_home proc~plot_write_vdw_data->proc~utility_translate_home proc~plot_write_xyz->proc~io_date proc~plot_write_xyz->proc~set_error_file proc~plot_write_xyz->proc~utility_translate_home proc~utility_inv3 utility_inv3 proc~utility_recip_lattice_base->proc~utility_inv3 proc~clean_ws_translate clean_ws_translate proc~ws_translate_dist->proc~clean_ws_translate proc~r_wz_sc R_wz_sc proc~ws_translate_dist->proc~r_wz_sc proc~ws_translate_dist->proc~set_error_alloc proc~ws_translate_dist->proc~set_error_fatal proc~ws_translate_dist->proc~utility_frac_to_cart proc~ws_translate_dist->proc~utility_inverse_mat proc~ws_write_vec->proc~io_date proc~ws_write_vec->proc~set_error_file proc~comms_allreduce_cmplx comms_allreduce_cmplx interface~comms_allreduce->proc~comms_allreduce_cmplx proc~comms_allreduce_real comms_allreduce_real interface~comms_allreduce->proc~comms_allreduce_real proc~comms_reduce_cmplx comms_reduce_cmplx interface~comms_reduce->proc~comms_reduce_cmplx proc~comms_reduce_int comms_reduce_int interface~comms_reduce->proc~comms_reduce_int proc~comms_reduce_real comms_reduce_real interface~comms_reduce->proc~comms_reduce_real proc~clean_ws_translate->proc~set_error_dealloc proc~comms_array_split->proc~mpisize proc~hamiltonian_wigner_seitz->proc~io_stopwatch_start proc~hamiltonian_wigner_seitz->proc~io_stopwatch_stop proc~hamiltonian_wigner_seitz->proc~set_error_alloc proc~hamiltonian_wigner_seitz->proc~set_error_dealloc proc~hamiltonian_wigner_seitz->proc~set_error_fatal proc~hamiltonian_wigner_seitz->proc~utility_metric proc~plot_read_unk->proc~set_error_file proc~r_wz_sc->proc~set_error_fatal proc~r_wz_sc->proc~utility_cart_to_frac proc~r_wz_sc->proc~utility_frac_to_cart proc~comms_sync_error comms_sync_error proc~set_error_alloc->proc~comms_sync_error proc~set_base_error set_base_error proc~set_error_alloc->proc~set_base_error proc~set_error_dealloc->proc~comms_sync_error proc~set_error_dealloc->proc~set_base_error proc~set_error_fatal->proc~comms_sync_error proc~set_error_fatal->proc~set_base_error proc~set_error_file->proc~comms_sync_error proc~set_error_file->proc~set_base_error proc~set_error_input->proc~comms_sync_error proc~set_error_input->proc~set_base_error proc~set_error_warn->proc~comms_sync_error proc~set_error_warn->proc~set_base_error proc~utility_inverse_mat->proc~utility_inv3 proc~utility_translate_home->proc~utility_recip_lattice_base proc~utility_translate_home->proc~utility_cart_to_frac proc~utility_translate_home->proc~utility_frac_to_cart proc~comms_allreduce_cmplx->proc~comms_sync_error proc~comms_no_sync_allreduce_cmplx comms_no_sync_allreduce_cmplx proc~comms_allreduce_cmplx->proc~comms_no_sync_allreduce_cmplx proc~comms_allreduce_real->proc~comms_sync_error proc~comms_no_sync_allreduce_real comms_no_sync_allreduce_real proc~comms_allreduce_real->proc~comms_no_sync_allreduce_real proc~comms_reduce_cmplx->proc~comms_sync_error proc~comms_no_sync_reduce_cmplx comms_no_sync_reduce_cmplx proc~comms_reduce_cmplx->proc~comms_no_sync_reduce_cmplx proc~comms_reduce_int->proc~comms_sync_error proc~comms_no_sync_reduce_int comms_no_sync_reduce_int proc~comms_reduce_int->proc~comms_no_sync_reduce_int proc~comms_reduce_real->proc~comms_sync_error proc~comms_no_sync_reduce_real comms_no_sync_reduce_real proc~comms_reduce_real->proc~comms_no_sync_reduce_real

Called by

proc~~plot_main~~CalledByGraph proc~plot_main plot_main proc~w90_plot w90_plot proc~w90_plot->proc~plot_main program~wannier wannier program~wannier->proc~w90_plot

Source Code

  subroutine plot_main(atom_data, band_plot, dis_manifold, fermi_energy_list, fermi_surface_plot, &
                       ham_logical, kmesh_info, kpt_latt, output_file, wvfn_read, real_space_ham, &
                       kpoint_path, print_output, wannier_data, wannier_plot, ws_region, &
                       w90_calculation, ham_k, ham_r, m_matrix, u_matrix, u_matrix_opt, eigval, &
                       real_lattice, wannier_centres_translated, bohr, irvec, mp_grid, ndegen, &
                       shift_vec, nrpts, num_bands, num_kpts, num_wann, rpt_origin, &
                       transport_mode, have_disentangled, lsitesymmetry, w90_system, seedname, &
                       stdout, timer, dist_k, error, comm)
    !================================================!
    !
    !! Main plotting routine
    !
    !================================================!

    use w90_constants, only: eps6, dp
    use w90_hamiltonian, only: hamiltonian_get_hr, hamiltonian_write_hr, hamiltonian_setup, &
                               hamiltonian_write_tb
    use w90_io, only: io_stopwatch_start, io_stopwatch_stop
    use w90_types, only: kmesh_info_type, wannier_data_type, atom_data_type, dis_manifold_type, &
                         kpoint_path_type, print_output_type, ws_region_type, ws_distance_type, timer_list_type, &
                         w90_system_type
    use w90_utility, only: utility_recip_lattice_base
    use w90_wannier90_types, only: w90_calculation_type, wvfn_read_type, output_file_type, &
                                   fermi_surface_plot_type, band_plot_type, wannier_plot_type, real_space_ham_type, &
                                   ham_logical_type
    use w90_ws_distance, only: ws_translate_dist, ws_write_vec
    use w90_error, only: w90_error_type

    implicit none

    ! arguments
    type(real_space_ham_type), intent(inout) :: real_space_ham
    type(w90_error_type), allocatable, intent(out) :: error
    type(timer_list_type), intent(inout) :: timer
    type(ham_logical_type), intent(inout) :: ham_logical

    complex(kind=dp), intent(inout), allocatable :: ham_r(:, :, :)
    complex(kind=dp), intent(inout), allocatable :: ham_k(:, :, :)

    real(kind=dp), intent(inout), allocatable :: wannier_centres_translated(:, :)

    integer, intent(inout), allocatable :: irvec(:, :)
    integer, intent(inout), allocatable :: ndegen(:)
    integer, intent(inout), allocatable :: shift_vec(:, :)
    integer, intent(inout)              :: nrpts
    integer, intent(inout)              :: rpt_origin

    type(atom_data_type), intent(in) :: atom_data
    type(band_plot_type), intent(in) :: band_plot
    type(dis_manifold_type), intent(in) :: dis_manifold
    type(fermi_surface_plot_type), intent(in) :: fermi_surface_plot
    type(kmesh_info_type), intent(in) :: kmesh_info
    type(kpoint_path_type), intent(in) :: kpoint_path
    type(output_file_type), intent(in) :: output_file
    type(print_output_type), intent(in) :: print_output
    type(w90_calculation_type), intent(in) :: w90_calculation
    type(w90_comm_type), intent(in) :: comm
    type(w90_system_type), intent(in) :: w90_system
    type(wannier_data_type), intent(in) :: wannier_data
    type(wannier_plot_type), intent(in) :: wannier_plot
    type(ws_region_type), intent(in) :: ws_region
    type(wvfn_read_type), intent(in) :: wvfn_read

    complex(kind=dp), intent(in) :: m_matrix(:, :, :, :)
    complex(kind=dp), intent(in) :: u_matrix_opt(:, :, :)
    complex(kind=dp), intent(in) :: u_matrix(:, :, :)

    real(kind=dp), intent(in), allocatable :: fermi_energy_list(:)
    real(kind=dp), intent(in) :: bohr
    real(kind=dp), intent(in) :: eigval(:, :)
    real(kind=dp), intent(in) :: kpt_latt(:, :)
    real(kind=dp), intent(in) :: real_lattice(3, 3)

    integer, intent(in) :: mp_grid(3)
    integer, intent(in) :: num_bands
    integer, intent(in) :: num_kpts
    integer, intent(in) :: num_wann
    integer, intent(in) :: stdout
    integer, intent(in) :: dist_k(:)

    character(len=20), intent(in) :: transport_mode
    character(len=50), intent(in) :: seedname

    logical, intent(in) :: have_disentangled
    logical, intent(in) :: lsitesymmetry

    ! local variables
    type(ws_distance_type) :: ws_distance
    real(kind=dp) :: recip_lattice(3, 3), volume
    integer :: nkp, bands_num_spec_points, my_node_id, i
    logical :: have_gamma
    logical :: on_root = .false.

    my_node_id = mpirank(comm)

    if (my_node_id == 0) on_root = .true.

    call utility_recip_lattice_base(real_lattice, recip_lattice, volume)

    ! setup RS cluster for calculations that need it
    if (output_file%write_hr .or. &
        output_file%write_hr_diag .or. &
        output_file%write_r2mn .or. &
        output_file%write_rmn .or. &
        output_file%write_tb .or. &
        w90_calculation%bands_plot .or. &
        w90_calculation%fermi_surface_plot) then

      call hamiltonian_setup(ham_logical, print_output, ws_region, w90_calculation, ham_k, ham_r, &
                             real_lattice, wannier_centres_translated, irvec, mp_grid, ndegen, &
                             num_kpts, num_wann, nrpts, rpt_origin, band_plot%mode, stdout, &
                             timer, error, transport_mode, comm)
      if (allocated(error)) return
    end if

    ! setup RS Hamilton eqn for calculations that need it
    if (output_file%write_hr .or. &
        output_file%write_hr_diag .or. &
        output_file%write_tb .or. &
        w90_calculation%bands_plot .or. &
        w90_calculation%fermi_surface_plot) then

      ! Check if the kmesh includes the gamma point
      have_gamma = .false.
      do nkp = 1, num_kpts
        if (all(abs(kpt_latt(:, nkp)) < eps6)) have_gamma = .true.
      end do
      if (.not. have_gamma) then
        write (stdout, '(1x,a)') '!!!! Kpoint grid does not include Gamma. '// &
          ' Interpolation may be incorrect. !!!!'
      end if

      ! Transform Hamiltonian to WF basis
      call hamiltonian_get_hr(atom_data, dis_manifold, ham_logical, real_space_ham, print_output, &
                              ham_k, ham_r, u_matrix, u_matrix_opt, eigval, kpt_latt, &
                              real_lattice, wannier_data%centres, wannier_centres_translated, &
                              irvec, shift_vec, nrpts, num_bands, num_kpts, num_wann, &
                              have_disentangled, stdout, timer, error, lsitesymmetry, comm)

      if (allocated(error)) return
    end if

    if (on_root) then
      if (print_output%timing_level > 0) call io_stopwatch_start('plot: main', timer)

      if (print_output%iprint > 0) then
        ! Print the header only if there is something to plot
        if (output_file%write_hr .or. &
            output_file%write_r2mn .or. &
            output_file%write_rmn .or. &
            output_file%write_tb .or. &
            output_file%write_u_matrices .or. &
            w90_calculation%bands_plot .or. &
            w90_calculation%fermi_surface_plot .or. &
            w90_calculation%wannier_plot) then
          write (stdout, '(1x,a)') '*---------------------------------------------------------------------------*'
          write (stdout, '(1x,a)') '|                               PLOTTING                                    |'
          write (stdout, '(1x,a)') '*---------------------------------------------------------------------------*'
          write (stdout, *)
        end if
      end if

      if (w90_calculation%fermi_surface_plot) then
        call plot_fermi_surface(fermi_energy_list, recip_lattice, fermi_surface_plot, num_wann, &
                                ham_r, irvec, ndegen, nrpts, print_output%timing_level, stdout, &
                                seedname, timer, error, comm)
        if (allocated(error)) return
      end if

      if (output_file%write_hr .or. output_file%write_tb) then
        call ws_translate_dist(ws_distance, ws_region, num_wann, &
                               wannier_data%centres, real_lattice, mp_grid, nrpts, irvec, &
                               error, comm, force_recompute=.false.)
        if (allocated(error)) return

        call ws_write_vec(ws_distance, nrpts, irvec, num_wann, ws_region%use_ws_distance, &
                          seedname, error, comm)
        if (allocated(error)) return
      end if

      ! calculate and write projection of WFs on original bands in outer window
      ! only meaningful in disentanglement case (and otherwise lwindow is not available)
      if (output_file%write_proj .and. num_bands > num_wann) then
        call plot_calc_projection(num_bands, num_wann, num_kpts, u_matrix_opt, eigval, &
                                  dis_manifold%lwindow, print_output%timing_level, &
                                  print_output%iprint, stdout, timer)
        if (allocated(error)) return
      end if

      if (output_file%write_bvec) then
        call plot_bvec(kmesh_info, num_kpts, seedname, error, comm)
        if (allocated(error)) return
      end if

      if (output_file%write_hr) then
        ! this is a trivial matrix write; no need to parallelize
        call hamiltonian_write_hr(ham_r, irvec, ndegen, nrpts, num_wann, &
                                  print_output%timing_level, seedname, timer, error, comm)
        if (allocated(error)) return
      end if

      if (output_file%write_hr_diag) then
        if (print_output%iprint > 0) then
          write (stdout, *)
          write (stdout, '(1x,a)') 'On-site Hamiltonian matrix elements'
          write (stdout, '(3x,a)') '  n        <0n|H|0n> (eV)'
          write (stdout, '(3x,a)') '-------------------------'
          do i = 1, num_wann
            write (stdout, '(3x,i3,5x,f12.6)') i, real(ham_r(i, i, rpt_origin), kind=dp)
          end do
          write (stdout, *)
        end if
      end if

      if (output_file%write_u_matrices) then
        call plot_u_matrices(u_matrix_opt, u_matrix, kpt_latt, dis_manifold, have_disentangled, &
                             num_wann, num_kpts, num_bands, seedname, error, comm)
        if (allocated(error)) return
      end if

      if (output_file%write_vdw_data) then
        ! aam: write data required for vdW utility
        call plot_write_vdw_data(num_wann, wannier_data, real_lattice, u_matrix, u_matrix_opt, &
                                 have_disentangled, w90_system, error, comm, stdout, seedname)
        if (allocated(error)) return
      end if

      if (output_file%write_xyz) then
        call plot_write_xyz(real_space_ham%translate_home_cell, num_wann, wannier_data%centres, &
                            real_lattice, atom_data, print_output, error, comm, stdout, seedname)
        if (allocated(error)) return
      end if
    end if !on_root

    if (w90_calculation%bands_plot) then
      bands_num_spec_points = 0
      if (allocated(kpoint_path%labels)) bands_num_spec_points = size(kpoint_path%labels)

      call plot_interpolate_bands(mp_grid, real_lattice, band_plot, kpoint_path, real_space_ham, &
                                  ws_region, print_output, recip_lattice, num_wann, wannier_data, &
                                  ham_r, irvec, ndegen, nrpts, wannier_centres_translated, &
                                  ws_distance, bands_num_spec_points, stdout, seedname, timer, &
                                  error, comm)
      if (allocated(error)) return
    end if

    if (output_file%svd_omega) then
      call plot_svd_omega_i(num_wann, num_kpts, kmesh_info, m_matrix, print_output, timer, dist_k, &
                            error, comm, stdout)
      if (allocated(error)) return
    end if

    if (output_file%write_rmn) then
      ! parallel write_rmn
      call plot_write_rmn(kmesh_info, m_matrix, kpt_latt, irvec, nrpts, num_kpts, num_wann, &
                          seedname, dist_k, error, comm)
      if (allocated(error)) return
    end if

    if (output_file%write_r2mn) then
      ! write matrix elements <m|r^2|n> to file
      call plot_write_r2mn(num_kpts, num_wann, kmesh_info, m_matrix, seedname, dist_k, error, comm)
      if (allocated(error)) return
    end if

    if (output_file%write_tb) then
      call hamiltonian_write_tb(kmesh_info, ham_r, m_matrix, kpt_latt, real_lattice, irvec, &
                                ndegen, nrpts, num_kpts, num_wann, print_output%timing_level, &
                                seedname, timer, dist_k, error, comm)
      if (allocated(error)) return
    end if

    if (w90_calculation%wannier_plot) then
      call plot_wannier(wannier_plot, wvfn_read, wannier_data, print_output, u_matrix_opt, &
                        dis_manifold, real_lattice, atom_data, kpt_latt, u_matrix, num_kpts, &
                        num_bands, num_wann, have_disentangled, w90_system%spinors, bohr, stdout, &
                        seedname, timer, dist_k, error, comm)
      if (allocated(error)) return
    end if

    if (on_root .and. print_output%timing_level > 0) call io_stopwatch_stop('plot: main', timer)
  end subroutine plot_main