DenseLinAlgPack_DMatrixInFunc.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <sstream>
00030 
00031 #include "InputStreamHelperPack_EatInputComment.hpp"
00032 #include "DenseLinAlgPack_DMatrixInFunc.hpp"
00033 #include "DenseLinAlgPack_DVectorInFunc.hpp"
00034 #include "DenseLinAlgPack_DMatrixClass.hpp"
00035 
00036 namespace { // Local inplementation
00037 std::istream& input_gms(std::istream& is, DenseLinAlgPack::DMatrixSlice* gms, const char func[]);
00038 }
00039 
00040 std::istream& DenseLinAlgPack::input(std::istream& is, DMatrix* gm, LinAlgPackIO::fmtflags extra_flags) {
00041   if( !(extra_flags & LinAlgPackIO::ignore_dim_bit) ) {
00042     size_type m, n;
00043     is >> m >> n;
00044     if(is.fail())
00045       throw LinAlgPackIO::InputException( "DenseLinAlgPack::input() {DMatrix}: "
00046         "Input operation of matrix dimension failed.  Check that the constant n "
00047         "is a valid integer." );
00048     if(is.bad())
00049       throw std::ios_base::failure( "DenseLinAlgPack::input() {DMatrix}: "
00050         "Input operation failed because the stream became currupted." );
00051     gm->resize(m,n);
00052   }
00053   DMatrixSlice gms = (*gm)();
00054   return input_gms(is,&gms,"DenseLinAlgPack::input() {DMatrix}");
00055 }
00056 
00057 std::istream& DenseLinAlgPack::input(std::istream& is, DMatrixSlice* gms, LinAlgPackIO::fmtflags extra_flags) {
00058   if( !(extra_flags & LinAlgPackIO::ignore_dim_bit) ) {
00059     size_type m, n;
00060     is >> m >> n;
00061     if(is.fail())
00062       throw LinAlgPackIO::InputException( "DenseLinAlgPack::input() {DMatrixSlice}: "
00063         "Input operation of matrix dimension failed.  Check that the constant n "
00064         " is a valid integer.");
00065     if(is.bad())
00066       throw std::ios_base::failure( "DenseLinAlgPack::input() {DMatrixSlice}: "
00067         "Input operation failed because the stream became currupted." );
00068     DenseLinAlgPack::assert_gms_lhs(*gms,m,n);
00069   }
00070   return input_gms( is, gms, "DenseLinAlgPack::input() {DMatrixSlice}" );
00071 }
00072 
00073 // //////////////////////
00074 // Local implementation
00075 
00076 namespace {
00077 
00078 // Read in a specified number of elements into a DMatrixSlice object.
00079 // The dim of gms is not checked.  If an element input operation fails or the end of the file
00080 // is reached before all of the elements are read in then a LinAlgPackIO::InputException is thrown.
00081 // If the stream becomes currupted durring the input then a std::ios_base::failure exception
00082 // is thrown.  The state of the input steam remains the same on return accept for the char's
00083 // that have been extracted.
00084 std::istream& input_gms(std::istream& is, DenseLinAlgPack::DMatrixSlice* gms, const char func[]) {
00085   using std::ios_base;
00086   using DenseLinAlgPack::size_type;
00087   using DenseLinAlgPack::DVectorSlice;
00088   if(!gms->rows()) return is; // If we are inputting an unsized matrix then there are no elements
00089                 // to extract so just return.
00090   ios_base::iostate old_state = is.exceptions();    // save the old state
00091   is.exceptions(ios_base::badbit | ios_base::failbit | ios_base::eofbit);
00092   try {
00093     // Read in the rows
00094     for(size_type i = 1; i <= gms->rows(); ++i) {
00095       InputStreamHelperPack::eat_comment_lines(is,'*');
00096       DVectorSlice gms_row_i = gms->row(i);
00097       DenseLinAlgPack::input( is, &gms_row_i
00098         , (DenseLinAlgPack::LinAlgPackIO::fmtflags)(DenseLinAlgPack::LinAlgPackIO::ignore_dim_bit) );
00099     }
00100   }
00101   catch(...) {
00102     is.exceptions(old_state);
00103     throw;
00104   }
00105   is.exceptions(old_state);
00106   return is;
00107 }
00108 
00109 } // end namespace

Generated on Thu Sep 18 12:35:16 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1