symb_analyzer.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:3k
源码类别:

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = symb_analyzer.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "symb_analyzer.h"
  8. #include "typedefs.h"
  9. #include "model_graph.h"
  10. #include "syst_graph.h"
  11. extern ParmFile *ParmInput;
  12. extern ofstream *DebugFile;
  13. extern SystemGraph CommSystemGraph;
  14. extern int PassNumber;
  15. extern int MaxPassNumber;
  16. //======================================================
  17. SymbSeqAnalyzer::SymbSeqAnalyzer( char* instance_name,
  18.                         PracSimModel* outer_model,
  19.                         Signal<byte_t>* symb_seq )
  20.           :PracSimModel(instance_name,
  21.                         outer_model)
  22. {
  23.   MODEL_NAME(SymbSeqAnalyzer);
  24.   In_Sig = symb_seq;
  25.   OPEN_PARM_BLOCK;
  26.   GET_INT_PARM(Report_Intvl_In_Blocks);
  27.   GET_INT_PARM(Bits_Per_Symb);
  28.   MAKE_INPUT(In_Sig);
  29.   Num_Diff_Symbs = 1<<Bits_Per_Symb;
  30.   Symb_Count = new int[Num_Diff_Symbs];
  31.   Double_Count = new int[Num_Diff_Symbs*Num_Diff_Symbs];
  32. }
  33. //======================================================
  34. SymbSeqAnalyzer::~SymbSeqAnalyzer( void ){ };
  35. //======================================================
  36. void SymbSeqAnalyzer::Initialize(void)
  37. {
  38.    int i;
  39.    Block_Size = In_Sig->GetBlockSize();
  40.    for(i=0; i<Num_Diff_Symbs; i++)
  41.       Symb_Count[i] = 0;
  42.    for(i=0; i<Num_Diff_Symbs*Num_Diff_Symbs; i++)
  43.       Double_Count[i] = 0;
  44. };
  45. //======================================================
  46. int SymbSeqAnalyzer::Execute()
  47. {
  48.    byte_t *in_byte_ptr, in_byte;
  49.    byte_t old_byte;
  50.    int is, i,j;
  51.    in_byte_ptr = GET_INPUT_PTR( In_Sig );
  52.    for( is=0; is < Block_Size; is++)
  53.    {
  54.       in_byte = *in_byte_ptr++;
  55.       Symb_Count[in_byte]++;
  56.       if(is%2)
  57.       {
  58.          Double_Count[old_byte*Num_Diff_Symbs + in_byte]++;
  59.       }
  60.       else
  61.       {
  62.          old_byte = in_byte;
  63.       }
  64.      
  65.    }
  66.    if( (PassNumber % Report_Intvl_In_Blocks) == 0)
  67.    {
  68.       float total_count = float(Symb_Count[0]);
  69.       for( i=1; i<Num_Diff_Symbs; i++)
  70.          total_count += Symb_Count[i];
  71.       BasicResults << Instance_Name << ": "
  72.               << PassNumber << "  symbol %'s: "
  73.               << (Symb_Count[0]/total_count);
  74.       for( i=1; i<Num_Diff_Symbs; i++)
  75.       {
  76.          BasicResults << ", " << (Symb_Count[i]/total_count);
  77.       }
  78.       BasicResults << "n" << endl;
  79.       total_count = float(Double_Count[0]);
  80.       for( i=1; i<Num_Diff_Symbs*Num_Diff_Symbs; i++)
  81.          total_count += Double_Count[i];
  82.       for( i=0; i<Num_Diff_Symbs; i++)
  83.       {
  84.          for( j=0; j<Num_Diff_Symbs; j++)
  85.          {
  86.             BasicResults << ", " << (Double_Count[i*Num_Diff_Symbs+j]/total_count);
  87.          }
  88.          BasicResults << "n" << endl;
  89.       }
  90.    }
  91.    return(_MES_AOK);
  92. }