ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvarm_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 // file: fvarm_io.cpp
00012 
00014 
00015 #include "fvar.hpp"
00016 
00017 
00018 #ifdef __TURBOC__
00019   #pragma hdrstop
00020   #include <iostream.h>
00021   #include <iomanip.h>
00022   #include <fstream.h>
00023   #define __USE_IOSTREAM__
00024 #endif
00025 
00026 #ifdef __ZTC__
00027   #include <iostream.hpp>
00028   #include <iomanip.hpp>
00029   #include <fstream.hpp>
00030   #define __USE_IOSTREAM__
00031 #endif
00032 
00037 ostream& operator<<(const ostream& _ostr, const dvar_matrix& z)
00038 {
00039   ostream& ostr= (ostream&) _ostr;
00040   z.write_on(ostr);
00041 
00042   return ostr;
00043 }
00044 
00049 void dvar_matrix::write_on(const ostream& _s) const
00050 {
00051   ostream& s = (ostream&)_s;
00052 #ifdef __USE_IOSTREAM__
00053   using std::streamsize;
00054   streamsize new_w = s.width();
00055   streamsize new_p = s.precision();
00056 #if !defined(__cplusplus)
00057   long new_form = s.flags();
00058 #else
00059   ios::fmtflags new_form = s.flags();
00060 #endif
00061   char new_fill = s.fill();
00062 #endif
00063 
00064   for (int i=rowmin(); i <= rowmax(); i++)
00065   {
00066   #ifdef __USE_IOSTREAM__
00067     s.width(new_w);
00068     s.precision(new_p);
00069     s.flags(new_form);
00070     s.fill(new_fill);
00071   #endif
00072     s << (*this)[i];
00073     if(i<rowmax())
00074     {
00075       s << endl;
00076     }
00077   }
00078 }
00079 
00084 istream& operator>>(const istream& _istr, const dvar_matrix& _z)
00085 {
00086   dvar_matrix& z = (dvar_matrix&)_z;
00087   istream& istr= (istream&) _istr;
00088   z.read_from(istr);
00089 
00090   return istr;
00091 }
00092 
00097 void dvar_matrix::read_from(const istream& s)
00098 {
00099   int n = rowmin() + rowsize() - 1;
00100 
00101   for (int i=rowmin(); i <= n; i++)
00102   {
00103     s >> (*this)[i];
00104     /*
00105     if (!s.good())
00106     {
00107       cerr << " Error in dvar_matrix read\n";
00108       ad_exit(1);
00109     }
00110     */
00111   }
00112 }