#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int CountNewLine(FILE *f) {
char c;
int line = 0;
while ((c = fgetc(f)) != EOF) {
if (c == '\n') {
++line;
}
}
return line;
}
int ReadIQDataFromFile(const char *filePath, double **IData, double **QData, int *size) {
int lineCount = 0;
FILE *f = fopen(filePath, "r");
if (f == NULL) {
return -1;
}
lineCount = CountNewLine(f);
fclose(f);
if (lineCount == 0) {
return 0;
}
double *IArray = (double *)malloc(lineCount * sizeof(double));
double *QArray = (double *)malloc(lineCount * sizeof(double));
f = fopen(filePath, "r");
for (int i = 0; i < lineCount; ++i) {
fscanf(f, "%lf %lf\n", &IArray[i], &QArray[i]);
}
*IData = IArray;
*QData = QArray;
*size = lineCount;
return 1;
}
IQ文件为一列I,一列Q,预先不知道有多少行,通过先读取行数,再读取data。
0.0291044171899557114000000000000000 -0.4149183034896850590000000000000000
0.0616965517401695252000000000000000 -0.3455247282981872560000000000000000
0.0982574671506881714000000000000000 -0.2555656433105468750000000000000000
0.1308495998382568360000000000000000 -0.1599540263414382930000000000000000
0.1540609747171401980000000000000000 -0.0740839689970016480000000000000000
0.1659673303365707400000000000000000 -0.0105834240093827248000000000000000
0.1687334477901458740000000000000000 0.0222492422908544540000000000000000
0.1675307899713516240000000000000000 0.0221289787441492081000000000000000
0.1692145168781280520000000000000000 -0.0076970355585217475900000000000000
0.1808803379535675050000000000000000 -0.0589304268360137940000000000000000
0.2076997011899948120000000000000000 -0.1205067113041877750000000000000000
0.2511157691478729250000000000000000 -0.1796776801347732540000000000000000
0.3083624839782714840000000000000000 -0.2252585589885711670000000000000000
0.3727049231529235840000000000000000 -0.2484699189662933350000000000000000
0.4341609477996826170000000000000000 -0.2446214109659194950000000000000000