[Dart-dev] [3282] DART/trunk/models/MITgcm_ocean/matlab: rdslice.m, wrslice.m, and rdmds.m are 'origina' routines from Ibrahim.

thoar at subversion.ucar.edu thoar at subversion.ucar.edu
Thu Mar 27 14:45:52 MDT 2008


An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/dart-dev/attachments/20080327/3687dd06/attachment-0001.html
-------------- next part --------------
Added: DART/trunk/models/MITgcm_ocean/matlab/CheckMask.m
===================================================================
--- DART/trunk/models/MITgcm_ocean/matlab/CheckMask.m	                        (rev 0)
+++ DART/trunk/models/MITgcm_ocean/matlab/CheckMask.m	2008-03-27 20:45:52 UTC (rev 3282)
@@ -0,0 +1,40 @@
+function CheckMask()
+% CheckMask 
+% 
+%
+
+% Data Assimilation Research Testbed -- DART
+% Copyright 2004-2007, Data Assimilation Research Section
+% University Corporation for Atmospheric Research
+% Licensed under the GPL -- www.gpl.org/licenses/gpl.html
+%
+% <next few lines under version control, do not edit>
+% $URL$
+% $Id$
+% $Revision$
+% $Date$
+
+%-------------------------------------------------------------------------------
+%-------------------------------------------------------------------------------
+
+mitbase = '/fs/image/home/nancy/subversion/trunk/models/MITgcm_ocean/data2/';
+
+S     = rdmds(sprintf('%s/%s.0000040992',mitbase,'S'));
+Sinds = find(S == 0.0); clear S;
+
+T     = rdmds(sprintf('%s/%s.0000040992',mitbase,'T'));
+Tinds = find(T == 0.0); clear T;
+
+U     = rdmds(sprintf('%s/%s.0000040992',mitbase,'U'));
+Uinds = find(U == 0.0); clear U;
+
+V     = rdmds(sprintf('%s/%s.0000040992',mitbase,'V'));
+Vinds = find(V == 0.0); clear V;
+
+SSH = rdmds(sprintf('%s/%s.0000040992',mitbase,'Eta'));
+
+disp(sprintf('S has %d zeros',length(Sinds)))
+disp(sprintf('T has %d zeros',length(Tinds)))
+disp(sprintf('U has %d zeros',length(Uinds)))
+disp(sprintf('V has %d zeros',length(Vinds)))
+


Property changes on: DART/trunk/models/MITgcm_ocean/matlab/CheckMask.m
___________________________________________________________________
Name: svn:mime-type
   + text/x-matlab
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: DART/trunk/models/MITgcm_ocean/matlab/VerifyNetCDF.m
===================================================================
--- DART/trunk/models/MITgcm_ocean/matlab/VerifyNetCDF.m	                        (rev 0)
+++ DART/trunk/models/MITgcm_ocean/matlab/VerifyNetCDF.m	2008-03-27 20:45:52 UTC (rev 3282)
@@ -0,0 +1,125 @@
+function VerifyNetCDF(varname)
+% VerifyNetCDF compares the fortran direct-access input files with the variables
+% in the True_State.nc file. This script was used to ensure the state variable was
+% being read properly and that we could parse it correctly ... and that the netCDF
+% routines were working as expected.
+% 
+% VerifyNetCDF('T')
+%
+
+% Data Assimilation Research Testbed -- DART
+% Copyright 2004-2007, Data Assimilation Research Section
+% University Corporation for Atmospheric Research
+% Licensed under the GPL -- www.gpl.org/licenses/gpl.html
+%
+% <next few lines under version control, do not edit>
+% $URL$
+% $Id$
+% $Revision$
+% $Date$
+
+varname = upper(varname);
+mitbase = '/fs/image/home/nancy/subversion/trunk/models/MITgcm_ocean/data2/';
+
+switch varname
+case {'S','T','U','V'}
+   mitO  = rdmds(sprintf('%s/%s.0000040992',mitbase,varname));
+   [nx ny nz] = size(mitO);
+otherwise
+   mitO  = rdmds(sprintf('%s/Eta.0000040992',mitbase));
+   [nx ny] = size(mitO);
+   nz = 1;
+   varname = 'SSH';
+end
+
+levels = getnc('True_State.nc','ZC');
+
+% uncomfortable assumption about missing value flag
+% The DART routines make the same uncomfortable assumption.
+
+inds   = find(mitO == 0.0);
+mitO(inds) = NaN;
+   
+%  fid = fopen('perfect_ics','rt');
+%  [validtime, count] = fscanf(fid,'%d',2);
+%  x     = fscanf(fid,'%f');
+%  fclose(fid)
+%  
+%  mysize = prod(size(s)) + prod(size(t)) + prod(size(u)) + prod(size(v)) + prod(size(ssh));
+%  psize = length(x);
+%  
+%  disp(sprintf('MIT size is %d, DART size is %d',mysize,psize))
+
+%  s_end = prod(size(s));
+%  ICS = reshape(x(1:s_end),size(s));
+
+%-------------------------------------------------------------------------------
+%-------------------------------------------------------------------------------
+
+for i = 1:nz
+
+   figure(1); clf; colormap(gauss3);
+
+   switch varname
+   case {'S','T','U','V'}
+      mit = squeeze(mitO(:,:,i));
+      corner = [-1 -1 i -1 -1];
+      endpnt = [-1 -1 i -1 -1];
+   otherwise
+      mit = mitO(:,:);
+      corner = [-1 i -1 -1];
+      endpnt = [-1 i -1 -1];
+   end
+
+   dart = getnc('True_State.nc',varname,corner,endpnt,-1,-2);
+
+   datmat = (dart - mit);
+
+   inds = isfinite(mit);
+   mmin = min(mit(inds));
+   mmax = max(mit(inds));
+   nmitzeros = length(inds);
+   b = datmat(inds);
+
+   inds = isfinite(dart);
+   dmin = min(dart(inds));
+   dmax = max(dart(inds));
+   ndartzeros = length(inds);
+
+   if (ndartzeros ~= nmitzeros) 
+      disp(sprintf('WARNING: mit has %d zeros dart has %d zeros',nmitzeros,ndartzeros))
+   end
+   if (mmin ~= dmin) 
+      disp(sprintf('WARNING: mit minimum %f dart minimum %d',mmin,dmin))
+   end
+   if (mmax ~= dmax) 
+      disp(sprintf('WARNING: mit maximum %f dart maximum %d',mmax,dmax))
+   end
+
+   subplot(2,2,1)
+   imagesc(mit'); set(gca,'YDir','normal')
+   title({sprintf('Original : level %d of %d   %f',i,nz,levels(i)),...
+          sprintf('min %f max %f',mmin,mmax)})
+   colorbar
+
+   subplot(2,2,2)
+   imagesc(dart'); set(gca,'YDir','normal')
+   title(sprintf('netcdf min %f max %f',dmin,dmax))
+   colorbar
+
+   subplot(2,2,3)
+   imagesc(datmat'); set(gca,'YDir','normal')
+   title({'difference (netcdf - original)', ...
+         sprintf('min %f max %f',min(b), max(b))})
+   colorbar
+
+   subplot(2,2,4)
+   hist(b,50);
+   title({'difference (netcdf - original)', ...
+         sprintf('min %f max %f',min(b), max(b))})
+
+   % disp('Pausing - hit any key to continue')
+   disp('Pausing for one second')
+   pause(1.0)
+
+end


Property changes on: DART/trunk/models/MITgcm_ocean/matlab/VerifyNetCDF.m
___________________________________________________________________
Name: svn:mime-type
   + text/x-matlab
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: DART/trunk/models/MITgcm_ocean/matlab/rdmds.m
===================================================================
--- DART/trunk/models/MITgcm_ocean/matlab/rdmds.m	                        (rev 0)
+++ DART/trunk/models/MITgcm_ocean/matlab/rdmds.m	2008-03-27 20:45:52 UTC (rev 3282)
@@ -0,0 +1,354 @@
+function [AA] = rdmds(fnamearg,varargin)
+% RDMDS  Read MITgcmUV meta/data files
+%
+% A = RDMDS(FNAME)
+% A = RDMDS(FNAME,ITER)
+% A = RDMDS(FNAME,[ITER1 ITER2 ...])
+%
+%   A = RDMDS(FNAME) reads data described by meta/data file format.
+%   FNAME is a string containing the "head" of the file names.
+%  
+%   eg. To load the meta-data files
+%       T.0000002880.000.000.meta, T.0000002880.000.000.data
+%       T.0000002880.001.000.meta, T.0000002880.001.000.data
+%       T.0000002880.002.000.meta, T.0000002880.002.000.data
+%       T.0000002880.003.000.meta, T.0000002880.003.000.data
+%   use
+%      >> A=rdmds('T.0000002880');
+%      >> size(A)
+%   ans =
+%      64    32     5
+%   eg. To load a multiple record file
+%      >> A=rdmds('pickup.0000002880');
+%      >> size(A)
+%   ans =
+%      64    32     5    61
+%  
+%  
+%   A = RDMDS(FNAME,ITER) reads data described by meta/data file format.
+%   FNAME is a string containing the "head" of the file name excluding the
+%   10-digit iterartion number.
+%   ITER is a vector of positive integers that will expand to the 10-digit
+%   number in the file name.
+%  
+%   eg. To repeat above operation
+%      >> A=rdmds('T',2880);
+%   eg. To read multiple time steps
+%      >> A=rdmds('T',[0 1440 2880]);
+%   Note: this form can not read files with no iteration count in file name.
+%  
+%   A = RDMDS(FNAME,MACHINEFORMAT)
+%   A = RDMDS(FNAME,ITER,MACHINEFORMAT) allows the machine format to be
+%   specified which MACHINEFORMAT is on of the following strings:
+%     'n' 'l' 'b' 'd' 'g' 'c' 'a' 's'  - see FOPEN for more details
+%  
+%  
+% $Header: /u/gcmpack/MITgcm/utils/matlab/rdmds.m,v 1.8.4.1 2002/02/06 15:48:10 heimbach Exp $
+
+% Default options
+ieee='b';
+fname=fnamearg;
+iters=-1;
+
+% Check optional arguments
+for ind=1:size(varargin,2);
+ arg=varargin{ind};
+ if ischar(arg)
+  if strcmp(arg,'n') | strcmp(arg,'native')
+   ieee='n';
+  elseif strcmp(arg,'l') | strcmp(arg,'ieee-le')
+   ieee='l';
+  elseif strcmp(arg,'b') | strcmp(arg,'ieee-be')
+   ieee='b';
+  elseif strcmp(arg,'c') | strcmp(arg,'cray')
+   ieee='c';
+  elseif strcmp(arg,'a') | strcmp(arg,'ieee-le.l64')
+   ieee='a';
+  elseif strcmp(arg,'s') | strcmp(arg,'ieee-be.l64')
+   ieee='s';
+  else
+   error(['Optional argument ' arg ' is unknown'])
+  end
+ else
+  if isnan(arg)
+   iters=scanforfiles(fname);
+   disp([ sprintf('Reading %i time levels:',size(iters,2)) sprintf(' %i',iters) ]);
+  elseif isinf(arg)
+   iters=scanforfiles(fname);
+   disp([ sprintf('Found %i time levels, reading %i',size(iters,2),iters(end)) ]);
+   iters=iters(end);
+  elseif prod(arg>=0) & prod(round(arg)==arg)
+   if arg>=9999999999
+    error(sprintf('Argument %i > 9999999999',arg))
+   end
+   iters=arg;
+  else
+   error(sprintf('Argument %i must be a positive integer',arg))
+  end
+ end
+end
+
+% Loop over each iteration
+for iter=1:size(iters,2);
+if iters(iter)>=0
+ fname=sprintf('%s.%10.10i',fnamearg,iters(iter));
+end
+
+% Figure out if there is a path in the filename
+NS=findstr('/',fname);
+if size(NS)>0
+ Dir=fname(1:NS(end));
+else
+ Dir='./';
+end
+
+% Match name of all meta-files
+allfiles=dir( sprintf('%s*.meta',fname) );
+
+if size(allfiles,1)==0
+ disp(sprintf('No files match the search: %s.*.meta',fname));
+%allow partial reads%  error('No files found.')
+end
+
+% Loop through allfiles
+for j=1:size(allfiles,1);
+
+% Read meta- and data-file
+[A,N] = localrdmds([Dir allfiles(j).name],ieee);
+
+bdims=N(1,:);
+r0=N(2,:);
+rN=N(3,:);
+ndims=prod(size(bdims));
+if     (ndims == 1)
+ AA(r0(1):rN(1),iter)=A;
+elseif (ndims == 2)
+ AA(r0(1):rN(1),r0(2):rN(2),iter)=A;
+elseif (ndims == 3)
+ AA(r0(1):rN(1),r0(2):rN(2),r0(3):rN(3),iter)=A;
+elseif (ndims == 4)
+ AA(r0(1):rN(1),r0(2):rN(2),r0(3):rN(3),r0(4):rN(4),iter)=A;
+elseif (ndims == 5)
+ AA(r0(1):rN(1),r0(2):rN(2),r0(3):rN(3),r0(4):rN(4),r0(5):rN(5),iter)=A;
+else
+ error('Dimension of data set is larger than currently coded. Sorry!')
+end
+
+end % files
+end % iterations
+
+%-------------------------------------------------------------------------------
+
+function [A,N] = localrdmds(fname,ieee)
+
+mname=strrep(fname,' ','');
+dname=strrep(mname,'.meta','.data');
+
+% Read and interpret Meta file
+fid = fopen(mname,'r');
+if (fid == -1)
+ error(['File' mname ' could not be opened'])
+end
+
+% Scan each line of the Meta file
+allstr=' ';
+keepgoing = 1;
+while keepgoing > 0,
+ line = fgetl(fid);
+ if (line == -1)
+  keepgoing=-1;
+ else
+% Strip out "(PID.TID *.*)" by finding first ")"
+%old  ind=findstr([line ')'],')'); line=line(ind(1)+1:end);
+  ind=findstr(line,')');
+  if size(ind) ~= 0
+    line=line(ind(1)+1:end);
+  end
+% Remove comments of form //
+  line=[line ' //']; ind=findstr(line,'//'); line=line(1:ind(1)-1);
+% Add to total string
+  allstr=[allstr line];
+ end
+end
+
+% Close meta file
+fclose(fid);
+
+% Strip out comments of form /* ... */
+ind1=findstr(allstr,'/*'); ind2=findstr(allstr,'*/');
+if size(ind1) ~= size(ind2)
+ error('The /* ... */ comments are not properly paired')
+end
+while size(ind1,2) > 0
+ allstr=[allstr(1:ind1(1)-1) allstr(ind2(1)+3:end)];
+ ind1=findstr(allstr,'/*'); ind2=findstr(allstr,'*/');
+end
+
+% This is a kludge to catch whether the meta-file is of the
+% old or new type. nrecords does not exist in the old type.
+nrecords = -987;
+
+% Everything in lower case
+allstr=lower(allstr);
+
+% Fix the unfortunate choice of 'format'
+allstr=strrep(allstr,'format','dataprec');
+
+% Evaluate meta information
+eval(allstr);
+
+N=reshape( dimlist , 3 , prod(size(dimlist))/3 );
+if nrecords ~= -987 & nrecords > 1
+ N=[N,[nrecords 1 nrecords]'];
+end
+
+if nrecords == -987
+% This is the old 'meta' method that used sequential access
+
+A=allstr;
+% Open data file
+fid=fopen(dname,'r',ieee);
+
+% Read record size in bytes
+recsz=fread(fid,1,'uint32');
+ldims=N(3,:)-N(2,:)+1;
+numels=prod(ldims);
+
+rat=recsz/numels;
+if rat == 4
+ A=fread(fid,numels,'real*4');
+elseif rat == 8
+ A=fread(fid,numels,'real*8');
+else
+ sprintf(' Implied size in meta-file = %d', numels )
+ sprintf(' Record size in data-file = %d', recsz )
+ error('Ratio between record size and size in meta-file inconsistent')
+end
+
+erecsz=fread(fid,1,'uint32');
+if erecsz ~= recsz
+ sprintf('WARNING: Record sizes at beginning and end of file are inconsistent')
+end
+
+fclose(fid);
+
+A=reshape(A,ldims);
+
+else
+% This is the new MDS format that uses direct access
+
+ ldims=N(3,:)-N(2,:)+1;
+ if dataprec == 'float32'
+  A=myrdda(dname,ldims,1,'real*4',ieee);
+ elseif dataprec == 'float64'
+  A=myrdda(dname,ldims,1,'real*8',ieee);
+ else
+  error(['Unrecognized format in meta-file = ' format]);
+ end
+
+end
+
+%-------------------------------------------------------------------------------
+
+% result = RDDA( file, dim, irec [options] )
+%
+% This routine reads the irec'th record of shape 'dim' from the
+% direct-access binary file (float or double precision) 'file'.
+%
+% Required arguments:
+%
+%   file  - string  - name of file to read from
+%   dim   - vector  - dimensions of the file records and the resulting array
+%   irec  - integer - record number in file in which to write data
+%
+% Optional arguments (must appear after the required arguments):
+%   prec  - string  - precision of storage in file. Default = 'real*8'.
+%   ieee  - string  - IEEE bit-wise representation in file. Default = 'b'.
+%
+% 'prec' may take the values:
+%       'real*4' - floating point, 32 bits.
+%       'real*8' - floating point, 64 bits - the efault.
+%
+% 'ieee' may take values:
+%    'ieee-be'     or 'b' - IEEE floating point with big-endian
+%                           byte ordering - the default
+%    'ieee-le'     or 'l' - IEEE floating point with little-endian
+%                           byte ordering
+%    'native'      or 'n' - local machine format
+%    'cray'        or 'c' - Cray floating point with big-endian
+%                           byte ordering
+%    'ieee-le.l64' or 'a' - IEEE floating point with little-endian
+%                           byte ordering and 64 bit long data type
+%    'ieee-be.l64' or 's' - IEEE floating point with big-endian byte
+%                           ordering and 64 bit long data type.
+%
+% eg.   T=rdda('t.data',[64 64 32],1);
+%       T=rdda('t.data',[256],4,'real*4');
+%       T=rdda('t.data',[128 64],2,'real*4','b');
+function [arr] = myrdda(file,N,k,varargin)
+
+% Defaults
+WORDLENGTH=8;
+rtype='real*8';
+ieee='b';
+
+% Check optional arguments
+args=char(varargin);
+while (size(args,1) > 0)
+ if deblank(args(1,:)) == 'real*4'
+  WORDLENGTH=4;
+  rtype='real*4';
+ elseif deblank(args(1,:)) == 'real*8'
+  WORDLENGTH=8;
+  rtype='real*8';
+ elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
+  ieee='n';
+ elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
+  ieee='l';
+ elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
+  ieee='b';
+ elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
+  ieee='c';
+ elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
+  ieee='a';
+ elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
+  ieee='s';
+ else
+  error(['Optional argument ' args(1,:) ' is unknown'])
+ end
+ args=args(2:end,:);
+end
+
+nnn=prod(N);
+
+[fid mess]=fopen(file,'r',ieee);
+if fid == -1
+ error('Error while opening file:\n%s',mess)
+end
+st=fseek(fid,nnn*(k-1)*WORDLENGTH,'bof');
+if st ~= 0
+ mess=ferror(fid);
+ error('There was an error while positioning the file pointer:\n%s',mess)
+end
+[arr count]=fread(fid,nnn,rtype);
+if count ~= nnn
+ error('Not enough data was available to be read: off EOF?')
+end
+st=fclose(fid);
+arr=reshape(arr,N);
+
+%
+function [iters] = scanforfiles(fname)
+
+allfiles=dir([fname '.*.001.001.meta']);
+if isempty(allfiles)
+ allfiles=dir([fname '.*.meta']);
+ ioff=0;
+else
+ ioff=8;
+end
+for k=1:size(allfiles,1);
+ hh=allfiles(k).name;
+ iters(k)=str2num( hh(end-14-ioff:end-5-ioff) );
+end
+


Property changes on: DART/trunk/models/MITgcm_ocean/matlab/rdmds.m
___________________________________________________________________
Name: svn:mime-type
   + text/x-matlab
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: DART/trunk/models/MITgcm_ocean/matlab/rdslice.m
===================================================================
--- DART/trunk/models/MITgcm_ocean/matlab/rdslice.m	                        (rev 0)
+++ DART/trunk/models/MITgcm_ocean/matlab/rdslice.m	2008-03-27 20:45:52 UTC (rev 3282)
@@ -0,0 +1,67 @@
+% rdslice(filename,[nx ny ...],k) returns an array of shape [nx,ny,...]
+% read from a direct access binary file (float or double precisision) named
+% by the string 'filename'. The file may contain multi-dimensional
+% data. Note that cumsum([nx ny ...]*k) <= length of file.
+%
+% eg.   temp=rdslice('t.xyt',[160 120],4);
+%
+% rdsclice(filename,[nx ny ...],k,type) returns an array of type 'type'.
+% where type can be one of 'real*4' or 'real*8'. The default is 'real*8'.
+function [arr] = rdslice(file,N,k,varargin)
+
+% Default word-length
+WORDLENGTH=8;
+rtype='real*8';
+ieee='b';
+
+% Check optional arguments
+args=char(varargin);
+while (size(args,1) > 0)
+ if deblank(args(1,:)) == 'real*4'
+  WORDLENGTH=4;
+  rtype='real*4';
+ elseif deblank(args(1,:)) == 'real*8'
+  WORDLENGTH=8;
+  rtype='real*8';
+ elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
+  ieee='n';
+ elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
+  ieee='l';
+ elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
+  ieee='b';
+ elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
+  ieee='c';
+ elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
+  ieee='a';
+ elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
+  ieee='s';
+ else
+  sprintf(['Optional argument ' args(1,:) ' is unknown'])
+  return
+ end
+ args=args(2:end,:);
+end
+
+nnn=prod(N);
+
+[fid mess]=fopen(file,'r',ieee);
+if fid == -1
+ sprintf('Error while opening file:\n%s',mess)
+ arr=0;
+ return
+end
+st=fseek(fid,nnn*(k-1)*WORDLENGTH,'bof');
+if st ~= 0
+ mess=ferror(fid);
+ sprintf('There was an error while positioning the file pointer:\n%s',mess)
+ arr=0;
+ return
+end
+[arr count]=fread(fid,nnn,rtype);
+if count ~= nnn
+ sprintf('Not enough data was available to be read: off EOF?')
+ arr=0;
+ return
+end
+st=fclose(fid);
+arr=reshape(arr,N);


Property changes on: DART/trunk/models/MITgcm_ocean/matlab/rdslice.m
___________________________________________________________________
Name: svn:mime-type
   + text/x-matlab
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native

Added: DART/trunk/models/MITgcm_ocean/matlab/wrslice.m
===================================================================
--- DART/trunk/models/MITgcm_ocean/matlab/wrslice.m	                        (rev 0)
+++ DART/trunk/models/MITgcm_ocean/matlab/wrslice.m	2008-03-27 20:45:52 UTC (rev 3282)
@@ -0,0 +1,69 @@
+% wrslice(filename,arr,n,k) writes an array of shape [nx,ny,...]
+% to a direct access binary file (float or double precisision) named
+% by the string 'filename'. The file may contain multi-dimensional
+% data. 'n' is the record number to be written where the record length
+% is the size of the array 'arr'.
+%
+% eg.   wrslice('t.xyt',T,4);
+%
+% rdsclice(filename,A,k,type) writes an array of type 'type'.
+% where type can be one of 'real*4' or 'real*8'. The default is 'real*8'.
+function [] = wrslice(file,arr,k,varargin)
+
+% Default word-length
+WORDLENGTH=8;
+rtype='real*8';
+ieee='b';
+
+% Check optional arguments
+args=char(varargin);
+while (size(args,1) > 0)
+ if deblank(args(1,:)) == 'real*4'
+  WORDLENGTH=4;
+  rtype='real*4';
+ elseif deblank(args(1,:)) == 'real*8'
+  WORDLENGTH=8;
+  rtype='real*8';
+ elseif deblank(args(1,:)) == 'n' | deblank(args(1,:)) == 'native'
+  ieee='n';
+ elseif deblank(args(1,:)) == 'l' | deblank(args(1,:)) == 'ieee-le'
+  ieee='l';
+ elseif deblank(args(1,:)) == 'b' | deblank(args(1,:)) == 'ieee-be'
+  ieee='b';
+ elseif deblank(args(1,:)) == 'c' | deblank(args(1,:)) == 'cray'
+  ieee='c';
+ elseif deblank(args(1,:)) == 'a' | deblank(args(1,:)) == 'ieee-le.l64'
+  ieee='a';
+ elseif deblank(args(1,:)) == 's' | deblank(args(1,:)) == 'ieee-be.l64'
+  ieee='s';
+ else
+  sprintf(['Optional argument ' args(1,:) ' is unknown'])
+  return
+ end
+ args=args(2:end,:);
+end
+
+
+N=size(arr);
+nnn=prod(N);
+
+[fid mess]=fopen(file,'r+',ieee);
+if fid == -1
+ [fid mess]=fopen(file,'w',ieee);
+ if fid == -1
+  sprintf('Error while opening file:\n%s',mess)
+  return
+ end
+end
+st=fseek(fid,nnn*(k-1)*WORDLENGTH,'bof');
+if st ~= 0
+ mess=ferror(fid);
+ sprintf('There was an error while positioning the file pointer:\n%s',mess)
+ return
+end
+count=fwrite(fid,arr,rtype);
+if count ~= nnn
+ sprintf('Not enough data was available to be read: off EOF?')
+ return
+end
+st=fclose(fid);


Property changes on: DART/trunk/models/MITgcm_ocean/matlab/wrslice.m
___________________________________________________________________
Name: svn:mime-type
   + text/x-matlab
Name: svn:keywords
   + Date Rev Author URL Id
Name: svn:eol-style
   + native


More information about the Dart-dev mailing list