CPPLapack
 All Classes Files Functions Variables Friends
zgematrix-io.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! operator() for non-const object */
00003 inline comple& zgematrix::operator()(const long& i, const long& j)
00004 {VERBOSE_REPORT;
00005 #ifdef  CPPL_DEBUG
00006   if( i<0 || j<0 || m<=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   //return array[i+m*j];
00015   return darray[j][i];
00016 }
00017 
00018 //=============================================================================
00019 /*! operator() for const object */
00020 inline comple zgematrix::operator()(const long& i, const long& j) const
00021 {VERBOSE_REPORT;
00022 #ifdef  CPPL_DEBUG
00023   if( i<0 || j<0 || m<=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   //return array[i+m*j];
00032   return darray[j][i];
00033 }
00034 
00035 ///////////////////////////////////////////////////////////////////////////////
00036 ///////////////////////////////////////////////////////////////////////////////
00037 ///////////////////////////////////////////////////////////////////////////////
00038 
00039 //=============================================================================
00040 /*! set value for const object */
00041 inline zgematrix& zgematrix::set(const long& i, const long& j, const comple& v)
00042 {VERBOSE_REPORT;
00043 #ifdef  CPPL_DEBUG
00044   if( i<0 || j<0 || m<=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   //array[i+m*j] =v;
00053   darray[j][i] =v;
00054   
00055   return *this;
00056 }
00057 
00058 ///////////////////////////////////////////////////////////////////////////////
00059 ///////////////////////////////////////////////////////////////////////////////
00060 ///////////////////////////////////////////////////////////////////////////////
00061 
00062 //=============================================================================
00063 inline std::ostream& operator<<(std::ostream& s, const zgematrix& mat)
00064 {VERBOSE_REPORT;
00065   for(long i=0; i<mat.m; i++){
00066     for(long j=0; j<mat.n; j++){
00067       s << " " << mat(i,j);
00068     }
00069     s << std::endl;
00070   }
00071   return s;
00072 }
00073 
00074 ///////////////////////////////////////////////////////////////////////////////
00075 ///////////////////////////////////////////////////////////////////////////////
00076 ///////////////////////////////////////////////////////////////////////////////
00077 
00078 //=============================================================================
00079 inline void zgematrix::write(const char* filename) const
00080 {VERBOSE_REPORT;
00081   std::ofstream ofs(filename, std::ios::trunc);
00082   ofs.setf(std::cout.flags());
00083   ofs.precision(std::cout.precision());
00084   ofs.width(std::cout.width());
00085   ofs.fill(std::cout.fill());
00086   
00087   ofs << "#zgematrix" << " " << m << " " << n << std::endl;
00088   for(long i=0; i<m; i++){
00089     for(long j=0; j<n; j++ ){
00090       ofs << operator()(i,j) << " ";
00091     }
00092     ofs << std::endl;
00093   }
00094   
00095   ofs.close();
00096 }
00097 
00098 //=============================================================================
00099 inline void zgematrix::read(const char* filename)
00100 {VERBOSE_REPORT;
00101   std::ifstream s( filename );
00102   if(!s){
00103     ERROR_REPORT;
00104     std::cerr << "The file \"" << filename << "\" can not be opened." << std::endl;
00105     exit(1);
00106   }
00107 
00108   std::string id;
00109   s >> id;
00110   if( id != "zgematrix" && id != "#zgematrix" ){
00111     ERROR_REPORT;
00112     std::cerr << "The type name of the file \"" << filename << "\" is not zgematrix." << std::endl
00113               << "Its type name was " << id << " ." << std::endl;
00114     exit(1);
00115   }
00116   
00117   s >> m >> n;
00118   resize(m, n);
00119   for(long i=0; i<m; i++){
00120     for(long j=0; j<n; j++ ){
00121       s >> operator()(i,j);
00122     }
00123   }
00124   if(s.eof()){
00125     ERROR_REPORT;
00126     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00127               << "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;
00128     exit(1);
00129   }
00130   
00131   s >> id;
00132   if(!s.eof()){
00133     ERROR_REPORT;
00134     std::cerr << "There is something is wrong with the file \"" << filename << "\"." << std::endl
00135               << "Most likely, there are extra data components." << std::endl;
00136     exit(1);
00137   }
00138   
00139   
00140   s.close();
00141 }
 All Classes Files Functions Variables Friends