/[MITgcm]/MITgcm/verification/advect_cs/input/rdda.m
ViewVC logotype

Annotation of /MITgcm/verification/advect_cs/input/rdda.m

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


Revision 1.1 - (hide annotations) (download)
Tue Mar 30 13:59:46 2010 UTC (14 years ago) by dfer
Branch: MAIN
CVS Tags: checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63g, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint64, checkpoint65, checkpoint63, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65o, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62z, checkpoint62y, checkpoint62x, HEAD
Fix matlab script.

1 dfer 1.1 % result = RDDA( file, dim, irec [options] )
2     %
3     % This routine reads the irec'th record of shape 'dim' from the
4     % direct-access binary file (float or double precision) 'file'.
5     %
6     % Required arguments:
7     %
8     % file - string - name of file to read from
9     % dim - vector - dimensions of the file records and the resulting array
10     % irec - integer - record number in file in which to write data
11     %
12     % Optional arguments (must appear after the required arguments):
13     % prec - string - precision of storage in file. Default = 'real*8'.
14     % ieee - string - IEEE bit-wise representation in file. Default = 'b'.
15     %
16     % 'prec' may take the values:
17     % 'real*4' - floating point, 32 bits.
18     % 'real*8' - floating point, 64 bits - the efault.
19     %
20     % 'ieee' may take values:
21     % 'ieee-be' or 'b' - IEEE floating point with big-endian
22     % byte ordering - the default
23     % 'ieee-le' or 'l' - IEEE floating point with little-endian
24     % byte ordering
25     % 'native' or 'n' - local machine format
26     % 'cray' or 'c' - Cray floating point with big-endian
27     % byte ordering
28     % 'ieee-le.l64' or 'a' - IEEE floating point with little-endian
29     % byte ordering and 64 bit long data type
30     % 'ieee-be.l64' or 's' - IEEE floating point with big-endian byte
31     % ordering and 64 bit long data type.
32     %
33     % eg. T=rdda('t.data',[64 64 32],1);
34     % T=rdda('t.data',[256],4,'real*4');
35     % T=rdda('t.data',[128 64],2,'real*4','b');
36     function [arr] = rdda(file,N,k,varargin)
37    
38     % Defaults
39     WORDLENGTH=8;
40     rtype='real*8';
41     ieee='b';
42    
43     % Check optional arguments
44     args=char(varargin);
45     while (size(args,1) > 0)
46     if deblank(args(1,:)) == 'real*4'
47     WORDLENGTH=4;
48     rtype='real*4';
49     elseif deblank(args(1,:)) == 'real*8'
50     WORDLENGTH=8;
51     rtype='real*8';
52     elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
53     ieee='n';
54     elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
55     ieee='l';
56     elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
57     ieee='b';
58     elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
59     ieee='c';
60     elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
61     ieee='a';
62     elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
63     ieee='s';
64     else
65     sprintf(['Optional argument ' args(1,:) ' is unknown'])
66     return
67     end
68     args=args(2:end,:);
69     end
70    
71     nnn=prod(N);
72    
73     [fid mess]=fopen(file,'r',ieee);
74     if fid == -1
75     sprintf('Error while opening file:\n%s',mess)
76     arr=0;
77     return
78     end
79     st=fseek(fid,nnn*(k-1)*WORDLENGTH,'bof');
80     if st ~= 0
81     mess=ferror(fid);
82     sprintf('There was an error while positioning the file pointer:\n%s',mess)
83     arr=0;
84     return
85     end
86     [arr count]=fread(fid,nnn,rtype);
87     if count ~= nnn
88     sprintf('Not enough data was available to be read: off EOF?')
89     arr=0;
90     return
91     end
92     st=fclose(fid);
93     arr=reshape(arr,N);

  ViewVC Help
Powered by ViewVC 1.1.22