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