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

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/write2file.m

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


Revision 1.2 - (hide 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: +5 -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 gforget 1.1 function []=write2file(fileOut,fldIn,varargin);
2     %purpose: write array to binary file
3     %
4     %inputs: fileOut is the file name
5     % fldIn is the array to write to disk
6     %(optional) prec is the file precision (32, by default, or 64)
7    
8     if nargin>2; prec=varargin{1}; else; prec=32; end;
9 gforget 1.2 if nargin>3; omitNaNs=varargin{2}; else; omitNaNs=1; end;
10 gforget 1.1
11     if ~ischar(fldIn);
12 gforget 1.2 fid=fopen(fileOut,'w','b'); tmp1=fldIn;
13     if omitNaNs; tmp1(isnan(tmp1))=0; end;
14     fwrite(fid,tmp1,['float' num2str(prec)]);
15     fclose(fid);
16 gforget 1.1 else;
17     fid=fopen(fileOut,'wt'); fwrite(fid,fldIn); fclose(fid);
18     end;
19    
20    
21    

  ViewVC Help
Powered by ViewVC 1.1.22