/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/write2meta.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/write2meta.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Wed Mar 16 15:02:19 2016 UTC (9 years, 3 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.1: +11 -1 lines
- process2nctiles.m: rename 'step' netcdf variable as 'timstep' to avoid
  conflict with existing function; add hard coded 'diagsDir' param;
  omit grid variables in netcdf file when RAC has not been defined;
  use repmat to avoid loop over size(myDiag{1},4).
- write2file.m: add omitNaNs option (2nd optional input parameter; 1 by default)
- write2meta.m: add fldList option (2nd optional input parameter; [] by default)
- write2nctiles.m: switch to 'NETCDF4' if array size exceed 1.5G; clear
  temporary variables once they are no longer needed.

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 1) myPrec is the file myPrecision (32, by default, or 64)
7 %(optional 2) fldList is the list of field names (cell array)
8
9 %precision:
10 if nargin>2; myPrec=varargin{1}; else; myPrec=32; end;
11 if nargin>3; fldList=varargin{2}; else; fldList=[]; end;
12 %number of dimensions
13 nDim=length(myDim);
14 %number of records:
15 tmp1=dir(myFile);
16 nRec=tmp1.bytes/myDim(1)/myDim(2)/myPrec*8;
17 if nDim>2; nRec=nRec/myDim(3); end;
18 if nRec<1|floor(nRec)~=nRec; error('inconsistent dimensions'); end;
19 %check that creating a meta file makes sense w\r\t rdmds
20 if ~strcmp(myFile(end-4:end),'.data');
21 error('file name must finish in ''.data''\n');
22 else;
23 myFile=[myFile(1:end-5) '.meta'];
24 end;
25
26 %create the meta file:
27 fid=fopen(myFile,'wt');
28 %%
29 fprintf(fid,'nDims = [ %i ];\n',min(nDim,3));
30 fprintf(fid,' dimList = [\n');
31 fprintf(fid,' %5i, %5i, %5i,\n',myDim(1),1,myDim(1));
32 fprintf(fid,' %5i, %5i, %5i,\n',myDim(2),1,myDim(2));
33 if nDim>2; fprintf(fid,' %5i, %5i, %5i,\n',myDim(3),1,myDim(3)); end;
34 fprintf(fid,' ];\n');
35 fprintf(fid,' dataprec = [ ''float%2i'' ];\n',myPrec);
36 fprintf(fid,' nrecords = [ %5i ];\n',nRec);
37 if ~isempty(fldList);
38 nFlds=length(fldList);
39 fprintf(fid,' nFlds = [ %i ];\n',nFlds);
40 fprintf(fid,' fldList = {\n');
41 txt=' '; for ii=1:length(fldList); txt=[txt '''' fldList{ii} '''' ' ']; end;
42 fprintf(fid,[txt '\n']);
43 fprintf(fid,' };\n');
44 end;
45 %%
46 fclose(fid);
47

  ViewVC Help
Powered by ViewVC 1.1.22