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