編集:ありがとう、興味のある人のための修正コード: ert_main.cpp:
#include <stdio.h> /* This ert_main.c example uses printf/fflush */
#include "Rx.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
#include <stdlib.h>
#include <iostream>
#include <istream>
#include <sstream>
#include <fstream>
#include <string>
//#include <ofstream>//for writing results to file
//#include <ifstream> //doesn't work
#include <vector>
#define lengthOFSignal 5000
主な機能で:
using namespace std;
std::vector<std::string> words;
std::string word;
ifstream iFile;
string path = __FILE__; //gets source code path, include file name
path = path.substr(0,1+path.find_last_of('\\')); //removes file name
string testFileName = "LEGACY_R12_800BITS_40MHz.dat";
path+= testFileName; //adds input file to path
int signal_length=0;
std::vector<real_T> real_part_VEC, imag_part_VEC;
std::istringstream ss;
real_T real_temp, imag_temp;
iFile.open(path,ios::binary );
//iFile.open(path.c_str(), ios::binary);
if (iFile.is_open()) {
while (std::getline(iFile, word)) {
words.push_back(word);
}
iFile.close();
}
signal_length=words.size();
for(int i=0; i< signal_length;i++)
{
ss.str(words[i]);
ss >> real_temp >> imag_temp;
real_part_VEC.push_back(real_temp);
imag_part_VEC.push_back(imag_temp);
}
real_T real_part[lengthOFSignal];
real_T imag_part[lengthOFSignal];
for (int i=0; i < signal_length; i++) {
real_part[i]=real_part_VEC[i];
imag_part[i]=imag_part_VEC[i];
}
/* Initialize model */
Rx_initialize(real_part,imag_part,signal_length);
古いコードと問題:
.dat ファイルは、数字が並んだ 2 つの直線の列のように見えます (間隔が空いています)。
読み取ったデータのループに関するエラーが発生します (strtok -> atof (Null pointer) )
編集された ert_main.cpp メイン関数:
#include <stdio.h> /* This ert_main.c example uses printf/fflush */
#include "Rx.h" /* Model's header file */
#include "rtwtypes.h" /* MathWorks types */
#include <stdlib.h>
#include "mat.h"
#define lengthOFSignal 5000
#define SizeOfLine 35
int_T main(int_T argc, const char *argv[])
{
/* Unused arguments */
(void)(argc);
(void)(argv);
int i=0;
char bFileName[] = "QPSK_SISO_802_11_packet_awgn_fr_shft.dat";
char chr[SizeOfLine*lengthOFSignal];
char *token;
real_T real_part[lengthOFSignal];
real_T image_part[lengthOFSignal];
int signal_length=0;
std::ifstream iFile(bFileName, std::ios::binary);
iFile.getline(chr,100);
for(int i=0; i<lengthOFSignal; i++) {
if (chr== NULL) break;
token= strtok(chr," ");
real_part[i]=atof(token); // real part.---problem occurs here!!!!
token= strtok(NULL," ");
image_part[i]=atof(token);// imaginary part.
iFile.getline(chr,100);
signal_length++;
}
iFile.close();
/* Initialize model */
Rx_initialize(real_part,image_part,signal_length);
/* Attach rt_OneStep to a timer or interrupt service routine with
* period 40.0 seconds (the model's base sample time) here. The
* call syntax for rt_OneStep is
*
* rt_OneStep();
*/
printf("Warning: The simulation will run forever. "
"Generated ERT main won't simulate model step behavior. "
"To change this behavior select the 'MAT-file logging' option.\n");
fflush((NULL));
while (rtmGetErrorStatus(Rx_M) == (NULL)) {
/* Perform other application tasks here */
rt_OneStep();
if(Rx_Y.EVM!=0) break;
}
/* Disable rt_OneStep() here */
/* Terminate model */
Rx_terminate();
return 0;
}
ソリューションへのリンク (VS 2012) プロジェクト/ソリューションへのリンク