/*
    DFT++ is a density functional package developed by the research group
    of Professor Tomas Arias

    Copyright 1996-2003 Sohrab Ismail-Beigi

    This file is part of DFT++.

    DFT++ is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DFT++ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DFT++; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    Please see the file CREDITS for a list of authors.

    For academic users, we request that publications using results obtained with
    this software reference

    "New algebraic formulation of density functional calculation," by Sohrab Ismail-Beigi
    and T.A. Arias, Computer Physics Communications 128:1-2, 1-45 (June 2000).

    and, if using the wavelet basis, further reference

    "Multiresolution analysis of electronic structure: semicardinal and wavelet bases,"
    T.A. Arias, Reviews of Modern Physics 71:1, 267-311 (January 1999).

    and 

    "Robust ab initio calculation of condensed matter: transparent convergence through
    semicardinal multiresolution analysis,'' I.P. Daykov, T.A. Arias, and
    Torkel D. Engeness, Physical Review Letters, 90:21, 216402 (May 2003).

    For your convenience, preprints of the above articles may be obtained from
    http://arXiv.org/abs/cond-mat/9909130, 9805262, and 0204411, respectively.
*/

//
// Sohrab Ismail-Beigi           April 2000
//
// This file is defines the function that creates the command list.
// The command list is a linked list of command instances, and each
// command must have a setup function (see <command_name>.c) called
// setup_<command_name>(command *p) that does the setup associated
// with the command (setting string values such as names and comments,
// dependencies, etc.).  It places all of this into a newly allocated
// command instance (using the function defined further below) and
// returns its pointer.  The setup func also uses the input pointer p to
// set its "next" pointer, so as to keep building the list.
//

#include "command.h"

// This function creates the linked list of commands
// by calling all the command setup functions.  Returns
// the head of the linked list.
command* create_command_list()
{
  command* ptr = NULL;

  ptr = setup_electronic_minimization(ptr);
//#ifdef PLANEWAVES
  ptr = setup_calculate_forces(ptr);
//#endif
  ptr = setup_relax_ions(ptr);
  //  ptr = setup_ionic_dynamics(ptr);
  ptr = setup_band_structure(ptr);
  ptr = setup_spinorbit(ptr);
  //  ptr = setup_dump_bands(ptr);
  ptr = setup_finite_diff_test(ptr);
  ptr = setup_lattice(ptr);
  ptr = setup_latt_scale(ptr);
  ptr = setup_ion(ptr);
  ptr = setup_ion_species(ptr);
  ptr = setup_coords_type(ptr);
  ptr = setup_elec_n_bands(ptr);
  ptr = setup_elec_fermi_fillings(ptr);
  ptr = setup_elec_ex_corr(ptr);
  ptr = setup_elec_initial_fillings(ptr);
  ptr = setup_kpoint(ptr);

  ptr = setup_kpoint_folding(ptr);
  ptr = setup_spintype(ptr);
  ptr = setup_ewald(ptr);
  ptr = setup_cntrl_max_elec_steps(ptr);
  ptr = setup_cntrl_elec_stepsize(ptr);
  ptr = setup_cntrl_energy_convergence(ptr);
#ifdef PLANEWAVES
  ptr = setup_cntrl_force_convergence(ptr);
  ptr = setup_cntrl_force_diff_convergence(ptr);
  ptr = setup_cntrl_force_diff_check(ptr);
#endif
  ptr = setup_cntrl_update_stepsize(ptr);
  ptr = setup_cntrl_stepsize_min(ptr);
  ptr = setup_cntrl_nel_fermi_tol(ptr);
  ptr = setup_cntrl_subspace_rotation(ptr);
  ptr = setup_cntrl_dump_n(ptr);
  ptr = setup_cntrl_algorithm(ptr);
  ptr = setup_cntrl_max_ionic_steps(ptr);
  ptr = setup_cntrl_read_density(ptr);
  ptr = setup_cntrl_linmin_method(ptr);
  ptr = setup_cntrl_read_vloc(ptr);
  ptr = setup_cntrl_read_vscloc(ptr);
  ptr = setup_wavefunction(ptr);
  //  ptr = setup_ion_dynamics_param(ptr);
  ptr = setup_ion_relax_param(ptr);
  ptr = setup_symmetries(ptr);
  ptr = setup_symmetry_matrix(ptr);
  // Basis initialization options
#ifdef PLANEWAVES
  ptr = setup_fftbox(ptr);
  ptr = setup_elec_cutoff(ptr);
  ptr = setup_basis(ptr);
#elif defined WAVELETS
  ptr = setup_gridspec(ptr);
  ptr = setup_wl_embedding(ptr);
  ptr = setup_wl_use_L_orthorhombic(ptr);
#else
#error gotta use some basis, man!
#endif

  return ptr;
}

// Allocates a command
command *
alloc_command()
{
  command *c;
  c = (command *)mymalloc(sizeof(command),"class command","alloc_command");
  c->init();
  return c;
}

// Free the memory used by the command linked list
void
free_command_list(command *list)
{
  command *cur,*next;

  cur = list;
  while (cur!= NULL)
    {
      next = cur->next_command;
      myfree(cur);
      cur = next;
    }
}
