/[MITgcm]/MITgcm/verification/seaice_obcs/input/writebin.m
ViewVC logotype

Contents of /MITgcm/verification/seaice_obcs/input/writebin.m

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


Revision 1.1 - (show annotations) (download)
Tue Jan 8 10:39:33 2008 UTC (16 years, 4 months ago) by dimitri
Branch: MAIN
CVS Tags: checkpoint62c, checkpoint62b, checkpoint62a, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint61p, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint59o, checkpoint59p, checkpoint59n, checkpoint61k, checkpoint61h, checkpoint59r, checkpoint61x, checkpoint61q, checkpoint61y, checkpoint59m, checkpoint61f, checkpoint61g, checkpoint61d, checkpoint61e, checkpoint61b, checkpoint61c, checkpoint61i, checkpoint61a, checkpoint61n, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63g, checkpoint61z, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint61v, checkpoint59q, checkpoint61w, checkpoint61j, checkpoint61t, checkpoint64, checkpoint61u, checkpoint60, checkpoint61, checkpoint62, checkpoint63, checkpoint61r, checkpoint61s
o added verification/seaice_obcs both to test seaice open boundaries
  and to provide an example matlab scrpt for generating them

1 function writebin(fnam,fld,typ,prec,skip,mform)
2
3 % Function writebin(fnam,fld,typ,prec,skip,mform)
4 % write N-D binary field
5 %
6 % INPUTS
7 % fnam input path and file name
8 % fld input array
9 % typ 0: sequential FORTRAN; 1: plain binary (the default)
10 % prec numeric precision (default 'real*4')
11 % skip records to skip before writing (default 0)
12 % mform machine format (see fopen; default: 'ieee-be')
13 %
14 % SEE ALSO
15 % readbin
16
17 if nargin < 6, mform='ieee-be'; end
18 if nargin < 5, skip=0; end
19 if nargin < 4, prec='real*4'; end
20 if nargin < 3, typ=1; end
21 if skip>0 & typ==0, error('feature not implemented yet'); end
22 if nargin < 2, error('please specify array and output file name'); end
23 reclength=0;
24
25 if exist(fnam)==2
26 fid=fopen(fnam,'r+',mform);
27 else
28 fid=fopen(fnam,'w',mform);
29 end
30
31 switch typ
32
33 case 0
34
35 write_record(fid,fld,prec);
36
37 case 1
38
39 if skip==0
40
41 fwrite(fid,fld,prec);
42
43 else
44
45 switch prec
46 case {'int8','integer*1'}
47 reclength=prod(size(fld));
48 case {'int16','integer*2','uint16','integer*2'}
49 reclength=2*prod(size(fld));
50 case {'int32','integer*4','uint32','single','real*4','float32'}
51 reclength=4*prod(size(fld));
52 case {'int64','integer*8','uint64','double','real*8','float64'}
53 reclength=8*prod(size(fld));
54 end
55
56 if fseek(fid,skip*reclength,'bof') == 0
57
58 fwrite(fid,fld,prec);
59
60 else
61
62 fseek(fid,0,'eof');
63 file_length=ftell(fid);
64 fwrite(fid,zeros((skip*reclength-file_length),1),'int8');
65 fwrite(fid,fld,prec);
66
67 end
68
69 end
70
71 end
72
73 fid=fclose(fid);

  ViewVC Help
Powered by ViewVC 1.1.22