00001 #ifndef RepositorySOMDataFile_H
00002 #define RepositorySOMDataFile_H
00003
00010 #include <stdio.h>
00011 #include "xfile.h"
00012 #include <string>
00013 #include "TokenFinder.h"
00014 #include "WordIter.h"
00015 #include "TokenIter.h"
00016
00017 #include <iostream>
00018 #include "ISOMDataRepository.h"
00019 #include "Data.h"
00020 #include "defs.h"
00021
00022
00023 using std::cout;
00024
00025 class RepositorySOMDataFile : public ISOMDataRepository {
00026 public:
00028 void save( SOMData data );
00029
00031 SOMData * load( vector<string> params, int flag );
00032 };
00033
00034 void
00035 RepositorySOMDataFile::save( SOMData data ) {
00036 cout << "Save SOMData\n";
00037 };
00038
00039
00040 SOMData *
00041 RepositorySOMDataFile::load( vector<string> params, int flag ) {
00042 long storage_type = 0;
00043 long lSize;
00044 char* buffer;
00045 typedef vector<float> VecInt;
00046 typedef vector< VecInt > MatrixInt;
00047 TvecLabel lvec;
00048 MatrixInt mat;
00049 VecInt vec;
00050 MatrixInt::iterator im;
00051 VecInt::iterator iv;
00052 int dimension;
00053 int cont, contd;
00054
00055
00056 CxFile dataf( storage_type );
00057 dataf.Open( params[0].c_str(), "rb" );
00058
00059 lSize = dataf.Size();
00060
00061 buffer = (char*) malloc (lSize);
00062
00063 if (buffer == NULL) exit (2);
00064
00065 dataf.Read( buffer, 1, lSize );
00066
00067 string data( buffer );
00068
00069 token::WordIter wi(data);
00070
00071 cont = 0; contd = 1;
00072 while (wi != token::WordIter())
00073 {
00074 if ( isValid( *wi ) ) {
00075 if (cont==0)
00076 {
00077 dimension = strtoint( *wi );
00078 }
00079 else
00080 {
00081 if ( contd == dimension )
00082 {
00083 contd = 1;
00084 vec.push_back( strtofloat(*wi) );
00085 mat.push_back( vec );
00086 vec.clear();
00087 }
00088 else
00089 if ( isNumeric( *wi ) )
00090 {
00091 vec.push_back( strtofloat(*wi) );
00092 contd++;
00093 }
00094 else
00095 lvec.push_back( *wi );
00096 }
00097 cont++;
00098 }
00099 ++wi;
00100 }
00101
00102 TMatrix mdata = create_matrix( 1, mat.size(), 1, dimension );
00103 int i, j; i = j = 1;
00104
00105 for (im=mat.begin(); im<mat.end(); im++) {
00106 j = 1;
00107 for (iv=(*im).begin(); iv < (*im).end(); iv++)
00108 {
00109 mdata[i][j] = *iv;
00110 j++;
00111 }
00112 i++;
00113 }
00114
00115 SOMData * som_data = new SOMData;
00116
00117 som_data->setDimension( dimension );
00118 som_data->setDataSize( mat.size() );
00119 som_data->setEntries( mdata );
00120 som_data->setLabel( lvec );
00121
00122 free(buffer);
00123 dataf.Close();
00124
00125 return som_data;
00126 };
00127
00128 #endif
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00155
00156
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263