/** \file bar2dat.h
		\author Vishnu Krishnamachari
		\date June 2006 - May 2008
		\brief Contains the code for generating bar2dat utility.
		
		Compile this source code to generate bar2dat utility. With this utility the .bar files created by the focus3d and dipole_radiation objects can be converted into ascii data files which can be used in gnuplot or MATLAB programs. 
*/

/** \page page1 BAR2DAT utility
	\author Vishnu Krishnamachari,	University of California Irvine, Irvine, CA, USA
	\date June 2006 - May 2008
	\version 1.0
	
	BAR2DAT utility which can be gnerated from the supplied source code can be used for generating ASCII data files from the .bar files that focus3d and dipole_radiation objects create. 
	
	USAGE: bar2dat <filename.bar> <dimensions> <isComplex (y/n)>
		- filename.bar - name of the .bar file
		- dimensions - number of dimensions of the matrix stored in the file
		- isComplex - input 'y' if the data stored is complex and 'n' if not.
		
	Note that .bar files can be opened in any text editor. From the first line of the file which shows the size of the matrix, its dimensions can be deduced. Similarly whether the data stored is complex or not can be obtained by examining the file.
	
	focus3d objects generate a set of files and dipole_radiation objects generate another set of .bar files. A simple shell script can be written to convert these sets of files to their corresponding data flies. 
	
	The following script converts the .bar files generated by focus3d objects and stores in a subfolder called "data_files/":
	\code
	if [ $# -lt 1 ]
	then
		echo Usage: $0 directory
 	else
		if [ -d $1 ]	
			then
				if [ -x bar2dat ]
					then
						./bar2dat $1/x.bar 1 n
						./bar2dat $1/y.bar 1 n
						./bar2dat $1/z.bar 1 n
						./bar2dat $1/theta.bar 1 n
						./bar2dat $1/phi.bar 1 n
						./bar2dat $1/E_focus_x.bar 3 y
						./bar2dat $1/E_focus_y.bar 3 y
						./bar2dat $1/E_focus_z.bar 3 y
						./bar2dat $1/E_incident_x.bar 2 y
						./bar2dat $1/E_incident_y.bar 2 y
						./bar2dat $1/E_incident_z.bar 2 y
						./bar2dat $1/angular_weights.bar 2 y
					else
						echo Error: bar2dat not in path!
				fi	
			else
				echo Error: $1 is not a directory!
		fi
	fi
	\endcode
	
	The following script converts the .bar files generated by dipole_radiation objects and stores in a subfolder called "data_files/":
	\code
	if [ $# -lt 1 ]
	then
		echo Usage: $0 directory
 	else
		if [ -d $1 ]	
			then
				if [ -x bar2dat ]
					then
						./bar2dat $1/x.bar 1 n
						./bar2dat $1/y.bar 1 n
						./bar2dat $1/z.bar 1 n
						./bar2dat $1/theta.bar 1 n
						./bar2dat $1/phi.bar 1 n
						./bar2dat $1/E_dipole_x.bar 3 y
						./bar2dat $1/E_dipole_y.bar 3 y
						./bar2dat $1/E_dipole_z.bar 3 y
						./bar2dat $1/E_far_x.bar 2 y
						./bar2dat $1/E_far_y.bar 2 y
						./bar2dat $1/E_far_z.bar 2 y
						./bar2dat $1/E_refracted_x.bar 2 y
						./bar2dat $1/E_refracted_y.bar 2 y
						./bar2dat $1/E_refracted_z.bar 2 y
					else
						echo Error: bar2dat not in path!
				fi	
			else
				echo Error: $1 is not a directory!
		fi
	fi
	\endcode
*/
	

#ifndef __BAR2DAT_H__
#define __BAR2DAT_H__

#include "utilities.h"

template <int N> void read_bar(string filename, Array<complex<double>,N> &res);
template <int N> void save_double_bar_to_dat(Array<complex<double>,N> A, string outfilename, char im_real_part);
template <int N> void save_bar_to_dat(Array<complex<double>,N> A, string outfilename, char isComplex);
int main(int argc, char** argv);

#endif
