ADMB Documentation  11.1.1890
 All Classes Files Functions Variables Typedefs Friends Defines
fvarm_io.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvarm_io.cpp 1864 2014-04-08 00:50:10Z johnoel $
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   int new_w = s.width();
00054   int new_p = s.precision();
00055 #if !defined(__cplusplus)
00056   long new_form = s.flags();
00057 #else
00058   ios::fmtflags new_form = s.flags();
00059 #endif
00060   char new_fill = s.fill();
00061 #endif
00062 
00063   for (int i=rowmin(); i <= rowmax(); i++)
00064   {
00065   #ifdef __USE_IOSTREAM__
00066     s.width(new_w);
00067     s.precision(new_p);
00068     s.flags(new_form);
00069     s.fill(new_fill);
00070   #endif
00071     s << (*this)[i];
00072     if(i<rowmax())
00073     {
00074       s << endl;
00075     }
00076   }
00077 }
00078 
00083 istream& operator>>(const istream& _istr, const dvar_matrix& _z)
00084 {
00085   dvar_matrix& z = (dvar_matrix&)_z;
00086   istream& istr= (istream&) _istr;
00087   z.read_from(istr);
00088 
00089   return istr;
00090 }
00091 
00096 void dvar_matrix::read_from(const istream& s)
00097 {
00098   int n = rowmin() + rowsize() - 1;
00099 
00100   for (int i=rowmin(); i <= n; i++)
00101   {
00102     s >> (*this)[i];
00103     /*
00104     if (!s.good())
00105     {
00106       cerr << " Error in dvar_matrix read\n";
00107       ad_exit(1);
00108     }
00109     */
00110   }
00111 }