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_gauss.h"
00016 #include "sou3d_ylm.h"
00017 #include "sou1d_bsplines.h"
00018 #include "kernel.h"
00019 #include "basisfunc_imager1d.h"
00020 #include "uncoupled_imager3d.h"
00021 #include "constants.h"
00022 #include "corr1d_histo.h"
00023 #include "corr3d_ylm.h"
00024 #include "convolution.h"
00025
00026 using namespace std;
00027
00028
00029
00030
00031 void getHelp(void);
00032 int main(int argc, char* argv[]);
00033
00034
00035
00036
00037
00038
00040 void getHelp(void){
00041 cout<<"\n";
00042 cout<<"\n";
00043 cout<<"\nUsage: converts2c <option> [inputFile.dat]"<<endl;
00044 cout<<" options -h, -help, --help all print this message, then quit"<<endl;
00045 cout<<" -legendre inputFile.dat uses Legendre polynomial basis" <<endl;
00046 cout<<" -bspline inputFile.dat uses Basis Spline basis" <<endl;
00047 cout<<" -laguerre inputFile.dat uses Laguerre function basis" <<endl;
00048 cout<<" -chebyshev inputFile.dat uses Chebyshev polynomial basis" <<endl;
00049 cout<<" -histogram inputFile.dat uses Histogram basis" <<endl;
00050 cout<<" -hermite inputFile.dat uses Hermite function basis" <<endl;
00051 cout<<" -gaussian inputFile.dat is a 1d Gaussian" <<endl;
00052 cout<<" -3d inputFile.dat is a 3d source" <<endl;
00053 cout<<" -convolve Use convoluter, not imager for this (uncertainty not included)" <<endl;
00054 exit(0);
00055 }
00056
00057
00058 int main(int argc, char* argv[]){
00059
00060 cout << "*** Widget to Convert Sources to Correlations (ConvertS2C) using CorAL ***"<<endl;
00061 cout << endl;
00062
00063 bool got_file = false;
00064 bool three_d_source=false;
00065 bool convolve_with_kernel=false;
00066
00067 MESSAGE << CMessage::warning;
00068
00069
00070 if (argc==1) getHelp();
00071 string paramFile("");
00072 vector<string> modeList;
00073 for (int iarg = 1; iarg<argc; ++iarg){
00074 string sarg(argv[iarg]);
00075 if (sarg=="-help") getHelp();
00076 if (sarg=="--help") getHelp();
00077 if (sarg=="-h") getHelp();
00078 if (sarg=="-3d") three_d_source=true;
00079 else if (sarg=="-convolve") convolve_with_kernel=true;
00080 else if (sarg.substr(0,1)=="-") modeList.push_back(sarg);
00081 else {
00082 paramFile = sarg;
00083 got_file = true;
00084 }
00085 }
00086
00087
00088 if (!got_file) {
00089 MESSAGE<<"No inputFile parameter file given!!"<<ENDM_WARN;
00090 getHelp();
00091 }
00092 parameterMap inMap;
00093 parameter::ReadParsFromFile(inMap, paramFile);
00094
00095 if (three_d_source) {
00096 if (convolve_with_kernel) MESSAGE<<"Not written yet!! You have to do it yourself term by term!!"<<ENDM_FATAL;
00097 CCorrFtn3dSphr answer;
00098 parameterMap outMap;
00099 parameterMap sourceInMap;
00100 parameter::ReadParsFromFile(sourceInMap, parameter::getS(inMap,"source_file","input_source.dat"));
00101 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it)
00102 {
00103 if ( *it == "-legendre" ) {
00104 CSourceFtn3dSphr< CSourceFtn1dLegendrePoly > souIn;
00105 souIn.Read( sourceInMap );
00106 souIn.readTerms();
00107 UncoupledLegendrePolyImager3d imager;
00108 imager.Read( inMap );
00109 imager.convertSourceToCorrelation( souIn, answer, inMap );
00110 }
00111 else if ( *it == "-bspline" ) {
00112 CSourceFtn3dSphr< CSourceFtn1dBSpline > souIn;
00113 souIn.Read( sourceInMap );
00114 souIn.readTerms();
00115 UncoupledBasisSplineImager3d imager;
00116 imager.Read( inMap );
00117 imager.convertSourceToCorrelation( souIn, answer, inMap );
00118 }
00119 else if ( *it == "-laguerre" ) {
00120 CSourceFtn3dSphr< CSourceFtn1dLaguerrePoly > souIn;
00121 souIn.Read( sourceInMap );
00122 souIn.readTerms();
00123 UncoupledLaguerrePolyImager3d imager;
00124 imager.Read( inMap );
00125 imager.convertSourceToCorrelation( souIn, answer, inMap );
00126 }
00127 else if ( *it == "-chebyshev" ) {
00128 CSourceFtn3dSphr< CSourceFtn1dChebyshevPoly > souIn;
00129 souIn.Read( sourceInMap );
00130 souIn.readTerms();
00131 UncoupledChebyshevPolyImager3d imager;
00132 imager.Read( inMap );
00133 imager.convertSourceToCorrelation( souIn, answer, inMap );
00134 }
00135 else if ( *it == "-histogram" ) {
00136 CSourceFtn3dSphr< CSourceFtn1dHisto > souIn;
00137 souIn.Read( sourceInMap );
00138 souIn.readTerms();
00139 UncoupledHistoImager3d imager;
00140 imager.Read( inMap );
00141 imager.convertSourceToCorrelation( souIn, answer, inMap );
00142 }
00143 else if ( *it == "-hermite" ) {
00144 CSourceFtn3dSphr< CSourceFtn1dHermitePoly > souIn;
00145 souIn.Read( sourceInMap );
00146 souIn.readTerms();
00147 UncoupledHermitePolyImager3d imager;
00148 imager.Read( inMap );
00149 imager.convertSourceToCorrelation( souIn, answer, inMap );
00150 }
00151 else if ( *it == "-gaussian" ) { MESSAGE<<"Not available in 3d: '"<<*it<<"'"<<ENDM_WARN; }
00152 else MESSAGE<<"Unknown mode: '"<<*it<<"'"<<ENDM_WARN;
00153 }
00154 answer.Write(outMap);
00155 parameter::WriteParsToFile(outMap, parameter::getS(inMap,"correlation_file","output_correlation.dat"));
00156 answer.writeTerms();
00157 }
00158 else {
00159 CCorrFtn1dHisto answer;
00160 parameterMap outMap;
00161 yasper::ptr< CSourceFtnBase > pExpansion;
00162 for ( vector<string>::iterator it=modeList.begin(); it!=modeList.end(); ++it)
00163 {
00164 if ( *it == "-legendre" ) { pExpansion = new CSourceFtn1dLegendrePoly; }
00165 else if ( *it == "-bspline" ) { pExpansion = new CSourceFtn1dBSpline; }
00166 else if ( *it == "-laguerre" ) { pExpansion = new CSourceFtn1dLaguerrePoly; }
00167 else if ( *it == "-chebyshev" ) { pExpansion = new CSourceFtn1dChebyshevPoly; }
00168 else if ( *it == "-histogram" ) { pExpansion = new CSourceFtn1dHisto; }
00169 else if ( *it == "-hermite" ) { pExpansion = new CSourceFtn1dHermitePoly; }
00170 else if ( *it == "-gaussian" ) { pExpansion = new CGaussianSource; }
00171 else MESSAGE<<"Unknown mode: '"<<*it<<"'"<<ENDM_WARN;
00172 }
00173 parameterMap sourceInMap;
00174 parameter::ReadParsFromFile(sourceInMap, parameter::getS(inMap,"source_file","input_source.dat"));
00175 pExpansion->Read( sourceInMap );
00176 if (convolve_with_kernel) {
00177 CBasisFunctionExpansion1d* pJunk = dynamic_cast<CBasisFunctionExpansion1d*>(pExpansion.GetRawPointer());
00178 if (!pJunk) throw MESSAGE << "Dead pointer pJunk"<<ENDM_FATAL;
00179 answer = convolute( *pJunk, inMap );
00180 } else {
00181 CBasisFuncImager1d imager;
00182 imager.Read( inMap );
00183 imager.convertSourceToCorrelation( *pExpansion, answer, inMap );
00184 }
00185 answer.Write(outMap);
00186 parameter::WriteParsToFile(outMap, parameter::getS(inMap,"correlation_file","output_correlation.dat"));
00187 }
00188 return true;
00189 }
00190