/[MITgcm]/MITgcm_contrib/timour_matlab/mscripts/Readmodel.m
ViewVC logotype

Annotation of /MITgcm_contrib/timour_matlab/mscripts/Readmodel.m

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


Revision 1.1 - (hide annotations) (download)
Wed Sep 3 21:22:22 2003 UTC (21 years, 10 months ago) by edhill
Branch: MAIN
CVS Tags: HEAD
initial checkin of Timour's MatLAB scripts

1 edhill 1.1 %
2     % Load M.I.T. GCM model data output files.
3     %
4     function array = Readmodel( fileName, dims, format )
5     if nargin < 2
6     fprintf(2,'**ERROR** Wrong number of arguments.\n')
7     fprintf(2,'Usage: Readmodel(''pathname'', [dim1 dim2 dim3 ...])\n')
8     return
9     end
10     if nargin == 2
11     format = 'float32';
12     end
13     if size(dims,1) ~= 1
14     fprintf(2,'**ERROR** Array dimensions mis-specified.\n')
15     fprintf(2,'Usage: Readmodel(''pathname'', [dim1 dim2 dim3 ...])\n')
16     return
17     end
18     fid=fopen(fileName,'r','b');
19     if fid < 0
20     fprintf(2,'**ERROR** Unable to open input file "%s".\n',fileName)
21     fprintf(2,'Usage: Readmodel(''pathname'', [dim1 dim2 dim3 ...])\n')
22     return
23     end
24     arraySize=1+size(dims,2)+prod(dims);
25     array=zeros(1,arraySize);
26     array(1)=size(dims,2);
27     for i = 1 : size(dims,2);
28     array(i+1)=dims(1,i);
29     end
30     [dummy,cnt]=fread(fid,1,'int');
31     if cnt ~= 1
32     fprintf(2,'**ERROR** Unable to read first byte of file "%s".\n',fileName)
33     fprintf(2,'Usage: Readmodel(''pathname'', [dim1 dim2 dim3 ...])\n')
34     fclose(fid)
35     return
36     end
37     [array(1+size(dims,2)+1:size(array,2)),cnt]=fread(fid,prod(dims),format);
38     if cnt ~= prod(dims)
39     fprintf(2,'**ERROR** Unable to read field data from file "%s".\n',fileName)
40     fprintf(2,'Usage: Readmodel(''pathname'', [dim1 dim2 dim3 ...])\n')
41     fclose(fid)
42     return
43     end
44     return

  ViewVC Help
Powered by ViewVC 1.1.22