00001
00003 inline __zhecomplex zhematrix::operator()(const long& i, const long& j)
00004 {
00005 #ifdef CPPL_VERBOSE
00006 std::cerr << "# [MARK] zhematrix::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] zhematrix::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
00022 if(i>=j){ return __zhecomplex( Darray[j][i], i, j ); }
00023 else{ return __zhecomplex( Darray[i][j], i, j ); }
00024 }
00025
00026
00028 inline std::complex<double> zhematrix::operator()(const long& i, const long& j) const
00029 {
00030 #ifdef CPPL_VERBOSE
00031 std::cerr << "# [MARK] zhematrix::operator()(const long&, const long&) const"
00032 << std::endl;
00033 #endif//CPPL_VERBOSE
00034
00035 #ifdef CPPL_DEBUG
00036 if( i<0 || j<0 || N<=i || N<=j ){
00037 std::cerr << "[ERROR] zhematrix::operator()(long, long) const" << std::endl
00038 << "The required component is out of the matrix size."
00039 << std::endl
00040 << "Your input was (" << i << "," << j << ")." << std::endl;
00041 exit(1);
00042 }
00043 #endif//CPPL_DEBUG
00044
00045
00046
00047 if(i>=j){ return Darray[j][i]; }
00048 else{ return std::conj(Darray[i][j]); }
00049 }
00050
00054
00055
00057 inline void zhematrix::set(const long& i, const long& j,
00058 const std::complex<double>& v) const
00059 {
00060 #ifdef CPPL_VERBOSE
00061 std::cerr << "# [MARK] zhematrix::set(const long&, const long&, const std::complex<double>&) const"
00062 << std::endl;
00063 #endif//CPPL_VERBOSE
00064
00065 #ifdef CPPL_DEBUG
00066 if( i<0 || j<0 || N<=i || N<=j ){
00067 std::cerr << "[ERROR] zhematrix::set"
00068 << "(long&, long&, std::complex<double>&) const" << std::endl
00069 << "The required component is out of the matrix size."
00070 << std::endl
00071 << "Your input was (" << i << "," << j << ")." << std::endl;
00072 exit(1);
00073 }
00074 #endif//CPPL_DEBUG
00075
00076
00077
00078 if(i>=j){ Darray[j][i] = v; }
00079 else{ Darray[i][j] = std::conj(v); }
00080 }
00081
00085
00086
00087 inline std::ostream& operator<<(std::ostream& s, const zhematrix& mat)
00088 {
00089 #ifdef CPPL_VERBOSE
00090 std::cerr << "# [MARK] operator<<(std::ostream&, const zhematrix&)"
00091 << std::endl;
00092 #endif//CPPL_VERBOSE
00093
00094 for(long i=0; i<mat.N; i++){
00095 for(long j=0; j<mat.N; j++){
00096 if(i>j){ s << " " << mat(i,j) << " "; }
00097 else if(i==j){ s << " " << std::real(mat(i,i)) << " "; }
00098 else{ s << "{" << std::conj(mat(j,i)) << "} "; }
00099 }
00100 s << std::endl;
00101
00102 #ifdef CPPL_DEBUG
00103 if(std::fabs(std::imag(mat(i,i))) > CPPL_EPS){
00104 std::cerr << "[WARNING] operator<<(std::ostream&, const zhematrix&)"
00105 << std::endl
00106 << "The " << i << "th diagonal component of the zhematrix"
00107 << "is not a real number." << std::endl;
00108 }
00109 #endif//CPPL_DEBUG
00110 }
00111
00112 return s;
00113 }
00114
00118
00119
00120 inline void zhematrix::write(const char* filename) const
00121 {
00122 #ifdef CPPL_VERBOSE
00123 std::cerr << "# [MARK] zhematrix::write(const char*) const"
00124 << std::endl;
00125 #endif//CPPL_VERBOSE
00126
00127 std::ofstream s(filename, std::ios::trunc);
00128
00129 s << "zhematrix" << " " << 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 #ifdef CPPL_DEBUG
00137 if(std::fabs(std::imag(operator()(i,i))) > CPPL_EPS){
00138 std::cerr << "[WARNING] zhematrix::write(const char*)" << std::endl
00139 << "The " << i << "th diagonal component of the zhematrix"
00140 << "is not a real number." << std::endl;
00141 }
00142 #endif//CPPL_DEBUG
00143 }
00144
00145 s.close();
00146 }
00147
00148
00149 inline void zhematrix::read(const char* filename)
00150 {
00151 #ifdef CPPL_VERBOSE
00152 std::cerr << "# [MARK] zhematrix::read(const char*)"
00153 << std::endl;
00154 #endif//CPPL_VERBOSE
00155
00156 std::ifstream s(filename);
00157 if(!s){
00158 std::cerr << "[ERROR] zhematrix::read(const char*) " << std::endl
00159 << "The file \"" << filename << "\" can not be opened."
00160 << std::endl;
00161 exit(1);
00162 }
00163
00164 std::string id;
00165 s >> id;
00166 if( id != "zhematrix" ){
00167 std::cerr << "[ERROR] zhematrix::read(const char*) " << std::endl
00168 << "The type name of the file \"" << filename
00169 << "\" is not zhematrix." << std::endl
00170 << "Its type name was " << id << " ." << std::endl;
00171 exit(1);
00172 }
00173
00174 s >> N;
00175 resize(N);
00176 for(long i=0; i<N; i++){
00177 for(long j=0; j<=i; j++ ){
00178 s >> Darray[j][i];
00179
00180 }
00181 }
00182 if(s.eof()){
00183 std::cerr << "[ERROR] zhematrix::read(const char*) " << std::endl
00184 << "There is something is wrong with the file \""
00185 << filename << " ." << std::endl
00186 << "Most likely, there is not enough data components, "
00187 << "or a linefeed code or space code is missing "
00188 << "at the end of the last line." << std::endl;
00189 exit(1);
00190 }
00191
00192 s.close();
00193 }