2011-03-23 268 views
0

我正在使用其他人写入的代码来加载文件格式,我找不到任何文档或规格。文件格式是* .vpd,这是用于EKG's的varioport阅读器的输出。未知的时间和日期格式

它读出4个字节的时间和4个字节的日期,每个存储在4个元素的数组中。在我的测试文件中,4个时间字节是{19,38,3,0},4个日期字节是{38,9,8,0}。它也可能是一个32位整数,写这个的人读错了。通过两者的尾部0来判断,我将假设小端,在这种情况下,时间和日期的值分别为206355和526630。

你知道用4个字节(或一个int)表示的任何时间/日期格式吗?我现在毫无希望地迷失了。

编辑:我应该补充说,我不知道什么值可能是,除了日期可能是在过去几年内。

该代码,没有与它相关的评论。

s.Rstime  = fread(fid, 4, 'uint8'); 
s.Rsdate  = fread(fid, 4, 'uint8'); 
+0

能否请您发布一些代码?也许代码中的评论可能会有所帮助。 – Redger 2011-03-23 14:41:42

+0

你还有别的测试文件吗? – Redger 2011-03-23 15:12:24

回答

1

在Varioport VPD文件格式中,BCD(二进制编码的十进制)码用于日期和时间。你没有机会猜测这个,因为你发布的fread电话显然是无稽之谈。你在错误的地方阅读。

在C/C试试这个++(MATLAB代码看起来非常相似):

typedef struct 
{ 
    int channelCount; 
    int scanRate; 
    unsigned char measureDate[3]; 
    unsigned char measureTime[3]; 
    ... 
} 
VPD_FILEINFO; 

... 

unsigned char threeBytes[3]; 
size_t itemsRead = 0; 

errno_t err = _tfopen_s(&fp, filename, _T("r+b")); 
// n.b.: vpd files have big-endian byte order! 

if (err != 0) 
{ 
    _tprintf(_T("Cannot open file %s\n"), filename); 
    return false; 
} 

// read date of measurement 
fseek(fp, 16, SEEK_SET); 
itemsRead = fread(&threeBytes, 1, 3, fp); 

if (itemsRead != 3) 
{ 
    _tprintf(_T("Error trying to read measureDate\n")); 
    return false; 
} 
else 
{ 
    info.measureDate[0] = threeBytes[0]; // day, binary coded decimal 
    info.measureDate[1] = threeBytes[1]; // month, binary coded decimal 
    info.measureDate[2] = threeBytes[2]; // year, binary coded decimal 
} 

// read time of measurement 
fseek(fp, 12, SEEK_SET); 
itemsRead = fread(&threeBytes, 1, 3, fp); 

if (itemsRead != 3) 
{ 
    _tprintf(_T("Error trying to read measureTime\n")); 
    return false; 
} 
else 
{ 
    info.measureTime[0] = threeBytes[0]; // hours, binary coded decimal 
    info.measureTime[1] = threeBytes[1]; // minutes, binary coded decimal 
    info.measureTime[2] = threeBytes[2]; // seconds, binary coded decimal 
} 

... 

_tprintf(_T("Measure date == %x %x %x\n"), 
     info.measureDate[0], 
     info.measureDate[1], 
     info.measureDate[2]); 

_tprintf(_T("Measure time == %x %x %x\n"), 
     info.measureTime[0], 
     info.measureTime[1], 
     info.measureTime[2]); 
+0

对不起,我错过了这个答案!你是对的,它是一个BCD,我得到了合理的时间,现在约会:)。谢谢一堆 – Hannesh 2011-07-30 21:03:31

0

这不重要了,我怀疑任何人都可以回答它。