#include <fstream>
#include <iomanip>
#include <vector>
#include <iostream>
//
// function for making source data of animation
//
int fileoutput(std::vector<double>& x, int time)
{
//
// the output file
//
std::fstream outputfile;
outputfile.open("outputfile", std::ios::out);
// fileopen check
if ( ! outputfile.is_open() ){
std::cerr << "Open outputfile error" << std::endl;
return EXIT_FAILURE;
}
// write the movement in the "outputfile" (diagonal movement of a point)
else
outputfile << x[0] << " " << x[1] << std::endl;
outputfile.close();
//
// shell script file for renaming the "outputfile"
//
std::fstream filerenamecom;
filerenamecom.open("filerenamecom", std::ios::out);
// fileopen check
if ( ! filerenamecom.is_open() ){
std::cerr << "Open outputfile error" << std::endl;
return EXIT_FAILURE;
}
else{
filerenamecom << "mv outputfile "
<< std::setfill('0') << std::setw(5) << std::right << time << std::endl;
}
filerenamecom.close();
// excute and remove the filerenamecom
system("sh ./filerenamecom");
system("rm ./filerenamecom");
return EXIT_SUCCESS;
}
//
// the main funciton
//
int main(){
std::vector<double> x(2);
for(int time=0; time<100; ++time){
x[0] = static_cast<double>(time);
x[1] = static_cast<double>(time);
fileoutput(x, time);
}
return EXIT_SUCCESS;
}