00001 #include <iostream>
00002 #include <fstream>
00003 #include <iomanip>
00004 #include <string>
00005 #include "yasper.h"
00006 #include "message.h"
00007 #include "parametermap.h"
00008 #include "cheezyparser.h"
00009 #include "kernel_chooser.h"
00010 #include "sou1d_legendre.h"
00011 #include "sou1d_laguerre.h"
00012 #include "sou1d_hermite.h"
00013 #include "sou1d_chebyshev.h"
00014 #include "sou1d_histo.h"
00015 #include "sou1d_bsplines.h"
00016 #include "sou1d_gauss.h"
00017 #include "sou3d_ylm.h"
00018 #include "corr3d_ylm.h"
00019 #include "corr3d_histo.h"
00020 #include "sou3d_histo.h"
00021 #include "constants.h"
00022
00023 using namespace std;
00024
00025
00026
00027
00028 void plotWidget1d( yasper::ptr< CObject1d > pExpansion, const parameterMap& inMap, double xmin, double xmax );
00029 void plot3dSlices( yasper::ptr< CObject3d > pObj, const parameterMap& inMap );
00030 void getHelp(void);
00031 int main(int argc, char* argv[]);
00032
00033
00034
00035
00036
00037
00039 void getHelp(void){
00040 cout<<"\n";
00041 cout<<"\nUsage: scplot <option> [inputFile.dat]"<<endl;
00042 cout<<" options -h, -help, --help all print this message, then quit"<<endl;
00043 cout<<" -legendre Print out using Legendre polynomial basis" <<endl;
00044 cout<<" -bspline Print out using Basis Spline basis" <<endl;
00045 cout<<" -laguerre Print out using Laguerre function basis" <<endl;
00046 cout<<" -chebyshev Print out using Chebyshev polynomial basis" <<endl;
00047 cout<<" -histogram Print out using Histogram basis" <<endl;
00048 cout<<" -hermite Print out using Hermite function basis" <<endl;
00049 cout<<" -gaussian Print out using using Gaussian class" <<endl;
00050 cout<<" -correlation inputFile.dat is a correlation, only histogram basis available" <<endl;
00051 cout<<" -3dsphr inputFile.dat is a 3d object, in spherical harmonics"<<endl;
00052 cout<<" -3dcarthisto inputFile.dat is a 3d Cartesian histogram object"<<endl;
00053 exit(0);
00054 }
00055
00056
00057 int main(int argc, char* argv[]){
00058
00059 cout << "*** Widget to PLOT Sources and Correlation (SCPLOT) using CorAL ***"<<endl;
00060 cout << " (we need a catchy name for this code) "<<endl;
00061 cout << endl;
00062
00063 bool got_file = false;
00064 bool is_3dsphr_object = false;
00065 bool is_3dcarthisto_object = false;
00066
00067
00068 if (argc==1) getHelp();
00069 string paramFile("");
00070 vector<string> modeList;
00071 for (int iarg = 1; iarg<argc; ++iarg){
00072 string sarg(argv[iarg]);
00073 if (sarg=="-help") getHelp();
00074 if (sarg=="--help") getHelp();
00075 if (sarg=="-h") getHelp();
00076 if (sarg=="-3dsphr") is_3dsphr_object=true;
00077 else if (sarg=="-3dcarthisto") is_3dcarthisto_object=true;
00078 else if (sarg.substr(0,1)=="-") modeList.push_back(sarg);
00079 else {
00080 paramFile = sarg;
00081 got_file = true;
00082 }
00083 }
00084
00085
00086 if (!got_file) {
00087 MESSAGE<<"No inputFile parameter file given!!"<<ENDM_WARN;
00088 getHelp();
00089 }
00090 parameterMap inMap;
00091 parameter::ReadParsFromFile( inMap, paramFile );
00092
00093 if ( !is_3dsphr_object && !is_3dcarthisto_object ) {
00094 yasper::ptr< CObject1d > pExpansion;
00095 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it)
00096 {
00097 if ( *it == "-legendre" ) { pExpansion = new CLegendrePolynomialExpansion1d; }
00098 else if ( *it == "-bspline" ) { pExpansion = new CBasisSpline1d; }
00099 else if ( *it == "-laguerre" ) { pExpansion = new CLaguerrePolynomialExpansion1d; }
00100 else if ( *it == "-chebyshev" ) { pExpansion = new CChebyshevPolynomialExpansion1d; }
00101 else if ( *it == "-histogram" ) { pExpansion = new CHistogram1d; }
00102 else if ( *it == "-hermite" ) { pExpansion = new CHermiteFunctionExpansion1d; }
00103 else if ( *it == "-gaussian" ) { pExpansion = new CGaussianSource; }
00104 else if ( *it == "-correlation" ) { pExpansion = new CHistogram1d; }
00105 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00106 }
00107 pExpansion->Read( inMap );
00108 plotWidget1d( pExpansion, inMap, 0.0, 100.0 );
00109 }
00110 else if ( is_3dsphr_object ){
00111 yasper::ptr< CObject3d > pObj;
00112 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it)
00113 {
00114 if ( *it == "-legendre" ) { pObj = new CSphericalHarmonicExpansion< CLegendrePolynomialExpansion1d >; }
00115 else if ( *it == "-bspline" ) { pObj = new CSphericalHarmonicExpansion< CBasisSpline1d >; }
00116 else if ( *it == "-laguerre" ) { pObj = new CSphericalHarmonicExpansion< CLaguerrePolynomialExpansion1d >; }
00117 else if ( *it == "-chebyshev" ) { pObj = new CSphericalHarmonicExpansion< CChebyshevPolynomialExpansion1d >; }
00118 else if ( *it == "-histogram" ) { pObj = new CSphericalHarmonicExpansion< CHistogram1d >; }
00119 else if ( *it == "-hermite" ) { pObj = new CSphericalHarmonicExpansion< CHermiteFunctionExpansion1d >; }
00120 else if ( *it == "-gaussian" ) { pObj = new CSphericalHarmonicExpansion< CGaussianSource >; }
00121 else if ( *it == "-correlation" ) { pObj = new CSphericalHarmonicExpansion< CHistogram1d >; }
00122 else MESSAGE<<"Unknown mode: '"<<*it<<ENDM_WARN;
00123 }
00124 pObj->Read( inMap );
00125 pObj->readTerms();
00126 plot3dSlices( pObj, inMap );
00127 }
00128 else if ( is_3dcarthisto_object ){
00129 yasper::ptr< CObject3d > pObj = new CHistogram3d;
00130 pObj->Read( inMap );
00131 plot3dSlices( pObj, inMap );
00132 }
00133 return true;
00134 }
00135
00136
00137 void plotWidget1d( yasper::ptr< CObject1d > pExpansion, const parameterMap& inMap, double xmin, double xmax ){
00138 string outFile = parameter::getS(inMap,"plot_file","output_plot.dat");
00139 cout << " Plotting object to " << outFile << endl;
00140 double x;
00141 ofstream fout(outFile.c_str());
00142 for (int n=0;n<100;++n) {
00143 x = (xmax-xmin)*double(n)/100.0 + xmin;
00144 fout << x << " " << pExpansion->getValue(x)<<" "<<pExpansion->getError(x)<<endl;
00145 }
00146 }
00147
00148
00149 void plot3dSlices( yasper::ptr< CObject3d > pObj, const parameterMap& inMap ){
00150 string xFileName = parameter::getS(inMap,"plot_file_x","output_plot_x.dat");
00151 string yFileName = parameter::getS(inMap,"plot_file_y","output_plot_y.dat");
00152 string zFileName = parameter::getS(inMap,"plot_file_z","output_plot_z.dat");
00153 cout << "Writing X slice to plot file "<<xFileName<<endl;
00154 ofstream dataX( xFileName.c_str() );
00155 for (int i=0; i<52; ++i){
00156 double x = (double)i;
00157 dataX << x << " " << pObj->getValueCart(x,0.,0.) << " " << pObj->getErrorCart(x,0.,0.)<<endl;
00158 }
00159 cout << "Writing Y slice to plot file "<<yFileName<<endl;
00160 ofstream dataY( yFileName.c_str() );
00161 for (int i=0; i<52; ++i){
00162 double x = (double)i;
00163 dataY << x << " " << pObj->getValueCart(0.,x,0.) << " " << pObj->getErrorCart(0.,x,0.)<<endl;
00164 }
00165 cout << "Writing Z slice to plot file "<<zFileName<<endl;
00166 ofstream dataZ( zFileName.c_str() );
00167 for (int i=0; i<52; ++i){
00168 double x = (double)i;
00169 dataZ << x << " " << pObj->getValueCart(0.,0.,x) << " " << pObj->getErrorCart(0.,0.,x)<<endl;
00170 }
00171 }
00172
00173