CPPLapack
 All Classes Files Functions Variables Friends
_zgsmatrix-io.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! operator() for const object */
00003 inline comple _zgsmatrix::operator()(const long& i, const long& j) const
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   //////// search (i,j) component ////////
00015   for(std::vector<uint32_t>::iterator p=rows[i].begin(); p!=rows[i].end(); p++){
00016     if( long(data[*p].j)==j ){ return data[*p].v; }
00017   }
00018   
00019   //////// (i,j) component was not found ////////
00020   return comple(0.0,0.0);
00021 }
00022 
00023 ///////////////////////////////////////////////////////////////////////////////
00024 ///////////////////////////////////////////////////////////////////////////////
00025 ///////////////////////////////////////////////////////////////////////////////
00026 
00027 //=============================================================================
00028 inline std::ostream& operator<<(std::ostream& s, const _zgsmatrix& mat)
00029 {VERBOSE_REPORT;
00030   for(long i=0; i<mat.m; i++){
00031     for(long j=0; j<mat.n; j++){
00032       std::vector<uint32_t>::iterator q;
00033       for(q=mat.rows[i].begin(); q!=mat.rows[i].end(); q++){
00034         if( long(mat.data[*q].j)==j ){ break; }
00035       }
00036       if(q!=mat.rows[i].end()){ s << " " << mat.data[*q].v; }
00037       else{ s << " x"; }
00038     }
00039     s << std::endl;
00040   }
00041   
00042   mat.destroy();
00043   return s;
00044 }
00045 
00046 ///////////////////////////////////////////////////////////////////////////////
00047 ///////////////////////////////////////////////////////////////////////////////
00048 ///////////////////////////////////////////////////////////////////////////////
00049 
00050 //=============================================================================
00051 inline void _zgsmatrix::write(const char* filename) const
00052 {VERBOSE_REPORT;
00053   std::ofstream ofs(filename, std::ios::trunc);
00054   ofs.setf(std::cout.flags());
00055   ofs.precision(std::cout.precision());
00056   ofs.width(std::cout.width());
00057   ofs.fill(std::cout.fill());
00058   
00059   ofs << "#zgsmatrix" << " " << m << " " << n << std::endl;
00060   for(std::vector<zcomponent>::const_iterator it=data.begin(); it!=data.end(); it++){
00061     ofs << it->i << " " << it->j << " " << it->v << std::endl;
00062   }
00063   
00064   ofs.close();
00065   destroy();
00066 }
 All Classes Files Functions Variables Friends