1 |
function write_record (file_id, field, record_type) |
2 |
% function write_record (file_id, field, record_type) |
3 |
% write a fortran record |
4 |
% file needs to be previously opened in write binary mode, i.e., |
5 |
% file_id=fopen(fname,'w','b'); |
6 |
% field contains the variable to be written |
7 |
% record_type defaults to real*4 |
8 |
|
9 |
if nargin<3, record_type='real*4'; end |
10 |
switch lower(record_type) |
11 |
case {'uint8','integer*1','int8', ... |
12 |
'schar','signed char','uchar','unsigned char','char','char*1'} |
13 |
record_length=length(field(:)); |
14 |
case {'uint16','integer*2','int16','integer*2'} |
15 |
record_length=length(field(:))*2; |
16 |
case {'float32','real*4','uint32','integer*4','int32','integer*4'} |
17 |
record_length=length(field(:))*4; |
18 |
case {'float64','real*8','uint64','integer*8','int64','integer*8'} |
19 |
record_length=length(field(:))*8; |
20 |
end |
21 |
tmp=fwrite(file_id,record_length,'uint32'); % fortran record length |
22 |
tmp=fwrite(file_id,field,record_type); |
23 |
tmp=fwrite(file_id,record_length,'uint32'); % fortran record length |