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

Contents of /MITgcm_contrib/high_res_cube/matlab-grid-generator/bin/f77read.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 % f77read(filename,shape,options) returns an array of shape "shape"
2 % filename - is a string containing the name of the file to be read
3 % shape - is a vector containing the dimensions of the data
4 % eg. shape=[nx ny nz]
5 % options - (optional) specifies the data-type or the binary format
6 %
7 % Default data-type and binary format are 'real*8' and 'native'.
8 %
9 % Other data types can be one of:
10 % 'real*4' - floating point, 32 bits.
11 % 'real*8' - floating point, 64 bits.
12 %
13 % Other binary formats can be one of:
14 % 'native' or 'n' - local machine format - the default
15 % 'ieee-le' or 'l' - IEEE floating point with little-endian
16 % byte ordering
17 % 'ieee-be' or 'b' - IEEE floating point with big-endian
18 % byte ordering
19 % 'cray' or 'c' - Cray floating point with big-endian
20 % byte ordering
21 % 'ieee-le.l64' or 'a' - IEEE floating point with little-endian
22 % byte ordering and 64 bit long data type
23 % 'ieee-be.l64' or 's' - IEEE floating point with big-endian byte
24 % ordering and 64 bit long data type.
25 %
26 %
27 % eg. Read a real*8 dataset of size 160 x 10 x 16
28 % temp=f77read('T.bin',[160 10 16]);
29 %
30 % eg. Read a real*4 dataset of size 120 x 45 in Little endian format
31 % temp=f77read('T.bin',[120 45],'real*4','l');
32 %
33 function [arr] = read3d(file,N,varargin)
34
35 % Defaults
36 rtype='real*8'; % This is the default type of data
37 ieee='n'; % This is the default binary representation
38
39 % Set arr to null incase we do an early "return"
40 arr=0;
41
42 % Check optional arguments
43 args=char(varargin);
44 while (size(args,1) > 0)
45 if deblank(args(1,:)) == 'real*4'
46 rtype='real*4';
47 elseif deblank(args(1,:)) == 'real*8'
48 rtype='real*8';
49 elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
50 ieee='n';
51 elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
52 ieee='l';
53 elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
54 ieee='b';
55 elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
56 ieee='c';
57 elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
58 ieee='a';
59 elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
60 ieee='s';
61 else
62 sprintf(['Optional argument ' args(1,:) ' is unknown'])
63 return
64 end
65 args=args(2:end,:);
66 end
67
68 fid=fopen(file,'r',ieee);
69 % read the initial 4 bytes used in f77_unformatted
70 q=fread(fid,1,'uint32');
71 % read the data
72 arr=fread(fid,prod(N),rtype);
73 % reshape the data
74 arr=reshape(arr,N);
75 % close the file
76 st=fclose(fid);

  ViewVC Help
Powered by ViewVC 1.1.22