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