/[MITgcm]/MITgcm/verification/global_ocean.90x40x15/diags_matlab/rdmeta.m
ViewVC logotype

Contents of /MITgcm/verification/global_ocean.90x40x15/diags_matlab/rdmeta.m

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


Revision 1.1 - (show annotations) (download)
Tue Oct 22 13:30:40 2002 UTC (21 years, 11 months ago) by mlosch
Branch: MAIN
CVS Tags: checkpoint57t_post, checkpoint58l_post, checkpoint48f_post, checkpoint46k_post, checkpoint51k_post, checkpoint53f_post, checkpoint47j_post, checkpoint54a_pre, checkpoint55c_post, checkpoint53b_pre, checkpoint48d_pre, checkpoint51l_post, checkpoint51j_post, branch-exfmods-tag, checkpoint47e_post, checkpoint57m_post, checkpoint47i_post, checkpoint52l_pre, checkpoint48i_post, checkpoint52e_pre, checkpoint58e_post, checkpoint57v_post, checkpoint57g_pre, checkpoint52j_post, checkpoint47f_post, checkpoint48d_post, checkpoint51o_pre, checkpoint57f_post, checkpoint50e_post, checkpoint52e_post, checkpoint50c_post, checkpoint57s_post, checkpoint51n_pre, checkpoint47d_post, checkpoint57j_post, checkpoint58b_post, checkpoint58m_post, checkpoint47a_post, checkpoint57b_post, checkpoint46l_pre, checkpoint53c_post, checkpoint53d_post, checkpoint57f_pre, checkpoint48a_post, checkpoint55d_pre, checkpoint46n_post, checkpoint51f_pre, checkpoint57g_post, checkpoint48e_post, checkpoint57a_post, checkpoint48h_post, checkpoint55j_post, checkpoint56b_post, checkpoint50c_pre, checkpoint57h_pre, checkpoint57y_post, branchpoint-genmake2, checkpoint46l_post, checkpoint58g_post, checkpoint57x_post, checkpoint52j_pre, checkpoint54a_post, branch-netcdf, checkpoint50d_pre, checkpoint55h_post, checkpoint51r_post, checkpoint52b_pre, checkpoint52n_post, checkpoint54b_post, checkpoint58h_post, checkpoint51i_post, checkpoint57e_post, checkpoint54d_post, checkpoint47h_post, checkpoint48c_post, checkpoint56c_post, checkpoint54e_post, checkpoint58j_post, checkpoint55b_post, checkpoint51e_post, checkpoint51b_post, checkpoint57h_post, checkpoint51l_pre, checkpoint52m_post, checkpoint51c_post, checkpoint57y_pre, checkpoint55, checkpoint53a_post, checkpoint55a_post, checkpoint57c_pre, checkpoint48, checkpoint49, checkpoint47b_post, checkpoint53b_post, checkpoint57o_post, checkpoint55g_post, checkpoint57r_post, checkpoint51o_post, checkpoint48g_post, checkpoint57k_post, checkpoint57d_post, checkpoint55f_post, checkpoint57i_post, checkpoint51q_post, checkpoint52l_post, checkpoint52k_post, checkpoint58, checkpoint57a_pre, checkpoint54, checkpoint57, checkpoint56, checkpoint51, checkpoint50, checkpoint53, checkpoint52, checkpoint50d_post, checkpoint52d_post, checkpoint46m_post, checkpoint51b_pre, checkpoint52a_post, checkpoint57h_done, checkpoint47g_post, checkpoint58f_post, checkpoint52b_post, checkpoint53g_post, checkpoint52f_post, checkpoint57n_post, checkpoint52c_post, checkpoint58d_post, checkpoint57w_post, checkpoint57p_post, checkpint57u_post, checkpoint51h_pre, checkpoint58a_post, checkpoint50g_post, checkpoint58i_post, checkpoint57q_post, checkpoint51g_post, ecco_c52_e35, checkpoint57z_post, checkpoint54f_post, checkpoint51f_post, checkpoint48b_post, checkpoint50b_post, eckpoint57e_pre, checkpoint58c_post, checkpoint58k_post, checkpoint57c_post, checkpoint50f_post, checkpoint50a_post, checkpoint50f_pre, checkpoint52a_pre, checkpoint47d_pre, checkpoint51d_post, checkpoint48c_pre, checkpoint51m_post, checkpoint51t_post, checkpoint53d_pre, checkpoint47, checkpoint55e_post, checkpoint54c_post, checkpoint50h_post, checkpoint52i_post, checkpoint51a_post, checkpoint50e_pre, checkpoint50i_post, checkpoint51p_post, checkpoint51n_post, checkpoint55i_post, checkpoint51i_pre, checkpoint57l_post, checkpoint52i_pre, checkpoint51u_post, checkpoint52h_pre, checkpoint52f_pre, checkpoint50b_pre, checkpoint56a_post, checkpoint51s_post, checkpoint55d_post
Branch point for: netcdf-sm0, branch-genmake2, branch-nonh, tg2-branch, checkpoint51n_branch, release1, branch-exfmods-curt
 fixed the verification/global_ocean.90x40x15 experiment:
 - new bathymetry (the world according to A., JMC, and M.)
 - new initial fields and forcing fields (*.bin files)
 - new POLY3.COEFFS (for the next release one should switch to a full
   equation of state: JMD95P or MDJWF)
 - fixed several errors and redundancies in the data file
 - experiment uses looped cells
 - added matlab directory with diagnostic scripts for plotting of output

1 function [AA] = rdmds(fname,varargin)
2 %
3 % Read MITgcmUV Meta/Data files
4 %
5 % A = RDMDS(FNAME) reads data described by meta/data file format.
6 % FNAME is a string containing the "head" of the file names.
7 %
8 % eg. To load the meta-data files
9 % T.0000002880.000.000.meta, T.0000002880.000.000.data
10 % T.0000002880.001.000.meta, T.0000002880.001.000.data
11 % T.0000002880.002.000.meta, T.0000002880.002.000.data
12 % T.0000002880.003.000.meta, T.0000002880.003.000.data
13 % use
14 % >> A=rdmds('T.0000002880');
15 %
16 % A = RDMDS(FNAME,MACHINEFORMAT) allows the machine format to be specified
17 % which MACHINEFORMAT is on of the following strings:
18 %
19 % 'native' or 'n' - local machine format - the default
20 % 'ieee-le' or 'l' - IEEE floating point with little-endian
21 % byte ordering
22 % 'ieee-be' or 'b' - IEEE floating point with big-endian
23 % byte ordering
24 % 'vaxd' or 'd' - VAX D floating point and VAX ordering
25 % 'vaxg' or 'g' - VAX G floating point and VAX ordering
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
34 % Default options
35 ieee='b';
36
37 % Check optional arguments
38 args=char(varargin);
39 while (size(args,1) > 0)
40 if deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
41 ieee='n';
42 elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
43 ieee='l';
44 elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
45 ieee='b';
46 elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
47 ieee='c';
48 elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
49 ieee='a';
50 elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
51 ieee='s';
52 else
53 error(['Optional argument ' args(1,:) ' is unknown'])
54 end
55 args=args(2:end,:);
56 end
57
58 % Match name of all meta-files
59 eval(['ls ' fname '*.meta;']);
60 allfiles=ans;
61
62 % Beginning and end of strings
63 Iend=findstr(allfiles,'.meta')+4;
64 Ibeg=[1 Iend(1:end-1)+2];
65
66 % Loop through allfiles
67 for j=1:prod(size(Ibeg)),
68
69 % Read meta- and data-file
70 [A,N] = localrdmds(allfiles(Ibeg(j):Iend(j)),ieee);
71
72 bdims=N(1,:);
73 r0=N(2,:);
74 rN=N(3,:);
75 ndims=prod(size(bdims));
76 if (ndims == 1)
77 AA(r0(1):rN(1))=A;
78 elseif (ndims == 2)
79 AA(r0(1):rN(1),r0(2):rN(2))=A;
80 elseif (ndims == 3)
81 AA(r0(1):rN(1),r0(2):rN(2),r0(3):rN(3))=A;
82 elseif (ndims == 4)
83 AA(r0(1):rN(1),r0(2):rN(2),r0(3):rN(3),r0(4):rN(4))=A;
84 else
85 error('Dimension of data set is larger than currently coded. Sorry!')
86 end
87
88 end
89
90 %-------------------------------------------------------------------------------
91
92 function [A,N] = localrdmds(fname,ieee)
93
94 mname=strrep(fname,' ','');
95 dname=strrep(mname,'.meta','.data');
96
97 % Read and interpret Meta file
98 fid = fopen(mname,'r');
99 if (fid == -1)
100 error(['File' mname ' could not be opened'])
101 end
102
103 % Scan each line of the Meta file
104 allstr=' ';
105 keepgoing = 1;
106 while keepgoing > 0,
107 line = fgetl(fid);
108 if (line == -1)
109 keepgoing=-1;
110 else
111 % Strip out "(PID.TID *.*)" by finding first ")"
112 %old ind=findstr([line ')'],')'); line=line(ind(1)+1:end);
113 ind=findstr(line,')');
114 if size(ind) ~= 0
115 line=line(ind(1)+1:end);
116 end
117 % Remove comments of form //
118 line=[line ' //']; ind=findstr(line,'//'); line=line(1:ind(1)-1);
119 % Add to total string
120 allstr=[allstr line];
121 end
122 end
123
124 % Close meta file
125 fclose(fid);
126
127 % Strip out comments of form /* ... */
128 ind1=findstr(allstr,'/*'); ind2=findstr(allstr,'*/');
129 if size(ind1) ~= size(ind2)
130 error('The /* ... */ comments are not properly paired')
131 end
132 while size(ind1,2) > 0
133 allstr=[allstr(1:ind1(1)-1) allstr(ind2(1)+3:end)];
134 ind1=findstr(allstr,'/*'); ind2=findstr(allstr,'*/');
135 end
136
137 % This is a kludge to catch whether the meta-file is of the
138 % old or new type. nrecords does not exist in the old type.
139 nrecords = -987;
140
141 % Everything in lower case
142 allstr=lower(allstr);
143
144 % Fix the unfortunate choice of 'format'
145 allstr=strrep(allstr,'format','dataprec');
146
147 % Evaluate meta information
148 eval(allstr);
149
150 N=reshape( dimlist , 3 , prod(size(dimlist))/3 );
151
152 if nrecords == -987
153 % This is the old 'meta' method that used sequential access
154
155 A=allstr;
156 % Open data file
157 fid=fopen(dname,'r',ieee);
158
159 % Read record size in bytes
160 recsz=fread(fid,1,'uint32');
161 ldims=N(3,:)-N(2,:)+1;
162 numels=prod(ldims);
163
164 rat=recsz/numels;
165 if rat == 4
166 A=fread(fid,numels,'real*4');
167 elseif rat == 8
168 A=fread(fid,numels,'real*8');
169 else
170 sprintf(' Implied size in meta-file = %d', numels )
171 sprintf(' Record size in data-file = %d', recsz )
172 error('Ratio between record size and size in meta-file inconsistent')
173 end
174
175 erecsz=fread(fid,1,'uint32');
176 if erecsz ~= recsz
177 sprintf('WARNING: Record sizes at beginning and end of file are inconsistent')
178 end
179
180 fclose(fid);
181
182 A=reshape(A,ldims);
183
184 else
185 % This is the new MDS format that uses direct access
186
187 ldims=N(3,:)-N(2,:)+1;
188 if dataprec == 'float32'
189 A=myrdda(dname,ldims,1,'real*4',ieee);
190 elseif dataprec == 'float64'
191 A=myrdda(dname,ldims,1,'real*8',ieee);
192 else
193 error(['Unrecognized format in meta-file = ' format]);
194 end
195
196 end
197
198 %-------------------------------------------------------------------------------
199
200 % result = RDDA( file, dim, irec [options] )
201 %
202 % This routine reads the irec'th record of shape 'dim' from the
203 % direct-access binary file (float or double precision) 'file'.
204 %
205 % Required arguments:
206 %
207 % file - string - name of file to read from
208 % dim - vector - dimensions of the file records and the resulting array
209 % irec - integer - record number in file in which to write data
210 %
211 % Optional arguments (must appear after the required arguments):
212 % prec - string - precision of storage in file. Default = 'real*8'.
213 % ieee - string - IEEE bit-wise representation in file. Default = 'b'.
214 %
215 % 'prec' may take the values:
216 % 'real*4' - floating point, 32 bits.
217 % 'real*8' - floating point, 64 bits - the efault.
218 %
219 % 'ieee' may take values:
220 % 'ieee-be' or 'b' - IEEE floating point with big-endian
221 % byte ordering - the default
222 % 'ieee-le' or 'l' - IEEE floating point with little-endian
223 % byte ordering
224 % 'native' or 'n' - local machine format
225 % 'cray' or 'c' - Cray floating point with big-endian
226 % byte ordering
227 % 'ieee-le.l64' or 'a' - IEEE floating point with little-endian
228 % byte ordering and 64 bit long data type
229 % 'ieee-be.l64' or 's' - IEEE floating point with big-endian byte
230 % ordering and 64 bit long data type.
231 %
232 % eg. T=rdda('t.data',[64 64 32],1);
233 % T=rdda('t.data',[256],4,'real*4');
234 % T=rdda('t.data',[128 64],2,'real*4','b');
235 function [arr] = myrdda(file,N,k,varargin)
236
237 % Defaults
238 WORDLENGTH=8;
239 rtype='real*8';
240 ieee='b';
241
242 % Check optional arguments
243 args=char(varargin);
244 while (size(args,1) > 0)
245 if deblank(args(1,:)) == 'real*4'
246 WORDLENGTH=4;
247 rtype='real*4';
248 elseif deblank(args(1,:)) == 'real*8'
249 WORDLENGTH=8;
250 rtype='real*8';
251 elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
252 ieee='n';
253 elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
254 ieee='l';
255 elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
256 ieee='b';
257 elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
258 ieee='c';
259 elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
260 ieee='a';
261 elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
262 ieee='s';
263 else
264 error(['Optional argument ' args(1,:) ' is unknown'])
265 end
266 args=args(2:end,:);
267 end
268
269 nnn=prod(N);
270
271 [fid mess]=fopen(file,'r',ieee);
272 if fid == -1
273 error('Error while opening file:\n%s',mess)
274 end
275 st=fseek(fid,nnn*(k-1)*WORDLENGTH,'bof');
276 if st ~= 0
277 mess=ferror(fid);
278 error('There was an error while positioning the file pointer:\n%s',mess)
279 end
280 [arr count]=fread(fid,nnn,rtype);
281 if count ~= nnn
282 error('Not enough data was available to be read: off EOF?')
283 end
284 st=fclose(fid);
285 arr=reshape(arr,N);

  ViewVC Help
Powered by ViewVC 1.1.22