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

3G开发

开发平台:

Visual C++

  1. //
  2. //  File =ogive.cpp
  3. //
  4. #include <stdlib.h>
  5. #include <fstream>
  6. #include "parmfile.h"
  7. #include "model_graph.h"
  8. #include "ogive.h"
  9. #ifdef _DEBUG
  10.   extern ofstream *DebugFile;
  11. #endif
  12. extern ParmFile *ParmInput;
  13. extern int PassNumber;
  14. //======================================================
  15. template <class T>
  16. OgiveBuilder<T>::OgiveBuilder( char* instance_name,
  17.                                   PracSimModel* outer_model,
  18.                                   Signal<T>* in_sig )
  19.                 :PracSimModel( instance_name,
  20.                                 outer_model )
  21. {
  22.   MODEL_NAME(OgiveBuilder);
  23.   OPEN_PARM_BLOCK;
  24.   GET_INT_PARM(Num_Segs_To_Tally);
  25.   GET_INT_PARM(Hold_Off);
  26.   Hist_File_Name = new char[64];
  27.   strcpy(Hist_File_Name, "");
  28.   GET_STRING_PARM(Hist_File_Name);
  29.   GET_INT_PARM(Num_Bins);
  30.   GET_DOUBLE_PARM(Bin_Width);
  31.   GET_BOOL_PARM(Positive_Only);
  32.   GET_BOOL_PARM(Halt_When_Completed);
  33.   if(!Positive_Only)
  34.   {
  35.      if(Num_Bins%2 == 0) Num_Bins++;
  36.      First_Pos_Bin = (Num_Bins-1)/2;
  37.   }
  38.   else
  39.   {
  40.       First_Pos_Bin = 0;
  41.    }
  42.   In_Sig = in_sig;
  43.   MAKE_INPUT(In_Sig);
  44.   Hist_Bins = new int[Num_Bins];
  45.   for(int is=0; is<Num_Bins; is++)
  46.     {
  47.     Hist_Bins[is] = 0;
  48.     }
  49.   Hist_File = new ofstream(Hist_File_Name, ios::out);
  50.   Processing_Completed = false;
  51. }
  52. template <class T>
  53. OgiveBuilder<T>::~OgiveBuilder( void ){ };
  54. template <class T>
  55. void OgiveBuilder<T>::Initialize(void)
  56. {
  57.    Segs_In_Tally = 0;
  58.    Pts_In_Tally = 0;
  59.    Block_Size = In_Sig->GetBlockSize();
  60.    //Samp_Intvl = In_Sig->GetSampIntvl();
  61. };
  62. template <class T>
  63. int OgiveBuilder<T>::Execute()
  64. {
  65.    int is;
  66.    float left_edge, right_edge, gap_on_left;
  67.    #ifdef _DEBUG
  68.       *DebugFile << "In OgiveBuilder::Execute" << endl;
  69.    #endif
  70.    if(Processing_Completed) return(_MES_AOK);
  71.    if(PassNumber < Hold_Off) return (_MES_AOK);
  72.    //--------------------------------
  73.    //  Get pointers for buffers
  74.    T *in_sig_ptr = GET_INPUT_PTR(In_Sig);
  75.    T in_sig_val;
  76.    int bin_idx;
  77.    int sum;
  78.    double val;
  79.    for(is=0; is<Block_Size; is++)
  80.    {
  81.       in_sig_val = *in_sig_ptr++;
  82.       bin_idx = First_Pos_Bin + int(floor(in_sig_val/Bin_Width));
  83.       Hist_Bins[bin_idx]++;
  84.       Pts_In_Tally++;
  85.    }
  86.    Segs_In_Tally++;
  87.    // is it time to dump the results?
  88.    if(Segs_In_Tally == Num_Segs_To_Tally)
  89.    {
  90.       sum = 0;
  91.       for(is=0; is<Num_Bins; is++)
  92.       {
  93.          gap_on_left = float((is-First_Pos_Bin)*Bin_Width);
  94.          left_edge = float((is-First_Pos_Bin)*Bin_Width);
  95.          right_edge = float(((is-First_Pos_Bin)+1.0)*Bin_Width);
  96.          sum += Hist_Bins[is];
  97.          val = double(sum)/double(Pts_In_Tally);
  98.          (*Hist_File) << gap_on_left << ", " << 0 << endl;
  99.          (*Hist_File) << left_edge << ", " << val << endl;
  100.          (*Hist_File) << right_edge << ", " << val << endl;
  101.       }
  102.       gap_on_left = float((is-First_Pos_Bin)*Bin_Width);
  103.       (*Hist_File) << gap_on_left << ", " << 0 << endl;
  104.       Processing_Completed = true;
  105.       Hist_File->close();
  106.       if(Halt_When_Completed)
  107.       {
  108.          #ifdef _DEBUG
  109.             *DebugFile << "Execution halted by " << GetModelName() << endl;
  110.          #endif
  111.          exit(0);
  112.       }
  113.    }
  114.    return(_MES_AOK);
  115. }
  116. //template HistogramBuilder<std::complex<float> >;
  117. template OgiveBuilder<float>;