Go to the documentation of this file.00001
00002
00003 inline double& dsymatrix::operator()(const long& i, const long& j)
00004 {VERBOSE_REPORT;
00005 #ifdef CPPL_DEBUG
00006 if( i<0 || j<0 || n<=i || n<=j ){
00007 ERROR_REPORT;
00008 std::cerr << "The required component is out of the matrix size." << std::endl
00009 << "Your input was (" << i << "," << j << ")." << std::endl;
00010 exit(1);
00011 }
00012 #endif//CPPL_DEBUG
00013
00014 if( i >= j ) {
00015
00016 return darray[j][i];
00017 } else {
00018
00019 return darray[i][j];
00020 }
00021 }
00022
00023
00024
00025 inline double dsymatrix::operator()(const long& i, const long& j) const
00026 {VERBOSE_REPORT;
00027 #ifdef CPPL_DEBUG
00028 if( i<0 || j<0 || n<=i || n<=j ){
00029 ERROR_REPORT;
00030 std::cerr << "The required component is out of the matrix size." << std::endl
00031 << "Your input was (" << i << "," << j << ")." << std::endl;
00032 exit(1);
00033 }
00034 #endif//CPPL_DEBUG
00035
00036 if( i >= j ) {
00037
00038 return darray[j][i];
00039 } else {
00040
00041 return darray[i][j];
00042 }
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 inline dsymatrix& dsymatrix::set(const long& i, const long& j, const double& v)
00052 {VERBOSE_REPORT;
00053 #ifdef CPPL_DEBUG
00054 if( i<0 || j<0 || n<=i || n<=j ){
00055 ERROR_REPORT;
00056 std::cerr << "The required component is out of the matrix size." << std::endl
00057 << "Your input was (" << i << "," << j << ")." << std::endl;
00058 exit(1);
00059 }
00060 #endif//CPPL_DEBUG
00061
00062 if( i >= j ) {
00063
00064 darray[j][i] =v;
00065 } else {
00066
00067 darray[i][j] =v;
00068 }
00069 return *this;
00070 }
00071
00072
00073
00074
00075
00076
00077 inline std::ostream& operator<<(std::ostream& s, const dsymatrix& mat)
00078 {VERBOSE_REPORT;
00079 for(long i=0; i<mat.n; i++){
00080 for(long j=0; j<=i; j++){
00081 s << " " << mat(i,j) << " ";
00082 }
00083 for(long j=i+1; j<mat.n; j++){
00084 s << "{" << mat(i,j) << "}";
00085 }
00086 s << std::endl;
00087 }
00088 return s;
00089 }
00090
00091
00092
00093
00094
00095
00096 inline void dsymatrix::write(const char* filename) const
00097 {VERBOSE_REPORT;
00098 std::ofstream ofs(filename, std::ios::trunc);
00099 ofs.setf(std::cout.flags());
00100 ofs.precision(std::cout.precision());
00101 ofs.width(std::cout.width());
00102 ofs.fill(std::cout.fill());
00103
00104 ofs << "#dsymatrix" << " " << n << std::endl;
00105 for(long i=0; i<n; i++){
00106 for(long j=0; j<=i; j++){
00107 ofs << operator()(i,j) << " ";
00108 }
00109 ofs << std::endl;
00110 }
00111
00112 ofs.close();
00113 }
00114
00115
00116 inline void dsymatrix::read(const char* filename)
00117 {VERBOSE_REPORT;
00118 std::ifstream s(filename);
00119 if(!s){
00120 ERROR_REPORT;
00121 std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
00122 exit(1);
00123 }
00124
00125 std::string id;
00126 s >> id;
00127 if( id != "dsymatrix" && id != "#dsymatrix" ){
00128 ERROR_REPORT;
00129 std::cerr << "The type name of the file \"" << filename << "\" is not dsymatrix." << std::endl
00130 << "Its type name was " << id << " ." << std::endl;
00131 exit(1);
00132 }
00133
00134 s >> n;
00135 resize(n);
00136 for(long i=0; i<n; i++){
00137 for(long j=0; j<=i; j++ ){
00138 s >> operator()(i,j);
00139 }
00140 }
00141 if(s.eof()){
00142 ERROR_REPORT;
00143 std::cerr << "There is something is wrong with the file \"" << filename << " ." << std::endl
00144 << "Most likely, there is not enough data components, or a linefeed code or space code is missing at the end of the last line." << std::endl;
00145 exit(1);
00146 }
00147
00148 s >> id;
00149 if(!s.eof()){
00150 ERROR_REPORT;
00151 std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00152 << "Most likely, there are extra data components." << std::endl;
00153 exit(1);
00154 }
00155
00156 s.close();
00157 }