ShortRealFeatures.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "features/ShortRealFeatures.h"
00012 #include "lib/File.h"
00013
00014 bool CShortRealFeatures::load(char* fname)
00015 {
00016 bool status=false;
00017 num_vectors=1;
00018 num_features=0;
00019 CFile f(fname, 'r', F_SHORTREAL);
00020 int64_t numf=0;
00021 free_feature_matrix();
00022 feature_matrix=f.load_shortreal_data(NULL, numf);
00023 num_features=numf;
00024
00025
00026 if (!f.is_ok()) {
00027 SG_ERROR( "loading file \"%s\" failed", fname);
00028 }
00029 else
00030 status=true;
00031
00032 return status;
00033 }
00034
00035 bool CShortRealFeatures::save(char* fname)
00036 {
00037 int32_t len;
00038 bool free;
00039 float32_t* fv;
00040
00041 CFile f(fname, 'w', F_SHORTREAL);
00042
00043 for (int32_t i=0; i< (int32_t) num_vectors && f.is_ok(); i++)
00044 {
00045 if (!(i % (num_vectors/10+1)))
00046 SG_PRINT( "%02d%%.", (int) (100.0*i/num_vectors));
00047 else if (!(i % (num_vectors/200+1)))
00048 SG_PRINT( ".");
00049
00050 fv=get_feature_vector(i, len, free);
00051 f.save_shortreal_data(fv, len);
00052 free_feature_vector(fv, i, free) ;
00053 }
00054
00055 if (f.is_ok())
00056 SG_INFO( "%d vectors with %d features each successfully written (filesize: %ld)\n", num_vectors, num_features, num_vectors*num_features*sizeof(float32_t));
00057
00058 return true;
00059 }