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