/* $Id: cnubeam_comp.h,v 1.7 2009-12-08 17:03:25 Alex_Pletzer Exp $ */

// nubeam includes 
#include "nbiTypes.h"

// plasma_state includes
#include "cpp/cxxps.h"

// fortran name mangling
#include "fpreproc/f77name.h"

// some prototypes

#ifndef CNUBEAM_COMP
#define CNUBEAM_COMP

#ifdef __cplusplus
extern "C" {
#endif

#define nbOpenLogFile F77NAME(nbi_open_log_file)
  void nbOpenLogFile(const char* logfile, size_t);

#define nbCloseLogFile F77NAME(nbi_close_log_file)
  void nbCloseLogFile();

#define nbCtrlInitDefault F77NAME(cnbi_ctrl_init_dflt)
  void nbCtrlInitDefault(nbiCtrlInit* blk);

#define nbCtrlInitCdfread F77NAME(cnbi_ctrl_init_cdfread)
  void nbCtrlInitCdfread(const char* filename, nbiCtrlInit* blk, int* ierr, 
			size_t);

#define nbCtrlInitRead F77NAME(cnbi_ctrl_init_read)
  void nbCtrlInitRead(const char* filename, nbiCtrlInit* blk, int* ierr, 
			size_t);

#define nbCtrlInitialize F77NAME(cnubeam_ctrl_init)
  void nbCtrlInitialize(int psHandle[], nbiCtrlInit* blk, int* ierr);

#define nbStates F77NAME(nbi_states)
  void nbStates(const char* filenamefld, const char* filenameptcl, 
		 const char* action, const int* irunmode, int* ierr,
		 size_t filenamefld_len, 
		 size_t filenameptcl_len,
		 size_t action_len);

#define nbWorkpathRetrieve F77NAME(nubeam_workpath_retrieve)
  void nbWorkpathRetrieve(char* zpath, size_t);

#define nbWorkpathReset F77NAME(nubeam_workpath_reset)
  void nbWorkpathReset(const char* zpath, size_t);

#define nbCtrlUpdateDefault F77NAME(cnbi_ctrl_update_dflt)
  void nbCtrlUpdateDefault(nbiCtrlUpdate* blk);

#define nbCtrlUpdateCdfread F77NAME(cnbi_ctrl_update_cdfread)
  void nbCtrlUpdateCdfread(const char* filename, nbiCtrlUpdate* blk, int* ierr,
			   size_t);

#define nbCtrlUpdateRead F77NAME(cnbi_ctrl_update_read)
  void nbCtrlUpdateRead(const char* filename, nbiCtrlUpdate* blk, int* ierr,
			   size_t);

#define nbCtrlStep F77NAME(cnubeam_ctrl_step)
  void nbCtrlStep(int ss_inh[], int ss_outh[], nbiCtrlUpdate* blk, int* ierr); 

#define nbCtrlStepChild F77NAME(cnubeam_ctrl_step_child)
  void nbCtrlStepChild( int* ierr); 

#define nbCtrlNostep F77NAME(cnubeam_ctrl_nostep)
  void nbCtrlNostep(int ss_inh[],int* ierr); 

#define nbOutputAll F77NAME(nbo_output_all)
  void nbOutputAll(int* ierr);

#define nbiSetComm F77NAME(nbi_set_comm)
  void nbiSetComm(const int *);

#define nbiSetMyid F77NAME(nbi_set_myid)
  void nbiSetMyid(const int *);

#define nbiSetNumprocs F77NAME(nbi_set_numprocs)
  void nbiSetNumprocs(const int *);

#ifdef __cplusplus
}
#endif

/**nubeam_workpath_retrieve
 * Rudimentary read and parse Fortran namelist file routine
 *
 * @param filename ascii file to open
 * @param kv key=value hash table to fill in
 */
void cnbFillInNamelistValues(const std::string& filename, 
			     std::map<std::string, 
			     std::string> &kv);

int cnbGetAction(std::string &action, bool &init);

int cnbGetWorkpath(std::string &workpath, bool &workpath_cwd);

int cnbGetPreactdir(std::string &preactdir);

int cnbGetAdasdir(std::string &adasdir);

int cnbParseNamelistFile(const int init, std::string &filename, 
		      std::map<std::string, std::string> &kv,
		      int &iinit, int &istep, bool &ipso, 
		      bool &ps_update_flag);

void cnbErrorCheck(const int ier, const std::string &msg, const int line);

int cnbGetMax_mpi_int_block(std::string& max_mpi_int_block);

int cnbGetMax_mpi_r8_block(std::string& max_mpi_r8_block);

#endif // CNUBEAM_COMP
