使用C语言读取IQ文件

#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值