有效的方法将3位小数的数组数据保存到文本文件中

时间:2014-08-06 14:35:22

标签: objective-c

我正在保存加速度计数据,我将其存储在数组中,直到我的捕获会话结束。当我触摸一个按钮时,我将数据保存为逗号分隔的文本文件,其精度为3,并且我添加了几列以显示数据是否在一个范围内。 我有大约26,000个数据点,每个数据点的时间,X,Y和Z值。我的所有数组都是long类型,我想要的float值是数组值除以1000。 我目前的格式化和保存数据的方法需要花费很长时间(约50秒),有人可以告诉我一个更有效的方法吗(也许以某种方式流式传输?)?

dd= [dd stringByAppendingString:@"Secs,PitchG,ThrottleG,YawG,.,.\r\n"];
for (int lop=1;lop< numd+1;lop++) {
    if (labs(logX[lop])<1000 && labs(logY[lop])<1000 && labs(logZ[lop])<1000){
        grnT= @".1";
        grnB= @"-.1";
    }else{
        grnT= @"0";
        grnB= @"0";
    }
    dd= [dd stringByAppendingString:[NSString stringWithFormat:@"%.3f,%.3f,%.3f,%.3f,%@,%@\r\n",
                                                (float)(dtime[lop])/1000,(float)(logY[lop])/1000,
                                                (float)(logZ[lop])/1000, (float)(logX[lop])/1000, grnT, grnB]];
}
NSData* ifodata = [dd dataUsingEncoding:NSUTF8StringEncoding];
NSString *sNTSpath= [NSString stringWithFormat:@"%@/%@.csv",docsDir,restartAtStr];
[filemgr createFileAtPath:sNTSpath contents:nil attributes:nil];
NSFileHandle *ntsfile= [NSFileHandle fileHandleForUpdatingAtPath:sNTSpath];
[ntsfile writeData:ifodata];
[ntsfile closeFile];

0 个答案:

没有答案