00001
00022 #include "data.h"
00023 bool loadPosVelFromFile(std::string filename, int &N, FLOAT_ARRAY_TYPE *pos, FLOAT_ARRAY_TYPE *vel)
00024 {
00025 std::ifstream indata(filename.c_str());
00026 assert(indata.good());
00027 for (int i=0; i<N; ++i)
00028 {
00029 if (!indata.eof())
00030 {
00031 indata >> pos[i].x >> pos[i].y >> pos[i].z >> vel[i].x >> vel[i].y >> vel[i].z;
00032 }
00033 else
00034 {
00035 std::cout<<"Not enough input data is provieded for "<<N<<"particles!\n";
00036 indata.close();
00037 return false;
00038 }
00039 }
00040 indata.close();
00041 return true;
00042 }
00043
00044
00045 bool loadInitData(std::string filename, FLOAT_ARRAY_TYPE *pos, FLOAT_ARRAY_TYPE *vel, int* cnn, int &N, int &numNN)
00046 {
00047 std::ifstream indata(filename.c_str());
00048 if (!indata.good())
00049 {
00050 std::cout<<filename<<" could not be read!\n";
00051 return false;
00052 }
00053 for (int i=0; i<N; ++i)
00054 {
00055 if (!indata.eof())
00056 {
00057 indata >> pos[i].x >> pos[i].y >> pos[i].z >> vel[i].x >> vel[i].y >> vel[i].z;
00058 for (int j=0; j<numNN; ++j)
00059 {
00060
00061 indata >>cnn[i+j*N];
00062 }
00063 }
00064 else
00065 {
00066 std::cout<<"Not enough input data is provieded for "<<N<<"particles!\n";
00067 return false;
00068 }
00069 }
00070 indata.close();
00071 return true;
00072 }
00073
00074
00075 bool writeData(std::string &basename, FLOAT_ARRAY_TYPE *pos, FLOAT_ARRAY_TYPE *vel, int *cnn, int &N, int &numNN, int timestamp)
00076 {
00077 std::ostringstream ss_file;
00078 std::string file;
00079 std::ofstream out;
00080 ss_file.fill('0');
00081 ss_file<<basename<<"";
00082 ss_file.width(10);
00083 ss_file<<timestamp;
00084 ss_file.width(1);
00085 ss_file<<".dat";
00086 file = ss_file.str();
00087 out.open(file.c_str());
00088 if (!out.good())
00089 {
00090 std::cout<<"File not open!\n";
00091 return false;
00092 }
00093
00094 out.setf(std::ios_base::scientific);
00095 out.precision(std::numeric_limits< float >::digits10);
00096 for (int i=0; i<N; ++i)
00097 {
00098 out<<pos[i].x<< " "<<pos[i].y<<" "<<pos[i].z<<" "<<vel[i].x<<" "<<vel[i].y<<" "<<vel[i].z<<" ";
00099 for (int j=0; j<numNN; ++j)
00100 {
00101 out<<cnn[i+j*N]<<" ";
00102 }
00103 out<<"\n";
00104 }
00105 out.close();
00106 return true;
00107 }