/[MITgcm]/MITgcm_contrib/high_res_cube/matlab-grid-generator/bin/f77write.m
ViewVC logotype

Contents of /MITgcm_contrib/high_res_cube/matlab-grid-generator/bin/f77write.m

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


Revision 1.1.1.1 - (show annotations) (download) (vendor branch)
Tue Nov 11 18:08:08 2003 UTC (21 years, 8 months ago) by cnh
Branch: MAIN, initial
CVS Tags: baseline, HEAD
Changes since 1.1: +0 -0 lines
Checking in work done with Dimitri on high-resolution cube gridding and parallel 
communications. 
   o code is in a contrib experiment for now so we can continue collaborating
     on it. However most code is general and will be moved into main branch once 
     it is fully hardened.
   o There are README files in the contrib root and in the subdirectories that
     explain the contents

1 % f77write(filename,array,options) writes an array to filename
2 % filename - is a string containing the name of the file to be read
3 % array - is a array containing of arbitrary dimensions
4 % options - (optional) specifies the data-type or the binary format
5 %
6 % Default data-type and binary format are 'real*8' and 'native'.
7 %
8 % Other data types can be one of:
9 % 'real*4' - floating point, 32 bits.
10 % 'real*8' - floating point, 64 bits.
11 %
12 % Other binary formats can be one of:
13 % 'native' or 'n' - local machine format - the default
14 % 'ieee-le' or 'l' - IEEE floating point with little-endian
15 % byte ordering
16 % 'ieee-be' or 'b' - IEEE floating point with big-endian
17 % byte ordering
18 % 'cray' or 'c' - Cray floating point with big-endian
19 % byte ordering
20 % 'ieee-le.l64' or 'a' - IEEE floating point with little-endian
21 % byte ordering and 64 bit long data type
22 % 'ieee-be.l64' or 's' - IEEE floating point with big-endian byte
23 % ordering and 64 bit long data type.
24 %
25 %
26 % eg. Write a real*8 dataset of size 160 x 10 x 16
27 % f77write('T.bin',A);
28 %
29 % eg. Write a real*4 dataset of size 120 x 45 in Little endian format
30 % f77write('T.bin',B,'real*4','l');
31 %
32 function [] = read3d(file,arr,varargin)
33
34 % Defaults
35 rtype='real*8'; % This is the default type of data
36 ieee='n'; % This is the default binary representation
37
38 % Check optional arguments
39 args=char(varargin);
40 while (size(args,1) > 0)
41 if deblank(args(1,:)) == 'real*4'
42 rtype='real*4';
43 elseif deblank(args(1,:)) == 'real*8'
44 rtype='real*8';
45 elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
46 ieee='n';
47 elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
48 ieee='l';
49 elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
50 ieee='b';
51 elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
52 ieee='c';
53 elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
54 ieee='a';
55 elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
56 ieee='s';
57 else
58 sprintf(['Optional argument ' args(1,:) ' is unknown'])
59 return
60 end
61 args=args(2:end,:);
62 end
63
64 if rtype == 'real*4'
65 wordsize=4;
66 elseif rtype == 'real*8'
67 wordsize=8;
68 else
69 sprintf('Somehow, rtype has an illegal value...!')
70 return
71 end
72 fid=fopen(file,'w',ieee);
73 % write the initial 4 bytes used in f77_unformatted
74 fwrite(fid,prod(size(arr))*wordsize,'uint32');
75 % write the data
76 fwrite(fid,arr,rtype);
77 % write the last 4 bytes used in f77_unformatted
78 fwrite(fid,prod(size(arr))*wordsize,'uint32');
79 % close the file
80 st=fclose(fid);

  ViewVC Help
Powered by ViewVC 1.1.22