How to skip header consit of integer words
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponse acceptée
dpb
le 9 Juil 2014
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 commentaires
dpb
le 9 Juil 2014
Modifié(e) : dpb
le 9 Juil 2014
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).
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur String Parsing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!