Warning, /verification/natl_box/matlab/write_record.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit cdf4d124 on 2000-11-13 16:02:33 UTC
cdf4d1244c Patr*0001 function write_record (file_id, field, record_type)
0002 % function write_record (file_id, field, record_type)
0003 % write a fortran record
0004 % file needs to be previously opened in write binary mode, i.e.,
0005 % file_id=fopen(fname,'w','b');
0006 % field contains the variable to be written
0007 % record_type defaults to real*4
0008
0009 if nargin<3, record_type='real*4'; end
0010 switch lower(record_type)
0011 case {'uint8','integer*1','int8', ...
0012 'schar','signed char','uchar','unsigned char','char','char*1'}
0013 record_length=length(field(:));
0014 case {'uint16','integer*2','int16','integer*2'}
0015 record_length=length(field(:))*2;
0016 case {'float32','real*4','uint32','integer*4','int32','integer*4'}
0017 record_length=length(field(:))*4;
0018 case {'float64','real*8','uint64','integer*8','int64','integer*8'}
0019 record_length=length(field(:))*8;
0020 end
0021 tmp=fwrite(file_id,record_length,'uint32'); % fortran record length
0022 tmp=fwrite(file_id,field,record_type);
0023 tmp=fwrite(file_id,record_length,'uint32'); % fortran record length