How to skip header consit of integer words

4 次查看(过去 30 天)
The file I am trying to read has following description: The files were written in IEEE binary (big-endian). Each file contains three records described as follows:
rec 1: date and version number (8 4-byte integer words)
rec 2: gridded sst values in degC (360*180 4-byte real words)
rec 3: gridded ice concentration (360*180 1-byte integer words)
How can I read rec 2 and rec 3 data without worrying about the rec 1? I've tried using fseek but it's not working. For rec 2 I am using something like: sst=fread(fid2,[360,200],'real*4',1,'ieee-be'); but I am getting all crazy nos which doesn't make any sense.
Thanks.

采纳的回答

dpb
dpb 2014-7-9
fid=fopen('file','r','ieee-be');
fseek(fid,8*4);
temp=fread(fid,[360,180],'real*4','ieee-be').'; % no skip and fix size and orientation
ice=fread(fid,[360,180],'real*4','ieee-be').';
fid=fclose(fid);
Certainly after the first value skipping a byte will really screw everything after up until get thru the cycle of four bytes at which you should get one correct value again. Also remember Matlab fills the array in column-major order.
If after the above, data don't look like real floating point values, I'd suspect native format as the option.
  3 个评论
dpb
dpb 2014-7-9
编辑:dpb 2014-7-9
OOOPS! My bad; I cut 'n pasted and forgot to change the size. It says "1-byte integer" so I'd probably choose 'int8' or 'integer*1' but one presumes a concentration won't be negative so IA's 'uint8' will have the same effect.
Sorry for the oversight...
ADDENDUM
Also, just for the record note that memmapfile is useful for decoding such things, particularly if there are multiple sets of data within the file (C structs, iow).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 String Parsing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by