1 |
function []=write2meta(myFile,myDim,varargin); |
2 |
%purpose: write meta file to match binary file |
3 |
% |
4 |
%inputs: myFile is the file name (must finish with '.data') |
5 |
% myDim is the size of a field (2D or 3D integer vector) |
6 |
%(optional) myPrec is the file myPrecision (32, by default, or 64) |
7 |
|
8 |
%precision: |
9 |
if nargin>2; myPrec=varargin{1}; else; myPrec=32; end; |
10 |
%number of dimensions |
11 |
nDim=length(myDim); |
12 |
%number of records: |
13 |
tmp1=dir(myFile); |
14 |
nRec=tmp1.bytes/myDim(1)/myDim(2)/myPrec*8; |
15 |
if nDim>2; nRec=nRec/myDim(3); end; |
16 |
if nRec<1|floor(nRec)~=nRec; error('inconsistent dimensions'); end; |
17 |
%check that creating a meta file makes sense w\r\t rdmds |
18 |
if ~strcmp(myFile(end-4:end),'.data'); |
19 |
error('file name must finish in ''.data''\n'); |
20 |
else; |
21 |
myFile=[myFile(1:end-5) '.meta']; |
22 |
end; |
23 |
|
24 |
%create the meta file: |
25 |
fid=fopen(myFile,'wt'); |
26 |
%% |
27 |
fprintf(fid,'nDims = [ %i ];\n',min(nDim,3)); |
28 |
fprintf(fid,' dimList = [\n'); |
29 |
fprintf(fid,' %5i, %5i, %5i,\n',myDim(1),1,myDim(1)); |
30 |
fprintf(fid,' %5i, %5i, %5i,\n',myDim(2),1,myDim(2)); |
31 |
if nDim>2; fprintf(fid,' %5i, %5i, %5i,\n',myDim(3),1,myDim(3)); end; |
32 |
fprintf(fid,' ];\n'); |
33 |
fprintf(fid,' dataprec = [ ''float%2i'' ];\n',myPrec); |
34 |
fprintf(fid,' nrecords = [ %5i ];\n',nRec); |
35 |
%% |
36 |
fclose(fid); |
37 |
|