00001 #ifndef MFILE_IMPL_HPP
00002 #define MFILE_IMPL_HPP
00003
00004 #include <string>
00005
00006 namespace Kalman {
00007
00008 template<typename T, K_UINT_32 BEG, bool DBG>
00009 inline int MFile::get(std::string name, KVector<T,BEG,DBG>& tmpvector)
00010 {
00011 unsigned int i;
00012
00013 for(i=0; i<VectorMFileElement.size(); i++)
00014 {
00015 if (VectorMFileElement[i].Name == name)
00016 break;
00017 }
00018
00019 if (i==VectorMFileElement.size())
00020 return -1;
00021
00022 if (VectorMFileElement[i].Cols>VectorMFileElement[i].Rows)
00023 {
00024
00025 tmpvector.resize(VectorMFileElement[i].Cols);
00026 for(unsigned int j=0; j<VectorMFileElement[i].Cols; j++)
00027 {
00028 tmpvector(BEG+j)=Data[VectorMFileElement[i].Index+j];
00029 }
00030 }
00031 else
00032 {
00033
00034 tmpvector.resize(VectorMFileElement[i].Rows);
00035 for(unsigned int j=0; j<VectorMFileElement[i].Rows; j++)
00036 {
00037 tmpvector(BEG+j)=Data[VectorMFileElement[i].Index+j*VectorMFileElement[i].Cols];
00038 }
00039 }
00040
00041 return 0;
00042 }
00043
00044
00045 template<typename T, K_UINT_32 BEG, bool DBG>
00046 inline int MFile::get(std::string name, KMatrix<T,BEG,DBG>& tmpmatrix)
00047 {
00048 unsigned int i;
00049
00050 for(i=0; i<VectorMFileElement.size(); i++)
00051 {
00052 if (VectorMFileElement[i].Name == name)
00053 break;
00054 }
00055
00056 if (i==VectorMFileElement.size())
00057 return -1;
00058
00059 tmpmatrix.resize(VectorMFileElement[i].Rows, VectorMFileElement[i].Cols);
00060
00061 for(unsigned int j=0; j<VectorMFileElement[i].Rows; j++)
00062 {
00063 for(unsigned int k=0; k<VectorMFileElement[i].Cols; k++)
00064 {
00065 tmpmatrix(BEG+j,BEG+k) = Data[VectorMFileElement[i].Index + j*VectorMFileElement[i].Cols + k];
00066 }
00067 }
00068
00069 return 0;
00070 }
00071
00072
00073 template<typename T, K_UINT_32 BEG, bool DBG>
00074 inline int MFile::add(std::string name, KVector<T,BEG,DBG>& tmpvector, int type)
00075 {
00076 unsigned int i;
00077 MFileElement tmpElement;
00078 double tmpdouble;
00079
00080 for(i=0; i<VectorMFileElement.size(); i++)
00081 {
00082 if (VectorMFileElement[i].Name == name)
00083 break;
00084 }
00085
00086
00087 if (i!=VectorMFileElement.size())
00088 return -1;
00089
00090 if (type == ROW_VECTOR)
00091 {
00092 tmpElement.Rows = 1;
00093 tmpElement.Cols = tmpvector.size();
00094 tmpElement.Name = name;
00095 tmpElement.Index = Data.size();
00096 }
00097 else
00098 {
00099 tmpElement.Rows = tmpvector.size();
00100 tmpElement.Cols = 1;
00101 tmpElement.Name = name;
00102 tmpElement.Index = Data.size();
00103 }
00104
00105 VectorMFileElement.push_back(tmpElement);
00106
00107
00108 for(unsigned int i=0; i<tmpvector.size(); i++)
00109 {
00110 tmpdouble = tmpvector(BEG + i);
00111 Data.push_back(tmpdouble);
00112 }
00113
00114 return 0;
00115 }
00116
00117
00118 template<typename T, K_UINT_32 BEG, bool DBG>
00119 inline int MFile::add(std::string name, KMatrix<T,BEG,DBG>& tmpmatrix)
00120 {
00121 unsigned int i;
00122 MFileElement tmpElement;
00123 double tmpdouble;
00124
00125
00126 for(i=0; i<VectorMFileElement.size(); i++)
00127 {
00128 if (VectorMFileElement[i].Name == name)
00129 break;
00130 }
00131
00132
00133 if (i!=VectorMFileElement.size())
00134 return -1;
00135
00136 tmpElement.Rows = tmpmatrix.nrow();
00137 tmpElement.Cols = tmpmatrix.ncol();
00138 tmpElement.Name = name;
00139 tmpElement.Index = Data.size();
00140 VectorMFileElement.push_back(tmpElement);
00141
00142 for(unsigned int i=0; i<tmpmatrix.nrow(); i++)
00143 {
00144 for(unsigned int j=0; j<tmpmatrix.ncol(); j++)
00145 {
00146 tmpdouble = tmpmatrix(BEG + i,BEG + j);
00147 Data.push_back(tmpdouble);
00148 }
00149 }
00150
00151 return 0;
00152 }
00153
00154 }
00155
00156 #endif