ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvarm1_i.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 #include "fvar.hpp"
00013 
00015 
00016 
00017 #ifdef __TURBOC__
00018   #pragma hdrstop
00019   #include <iostream.h>
00020   #include <iomanip.h>
00021   #include <fstream.h>
00022   #define __USE_IOSTREAM__
00023 #endif
00024 
00025 #ifdef __ZTC__
00026   #include <iostream.hpp>
00027   #include <iomanip.hpp>
00028   #include <fstream.hpp>
00029   #define __USE_IOSTREAM__
00030 #endif
00031 
00032 
00033 // unformatted i/o
00034 
00035 #ifdef __USE_IOSTREAM__
00036 
00040 uistream& operator>>(const uistream& istr, const dvar_matrix& _z)
00041 {
00042   ADUNCONST(dvar_matrix,z)
00043   z.read_from(istr);
00044   return (uistream&)istr;
00045 }
00046 
00051 void dvar_matrix::read_from(const uistream& s)
00052 {
00053   if (allocated(*this))
00054   {
00055     int n = rowmin() + rowsize() - 1;
00056 
00057     for (int i=rowmin(); i <= n; i++)
00058     {
00059       s >> (*this)[i];
00060       if (!s.good())
00061       {
00062         cerr << " Error in dvar_matrix read\n";
00063         ad_exit(1);
00064       }
00065     }
00066   }
00067 }
00068 
00073 uostream& operator<<(const uostream& ostr, const dvar_matrix& z)
00074 {
00075   if (allocated(z))
00076     z.write_on(ostr);
00077 
00078   return (uostream&)ostr;
00079 }
00080 
00085 void dvar_matrix::write_on(const uostream& s) const
00086 {
00087   if (allocated(*this))
00088   {
00089     int n = rowmin() + rowsize() - 1;
00090     for (int i=rowmin(); i <= n; i++)
00091     {
00092       s << (*this)[i];
00093       if (!s.good())
00094       {
00095         cerr << " Error in dvar_matrix write\n";
00096         ad_exit(1);
00097       }
00098     }
00099   }
00100 }
00101 #endif
00102