// runs through the given file and calculates PAA with a N points in each block std::string PAAaFile(std::string inData, int N) { if (N <= 0) { std::cout << "ERROR: block size is " << N << ": should be greater than 0" << std::endl; return ""; } std::ifstream inFile(inData.c_str()); std::string PAAFile = createPAAFilepath(inData); std::ofstream outFile(PAAFile.c_str()); std::string timePoint; std::size_t newLine = std::string::npos; std::vector<double> data; char delim = ','; if (!inFile) { std::cout << "ERROR: ifstream failed on " << inData << ": " << strerror(errno) << std::endl; return ""; } int len = inFile.tellg(); std::getline(inFile, timePoint); if (timePoint.find(",") == std::string::npos) { // no commas delim = ' '; } inFile.seekg(len, std::ios_base::beg); while (inFile.good()) { // run until N time points are grabbed OR // the end of the time series is hit for (int i=0; (i < N) && (newLine == std::string::npos); i++ ) { // get one time value std::getline(inFile, timePoint, delim); // check if we hit the end of the time series // ex) "number1\nnumber2" newLine = timePoint.find("\n"); data.push_back(stod(timePoint)); } // send one chunk of data to PAA and write to outFile outFile << PAA(data) << " "; // clear data to grab the next chunk data.clear(); // if you hit the end of a time series "number1\nnumber2" if (newLine != std::string::npos) { // timer series break outFile << std::endl << std::endl; // add the second number to data if (timePoint.substr(newLine).size() > 1) { data.push_back(stod(timePoint.substr(newLine))); } // reset newLine newLine = std::string::npos; } } return PAAFile; }
int main(int argc, char*argv[]){ // GalPot Pot("../../Torus/pot/PJM11.Tpot"); Logarithmic Pot(220.,1.,0.9); if(argc<8){ std::cerr<<"Need to pass phase-space point and filename\n"; return 0; } VecDoub X(6,0.); for(unsigned i=0;i<6;++i) X[i]=atof(argv[i+1]); Orbit O(&Pot); // Fudge Actions_AxisymmetricStackel_Fudge AA(&Pot,-30.); // Iterative Torus // IterativeTorusMachine Tor(&AA,&Pot,1e-8,5,1e-3); // Generating Function Actions_Genfunc AG(&Pot,"axisymmetric"); // Average generating Function Actions_Genfunc_Average AGav(&Pot,"axisymmetric"); // uvorb uv_orb UV(&Pot,1.,20.,10,10,"example.delta_uv"); // Polar Adiabatic Actions_PolarAdiabaticApproximation PAA(&Pot,"example.paa",true,false); // Spheroidal Adiabatic Actions_SpheroidalAdiabaticApproximation SAA(&Pot,"example.saa",true,false,-30.); // Spheroidal Adiabatic Actions_StackelFit SF(&Pot); double tt = 10.; if(argc>8) tt=atof(argv[8]); O.integrate(X,tt*Pot.torb(X),0.01*Pot.torb(X)); // O.plot(0,2); std::ofstream outfile; outfile.open(argv[7]); outfile<<"# Fudge Genfunc GenfuncAv uvOrb PAA SAA FIT\n"; int guess_alpha=1; VecDoub Fudge, ITorus, Genfunc, GenfuncAv, uvAct, paaAct, saaAct, fitAct; for(auto i:O.results()){ Fudge = AA.actions(i,&guess_alpha); // ITorus = Tor.actions(i); Genfunc = AG.actions(i); GenfuncAv = AGav.actions(i); uvAct = UV.actions(i); paaAct = PAA.actions(i); saaAct = SAA.actions(i,&guess_alpha); fitAct = SF.actions(i); outfile <<Fudge[0]<<" "<<Fudge[2]<<" " // <<ITorus[0]<<" "<<ITorus[2]<<" " <<Genfunc[0]<<" "<<Genfunc[2]<<" " <<GenfuncAv[0]<<" "<<GenfuncAv[2]<<" " <<uvAct[0]<<" "<<uvAct[2]<<" " <<paaAct[0]<<" "<<paaAct[2]<<" " <<saaAct[0]<<" "<<saaAct[2]<<" " <<fitAct[0]<<" "<<fitAct[2]<<" "; for(auto j:i) outfile<<j<<" "; outfile <<std::endl; } outfile.close(); }